From b5e3f49d06a2cfcd68cf30d875c99bd283cd9930 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 27 Jan 2025 11:29:23 -0800 Subject: [PATCH 1/4] fix: Converts MakersMark gump to static & CraftGumpItem to dynamic (#2095) --- .../Engines/Craft/Core/CraftGumpItem.cs | 520 +++++++++--------- .../UOContent/Engines/Craft/Core/CraftItem.cs | 1 - .../Engines/Craft/Core/QueryMakersMarkGump.cs | 87 ++- 3 files changed, 307 insertions(+), 301 deletions(-) diff --git a/Projects/UOContent/Engines/Craft/Core/CraftGumpItem.cs b/Projects/UOContent/Engines/Craft/Core/CraftGumpItem.cs index a8938b5114..25cab64b61 100644 --- a/Projects/UOContent/Engines/Craft/Core/CraftGumpItem.cs +++ b/Projects/UOContent/Engines/Craft/Core/CraftGumpItem.cs @@ -4,333 +4,341 @@ using Server.Mobiles; using Server.Network; -namespace Server.Engines.Craft +namespace Server.Engines.Craft; + +public class CraftGumpItem : DynamicGump { - public class CraftGumpItem : Gump - { - private const int LabelHue = 0x480; // 0x384 - private const int RedLabelHue = 0x20; + private const int LabelHue = 0x480; // 0x384 + private const int RedLabelHue = 0x20; - private const int LabelColor = 0x7FFF; - private const int RedLabelColor = 0x6400; + private const int LabelColor = 0x7FFF; + private const int RedLabelColor = 0x6400; - private const int GreyLabelColor = 0x3DEF; + private const int GreyLabelColor = 0x3DEF; - private static readonly Type typeofBlankScroll = typeof(BlankScroll); - private static readonly Type typeofSpellScroll = typeof(SpellScroll); - private readonly CraftItem m_CraftItem; - private readonly CraftSystem m_CraftSystem; - private readonly Mobile m_From; - private readonly BaseTool m_Tool; + private static readonly Type typeofBlankScroll = typeof(BlankScroll); + private static readonly Type typeofSpellScroll = typeof(SpellScroll); - private int m_OtherCount; + private readonly Mobile _from; + private readonly CraftItem _craftItem; + private readonly CraftSystem _craftSystem; + private readonly BaseTool _tool; - private bool m_ShowExceptionalChance; + public override bool Singleton => true; - public override bool Singleton => true; + public CraftGumpItem(Mobile from, CraftSystem craftSystem, CraftItem craftItem, BaseTool tool) : base(40, 40) + { + _from = from; + _craftSystem = craftSystem; + _craftItem = craftItem; + _tool = tool; + } - public CraftGumpItem(Mobile from, CraftSystem craftSystem, CraftItem craftItem, BaseTool tool) : base(40, 40) + protected override void BuildLayout(ref DynamicGumpBuilder builder) + { + builder.AddPage(); + builder.AddBackground(0, 0, 530, 417, 5054); + builder.AddImageTiled(10, 10, 510, 22, 2624); + builder.AddImageTiled(10, 37, 150, 148, 2624); + builder.AddImageTiled(165, 37, 355, 90, 2624); + builder.AddImageTiled(10, 190, 155, 22, 2624); + builder.AddImageTiled(10, 217, 150, 53, 2624); + builder.AddImageTiled(165, 132, 355, 80, 2624); + builder.AddImageTiled(10, 275, 155, 22, 2624); + builder.AddImageTiled(10, 302, 150, 53, 2624); + builder.AddImageTiled(165, 217, 355, 80, 2624); + builder.AddImageTiled(10, 360, 155, 22, 2624); + builder.AddImageTiled(165, 302, 355, 80, 2624); + builder.AddImageTiled(10, 387, 510, 22, 2624); + builder.AddAlphaRegion(10, 10, 510, 399); + + builder.AddHtmlLocalized(170, 40, 150, 20, 1044053, LabelColor); // ITEM + builder.AddHtmlLocalized(10, 192, 150, 22, 1044054, LabelColor); //
SKILLS
+ builder.AddHtmlLocalized(10, 277, 150, 22, 1044055, LabelColor); //
MATERIALS
+ builder.AddHtmlLocalized(10, 362, 150, 22, 1044056, LabelColor); //
OTHER
+ + if (_craftSystem.GumpTitle.Number > 0) { - m_From = from; - m_CraftSystem = craftSystem; - m_CraftItem = craftItem; - m_Tool = tool; - - AddPage(0); - AddBackground(0, 0, 530, 417, 5054); - AddImageTiled(10, 10, 510, 22, 2624); - AddImageTiled(10, 37, 150, 148, 2624); - AddImageTiled(165, 37, 355, 90, 2624); - AddImageTiled(10, 190, 155, 22, 2624); - AddImageTiled(10, 217, 150, 53, 2624); - AddImageTiled(165, 132, 355, 80, 2624); - AddImageTiled(10, 275, 155, 22, 2624); - AddImageTiled(10, 302, 150, 53, 2624); - AddImageTiled(165, 217, 355, 80, 2624); - AddImageTiled(10, 360, 155, 22, 2624); - AddImageTiled(165, 302, 355, 80, 2624); - AddImageTiled(10, 387, 510, 22, 2624); - AddAlphaRegion(10, 10, 510, 399); - - AddHtmlLocalized(170, 40, 150, 20, 1044053, LabelColor); // ITEM - AddHtmlLocalized(10, 192, 150, 22, 1044054, LabelColor); //
SKILLS
- AddHtmlLocalized(10, 277, 150, 22, 1044055, LabelColor); //
MATERIALS
- AddHtmlLocalized(10, 362, 150, 22, 1044056, LabelColor); //
OTHER
- - if (craftSystem.GumpTitle.Number > 0) - { - AddHtmlLocalized(10, 12, 510, 20, craftSystem.GumpTitle.Number, LabelColor); - } - else - { - AddHtml(10, 12, 510, 20, craftSystem.GumpTitle.String); - } + builder.AddHtmlLocalized(10, 12, 510, 20, _craftSystem.GumpTitle.Number, LabelColor); + } + else + { + builder.AddHtml(10, 12, 510, 20, _craftSystem.GumpTitle.String); + } - AddButton(15, 387, 4014, 4016, 0); - AddHtmlLocalized(50, 390, 150, 18, 1044150, LabelColor); // BACK + builder.AddButton(15, 387, 4014, 4016, 0); + builder.AddHtmlLocalized(50, 390, 150, 18, 1044150, LabelColor); // BACK - var needsRecipe = craftItem.Recipe != null && from is PlayerMobile mobile && - !mobile.HasRecipe(craftItem.Recipe); + var needsRecipe = _craftItem.Recipe != null && _from is PlayerMobile mobile && + !mobile.HasRecipe(_craftItem.Recipe); - if (needsRecipe) - { - AddButton(270, 387, 4005, 4007, 0, GumpButtonType.Page); - AddHtmlLocalized(305, 390, 150, 18, 1044151, GreyLabelColor); // MAKE NOW - } - else - { - AddButton(270, 387, 4005, 4007, 1); - AddHtmlLocalized(305, 390, 150, 18, 1044151, LabelColor); // MAKE NOW - } + if (needsRecipe) + { + builder.AddButton(270, 387, 4005, 4007, 0, GumpButtonType.Page); + builder.AddHtmlLocalized(305, 390, 150, 18, 1044151, GreyLabelColor); // MAKE NOW + } + else + { + builder.AddButton(270, 387, 4005, 4007, 1); + builder.AddHtmlLocalized(305, 390, 150, 18, 1044151, LabelColor); // MAKE NOW + } - if (craftItem.NameNumber > 0) - { - AddHtmlLocalized(330, 40, 180, 18, craftItem.NameNumber, LabelColor); - } - else - { - AddLabel(330, 40, LabelHue, craftItem.NameString); - } + if (_craftItem.NameNumber > 0) + { + builder.AddHtmlLocalized(330, 40, 180, 18, _craftItem.NameNumber, LabelColor); + } + else + { + builder.AddLabel(330, 40, LabelHue, _craftItem.NameString); + } - if (craftItem.UseAllRes) - { - AddHtmlLocalized( - 170, - 302 + m_OtherCount++ * 20, - 310, - 18, - 1048176, // Makes as many as possible at once - LabelColor - ); - } + if (_craftItem.UseAllRes) + { + builder.AddHtmlLocalized( + 170, + 302, + 310, + 18, + 1048176, // Makes as many as possible at once + LabelColor + ); + } - DrawItem(); - DrawSkill(); - DrawResource(); + var otherCount = 1; - if (craftItem.RequiredExpansion != Expansion.None) - { - var supportsEx = from.NetState?.SupportsExpansion(craftItem.RequiredExpansion) == true; - RequiredExpansionMessage(craftItem.RequiredExpansion).AddHtmlText( - this, - 170, - 302 + m_OtherCount++ * 20, - 310, - 18, - false, - false, - supportsEx ? LabelColor : RedLabelColor, - supportsEx ? LabelHue : RedLabelHue - ); - } + DrawItem(ref builder, ref otherCount, out var showExceptionalChance); + DrawSkill(ref builder, showExceptionalChance); + DrawResource(ref builder, ref otherCount); - if (needsRecipe) - { - AddHtmlLocalized( - 170, - 302 + m_OtherCount++ * 20, - 310, - 18, - 1073620, // You have not learned this recipe. - RedLabelColor - ); - } + if (_craftItem.RequiredExpansion != Expansion.None) + { + var supportsEx = _from.NetState?.SupportsExpansion(_craftItem.RequiredExpansion) == true; + RequiredExpansionMessage(_craftItem.RequiredExpansion).AddHtmlText( + ref builder, + 170, + 302 + otherCount++ * 20, + 310, + 18, + false, + false, + supportsEx ? LabelColor : RedLabelColor, + supportsEx ? LabelHue : RedLabelHue + ); } - private static TextDefinition RequiredExpansionMessage(Expansion expansion) + if (needsRecipe) { - return expansion switch - { - Expansion.SE => 1063363, // * Requires the "Samurai Empire" expansion - Expansion.ML => 1072651, // * Requires the "Mondain's Legacy" expansion - _ => $"* Requires the \"{ExpansionInfo.GetInfo(expansion).Name}\" expansion" - }; + builder.AddHtmlLocalized( + 170, + 302 + otherCount++ * 20, + 310, + 18, + 1073620, // You have not learned this recipe. + RedLabelColor + ); } + } - public void DrawItem() + private static TextDefinition RequiredExpansionMessage(Expansion expansion) + { + return expansion switch { - var type = m_CraftItem.ItemType; + Expansion.SE => 1063363, // * Requires the "Samurai Empire" expansion + Expansion.ML => 1072651, // * Requires the "Mondain's Legacy" expansion + _ => $"* Requires the \"{ExpansionInfo.GetInfo(expansion).Name}\" expansion" + }; + } - AddItem(20, 50, m_CraftItem.ItemId, m_CraftItem.ItemHue); + public void DrawItem(ref DynamicGumpBuilder builder, ref int otherCount, out bool showExceptionalChance) + { + var type = _craftItem.ItemType; - if (m_CraftItem.IsMarkable(type)) - { - AddHtmlLocalized( - 170, - 302 + m_OtherCount++ * 20, - 310, - 18, - 1044059, // This item may hold its maker's mark - LabelColor - ); - m_ShowExceptionalChance = true; - } - } + builder.AddItem(20, 50, _craftItem.ItemId, _craftItem.ItemHue); - public void DrawSkill() + if (_craftItem.IsMarkable(type)) { - for (var i = 0; i < m_CraftItem.Skills.Count; i++) - { - var skill = m_CraftItem.Skills[i]; - var minSkill = Math.Max(skill.MinSkill, 0); + builder.AddHtmlLocalized( + 170, + 302 + otherCount++ * 20, + 310, + 18, + 1044059, // This item may hold its maker's mark + LabelColor + ); - AddHtmlLocalized(170, 132 + i * 20, 200, 18, AosSkillBonuses.GetLabel(skill.SkillToMake), LabelColor); - AddLabel(430, 132 + i * 20, LabelHue, $"{minSkill:F1}"); - } + showExceptionalChance = true; + } + else + { + showExceptionalChance = false; + } + } - var res = m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes; - var resIndex = -1; + public void DrawSkill(ref DynamicGumpBuilder builder, bool showExceptionalChance) + { + for (var i = 0; i < _craftItem.Skills.Count; i++) + { + var skill = _craftItem.Skills[i]; + var minSkill = Math.Max(skill.MinSkill, 0); - var context = m_CraftSystem.GetContext(m_From); + builder.AddHtmlLocalized(170, 132 + i * 20, 200, 18, AosSkillBonuses.GetLabel(skill.SkillToMake), LabelColor); + builder.AddLabel(430, 132 + i * 20, LabelHue, $"{minSkill:F1}"); + } - if (context != null) - { - resIndex = m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex; - } + var res = _craftItem.UseSubRes2 ? _craftSystem.CraftSubRes2 : _craftSystem.CraftSubRes; + var resIndex = -1; - var chance = m_CraftItem.GetSuccessChance( - m_From, - resIndex > -1 ? res.GetAt(resIndex).ItemType : null, - m_CraftSystem, - false, - out _ - ); + var context = _craftSystem.GetContext(_from); - AddHtmlLocalized(170, 80, 250, 18, 1044057, LabelColor); // Success Chance: - AddLabel(430, 80, LabelHue, $"{Math.Clamp(chance, 0, 1) * 100:F1}%"); + if (context != null) + { + resIndex = _craftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex; + } - if (m_ShowExceptionalChance) - { - var exceptChance = Math.Clamp(m_CraftItem.GetExceptionalChance(m_CraftSystem, chance, m_From), 0, 1.0); + var chance = _craftItem.GetSuccessChance( + _from, + resIndex > -1 ? res.GetAt(resIndex).ItemType : null, + _craftSystem, + false, + out _ + ); - AddHtmlLocalized(170, 100, 250, 18, 1044058, 32767); // Exceptional Chance: - AddLabel(430, 100, LabelHue, $"{exceptChance * 100:F1}%"); - } - } + builder.AddHtmlLocalized(170, 80, 250, 18, 1044057, LabelColor); // Success Chance: + builder.AddLabel(430, 80, LabelHue, $"{Math.Clamp(chance, 0, 1) * 100:F1}%"); - public void DrawResource() + if (showExceptionalChance) { - var retainedColor = false; + var exceptChance = Math.Clamp(_craftItem.GetExceptionalChance(_craftSystem, chance, _from), 0, 1.0); - var context = m_CraftSystem.GetContext(m_From); + builder.AddHtmlLocalized(170, 100, 250, 18, 1044058, 32767); // Exceptional Chance: + builder.AddLabel(430, 100, LabelHue, $"{exceptChance * 100:F1}%"); + } + } - var res = m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes; - var resIndex = -1; + public void DrawResource(ref DynamicGumpBuilder builder, ref int otherCount) + { + var retainedColor = false; - if (context != null) - { - resIndex = m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex; - } + var context = _craftSystem.GetContext(_from); - var cropScroll = m_CraftItem.Resources.Count > 1 - && m_CraftItem.Resources[^1].ItemType == typeofBlankScroll - && typeofSpellScroll.IsAssignableFrom(m_CraftItem.ItemType); + var res = _craftItem.UseSubRes2 ? _craftSystem.CraftSubRes2 : _craftSystem.CraftSubRes; + var resIndex = -1; - for (var i = 0; i < m_CraftItem.Resources.Count - (cropScroll ? 1 : 0) && i < 4; i++) - { - var craftResource = m_CraftItem.Resources[i]; + if (context != null) + { + resIndex = _craftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex; + } - var type = craftResource.ItemType; - var nameString = craftResource.Name.String; - var nameNumber = craftResource.Name.Number; + var cropScroll = _craftItem.Resources.Count > 1 + && _craftItem.Resources[^1].ItemType == typeofBlankScroll + && typeofSpellScroll.IsAssignableFrom(_craftItem.ItemType); - // Resource Mutation - if (type == res.ResType && resIndex > -1) - { - var subResource = res.GetAt(resIndex); + for (var i = 0; i < _craftItem.Resources.Count - (cropScroll ? 1 : 0) && i < 4; i++) + { + var craftResource = _craftItem.Resources[i]; - type = subResource.ItemType; + var type = craftResource.ItemType; + var nameString = craftResource.Name.String; + var nameNumber = craftResource.Name.Number; - nameString = subResource.Name.String; - nameNumber = subResource.GenericNameNumber; + // Resource Mutation + if (type == res.ResType && resIndex > -1) + { + var subResource = res.GetAt(resIndex); - if (nameNumber <= 0) - { - nameNumber = subResource.Name.Number; - } - } - // ****************** + type = subResource.ItemType; - if (!retainedColor && m_CraftItem.RetainsColorFrom(m_CraftSystem, type)) - { - retainedColor = true; - AddHtmlLocalized( - 170, - 302 + m_OtherCount++ * 20, - 310, - 18, - 1044152, // * The item retains the color of this material - LabelColor - ); - AddLabel(500, 219 + i * 20, LabelHue, "*"); - } + nameString = subResource.Name.String; + nameNumber = subResource.GenericNameNumber; - if (nameNumber > 0) + if (nameNumber <= 0) { - AddHtmlLocalized(170, 219 + i * 20, 310, 18, nameNumber, LabelColor); + nameNumber = subResource.Name.Number; } - else - { - AddLabel(170, 219 + i * 20, LabelHue, nameString); - } - - AddLabel(430, 219 + i * 20, LabelHue, craftResource.Amount.ToString()); } + // ****************** - if (m_CraftItem.NameNumber == 1041267) // runebook + if (!retainedColor && _craftItem.RetainsColorFrom(_craftSystem, type)) { - AddHtmlLocalized(170, 219 + m_CraftItem.Resources.Count * 20, 310, 18, 1044447, LabelColor); - AddLabel(430, 219 + m_CraftItem.Resources.Count * 20, LabelHue, "1"); - } - - if (cropScroll) - { - AddHtmlLocalized( + retainedColor = true; + builder.AddHtmlLocalized( 170, - 302 + m_OtherCount++ * 20, - 360, + 302 + otherCount++ * 20, + 310, 18, - 1044379, // Inscribing scrolls also requires a blank scroll and mana. + 1044152, // * The item retains the color of this material LabelColor ); + builder.AddLabel(500, 219 + i * 20, LabelHue, "*"); + } + + if (nameNumber > 0) + { + builder.AddHtmlLocalized(170, 219 + i * 20, 310, 18, nameNumber, LabelColor); } + else + { + builder.AddLabel(170, 219 + i * 20, LabelHue, nameString); + } + + builder.AddLabel(430, 219 + i * 20, LabelHue, craftResource.Amount.ToString()); } - public override void OnResponse(NetState sender, in RelayInfo info) + if (_craftItem.NameNumber == 1041267) // runebook { - // Back Button - if (info.ButtonID == 0) + builder.AddHtmlLocalized(170, 219 + _craftItem.Resources.Count * 20, 310, 18, 1044447, LabelColor); + builder.AddLabel(430, 219 + _craftItem.Resources.Count * 20, LabelHue, "1"); + } + + if (cropScroll) + { + builder.AddHtmlLocalized( + 170, + 302 + otherCount++ * 20, + 360, + 18, + 1044379, // Inscribing scrolls also requires a blank scroll and mana. + LabelColor + ); + } + } + + public override void OnResponse(NetState sender, in RelayInfo info) + { + var from = sender.Mobile; + + // Back Button + if (info.ButtonID == 0) + { + var craftGump = new CraftGump(from, _craftSystem, _tool, null); + from.SendGump(craftGump); + } + else // Make Button + { + var num = _craftSystem.CanCraft(from, _tool, _craftItem.ItemType); + + if (num > 0) { - var craftGump = new CraftGump(m_From, m_CraftSystem, m_Tool, null); - m_From.SendGump(craftGump); + from.SendGump(new CraftGump(from, _craftSystem, _tool, num)); } - else // Make Button + else { - var num = m_CraftSystem.CanCraft(m_From, m_Tool, m_CraftItem.ItemType); + Type type = null; - if (num > 0) - { - m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, num)); - } - else - { - Type type = null; + var context = _craftSystem.GetContext(from); - var context = m_CraftSystem.GetContext(m_From); + if (context != null) + { + var res = _craftItem.UseSubRes2 ? _craftSystem.CraftSubRes2 : _craftSystem.CraftSubRes; + var resIndex = _craftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex; - if (context != null) + if (resIndex > -1) { - var res = m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes; - var resIndex = m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex; - - if (resIndex > -1) - { - type = res.GetAt(resIndex).ItemType; - } + type = res.GetAt(resIndex).ItemType; } - - m_CraftSystem.CreateItem(m_From, m_CraftItem.ItemType, type, m_Tool, m_CraftItem); } + + _craftSystem.CreateItem(from, _craftItem.ItemType, type, _tool, _craftItem); } } } diff --git a/Projects/UOContent/Engines/Craft/Core/CraftItem.cs b/Projects/UOContent/Engines/Craft/Core/CraftItem.cs index 42e7856f7f..3843d07d17 100644 --- a/Projects/UOContent/Engines/Craft/Core/CraftItem.cs +++ b/Projects/UOContent/Engines/Craft/Core/CraftItem.cs @@ -1400,7 +1400,6 @@ protected override void OnTick() m_From.SendGump( new QueryMakersMarkGump( quality, - m_From, m_CraftItem, m_CraftSystem, m_TypeRes, diff --git a/Projects/UOContent/Engines/Craft/Core/QueryMakersMarkGump.cs b/Projects/UOContent/Engines/Craft/Core/QueryMakersMarkGump.cs index 60f6fec454..e2bbd57ea7 100644 --- a/Projects/UOContent/Engines/Craft/Core/QueryMakersMarkGump.cs +++ b/Projects/UOContent/Engines/Craft/Core/QueryMakersMarkGump.cs @@ -3,59 +3,58 @@ using Server.Items; using Server.Network; -namespace Server.Engines.Craft +namespace Server.Engines.Craft; + +public class QueryMakersMarkGump : StaticGump { - public class QueryMakersMarkGump : Gump + private readonly CraftItem _craftItem; + private readonly CraftSystem _craftSystem; + private readonly int _quality; + private readonly BaseTool _tool; + private readonly Type _typeRes; + + public override bool Singleton => true; + + public QueryMakersMarkGump(int quality, CraftItem craftItem, CraftSystem craftSystem, Type typeRes, BaseTool tool) + : base(100, 200) { - private readonly CraftItem m_CraftItem; - private readonly CraftSystem m_CraftSystem; - private readonly Mobile m_From; - private readonly int m_Quality; - private readonly BaseTool m_Tool; - private readonly Type m_TypeRes; - - public override bool Singleton => true; - - public QueryMakersMarkGump( - int quality, Mobile from, CraftItem craftItem, CraftSystem craftSystem, Type typeRes, - BaseTool tool - ) : base(100, 200) - { - m_Quality = quality; - m_From = from; - m_CraftItem = craftItem; - m_CraftSystem = craftSystem; - m_TypeRes = typeRes; - m_Tool = tool; + _quality = quality; + _craftItem = craftItem; + _craftSystem = craftSystem; + _typeRes = typeRes; + _tool = tool; + } - AddPage(0); + protected override void BuildLayout(ref StaticGumpBuilder builder) + { + builder.AddPage(); - AddBackground(0, 0, 220, 170, 5054); - AddBackground(10, 10, 200, 150, 3000); + builder.AddBackground(0, 0, 220, 170, 5054); + builder.AddBackground(10, 10, 200, 150, 3000); - AddHtmlLocalized(20, 20, 180, 80, 1018317); // Do you wish to place your maker's mark on this item? + builder.AddHtmlLocalized(20, 20, 180, 80, 1018317); // Do you wish to place your maker's mark on this item? - AddHtmlLocalized(55, 100, 140, 25, 1011011); // CONTINUE - AddButton(20, 100, 4005, 4007, 1); + builder.AddHtmlLocalized(55, 100, 140, 25, 1011011); // CONTINUE + builder.AddButton(20, 100, 4005, 4007, 1); - AddHtmlLocalized(55, 125, 140, 25, 1011012); // CANCEL - AddButton(20, 125, 4005, 4007, 0); - } + builder.AddHtmlLocalized(55, 125, 140, 25, 1011012); // CANCEL + builder.AddButton(20, 125, 4005, 4007, 0); + } + + public override void OnResponse(NetState sender, in RelayInfo info) + { + var from = sender.Mobile; + var makersMark = info.ButtonID == 1; - public override void OnResponse(NetState sender, in RelayInfo info) + if (makersMark) { - var makersMark = info.ButtonID == 1; - - if (makersMark) - { - m_From.SendLocalizedMessage(501808); // You mark the item. - } - else - { - m_From.SendLocalizedMessage(501809); // Cancelled mark. - } - - m_CraftItem.CompleteCraft(m_Quality, makersMark, m_From, m_CraftSystem, m_TypeRes, m_Tool, null); + from.SendLocalizedMessage(501808); // You mark the item. } + else + { + from.SendLocalizedMessage(501809); // Cancelled mark. + } + + _craftItem.CompleteCraft(_quality, makersMark, from, _craftSystem, _typeRes, _tool, null); } } From ed87df1a61df123f36a473cfd0fbfed9d06371d3 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 27 Jan 2025 14:00:32 -0800 Subject: [PATCH 2/4] fix: Converts bedroll/insurance gumps to static. (#2096) --- .../Items/Skill Items/Camping/Bedroll.cs | 31 +- .../Items/Skill Items/Camping/Campfire.cs | 38 +-- Projects/UOContent/Mobiles/PlayerMobile.cs | 312 ++++++++---------- 3 files changed, 174 insertions(+), 207 deletions(-) diff --git a/Projects/UOContent/Items/Skill Items/Camping/Bedroll.cs b/Projects/UOContent/Items/Skill Items/Camping/Bedroll.cs index dd6375720f..33aebc3ce3 100644 --- a/Projects/UOContent/Items/Skill Items/Camping/Bedroll.cs +++ b/Projects/UOContent/Items/Skill Items/Camping/Bedroll.cs @@ -55,23 +55,26 @@ public override void OnDoubleClick(Mobile from) } } - private class LogoutGump : Gump + private class LogoutGump : StaticGump { - private Bedroll _dedroll; + private readonly Bedroll _bedroll; private TimerExecutionToken _closeTimerToken; - private CampfireEntry _entry; + private readonly CampfireEntry _entry; public LogoutGump(CampfireEntry entry, Bedroll bedroll) : base(100, 0) { _entry = entry; - _dedroll = bedroll; + _bedroll = bedroll; Timer.StartTimer(TimeSpan.FromSeconds(10.0), CloseGump, out _closeTimerToken); + } - AddBackground(0, 0, 400, 350, 0xA28); + protected override void BuildLayout(ref StaticGumpBuilder builder) + { + builder.AddBackground(0, 0, 400, 350, 0xA28); - AddHtmlLocalized(100, 20, 200, 35, 1011015); //
Logging out via camping
+ builder.AddHtmlLocalized(100, 20, 200, 35, 1011015); //
Logging out via camping
/* Using a bedroll in the safety of a camp will log you out of the game safely. * If this is what you wish to do choose CONTINUE and you will be logged out. @@ -79,13 +82,13 @@ public LogoutGump(CampfireEntry entry, Bedroll bedroll) : base(100, 0) * The camp will remain secure for 10 seconds at which time this window will close * and you not be logged out. */ - AddHtmlLocalized(50, 55, 300, 140, 1011016, true, true); + builder.AddHtmlLocalized(50, 55, 300, 140, 1011016, true, true); - AddButton(45, 298, 0xFA5, 0xFA7, 1); - AddHtmlLocalized(80, 300, 110, 35, 1011011); // CONTINUE + builder.AddButton(45, 298, 0xFA5, 0xFA7, 1); + builder.AddHtmlLocalized(80, 300, 110, 35, 1011011); // CONTINUE - AddButton(200, 298, 0xFA5, 0xFA7, 0); - AddHtmlLocalized(235, 300, 110, 35, 1011012); // CANCEL + builder.AddButton(200, 298, 0xFA5, 0xFA7, 0); + builder.AddHtmlLocalized(235, 300, 110, 35, 1011012); // CANCEL } public override void OnResponse(NetState sender, in RelayInfo info) @@ -99,10 +102,10 @@ public override void OnResponse(NetState sender, in RelayInfo info) return; } - if (info.ButtonID == 1 && _entry.Safe && _dedroll.Parent == null && _dedroll.IsAccessibleTo(pm) - && _dedroll.VerifyMove(pm) && _dedroll.Map == pm.Map && pm.InRange(_dedroll, 2)) + if (info.ButtonID == 1 && _entry.Safe && _bedroll.Parent == null && _bedroll.IsAccessibleTo(pm) + && _bedroll.VerifyMove(pm) && _bedroll.Map == pm.Map && pm.InRange(_bedroll, 2)) { - pm.PlaceInBackpack(_dedroll); + pm.PlaceInBackpack(_bedroll); pm.BedrollLogout = true; sender.Disconnect("Used a bedroll to log out."); diff --git a/Projects/UOContent/Items/Skill Items/Camping/Campfire.cs b/Projects/UOContent/Items/Skill Items/Camping/Campfire.cs index 7aa45e4c0c..c45962a3ab 100644 --- a/Projects/UOContent/Items/Skill Items/Camping/Campfire.cs +++ b/Projects/UOContent/Items/Skill Items/Camping/Campfire.cs @@ -15,11 +15,11 @@ public enum CampfireStatus [SerializationGenerator(0, false)] public partial class Campfire : Item { - public static readonly int SecureRange = 7; + public const int SecureRange = 7; - private static readonly Dictionary m_Table = new(); + private static readonly Dictionary _table = []; - private readonly List m_Entries; + private readonly List _entries; private TimerExecutionToken _timerToken; @@ -28,8 +28,7 @@ public Campfire() : base(0xDE3) Movable = false; Light = LightType.Circle300; - m_Entries = new List(); - + _entries = []; Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnTick, out _timerToken); } @@ -79,16 +78,12 @@ public CampfireStatus Status } } - public static CampfireEntry GetEntry(Mobile player) - { - m_Table.TryGetValue(player, out var value); - return value; - } + public static CampfireEntry GetEntry(Mobile player) => _table.GetValueOrDefault(player); public static void RemoveEntry(CampfireEntry entry) { - m_Table.Remove(entry.Player); - entry.Fire.m_Entries.Remove(entry); + _table.Remove(entry.Player); + entry.Fire._entries.Remove(entry); } private void OnTick() @@ -114,9 +109,9 @@ private void OnTick() return; } - for (var i = m_Entries.Count - 1; i >= 0; i--) + for (var i = _entries.Count - 1; i >= 0; i--) { - var entry = m_Entries[i]; + var entry = _entries[i]; if (!entry.Valid || entry.Player.NetState == null) { @@ -135,8 +130,8 @@ private void OnTick() { var entry = new CampfireEntry(pm, this); - m_Table[pm] = entry; - m_Entries.Add(entry); + _table[pm] = entry; + _entries.Add(entry); pm.SendLocalizedMessage(500620); // You feel it would take a few moments to secure your camp. } @@ -145,24 +140,23 @@ private void OnTick() private void ClearEntries() { - if (m_Entries == null) + if (_entries == null) { return; } - foreach (var entry in m_Entries) + foreach (var entry in _entries) { - m_Table.Remove(entry.Player); + _table.Remove(entry.Player); } - m_Entries.Clear(); - m_Entries.TrimExcess(); + _entries.Clear(); + _entries.TrimExcess(); } public override void OnAfterDelete() { _timerToken.Cancel(); - ClearEntries(); } diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index d4861299e4..9da05f1c13 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -3853,11 +3853,8 @@ private void AutoRenewInventoryInsurance() return; } - SendLocalizedMessage( - 1060881, - "", - 0x23 - ); // You have selected to automatically reinsure all insured items upon death + // You have selected to automatically reinsure all insured items upon death + SendLocalizedMessage(1060881, "", 0x23); AutoRenewInsurance = true; } @@ -3868,20 +3865,14 @@ private void CancelRenewInventoryInsurance() return; } - if (Core.SE && NetState is { } ns) + if (Core.SE) { - if (!ns.HasGump()) - { - ns.SendGump(new CancelRenewInventoryInsuranceGump(this, null)); - } + NetState?.SendGump(new CancelRenewInventoryInsuranceGump(null)); } else { - SendLocalizedMessage( - 1061075, - "", - 0x23 - ); // You have cancelled automatically reinsuring all insured items upon death + // You have cancelled automatically reinsuring all insured items upon death + SendLocalizedMessage(1061075, "", 0x23); AutoRenewInsurance = false; } } @@ -3917,18 +3908,15 @@ private void OpenItemInsuranceMenu() } // TODO: Investigate item sorting - - if (NetState is { } ns) + if (NetState != null) { - ns.CloseGump(); - if (queue.Count == 0) { SendLocalizedMessage(1114915, "", 0x35); // None of your current items meet the requirements for insurance. } else { - ns.SendGump(new ItemInsuranceMenuGump(this, queue.ToArray())); + NetState.SendGump(new ItemInsuranceMenuGump(this, queue.ToArray())); } } } @@ -4615,43 +4603,35 @@ public override void OnClick(Mobile from, IEntity target) } } - private class CancelRenewInventoryInsuranceGump : Gump + private class CancelRenewInventoryInsuranceGump : StaticGump { - private readonly ItemInsuranceMenuGump m_InsuranceGump; - private readonly PlayerMobile m_Player; + private readonly ItemInsuranceMenuGump _insuranceGump; - public CancelRenewInventoryInsuranceGump(PlayerMobile player, ItemInsuranceMenuGump insuranceGump) : base( - 250, - 200 - ) - { - m_Player = player; - m_InsuranceGump = insuranceGump; + public override bool Singleton => true; + + public CancelRenewInventoryInsuranceGump(ItemInsuranceMenuGump insuranceGump) : base(250, 200) => + _insuranceGump = insuranceGump; - AddBackground(0, 0, 240, 142, 0x13BE); - AddImageTiled(6, 6, 228, 100, 0xA40); - AddImageTiled(6, 116, 228, 20, 0xA40); - AddAlphaRegion(6, 6, 228, 142); + protected override void BuildLayout(ref StaticGumpBuilder builder) + { + builder.AddBackground(0, 0, 240, 142, 0x13BE); + builder.AddImageTiled(6, 6, 228, 100, 0xA40); + builder.AddImageTiled(6, 116, 228, 20, 0xA40); + builder.AddAlphaRegion(6, 6, 228, 142); - AddHtmlLocalized( - 8, - 8, - 228, - 100, - 1071021, - 0x7FFF - ); // You are about to disable inventory insurance auto-renewal. + // You are about to disable inventory insurance auto-renewal. + builder.AddHtmlLocalized(8, 8, 228, 100, 1071021, 0x7FFF); - AddButton(6, 116, 0xFB1, 0xFB2, 0); - AddHtmlLocalized(40, 118, 450, 20, 1060051, 0x7FFF); // CANCEL + builder.AddButton(6, 116, 0xFB1, 0xFB2, 0); + builder.AddHtmlLocalized(40, 118, 450, 20, 1060051, 0x7FFF); // CANCEL - AddButton(114, 116, 0xFA5, 0xFA7, 1); - AddHtmlLocalized(148, 118, 450, 20, 1071022, 0x7FFF); // DISABLE IT! + builder.AddButton(114, 116, 0xFA5, 0xFA7, 1); + builder.AddHtmlLocalized(148, 118, 450, 20, 1071022, 0x7FFF); // DISABLE IT! } public override void OnResponse(NetState sender, in RelayInfo info) { - if (!m_Player.CheckAlive()) + if (sender.Mobile is not PlayerMobile pm || !pm.CheckAlive()) { return; } @@ -4659,106 +4639,103 @@ public override void OnResponse(NetState sender, in RelayInfo info) if (info.ButtonID == 1) { // You have cancelled automatically reinsuring all insured items upon death - m_Player.SendLocalizedMessage(1061075, "", 0x23); - m_Player.AutoRenewInsurance = false; + pm.SendLocalizedMessage(1061075, "", 0x23); + pm.AutoRenewInsurance = false; } else { - m_Player.SendLocalizedMessage(1042021); // Cancelled. + pm.SendLocalizedMessage(1042021); // Cancelled. } - if (m_InsuranceGump != null) + if (_insuranceGump != null) { - m_Player.SendGump(m_InsuranceGump.NewInstance()); + pm.SendGump(_insuranceGump); } } } - private class ItemInsuranceMenuGump : Gump + private class ItemInsuranceMenuGump : DynamicGump { - private readonly PlayerMobile m_From; - private readonly bool[] m_Insure; - private readonly Item[] m_Items; - private readonly int m_Page; + private readonly PlayerMobile _from; + private readonly bool[] _insure; + private readonly Item[] _items; + private int _page; + + public override bool Singleton => true; - public ItemInsuranceMenuGump(PlayerMobile from, Item[] items, bool[] insure = null, int page = 0) - : base(25, 50) + public ItemInsuranceMenuGump(PlayerMobile from, Item[] items) : base(25, 50) { - m_From = from; - m_Items = items; + _from = from; + _items = items; + _insure = new bool[items.Length]; - if (insure == null) + for (var i = 0; i < items.Length; ++i) { - insure = new bool[items.Length]; - - for (var i = 0; i < items.Length; ++i) - { - insure[i] = items[i].Insured; - } + _insure[i] = items[i].Insured; } + } - m_Insure = insure; - m_Page = page; - - AddPage(0); + protected override void BuildLayout(ref DynamicGumpBuilder builder) + { + builder.AddPage(); - AddBackground(0, 0, 520, 510, 0x13BE); - AddImageTiled(10, 10, 500, 30, 0xA40); - AddImageTiled(10, 50, 500, 355, 0xA40); - AddImageTiled(10, 415, 500, 80, 0xA40); - AddAlphaRegion(10, 10, 500, 485); + builder.AddBackground(0, 0, 520, 510, 0x13BE); + builder.AddImageTiled(10, 10, 500, 30, 0xA40); + builder.AddImageTiled(10, 50, 500, 355, 0xA40); + builder.AddImageTiled(10, 415, 500, 80, 0xA40); + builder.AddAlphaRegion(10, 10, 500, 485); - AddButton(15, 470, 0xFB1, 0xFB2, 0); - AddHtmlLocalized(50, 472, 80, 20, 1011012, 0x7FFF); // CANCEL + builder.AddButton(15, 470, 0xFB1, 0xFB2, 0); + builder.AddHtmlLocalized(50, 472, 80, 20, 1011012, 0x7FFF); // CANCEL - if (from.AutoRenewInsurance) + if (_from.AutoRenewInsurance) { - AddButton(360, 10, 9723, 9724, 1); + builder.AddButton(360, 10, 9723, 9724, 1); } else { - AddButton(360, 10, 9720, 9722, 1); + builder.AddButton(360, 10, 9720, 9722, 1); } - AddHtmlLocalized(395, 14, 105, 20, 1114122, 0x7FFF); // AUTO REINSURE + builder.AddHtmlLocalized(395, 14, 105, 20, 1114122, 0x7FFF); // AUTO REINSURE - AddButton(395, 470, 0xFA5, 0xFA6, 2); - AddHtmlLocalized(430, 472, 50, 20, 1006044, 0x7FFF); // OK + builder.AddButton(395, 470, 0xFA5, 0xFA6, 2); + builder.AddHtmlLocalized(430, 472, 50, 20, 1006044, 0x7FFF); // OK - AddHtmlLocalized(10, 14, 150, 20, 1114121, 0x7FFF); //
ITEM INSURANCE MENU
+ builder.AddHtmlLocalized(10, 14, 150, 20, 1114121, 0x7FFF); //
ITEM INSURANCE MENU
- AddHtmlLocalized(45, 54, 70, 20, 1062214, 0x7FFF); // Item - AddHtmlLocalized(250, 54, 70, 20, 1061038, 0x7FFF); // Cost - AddHtmlLocalized(400, 54, 70, 20, 1114311, 0x7FFF); // Insured + builder.AddHtmlLocalized(45, 54, 70, 20, 1062214, 0x7FFF); // Item + builder.AddHtmlLocalized(250, 54, 70, 20, 1061038, 0x7FFF); // Cost + builder.AddHtmlLocalized(400, 54, 70, 20, 1114311, 0x7FFF); // Insured - var balance = Banker.GetBalance(from); + var balance = Banker.GetBalance(_from); var cost = 0; - for (var i = 0; i < items.Length; ++i) + for (var i = 0; i < _items.Length; ++i) { - if (insure[i]) + if (_insure[i]) { - cost += GetInsuranceCost(items[i]); + cost += GetInsuranceCost(_items[i]); } } - AddHtmlLocalized(15, 420, 300, 20, 1114310, 0x7FFF); // GOLD AVAILABLE: - AddLabel(215, 420, 0x481, balance.ToString()); - AddHtmlLocalized(15, 435, 300, 20, 1114123, 0x7FFF); // TOTAL COST OF INSURANCE: - AddLabel(215, 435, 0x481, cost.ToString()); + builder.AddHtmlLocalized(15, 420, 300, 20, 1114310, 0x7FFF); // GOLD AVAILABLE: + builder.AddLabel(215, 420, 0x481, balance.ToString()); + builder.AddHtmlLocalized(15, 435, 300, 20, 1114123, 0x7FFF); // TOTAL COST OF INSURANCE: + builder.AddLabel(215, 435, 0x481, cost.ToString()); if (cost != 0) { - AddHtmlLocalized(15, 450, 300, 20, 1114125, 0x7FFF); // NUMBER OF DEATHS PAYABLE: - AddLabel(215, 450, 0x481, (balance / cost).ToString()); + builder.AddHtmlLocalized(15, 450, 300, 20, 1114125, 0x7FFF); // NUMBER OF DEATHS PAYABLE: + builder.AddLabel(215, 450, 0x481, (balance / cost).ToString()); } - for (int i = page * 4, y = 72; i < (page + 1) * 4 && i < items.Length; ++i, y += 75) + for (int i = _page * 4, y = 72; i < (_page + 1) * 4 && i < _items.Length; ++i, y += 75) { - var item = items[i]; + var item = _items[i]; var b = ItemBounds.Table[item.ItemID]; - AddImageTiledButton( + builder.AddImageTiledButton( 40, y, 0x918, @@ -4771,38 +4748,36 @@ public ItemInsuranceMenuGump(PlayerMobile from, Item[] items, bool[] insure = nu 40 - b.Width / 2 - b.X, 30 - b.Height / 2 - b.Y ); - AddItemProperty(item.Serial); + builder.AddItemProperty(item.Serial); - if (insure[i]) + if (_insure[i]) { - AddButton(400, y, 9723, 9724, 100 + i); - AddLabel(250, y, 0x481, GetInsuranceCost(item).ToString()); + builder.AddButton(400, y, 9723, 9724, 100 + i); + builder.AddLabel(250, y, 0x481, GetInsuranceCost(item).ToString()); } else { - AddButton(400, y, 9720, 9722, 100 + i); - AddLabel(250, y, 0x66C, GetInsuranceCost(item).ToString()); + builder.AddButton(400, y, 9720, 9722, 100 + i); + builder.AddLabel(250, y, 0x66C, GetInsuranceCost(item).ToString()); } } - if (page >= 1) + if (_page >= 1) { - AddButton(15, 380, 0xFAE, 0xFAF, 3); - AddHtmlLocalized(50, 380, 450, 20, 1044044, 0x7FFF); // PREV PAGE + builder.AddButton(15, 380, 0xFAE, 0xFAF, 3); + builder.AddHtmlLocalized(50, 380, 450, 20, 1044044, 0x7FFF); // PREV PAGE } - if ((page + 1) * 4 < items.Length) + if ((_page + 1) * 4 < _items.Length) { - AddButton(400, 380, 0xFA5, 0xFA7, 4); - AddHtmlLocalized(435, 380, 70, 20, 1044045, 0x7FFF); // NEXT PAGE + builder.AddButton(400, 380, 0xFA5, 0xFA7, 4); + builder.AddHtmlLocalized(435, 380, 70, 20, 1044045, 0x7FFF); // NEXT PAGE } } - public ItemInsuranceMenuGump NewInstance() => new(m_From, m_Items, m_Insure, m_Page); - public override void OnResponse(NetState sender, in RelayInfo info) { - if (info.ButtonID == 0 || !m_From.CheckAlive()) + if (info.ButtonID == 0 || !_from.CheckAlive()) { return; } @@ -4811,41 +4786,40 @@ public override void OnResponse(NetState sender, in RelayInfo info) { case 1: // Auto Reinsure { - if (m_From.AutoRenewInsurance) + if (_from.AutoRenewInsurance) { - if (!m_From.HasGump()) - { - m_From.SendGump(new CancelRenewInventoryInsuranceGump(m_From, this)); - } + _from.SendGump(new CancelRenewInventoryInsuranceGump(this)); } else { - m_From.AutoRenewInventoryInsurance(); - m_From.SendGump(new ItemInsuranceMenuGump(m_From, m_Items, m_Insure, m_Page)); + _from.AutoRenewInventoryInsurance(); + _from.SendGump(this); } break; } case 2: // OK { - m_From.SendGump(new ItemInsuranceMenuConfirmGump(m_From, m_Items, m_Insure, m_Page)); + _from.SendGump(new ItemInsuranceMenuConfirmGump(this)); break; } case 3: // Prev { - if (m_Page >= 1) + if (_page >= 1) { - m_From.SendGump(new ItemInsuranceMenuGump(m_From, m_Items, m_Insure, m_Page - 1)); + _page--; + _from.SendGump(this); } break; } case 4: // Next { - if ((m_Page + 1) * 4 < m_Items.Length) + if ((_page + 1) * 4 < _items.Length) { - m_From.SendGump(new ItemInsuranceMenuGump(m_From, m_Items, m_Insure, m_Page + 1)); + _page++; + _from.SendGump(this); } break; @@ -4854,71 +4828,67 @@ public override void OnResponse(NetState sender, in RelayInfo info) { var idx = info.ButtonID - 100; - if (idx >= 0 && idx < m_Items.Length) + if (idx >= 0 && idx < _items.Length) { - m_Insure[idx] = !m_Insure[idx]; + _insure[idx] = !_insure[idx]; } - m_From.SendGump(new ItemInsuranceMenuGump(m_From, m_Items, m_Insure, m_Page)); + _from.SendGump(this); break; } } } - } - private class ItemInsuranceMenuConfirmGump : Gump - { - private readonly PlayerMobile m_From; - private readonly bool[] m_Insure; - private readonly Item[] m_Items; - private readonly int m_Page; - - public ItemInsuranceMenuConfirmGump(PlayerMobile from, Item[] items, bool[] insure, int page) - : base(250, 200) + private class ItemInsuranceMenuConfirmGump : StaticGump { - m_From = from; - m_Items = items; - m_Insure = insure; - m_Page = page; + private readonly ItemInsuranceMenuGump _parentGump; - AddBackground(0, 0, 240, 142, 0x13BE); - AddImageTiled(6, 6, 228, 100, 0xA40); - AddImageTiled(6, 116, 228, 20, 0xA40); - AddAlphaRegion(6, 6, 228, 142); + public ItemInsuranceMenuConfirmGump(ItemInsuranceMenuGump parentGump) : base(250, 200) => + _parentGump = parentGump; - AddHtmlLocalized(8, 8, 228, 100, 1114300, 0x7FFF); // Do you wish to insure all newly selected items? + protected override void BuildLayout(ref StaticGumpBuilder builder) + { + builder.AddBackground(0, 0, 240, 142, 0x13BE); + builder.AddImageTiled(6, 6, 228, 100, 0xA40); + builder.AddImageTiled(6, 116, 228, 20, 0xA40); + builder.AddAlphaRegion(6, 6, 228, 142); - AddButton(6, 116, 0xFB1, 0xFB2, 0); - AddHtmlLocalized(40, 118, 450, 20, 1060051, 0x7FFF); // CANCEL + builder.AddHtmlLocalized(8, 8, 228, 100, 1114300, 0x7FFF); // Do you wish to insure all newly selected items? - AddButton(114, 116, 0xFA5, 0xFA7, 1); - AddHtmlLocalized(148, 118, 450, 20, 1073996, 0x7FFF); // ACCEPT - } + builder.AddButton(6, 116, 0xFB1, 0xFB2, 0); + builder.AddHtmlLocalized(40, 118, 450, 20, 1060051, 0x7FFF); // CANCEL - public override void OnResponse(NetState sender, in RelayInfo info) - { - if (!m_From.CheckAlive()) - { - return; + builder.AddButton(114, 116, 0xFA5, 0xFA7, 1); + builder.AddHtmlLocalized(148, 118, 450, 20, 1073996, 0x7FFF); // ACCEPT } - if (info.ButtonID == 1) + public override void OnResponse(NetState sender, in RelayInfo info) { - for (var i = 0; i < m_Items.Length; ++i) + if (sender.Mobile is not PlayerMobile pm || !pm.CheckAlive()) { - var item = m_Items[i]; + return; + } - if (item.Insured != m_Insure[i]) + if (info.ButtonID == 1) + { + var items = _parentGump._items; + var insure = _parentGump._insure; + for (var i = 0; i < items.Length; ++i) { - m_From.ToggleItemInsurance_Callback(m_From, item, false); + var item = items[i]; + + if (item.Insured != insure[i]) + { + pm.ToggleItemInsurance_Callback(pm, item, false); + } } } - } - else - { - m_From.SendLocalizedMessage(1042021); // Cancelled. - m_From.SendGump(new ItemInsuranceMenuGump(m_From, m_Items, m_Insure, m_Page)); + else + { + pm.SendLocalizedMessage(1042021); // Cancelled. + pm.SendGump(_parentGump); + } } } } From cbae44ef2093c4ec53b85961ed718b293c23ba09 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 27 Jan 2025 17:57:25 -0800 Subject: [PATCH 3/4] fix: Updates SummonFamiliar & Tracking gumps to static (#2098) --- .../Skills/Tracking/TrackingGumpTests.cs | 28 - .../UOContent/Skills/Tracking/Tracking.cs | 499 +++++++++--------- .../Spells/Necromancy/SummonFamiliar.cs | 73 ++- 3 files changed, 284 insertions(+), 316 deletions(-) delete mode 100644 Projects/UOContent.Tests/Tests/Skills/Tracking/TrackingGumpTests.cs diff --git a/Projects/UOContent.Tests/Tests/Skills/Tracking/TrackingGumpTests.cs b/Projects/UOContent.Tests/Tests/Skills/Tracking/TrackingGumpTests.cs deleted file mode 100644 index c55cf740c6..0000000000 --- a/Projects/UOContent.Tests/Tests/Skills/Tracking/TrackingGumpTests.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Server.Gumps; -using Server.Mobiles; -using Server.SkillHandlers; -using Server.Tests; -using Server.Tests.Network; -using Xunit; - -namespace UOContent.Tests; - -public class TrackingGumpTests : IClassFixture -{ - [Fact] - // Regression test used to identify an issue with AddItem compilation of the packet - public void TestTrackingGump() - { - var pm = new PlayerMobile(); - pm.Skills.Tracking.BaseFixedPoint = 1000; - var g = new TrackWhatGump(pm); - - var ns = PacketTestUtilities.CreateTestNetState(); - - var expected = g.Compile(ns).Compile(); - ns.SendGump(g); - - var result = ns.SendPipe.Reader.AvailableToRead(); - AssertThat.Equal(result, expected); - } -} diff --git a/Projects/UOContent/Skills/Tracking/Tracking.cs b/Projects/UOContent/Skills/Tracking/Tracking.cs index f59f3462a2..0cb1f792aa 100644 --- a/Projects/UOContent/Skills/Tracking/Tracking.cs +++ b/Projects/UOContent/Skills/Tracking/Tracking.cs @@ -7,350 +7,349 @@ using Server.Spells; using Server.Spells.Necromancy; -namespace Server.SkillHandlers +namespace Server.SkillHandlers; + +public static class Tracking { - public static class Tracking - { - private static readonly Dictionary _table = new(); + private static readonly Dictionary _table = new(); - public static unsafe void Configure() - { - IncomingExtendedCommandPackets.RegisterExtended(0x07, true, &QuestArrow); - } + public static unsafe void Configure() + { + IncomingExtendedCommandPackets.RegisterExtended(0x07, true, &QuestArrow); + } - public static void Initialize() - { - SkillInfo.Table[(int)SkillName.Tracking].Callback = OnUse; - } + public static void Initialize() + { + SkillInfo.Table[(int)SkillName.Tracking].Callback = OnUse; + } - public static void QuestArrow(NetState state, SpanReader reader) + public static void QuestArrow(NetState state, SpanReader reader) + { + if (state.Mobile is PlayerMobile from) { - if (state.Mobile is PlayerMobile from) - { - var rightClick = reader.ReadBoolean(); + var rightClick = reader.ReadBoolean(); - from.QuestArrow?.OnClick(rightClick); - } + from.QuestArrow?.OnClick(rightClick); } + } - public static TimeSpan OnUse(Mobile m) + public static TimeSpan OnUse(Mobile m) + { + if (m is PlayerMobile pm) { - if (m is PlayerMobile pm) - { - m.SendLocalizedMessage(1011350); // What do you wish to track? + m.SendLocalizedMessage(1011350); // What do you wish to track? - var gumps = pm.GetGumps(); - - gumps.Close(); - gumps.Close(); - gumps.Send(new TrackWhatGump(pm)); - } + var gumps = pm.GetGumps(); - return TimeSpan.FromSeconds(10.0); // 10 second delay before being able to re-use a skill + gumps.Close(); + gumps.Close(); + gumps.Send(new TrackWhatGump()); } - public static void AddInfo(Mobile tracker, Mobile target) + return TimeSpan.FromSeconds(10.0); // 10 second delay before being able to re-use a skill + } + + public static void AddInfo(Mobile tracker, Mobile target) + { + var info = new TrackingInfo(tracker, target); + _table[tracker] = info; + } + + public static double GetStalkingBonus(Mobile tracker, Mobile target) + { + if (!_table.Remove(tracker, out var info) || info._target != target || info._map != target.Map) { - var info = new TrackingInfo(tracker, target); - _table[tracker] = info; + return 0.0; } - public static double GetStalkingBonus(Mobile tracker, Mobile target) - { - if (!_table.Remove(tracker, out var info) || info._target != target || info._map != target.Map) - { - return 0.0; - } + var xDelta = info._location.X - target.X; + var yDelta = info._location.Y - target.Y; - var xDelta = info._location.X - target.X; - var yDelta = info._location.Y - target.Y; + var bonus = Math.Sqrt(xDelta * xDelta + yDelta * yDelta); - var bonus = Math.Sqrt(xDelta * xDelta + yDelta * yDelta); + return Core.ML ? Math.Min(bonus, 10 + tracker.Skills.Tracking.Value / 10) : bonus; + } - return Core.ML ? Math.Min(bonus, 10 + tracker.Skills.Tracking.Value / 10) : bonus; - } + public static void ClearTrackingInfo(Mobile tracker) + { + _table.Remove(tracker); + } - public static void ClearTrackingInfo(Mobile tracker) - { - _table.Remove(tracker); - } + private class TrackingInfo + { + public Point2D _location; + public readonly Map _map; + public readonly Mobile _target; + public Mobile _tracker; - private class TrackingInfo + public TrackingInfo(Mobile tracker, Mobile target) { - public Point2D _location; - public readonly Map _map; - public readonly Mobile _target; - public Mobile _tracker; - - public TrackingInfo(Mobile tracker, Mobile target) - { - _tracker = tracker; - _target = target; - _location = new Point2D(target); - _map = target.Map; - } + _tracker = tracker; + _target = target; + _location = new Point2D(target); + _map = target.Map; } } +} - public class TrackWhatGump : Gump +public class TrackWhatGump : StaticGump +{ + public TrackWhatGump() : base(20, 30) { - private readonly PlayerMobile _from; - private readonly bool _success; - - public TrackWhatGump(PlayerMobile from) : base(20, 30) - { - _from = from; - _success = from.CheckSkill(SkillName.Tracking, 0.0, 21.1); + } - AddPage(0); + protected override void BuildLayout(ref StaticGumpBuilder builder) + { + builder.AddPage(); - AddBackground(0, 0, 440, 135, 5054); + builder.AddBackground(0, 0, 440, 135, 5054); - AddBackground(10, 10, 420, 75, 2620); - AddBackground(10, 85, 420, 25, 3000); + builder.AddBackground(10, 10, 420, 75, 2620); + builder.AddBackground(10, 85, 420, 25, 3000); - AddItem(20, 20, 9682); - AddButton(20, 110, 4005, 4007, 1); - AddHtmlLocalized(20, 90, 100, 20, 1018087); // Animals + builder.AddItem(20, 20, 9682); + builder.AddButton(20, 110, 4005, 4007, 1); + builder.AddHtmlLocalized(20, 90, 100, 20, 1018087); // Animals - AddItem(120, 20, 9607); - AddButton(120, 110, 4005, 4007, 2); - AddHtmlLocalized(120, 90, 100, 20, 1018088); // Monsters + builder.AddItem(120, 20, 9607); + builder.AddButton(120, 110, 4005, 4007, 2); + builder.AddHtmlLocalized(120, 90, 100, 20, 1018088); // Monsters - AddItem(220, 20, 8454); - AddButton(220, 110, 4005, 4007, 3); - AddHtmlLocalized(220, 90, 100, 20, 1018089); // Human NPCs + builder.AddItem(220, 20, 8454); + builder.AddButton(220, 110, 4005, 4007, 3); + builder.AddHtmlLocalized(220, 90, 100, 20, 1018089); // Human NPCs - AddItem(320, 20, 8455); - AddButton(320, 110, 4005, 4007, 4); - AddHtmlLocalized(320, 90, 100, 20, 1018090); // Players - } + builder.AddItem(320, 20, 8455); + builder.AddButton(320, 110, 4005, 4007, 4); + builder.AddHtmlLocalized(320, 90, 100, 20, 1018090); // Players + } - public override void OnResponse(NetState state, in RelayInfo info) + public override void OnResponse(NetState state, in RelayInfo info) + { + if (info.ButtonID is >= 1 and <= 4 && state.Mobile is PlayerMobile pm) { - if (info.ButtonID >= 1 && info.ButtonID <= 4) - { - TrackWhoGump.DisplayTo(_success, _from, info.ButtonID - 1); - } + var success = pm.CheckSkill(SkillName.Tracking, 0.0, 21.1); + TrackWhoGump.DisplayTo(success, pm, info.ButtonID - 1); } } +} - public class TrackWhoGump : Gump - { - private const int MaxClosest = 12; +public class TrackWhoGump : DynamicGump +{ + private const int MaxClosest = 12; - private readonly PlayerMobile _from; - private readonly Mobile[] _targets; - private readonly int _range; + private readonly Mobile[] _targets; + private readonly int _range; - private TrackWhoGump(PlayerMobile from, Mobile[] targets, int range) : base(20, 30) - { - _from = from; - _targets = targets; - _range = range; + private TrackWhoGump(Mobile[] targets, int range) : base(20, 30) + { + _targets = targets; + _range = range; + } - AddPage(0); + public static void DisplayTo(bool success, PlayerMobile from, int type) + { + if (!success) + { + from.SendLocalizedMessage(1018092); // You see no evidence of those in the area. + return; + } - AddBackground(0, 0, 440, 155, 5054); + var map = from.Map; - AddBackground(10, 10, 420, 75, 2620); - AddBackground(10, 85, 420, 45, 3000); + if (map == null) + { + return; + } - if (targets.Length > 4) - { - AddBackground(0, 155, 440, 155, 5054); + from.CheckSkill(SkillName.Tracking, 21.1, 100.0); // Passive gain - AddBackground(10, 165, 420, 75, 2620); - AddBackground(10, 240, 420, 45, 3000); + var range = 10 + (int)(from.Skills.Tracking.Value / 10); - if (targets.Length > 8) - { - AddBackground(0, 310, 440, 155, 5054); + var mobs = GetClosestMobs(from, range, type); - AddBackground(10, 320, 420, 75, 2620); - AddBackground(10, 395, 420, 45, 3000); - } - } + if (mobs.Length > 0) + { + from.SendGump(new TrackWhoGump(mobs, range)); + from.SendLocalizedMessage(1018093); // Select the one you would like to track. + } + else if (type == 0) + { + from.SendLocalizedMessage(502991); // You see no evidence of animals in the area. + } + else if (type == 1) + { + from.SendLocalizedMessage(502993); // You see no evidence of creatures in the area. + } + else + { + from.SendLocalizedMessage(502995); // You see no evidence of people in the area. + } + } - for (var i = 0; i < targets.Length; ++i) - { - var m = targets[i]; + protected override void BuildLayout(ref DynamicGumpBuilder builder) + { + builder.AddPage(); - AddItem(20 + i % 4 * 100, 20 + i / 4 * 155, ShrinkTable.Lookup(m)); - AddButton(20 + i % 4 * 100, 130 + i / 4 * 155, 4005, 4007, i + 1); + builder.AddBackground(0, 0, 440, 155, 5054); - if (m.Name != null) - { - AddHtml(20 + i % 4 * 100, 90 + i / 4 * 155, 90, 40, m.Name); - } - } - } + builder.AddBackground(10, 10, 420, 75, 2620); + builder.AddBackground(10, 85, 420, 45, 3000); - public static void DisplayTo(bool success, PlayerMobile from, int type) + if (_targets.Length > 4) { - if (!success) - { - from.SendLocalizedMessage(1018092); // You see no evidence of those in the area. - return; - } + builder.AddBackground(0, 155, 440, 155, 5054); - var map = from.Map; + builder.AddBackground(10, 165, 420, 75, 2620); + builder.AddBackground(10, 240, 420, 45, 3000); - if (map == null) + if (_targets.Length > 8) { - return; - } + builder.AddBackground(0, 310, 440, 155, 5054); - from.CheckSkill(SkillName.Tracking, 21.1, 100.0); // Passive gain + builder.AddBackground(10, 320, 420, 75, 2620); + builder.AddBackground(10, 395, 420, 45, 3000); + } + } - var range = 10 + (int)(from.Skills.Tracking.Value / 10); + for (var i = 0; i < _targets.Length; ++i) + { + var m = _targets[i]; - var mobs = GetClosestMobs(from, range, type); + builder.AddItem(20 + i % 4 * 100, 20 + i / 4 * 155, ShrinkTable.Lookup(m)); + builder.AddButton(20 + i % 4 * 100, 130 + i / 4 * 155, 4005, 4007, i + 1); - if (mobs.Length > 0) - { - from.SendGump(new TrackWhoGump(from, mobs, range)); - from.SendLocalizedMessage(1018093); // Select the one you would like to track. - } - else if (type == 0) - { - from.SendLocalizedMessage(502991); // You see no evidence of animals in the area. - } - else if (type == 1) - { - from.SendLocalizedMessage(502993); // You see no evidence of creatures in the area. - } - else + if (m.Name != null) { - from.SendLocalizedMessage(502995); // You see no evidence of people in the area. + builder.AddHtml(20 + i % 4 * 100, 90 + i / 4 * 155, 90, 40, m.Name); } } + } - private static Mobile[] GetClosestMobs(Mobile from, int range, int type) - { - var loc = from.Location; + private static Mobile[] GetClosestMobs(Mobile from, int range, int type) + { + var loc = from.Location; - // We only track the closest 12 - var mobs = new Mobile[MaxClosest]; - Span distances = stackalloc double[MaxClosest]; - distances.Fill(double.MaxValue); // Fill with max values - var total = 0; + // We only track the closest 12 + var mobs = new Mobile[MaxClosest]; + Span distances = stackalloc double[MaxClosest]; + distances.Fill(double.MaxValue); // Fill with max values + var total = 0; - foreach (var m in from.GetMobilesInRange(range)) + foreach (var m in from.GetMobilesInRange(range)) + { + if (m == from || Core.AOS && !m.Alive || + m.Hidden && m.AccessLevel != AccessLevel.Player && from.AccessLevel <= m.AccessLevel || + !IsValidMobileType(m, type) || !CheckDifficulty(from, m)) { - if (m == from || Core.AOS && !m.Alive || - m.Hidden && m.AccessLevel != AccessLevel.Player && from.AccessLevel <= m.AccessLevel || - !IsValidMobileType(m, type) || !CheckDifficulty(from, m)) - { - continue; - } + continue; + } - total++; + total++; - var distance = m.GetDistanceToSqrt(loc); - for (var i = 0; i < MaxClosest; i++) + var distance = m.GetDistanceToSqrt(loc); + for (var i = 0; i < MaxClosest; i++) + { + if (distance < distances[i]) { - if (distance < distances[i]) + // Shift down the rest + for (int j = MaxClosest - 1; j > i; j--) { - // Shift down the rest - for (int j = MaxClosest - 1; j > i; j--) - { - mobs[j] = mobs[j - 1]; - distances[j] = distances[j - 1]; - } - - mobs[i] = m; - distances[i] = distance; - break; + mobs[j] = mobs[j - 1]; + distances[j] = distances[j - 1]; } - } - } - if (total < MaxClosest) - { - Array.Resize(ref mobs, total); + mobs[i] = m; + distances[i] = distance; + break; + } } + } - return mobs; + if (total < MaxClosest) + { + Array.Resize(ref mobs, total); } - // Tracking players uses tracking and detect hidden vs. hiding and stealth - private static bool CheckDifficulty(Mobile from, Mobile m) + return mobs; + } + + // Tracking players uses tracking and detect hidden vs. hiding and stealth + private static bool CheckDifficulty(Mobile from, Mobile m) + { + if (!Core.AOS || !m.Player) { - if (!Core.AOS || !m.Player) - { - return true; - } + return true; + } - var tracking = from.Skills.Tracking.Fixed; - var detectHidden = from.Skills.DetectHidden.Fixed; + var tracking = from.Skills.Tracking.Fixed; + var detectHidden = from.Skills.DetectHidden.Fixed; - if (Core.ML && m.Race == Race.Elf) - { - tracking /= 2; // The 'Guide' says that it requires twice as Much tracking SKILL to track an elf. Not the total difficulty to track. - } + if (Core.ML && m.Race == Race.Elf) + { + tracking /= 2; // The 'Guide' says that it requires twice as Much tracking SKILL to track an elf. Not the total difficulty to track. + } - var hiding = m.Skills.Hiding.Fixed; - var stealth = m.Skills.Stealth.Fixed; - var divisor = hiding + stealth; + var hiding = m.Skills.Hiding.Fixed; + var stealth = m.Skills.Stealth.Fixed; + var divisor = hiding + stealth; - // Necromancy forms affect tracking difficulty - if (TransformationSpellHelper.UnderTransformation(m, typeof(HorrificBeastSpell))) - { - divisor -= 200; - } - else if (TransformationSpellHelper.UnderTransformation(m, typeof(VampiricEmbraceSpell)) && divisor < 500) - { - divisor = 500; - } - else if (TransformationSpellHelper.UnderTransformation(m, typeof(WraithFormSpell)) && divisor <= 2000) - { - divisor += 200; - } + // Necromancy forms affect tracking difficulty + if (TransformationSpellHelper.UnderTransformation(m, typeof(HorrificBeastSpell))) + { + divisor -= 200; + } + else if (TransformationSpellHelper.UnderTransformation(m, typeof(VampiricEmbraceSpell)) && divisor < 500) + { + divisor = 500; + } + else if (TransformationSpellHelper.UnderTransformation(m, typeof(WraithFormSpell)) && divisor <= 2000) + { + divisor += 200; + } - int chance; - if (divisor > 0) + int chance; + if (divisor > 0) + { + if (Core.SE) { - if (Core.SE) - { - chance = 50 * (tracking * 2 + detectHidden) / divisor; - } - else - { - chance = 50 * (tracking + detectHidden + 10 * Utility.RandomMinMax(1, 20)) / divisor; - } + chance = 50 * (tracking * 2 + detectHidden) / divisor; } else { - chance = 100; + chance = 50 * (tracking + detectHidden + 10 * Utility.RandomMinMax(1, 20)) / divisor; } - - return chance >= 100 || chance > Utility.Random(100); + } + else + { + chance = 100; } - private static bool IsValidMobileType(Mobile m, int type) => - type switch - { - 0 => !m.Player && m.Body.IsAnimal, - 1 => !m.Player && m.Body.IsMonster, - 2 => !m.Player && m.Body.IsHuman, - _ => m.Player - }; + return chance >= 100 || chance > Utility.Random(100); + } - public override void OnResponse(NetState state, in RelayInfo info) + private static bool IsValidMobileType(Mobile m, int type) => + type switch { - var index = info.ButtonID - 1; + 0 => !m.Player && m.Body.IsAnimal, + 1 => !m.Player && m.Body.IsMonster, + 2 => !m.Player && m.Body.IsHuman, + _ => m.Player + }; - if (index >= 0 && index < _targets.Length && index < 12) - { - var m = _targets[index]; + public override void OnResponse(NetState state, in RelayInfo info) + { + var index = info.ButtonID - 1; - _from.QuestArrow = new TrackArrow(_from, m, _range * 2); + if (index >= 0 && index < _targets.Length && index < 12 && state.Mobile is PlayerMobile pm) + { + var m = _targets[index]; - if (Core.SE) - { - Tracking.AddInfo(_from, m); - } + pm.QuestArrow = new TrackArrow(pm, m, _range * 2); + + if (Core.SE) + { + Tracking.AddInfo(pm, m); } } } diff --git a/Projects/UOContent/Spells/Necromancy/SummonFamiliar.cs b/Projects/UOContent/Spells/Necromancy/SummonFamiliar.cs index 900d7e8cb6..b9050af35e 100644 --- a/Projects/UOContent/Spells/Necromancy/SummonFamiliar.cs +++ b/Projects/UOContent/Spells/Necromancy/SummonFamiliar.cs @@ -80,7 +80,7 @@ public override void OnCast() public class SummonFamiliarEntry { - public SummonFamiliarEntry(Type type, object name, double reqNecromancy, double reqSpiritSpeak) + public SummonFamiliarEntry(Type type, TextDefinition name, double reqNecromancy, double reqSpiritSpeak) { Type = type; Name = name; @@ -90,14 +90,14 @@ public SummonFamiliarEntry(Type type, object name, double reqNecromancy, double public Type Type { get; } - public object Name { get; } + public TextDefinition Name { get; } public double ReqNecromancy { get; } public double ReqSpiritSpeak { get; } } -public class SummonFamiliarGump : Gump +public class SummonFamiliarGump : DynamicGump { private const int EnabledColor16 = 0x0F20; private const int DisabledColor16 = 0x262A; @@ -105,8 +105,8 @@ public class SummonFamiliarGump : Gump private const int EnabledColor32 = 0x18CD00; private const int DisabledColor32 = 0x4A8B52; - private readonly SummonFamiliarEntry[] _entries; private readonly Mobile _from; + private readonly SummonFamiliarEntry[] _entries; private readonly SummonFamiliarSpell _spell; @@ -117,49 +117,47 @@ public SummonFamiliarGump(Mobile from, SummonFamiliarEntry[] entries, SummonFami _from = from; _entries = entries; _spell = spell; + } - AddPage(0); + protected override void BuildLayout(ref DynamicGumpBuilder builder) + { + builder.AddPage(); - AddBackground(10, 10, 250, 178, 9270); - AddAlphaRegion(20, 20, 230, 158); + builder.AddBackground(10, 10, 250, 178, 9270); + builder.AddAlphaRegion(20, 20, 230, 158); - AddImage(220, 20, 10464); - AddImage(220, 72, 10464); - AddImage(220, 124, 10464); + builder.AddImage(220, 20, 10464); + builder.AddImage(220, 72, 10464); + builder.AddImage(220, 124, 10464); - AddItem(188, 16, 6883); - AddItem(198, 168, 6881); - AddItem(8, 15, 6882); - AddItem(2, 168, 6880); + builder.AddItem(188, 16, 6883); + builder.AddItem(198, 168, 6881); + builder.AddItem(8, 15, 6882); + builder.AddItem(2, 168, 6880); - AddHtmlLocalized(30, 26, 200, 20, 1060147, EnabledColor16); // Chose thy familiar... + builder.AddHtmlLocalized(30, 26, 200, 20, 1060147, EnabledColor16); // Chose thy familiar... - var necro = from.Skills.Necromancy.Value; - var spirit = from.Skills.SpiritSpeak.Value; + var necro = _from.Skills.Necromancy.Value; + var spirit = _from.Skills.SpiritSpeak.Value; - for (var i = 0; i < entries.Length; ++i) + for (var i = 0; i < _entries.Length; ++i) { - var entry = entries[i]; + var entry = _entries[i]; var name = entry.Name; var enabled = necro >= entry.ReqNecromancy && spirit >= entry.ReqSpiritSpeak; - AddButton(27, 53 + i * 21, 9702, 9703, i + 1); - - if (name is int intName) - { - AddHtmlLocalized(50, 51 + i * 21, 150, 20, intName, enabled ? EnabledColor16 : DisabledColor16); - } - else if (name is string strName) - { - AddHtml( - 50, - 51 + i * 21, - 150, - 20, - strName.Color(enabled ? EnabledColor32 : DisabledColor32) - ); - } + builder.AddButton(27, 53 + i * 21, 9702, 9703, i + 1); + + name.AddHtmlText( + ref builder, + 50, + 51 + i * 21, + 150, + 20, + numberColor: enabled ? EnabledColor16 : DisabledColor16, + stringColor: enabled ? EnabledColor32 : DisabledColor32 + ); } } @@ -190,13 +188,12 @@ public override void OnResponse(NetState sender, in RelayInfo info) // That familiar requires ~1_NECROMANCY~ Necromancy and ~2_SPIRIT~ Spirit Speak. _from.SendLocalizedMessage(1061606, $"{entry.ReqNecromancy:F1}\t{entry.ReqSpiritSpeak:F1}"); - _from.SendGump(new SummonFamiliarGump(_from, SummonFamiliarSpell.Entries, _spell)); + _from.SendGump(this); } else if (entry.Type == null) { _from.SendMessage("That familiar has not yet been defined."); - - _from.SendGump(new SummonFamiliarGump(_from, SummonFamiliarSpell.Entries, _spell)); + _from.SendGump(this); } else { From 1264302ee0733f94cff27981d72c8f5aa146eb42 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Mon, 27 Jan 2025 21:36:56 -0800 Subject: [PATCH 4/4] fix: Converts barkeep and house foundation commit gumps to dynamic (#2099) --- .../Mobiles/Vendors/PlayerBarkeeper.cs | 348 +++++++++--------- .../Multis/Houses/HouseFoundation.cs | 57 +-- 2 files changed, 211 insertions(+), 194 deletions(-) diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs index c658e0111a..a3af3d31bb 100644 --- a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs +++ b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs @@ -385,7 +385,7 @@ public void BeginManagement(Mobile from) return; } - from.SendGump(new BarkeeperGump(from, this)); + from.SendGump(new BarkeeperGump(this)); } public void Dismiss() @@ -496,7 +496,7 @@ public void RemoveTip(Mobile from) public void BeginChangeTitle(Mobile from) { - from.SendGump(new BarkeeperTitleGump(from, this)); + from.SendGump(new BarkeeperTitleGump(this)); } public void EndChangeTitle(Mobile from, string title, bool vendor) @@ -508,7 +508,7 @@ public void EndChangeTitle(Mobile from, string title, bool vendor) public void CancelChangeTitle(Mobile from) { - from.SendGump(new BarkeeperGump(from, this)); + from.SendGump(new BarkeeperGump(this)); } public void BeginChangeAppearance(Mobile from) @@ -678,10 +678,9 @@ public class BarkeeperTitleGump : StaticGump new(1078495, null) // No Title }; - private static int _pageCount = (_entries.Length + 19) / 20; + private static readonly int _pageCount = (_entries.Length + 19) / 20; private readonly PlayerBarkeeper _barkeeper; - private readonly Mobile _from; public override bool Singleton => true; @@ -695,11 +694,7 @@ protected override void BuildLayout(ref StaticGumpBuilder builder) } } - public BarkeeperTitleGump(Mobile from, PlayerBarkeeper barkeeper) : base(0, 0) - { - _from = from; - _barkeeper = barkeeper; - } + public BarkeeperTitleGump(PlayerBarkeeper barkeeper) : base(0, 0) => _barkeeper = barkeeper; private static void RenderBackground(ref StaticGumpBuilder builder) { @@ -815,16 +810,18 @@ public override void OnResponse(NetState sender, in RelayInfo info) return; } + var from = sender.Mobile; + if (buttonID-- <= 0) { - _barkeeper.CancelChangeTitle(_from); + _barkeeper.CancelChangeTitle(from); return; } if (buttonID < _entries.Length) { var entry = _entries[buttonID]; - _barkeeper.EndChangeTitle(_from, entry.Title, entry.Vendor); + _barkeeper.EndChangeTitle(from, entry.Title, entry.Vendor); } } @@ -843,243 +840,249 @@ public Entry(int desc, string title, bool vendor = false) } } - public class BarkeeperGump : Gump + public class BarkeeperGump : DynamicGump { - private readonly PlayerBarkeeper m_Barkeeper; - private readonly Mobile m_From; + private readonly PlayerBarkeeper _barkeeper; public override bool Singleton => true; - public BarkeeperGump(Mobile from, PlayerBarkeeper barkeeper) : base(0, 0) + public static void DisplayTo(Mobile from, PlayerBarkeeper barkeeper) { - m_From = from; - m_Barkeeper = barkeeper; - from.CloseGump(); + from.SendGump(new BarkeeperGump(barkeeper)); + } - RenderBackground(); - RenderCategories(); - RenderMessageManagement(); - RenderDismissConfirmation(); - RenderMessageManagement_Message_AddOrChange(); - RenderMessageManagement_Message_Remove(); - RenderMessageManagement_Tip_AddOrChange(); - RenderMessageManagement_Tip_Remove(); - RenderAppearanceCategories(); + public BarkeeperGump(PlayerBarkeeper barkeeper) : base(0, 0) + { + _barkeeper = barkeeper; } - public void RenderBackground() + protected override void BuildLayout(ref DynamicGumpBuilder builder) { - AddPage(0); - - AddBackground(30, 40, 585, 410, 5054); - - AddImage(30, 40, 9251); - AddImage(180, 40, 9251); - AddImage(30, 40, 9253); - AddImage(30, 130, 9253); - AddImage(598, 40, 9255); - AddImage(598, 130, 9255); - AddImage(30, 433, 9257); - AddImage(180, 433, 9257); - AddImage(30, 40, 9250); - AddImage(598, 40, 9252); - AddImage(598, 433, 9258); - AddImage(30, 433, 9256); - - AddItem(30, 40, 6816); - AddItem(30, 125, 6817); - AddItem(30, 233, 6817); - AddItem(30, 341, 6817); - AddItem(580, 40, 6814); - AddItem(588, 125, 6815); - AddItem(588, 233, 6815); - AddItem(588, 341, 6815); - - AddBackground(183, 25, 280, 30, 5054); - - AddImage(180, 25, 10460); - AddImage(434, 25, 10460); - AddImage(560, 20, 1417); - - AddHtml(223, 32, 200, 40, "BARKEEP CUSTOMIZATION MENU"); - AddBackground(243, 433, 150, 30, 5054); - - AddImage(240, 433, 10460); - AddImage(375, 433, 10460); + RenderBackground(ref builder); + RenderCategories(ref builder); + RenderMessageManagement(ref builder); + RenderDismissConfirmation(ref builder); + RenderMessageManagement_Message_AddOrChange(ref builder); + RenderMessageManagement_Message_Remove(ref builder); + RenderMessageManagement_Tip_AddOrChange(ref builder); + RenderMessageManagement_Tip_Remove(ref builder); + RenderAppearanceCategories(ref builder); } - public void RenderCategories() + public static void RenderBackground(ref DynamicGumpBuilder builder) { - AddPage(1); + builder.AddPage(); - AddButton(130, 120, 4005, 4007, 0, GumpButtonType.Page, 2); - AddHtml(170, 120, 200, 40, "Message Control"); + builder.AddBackground(30, 40, 585, 410, 5054); - AddButton(130, 200, 4005, 4007, 0, GumpButtonType.Page, 8); - AddHtml(170, 200, 200, 40, "Customize your barkeep"); + builder.AddImage(30, 40, 9251); + builder.AddImage(180, 40, 9251); + builder.AddImage(30, 40, 9253); + builder.AddImage(30, 130, 9253); + builder.AddImage(598, 40, 9255); + builder.AddImage(598, 130, 9255); + builder.AddImage(30, 433, 9257); + builder.AddImage(180, 433, 9257); + builder.AddImage(30, 40, 9250); + builder.AddImage(598, 40, 9252); + builder.AddImage(598, 433, 9258); + builder.AddImage(30, 433, 9256); - AddButton(130, 280, 4005, 4007, 0, GumpButtonType.Page, 3); - AddHtml(170, 280, 200, 40, "Dismiss your barkeep"); + builder.AddItem(30, 40, 6816); + builder.AddItem(30, 125, 6817); + builder.AddItem(30, 233, 6817); + builder.AddItem(30, 341, 6817); + builder.AddItem(580, 40, 6814); + builder.AddItem(588, 125, 6815); + builder.AddItem(588, 233, 6815); + builder.AddItem(588, 341, 6815); - AddButton(338, 437, 4014, 4016, 0); - AddHtml(290, 440, 35, 40, "Back"); + builder.AddBackground(183, 25, 280, 30, 5054); - AddItem(574, 43, 5360); + builder.AddImage(180, 25, 10460); + builder.AddImage(434, 25, 10460); + builder.AddImage(560, 20, 1417); + + builder.AddHtmlLocalized(223, 32, 200, 40, 1078366); // BARKEEP CUSTOMIZATION MENU + builder.AddBackground(243, 433, 150, 30, 5054); + + builder.AddImage(240, 433, 10460); + builder.AddImage(375, 433, 10460); + } + + public static void RenderCategories(ref DynamicGumpBuilder builder) + { + builder.AddPage(1); + + builder.AddButton(130, 120, 4005, 4007, 0, GumpButtonType.Page, 2); + builder.AddHtmlLocalized(170, 120, 200, 40, 1078352); // Message Control + + builder.AddButton(130, 200, 4005, 4007, 0, GumpButtonType.Page, 8); + builder.AddHtmlLocalized(170, 200, 200, 40, 1078353); // Customize your barkeep + + builder.AddButton(130, 280, 4005, 4007, 0, GumpButtonType.Page, 3); + builder.AddHtmlLocalized(170, 280, 200, 40, 1078354); // Dismiss your barkeep + + builder.AddButton(338, 437, 4014, 4016, 0); + builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back + + builder.AddItem(574, 43, 5360); } - public void RenderMessageManagement() + public static void RenderMessageManagement(ref DynamicGumpBuilder builder) { - AddPage(2); + builder.AddPage(2); - AddButton(130, 120, 4005, 4007, 0, GumpButtonType.Page, 4); - AddHtml(170, 120, 380, 20, "Add or change a message and keyword"); + builder.AddButton(130, 120, 4005, 4007, 0, GumpButtonType.Page, 4); + builder.AddHtmlLocalized(170, 120, 380, 20, 1078355); // Add or change a message and keyword - AddButton(130, 200, 4005, 4007, 0, GumpButtonType.Page, 5); - AddHtml(170, 200, 380, 20, "Remove a message and keyword from your barkeep"); + builder.AddButton(130, 200, 4005, 4007, 0, GumpButtonType.Page, 5); + builder.AddHtmlLocalized(170, 200, 380, 20, 1078356); // Remove a message and keyword from your barkeep - AddButton(130, 280, 4005, 4007, 0, GumpButtonType.Page, 6); - AddHtml(170, 280, 380, 20, "Add or change your barkeeper's tip message"); + builder.AddButton(130, 280, 4005, 4007, 0, GumpButtonType.Page, 6); + builder.AddHtmlLocalized(170, 280, 380, 20, 1078357); // Add or change your barkeeper's tip message - AddButton(130, 360, 4005, 4007, 0, GumpButtonType.Page, 7); - AddHtml(170, 360, 380, 20, "Delete your barkeepers tip message"); + builder.AddButton(130, 360, 4005, 4007, 0, GumpButtonType.Page, 7); + builder.AddHtmlLocalized(170, 360, 380, 20, 1078358); // Delete your barkeepers tip message - AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 1); - AddHtml(290, 440, 35, 40, "Back"); + builder.AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 1); + builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back - AddItem(580, 46, 4030); + builder.AddItem(580, 46, 4030); } - public void RenderDismissConfirmation() + public static void RenderDismissConfirmation(ref DynamicGumpBuilder builder) { - AddPage(3); + builder.AddPage(3); - AddHtml(170, 160, 380, 20, "Are you sure you want to dismiss your barkeeper?"); + builder.AddHtmlLocalized(170, 160, 380, 20, 1078359); // Are you sure you want to dismiss your barkeeper? - AddButton(205, 280, 4005, 4007, GetButtonID(0, 0)); - AddHtml(240, 280, 100, 20, @"Yes"); + builder.AddButton(205, 280, 4005, 4007, GetButtonID(0, 0)); + builder.AddHtmlLocalized(240, 280, 100, 20, 1046362); // Yes - AddButton(395, 280, 4005, 4007, 0); - AddHtml(430, 280, 100, 20, "No"); + builder.AddButton(395, 280, 4005, 4007, 0); + builder.AddHtmlLocalized(430, 280, 100, 20, 1046363); // No - AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 1); - AddHtml(290, 440, 35, 40, "Back"); + builder.AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 1); + builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back - AddItem(574, 43, 5360); - AddItem(584, 34, 6579); + builder.AddItem(574, 43, 5360); + builder.AddItem(584, 34, 6579); } - public void RenderMessageManagement_Message_AddOrChange() + public void RenderMessageManagement_Message_AddOrChange(ref DynamicGumpBuilder builder) { - AddPage(4); + builder.AddPage(4); - AddHtml(250, 60, 500, 25, "Add or change a message"); + builder.AddHtmlLocalized(250, 60, 500, 25, 1078360); // Add or change a message - var rumors = m_Barkeeper.Rumors; + var rumors = _barkeeper.Rumors; for (var i = 0; i < rumors.Length; ++i) { var rumor = rumors[i]; - AddHtml(100, 70 + i * 120, 50, 20, "Message"); - AddHtml(100, 90 + i * 120, 450, 40, rumor == null ? "No current message" : rumor.Message, true); - AddHtml(100, 130 + i * 120, 50, 20, "Keyword"); - AddHtml(100, 150 + i * 120, 450, 40, rumor == null ? "None" : rumor.Keyword, true); + builder.AddHtml(100, 70 + i * 120, 50, 20, "Message"); + builder.AddHtml(100, 90 + i * 120, 450, 40, rumor == null ? "No current message" : rumor.Message, true); + builder.AddHtmlLocalized(100, 130 + i * 120, 50, 20, 1078361); // Keyword + builder.AddHtml(100, 150 + i * 120, 450, 40, rumor == null ? "None" : rumor.Keyword, true); - AddButton(60, 90 + i * 120, 4005, 4007, GetButtonID(1, i)); + builder.AddButton(60, 90 + i * 120, 4005, 4007, GetButtonID(1, i)); } - AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 2); - AddHtml(290, 440, 35, 40, "Back"); + builder.AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 2); + builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back - AddItem(580, 46, 4030); + builder.AddItem(580, 46, 4030); } - public void RenderMessageManagement_Message_Remove() + public void RenderMessageManagement_Message_Remove(ref DynamicGumpBuilder builder) { - AddPage(5); + builder.AddPage(5); - AddHtml(190, 60, 500, 25, "Choose the message you would like to remove"); + builder.AddHtmlLocalized(190, 60, 500, 25, 1078362); // Choose the message you would like to remove - var rumors = m_Barkeeper.Rumors; + var rumors = _barkeeper.Rumors; for (var i = 0; i < rumors.Length; ++i) { var rumor = rumors[i]; - AddHtml(100, 70 + i * 120, 50, 20, "Message"); - AddHtml(100, 90 + i * 120, 450, 40, rumor == null ? "No current message" : rumor.Message, true); - AddHtml(100, 130 + i * 120, 50, 20, "Keyword"); - AddHtml(100, 150 + i * 120, 450, 40, rumor == null ? "None" : rumor.Keyword, true); + builder.AddHtml(100, 70 + i * 120, 50, 20, "Message"); + builder.AddHtml(100, 90 + i * 120, 450, 40, rumor == null ? "No current message" : rumor.Message, true); + builder.AddHtmlLocalized(100, 130 + i * 120, 50, 20, 1078361); // Keyword + builder.AddHtml(100, 150 + i * 120, 450, 40, rumor == null ? "None" : rumor.Keyword, true); - AddButton(60, 90 + i * 120, 4005, 4007, GetButtonID(2, i)); + builder.AddButton(60, 90 + i * 120, 4005, 4007, GetButtonID(2, i)); } - AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 2); - AddHtml(290, 440, 35, 40, "Back"); + builder.AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 2); + builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back - AddItem(580, 46, 4030); + builder.AddItem(580, 46, 4030); } - private int GetButtonID(int type, int index) => 1 + index * 6 + type; + private static int GetButtonID(int type, int index) => 1 + index * 6 + type; - private void RenderMessageManagement_Tip_AddOrChange() + private void RenderMessageManagement_Tip_AddOrChange(ref DynamicGumpBuilder builder) { - AddPage(6); + builder.AddPage(6); - AddHtml(250, 95, 500, 20, "Change this tip message"); - AddHtml(100, 190, 50, 20, "Message"); - AddHtml(100, 210, 450, 40, m_Barkeeper.TipMessage ?? "No current message", true); + builder.AddHtmlLocalized(250, 95, 500, 20, 1078363); // Change this tip message + builder.AddHtml(100, 190, 50, 20, "Message"); + builder.AddHtml(100, 210, 450, 40, _barkeeper.TipMessage ?? "No current message", true); - AddButton(60, 210, 4005, 4007, GetButtonID(3, 0)); + builder.AddButton(60, 210, 4005, 4007, GetButtonID(3, 0)); - AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 2); - AddHtml(290, 440, 35, 40, "Back"); + builder.AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 2); + builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back - AddItem(580, 46, 4030); + builder.AddItem(580, 46, 4030); } - private void RenderMessageManagement_Tip_Remove() + private void RenderMessageManagement_Tip_Remove(ref DynamicGumpBuilder builder) { - AddPage(7); + builder.AddPage(7); - AddHtml(250, 95, 500, 20, "Remove this tip message"); - AddHtml(100, 190, 50, 20, "Message"); - AddHtml(100, 210, 450, 40, m_Barkeeper.TipMessage ?? "No current message", true); + builder.AddHtmlLocalized(250, 95, 500, 20, 1078364); // Remove this tip message + builder.AddHtml(100, 190, 50, 20, "Message"); + builder.AddHtml(100, 210, 450, 40, _barkeeper.TipMessage ?? "No current message", true); - AddButton(60, 210, 4005, 4007, GetButtonID(4, 0)); + builder.AddButton(60, 210, 4005, 4007, GetButtonID(4, 0)); - AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 2); - AddHtml(290, 440, 35, 40, "Back"); + builder.AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 2); + builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back - AddItem(580, 46, 4030); + builder.AddItem(580, 46, 4030); } - private void RenderAppearanceCategories() + private void RenderAppearanceCategories(ref DynamicGumpBuilder builder) { - AddPage(8); + builder.AddPage(8); - AddButton(130, 120, 4005, 4007, GetButtonID(5, 0)); - AddHtml(170, 120, 120, 20, "Title"); + builder.AddButton(130, 120, 4005, 4007, GetButtonID(5, 0)); + builder.AddHtml(170, 120, 120, 20, "Title"); - if (m_Barkeeper.Body != 0x340 && m_Barkeeper.Body != 0x402) + if ((int)_barkeeper.Body is not 0x340 and not 0x402) { - AddButton(130, 200, 4005, 4007, GetButtonID(5, 1)); - AddHtml(170, 200, 120, 20, "Appearance"); + builder.AddButton(130, 200, 4005, 4007, GetButtonID(5, 1)); + builder.AddHtmlLocalized(170, 200, 120, 20, 1077829); // Appearance - AddButton(130, 280, 4005, 4007, GetButtonID(5, 2)); - AddHtml(170, 280, 120, 20, "Male / Female"); + builder.AddButton(130, 280, 4005, 4007, GetButtonID(5, 2)); + builder.AddHtmlLocalized(170, 280, 120, 20, 1078365); // Male / Female - AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 1); - AddHtml(290, 440, 35, 40, "Back"); + builder.AddButton(338, 437, 4014, 4016, 0, GumpButtonType.Page, 1); + builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back } - AddItem(580, 44, 4033); + builder.AddItem(580, 44, 4033); } public override void OnResponse(NetState state, in RelayInfo info) { - if (!m_Barkeeper.IsOwner(m_From)) + var from = state.Mobile; + if (!_barkeeper.IsOwner(from)) { return; } @@ -1091,8 +1094,7 @@ public override void OnResponse(NetState state, in RelayInfo info) return; } - var type = index % 6; - index /= 6; + index = Math.DivRem(index, 6, out var type); switch (type) { @@ -1102,7 +1104,7 @@ public override void OnResponse(NetState state, in RelayInfo info) { case 0: // Dismiss { - m_Barkeeper.Dismiss(); + _barkeeper.Dismiss(); break; } } @@ -1111,22 +1113,22 @@ public override void OnResponse(NetState state, in RelayInfo info) } case 1: // Change message { - m_Barkeeper.BeginChangeRumor(m_From, index); + _barkeeper.BeginChangeRumor(from, index); break; } case 2: // Remove message { - m_Barkeeper.RemoveRumor(m_From, index); + _barkeeper.RemoveRumor(from, index); break; } case 3: // Change tip { - m_Barkeeper.BeginChangeTip(m_From); + _barkeeper.BeginChangeTip(from); break; } case 4: // Remove tip { - m_Barkeeper.RemoveTip(m_From); + _barkeeper.RemoveTip(from); break; } case 5: // Appearance category selection @@ -1134,14 +1136,20 @@ public override void OnResponse(NetState state, in RelayInfo info) switch (index) { case 0: - m_Barkeeper.BeginChangeTitle(m_From); - break; + { + _barkeeper.BeginChangeTitle(from); + break; + } case 1: - m_Barkeeper.BeginChangeAppearance(m_From); - break; + { + _barkeeper.BeginChangeAppearance(from); + break; + } case 2: - m_Barkeeper.ChangeGender(m_From); - break; + { + _barkeeper.ChangeGender(from); + break; + } } break; diff --git a/Projects/UOContent/Multis/Houses/HouseFoundation.cs b/Projects/UOContent/Multis/Houses/HouseFoundation.cs index 74ad5e4e77..0620f9f621 100644 --- a/Projects/UOContent/Multis/Houses/HouseFoundation.cs +++ b/Projects/UOContent/Multis/Houses/HouseFoundation.cs @@ -2097,53 +2097,62 @@ public static bool IsFixture(int itemID) => }; } - public class ConfirmCommitGump : Gump + public class ConfirmCommitGump : DynamicGump { private readonly HouseFoundation m_Foundation; + private readonly int _bankBalance; + private readonly int _oldPrice; + private readonly int _newPrice; public ConfirmCommitGump(HouseFoundation foundation, int bankBalance, int oldPrice, int newPrice) : base(50, 50) { m_Foundation = foundation; + _bankBalance = bankBalance; + _oldPrice = oldPrice; + _newPrice = newPrice; + } - AddPage(0); + protected override void BuildLayout(ref DynamicGumpBuilder builder) + { + builder.AddPage(); - AddBackground(0, 0, 320, 320, 5054); + builder.AddBackground(0, 0, 320, 320, 5054); - AddImageTiled(10, 10, 300, 20, 2624); - AddImageTiled(10, 40, 300, 240, 2624); - AddImageTiled(10, 290, 300, 20, 2624); + builder.AddImageTiled(10, 10, 300, 20, 2624); + builder.AddImageTiled(10, 40, 300, 240, 2624); + builder.AddImageTiled(10, 290, 300, 20, 2624); - AddAlphaRegion(10, 10, 300, 300); + builder.AddAlphaRegion(10, 10, 300, 300); - AddHtmlLocalized(10, 10, 300, 20, 1062060, 32736); //
COMMIT DESIGN
+ builder.AddHtmlLocalized(10, 10, 300, 20, 1062060, 32736); //
COMMIT DESIGN
- AddHtmlLocalized(10, 40, 300, 140, newPrice - oldPrice <= bankBalance ? 1061898 : 1061903, 1023, false, true); + builder.AddHtmlLocalized(10, 40, 300, 140, _newPrice - _oldPrice <= _bankBalance ? 1061898 : 1061903, 1023, false, true); - AddHtmlLocalized(10, 190, 150, 20, 1061902, 32736); // Bank Balance: - AddLabel(170, 190, 55, bankBalance.ToString()); + builder.AddHtmlLocalized(10, 190, 150, 20, 1061902, 32736); // Bank Balance: + builder.AddLabel(170, 190, 55, _bankBalance.ToString()); - AddHtmlLocalized(10, 215, 150, 20, 1061899, 1023); // Old Value: - AddLabel(170, 215, 90, oldPrice.ToString()); + builder.AddHtmlLocalized(10, 215, 150, 20, 1061899, 1023); // Old Value: + builder.AddLabel(170, 215, 90, _oldPrice.ToString()); - AddHtmlLocalized(10, 235, 150, 20, 1061900, 1023); // Cost To Commit: - AddLabel(170, 235, 90, newPrice.ToString()); + builder.AddHtmlLocalized(10, 235, 150, 20, 1061900, 1023); // Cost To Commit: + builder.AddLabel(170, 235, 90, _newPrice.ToString()); - if (newPrice - oldPrice < 0) + if (_newPrice - _oldPrice < 0) { - AddHtmlLocalized(10, 260, 150, 20, 1062059, 992); // Your Refund: - AddLabel(170, 260, 70, (oldPrice - newPrice).ToString()); + builder. AddHtmlLocalized(10, 260, 150, 20, 1062059, 992); // Your Refund: + builder.AddLabel(170, 260, 70, (_oldPrice - _newPrice).ToString()); } else { - AddHtmlLocalized(10, 260, 150, 20, 1061901, 31744); // Your Cost: - AddLabel(170, 260, 40, (newPrice - oldPrice).ToString()); + builder.AddHtmlLocalized(10, 260, 150, 20, 1061901, 31744); // Your Cost: + builder.AddLabel(170, 260, 40, (_newPrice - _oldPrice).ToString()); } - AddButton(10, 290, 4005, 4007, 1); - AddHtmlLocalized(45, 290, 55, 20, 1011036, 32767); // OKAY + builder.AddButton(10, 290, 4005, 4007, 1); + builder.AddHtmlLocalized(45, 290, 55, 20, 1011036, 32767); // OKAY - AddButton(170, 290, 4005, 4007, 0); - AddHtmlLocalized(195, 290, 55, 20, 1011012, 32767); // CANCEL + builder.AddButton(170, 290, 4005, 4007, 0); + builder.AddHtmlLocalized(195, 290, 55, 20, 1011012, 32767); // CANCEL } public override void OnResponse(NetState sender, in RelayInfo info)