## Summary First PR in a multi-PR migration of player-facing legacy `Gump` subclasses to the modern `DynamicGump` / `StaticGump<T>` system. Plan covers ~95 files across ~14 PRs by system; this PR is the foundation (smallest, isolated, no cross-refs). - `VirtueGump` → `DynamicGump`: per-instance virtue hues from `GetHueFor()` and the conditional self/other button block prevent layout caching. - `VirtueStatusGump` → `StaticGump<VirtueStatusGump>`: layout is identical for every player; only used as a navigation hub. - `VirtueInfoGump` → `DynamicGump`: dynamic cliloc IDs (`1051000 + (int)virtue`, the description cliloc, and the conditional `1052055`/`1052052` footer) cannot be cached by `StaticGump<T>` — cliloc *numbers* are baked into layout bytes, only HTML/label *text* can be deferred to placeholders. All three: - `Singleton => true` (replaces previous instance instead of stacking) - Constructors made `private`; entry points are static (`RequestVirtueGump`, `DisplayTo`) per the empty-gump rule (CLAUDE.md §13) - `OnResponse` updated to `in RelayInfo info` modern signature - `VirtueInfoGump` self-refresh button now uses `_beholder.SendGump(this)` instead of allocating a new instance - Removed the unused `VirtueGumpItem : GumpImage` nested class — replaced with direct `builder.AddImage(...)` calls; preserves the legacy `class=VirtueGumpItem` attribute for packet parity The special-cased TypeID for VirtueGump (`BaseGump.cs:86`) is preserved because the type's full name (`Server.Engines.Virtues.VirtueGump`) is unchanged.
147 lines
4.2 KiB
C#
147 lines
4.2 KiB
C#
using Server.Gumps;
|
|
using Server.Mobiles;
|
|
using Server.Network;
|
|
|
|
namespace Server.Engines.Virtues;
|
|
|
|
public class VirtueInfoGump : DynamicGump
|
|
{
|
|
private readonly PlayerMobile _beholder;
|
|
private readonly int _desc;
|
|
private readonly string _site;
|
|
private readonly VirtueName _virtue;
|
|
|
|
public override bool Singleton => true;
|
|
|
|
private VirtueInfoGump(PlayerMobile beholder, VirtueName virtue, int description, string webPage) : base(0, 0)
|
|
{
|
|
_beholder = beholder;
|
|
_virtue = virtue;
|
|
_desc = description;
|
|
_site = webPage;
|
|
}
|
|
|
|
public static void DisplayTo(PlayerMobile beholder, VirtueName virtue, int description, string webPage = null)
|
|
{
|
|
if (beholder?.NetState == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
beholder.SendGump(new VirtueInfoGump(beholder, virtue, description, webPage));
|
|
}
|
|
|
|
protected override void BuildLayout(ref DynamicGumpBuilder builder)
|
|
{
|
|
var value = VirtueSystem.GetVirtues(_beholder)?.GetValue((int)_virtue) ?? 0;
|
|
|
|
builder.AddPage();
|
|
|
|
builder.AddImage(30, 40, 2080);
|
|
builder.AddImage(47, 77, 2081);
|
|
builder.AddImage(47, 147, 2081);
|
|
builder.AddImage(47, 217, 2081);
|
|
builder.AddImage(47, 267, 2083);
|
|
builder.AddImage(70, 213, 2091);
|
|
|
|
builder.AddPage(1);
|
|
|
|
var maxValue = VirtueSystem.GetMaxAmount(_virtue);
|
|
|
|
int valueDesc;
|
|
int dots;
|
|
|
|
if (value < 4000)
|
|
{
|
|
dots = value / 400;
|
|
}
|
|
else if (value < 10000)
|
|
{
|
|
dots = (value - 4000) / 600;
|
|
}
|
|
else if (value < maxValue)
|
|
{
|
|
dots = (value - 10000) / ((maxValue - 10000) / 10);
|
|
}
|
|
else
|
|
{
|
|
dots = 10;
|
|
}
|
|
|
|
for (var i = 0; i < 10; ++i)
|
|
{
|
|
builder.AddImage(95 + i * 17, 50, i < dots ? 2362 : 2360);
|
|
}
|
|
|
|
if (value < 1)
|
|
{
|
|
valueDesc = 1052044; // You have not started on the path of this Virtue.
|
|
}
|
|
else if (value < 400)
|
|
{
|
|
valueDesc = 1052045; // You have barely begun your journey through the path of this Virtue.
|
|
}
|
|
else if (value < 2000)
|
|
{
|
|
valueDesc = 1052046; // You have progressed in this Virtue, but still have much to do.
|
|
}
|
|
else if (value < 3600)
|
|
{
|
|
valueDesc = 1052047; // Your journey through the path of this Virtue is going well.
|
|
}
|
|
else if (value < 4000)
|
|
{
|
|
valueDesc = 1052048; // You feel very close to achieving your next path in this Virtue.
|
|
}
|
|
else if (dots < 1)
|
|
{
|
|
valueDesc = 1052049; // You have achieved a path in this Virtue.
|
|
}
|
|
else if (dots < 9)
|
|
{
|
|
valueDesc = 1052047; // Your journey through the path of this Virtue is going well.
|
|
}
|
|
else if (dots < 10)
|
|
{
|
|
valueDesc = 1052048; // You feel very close to achieving your next path in this Virtue.
|
|
}
|
|
else
|
|
{
|
|
valueDesc = 1052050; // You have achieved the highest path in this Virtue.
|
|
}
|
|
|
|
builder.AddHtmlLocalized(157, 73, 200, 40, 1051000 + (int)_virtue);
|
|
builder.AddHtmlLocalized(75, 95, 220, 140, _desc);
|
|
builder.AddHtmlLocalized(70, 224, 229, 60, valueDesc);
|
|
|
|
builder.AddButton(65, 277, 1209, 1209, 1);
|
|
|
|
builder.AddButton(280, 43, 4014, 4014, 2);
|
|
|
|
// This virtue is not yet defined. OR -click to learn more (opens webpage)
|
|
builder.AddHtmlLocalized(83, 275, 400, 40, _site == null ? 1052055 : 1052052);
|
|
}
|
|
|
|
public override void OnResponse(NetState state, in RelayInfo info)
|
|
{
|
|
switch (info.ButtonID)
|
|
{
|
|
case 1:
|
|
{
|
|
_beholder.SendGump(this);
|
|
|
|
if (_site != null)
|
|
{
|
|
state.SendLaunchBrowser(_site); // No message about web browser starting on OSI
|
|
}
|
|
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
VirtueStatusGump.DisplayTo(_beholder);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|