Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Converts BarkeeperTitleGump to static gump and localizes entries #1980

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
344 changes: 180 additions & 164 deletions Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,217 +612,233 @@ private void UpgradeFromVersion0()
}
}

public class BarkeeperTitleGump : Gump
public class BarkeeperTitleGump : StaticGump<BarkeeperTitleGump>
{
private static readonly Entry[] m_Entries =
private static readonly Entry[] _entries =
{
new("Alchemist"),
new("Animal Tamer"),
new("Apothecary"),
new("Artist"),
new("Baker", true),
new("Bard"),
new("Barkeep", "the barkeeper", true),
new("Beggar"),
new("Blacksmith"),
new("Bounty Hunter"),
new("Brigand"),
new("Butler"),
new("Carpenter"),
new("Chef", true),
new("Commander"),
new("Curator"),
new("Drunkard"),
new("Farmer"),
new("Fisherman"),
new("Gambler"),
new("Gypsy"),
new("Herald"),
new("Herbalist"),
new("Hermit"),
new("Innkeeper", true),
new("Jailor"),
new("Jester"),
new("Librarian"),
new("Mage"),
new("Mercenary"),
new("Merchant"),
new("Messenger"),
new("Miner"),
new("Monk"),
new("Noble"),
new("Paladin"),
new("Peasant"),
new("Pirate"),
new("Prisoner"),
new("Prophet"),
new("Ranger"),
new("Sage"),
new("Sailor"),
new("Scholar"),
new("Scribe"),
new("Sentry"),
new("Servant"),
new("Shepherd"),
new("Soothsayer"),
new("Stoic"),
new("Storyteller"),
new("Tailor"),
new("Thief"),
new("Tinker"),
new("Town Crier"),
new("Treasure Hunter"),
new("Waiter", true),
new("Warrior"),
new("Watchman"),
new("No Title", null)
new(1076083, "the alchemist"),
new(1077244, "the animal tamer"),
new(1078440, "the apothecary"),
new(1078441, "the artist"),
new(1078442, "the baker", true),
new(1073298, "the bard"),
new(1076102, "the barkeep", true),
new(1078443, "the beggar"),
new(1073297, "the blacksmith"),
new(1078444, "the bounty hunter"),
new(1078446, "the brigand"),
new(1078447, "the butler"),
new(1060774, "the carpenter"),
new(1078448, "the chef", true),
new(1078449, "the commander"),
new(1078450, "the curator"),
new(1078451, "the drunkard"),
new(1078452, "the farmer"),
new(1078453, "the fisherman"),
new(1078454, "the gambler"),
new(1078455, "the gypsy"),
new(1075996, "the herald"),
new(1076107, "the herbalist"),
new(1078465, "the hermit"),
new(1078466, "the innkeeper", true),
new(1078467, "the jailor"),
new(1078468, "the jester"),
new(1078469, "the librarian"),
new(1073292, "the mage"),
new(1078470, "the mercenary"),
new(1060775, "the merchant"),
new(1078472, "the messenger"),
new(1076093, "the miner"),
new(1078475, "the monk"),
new(1078476, "the noble"),
new(1073290, "the paladin"),
new(1078479, "the peasant"),
new(1078480, "the pirate"),
new(1078481, "the prisoner"),
new(1078482, "the prophet"),
new(1078484, "the ranger"),
new(1078487, "the sage"),
new(1078488, "the sailor"),
new(1078489, "the scholar"),
new(1060773, "the scribe"),
new(1078490, "the sentry"),
new(1060795, "the servant"),
new(1078491, "the shepherd"),
new(1078492, "the soothsayer"),
new(1078493, "the stoic"),
new(1078494, "the storyteller"),
new(1076134, "the tailor"),
new(1076096, "the thief"),
new(1076137, "the tinker"),
new(1076097, "the town crier"),
new(1073291, "the treasure hunter"),
new(1076112, "the waiter", true),
new(1077242, "the warrior"),
new(1078496, "the watchman"),
new(1078495, null) // No Title
};

private readonly PlayerBarkeeper m_Barkeeper;
private readonly Mobile m_From;
private static int _pageCount = (_entries.Length + 19) / 20;

private readonly PlayerBarkeeper _barkeeper;
private readonly Mobile _from;

public override bool Singleton => true;

public BarkeeperTitleGump(Mobile from, PlayerBarkeeper barkeeper) : base(0, 0)
protected override void BuildLayout(ref StaticGumpBuilder builder)
{
m_From = from;
m_Barkeeper = barkeeper;

from.CloseGump<BarkeeperGump>();

var entries = m_Entries;

RenderBackground();

var pageCount = (entries.Length + 19) / 20;
RenderBackground(ref builder);

for (var i = 0; i < pageCount; ++i)
for (var i = 0; i < _pageCount; ++i)
{
RenderPage(entries, i);
RenderPage(ref builder, i);
}
}

private void RenderBackground()
public BarkeeperTitleGump(Mobile from, PlayerBarkeeper barkeeper) : base(0, 0)
{
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);

AddImage(560, 20, 1417);
AddItem(580, 44, 4033);

AddBackground(183, 25, 280, 30, 5054);

AddImage(180, 25, 10460);
AddImage(434, 25, 10460);

AddHtml(223, 32, 200, 40, "BARKEEP CUSTOMIZATION MENU");
AddBackground(243, 433, 150, 30, 5054);

AddImage(240, 433, 10460);
AddImage(375, 433, 10460);

AddImage(80, 398, 2151);
AddItem(72, 406, 2543);
_from = from;
_barkeeper = barkeeper;
}

