Skip to content

Commit

Permalink
fix: Adds static warning/notice gumps. (#1741)
Browse files Browse the repository at this point in the history
### Summary
* Adds `StaticNoticeGump<T>` and `StaticWarningGump<T>`
* Converts NoticeGump/WarningGump to use `DynamicGump`
* Changes various uses of notice gump and warning gump to their static counterpart.
  • Loading branch information
kamronbatman committed Apr 27, 2024
1 parent 65532ea commit bb7bc57
Show file tree
Hide file tree
Showing 19 changed files with 708 additions and 425 deletions.
24 changes: 12 additions & 12 deletions Projects/UOContent/Assistants/AssistantHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,7 @@ private static void FailedNegotiation(Mobile m)

if (AssistantConfiguration.Settings.WarnOnFailure)
{
var warningGump = new WarningGump(
1060635,
30720,
AssistantConfiguration.Settings.WarningMessage,
0xFFC000,
420,
250,
null,
false
);

m.SendGump(warningGump);
m.SendGump(new AssistantFailureWarningGump());
}

if (isPlayer)
Expand Down Expand Up @@ -154,4 +143,15 @@ public static void SendAssistHandshake(this NetState ns)

ns.Send(writer.Span);
}

private class AssistantFailureWarningGump : StaticWarningGump<AssistantFailureWarningGump>
{
private static readonly TextDefinition _warningMessage = AssistantConfiguration.Settings.WarningMessage;

public override int StaticLocalizedContent => _warningMessage?.Number ?? 0;
public override string Content => _warningMessage.String;
public override int Width => 420;
public override int Height => 250;
public override bool CancelButton => false;
}
}
39 changes: 23 additions & 16 deletions Projects/UOContent/Commands/Generic/Commands/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,8 @@ public void Execute(CommandEventArgs e, object obj, bool echo)
}

mob.SendGump(
new WarningGump(
1060637,
30720,
$"A game master is requesting to open your web browser to the following URL:<br>{url}",
0xFFC000,
320,
240,
new OpenBrowserWarningGump(
url,
okay => OpenBrowser_Callback(mob, okay, from, url, echo)
)
);
Expand All @@ -307,6 +302,16 @@ public void Execute(CommandEventArgs e, object obj, bool echo)
}
}

private class OpenBrowserWarningGump : StaticWarningGump<OpenBrowserWarningGump>
{
public override string Content { get; }
public override int Width => 320;
public override int Height => 240;

public OpenBrowserWarningGump(string url, Action<bool> callback) : base(callback) =>
Content = $"A game master is requesting to open your web browser to the following URL:<br>{url}";
}

public override void Execute(CommandEventArgs e, object obj)
{
Execute(e, obj, true);
Expand Down Expand Up @@ -912,15 +917,7 @@ public override void ExecuteList(CommandEventArgs e, List<object> list)
{
var from = e.Mobile;
from.SendGump(
new WarningGump(
1060637,
30720,
$"You are about to delete {list.Count} objects. This cannot be undone without a full server revert.<br><br>Continue?",
0xFFC000,
420,
280,
okay => OnConfirmCallback(from, okay, e, list)
)
new DeleteObjectsNoticeGump(list.Count, okay => OnConfirmCallback(from, okay, e, list))
);
AddResponse("Awaiting confirmation...");
}
Expand All @@ -930,6 +927,16 @@ public override void ExecuteList(CommandEventArgs e, List<object> list)
}
}

private class DeleteObjectsNoticeGump : StaticWarningGump<DeleteObjectsNoticeGump>
{
public override int Width => 420;
public override int Height => 280;
public override string Content { get; }

public DeleteObjectsNoticeGump(int count, Action<bool> callback) : base(callback) =>
Content = $"You are about to delete {count} objects. This cannot be undone without a full server revert.<br><br>Continue?";
}

