using System; using System.Collections.Concurrent; using Server; using Server.Gumps; using Server.Mobiles; using Server.Commands; using Server.Network; namespace Server.Custom.UI { public class StatusBar { // Safely tracks if a player prefers the vertical (true) or horizontal (false) layout public static ConcurrentDictionary Preferences = new ConcurrentDictionary(); public static void Initialize() { CommandSystem.Register("StatusBar", AccessLevel.Player, new CommandEventHandler(OnCommand)); } [Usage("StatusBar")] [Description("Opens a quick-view status bar for Fame, Karma, Hunger, Thirst, Tithing, and Kills.")] public static void OnCommand(CommandEventArgs e) { if (e.Mobile is PlayerMobile pm) { // Get their saved preference, defaulting to horizontal (false) bool isVert = Preferences.GetOrAdd(pm, false); // ModernUO Generics: Notice the brackets and empty parentheses! pm.CloseGump(); pm.SendGump(new StatusBarGump(pm, isVert)); } } public static void Refresh(Mobile from, bool force = false) { if (from is PlayerMobile pm && pm.NetState != null) { // ModernUO Generics: HasGump takes 0 arguments now if (pm.HasGump() || force) { bool isVert = Preferences.GetOrAdd(pm, false); pm.CloseGump(); pm.SendGump(new StatusBarGump(pm, isVert)); } } } } public class StatusBarGump : Gump { private PlayerMobile m_Player; private bool m_IsVertical; public StatusBarGump(PlayerMobile pm, bool isVertical) : base(50, 50) { m_Player = pm; m_IsVertical = isVertical; Closable = true; Disposable = true; Draggable = true; Resizable = false; AddPage(0); if (m_IsVertical) { AddBackground(0, 0, 150, 200, 9270); AddHtml(15, 15, 120, 20, $"Fame: {pm.Fame}", false, false); AddHtml(15, 40, 120, 20, $"Karma: {pm.Karma}", false, false); AddHtml(15, 65, 120, 20, $"Hunger: {pm.Hunger}/20", false, false); AddHtml(15, 90, 120, 20, $"Thirst: {pm.Thirst}/20", false, false); AddHtml(15, 115, 120, 20, $"Tithing: {pm.TithingPoints}", false, false); AddHtml(15, 140, 120, 20, $"Kills: {pm.MonsterKillPoints}", false, false); AddButton(115, 167, 9720, 9722, 2, GumpButtonType.Reply, 0); } else { AddBackground(0, 0, 650, 45, 9270); AddHtml(15, 12, 110, 20, $"Fame: {pm.Fame}", false, false); AddHtml(110, 12, 110, 20, $"Karma: {pm.Karma}", false, false); AddHtml(215, 12, 110, 20, $"Hunger: {pm.Hunger}/20", false, false); AddHtml(315, 12, 110, 20, $"Thirst: {pm.Thirst}/20", false, false); AddHtml(410, 12, 110, 20, $"Tithing: {pm.TithingPoints}", false, false); AddHtml(510, 12, 110, 20, $"Kills: {pm.MonsterKillPoints}", false, false); AddButton(625, 15, 9720, 9722, 2, GumpButtonType.Reply, 0); } } public override void OnResponse(NetState sender, in RelayInfo info) { if (m_Player == null || m_Player.Deleted) return; switch (info.ButtonID) { case 1: // Refresh the gump without changing layout m_Player.SendGump(new StatusBarGump(m_Player, m_IsVertical)); break; case 2: // Toggle the layout and save their preference StatusBar.Preferences[m_Player] = !m_IsVertical; m_Player.SendGump(new StatusBarGump(m_Player, !m_IsVertical)); break; } } } }