AddHtml(110, 412, 180, 25, "sells food and drink");
private static void RenderBackground(ref StaticGumpBuilder builder)
{
builder.AddPage();

builder.AddBackground(30, 40, 585, 410, 5054);

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);

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);

builder.AddImage(560, 20, 1417);
builder.AddItem(580, 44, 4033);

builder.AddBackground(183, 25, 280, 30, 5054);

builder.AddImage(180, 25, 10460);
builder.AddImage(434, 25, 10460);

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);

builder.AddImage(80, 398, 2151);
builder.AddItem(72, 406, 2543);

builder.AddHtmlLocalized(110, 412, 180, 25, 1078445); // sells food and drink
}

private void RenderPage(Entry[] entries, int page)
private static void RenderPage(ref StaticGumpBuilder builder, int page)
{
AddPage(1 + page);
var currentPage = page + 1;
builder.AddPage(currentPage);

AddHtml(430, 70, 180, 25, $"Page {page + 1} of {(entries.Length + 19) / 20}");
if (_pageCount == 3 && currentPage is >= 1 and <= 3)
{
var pageCliloc = currentPage switch
{
1 => 1078439, // Page 1 of 3
2 => 1078464, // Page 2 of 3
3 => 1078483, // Page 3 of 3
};

builder.AddHtmlLocalized(430, 70, 180, 25, pageCliloc);
}
else
{
// Page ~1_CUR~ of ~2_MAX~
builder.AddHtmlLocalized(430, 70, 180, 25, 1153561, $"{currentPage}\t{_pageCount}", 0x7FFF);
}

for (int count = 0, i = page * 20; count < 20 && i < entries.Length; ++count, ++i)
for (int count = 0, i = page * 20; count < 20 && i < _entries.Length; ++count, ++i)
{
var entry = entries[i];
var entry = _entries[i];

AddButton(80 + count / 10 * 260, 100 + count % 10 * 30, 4005, 4007, 2 + i);
AddHtml(
120 + count / 10 * 260,
100 + count % 10 * 30,
entry.m_Vendor ? 148 : 180,
var xOffset = Math.DivRem(count, 10, out var yOffset);

builder.AddButton(80 + xOffset * 260, 100 + yOffset * 30, 4005, 4007, 2 + i);
builder.AddHtmlLocalized(
120 + xOffset * 260,
100 + yOffset * 30,
entry.Vendor ? 148 : 180,
25,
entry.m_Description,
entry.Description,
true
);

if (entry.m_Vendor)
if (entry.Vendor)
{
AddImage(270 + count / 10 * 260, 98 + count % 10 * 30, 2151);
AddItem(262 + count / 10 * 260, 106 + count % 10 * 30, 2543);
builder.AddImage(270 + xOffset * 260, 98 + yOffset * 30, 2151);
builder.AddItem(262 + xOffset * 260, 106 + yOffset * 30, 2543);
}
}

AddButton(340, 400, 4005, 4007, 0, GumpButtonType.Page, 1 + (page + 1) % ((entries.Length + 19) / 20));
AddHtml(380, 400, 180, 25, "More Job Titles");
builder.AddButton(340, 400, 4005, 4007, 0, GumpButtonType.Page, currentPage + 1 % _pageCount);
builder.AddHtmlLocalized(380, 400, 180, 25, 1078456); // More Job Titles

AddButton(338, 437, 4014, 4016, 1);
AddHtml(290, 440, 35, 40, "Back");
builder.AddButton(338, 437, 4014, 4016, 1);
builder.AddHtmlLocalized(290, 440, 35, 40, 1005007); // Back
}

public override void OnResponse(NetState sender, in RelayInfo info)
{
if (_barkeeper.Deleted)
{
return;
}

var buttonID = info.ButtonID;

if (buttonID > 0)
if (buttonID-- <= 0)
{
--buttonID;
return;
}

if (buttonID > 0)
{
--buttonID;
if (buttonID-- <= 0)
{
_barkeeper.CancelChangeTitle(_from);
return;
}

if (buttonID < m_Entries.Length)
{
m_Barkeeper.EndChangeTitle(m_From, m_Entries[buttonID].m_Title, m_Entries[buttonID].m_Vendor);
}
}
else
{
m_Barkeeper.CancelChangeTitle(m_From);
}
if (buttonID < _entries.Length)
{
var entry = _entries[buttonID];
_barkeeper.EndChangeTitle(_from, entry.Title, entry.Vendor);
}
}

private class Entry
{
public readonly string m_Description;
public readonly string m_Title;
public readonly bool m_Vendor;

public Entry(string desc, bool vendor = false) : this(desc, $"the {desc.ToLower()}", vendor)
{
}
public readonly int Description;
public readonly string Title;
public readonly bool Vendor;

public Entry(string desc, string title, bool vendor = false)
public Entry(int desc, string title, bool vendor = false)
{
m_Description = desc;
m_Title = title;
m_Vendor = vendor;
Description = desc;
Title = title;
Vendor = vendor;
}
}
}
Expand Down
Loading