corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) 2006-2014, openmetaverse.org
3 * All rights reserved.
4 *
5 * - Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * - Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 * - Neither the name of the openmetaverse.org nor the names
11 * of its contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26  
27 using System;
28 using System.Drawing;
29 using System.IO;
30 using System.Windows.Forms;
31  
32 namespace OpenMetaverse.GUI
33 {
34 /// <summary>
35 /// RichTextBox GUI component for displaying a client's status output
36 /// </summary>
37 public class StatusOutput : RichTextBox
38 {
39 /// <summary>
40 /// A file that output should be logged to (or null, to disable logging)
41 /// </summary>
42 public string LogFile = null;
43  
44 private GridClient _Client;
45  
46 /// <summary>
47 /// Gets or sets the GridClient associated with this control
48 /// </summary>
49 public GridClient Client
50 {
51 get { return _Client; }
52 set { if (value != null) InitializeClient(value); }
53 }
54  
55 public StatusOutput()
56 {
57 this.ReadOnly = true;
58 this.BackColor = Color.White;
59 }
60  
61 public void LogText(string text, Color color)
62 {
63 if (!this.IsHandleCreated) return;
64  
65 if (this.InvokeRequired)
66 {
67 this.BeginInvoke((MethodInvoker)delegate { LogText(text, color); });
68 }
69 else
70 {
71 this.SelectionStart = this.Text.Length;
72 this.SelectionColor = color;
73 DateTime now = DateTime.Now;
74 string output = String.Format("{0}[{1}:{2}] {3}", Environment.NewLine, now.Hour.ToString().PadLeft(2, '0'), now.Minute.ToString().PadLeft(2, '0'), text);
75 this.SelectedText = output;
76 this.ScrollToCaret();
77  
78 if (LogFile != null)
79 File.AppendAllText(LogFile, output);
80 }
81 }
82  
83 private void InitializeClient(GridClient client)
84 {
85 _Client = client;
86 _Client.Network.SimChanged += Network_OnCurrentSimChanged;
87 _Client.Network.Disconnected += Network_OnDisconnected;
88 _Client.Network.LoginProgress += Network_OnLogin;
89 _Client.Self.AlertMessage += Self_AlertMessage;
90 _Client.Self.MoneyBalanceReply += Self_MoneyBalanceReply;
91 }
92  
93 void Self_AlertMessage(object sender, AlertMessageEventArgs e)
94 {
95 LogText(e.Message, Color.Gray);
96 }
97  
98 void Self_MoneyBalanceReply(object sender, MoneyBalanceReplyEventArgs e)
99 {
100 if (e.Description != String.Empty) LogText(e.Description, Color.Green);
101 LogText("Balance: L$" + e.Balance, Color.Green);
102 }
103  
104 void Network_OnCurrentSimChanged(object sender, SimChangedEventArgs e)
105 {
106 if (Client.Network.CurrentSim != null)
107 {
108 LogText("Entered region \"" + Client.Network.CurrentSim.Name + "\".", Color.Black);
109 }
110 }
111  
112 void Network_OnDisconnected(object sender, DisconnectedEventArgs e)
113 {
114 LogText("Disconnected" + (!String.IsNullOrEmpty(e.Message) ? ": " + e.Message : "."), Color.Black);
115 }
116  
117 void Network_OnLogin(object sender, LoginProgressEventArgs e)
118 {
119 if (e.Status == LoginStatus.Failed) LogText("Login failed: " + e.Message, Color.Red);
120 else if (e.Status != LoginStatus.Success) LogText(e.Message, Color.Black);
121 }
122 }
123 }