From 26588acf2d9c97039990798a5fd24dbbade20be2 Mon Sep 17 00:00:00 2001 From: WarrentyExpired Date: Wed, 26 Aug 2026 11:10:43 -0400 Subject: [PATCH] #W# Added a nice status bar. can be flipped vertical or horizontal. --- Scripts/Gumps/StatusBar.cs | 129 ++++++++++++++++++++++++++++++++ Scripts/Mobiles/PlayerMobile.cs | 18 +++++ Source/Mobile.cs | 24 +++++- 3 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 Scripts/Gumps/StatusBar.cs diff --git a/Scripts/Gumps/StatusBar.cs b/Scripts/Gumps/StatusBar.cs new file mode 100644 index 0000000..34f84da --- /dev/null +++ b/Scripts/Gumps/StatusBar.cs @@ -0,0 +1,129 @@ +using System; +using Server; +using Server.Gumps; +using Server.Mobiles; +using Server.Commands; +using Server.Network; + +namespace Server.Custom.UI +{ + public class StatusBar + { + public static void Initialize() + { + CommandSystem.Register("Status", AccessLevel.Player, new CommandEventHandler(OnCommand)); + } + + [Usage("Status")] + [Description("Opens a quick-view status bar for Fame, Karma, Hunger, Thirst, and Tithing.")] + public static void OnCommand(CommandEventArgs e) + { + if (e.Mobile is PlayerMobile) + { + PlayerMobile pm = (PlayerMobile)e.Mobile; + + pm.CloseGump(typeof(StatusBarGump)); + pm.SendGump(new StatusBarGump(pm, false)); + } + } + + public static void Refresh(Mobile from, bool force = false) + { + if (from is PlayerMobile && from.NetState != null) + { + if (from.HasGump(typeof(StatusBarGump)) || force) + { + bool isVert = false; + + foreach (Gump gump in from.NetState.Gumps) + { + if (gump is StatusBarGump) + { + // This line right here is what threw the CS1061 error earlier! + isVert = ((StatusBarGump)gump).IsVertical; + break; + } + } + + from.CloseGump(typeof(StatusBarGump)); + from.SendGump(new StatusBarGump((PlayerMobile)from, isVert)); + } + } + } + } + + public class StatusBarGump : Gump + { + private PlayerMobile m_Player; + private bool m_IsVertical; + + // --- HERE IS THE MISSING PROPERTY THAT FIXES THE CS1061 ERROR --- + public bool IsVertical { get { return m_IsVertical; } } + // ---------------------------------------------------------------- + + public StatusBarGump(PlayerMobile pm, bool isVertical) : base(50, 50) + { + m_Player = pm; + m_IsVertical = isVertical; + + Closable = true; + Disposable = true; + Dragable = true; + Resizable = false; + + AddPage(0); + + if (m_IsVertical) + { + // ========================================== + // VERTICAL LAYOUT + // ========================================== + AddBackground(0, 0, 150, 175, 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); + + AddButton(15, 142, 4011, 4012, 1, GumpButtonType.Reply, 0); + AddHtml(50, 143, 80, 20, "Refresh", false, false); + + AddButton(115, 142, 9720, 9722, 2, GumpButtonType.Reply, 0); + } + else + { + // ========================================== + // HORIZONTAL LAYOUT (Widened for Tithing) + // ========================================== + AddBackground(0, 0, 580, 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); + + AddButton(525, 12, 4011, 4012, 1, GumpButtonType.Reply, 0); + + AddButton(555, 15, 9720, 9722, 2, GumpButtonType.Reply, 0); + } + } + + public override void OnResponse(NetState sender, RelayInfo info) + { + if (m_Player == null || m_Player.Deleted) + return; + + switch (info.ButtonID) + { + case 1: + m_Player.SendGump(new StatusBarGump(m_Player, m_IsVertical)); + break; + case 2: + m_Player.SendGump(new StatusBarGump(m_Player, !m_IsVertical)); + break; + } + } + } +} diff --git a/Scripts/Mobiles/PlayerMobile.cs b/Scripts/Mobiles/PlayerMobile.cs index bce2753..f5c23c0 100644 --- a/Scripts/Mobiles/PlayerMobile.cs +++ b/Scripts/Mobiles/PlayerMobile.cs @@ -25,6 +25,7 @@ using Server.Engines.Craft; using Server.Spells.Spellweaving; using Server.Engines.PartySystem; using Server.Engines.MLQuests; +using Server.Custom.UI; namespace Server.Mobiles { @@ -4203,11 +4204,13 @@ namespace Server.Mobiles public override void OnKarmaChange( int oldValue ) { InvalidateMyRunUO(); + StatusBar.Refresh(this); } public override void OnFameChange( int oldValue ) { InvalidateMyRunUO(); + StatusBar.Refresh(this); } public override void OnSkillChange( SkillName skill, double oldBase ) @@ -4226,6 +4229,21 @@ namespace Server.Mobiles InvalidateMyRunUO(); } + public override void OnHungerChange(int oldValue) + { + StatusBar.Refresh(this); + } + + public override void OnThirstChange(int oldValue) + { + StatusBar.Refresh(this); + } + + public override void OnTithingPointsChange(int oldValue) + { + StatusBar.Refresh(this); + } + public override void OnAccessLevelChanged( AccessLevel oldLevel ) { if ( AccessLevel == AccessLevel.Player ) diff --git a/Source/Mobile.cs b/Source/Mobile.cs index 94791b5..5949470 100644 --- a/Source/Mobile.cs +++ b/Source/Mobile.cs @@ -1549,12 +1549,16 @@ namespace Server if( oldValue != value ) { m_Hunger = value; - + OnHungerChange(oldValue); EventSink.InvokeHungerChanged( new HungerChangedEventArgs( this, oldValue ) ); } } } + public virtual void OnHungerChange(int oldValue) + { + } + [CommandProperty( AccessLevel.GameMaster )] public int Thirst { @@ -1564,10 +1568,19 @@ namespace Server } set { - m_Thirst = value; + int oldValue = m_Thirst; + if (oldValue != value) + { + m_Thirst = value; + OnThirstChange(oldValue); + } } } + public virtual void OnThirstChange(int oldValue) + { + } + [CommandProperty( AccessLevel.GameMaster )] public int BAC { @@ -2512,13 +2525,18 @@ namespace Server { if( m_TithingPoints != value ) { + int oldValue = m_TithingPoints; m_TithingPoints = value; - Delta( MobileDelta.TithingPoints ); + OnTithingPointsChange(oldValue); } } } + public virtual void OnTithingPointsChange(int oldValue) + { + } + [CommandProperty( AccessLevel.GameMaster )] public int Followers {