Open sourced NatiBot
This commit is contained in:
105
SLBot/bot/GUI/controls/AccountList.cs
Normal file
105
SLBot/bot/GUI/controls/AccountList.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : AccountList.cs
|
||||
Version : 1.0.326
|
||||
Author(s) : Natalia Portillo
|
||||
|
||||
Component : NatiBot
|
||||
|
||||
Revision : r326
|
||||
Last change by : Natalia Portillo
|
||||
Date : 2010/01/01
|
||||
|
||||
--[ License ] --------------------------------------------------------------
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Copyright (C) 2008-2014 Claunia.com
|
||||
****************************************************************************/
|
||||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace bot.GUI
|
||||
{
|
||||
/// <summary>
|
||||
/// ListView GUI component for viewing a client's nearby avatars list
|
||||
/// </summary>
|
||||
public class AccountList : ListView
|
||||
{
|
||||
private ListColumnSorterNormal _ColumnSorter = new ListColumnSorterNormal();
|
||||
|
||||
/// <summary>
|
||||
/// TreeView control for an unspecified client's nearby avatar list
|
||||
/// </summary>
|
||||
public AccountList()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
|
||||
|
||||
ColumnHeader header1 = this.Columns.Add(bot.Localization.clResourceManager.getText("frmMain.ClName"));
|
||||
header1.Width = 170;
|
||||
|
||||
ColumnHeader header2 = this.Columns.Add(bot.Localization.clResourceManager.getText("frmMain.ClStatus"));
|
||||
header2.Width = 118;
|
||||
|
||||
ColumnHeader header3 = this.Columns.Add(bot.Localization.clResourceManager.getText("frmMain.clMaster"));
|
||||
header3.Width = 170;
|
||||
|
||||
ColumnHeader header4 = this.Columns.Add(bot.Localization.clResourceManager.getText("frmMain.clLocation"));
|
||||
header4.Width = 188;
|
||||
|
||||
ColumnHeader header5 = this.Columns.Add(bot.Localization.clResourceManager.getText("frmMain.clMoney"));
|
||||
header5.Width = 78;
|
||||
|
||||
this.MultiSelect = false;
|
||||
this.SelectedIndexChanged += new EventHandler(AvatarList_SelectedIndexChanged);
|
||||
|
||||
_ColumnSorter.SortColumn = 1;
|
||||
this.Sorting = SortOrder.Ascending;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
|
||||
this.DoubleBuffered = true;
|
||||
this.FullRowSelect = true;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
this.View = View.Details;
|
||||
this.ColumnClick += new ColumnClickEventHandler(AvatarList_ColumnClick);
|
||||
this.DoubleClick += new EventHandler(AvatarList_DoubleClick);
|
||||
}
|
||||
|
||||
void AvatarList_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AvatarList_ColumnClick(object sender, ColumnClickEventArgs e)
|
||||
{
|
||||
_ColumnSorter.SortColumn = e.Column;
|
||||
if ((_ColumnSorter.Ascending = (this.Sorting == SortOrder.Ascending))) this.Sorting = SortOrder.Descending;
|
||||
else this.Sorting = SortOrder.Ascending;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
}
|
||||
|
||||
void AvatarList_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
815
SLBot/bot/GUI/controls/AvatarList.cs
Normal file
815
SLBot/bot/GUI/controls/AvatarList.cs
Normal file
@@ -0,0 +1,815 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : AvatarList.cs
|
||||
Version : 1.0.326
|
||||
Author(s) : Natalia Portillo
|
||||
|
||||
Component : NatiBot
|
||||
|
||||
Revision : r326
|
||||
Last change by : Natalia Portillo
|
||||
Date : 2010/01/01
|
||||
|
||||
--[ License ] --------------------------------------------------------------
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Copyright (C) 2008-2014 Claunia.com
|
||||
Copyright (C) 2007-2009 openmetaverse.org
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
// Copied from OpenMetaverse.GUI
|
||||
/*
|
||||
* Copyright (c) 2007-2009, 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 OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace bot.GUI
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// ListView GUI component for viewing a client's nearby avatars list
|
||||
/// </summary>
|
||||
public class AvatarList : ListView
|
||||
{
|
||||
private SecondLifeBot _Client;
|
||||
private ListColumnSorter _ColumnSorter = new ListColumnSorter();
|
||||
private TrackedAvatar _SelectedAvatar;
|
||||
|
||||
private frmProfile _frmProfile;
|
||||
|
||||
private DoubleDictionary<uint, UUID, TrackedAvatar> _TrackedAvatars = new DoubleDictionary<uint, UUID, TrackedAvatar>();
|
||||
private Dictionary<UUID, TrackedAvatar> _UntrackedAvatars = new Dictionary<UUID, TrackedAvatar>();
|
||||
|
||||
public delegate void AvatarCallback(TrackedAvatar trackedAvatar);
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the user double clicks on an avatar in the list
|
||||
/// </summary>
|
||||
public event AvatarCallback OnAvatarDoubleClick;
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when a new avatar is added to the list
|
||||
/// </summary>
|
||||
public event AvatarCallback OnAvatarAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when an avatar is removed from the list
|
||||
/// </summary>
|
||||
public event AvatarCallback OnAvatarRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GridClient associated with this control
|
||||
/// </summary>
|
||||
public SecondLifeBot Client
|
||||
{
|
||||
get { return _Client; }
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
InitializeClient(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current selected avatar in the tracked avatars list
|
||||
/// </summary>
|
||||
public TrackedAvatar SelectedAvatar
|
||||
{
|
||||
get { return _SelectedAvatar; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TreeView control for an unspecified client's nearby avatar list
|
||||
/// </summary>
|
||||
public AvatarList()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
|
||||
|
||||
ColumnHeader header1 = this.Columns.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Name"));
|
||||
header1.Width = 192;
|
||||
|
||||
ColumnHeader header2 = this.Columns.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Distance"));
|
||||
header2.Width = 58;
|
||||
|
||||
ColumnHeader header3 = this.Columns.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Viewer"));
|
||||
header3.Width = 120;
|
||||
|
||||
ColumnHeader header4 = this.Columns.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Position"));
|
||||
header4.Width = 116;
|
||||
|
||||
this.MultiSelect = false;
|
||||
this.SelectedIndexChanged += new EventHandler(AvatarList_SelectedIndexChanged);
|
||||
|
||||
_ColumnSorter.SortColumn = 1;
|
||||
this.Sorting = SortOrder.Ascending;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
|
||||
EventHandler clickHandler = new EventHandler(defaultMenuItem_Click);
|
||||
this.ContextMenu = new ContextMenu();
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.CopyID"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.ShowProfile"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferTP"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.TPTo"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WalkTo"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.SendMessage"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.ListAttachs"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.DumpAttachs"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.DumpOutfit"), clickHandler);
|
||||
this.ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferFriendship"), clickHandler);
|
||||
|
||||
this.DoubleBuffered = true;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
this.View = View.Details;
|
||||
this.ColumnClick += new ColumnClickEventHandler(AvatarList_ColumnClick);
|
||||
this.DoubleClick += new EventHandler(AvatarList_DoubleClick);
|
||||
}
|
||||
|
||||
void AvatarList_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
lock (_TrackedAvatars)
|
||||
{
|
||||
lock (_UntrackedAvatars)
|
||||
{
|
||||
if (this.SelectedItems.Count > 0)
|
||||
{
|
||||
UUID selectedID = new UUID(this.SelectedItems[0].Name);
|
||||
TrackedAvatar selectedAV;
|
||||
if (!_TrackedAvatars.TryGetValue(selectedID, out selectedAV) && !_UntrackedAvatars.TryGetValue(selectedID, out selectedAV))
|
||||
selectedAV = null;
|
||||
|
||||
_SelectedAvatar = selectedAV;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe method for clearing the TreeView control
|
||||
/// </summary>
|
||||
public void ClearItems()
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
ClearItems();
|
||||
});
|
||||
else
|
||||
{
|
||||
if (this.Handle != IntPtr.Zero)
|
||||
this.Items.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public TrackedAvatar GetAvatar(UUID avatarID)
|
||||
{
|
||||
TrackedAvatar av;
|
||||
_TrackedAvatars.TryGetValue(avatarID, out av);
|
||||
return av;
|
||||
}
|
||||
|
||||
private void InitializeClient(SecondLifeBot client)
|
||||
{
|
||||
_Client = client;
|
||||
_Client.Avatars.AvatarAppearance += Avatars_OnAvatarAppearance;
|
||||
_Client.Avatars.UUIDNameReply += new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
|
||||
_Client.Grid.CoarseLocationUpdate += Grid_CoarseLocationUpdate;
|
||||
_Client.Network.SimChanged += Network_OnCurrentSimChanged;
|
||||
_Client.Objects.AvatarUpdate += Objects_OnNewAvatar;
|
||||
_Client.Objects.TerseObjectUpdate += Objects_OnObjectUpdated;
|
||||
}
|
||||
|
||||
void Avatars_UUIDNameReply(object sender, UUIDNameReplyEventArgs e)
|
||||
{
|
||||
lock (_UntrackedAvatars)
|
||||
{
|
||||
foreach (KeyValuePair<UUID, string> name in e.Names)
|
||||
{
|
||||
TrackedAvatar trackedAvatar;
|
||||
if (_UntrackedAvatars.TryGetValue(name.Key, out trackedAvatar))
|
||||
{
|
||||
trackedAvatar.Name = name.Value;
|
||||
|
||||
if (OnAvatarAdded != null && trackedAvatar.ListViewItem.Text == bot.Localization.clResourceManager.getText("Controls.Loading"))
|
||||
{
|
||||
try
|
||||
{
|
||||
OnAvatarAdded(trackedAvatar);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex);
|
||||
}
|
||||
}
|
||||
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
trackedAvatar.ListViewItem.Text = name.Value;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Grid_CoarseLocationUpdate(object sender, CoarseLocationUpdateEventArgs e)
|
||||
{
|
||||
UpdateCoarseInfo(e.Simulator, e.NewEntries, e.RemovedEntries);
|
||||
}
|
||||
|
||||
public void InitializateAvatars()
|
||||
{
|
||||
lock (Client.Network.Simulators)
|
||||
{
|
||||
for (int i = 0; i < Client.Network.Simulators.Count; i++)
|
||||
{
|
||||
Client.Network.Simulators[i].ObjectsAvatars.ForEach(
|
||||
delegate(Avatar av)
|
||||
{
|
||||
Vector3 coarsePos;
|
||||
if (!Client.Network.Simulators[i].AvatarPositions.TryGetValue(av.ID, out coarsePos))
|
||||
coarsePos = Vector3.Zero;
|
||||
coarsePos.Z = av.Position.Z;
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
AddAvatar(av.ID, av, coarsePos);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAvatar(UUID avatarID, Avatar avatar, Vector3 coarsePosition)
|
||||
{
|
||||
if (!this.IsHandleCreated)
|
||||
return;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
AddAvatar(avatar.ID, avatar, coarsePosition);
|
||||
});
|
||||
else
|
||||
{
|
||||
TrackedAvatar trackedAvatar = new TrackedAvatar();
|
||||
trackedAvatar.CoarseLocation = coarsePosition;
|
||||
trackedAvatar.ID = avatarID;
|
||||
trackedAvatar.ListViewItem = this.Items.Add(avatarID.ToString(), trackedAvatar.Name, null);
|
||||
trackedAvatar.ListViewItem.Name = avatarID.ToString();
|
||||
|
||||
string strDist = avatarID == _Client.Self.AgentID ? "--" : (int)Vector3.Distance(_Client.Self.SimPosition, coarsePosition) + "m";
|
||||
trackedAvatar.ListViewItem.SubItems.Add(strDist);
|
||||
|
||||
if (avatar != null)
|
||||
{
|
||||
string ViewerName;
|
||||
Dictionary<UUID, string> ClientNames = ClientTags.ToDictionary();
|
||||
|
||||
if (avatar.Textures == null)
|
||||
ViewerName = bot.Localization.clResourceManager.getText("Viewer.Unknown");
|
||||
else
|
||||
{
|
||||
if (avatar.Textures.FaceTextures[(int)AvatarTextureIndex.HeadBodypaint] != null)
|
||||
{
|
||||
if (!ClientNames.TryGetValue(avatar.Textures.FaceTextures[(int)AvatarTextureIndex.HeadBodypaint].TextureID, out ViewerName))
|
||||
ViewerName = bot.Localization.clResourceManager.getText("Viewer.Unidentified");
|
||||
}
|
||||
else
|
||||
ViewerName = bot.Localization.clResourceManager.getText("Viewer.Unknown");
|
||||
}
|
||||
|
||||
trackedAvatar.ListViewItem.SubItems.Add(ViewerName);
|
||||
}
|
||||
else
|
||||
{
|
||||
trackedAvatar.ListViewItem.SubItems.Add(bot.Localization.clResourceManager.getText("Viewer.Unknown"));
|
||||
}
|
||||
|
||||
trackedAvatar.ListViewItem.SubItems.Add(coarsePosition.ToString());
|
||||
|
||||
if (avatar != null)
|
||||
{
|
||||
trackedAvatar.Name = avatar.Name;
|
||||
trackedAvatar.ListViewItem.Text = avatar.Name;
|
||||
|
||||
lock (_TrackedAvatars)
|
||||
{
|
||||
if (_TrackedAvatars.ContainsKey(avatarID))
|
||||
_TrackedAvatars.Remove(avatarID);
|
||||
|
||||
_TrackedAvatars.Add(avatar.LocalID, avatarID, trackedAvatar);
|
||||
}
|
||||
|
||||
if (OnAvatarAdded != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnAvatarAdded(trackedAvatar);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lock (_UntrackedAvatars)
|
||||
{
|
||||
_UntrackedAvatars.Add(avatarID, trackedAvatar);
|
||||
|
||||
trackedAvatar.ListViewItem.ForeColor = Color.FromKnownColor(KnownColor.GrayText);
|
||||
|
||||
if (avatarID == _Client.Self.AgentID)
|
||||
{
|
||||
trackedAvatar.Name = _Client.Self.Name;
|
||||
trackedAvatar.ListViewItem.Text = _Client.Self.Name;
|
||||
}
|
||||
else if (_Client.Network.Connected)
|
||||
Client.Avatars.RequestAvatarName(avatarID);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveAvatar(UUID id)
|
||||
{
|
||||
if (!this.IsHandleCreated)
|
||||
return;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
RemoveAvatar(id);
|
||||
});
|
||||
else
|
||||
{
|
||||
TrackedAvatar trackedAvatar;
|
||||
|
||||
lock (_TrackedAvatars)
|
||||
{
|
||||
if (_TrackedAvatars.TryGetValue(id, out trackedAvatar))
|
||||
{
|
||||
this.Items.Remove(trackedAvatar.ListViewItem);
|
||||
_TrackedAvatars.Remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
lock (_UntrackedAvatars)
|
||||
{
|
||||
if (_UntrackedAvatars.TryGetValue(id, out trackedAvatar))
|
||||
{
|
||||
this.Items.Remove(trackedAvatar.ListViewItem);
|
||||
_UntrackedAvatars.Remove(trackedAvatar.ID);
|
||||
}
|
||||
}
|
||||
|
||||
if (OnAvatarRemoved != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
OnAvatarRemoved(trackedAvatar);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAvatar(Avatar avatar)
|
||||
{
|
||||
if (!this.IsHandleCreated)
|
||||
return;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
UpdateAvatar(avatar);
|
||||
});
|
||||
else
|
||||
{
|
||||
TrackedAvatar trackedAvatar;
|
||||
bool found;
|
||||
|
||||
lock (_UntrackedAvatars)
|
||||
found = _UntrackedAvatars.TryGetValue(avatar.ID, out trackedAvatar);
|
||||
|
||||
if (found)
|
||||
{
|
||||
trackedAvatar.Name = avatar.Name;
|
||||
trackedAvatar.ListViewItem.Text = avatar.Name;
|
||||
trackedAvatar.ListViewItem.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
|
||||
|
||||
lock (_TrackedAvatars)
|
||||
_TrackedAvatars.Add(avatar.LocalID, avatar.ID, trackedAvatar);
|
||||
_UntrackedAvatars.Remove(avatar.ID);
|
||||
}
|
||||
|
||||
lock (_TrackedAvatars)
|
||||
found = _TrackedAvatars.TryGetValue(avatar.ID, out trackedAvatar);
|
||||
|
||||
if (found)
|
||||
{
|
||||
string strDist = avatar.ID == _Client.Self.AgentID ? "--" : (int)Vector3.Distance(_Client.Self.SimPosition, avatar.Position) + "m";
|
||||
trackedAvatar.ListViewItem.SubItems[1].Text = strDist;
|
||||
trackedAvatar.ListViewItem.SubItems[3].Text = avatar.Position.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
AddAvatar(avatar.ID, avatar, Vector3.Zero);
|
||||
}
|
||||
|
||||
this.Sort();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCoarseInfo(Simulator sim, List<UUID> newEntries, List<UUID> removedEntries)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
UpdateCoarseInfo(sim, newEntries, removedEntries);
|
||||
});
|
||||
else
|
||||
{
|
||||
if (sim == null)
|
||||
return;
|
||||
|
||||
if (removedEntries != null)
|
||||
{
|
||||
for (int i = 0; i < removedEntries.Count; i++)
|
||||
RemoveAvatar(removedEntries[i]);
|
||||
}
|
||||
|
||||
if (newEntries != null)
|
||||
{
|
||||
for (int i = 0; i < newEntries.Count; i++)
|
||||
{
|
||||
int index = this.Items.IndexOfKey(newEntries[i].ToString());
|
||||
if (index == -1)
|
||||
{
|
||||
Vector3 coarsePos;
|
||||
if (!sim.AvatarPositions.TryGetValue(newEntries[i], out coarsePos))
|
||||
continue;
|
||||
|
||||
AddAvatar(newEntries[i], null, coarsePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void defaultMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MenuItem menuItem = (MenuItem)sender;
|
||||
|
||||
int MenuIndex;
|
||||
|
||||
if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.CopyID"))
|
||||
MenuIndex = 1;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.ShowProfile"))
|
||||
MenuIndex = 2;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferTP"))
|
||||
MenuIndex = 3;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.TPTo"))
|
||||
MenuIndex = 4;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WalkTo"))
|
||||
MenuIndex = 5;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.SendMessage"))
|
||||
MenuIndex = 6;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferFriendship"))
|
||||
MenuIndex = 7;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.ListAttachs"))
|
||||
MenuIndex = 8;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.DumpAttachs"))
|
||||
MenuIndex = 9;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.DumpOutfit"))
|
||||
MenuIndex = 10;
|
||||
else
|
||||
return;
|
||||
|
||||
switch (MenuIndex)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
Clipboard.SetText(_SelectedAvatar.ID.ToString().ToUpper(), TextDataFormat.Text);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
_frmProfile = new frmProfile(_Client, _SelectedAvatar.ID);
|
||||
_frmProfile.RefreshInfo();
|
||||
_frmProfile.Show();
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
frmDialog _frmDialog = new frmDialog(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferTP.DialogTitle"),
|
||||
String.Format(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferTP.DialogLabel"), _SelectedAvatar.Name),
|
||||
bot.Localization.clResourceManager.getText("Commands.RequestTeleport.Message"));
|
||||
|
||||
DialogResult _result = _frmDialog.ShowDialog();
|
||||
if (_result == DialogResult.OK)
|
||||
{
|
||||
this.Client.Self.SendTeleportLure(_SelectedAvatar.ID, _frmDialog._output);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
Vector3 pos;
|
||||
if (Client.Network.CurrentSim.AvatarPositions.TryGetValue(_SelectedAvatar.ID, out pos))
|
||||
Client.Self.Teleport(Client.Network.CurrentSim.Name, pos);
|
||||
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
Vector3 pos;
|
||||
if (Client.Network.CurrentSim.AvatarPositions.TryGetValue(_SelectedAvatar.ID, out pos))
|
||||
Client.Self.AutoPilotLocal((int)pos.X, (int)pos.Y, pos.Z);
|
||||
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
frmDialog _frmDialog = new frmDialog(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.SendIM.DialogTitle"),
|
||||
String.Format(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.SendIM.DialogLabel"), _SelectedAvatar.Name),
|
||||
"");
|
||||
|
||||
DialogResult _result = _frmDialog.ShowDialog();
|
||||
if (_result == DialogResult.OK)
|
||||
{
|
||||
this.Client.Self.InstantMessage(_SelectedAvatar.ID, _frmDialog._output);
|
||||
|
||||
bot.Chat.structInstantMessage sim;
|
||||
InstantMessage im = new InstantMessage();
|
||||
|
||||
im.Message = _frmDialog._output;
|
||||
im.FromAgentID = _SelectedAvatar.ID;
|
||||
im.FromAgentName = _SelectedAvatar.Name;
|
||||
im.Dialog = InstantMessageDialog.MessageFromAgent;
|
||||
|
||||
sim.client = this._Client;
|
||||
sim.isReceived = false;
|
||||
sim.message = im;
|
||||
sim.simulator = this._Client.Network.CurrentSim;
|
||||
sim.timestamp = DateTime.Now;
|
||||
|
||||
bot.Chat.receivedIM(sim);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
if (_Client.Friends.FriendList.ContainsKey(_SelectedAvatar.ID))
|
||||
{
|
||||
MessageBox.Show(String.Format(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferFriend.AlreadyDialogLabel"), _SelectedAvatar.Name),
|
||||
bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferFriend.AlreadyDialogTitle"), MessageBoxButtons.OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
frmDialog _frmDialog = new frmDialog(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferFriend.DialogTitle"),
|
||||
String.Format(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferFriend.DialogLabel"), _SelectedAvatar.Name),
|
||||
bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.OfferFriend.Message"));
|
||||
|
||||
DialogResult _result = _frmDialog.ShowDialog();
|
||||
if (_result == DialogResult.OK)
|
||||
{
|
||||
this.Client.Friends.OfferFriendship(_SelectedAvatar.ID, _frmDialog._output);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
string _result = _Client.DoCommandReturn("attachmentsuuid " + _SelectedAvatar.ID.ToString(),
|
||||
_Client.MasterKey, true);
|
||||
frmResult _frmResult = new frmResult(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.ListAttachsResultLabel"),
|
||||
String.Format(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.ListAttachsResultTitle"), SelectedAvatar.Name),
|
||||
_result);
|
||||
|
||||
_frmResult.ShowDialog();
|
||||
break;
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
DialogResult _dresult = MessageBox.Show(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WarningLine1") + System.Environment.NewLine +
|
||||
bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WarningLine2") + System.Environment.NewLine +
|
||||
bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WarningLine3"), bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WarningLine3"),
|
||||
MessageBoxButtons.YesNo);
|
||||
if (_dresult == DialogResult.Yes)
|
||||
{
|
||||
string _result = _Client.DoCommandReturn("dumpattachments " + _SelectedAvatar.ID.ToString(),
|
||||
_Client.MasterKey, true);
|
||||
frmResult _frmResult = new frmResult(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.DumpAttachsDumped"), "", _result);
|
||||
|
||||
_frmResult.ShowDialog();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 10:
|
||||
{
|
||||
DialogResult _dresult = MessageBox.Show(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WarningLine1") + System.Environment.NewLine +
|
||||
bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WarningLine2") + System.Environment.NewLine +
|
||||
bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WarningLine3"), bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.WarningLine3"),
|
||||
MessageBoxButtons.YesNo);
|
||||
if (_dresult == DialogResult.Yes)
|
||||
{
|
||||
string _result = _Client.DoCommandReturn("dumpoutfit " + _SelectedAvatar.ID.ToString(),
|
||||
_Client.MasterKey, true);
|
||||
frmResult _frmResult = new frmResult(bot.Localization.clResourceManager.getText("Controls.AvatarList.Menu.DumpOutfitDumped"), "", _result);
|
||||
|
||||
_frmResult.ShowDialog();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarList_ColumnClick(object sender, ColumnClickEventArgs e)
|
||||
{
|
||||
_ColumnSorter.SortColumn = e.Column;
|
||||
if ((_ColumnSorter.Ascending = (this.Sorting == SortOrder.Ascending)))
|
||||
this.Sorting = SortOrder.Descending;
|
||||
else
|
||||
this.Sorting = SortOrder.Ascending;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
}
|
||||
|
||||
void AvatarList_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
if (OnAvatarDoubleClick != null)
|
||||
{
|
||||
ListView list = (ListView)sender;
|
||||
if (list.SelectedItems.Count > 0)
|
||||
{
|
||||
TrackedAvatar trackedAvatar;
|
||||
if (!_TrackedAvatars.TryGetValue(new UUID(list.SelectedItems[0].Name), out trackedAvatar)
|
||||
&& !_UntrackedAvatars.TryGetValue(new UUID(list.SelectedItems[0].Name), out trackedAvatar))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
OnAvatarDoubleClick(trackedAvatar);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Avatars_OnAvatarAppearance(object sender, AvatarAppearanceEventArgs e)
|
||||
{
|
||||
TrackedAvatar trackedAvatar;
|
||||
bool foundAvatar;
|
||||
|
||||
lock (_TrackedAvatars)
|
||||
foundAvatar = _TrackedAvatars.TryGetValue(e.AvatarID, out trackedAvatar);
|
||||
|
||||
if (e.VisualParams.Count > 31)
|
||||
{
|
||||
if (foundAvatar)
|
||||
{
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
byte param = e.VisualParams[31];
|
||||
if (param > 0)
|
||||
trackedAvatar.ListViewItem.ForeColor = Color.Blue;
|
||||
else
|
||||
trackedAvatar.ListViewItem.ForeColor = Color.Magenta;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (foundAvatar)
|
||||
{
|
||||
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
string ViewerName;
|
||||
Dictionary<UUID, string> ClientNames = ClientTags.ToDictionary();
|
||||
|
||||
if (e.FaceTextures == null)
|
||||
ViewerName = bot.Localization.clResourceManager.getText("Viewer.Unknown");
|
||||
else
|
||||
{
|
||||
if (e.FaceTextures[(int)AvatarTextureIndex.HeadBodypaint] != null)
|
||||
{
|
||||
if (!ClientNames.TryGetValue(e.FaceTextures[(int)AvatarTextureIndex.HeadBodypaint].TextureID, out ViewerName))
|
||||
ViewerName = bot.Localization.clResourceManager.getText("Viewer.Unidentified");
|
||||
}
|
||||
else
|
||||
ViewerName = bot.Localization.clResourceManager.getText("Viewer.Unidentified");
|
||||
}
|
||||
|
||||
trackedAvatar.ListViewItem.SubItems[2].Text = ViewerName;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Network_OnCurrentSimChanged(object sender, SimChangedEventArgs e)
|
||||
{
|
||||
lock (_TrackedAvatars)
|
||||
_TrackedAvatars.Clear();
|
||||
|
||||
lock (_UntrackedAvatars)
|
||||
_UntrackedAvatars.Clear();
|
||||
|
||||
ClearItems();
|
||||
}
|
||||
|
||||
void Objects_OnNewAvatar(object sender, AvatarUpdateEventArgs e)
|
||||
{
|
||||
UpdateAvatar(e.Avatar);
|
||||
}
|
||||
|
||||
void Objects_OnObjectUpdated(object sender, TerseObjectUpdateEventArgs e)
|
||||
{
|
||||
bool found;
|
||||
lock (_TrackedAvatars)
|
||||
found = _TrackedAvatars.ContainsKey(e.Update.LocalID);
|
||||
|
||||
if (found)
|
||||
{
|
||||
Avatar av;
|
||||
if (e.Simulator.ObjectsAvatars.TryGetValue(e.Update.LocalID, out av))
|
||||
UpdateAvatar(av);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains any available information for an avatar in the simulator.
|
||||
/// A null value for .Avatar indicates coarse data for an avatar outside of visible range.
|
||||
/// </summary>
|
||||
public class TrackedAvatar
|
||||
{
|
||||
/// <summary>Assigned if the avatar is within visible range</summary>
|
||||
public Avatar Avatar = null;
|
||||
|
||||
/// <summary>Last known coarse location of avatar</summary>
|
||||
public Vector3 CoarseLocation;
|
||||
|
||||
/// <summary>Avatar ID</summary>
|
||||
public UUID ID;
|
||||
|
||||
/// <summary>ListViewItem associated with this avatar</summary>
|
||||
public ListViewItem ListViewItem;
|
||||
|
||||
/// <summary>Populated by RequestAvatarName if avatar is not visible</summary>
|
||||
public string Name = bot.Localization.clResourceManager.getText("Controls.Loading");
|
||||
}
|
||||
|
||||
}
|
||||
183
SLBot/bot/GUI/controls/GroupList.cs
Normal file
183
SLBot/bot/GUI/controls/GroupList.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : GroupList.cs
|
||||
Version : 1.0.326
|
||||
Author(s) : Natalia Portillo
|
||||
|
||||
Component : NatiBot
|
||||
|
||||
Revision : r326
|
||||
Last change by : Natalia Portillo
|
||||
Date : 2010/01/01
|
||||
|
||||
--[ License ] --------------------------------------------------------------
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Copyright (C) 2008-2014 Claunia.com
|
||||
Copyright (C) 2007-2009 openmetaverse.org
|
||||
****************************************************************************/
|
||||
|
||||
// Copied from OpenMetaverse
|
||||
/*
|
||||
* Copyright (c) 2007-2009, 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace bot.GUI
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// ListView GUI component for viewing a client's group list
|
||||
/// </summary>
|
||||
public class GroupList : ListView
|
||||
{
|
||||
private GridClient _Client;
|
||||
private ListColumnSorterNormal _ColumnSorter = new ListColumnSorterNormal();
|
||||
|
||||
public delegate void GroupDoubleClickCallback(Group group);
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when the user double clicks on a group in the list
|
||||
/// </summary>
|
||||
public event GroupDoubleClickCallback OnGroupDoubleClick;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GridClient associated with this control
|
||||
/// </summary>
|
||||
public GridClient Client
|
||||
{
|
||||
get { return _Client; }
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
InitializeClient(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TreeView control for an unspecified client's group list
|
||||
/// </summary>
|
||||
public GroupList()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
|
||||
|
||||
ColumnHeader header1 = this.Columns.Add(bot.Localization.clResourceManager.getText("Controls.GroupList.Column"));
|
||||
header1.Width = this.Width + 20;
|
||||
|
||||
this.DoubleBuffered = true;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
this.View = View.Details;
|
||||
|
||||
this.ColumnClick += new ColumnClickEventHandler(GroupList_ColumnClick);
|
||||
this.DoubleClick += new System.EventHandler(GroupList_DoubleClick);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TreeView control for the specified client's group list
|
||||
/// </summary>
|
||||
public GroupList(GridClient client) : this()
|
||||
{
|
||||
InitializeClient(client);
|
||||
}
|
||||
|
||||
private void InitializeClient(GridClient client)
|
||||
{
|
||||
_Client = client;
|
||||
_Client.Groups.CurrentGroups += Groups_CurrentGroups;
|
||||
_Client.Groups.RequestCurrentGroups();
|
||||
}
|
||||
|
||||
void Groups_CurrentGroups(object sender, CurrentGroupsEventArgs e)
|
||||
{
|
||||
RefreshGroups(e.Groups);
|
||||
}
|
||||
|
||||
private void RefreshGroups(Dictionary<UUID, Group> groups)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
RefreshGroups(groups);
|
||||
});
|
||||
else
|
||||
{
|
||||
this.Items.Clear();
|
||||
foreach (KeyValuePair<UUID, Group> group in groups)
|
||||
this.Items.Add(group.Key.ToString(), group.Value.Name, null).Tag = group.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private void GroupList_ColumnClick(object sender, ColumnClickEventArgs e)
|
||||
{
|
||||
if ((_ColumnSorter.Ascending = (this.Sorting == SortOrder.Ascending)))
|
||||
this.Sorting = SortOrder.Descending;
|
||||
else
|
||||
this.Sorting = SortOrder.Ascending;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
}
|
||||
|
||||
private void GroupList_DoubleClick(object sender, System.EventArgs e)
|
||||
{
|
||||
if (OnGroupDoubleClick != null)
|
||||
{
|
||||
ListView list = (ListView)sender;
|
||||
if (list.SelectedItems.Count > 0 && list.SelectedItems[0].Tag is Group)
|
||||
{
|
||||
Group group = (Group)list.SelectedItems[0].Tag;
|
||||
try
|
||||
{
|
||||
OnGroupDoubleClick(group);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
338
SLBot/bot/GUI/controls/InventoryTree.cs
Normal file
338
SLBot/bot/GUI/controls/InventoryTree.cs
Normal file
@@ -0,0 +1,338 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : InventoryTree.cs
|
||||
Version : 1.0.326
|
||||
Author(s) : Natalia Portillo
|
||||
|
||||
Component : NatiBot
|
||||
|
||||
Revision : r326
|
||||
Last change by : Natalia Portillo
|
||||
Date : 2010/01/01
|
||||
|
||||
--[ License ] --------------------------------------------------------------
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Copyright (C) 2008-2014 Claunia.com
|
||||
Copyright (C) 2007-2009 openmetaverse.org
|
||||
****************************************************************************/
|
||||
|
||||
// Copied from OpenMetaverse.GUI
|
||||
/*
|
||||
* Copyright (c) 2007-2009, 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;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace bot.GUI
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// TreeView GUI component for browsing a client's inventory
|
||||
/// </summary>
|
||||
public class InventoryTree : TreeView
|
||||
{
|
||||
private GridClient _Client;
|
||||
private ContextMenu _ContextMenu;
|
||||
private UUID _SelectedItemID;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the context menu associated with this control
|
||||
/// </summary>
|
||||
public ContextMenu Menu
|
||||
{
|
||||
get { return _ContextMenu; }
|
||||
set { _ContextMenu = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GridClient associated with this control
|
||||
/// </summary>
|
||||
public GridClient Client
|
||||
{
|
||||
get { return _Client; }
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
InitializeClient(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TreeView control for an unspecified client's inventory
|
||||
/// </summary>
|
||||
public InventoryTree()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
|
||||
|
||||
EventHandler clickHandler = new EventHandler(defaultMenuItem_Click);
|
||||
_ContextMenu = new ContextMenu();
|
||||
_ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("frmInventory.Menu.CopyID"), clickHandler);
|
||||
_ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("frmInventory.Menu.Delete"), clickHandler);
|
||||
_ContextMenu.MenuItems.Add("-");
|
||||
_ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("frmInventory.Menu.Attach"), clickHandler);
|
||||
_ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("frmInventory.Menu.Detach"), clickHandler);
|
||||
_ContextMenu.MenuItems.Add("-");
|
||||
_ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("frmInventory.Menu.EmptyTrash"), clickHandler);
|
||||
_ContextMenu.MenuItems.Add(bot.Localization.clResourceManager.getText("frmInventory.Menu.EmptyLF"), clickHandler);
|
||||
|
||||
this.NodeMouseClick += new TreeNodeMouseClickEventHandler(InventoryTree_NodeMouseClick);
|
||||
this.BeforeExpand += new TreeViewCancelEventHandler(InventoryTree_BeforeExpand);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TreeView control for the specified client's inventory
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
public InventoryTree(GridClient client) : this()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
|
||||
|
||||
InitializeClient(client);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe method for clearing the TreeView control
|
||||
/// </summary>
|
||||
public void ClearNodes()
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
ClearNodes();
|
||||
});
|
||||
else
|
||||
this.Nodes.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe method for collapsing a TreeNode in the control
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public void CollapseNode(TreeNode node)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
CollapseNode(node);
|
||||
});
|
||||
else if (!node.IsExpanded)
|
||||
node.Collapse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe method for expanding a TreeNode in the control
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public void ExpandNode(TreeNode node)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
ExpandNode(node);
|
||||
});
|
||||
else if (!node.IsExpanded)
|
||||
node.Expand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe method for updating the contents of the specified folder UUID
|
||||
/// </summary>
|
||||
/// <param name="folderID"></param>
|
||||
public void UpdateFolder(UUID folderID)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
UpdateFolder(folderID);
|
||||
});
|
||||
else
|
||||
{
|
||||
TreeNode node = null;
|
||||
TreeNodeCollection children;
|
||||
|
||||
if (folderID != Client.Inventory.Store.RootFolder.UUID)
|
||||
{
|
||||
TreeNode[] found = Nodes.Find(folderID.ToString(), true);
|
||||
if (found.Length > 0)
|
||||
{
|
||||
node = found[0];
|
||||
children = node.Nodes;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log("Received update for unknown TreeView node " + folderID, Helpers.LogLevel.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
children = this.Nodes;
|
||||
|
||||
children.Clear();
|
||||
|
||||
List<InventoryBase> contents = Client.Inventory.Store.GetContents(folderID);
|
||||
if (contents.Count == 0)
|
||||
{
|
||||
TreeNode add = children.Add(null, bot.Localization.clResourceManager.getText("Controls.InventoryList.Empty"));
|
||||
add.ForeColor = Color.FromKnownColor(KnownColor.GrayText);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (InventoryBase inv in contents)
|
||||
{
|
||||
string key = inv.UUID.ToString();
|
||||
|
||||
children.Add(key, inv.Name);
|
||||
if (inv is InventoryFolder)
|
||||
{
|
||||
children[key].Nodes.Add(null, bot.Localization.clResourceManager.getText("Controls.Loading")).ForeColor = Color.FromKnownColor(KnownColor.GrayText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeClient(GridClient client)
|
||||
{
|
||||
_Client = client;
|
||||
_Client.Inventory.FolderUpdated += Inventory_OnFolderUpdated;
|
||||
_Client.Network.LoginProgress += Network_OnLogin;
|
||||
if (Client.Inventory.Store != null)
|
||||
UpdateFolder(Client.Inventory.Store.RootFolder.UUID);
|
||||
}
|
||||
|
||||
private void defaultMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MenuItem menuItem = (MenuItem)sender;
|
||||
|
||||
InventoryItem item = (InventoryItem)Client.Inventory.Store[_SelectedItemID];
|
||||
|
||||
int MenuIndex;
|
||||
|
||||
if (menuItem.Text == bot.Localization.clResourceManager.getText("frmInventory.Menu.CopyID"))
|
||||
MenuIndex = 1;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("frmInventory.Menu.Delete"))
|
||||
MenuIndex = 2;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("frmInventory.Menu.Attach"))
|
||||
MenuIndex = 3;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("frmInventory.Menu.Detach"))
|
||||
MenuIndex = 4;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("frmInventory.Menu.EmptyTrash"))
|
||||
MenuIndex = 5;
|
||||
else if (menuItem.Text == bot.Localization.clResourceManager.getText("frmInventory.Menu.EmptyLF"))
|
||||
MenuIndex = 6;
|
||||
else
|
||||
return;
|
||||
|
||||
switch (MenuIndex)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
Clipboard.SetText(item.AssetUUID.ToString());
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (item.InventoryType == InventoryType.Folder)
|
||||
_Client.Inventory.RemoveFolder(item.UUID);
|
||||
else
|
||||
_Client.Inventory.RemoveItem(item.UUID);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
_Client.Appearance.Attach(item, AttachmentPoint.Default);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
_Client.Appearance.Detach(item);
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
_Client.Inventory.EmptyTrash();
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
_Client.Inventory.EmptyLostAndFound();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Network_OnLogin(object sender, LoginProgressEventArgs e)
|
||||
{
|
||||
/* if (e.Status == LoginStatus.Success)
|
||||
{
|
||||
if (Client.Inventory.Store != null)
|
||||
UpdateFolder(Client.Inventory.Store.RootFolder.UUID);
|
||||
}*/
|
||||
}
|
||||
|
||||
private void Inventory_OnFolderUpdated(object sender, FolderUpdatedEventArgs e)
|
||||
{
|
||||
UpdateFolder(e.FolderID);
|
||||
}
|
||||
|
||||
void InventoryTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
_SelectedItemID = new UUID(e.Node.Name);
|
||||
_ContextMenu.Show(this, e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
private void InventoryTree_BeforeExpand(object sender, TreeViewCancelEventArgs e)
|
||||
{
|
||||
InventoryFolder folder = (InventoryFolder)Client.Inventory.Store[new UUID(e.Node.Name)];
|
||||
Client.Inventory.RequestFolderContents(folder.UUID, _Client.Self.AgentID, true, true, InventorySortOrder.ByDate | InventorySortOrder.FoldersByName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
120
SLBot/bot/GUI/controls/ListColumnSorter.cs
Normal file
120
SLBot/bot/GUI/controls/ListColumnSorter.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : ListColumnSorter.cs
|
||||
Version : 1.0.326
|
||||
Author(s) : Natalia Portillo
|
||||
|
||||
Component : NatiBot
|
||||
|
||||
Revision : r326
|
||||
Last change by : Natalia Portillo
|
||||
Date : 2010/01/01
|
||||
|
||||
--[ License ] --------------------------------------------------------------
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Copyright (C) 2008-2014 Claunia.com
|
||||
Copyright (C) 2007-2009 openmetaverse.org
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2009, 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.Collections;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace bot.GUI
|
||||
{
|
||||
|
||||
class ListColumnSorter : IComparer
|
||||
{
|
||||
public bool Ascending = true;
|
||||
public int SortColumn = 0;
|
||||
|
||||
public int Compare(object a, object b)
|
||||
{
|
||||
ListViewItem itemA = (ListViewItem)a;
|
||||
ListViewItem itemB = (ListViewItem)b;
|
||||
|
||||
if (SortColumn == 1)
|
||||
{
|
||||
int valueA = itemB.SubItems.Count > 1 ? int.Parse(itemA.SubItems[1].Text.Replace("m", "").Replace("--", "0")) : 0;
|
||||
int valueB = itemB.SubItems.Count > 1 ? int.Parse(itemB.SubItems[1].Text.Replace("m", "").Replace("--", "0")) : 0;
|
||||
if (Ascending)
|
||||
{
|
||||
if (valueA == valueB)
|
||||
return 0;
|
||||
return valueA < valueB ? -1 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (valueA == valueB)
|
||||
return 0;
|
||||
return valueA < valueB ? 1 : -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Ascending)
|
||||
return string.Compare(itemA.Text, itemB.Text);
|
||||
else
|
||||
return -string.Compare(itemA.Text, itemB.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ListColumnSorterNormal : IComparer
|
||||
{
|
||||
public bool Ascending = true;
|
||||
public int SortColumn = 0;
|
||||
|
||||
public int Compare(object a, object b)
|
||||
{
|
||||
ListViewItem itemA = (ListViewItem)a;
|
||||
ListViewItem itemB = (ListViewItem)b;
|
||||
|
||||
if (Ascending)
|
||||
return string.Compare(itemA.Text, itemB.Text);
|
||||
else
|
||||
return -string.Compare(itemA.Text, itemB.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
554
SLBot/bot/GUI/controls/ObjectList.cs
Normal file
554
SLBot/bot/GUI/controls/ObjectList.cs
Normal file
@@ -0,0 +1,554 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : ObjectList.cs
|
||||
Version : 1.0.326
|
||||
Author(s) : Natalia Portillo
|
||||
|
||||
Component : NatiBot
|
||||
|
||||
Revision : r326
|
||||
Last change by : Natalia Portillo
|
||||
Date : 2010/01/01
|
||||
|
||||
--[ License ] --------------------------------------------------------------
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Copyright (C) 2008-2014 Claunia.com
|
||||
Portions copyright (C) 2007-2009 openmetaverse.org
|
||||
****************************************************************************/
|
||||
|
||||
// Derived from AvatarList.cs
|
||||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace bot.GUI
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// ListView GUI component for viewing a client's nearby avatars list
|
||||
/// </summary>
|
||||
public class ObjectList : ListView
|
||||
{
|
||||
private SecondLifeBot _Client;
|
||||
private ListColumnSorterNormal _ColumnSorter = new ListColumnSorterNormal();
|
||||
private TrackedObject _SelectedObject;
|
||||
|
||||
private Dictionary<UUID, TrackedObject> _TrackedObjects = new Dictionary<UUID, TrackedObject>();
|
||||
private Dictionary<UUID, TrackedObject> _UntrackedObjects = new Dictionary<UUID, TrackedObject>();
|
||||
private Dictionary<uint, UUID> _TrackedIDs = new Dictionary<uint, UUID>();
|
||||
|
||||
public delegate void ObjectCallback(TrackedObject trackedObject);
|
||||
|
||||
public event ObjectCallback OnObjectAdded;
|
||||
public event ObjectCallback OnObjectPropertiesUpdated;
|
||||
public event ObjectCallback OnObjectUpdated;
|
||||
public event ObjectCallback OnObjectRemoved;
|
||||
|
||||
public bool StopRefreshing = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GridClient associated with this control
|
||||
/// </summary>
|
||||
public SecondLifeBot Client
|
||||
{
|
||||
get { return _Client; }
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
InitializeClient(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current selected avatar in the tracked avatars list
|
||||
/// </summary>
|
||||
public TrackedObject SelectedObject
|
||||
{
|
||||
get { return _SelectedObject; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TreeView control for an unspecified client's nearby avatar list
|
||||
/// </summary>
|
||||
public ObjectList()
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
|
||||
|
||||
ColumnHeader header1 = this.Columns.Add(bot.Localization.clResourceManager.getText("Controls.ObjectList.Name"));
|
||||
header1.Width = 192;
|
||||
|
||||
ColumnHeader header2 = this.Columns.Add(bot.Localization.clResourceManager.getText("Controls.ObjectList.Position"));
|
||||
header2.Width = 58;
|
||||
|
||||
ColumnHeader header3 = this.Columns.Add(bot.Localization.clResourceManager.getText("Controls.ObjectList.ID"));
|
||||
header3.Width = 58;
|
||||
|
||||
this.MultiSelect = true;
|
||||
this.SelectedIndexChanged += new EventHandler(ObjectList_SelectedIndexChanged);
|
||||
|
||||
_ColumnSorter.SortColumn = 1;
|
||||
this.Sorting = SortOrder.Ascending;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
|
||||
this.DoubleBuffered = true;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
this.View = View.Details;
|
||||
this.ColumnClick += new ColumnClickEventHandler(ObjectList_ColumnClick);
|
||||
this.DoubleClick += new EventHandler(ObjectList_DoubleClick);
|
||||
}
|
||||
|
||||
void ObjectList_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
lock (_TrackedObjects)
|
||||
{
|
||||
lock (_UntrackedObjects)
|
||||
{
|
||||
if (this.SelectedItems.Count > 0)
|
||||
{
|
||||
UUID selectedID = new UUID(this.SelectedItems[0].Name);
|
||||
TrackedObject selectedOBJ;
|
||||
if (!_TrackedObjects.TryGetValue(selectedID, out selectedOBJ) && !_UntrackedObjects.TryGetValue(selectedID, out selectedOBJ))
|
||||
selectedOBJ = null;
|
||||
|
||||
_SelectedObject = selectedOBJ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe method for clearing the TreeView control
|
||||
/// </summary>
|
||||
public void ClearItems()
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
ClearItems();
|
||||
});
|
||||
else
|
||||
{
|
||||
if (this.Handle != IntPtr.Zero)
|
||||
this.Items.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public TrackedObject GetObject(UUID objectID)
|
||||
{
|
||||
TrackedObject obj;
|
||||
_TrackedObjects.TryGetValue(objectID, out obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private void InitializeClient(SecondLifeBot client)
|
||||
{
|
||||
_Client = client;
|
||||
_Client.Network.SimChanged += Network_OnCurrentSimChanged;
|
||||
_Client.Objects.ObjectUpdate += new EventHandler<PrimEventArgs>(Objects_ObjectUpdate);
|
||||
_Client.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_ObjectProperties);
|
||||
_Client.Objects.KillObject += new EventHandler<KillObjectEventArgs>(Objects_KillObject);
|
||||
}
|
||||
|
||||
void Objects_KillObject(object sender, KillObjectEventArgs e)
|
||||
{
|
||||
UUID objID;
|
||||
bool found;
|
||||
|
||||
if (StopRefreshing)
|
||||
return;
|
||||
|
||||
lock (_TrackedIDs)
|
||||
found = _TrackedIDs.TryGetValue(e.ObjectLocalID, out objID);
|
||||
|
||||
if (found)
|
||||
RemoveObject(objID);
|
||||
}
|
||||
|
||||
void Objects_ObjectUpdate(object sender, PrimEventArgs e)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
if (StopRefreshing)
|
||||
return;
|
||||
|
||||
lock (_TrackedObjects)
|
||||
found = _TrackedObjects.ContainsKey(e.Prim.ID);
|
||||
|
||||
if (!found && e.IsNew && !e.IsAttachment && e.Prim.ParentID == 0)
|
||||
{
|
||||
AddObject(e.Prim.ID, e.Prim, e.Prim.Position);
|
||||
return;
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
Primitive obj;
|
||||
if (e.Simulator.ObjectsPrimitives.TryGetValue(e.Prim.LocalID, out obj))
|
||||
UpdateObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private void Objects_ObjectProperties(object sender, ObjectPropertiesEventArgs e)
|
||||
{
|
||||
if (StopRefreshing)
|
||||
return;
|
||||
|
||||
UpdateObjectProperties(e.Properties.ObjectID, e.Properties);
|
||||
}
|
||||
|
||||
private void UpdateObjectProperties(UUID objID, Primitive.ObjectProperties objProperties)
|
||||
{
|
||||
if (!this.IsHandleCreated)
|
||||
return;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
UpdateObjectProperties(objID, objProperties);
|
||||
});
|
||||
else
|
||||
{
|
||||
TrackedObject trackedObject;
|
||||
bool found;
|
||||
|
||||
lock (_TrackedObjects)
|
||||
found = _TrackedObjects.TryGetValue(objID, out trackedObject);
|
||||
|
||||
if (found)
|
||||
{
|
||||
trackedObject.ListViewItem.Text = objProperties.Name;
|
||||
if (OnObjectPropertiesUpdated != null)
|
||||
OnObjectPropertiesUpdated(trackedObject);
|
||||
if (_Client.Account.LoginDetails.BotConfig.TouchMidnightMania)
|
||||
{
|
||||
if (objProperties.Name.ToLower().Contains("midnight") && objProperties.Name.ToLower().Contains("mania"))
|
||||
{
|
||||
_Client.Self.Touch(trackedObject.Primitive.LocalID);
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Controls.ObjectList.Midnight"), objID, objProperties.Name);
|
||||
}
|
||||
}
|
||||
if (_Client.Account.LoginDetails.BotConfig.HaveLuck)
|
||||
{
|
||||
if (objProperties.Name.ToLower().Contains("lucky") && objProperties.Name.ToLower().Contains("advent"))
|
||||
{
|
||||
_Client.Self.Touch(trackedObject.Primitive.LocalID);
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Controls.ObjectList.Advent"), objID, objProperties.Name);
|
||||
}
|
||||
if (objProperties.Name.ToLower().Contains("prize") && objProperties.Name.ToLower().Contains("pyramid"))
|
||||
{
|
||||
_Client.Self.Touch(trackedObject.Primitive.LocalID);
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Controls.ObjectList.Pyramid"), objID, objProperties.Name);
|
||||
}
|
||||
if (objProperties.Name.ToLower().Contains("lucky") && objProperties.Name.ToLower().Contains("dip"))
|
||||
{
|
||||
Client.Self.RequestSit(objID, Vector3.Zero);
|
||||
Client.Self.Sit();
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Controls.ObjectList.Dip"), objID, objProperties.Name);
|
||||
}
|
||||
if (objProperties.Name.ToLower().Contains("lucky") && objProperties.Name.ToLower().Contains("cupcake"))
|
||||
{
|
||||
Client.Self.RequestSit(objID, Vector3.Zero);
|
||||
Client.Self.Sit();
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Controls.ObjectList.Cupcake"), objID, objProperties.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshObjects()
|
||||
{
|
||||
if (StopRefreshing)
|
||||
return;
|
||||
|
||||
lock (Client.Network.Simulators)
|
||||
{
|
||||
if (Client.Network.Simulators.Count > 0)
|
||||
{
|
||||
Client.Network.Simulators[0].ObjectsPrimitives.ForEach(
|
||||
delegate(Primitive obj)
|
||||
{
|
||||
TrackedObject trackedObject;
|
||||
bool found;
|
||||
|
||||
if (obj.ParentID == 0)
|
||||
{
|
||||
lock (_TrackedObjects)
|
||||
found = _TrackedObjects.TryGetValue(obj.ID, out trackedObject);
|
||||
|
||||
if (found)
|
||||
{
|
||||
if (trackedObject.Primitive != null)
|
||||
{
|
||||
if (trackedObject.Primitive.Properties == null)
|
||||
{
|
||||
this._Client.Objects.RequestObject(this._Client.Network.CurrentSim, obj.LocalID);
|
||||
this._Client.Objects.SelectObject(this._Client.Network.CurrentSim, obj.LocalID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._Client.Objects.RequestObject(this._Client.Network.CurrentSim, obj.LocalID);
|
||||
this._Client.Objects.SelectObject(this._Client.Network.CurrentSim, obj.LocalID);
|
||||
}
|
||||
}
|
||||
//else
|
||||
// this.BeginInvoke((MethodInvoker)delegate { AddObject(obj.ID, obj, obj.Position); });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializateObjects()
|
||||
{
|
||||
lock (Client.Network.Simulators)
|
||||
{
|
||||
if (Client.Network.Simulators.Count > 0)
|
||||
{
|
||||
Client.Network.Simulators[0].ObjectsPrimitives.ForEach(
|
||||
delegate(Primitive obj)
|
||||
{
|
||||
if (obj.ParentID == 0)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
AddObject(obj.ID, obj, obj.Position);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddObject(UUID objectID, Primitive obj, Vector3 Position)
|
||||
{
|
||||
if (!this.IsHandleCreated)
|
||||
return;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
AddObject(obj.ID, obj, Position);
|
||||
});
|
||||
else
|
||||
{
|
||||
if (obj.Properties == null)
|
||||
{
|
||||
this._Client.Objects.RequestObject(this._Client.Network.CurrentSim, obj.LocalID);
|
||||
this._Client.Objects.SelectObject(this._Client.Network.CurrentSim, obj.LocalID);
|
||||
}
|
||||
|
||||
TrackedObject trackedObject = new TrackedObject();
|
||||
trackedObject.CoarseLocation = Position;
|
||||
trackedObject.ID = objectID;
|
||||
trackedObject.Primitive = obj;
|
||||
trackedObject.ListViewItem = this.Items.Add(objectID.ToString(), trackedObject.Name, null);
|
||||
trackedObject.ListViewItem.Name = objectID.ToString();
|
||||
|
||||
trackedObject.ListViewItem.SubItems.Add(Position.ToString());
|
||||
trackedObject.ListViewItem.SubItems.Add(objectID.ToString());
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj.Properties != null)
|
||||
trackedObject.Name = obj.Properties.Name;
|
||||
else
|
||||
trackedObject.Name = bot.Localization.clResourceManager.getText("Controls.Loading");
|
||||
|
||||
lock (_TrackedObjects)
|
||||
{
|
||||
if (_TrackedObjects.ContainsKey(objectID))
|
||||
{
|
||||
_TrackedObjects.Remove(objectID);
|
||||
_TrackedIDs.Remove(obj.LocalID);
|
||||
}
|
||||
|
||||
_TrackedObjects.Add(objectID, trackedObject);
|
||||
_TrackedIDs.Add(obj.LocalID, objectID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lock (_UntrackedObjects)
|
||||
{
|
||||
_UntrackedObjects.Add(objectID, trackedObject);
|
||||
|
||||
trackedObject.ListViewItem.ForeColor = Color.FromKnownColor(KnownColor.GrayText);
|
||||
}
|
||||
}
|
||||
|
||||
if (OnObjectAdded != null)
|
||||
OnObjectAdded(trackedObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveObject(UUID id)
|
||||
{
|
||||
if (!this.IsHandleCreated)
|
||||
return;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
RemoveObject(id);
|
||||
});
|
||||
else
|
||||
{
|
||||
TrackedObject trackedObject;
|
||||
|
||||
lock (_TrackedObjects)
|
||||
{
|
||||
if (_TrackedObjects.TryGetValue(id, out trackedObject))
|
||||
{
|
||||
this.Items.Remove(trackedObject.ListViewItem);
|
||||
_TrackedObjects.Remove(id);
|
||||
_TrackedIDs.Remove(trackedObject.Primitive.LocalID);
|
||||
}
|
||||
}
|
||||
|
||||
lock (_UntrackedObjects)
|
||||
{
|
||||
if (_UntrackedObjects.TryGetValue(id, out trackedObject))
|
||||
{
|
||||
this.Items.Remove(trackedObject.ListViewItem);
|
||||
_UntrackedObjects.Remove(trackedObject.ID);
|
||||
}
|
||||
}
|
||||
|
||||
if (OnObjectRemoved != null)
|
||||
OnObjectRemoved(trackedObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateObject(Primitive obj)
|
||||
{
|
||||
if (!this.IsHandleCreated)
|
||||
return;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
this.BeginInvoke((MethodInvoker)delegate
|
||||
{
|
||||
UpdateObject(obj);
|
||||
});
|
||||
else
|
||||
{
|
||||
TrackedObject trackedObject;
|
||||
bool found;
|
||||
|
||||
lock (_UntrackedObjects)
|
||||
found = _UntrackedObjects.TryGetValue(obj.ID, out trackedObject);
|
||||
|
||||
if (found)
|
||||
{
|
||||
if (obj.Properties != null)
|
||||
trackedObject.Name = obj.Properties.Name;
|
||||
else
|
||||
trackedObject.Name = bot.Localization.clResourceManager.getText("Controls.Loading");
|
||||
trackedObject.ListViewItem.Text = trackedObject.Name;
|
||||
trackedObject.ListViewItem.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
|
||||
|
||||
lock (_TrackedObjects)
|
||||
_TrackedObjects.Add(obj.ID, trackedObject);
|
||||
lock (_TrackedIDs)
|
||||
_TrackedIDs.Add(obj.LocalID, obj.ID);
|
||||
_UntrackedObjects.Remove(obj.ID);
|
||||
}
|
||||
|
||||
lock (_TrackedObjects)
|
||||
found = _TrackedObjects.TryGetValue(obj.ID, out trackedObject);
|
||||
|
||||
if (found)
|
||||
{
|
||||
trackedObject.ListViewItem.SubItems[1].Text = obj.Position.ToString();
|
||||
if (OnObjectUpdated != null)
|
||||
OnObjectUpdated(trackedObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddObject(obj.ID, obj, obj.Position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectList_ColumnClick(object sender, ColumnClickEventArgs e)
|
||||
{
|
||||
_ColumnSorter.SortColumn = e.Column;
|
||||
if ((_ColumnSorter.Ascending = (this.Sorting == SortOrder.Ascending)))
|
||||
this.Sorting = SortOrder.Descending;
|
||||
else
|
||||
this.Sorting = SortOrder.Ascending;
|
||||
this.ListViewItemSorter = _ColumnSorter;
|
||||
}
|
||||
|
||||
void ObjectList_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
/*if (OnAvatarDoubleClick != null)
|
||||
{
|
||||
ListView list = (ListView)sender;
|
||||
if (list.SelectedItems.Count > 0)
|
||||
{
|
||||
TrackedObject trackedAvatar;
|
||||
if (!_TrackedAvatars.TryGetValue(new UUID(list.SelectedItems[0].Name), out trackedAvatar)
|
||||
&& !_UntrackedAvatars.TryGetValue(new UUID(list.SelectedItems[0].Name), out trackedAvatar))
|
||||
return;
|
||||
|
||||
try { OnAvatarDoubleClick(trackedAvatar); }
|
||||
catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void Network_OnCurrentSimChanged(object sender, SimChangedEventArgs e)
|
||||
{
|
||||
lock (_TrackedObjects)
|
||||
_TrackedObjects.Clear();
|
||||
|
||||
lock (_UntrackedObjects)
|
||||
_UntrackedObjects.Clear();
|
||||
|
||||
ClearItems();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains any available information for an avatar in the simulator.
|
||||
/// A null value for .Avatar indicates coarse data for an avatar outside of visible range.
|
||||
/// </summary>
|
||||
public class TrackedObject
|
||||
{
|
||||
/// <summary>Assigned if the avatar is within visible range</summary>
|
||||
public Primitive Primitive = null;
|
||||
|
||||
/// <summary>Last known coarse location of avatar</summary>
|
||||
public Vector3 CoarseLocation;
|
||||
|
||||
/// <summary>Avatar ID</summary>
|
||||
public UUID ID;
|
||||
|
||||
/// <summary>ListViewItem associated with this avatar</summary>
|
||||
public ListViewItem ListViewItem;
|
||||
|
||||
/// <summary>Populated by RequestAvatarName if avatar is not visible</summary>
|
||||
public string Name = bot.Localization.clResourceManager.getText("Controls.Loading");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user