2008-08-05 06:43:40 +00:00
using OpenMetaverse ;
using OpenMetaverse.GUI ;
using System ;
using System.Collections.Generic ;
using System.Drawing ;
using System.Reflection ;
using System.Windows.Forms ;
namespace Dashboard
{
public partial class Dashboard : Form
{
GridClient Client ;
2009-03-27 18:29:32 +00:00
LoginParams ClientLogin ;
2009-03-31 21:28:51 +00:00
bool ShuttingDown = false ;
2008-08-05 06:43:40 +00:00
/// <summary>
/// Provides a full representation of OpenMetaverse.GUI
/// </summary>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
/// <param name="password"></param>
public Dashboard ( string firstName , string lastName , string password )
{
InitializeComponent ( ) ;
//force logout and exit when form is closed
this . FormClosing + = new FormClosingEventHandler ( Dashboard_FormClosing ) ;
2009-03-27 18:29:32 +00:00
//initialize the client object and related controls
InitializeClient ( true ) ;
//double-click events
2009-07-14 22:24:05 +00:00
avatarList1 . OnAvatarDoubleClick + = new AvatarList . AvatarCallback ( avatarList1_OnAvatarDoubleClick ) ;
2009-03-27 18:29:32 +00:00
friendsList1 . OnFriendDoubleClick + = new FriendList . FriendDoubleClickCallback ( friendsList1_OnFriendDoubleClick ) ;
groupList1 . OnGroupDoubleClick + = new GroupList . GroupDoubleClickCallback ( groupList1_OnGroupDoubleClick ) ;
//login
ClientLogin = Client . Network . DefaultLoginParams ( firstName , lastName , password , "OpenMetaverse Dashboard" , Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) ) ;
2009-03-31 21:28:51 +00:00
loginPanel1 . LoginParams = ClientLogin ;
2009-03-27 18:29:32 +00:00
ClientLogin . Start = "last" ;
2009-03-31 21:28:51 +00:00
if ( firstName ! = String . Empty & & lastName ! = String . Empty & & password ! = String . Empty )
Client . Network . BeginLogin ( ClientLogin ) ;
2009-03-27 18:29:32 +00:00
}
private void InitializeClient ( bool initialize )
{
if ( Client ! = null )
{
if ( Client . Network . Connected )
Client . Network . Logout ( ) ;
Client = null ;
}
if ( ! initialize ) return ;
2008-08-05 06:43:40 +00:00
//initialize client object
Client = new GridClient ( ) ;
2009-07-14 22:24:05 +00:00
Client . Settings . USE_LLSD_LOGIN = true ;
2009-07-19 03:50:09 +00:00
Client . Settings . USE_ASSET_CACHE = true ;
2008-08-05 06:43:40 +00:00
2009-10-28 08:01:52 +00:00
Client . Network . Disconnected + = Network_OnDisconnected ;
2009-10-16 02:53:53 +00:00
Client . Self . IM + = Self_IM ;
2009-03-31 21:28:51 +00:00
2008-08-05 06:43:40 +00:00
//define the client object for each GUI element
avatarList1 . Client = Client ;
friendsList1 . Client = Client ;
groupList1 . Client = Client ;
inventoryTree1 . Client = Client ;
localChat1 . Client = Client ;
2009-03-31 21:28:51 +00:00
loginPanel1 . Client = Client ;
2009-04-15 23:11:52 +00:00
messageBar1 . Client = Client ;
2008-08-05 06:43:40 +00:00
miniMap1 . Client = Client ;
2009-03-19 22:09:20 +00:00
statusOutput1 . Client = Client ;
2008-08-05 06:43:40 +00:00
}
2009-10-16 02:53:53 +00:00
void Self_IM ( object sender , InstantMessageEventArgs e )
{
if ( e . IM . Dialog = = InstantMessageDialog . RequestTeleport )
{
this . BeginInvoke ( ( MethodInvoker ) delegate
{
DialogResult result = MessageBox . Show ( this , e . IM . FromAgentName + " has offered you a teleport request:" + Environment . NewLine + e . IM . Message , this . Text , MessageBoxButtons . YesNo ) ;
if ( result = = DialogResult . Yes )
2010-10-21 13:30:55 +00:00
Client . Self . TeleportLureRespond ( e . IM . FromAgentID , e . IM . IMSessionID , true ) ;
2009-10-16 02:53:53 +00:00
} ) ;
}
}
2009-04-15 23:11:52 +00:00
void Dashboard_FormClosing ( object sender , FormClosingEventArgs e )
2008-08-05 06:43:40 +00:00
{
2009-03-31 21:28:51 +00:00
ShuttingDown = true ;
2009-03-27 18:29:32 +00:00
InitializeClient ( false ) ;
2008-08-05 06:43:40 +00:00
Environment . Exit ( 0 ) ;
}
2009-04-15 23:11:52 +00:00
void avatarList1_OnAvatarDoubleClick ( TrackedAvatar trackedAvatar )
2008-08-05 06:43:40 +00:00
{
2009-04-15 23:11:52 +00:00
messageBar1 . CreateSession ( trackedAvatar . Name , trackedAvatar . ID , trackedAvatar . ID , true ) ;
2008-08-05 06:43:40 +00:00
}
2009-04-15 23:11:52 +00:00
void friendsList1_OnFriendDoubleClick ( FriendInfo friend )
2008-08-05 06:43:40 +00:00
{
2009-04-15 23:11:52 +00:00
messageBar1 . CreateSession ( friend . Name , friend . UUID , friend . UUID , true ) ;
2008-08-05 06:43:40 +00:00
}
2009-04-15 23:11:52 +00:00
void groupList1_OnGroupDoubleClick ( Group group )
2008-08-05 06:43:40 +00:00
{
MessageBox . Show ( group . Name + " = " + group . ID ) ;
}
2009-10-28 08:01:52 +00:00
void Network_OnDisconnected ( object sender , DisconnectedEventArgs e )
2009-03-27 18:29:32 +00:00
{
2009-03-31 21:28:51 +00:00
InitializeClient ( ! ShuttingDown ) ;
2009-10-16 02:53:53 +00:00
}
2008-08-05 06:43:40 +00:00
}
}