OK,
I kinda have a way to track the Gumps.
Let me break it down, I would like to show you what I intend to use this for...
There is the main gump with 3 sub-panels, the main gump is an anchor, known as the "RPKUI" class.
The sub panels are known as "Left Panel or Main Panel", "Status Panel or Status Bar Panel" and "Ability Panel".
I do not need to post the sub-panel gump scripts, as they are tracked by a heirarchy registry system and are therefore obsolete in regards to this post.
This is the Main Gump, RPKUI class;
Code:
public class RPKUI : Gump
{
public static int DefaultX { get { return 110; } }
public static int DefaultY { get { return 80; } }
PlayerMobile caller;
//Timer m_Timer;
public static void Initialize()
{
Commands.Register("RPKUI", AccessLevel.Administrator, new CommandEventHandler(RPKUI_OnCommand));
}
[Usage("RPKUI")]
[Description("Starts a new instace of the RPK UI.")]
public static void RPKUI_OnCommand(CommandEventArgs e)
{
PlayerMobile caller = (PlayerMobile)e.Mobile;
caller.NewRPKUI();
}
public RPKUI(PlayerMobile from)
: this(from, 110, 80)
{ }
public RPKUI(PlayerMobile from, int x, int y)
: base(x, y)
{
if (from == null || from.Deleted)
return;
caller = from;
this.Closable = false;
this.Disposable = false;
this.Dragable = false;
this.Resizable = false;
AddPage(0);
//m_Timer = Timer.DelayCall(TimeSpan.FromSeconds(10.0), new TimerCallback(caller.RefreshRPKUI));
//m_Timer.Start();
RPKUICache.Register(caller);
}
public override void OnResponse(NetState sender, RelayInfo info)
{
PlayerMobile from = (PlayerMobile)sender.Mobile;
//switch (info.ButtonID)
//{
//}
}
public void Refresh()
{
RPKUIGumpInfo info = RPKUICache.GetGumpInfo(caller);
int x = info.UI.X, y = info.UI.Y;
if (caller.HasGump(typeof(RPKUI)))
caller.CloseGump(typeof(RPKUI));
caller.SendGump(info.UI);
RPKUICache.Register(caller);
}
public static void Serialize(PlayerMobile parent, GenericWriter writer)
{
writer.Write((int)1);
RPKUIGumpInfo info = RPKUICache.GetGumpInfo(parent);
Console.WriteLine(info.ToString());
if (info != null)
{
writer.Write((bool)info.HasUI);
writer.Write((int)info.UI.X);
writer.Write((int)info.UI.Y);
writer.Write((bool)info.HasLeftPanel);
writer.Write((bool)info.HasStatusPanel);
writer.Write((bool)info.HasAbilityPanel);
writer.Write((int)info.LeftPanelX);
writer.Write((int)info.LeftPanelY);
writer.Write((int)info.StatusPanelX);
writer.Write((int)info.StatusPanelY);
writer.Write((int)info.AbilityPanelX);
writer.Write((int)info.AbilityPanelY);
}
else
{
writer.Write((bool)(parent.RPKUI == null ? false : true));
if (parent.LeftPanel != null)
{
writer.Write((int)parent.RPKUI.X);
writer.Write((int)parent.RPKUI.Y);
}
else
{
writer.Write((int)RPKUI.DefaultX);
writer.Write((int)RPKUI.DefaultY);
}
writer.Write((bool)(parent.LeftPanel == null ? false : true));
writer.Write((bool)(parent.StatusPanel == null ? false : true));
writer.Write((bool)(parent.AbilityPanel == null ? false : true));
if (parent.LeftPanel != null)
{
writer.Write((int)parent.LeftPanel.X);
writer.Write((int)parent.LeftPanel.Y);
}
else
{
writer.Write((int)RPKUI.DefaultX);
writer.Write((int)RPKUI.DefaultY);
}
if (parent.StatusPanel != null)
{
writer.Write((int)parent.StatusPanel.X);
writer.Write((int)parent.StatusPanel.Y);
}
else
{
writer.Write((int)RPKUI.DefaultX);
writer.Write((int)RPKUI.DefaultY);
}
if (parent.LeftPanel != null)
{
writer.Write((int)parent.AbilityPanel.X);
writer.Write((int)parent.AbilityPanel.Y);
}
else
{
writer.Write((int)RPKUI.DefaultX);
writer.Write((int)RPKUI.DefaultY);
}
}
}
public static void Deserialize(PlayerMobile parent, GenericReader reader)
{
int version = reader.ReadInt();
bool rpkUI = true;
bool leftPanel = false;
bool statusPanel = false;
bool abilityPanel = false;
int uiX = DefaultX;
int uiY = DefaultY;
int lpX = DefaultX;
int lpY = DefaultY;
int spX = DefaultX;
int spY = DefaultY;
int apX = DefaultX;
int apY = DefaultY;
switch (version)
{
case 1:
{
rpkUI = reader.ReadBool();
uiX = reader.ReadInt();
uiY = reader.ReadInt();
goto case 0;
}
case 0:
{
leftPanel = reader.ReadBool();
statusPanel = reader.ReadBool();
abilityPanel = reader.ReadBool();
lpX = reader.ReadInt();
lpY = reader.ReadInt();
spX = reader.ReadInt();
spY = reader.ReadInt();
apX = reader.ReadInt();
apY = reader.ReadInt();
if (rpkUI)
parent.RPKUI = new RPKUI(parent, uiX, uiY);
if (leftPanel)
parent.LeftPanel = new RPKUILeftPanel(parent, lpX, lpY);
if (statusPanel)
parent.StatusPanel = new RPKUIStatusBars(parent, spX, spY);
if (abilityPanel)
parent.AbilityPanel = new RPKUIAbilityPanel(parent, apX, apY);
RPKUICache.Register(parent);
break;
}
}
}
}
This is the heirachy registry system for tracking the gumps;
Code:
public class RPKUICache
{
private static Hashtable m_Registry = new Hashtable();
public static Hashtable Registry { get { return m_Registry; } }
public static int Count { get { return m_Registry.Count; } }
public static RPKUIGumpInfo GetGumpInfo(PlayerMobile parent)
{
if (!m_Registry.ContainsKey(parent))
Register(parent);
return m_Registry[parent] as RPKUIGumpInfo;
}
public static void Register(PlayerMobile parent)
{
if (!m_Registry.ContainsKey(parent))
m_Registry.Add(parent, new RPKUIGumpInfo(parent));
else
m_Registry[parent] = new RPKUIGumpInfo(parent);
}
}
and finally... the Gump Info class;
Code:
public class RPKUIGumpInfo
{
private RPKUI rpkUI;
private PlayerMobile mobile;
private bool leftPanel;
private bool statusPanel;
private bool abilityPanel;
private int lpX;
private int lpY;
private int spX;
private int spY;
private int apX;
private int apY;
public RPKUI UI { get { return rpkUI; } }
public PlayerMobile Parent { get { return mobile; } }
public bool HasUI { get { return (rpkUI != null); } }
public bool HasLeftPanel { get { return leftPanel; } }
public bool HasStatusPanel { get { return statusPanel; } }
public bool HasAbilityPanel { get { return abilityPanel; } }
public int LeftPanelX { get { return lpX; } }
public int LeftPanelY { get { return lpY; } }
public int StatusPanelX { get { return spX; } }
public int StatusPanelY { get { return spY; } }
public int AbilityPanelX { get { return apX; } }
public int AbilityPanelY { get { return apY; } }
public RPKUIGumpInfo(PlayerMobile parent)
{
rpkUI = parent.RPKUI;
mobile = parent;
leftPanel = (bool)(parent.LeftPanel == null ? false : true);
statusPanel = (bool)(parent.StatusPanel == null ? false : true);
abilityPanel = (bool)(parent.AbilityPanel == null ? false : true);
if (leftPanel)
{
lpX = (int)parent.LeftPanel.X;
lpY = (int)parent.LeftPanel.Y;
}
else
{
lpX = RPKUI.DefaultX;
lpY = RPKUI.DefaultY;
}
if (statusPanel)
{
spX = (int)parent.StatusPanel.X;
spY = (int)parent.StatusPanel.Y;
}
else
{
spX = RPKUI.DefaultX;
spY = RPKUI.DefaultY;
}
if (abilityPanel)
{
apX = (int)parent.AbilityPanel.X;
apY = (int)parent.AbilityPanel.Y;
}
else
{
apX = RPKUI.DefaultX;
apY = RPKUI.DefaultY;
}
}
public override string ToString()
{
return String.Format("RPKUI Info: {0} - LP:{1} LPX:{2} LPY:{3} - SP:{4} SPX:{5} SPY:{6} - AP:{7} APX:{8} APY:{9} - UI:{10} UIX:{11} UIY:{12}", mobile.Name, leftPanel, lpX, lpY, statusPanel, spX, spY, abilityPanel, apX, apY, rpkUI.ToString(), rpkUI.X, rpkUI.Y);
}
}
Note that the Serialize/Deserialize methods i have added to RPKUI are actually serialized/deserialized on the PlayerMobile object.
For every player on the server, there should be one entry in the Cache.
I have managed to put ogether a gump that allows you to move a select panel by an incrment of your choice in any of 8 directions... But i'm still not sure if this is the best way to do thi...
If anyone see's anything that can be refined in these scripts, please let me know... Or if you have an opinion on the kind of system I should write to be able to track gump positions, it will be much appreciated.
Regards