public override void Execute(CommandEventArgs e, object obj)
{
if (obj is Item item)
Expand Down
20 changes: 13 additions & 7 deletions Projects/UOContent/Commands/Generic/Commands/DesignInsert.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Server.Gumps;
using Server.Items;
Expand Down Expand Up @@ -87,19 +88,24 @@ public override void ExecuteList(CommandEventArgs e, List<object> list)
{
var from = e.Mobile;
from.SendGump(
new WarningGump(
1060637,
30720,
$"You are about to insert {list.Count} objects. This cannot be undone without a full server revert.<br><br>Continue?",
0xFFC000,
420,
280,
new InsertObjectsNoticeGump(
list.Count,
okay => OnConfirmCallback(from, okay, list, e.Length < 1 || !e.GetBoolean(0))
)
);
AddResponse("Awaiting confirmation...");
}

private class InsertObjectsNoticeGump : StaticWarningGump<InsertObjectsNoticeGump>
{
public override int Width => 420;
public override int Height => 280;
public override string Content { get; }

public InsertObjectsNoticeGump(int count, Action<bool> callback) : base(callback) =>
Content = $"You are about to insert {count} objects. This cannot be undone without a full server revert.<br><br>Continue?";
}

private void OnConfirmCallback(Mobile from, bool okay, List<object> list, bool staticsOnly)
{
var flushToLog = false;
Expand Down
20 changes: 13 additions & 7 deletions Projects/UOContent/Commands/Handlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,8 @@ public static void ClearFacet_OnCommand(CommandEventArgs e)
);

from.SendGump(
new WarningGump(
1060635,
30720,
$"You are about to delete {list.Count} object{(list.Count == 1 ? "" : "s")} from this facet. Do you really wish to continue?",
0xFFC000,
360,
260,
new DeleteObjectsNoticeGump(
list.Count,
okay => DeleteList_Callback(from, okay, list)
)
);
Expand All @@ -268,6 +263,17 @@ public static void ClearFacet_OnCommand(CommandEventArgs e)
}
}

private class DeleteObjectsNoticeGump : StaticWarningGump<DeleteObjectsNoticeGump>
{
public override int Header => 1060635; // <CENTER>WARNING</CENTER>
public override int Width => 360;
public override int Height => 260;
public override string Content { get; }

public DeleteObjectsNoticeGump(int count, Action<bool> callback) : base(callback) =>
Content = $"You are about to delete {count} object{(count == 1 ? "" : "s")} from this facet. Do you really wish to continue?";
}

[Usage("GetFollowers")]
[Description("Teleports all pets of a targeted player to your location.")]
public static void GetFollowers_OnCommand(CommandEventArgs e)
Expand Down
68 changes: 15 additions & 53 deletions Projects/UOContent/Gumps/AdminGump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1767,13 +1767,8 @@ public static void Marked_Callback(Mobile from, bool okay, bool ban, List<object
}

from.SendGump(
new NoticeGump(
1060637,
30720,
new AdminNoticeGump(
$"You have {(ban ? "banned" : "deleted")} the account{(rads.Count == 1 ? "" : "s")}.",
0xFFC000,
420,
280,
() => ResendGump_Callback(from, list, rads, ban ? page : 0)
)
);
Expand All @@ -1786,13 +1781,8 @@ public static void Marked_Callback(Mobile from, bool okay, bool ban, List<object
else
{
from.SendGump(
new NoticeGump(
1060637,
30720,
new AdminNoticeGump(
$"You have chosen not to {(ban ? "ban" : "delete")} the account{(rads.Count == 1 ? "" : "s")}.",
0xFFC000,
420,
280,
() => ResendGump_Callback(from, list, rads, page)
)
);
Expand Down Expand Up @@ -3049,10 +3039,7 @@ public override void OnResponse(NetState sender, in RelayInfo info)

from.SendGump(
new WarningGump(
1060635,
30720,
sb.ToString(),
0xFFC000,
420,
400,
okay => BanShared_Callback(from, okay, a)
Expand Down Expand Up @@ -3099,10 +3086,7 @@ public override void OnResponse(NetState sender, in RelayInfo info)
{
from.SendGump(
new WarningGump(
1060635,
30720,
$"You are about to firewall {a.LoginIPs.Length} address{(a.LoginIPs.Length != 1 ? "s" : "")}. Do you wish to continue?",
0xFFC000,
420,
400,
okay => FirewallShared_Callback(from, okay, a)
Expand Down Expand Up @@ -3237,10 +3221,7 @@ public override void OnResponse(NetState sender, in RelayInfo info)

from.SendGump(
new WarningGump(
1060635,
30720,
$"<center>Account of {a.Username}</center><br>You are about to <em><basefont color=red>permanently delete</basefont></em> the account. Likewise, all characters on the account will be deleted, including equipped, inventory, and banked items. Any houses tied to the account will be demolished.<br><br>Do you wish to continue?",
0xFFC000,
420,
280,
okay => AccountDelete_Callback(from, okay, a)
Expand All @@ -3266,10 +3247,7 @@ public override void OnResponse(NetState sender, in RelayInfo info)
{
from.SendGump(
new WarningGump(
1060635,
30720,
$"You are about to ban {rads.Count} marked account{(rads.Count == 1 ? "" : "s")}. Be cautioned, the only way to reverse this is by hand--manually unbanning each account.<br><br>Do you wish to continue?",
0xFFC000,
420,
280,
okay => Marked_Callback(from, okay, true, list, rads, m_ListPage)
Expand All @@ -3279,13 +3257,8 @@ public override void OnResponse(NetState sender, in RelayInfo info)
else
{
from.SendGump(
new NoticeGump(
1060637,
30720,
new AdminNoticeGump(
"You have not yet marked any accounts. Place a check mark next to the accounts you wish to ban and then try again.",
0xFFC000,
420,
280,
() => ResendGump_Callback(from, list, rads, m_ListPage)
)
);
Expand All @@ -3306,14 +3279,7 @@ public override void OnResponse(NetState sender, in RelayInfo info)
{
from.SendGump(
new WarningGump(
1060635,
30720,
string.Format(
"You are about to <em><basefont color=red>permanently delete</basefont></em> {0} marked account{1}. Likewise, all characters on the account{1} will be deleted, including equipped, inventory, and banked items. Any houses tied to the account{1} will be demolished.<br><br>Do you wish to continue?",
rads.Count,
rads.Count == 1 ? "" : "s"
),
0xFFC000,
$"You are about to <em><basefont color=red>permanently delete</basefont></em> {rads.Count} marked account{(rads.Count == 1 ? "" : "s")}. Likewise, all characters on the account{(rads.Count == 1 ? "" : "s")} will be deleted, including equipped, inventory, and banked items. Any houses tied to the account{(rads.Count == 1 ? "" : "s")} will be demolished.<br><br>Do you wish to continue?",
420,
280,
okay => Marked_Callback(from, okay, false, list, rads, m_ListPage)
Expand All @@ -3323,13 +3289,8 @@ public override void OnResponse(NetState sender, in RelayInfo info)
else
{
from.SendGump(
new NoticeGump(
1060637,
30720,
new AdminNoticeGump(
"You have not yet marked any accounts. Place a check mark next to the accounts you wish to ban and then try again.",
0xFFC000,
420,
280,
() => ResendGump_Callback(from, list, rads, m_ListPage)
)
);
Expand Down Expand Up @@ -3554,10 +3515,7 @@ public override void OnResponse(NetState sender, in RelayInfo info)
{
from.SendGump(
new WarningGump(
1060635,
30720,
$"You are about to clear the address list for account {a} containing {ips.Length} {(ips.Length == 1 ? "entry" : "entries")}. Do you wish to continue?",
0xFFC000,
420,
280,
okay => RemoveLoginIPs_Callback(from, okay, a)
Expand Down Expand Up @@ -3998,10 +3956,7 @@ public override void OnResponse(NetState sender, in RelayInfo info)
{
from.SendGump(
new WarningGump(
1060635,
30720,
$"You are about to firewall {m_List[index]}. All connection attempts from a matching IP will be refused. Are you sure?",
0xFFC000,
420,
280,
okay => Firewall_Callback(from, okay, a, m_List[index])
Expand Down Expand Up @@ -4100,10 +4055,7 @@ public override void OnResponse(NetState sender, in RelayInfo info)

from.SendGump(
new WarningGump(
1060635,
30720,
$"You are about to remove address {ip} from account {a}. Do you wish to continue?",
0xFFC000,
420,
280,
okay => RemoveLoginIP_Callback(from, okay, a, ip)
Expand Down Expand Up @@ -4395,5 +4347,15 @@ public int Compare(IAccount x, IAccount y)
return aLevel < bLevel ? 1 : x.Username.InsensitiveCompare(y.Username);
}
}

private class AdminNoticeGump : StaticNoticeGump<AdminNoticeGump>
{
public override int Width => 420;
public override int Height => 280;

public override string Content { get; }

public AdminNoticeGump(string content, Action callback) : base(callback) => Content = content;
}
}
}

0 comments on commit bb7bc57

Please sign in to comment.