LIBOMV-344 Added LocalChat control to OpenMetaverse.GUI and made other minor GUI class changes for consistency

git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@2051 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
2008-08-02 08:01:56 +00:00
parent 5c766c2bf5
commit 1d896c1fc9
4 changed files with 133 additions and 9 deletions

View File

@@ -82,6 +82,14 @@ namespace OpenMetaverse.GUI
else this.Items.Clear();
}
private void InitializeClient(GridClient client)
{
_Client = client;
_Client.Network.OnCurrentSimChanged += new NetworkManager.CurrentSimChangedCallback(Network_OnCurrentSimChanged);
_Client.Objects.OnNewAvatar += new ObjectManager.NewAvatarCallback(Objects_OnNewAvatar);
_Client.Objects.OnObjectKilled += new ObjectManager.KillObjectCallback(Objects_OnObjectKilled);
}
private void UpdateAvatar(Avatar avatar)
{
if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { UpdateAvatar(avatar); });
@@ -125,14 +133,6 @@ namespace OpenMetaverse.GUI
}
}
private void InitializeClient(GridClient client)
{
_Client = client;
_Client.Network.OnCurrentSimChanged += new NetworkManager.CurrentSimChangedCallback(Network_OnCurrentSimChanged);
_Client.Objects.OnNewAvatar += new ObjectManager.NewAvatarCallback(Objects_OnNewAvatar);
_Client.Objects.OnObjectKilled += new ObjectManager.KillObjectCallback(Objects_OnObjectKilled);
}
private void AvatarList_DoubleClick(object sender, EventArgs e)
{
ListView list = (ListView)sender;

View File

@@ -24,7 +24,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
using OpenMetaverse;
using System.Collections.Generic;
using System.Windows.Forms;

View File

@@ -0,0 +1,121 @@
/*
* Copyright (c) 2007-2008, openmetaverse.org
* All rights reserved.
*
* - Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Neither the name of the openmetaverse.org nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace OpenMetaverse.GUI
{
public class LocalChat : Panel
{
private GridClient _Client;
private RichTextBox _rtfOutput = new RichTextBox();
private TextBox _txtInput = new TextBox();
/// <summary>
/// Gets or sets the GridClient associated with this control
/// </summary>
public GridClient Client
{
get { return _Client; }
set { if (value != null) InitializeClient(value); }
}
/// <summary>
/// Panel control for an unspecified client's local chat interaction
/// </summary>
public LocalChat()
{
_rtfOutput.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
_rtfOutput.Width = this.Width;
_rtfOutput.Height = this.Height - _txtInput.Height;
_rtfOutput.Top = 0;
_rtfOutput.Left = 0;
_txtInput.Dock = DockStyle.Bottom;
_txtInput.KeyDown += new KeyEventHandler(_txtInput_KeyDown);
this.Controls.AddRange(new Control[]{ _rtfOutput, _txtInput });
}
/// <summary>
/// Panel control for the specified client's local chat interaction
/// </summary>
public LocalChat(GridClient client)
{
_Client = client;
}
private void InitializeClient(GridClient client)
{
_Client = client;
_Client.Self.OnChat += new AgentManager.ChatCallback(Self_OnChat);
}
public void LogChat(string name, ChatType type, string text, Color color)
{
if (this.InvokeRequired)
{
this.BeginInvoke((MethodInvoker)delegate { LogChat(name, type, text, color); });
}
else
{
_rtfOutput.SelectionStart = _rtfOutput.Text.Length;
_rtfOutput.SelectionColor = color;
DateTime now = DateTime.Now;
string volume;
if (type == ChatType.Shout) volume = " shouts";
else if (type == ChatType.Whisper) volume = " whispers";
else volume = string.Empty;
_rtfOutput.SelectedText = string.Format("{0}[{1}:{2}] {3}{4}: {5}", Environment.NewLine, now.Hour.ToString().PadLeft(2, '0'), now.Minute.ToString().PadLeft(2, '0'), name, volume, text);
}
}
void Self_OnChat(string message, ChatAudibleLevel audible, ChatType type, ChatSourceType sourceType, string fromName, UUID id, UUID ownerid, Vector3 position)
{
if (audible == ChatAudibleLevel.Fully && type != ChatType.StartTyping && type != ChatType.StopTyping)
{
Color color;
if (sourceType == ChatSourceType.Agent) color = Color.FromKnownColor(KnownColor.ControlText);
else color = Color.FromKnownColor(KnownColor.GrayText);
LogChat(fromName, type, message, color);
}
}
void _txtInput_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && _txtInput.Text != string.Empty)
{
e.SuppressKeyPress = true;
_Client.Self.Chat(_txtInput.Text, 0, e.Control ? ChatType.Shout : ChatType.Normal);
_txtInput.Clear();
}
}
}
}

View File

@@ -30,6 +30,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
@@ -40,6 +41,9 @@
<Compile Include="InventoryTree.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="LocalChat.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>