using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using TGS.Interface;
using TGS.Interface.Components;
namespace TGS.ControlPanel
{
///
/// The main form
///
sealed partial class ControlPanel : CountedForm
{
///
/// List of instances being used by open control panels
///
public static IDictionary InstancesInUse { get; private set; } = new Dictionary();
///
/// The instance for this
///
readonly IServerInterface Interface;
///
/// Constructs a
///
/// The for the
public ControlPanel(IServerInterface I)
{
InitializeComponent();
FormClosed += ControlPanel_FormClosed;
Interface = I;
if (Interface.IsRemoteConnection)
Text = String.Format("TGS {0}: {1}:{2}", Interface.ServerVersion, Interface.LoginInfo.IP, Interface.LoginInfo.Port);
Text = String.Format("{0} Instance: {1}", Text, I.InstanceName);
Panels.SelectedIndexChanged += Panels_SelectedIndexChanged;
Panels.SelectedIndex += Math.Min(Properties.Settings.Default.LastPageIndex, Panels.TabCount - 1);
InitRepoPage();
InitBYONDPage();
InitServerPage();
UpdateSelectedPanel();
InstancesInUse.Add(I.InstanceName, this);
}
///
/// Called when the is closed
///
/// The sender of the event
/// The
void ControlPanel_FormClosed(object sender, FormClosedEventArgs e)
{
InstancesInUse.Remove(Interface.InstanceName);
}
///
/// Called from
///
void Cleanup()
{
InstancesInUse.Remove(Interface.InstanceName);
Interface.Dispose();
}
private void Main_Resize(object sender, EventArgs e)
{
Panels.Location = new Point(10, 10);
Panels.Width = ClientSize.Width - 20;
Panels.Height = ClientSize.Height - 20;
}
///
/// Updates the content of of
///
void UpdateSelectedPanel()
{
switch (Panels.SelectedIndex)
{
case 0: //repo
PopulateRepoFields();
break;
case 1: //byond
UpdateBYONDButtons();
break;
case 2: //scp
LoadServerPage();
break;
case 3: //chat
LoadChatPage();
break;
case 4: //static
InitStaticPage();
break;
}
Properties.Settings.Default.LastPageIndex = Panels.SelectedIndex;
}
void Panels_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateSelectedPanel();
}
bool CheckAdminWithWarning()
{
if (!Interface.ConnectToInstance().HasFlag(ConnectivityLevel.Administrator))
{
MessageBox.Show("Only system administrators may use this command!");
return false;
}
return true;
}
}
}