Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class ConfirmDialogGump : DialogGump
|
||||
{
|
||||
public virtual bool Confirmed { get; set; }
|
||||
|
||||
public ConfirmDialogGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
string title = null,
|
||||
string html = null,
|
||||
int icon = 7022,
|
||||
Action<GumpButton> onAccept = null,
|
||||
Action<GumpButton> onCancel = null)
|
||||
: base(user, parent, x, y, title, html, icon, onAccept, onCancel)
|
||||
{ }
|
||||
|
||||
protected override void OnAccept(GumpButton button)
|
||||
{
|
||||
Confirmed = true;
|
||||
base.OnAccept(button);
|
||||
}
|
||||
|
||||
protected override void OnCancel(GumpButton button)
|
||||
{
|
||||
Confirmed = false;
|
||||
base.OnCancel(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
267
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Dialogs/Dialog.cs
Normal file
267
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Dialogs/Dialog.cs
Normal file
@@ -0,0 +1,267 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#if ServUO58
|
||||
#define ServUOX
|
||||
#endif
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class DialogGump : SuperGump
|
||||
{
|
||||
public static int Defaultwidth = 400;
|
||||
public static int DefaultHeight = 300;
|
||||
|
||||
public static int DefaultIcon = 7000;
|
||||
public static string DefaultTitle = "Dialog";
|
||||
|
||||
protected IconDefinition _Icon;
|
||||
|
||||
public virtual Action<GumpButton> AcceptHandler { get; set; }
|
||||
public virtual Action<GumpButton> CancelHandler { get; set; }
|
||||
|
||||
public virtual string Title { get; set; }
|
||||
|
||||
public virtual bool HtmlBackground { get; set; }
|
||||
public virtual bool HtmlScrollbar { get; set; }
|
||||
|
||||
public virtual Color HtmlColor { get; set; }
|
||||
public virtual string Html { get; set; }
|
||||
|
||||
public virtual int Icon { get => _Icon.AssetID; set => _Icon.AssetID = Math.Max(0, value); }
|
||||
public virtual int IconHue { get => _Icon.Hue; set => _Icon.Hue = Math.Max(0, value); }
|
||||
|
||||
public virtual bool IconItem
|
||||
{
|
||||
get => _Icon.IsItemArt;
|
||||
set => _Icon.AssetType = value ? IconType.ItemArt : IconType.GumpArt;
|
||||
}
|
||||
|
||||
public virtual int IconTooltip { get; set; }
|
||||
|
||||
public virtual int Width { get; set; }
|
||||
public virtual int Height { get; set; }
|
||||
|
||||
public DialogGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
string title = null,
|
||||
string html = null,
|
||||
int icon = -1,
|
||||
Action<GumpButton> onAccept = null,
|
||||
Action<GumpButton> onCancel = null)
|
||||
: base(user, parent, x, y)
|
||||
{
|
||||
_Icon = IconDefinition.FromGump(icon >= 0 ? icon : DefaultIcon);
|
||||
_Icon.ComputeOffset = false;
|
||||
|
||||
Modal = true;
|
||||
CanDispose = false;
|
||||
|
||||
HtmlBackground = false;
|
||||
HtmlScrollbar = true;
|
||||
|
||||
HtmlColor = DefaultHtmlColor;
|
||||
|
||||
Width = Defaultwidth;
|
||||
Height = DefaultHeight;
|
||||
|
||||
Title = title ?? DefaultTitle;
|
||||
Html = html;
|
||||
|
||||
AcceptHandler = onAccept;
|
||||
CancelHandler = onCancel;
|
||||
}
|
||||
|
||||
protected virtual void OnAccept(GumpButton button)
|
||||
{
|
||||
if (AcceptHandler != null)
|
||||
{
|
||||
AcceptHandler(button);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnCancel(GumpButton button)
|
||||
{
|
||||
if (CancelHandler != null)
|
||||
{
|
||||
CancelHandler(button);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
Width = Math.Max(300, Math.Min(1024, Width));
|
||||
Height = Math.Max(200, Math.Min(768, Height));
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 9270;
|
||||
|
||||
layout.Add(
|
||||
"background/body/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 0, Width, Height, bgID);
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(10, 10, Width - 20, Height - 20, 2624);
|
||||
//AddAlphaRegion(10, 10, Width - 20, Height - 20);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"background/header/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 0, Width, 50, bgID);
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(10, 10, Width - 20, 30, 2624);
|
||||
//AddAlphaRegion(10, 10, Width - 20, 30);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"label/header/title",
|
||||
() =>
|
||||
{
|
||||
var title = Title.WrapUOHtmlBig().WrapUOHtmlColor(HtmlColor, false);
|
||||
|
||||
AddHtml(15, 15, Width - 30, 40, title, false, false);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"image/body/icon",
|
||||
() =>
|
||||
{
|
||||
if (_Icon == null || _Icon.IsEmpty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var iw = Math.Max(32, _Icon.Size.Width);
|
||||
var ih = Math.Max(32, _Icon.Size.Height);
|
||||
|
||||
if (sup)
|
||||
{
|
||||
if (_Icon.IsSpellIcon)
|
||||
{
|
||||
AddBackground(10, 50, iw + 30, ih + 30, 30536);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddBackground(15, 55, iw + 20, ih + 20, 40000);
|
||||
AddImageTiled(25, 65, iw, ih, 2624);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddBackground(15, 55, iw + 20, ih + 20, 9270);
|
||||
AddImageTiled(25, 65, iw, ih, 2624);
|
||||
}
|
||||
|
||||
_Icon.AddToGump(this, 25, 65);
|
||||
|
||||
if (IconTooltip > 0)
|
||||
{
|
||||
if (IconTooltip >= 0x40000000)
|
||||
{
|
||||
#if ServUOX
|
||||
AddProperties(new Serial(IconTooltip));
|
||||
#else
|
||||
AddProperties(IconTooltip);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
AddTooltip(IconTooltip);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"html/body/info",
|
||||
() =>
|
||||
{
|
||||
var x = 15;
|
||||
var y = 55;
|
||||
var w = Width - 30;
|
||||
var h = Height - 110;
|
||||
|
||||
if (_Icon != null && !_Icon.IsEmpty)
|
||||
{
|
||||
var iw = Math.Max(32, _Icon.Size.Width);
|
||||
|
||||
x += iw + 25;
|
||||
w -= iw + 25;
|
||||
}
|
||||
|
||||
if (SupportsUltimaStore)
|
||||
{
|
||||
AddBackground(x, y, w, h, 39925);
|
||||
|
||||
x += 20;
|
||||
y += 22;
|
||||
w -= 25;
|
||||
h -= 38;
|
||||
}
|
||||
|
||||
AddHtml(x, y, w, h, Html.WrapUOHtmlColor(HtmlColor, false), HtmlBackground, HtmlScrollbar);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"button/body/cancel",
|
||||
() =>
|
||||
{
|
||||
AddButton(Width - 90, Height - 45, 4018, 4019, OnCancel);
|
||||
AddTooltip(1006045);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"button/body/accept",
|
||||
() =>
|
||||
{
|
||||
AddButton(Width - 50, Height - 45, 4015, 4016, OnAccept);
|
||||
AddTooltip(1006044);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnDispose()
|
||||
{
|
||||
base.OnDispose();
|
||||
|
||||
_Icon = null;
|
||||
|
||||
AcceptHandler = null;
|
||||
CancelHandler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class ErrorDialogGump : DialogGump
|
||||
{
|
||||
public virtual Exception Error { get; set; }
|
||||
|
||||
public ErrorDialogGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
string title = null,
|
||||
Exception error = null,
|
||||
int icon = 7019,
|
||||
Action<GumpButton> onAccept = null,
|
||||
Action<GumpButton> onCancel = null)
|
||||
: base(user, parent, x, y, title, String.Empty, icon, onAccept, onCancel)
|
||||
{
|
||||
Error = error;
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
Html = Error != null ? Error.ToString() : String.Empty;
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class InputDateDialogGump : InputDialogGump
|
||||
{
|
||||
protected int Day;
|
||||
protected int Month;
|
||||
protected int Year;
|
||||
|
||||
public virtual Action<GumpButton, DateTime?> CallbackDate { get; set; }
|
||||
|
||||
public virtual DateTime MinDate { get; set; }
|
||||
public virtual DateTime MaxDate { get; set; }
|
||||
public virtual DateTime? InputDate { get; set; }
|
||||
|
||||
public InputDateDialogGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
string title = "Date Input",
|
||||
string html = "Enter a date below.",
|
||||
DateTime? input = null,
|
||||
DateTime? minDate = null,
|
||||
DateTime? maxDate = null,
|
||||
int icon = 7020,
|
||||
Action<GumpButton> onAccept = null,
|
||||
Action<GumpButton> onCancel = null,
|
||||
Action<GumpButton, DateTime?> callback = null)
|
||||
: base(user, parent, x, y, title, html, String.Empty, 10, icon, onAccept, onCancel)
|
||||
{
|
||||
if (input != null)
|
||||
{
|
||||
InputDate = input;
|
||||
InputText = InputDate.Value.ToSimpleString("m-d-y");
|
||||
}
|
||||
|
||||
MinDate = minDate ?? DateTime.MinValue;
|
||||
MaxDate = maxDate ?? DateTime.MaxValue;
|
||||
|
||||
Limit = 10;
|
||||
|
||||
CallbackDate = callback;
|
||||
|
||||
Callback = (b, text) =>
|
||||
{
|
||||
if (CallbackDate != null)
|
||||
{
|
||||
CallbackDate(b, InputDate);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
base.Compile();
|
||||
|
||||
Limit = 10;
|
||||
InputText = InputDate.HasValue ? InputDate.Value.ToSimpleString("m-d-y") : String.Empty;
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
layout.Remove("background/body/input");
|
||||
layout.Remove("textentry/body/input");
|
||||
|
||||
layout.Add(
|
||||
"background/body/input/month",
|
||||
() =>
|
||||
{
|
||||
AddHtml(20, Height - 45, 20, 20, "MM".WrapUOHtmlColor(HtmlColor), false, false);
|
||||
AddBackground(50, 250, 40, 30, 9350);
|
||||
AddTextEntryLimited(
|
||||
55,
|
||||
Height - 45,
|
||||
30,
|
||||
20,
|
||||
TextHue,
|
||||
0,
|
||||
InputDate.HasValue ? InputDate.Value.Month.ToString("D2") : String.Empty,
|
||||
2,
|
||||
ParseInput);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"background/body/input/day",
|
||||
() =>
|
||||
{
|
||||
AddHtml(100, Height - 45, 20, 20, "DD".WrapUOHtmlColor(HtmlColor), false, false);
|
||||
AddBackground(130, 250, 40, 30, 9350);
|
||||
AddTextEntryLimited(
|
||||
135,
|
||||
Height - 45,
|
||||
30,
|
||||
20,
|
||||
TextHue,
|
||||
1,
|
||||
InputDate.HasValue ? InputDate.Value.Day.ToString("D2") : String.Empty,
|
||||
2,
|
||||
ParseInput);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"background/body/input/year",
|
||||
() =>
|
||||
{
|
||||
AddHtml(180, Height - 45, 40, 20, "YYYY".WrapUOHtmlColor(HtmlColor), false, false);
|
||||
AddBackground(220, 250, 70, 30, 9350);
|
||||
AddTextEntryLimited(
|
||||
225,
|
||||
Height - 45,
|
||||
60,
|
||||
20,
|
||||
TextHue,
|
||||
2,
|
||||
InputDate.HasValue ? InputDate.Value.Year.ToString("D4") : String.Empty,
|
||||
4,
|
||||
ParseInput);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void ParseInput(GumpTextEntryLimited entry, string text)
|
||||
{
|
||||
switch (entry.EntryID)
|
||||
{
|
||||
case 0:
|
||||
Month = Int32.TryParse(text, out Month) ? Math.Max(1, Math.Min(12, Month)) : 0;
|
||||
break;
|
||||
case 1:
|
||||
Day = Int32.TryParse(text, out Day) ? Math.Max(1, Math.Min(31, Day)) : 0;
|
||||
break;
|
||||
case 2:
|
||||
Year = Int32.TryParse(text, out Year) ? Math.Max(1, Math.Min(9999, Year)) : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
base.ParseInput(entry, text);
|
||||
}
|
||||
|
||||
protected override void ParseInput(string text)
|
||||
{
|
||||
if (Year > 0 && Month > 0 && Day > 0)
|
||||
{
|
||||
Day = Math.Min(DateTime.DaysInMonth(Year, Month), Day);
|
||||
InputDate = new DateTime(Year, Month, Day);
|
||||
}
|
||||
else
|
||||
{
|
||||
InputDate = null;
|
||||
}
|
||||
|
||||
if (InputDate.HasValue)
|
||||
{
|
||||
if (InputDate < MinDate)
|
||||
{
|
||||
InputDate = MinDate;
|
||||
}
|
||||
else if (InputDate > MaxDate)
|
||||
{
|
||||
InputDate = MaxDate;
|
||||
}
|
||||
}
|
||||
|
||||
base.ParseInput(InputDate.HasValue ? InputDate.Value.ToSimpleString("m-d-y") : String.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class InputDialogGump : DialogGump
|
||||
{
|
||||
public virtual Action<GumpButton, string> Callback { get; set; }
|
||||
|
||||
public virtual string InputText { get; set; }
|
||||
public virtual int Limit { get; set; }
|
||||
|
||||
public bool Limited => Limit > 0;
|
||||
|
||||
public InputDialogGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
string title = null,
|
||||
string html = null,
|
||||
string input = null,
|
||||
int limit = 0,
|
||||
int icon = 7020,
|
||||
Action<GumpButton> onAccept = null,
|
||||
Action<GumpButton> onCancel = null,
|
||||
Action<GumpButton, string> callback = null)
|
||||
: base(user, parent, x, y, title, html, icon, onAccept, onCancel)
|
||||
{
|
||||
InputText = input ?? String.Empty;
|
||||
Limit = limit;
|
||||
Callback = callback;
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
layout.Add("background/body/input", () => AddBackground(20, Height - 50, Width - 120, 30, 9350));
|
||||
|
||||
layout.Add(
|
||||
"textentry/body/input",
|
||||
() =>
|
||||
{
|
||||
if (Limited)
|
||||
{
|
||||
AddTextEntryLimited(25, Height - 45, Width - 130, 20, TextHue, InputText, Limit, ParseInput);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddTextEntry(25, Height - 45, Width - 130, 20, TextHue, InputText, ParseInput);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void ParseInput(GumpTextEntry entry, string text)
|
||||
{
|
||||
ParseInput(text);
|
||||
}
|
||||
|
||||
protected virtual void ParseInput(GumpTextEntryLimited entry, string text)
|
||||
{
|
||||
ParseInput(text);
|
||||
}
|
||||
|
||||
protected virtual void ParseInput(string text)
|
||||
{
|
||||
InputText = text;
|
||||
}
|
||||
|
||||
protected override void OnAccept(GumpButton button)
|
||||
{
|
||||
if (Callback != null)
|
||||
{
|
||||
Callback(button, InputText);
|
||||
}
|
||||
|
||||
base.OnAccept(button);
|
||||
}
|
||||
|
||||
protected override void OnCancel(GumpButton button)
|
||||
{
|
||||
InputText = String.Empty;
|
||||
|
||||
base.OnCancel(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class NoticeDialogGump : DialogGump
|
||||
{
|
||||
public NoticeDialogGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
string title = null,
|
||||
string html = null,
|
||||
int icon = 7004,
|
||||
Action<GumpButton> onAccept = null,
|
||||
Action<GumpButton> onCancel = null)
|
||||
: base(user, parent, x, y, title, html, icon, onAccept, onCancel)
|
||||
{ }
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
layout.Remove("button/body/cancel");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class DigitalNumericDisplayGump : SuperGump
|
||||
{
|
||||
public int NumericWidth { get; set; }
|
||||
public int NumericHeight { get; set; }
|
||||
public int[] Numerics { get; set; }
|
||||
public int DisplayID { get; set; }
|
||||
public int NumericDisplayID { get; set; }
|
||||
|
||||
public DigitalNumericDisplayGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
int numericWidth = 30,
|
||||
int numericHeight = 60,
|
||||
int displayID = 10004,
|
||||
int numericDisplayID = 30073,
|
||||
params int[] numbers)
|
||||
: base(user, parent, x, y)
|
||||
{
|
||||
NumericWidth = numericWidth;
|
||||
NumericHeight = numericHeight;
|
||||
Numerics = numbers ?? new int[0];
|
||||
DisplayID = displayID;
|
||||
NumericDisplayID = numericDisplayID;
|
||||
|
||||
ForceRecompile = true;
|
||||
}
|
||||
|
||||
public static bool HasLines(ref int numeric, LCDLines lines)
|
||||
{
|
||||
return LCD.HasLines(Math.Max(0, Math.Min(9, numeric)), lines);
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
for (var i = 0; i < Numerics.Length; i++)
|
||||
{
|
||||
Numerics[i] = Math.Max(0, Math.Min(9, Numerics[i]));
|
||||
}
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
int lineHeight = (NumericHeight / 16),
|
||||
lineWidth = (NumericWidth / 9),
|
||||
halfHeight = (NumericHeight / 2),
|
||||
halfWidth = (NumericWidth / 2),
|
||||
eachWidth = (NumericWidth + halfWidth),
|
||||
width = 20 + (eachWidth * Numerics.Length),
|
||||
height = 20 + NumericHeight;
|
||||
|
||||
layout.Add("background/body/base", () => AddBackground(0, 0, width, height, 9270));
|
||||
|
||||
CompileNumericEntries(layout, width, height, lineHeight, lineWidth, halfHeight, halfWidth, eachWidth);
|
||||
}
|
||||
|
||||
protected virtual void CompileNumericEntries(
|
||||
SuperGumpLayout layout,
|
||||
int width,
|
||||
int height,
|
||||
int lineHeight,
|
||||
int lineWidth,
|
||||
int halfHeight,
|
||||
int halfWidth,
|
||||
int eachWidth)
|
||||
{
|
||||
for (var idx = 0; idx < Numerics.Length; idx++)
|
||||
{
|
||||
CompileNumericEntry(
|
||||
layout,
|
||||
lineHeight,
|
||||
lineWidth,
|
||||
halfHeight,
|
||||
halfWidth,
|
||||
idx,
|
||||
Numerics[idx],
|
||||
10 + (eachWidth * idx),
|
||||
10);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CompileNumericEntry(
|
||||
SuperGumpLayout layout,
|
||||
int lineHeight,
|
||||
int lineWidth,
|
||||
int halfHeight,
|
||||
int halfWidth,
|
||||
int index,
|
||||
int numeric,
|
||||
int xOffset,
|
||||
int yOffset)
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/bg" + index,
|
||||
() => AddImageTiled(xOffset, 10, NumericWidth + halfWidth, NumericHeight, DisplayID));
|
||||
|
||||
if (HasLines(ref numeric, LCDLines.Top))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/lines/t" + index,
|
||||
() => AddImageTiled(xOffset, yOffset, NumericWidth, lineHeight, NumericDisplayID));
|
||||
}
|
||||
|
||||
if (HasLines(ref numeric, LCDLines.TopLeft))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/lines/tl" + index,
|
||||
() => AddImageTiled(xOffset, yOffset, lineWidth, halfHeight, NumericDisplayID));
|
||||
}
|
||||
|
||||
if (HasLines(ref numeric, LCDLines.TopRight))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/lines/tr" + index,
|
||||
() => AddImageTiled(xOffset + (NumericWidth - lineWidth), yOffset, lineWidth, halfHeight, NumericDisplayID));
|
||||
}
|
||||
|
||||
if (HasLines(ref numeric, LCDLines.Middle))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/lines/m" + index,
|
||||
() => AddImageTiled(
|
||||
xOffset,
|
||||
yOffset + (halfHeight - (lineHeight / 2)),
|
||||
NumericWidth,
|
||||
lineHeight,
|
||||
NumericDisplayID));
|
||||
}
|
||||
|
||||
if (HasLines(ref numeric, LCDLines.BottomLeft))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/lines/bl" + index,
|
||||
() => AddImageTiled(xOffset, yOffset + halfHeight, lineWidth, halfHeight, 30073));
|
||||
}
|
||||
|
||||
if (HasLines(ref numeric, LCDLines.BottomRight))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/lines/br" + index,
|
||||
() => AddImageTiled(
|
||||
xOffset + (NumericWidth - lineWidth),
|
||||
yOffset + halfHeight,
|
||||
lineWidth,
|
||||
halfHeight,
|
||||
NumericDisplayID));
|
||||
}
|
||||
|
||||
if (HasLines(ref numeric, LCDLines.Bottom))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/lines/b" + index,
|
||||
() => AddImageTiled(xOffset, yOffset + (NumericHeight - lineHeight), NumericWidth, lineHeight, NumericDisplayID));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
168
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Info/OPLGump.cs
Normal file
168
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Info/OPLGump.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
using VitaNex.Text;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class OPLGump : SuperGump
|
||||
{
|
||||
private readonly IconDefinition _DefIcon = IconDefinition.FromItem(1, 0);
|
||||
private readonly string[] _DefProperties = { "Unknown Object" };
|
||||
|
||||
public IEntity Entity { get; set; }
|
||||
|
||||
public IconDefinition Icon { get; set; }
|
||||
public string[] Properties { get; set; }
|
||||
|
||||
public OPLGump(Mobile user, Gump parent = null)
|
||||
: base(user, parent)
|
||||
{
|
||||
CanClose = true;
|
||||
CanDispose = true;
|
||||
CanMove = true;
|
||||
CanResize = false;
|
||||
}
|
||||
|
||||
public OPLGump(Mobile user, IEntity entity, Gump parent = null)
|
||||
: this(user, parent)
|
||||
{
|
||||
Entity = entity;
|
||||
}
|
||||
|
||||
public OPLGump(Mobile user, int itemID, string name, Gump parent = null)
|
||||
: this(user, itemID, 0, name, parent)
|
||||
{ }
|
||||
|
||||
public OPLGump(Mobile user, int itemID, int hue, string name, Gump parent = null)
|
||||
: this(user, itemID, hue, new[] { name }, parent)
|
||||
{ }
|
||||
|
||||
public OPLGump(Mobile user, int itemID, string[] props, Gump parent = null)
|
||||
: this(user, itemID, 0, props, parent)
|
||||
{ }
|
||||
|
||||
public OPLGump(Mobile user, int itemID, int hue, string[] props, Gump parent = null)
|
||||
: this(user, parent)
|
||||
{
|
||||
Icon = IconDefinition.FromItem(itemID, hue);
|
||||
|
||||
Properties = props;
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
if (Entity != null)
|
||||
{
|
||||
var id = 0;
|
||||
|
||||
if (Entity is Mobile)
|
||||
{
|
||||
id = ShrinkTable.Lookup((Mobile)Entity);
|
||||
}
|
||||
else if (Entity is Item)
|
||||
{
|
||||
id = ((Item)Entity).ItemID;
|
||||
}
|
||||
|
||||
|
||||
if (Entity.GetPropertyValue("Hue", out
|
||||
int hue))
|
||||
{
|
||||
Icon = IconDefinition.FromItem(id, hue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Icon = IconDefinition.FromItem(id);
|
||||
}
|
||||
|
||||
Properties = Entity.GetOPLStrings(User).ToArray();
|
||||
}
|
||||
|
||||
if (Icon == null || Icon.IsEmpty)
|
||||
{
|
||||
Icon = _DefIcon;
|
||||
}
|
||||
|
||||
if (Properties.IsNullOrEmpty())
|
||||
{
|
||||
Properties = _DefProperties;
|
||||
}
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var pad = sup ? 15 : 10;
|
||||
var pad2 = pad * 2;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 5054;
|
||||
|
||||
var size = Icon.Size;
|
||||
|
||||
var innerHeight = UOFont.GetUnicodeHeight(1, Properties);
|
||||
|
||||
var outerHeight = innerHeight + pad2;
|
||||
|
||||
if (outerHeight < size.Height + pad2)
|
||||
{
|
||||
outerHeight = size.Height + pad2;
|
||||
innerHeight = outerHeight - pad2;
|
||||
}
|
||||
|
||||
layout.Add(
|
||||
"bg",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 0, size.Width + pad2, size.Height + pad2, bgID);
|
||||
AddBackground(size.Width + pad2, 0, 400, outerHeight, bgID);
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(pad, pad, size.Width, size.Height, 2624);
|
||||
AddAlphaRegion(pad, pad, size.Width, size.Height);
|
||||
|
||||
AddImageTiled(size.Width + pad2 + pad, pad, 400 - pad2, innerHeight, 2624);
|
||||
AddAlphaRegion(size.Width + pad2 + pad, pad, 400 - pad2, innerHeight);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"info",
|
||||
() =>
|
||||
{
|
||||
Icon.AddToGump(this, pad, pad);
|
||||
|
||||
var lines = Properties.Select((s, i) => i == 0 ? s.ToUpperWords().WrapUOHtmlColor(Color.Yellow) : s);
|
||||
var value = String.Join("\n", lines);
|
||||
|
||||
value = value.ToUpperWords();
|
||||
value = value.WrapUOHtmlCenter();
|
||||
value = value.WrapUOHtmlColor(Color.White, false);
|
||||
|
||||
AddHtml(size.Width + pad2 + pad, pad, 400 - pad2, innerHeight, value, false, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
353
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Info/ProgressBar.cs
Normal file
353
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Info/ProgressBar.cs
Normal file
@@ -0,0 +1,353 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public enum ProgressBarFlow
|
||||
{
|
||||
Up = Direction.Up,
|
||||
UpRight = Direction.North,
|
||||
Right = Direction.Right,
|
||||
DownRight = Direction.East,
|
||||
Down = Direction.Down,
|
||||
DownLeft = Direction.South,
|
||||
Left = Direction.Left,
|
||||
UpLeft = Direction.West
|
||||
}
|
||||
|
||||
public class ProgressBarGump : SuperGump
|
||||
{
|
||||
public static int DefaultWidth = 210;
|
||||
public static int DefaultHeight = 25;
|
||||
|
||||
public static int DefaultPadding = 5;
|
||||
|
||||
public static int DefaultBackgroundID = 9400;
|
||||
public static int DefaultForegroundID = 1464;
|
||||
|
||||
public static string DefaultText = "Progress";
|
||||
|
||||
public static ProgressBarFlow DefaultFlow = ProgressBarFlow.Right;
|
||||
|
||||
private double? _InitValue, _InitMaxValue;
|
||||
|
||||
private double _Value;
|
||||
private double _MaxValue;
|
||||
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public int Padding { get; set; }
|
||||
|
||||
public int BackgroundID { get; set; }
|
||||
public int ForegroundID { get; set; }
|
||||
|
||||
public Color TextColor { get; set; }
|
||||
public string Text { get; set; }
|
||||
|
||||
public bool DisplayPercent { get; set; }
|
||||
public ProgressBarFlow Flow { get; set; }
|
||||
|
||||
public Action<ProgressBarGump, double> ValueChanged { get; set; }
|
||||
|
||||
public double MaxValue
|
||||
{
|
||||
get => _MaxValue;
|
||||
set
|
||||
{
|
||||
_MaxValue = value;
|
||||
|
||||
if (_InitMaxValue == null)
|
||||
{
|
||||
_InitMaxValue = _MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double Value
|
||||
{
|
||||
get => _Value;
|
||||
set
|
||||
{
|
||||
if (_Value == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldValue = _Value;
|
||||
|
||||
InternalValue = Math.Min(_MaxValue, value);
|
||||
|
||||
OnValueChanged(oldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public double InternalValue
|
||||
{
|
||||
get => Value;
|
||||
set
|
||||
{
|
||||
if (_Value == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Value = Math.Min(_MaxValue, value);
|
||||
|
||||
if (_InitValue == null)
|
||||
{
|
||||
_InitValue = _Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double PercentComplete
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Value == _MaxValue)
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
if (_MaxValue != 0)
|
||||
{
|
||||
return _Value / _MaxValue;
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Completed => PercentComplete >= 1.0;
|
||||
|
||||
public ProgressBarGump(
|
||||
Mobile user,
|
||||
string text,
|
||||
double max,
|
||||
double value = 0,
|
||||
bool displayPercent = true,
|
||||
ProgressBarFlow? flow = null,
|
||||
Action<ProgressBarGump, double> valueChanged = null)
|
||||
: this(user, null, null, null, null, null, text, max, value, displayPercent, flow, valueChanged)
|
||||
{ }
|
||||
|
||||
public ProgressBarGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
int? w = null,
|
||||
int? h = null,
|
||||
string text = null,
|
||||
double max = 100,
|
||||
double value = 0,
|
||||
bool displayPercent = true,
|
||||
ProgressBarFlow? flow = null,
|
||||
Action<ProgressBarGump, double> valueChanged = null)
|
||||
: base(user, parent, x, y)
|
||||
{
|
||||
Width = w ?? DefaultWidth;
|
||||
Height = h ?? DefaultHeight;
|
||||
|
||||
BackgroundID = DefaultBackgroundID;
|
||||
ForegroundID = DefaultForegroundID;
|
||||
|
||||
Padding = DefaultPadding;
|
||||
|
||||
TextColor = DefaultHtmlColor;
|
||||
Text = text ?? DefaultText;
|
||||
|
||||
DisplayPercent = displayPercent;
|
||||
Flow = flow ?? DefaultFlow;
|
||||
ValueChanged = valueChanged;
|
||||
|
||||
_MaxValue = max;
|
||||
_Value = value;
|
||||
|
||||
ForceRecompile = true;
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
{
|
||||
_Value = _InitValue ?? 0;
|
||||
_MaxValue = _InitMaxValue ?? 100;
|
||||
|
||||
_InitValue = _InitMaxValue = null;
|
||||
}
|
||||
|
||||
public virtual string FormatText(bool html = false)
|
||||
{
|
||||
var text = String.Format("{0} {1}", Text, DisplayPercent ? PercentComplete.ToString("0.##%") : String.Empty);
|
||||
|
||||
if (html && !String.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
text = text.WrapUOHtmlColor(TextColor, false).WrapUOHtmlTag("center");
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
Width = Math.Max(10 + Padding, Math.Min(1024, Width));
|
||||
Height = Math.Max(10 + Padding, Math.Min(768, Height));
|
||||
|
||||
if (Padding < 0)
|
||||
{
|
||||
Padding = DefaultPadding;
|
||||
}
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
protected virtual void OnValueChanged(double oldValue)
|
||||
{
|
||||
if (ValueChanged != null)
|
||||
{
|
||||
ValueChanged(this, oldValue);
|
||||
}
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected bool FlowOffset(ref int x, ref int y, ref int w, ref int h)
|
||||
{
|
||||
double xo = x, yo = y, wo = w, ho = h;
|
||||
|
||||
switch (Flow)
|
||||
{
|
||||
case ProgressBarFlow.Up:
|
||||
{
|
||||
ho *= PercentComplete;
|
||||
yo = (y + h) - ho;
|
||||
}
|
||||
break;
|
||||
case ProgressBarFlow.UpRight:
|
||||
{
|
||||
wo *= PercentComplete;
|
||||
ho *= PercentComplete;
|
||||
yo = (y + h) - ho;
|
||||
}
|
||||
break;
|
||||
case ProgressBarFlow.Right:
|
||||
{
|
||||
wo *= PercentComplete;
|
||||
}
|
||||
break;
|
||||
case ProgressBarFlow.DownRight:
|
||||
{
|
||||
wo *= PercentComplete;
|
||||
ho *= PercentComplete;
|
||||
}
|
||||
break;
|
||||
case ProgressBarFlow.Down:
|
||||
{
|
||||
ho *= PercentComplete;
|
||||
}
|
||||
break;
|
||||
case ProgressBarFlow.DownLeft:
|
||||
{
|
||||
wo *= PercentComplete;
|
||||
ho *= PercentComplete;
|
||||
xo = (x + w) - wo;
|
||||
}
|
||||
break;
|
||||
case ProgressBarFlow.Left:
|
||||
{
|
||||
wo *= PercentComplete;
|
||||
xo = (x + w) - wo;
|
||||
}
|
||||
break;
|
||||
case ProgressBarFlow.UpLeft:
|
||||
{
|
||||
wo *= PercentComplete;
|
||||
ho *= PercentComplete;
|
||||
xo = (x + w) - wo;
|
||||
yo = (y + h) - ho;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
var contained = xo >= x && yo >= y && xo + wo <= x + w && yo + ho <= y + h;
|
||||
|
||||
x = (int)xo;
|
||||
y = (int)yo;
|
||||
w = (int)wo;
|
||||
h = (int)ho;
|
||||
|
||||
return contained;
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var xyPadding = Padding;
|
||||
var whPadding = xyPadding * 2;
|
||||
|
||||
layout.Add(
|
||||
"background/body/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 0, Width, Height, BackgroundID);
|
||||
|
||||
if (Width > whPadding && Height > whPadding)
|
||||
{
|
||||
AddAlphaRegion(xyPadding, xyPadding, Width - whPadding, Height - whPadding);
|
||||
}
|
||||
|
||||
//AddTooltip(Completed ? 1049071 : 1049070);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"imagetiled/body/visual",
|
||||
() =>
|
||||
{
|
||||
if (Width <= whPadding || Height <= whPadding)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int x = xyPadding, y = xyPadding, w = Width - whPadding, h = Height - whPadding;
|
||||
|
||||
if (FlowOffset(ref x, ref y, ref w, ref h))
|
||||
{
|
||||
AddImageTiled(x, y, w, h, ForegroundID);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"html/body/text",
|
||||
() =>
|
||||
{
|
||||
if (Width <= whPadding || Height <= whPadding)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var text = FormatText(true);
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
AddHtml(xyPadding, xyPadding, Width - whPadding, Math.Max(40, Height - whPadding), text, false, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class EntryListGump : ListGump<ListGumpEntry>
|
||||
{
|
||||
public EntryListGump(
|
||||
Mobile user,
|
||||
Gump parent,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<ListGumpEntry> list = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null)
|
||||
: base(user, parent, x, y, list, emptyText, title, opts)
|
||||
{ }
|
||||
|
||||
protected override void SelectEntry(GumpButton button, ListGumpEntry entry)
|
||||
{
|
||||
base.SelectEntry(button, entry);
|
||||
|
||||
if (entry.Handler != null)
|
||||
{
|
||||
entry.Handler(button);
|
||||
}
|
||||
}
|
||||
|
||||
protected override int GetLabelHue(int index, int pageIndex, ListGumpEntry entry)
|
||||
{
|
||||
return entry != null ? entry.Hue : base.GetLabelHue(index, pageIndex, ListGumpEntry.Empty);
|
||||
}
|
||||
|
||||
protected override string GetLabelText(int index, int pageIndex, ListGumpEntry entry)
|
||||
{
|
||||
return entry != null && !String.IsNullOrWhiteSpace(entry.Label)
|
||||
? entry.Label
|
||||
: base.GetLabelText(index, pageIndex, ListGumpEntry.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public abstract class GenericListGump<T> : ListGump<T>
|
||||
{
|
||||
public bool ChangesPending { get; protected set; }
|
||||
|
||||
public virtual bool CanAdd { get; set; }
|
||||
public virtual bool CanRemove { get; set; }
|
||||
public virtual bool CanClear { get; set; }
|
||||
|
||||
public virtual Action<T> AddCallback { get; set; }
|
||||
public virtual Action<T> RemoveCallback { get; set; }
|
||||
public virtual Action<List<T>> ApplyCallback { get; set; }
|
||||
public virtual Action ClearCallback { get; set; }
|
||||
|
||||
public GenericListGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<T> list = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null,
|
||||
bool canAdd = true,
|
||||
bool canRemove = true,
|
||||
bool canClear = true,
|
||||
Action<T> addCallback = null,
|
||||
Action<T> removeCallback = null,
|
||||
Action<List<T>> applyCallback = null,
|
||||
Action clearCallback = null)
|
||||
: base(user, parent, x, y, list, emptyText, title, opts)
|
||||
{
|
||||
CanAdd = canAdd;
|
||||
CanRemove = canRemove;
|
||||
CanClear = canClear;
|
||||
|
||||
AddCallback = addCallback;
|
||||
RemoveCallback = removeCallback;
|
||||
ApplyCallback = applyCallback;
|
||||
ClearCallback = clearCallback;
|
||||
|
||||
ForceRecompile = true;
|
||||
}
|
||||
|
||||
public override string GetSearchKeyFor(T key)
|
||||
{
|
||||
return key != null ? key.ToString() : base.GetSearchKeyFor(default(T));
|
||||
}
|
||||
|
||||
protected override string GetLabelText(int index, int pageIndex, T entry)
|
||||
{
|
||||
return entry != null ? entry.ToString() : base.GetLabelText(index, pageIndex, default(T));
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
if (ChangesPending)
|
||||
{
|
||||
if (!Title.EndsWith(" *"))
|
||||
{
|
||||
Title += " *";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Title.EndsWith(" *"))
|
||||
{
|
||||
Title = Title.Substring(0, Title.Length - 2);
|
||||
}
|
||||
}
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
protected override void CompileMenuOptions(MenuGumpOptions list)
|
||||
{
|
||||
if (ChangesPending)
|
||||
{
|
||||
list.Insert(0, new ListGumpEntry("Apply Changes", HandleApplyChanges, HighlightHue));
|
||||
list.Insert(1, new ListGumpEntry("Clear Changes", HandleClearChanges, HighlightHue));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.RemoveEntry("Apply Changes");
|
||||
list.RemoveEntry("Clear Changes");
|
||||
}
|
||||
|
||||
if (CanAdd)
|
||||
{
|
||||
list.Insert(2, new ListGumpEntry("Add", HandleAdd, HighlightHue));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.RemoveEntry("Add");
|
||||
}
|
||||
|
||||
if (CanClear)
|
||||
{
|
||||
list.Insert(3, new ListGumpEntry("Clear", HandleClear, ErrorHue));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.RemoveEntry("Clear");
|
||||
}
|
||||
|
||||
base.CompileMenuOptions(list);
|
||||
}
|
||||
|
||||
protected override void SelectEntry(GumpButton button, T entry)
|
||||
{
|
||||
base.SelectEntry(button, entry);
|
||||
|
||||
var opts = new MenuGumpOptions();
|
||||
|
||||
CompileEntryOptions(opts, entry);
|
||||
|
||||
new MenuGump(User, Refresh(), opts, button).Send();
|
||||
}
|
||||
|
||||
protected virtual void CompileEntryOptions(MenuGumpOptions opts, T entry)
|
||||
{
|
||||
if (CanRemove)
|
||||
{
|
||||
opts.AppendEntry("Remove", b => HandleRemove(entry), ErrorHue);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleAdd()
|
||||
{
|
||||
if (!OnBeforeListAdd())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var obj = GetListAddObject();
|
||||
|
||||
AddToList(obj);
|
||||
}
|
||||
|
||||
protected virtual void HandleRemove(T entry)
|
||||
{
|
||||
if (OnBeforeListRemove())
|
||||
{
|
||||
RemoveFromList(entry);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleClear()
|
||||
{
|
||||
if (OnBeforeListClear())
|
||||
{
|
||||
ClearList();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleApplyChanges()
|
||||
{
|
||||
if (!OnBeforeApplyChanges())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var destList = GetExternalList();
|
||||
|
||||
ApplyChangesToList(destList);
|
||||
}
|
||||
|
||||
protected virtual void HandleClearChanges()
|
||||
{
|
||||
if (!OnBeforeClearChanges())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var restoList = GetExternalList();
|
||||
|
||||
ClearChanges(restoList);
|
||||
}
|
||||
|
||||
public abstract List<T> GetExternalList();
|
||||
public abstract T GetListAddObject();
|
||||
|
||||
public virtual bool Validate(T obj)
|
||||
{
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
public virtual void AddToList(T obj)
|
||||
{
|
||||
if (!Validate(obj))
|
||||
{
|
||||
Refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
List.Add(obj);
|
||||
|
||||
if (AddCallback != null)
|
||||
{
|
||||
AddCallback(obj);
|
||||
}
|
||||
|
||||
ChangesPending = true;
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual void RemoveFromList(T obj)
|
||||
{
|
||||
if (obj != null && List.Contains(obj))
|
||||
{
|
||||
List.Remove(obj);
|
||||
}
|
||||
|
||||
if (RemoveCallback != null)
|
||||
{
|
||||
RemoveCallback(obj);
|
||||
}
|
||||
|
||||
ChangesPending = true;
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual void ClearList()
|
||||
{
|
||||
if (List != null)
|
||||
{
|
||||
List.Clear();
|
||||
}
|
||||
|
||||
if (ClearCallback != null)
|
||||
{
|
||||
ClearCallback();
|
||||
}
|
||||
|
||||
ChangesPending = true;
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual void ClearChanges(List<T> resto)
|
||||
{
|
||||
if (resto != null && resto != List)
|
||||
{
|
||||
List.Clear();
|
||||
List.AddRange(resto);
|
||||
}
|
||||
|
||||
ChangesPending = false;
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual void ApplyChangesToList(List<T> list)
|
||||
{
|
||||
if (list != null && list != List)
|
||||
{
|
||||
list.Clear();
|
||||
list.AddRange(List);
|
||||
}
|
||||
|
||||
if (ApplyCallback != null)
|
||||
{
|
||||
ApplyCallback(list);
|
||||
}
|
||||
|
||||
ChangesPending = false;
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected virtual bool OnBeforeClearChanges()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual bool OnBeforeApplyChanges()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual bool OnBeforeListAdd()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual bool OnBeforeListRemove()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual bool OnBeforeListClear()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnClosed(bool all)
|
||||
{
|
||||
base.OnClosed(all);
|
||||
|
||||
if (!ChangesPending)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
new ConfirmDialogGump(User)
|
||||
{
|
||||
Title = "Apply Changes?",
|
||||
Html = "There are changes waiting that have not been applied.\nDo you want to apply them now?",
|
||||
AcceptHandler = b =>
|
||||
{
|
||||
HandleApplyChanges();
|
||||
Close(all);
|
||||
}
|
||||
}.Send();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
using VitaNex.Network;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public abstract class Rect2DListGump : GenericListGump<Rectangle2D>
|
||||
{
|
||||
public bool Preview { get; set; }
|
||||
public int PreviewHue { get; set; }
|
||||
public int PreviewEffect { get; set; }
|
||||
public EffectRender PreviewRender { get; set; }
|
||||
public string PreviewName { get; set; }
|
||||
|
||||
public Rectangle2D? InputRect { get; set; }
|
||||
public Map InputMap { get; set; }
|
||||
|
||||
private RegionExtUtility.PreviewRegion _Preview;
|
||||
|
||||
public Rect2DListGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<Rectangle2D> list = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null,
|
||||
bool canAdd = true,
|
||||
bool canRemove = true,
|
||||
bool canClear = true,
|
||||
Action<Rectangle2D> addCallback = null,
|
||||
Action<Rectangle2D> removeCallback = null,
|
||||
Action<List<Rectangle2D>> applyCallback = null,
|
||||
Action clearCallback = null)
|
||||
: base(
|
||||
user,
|
||||
parent,
|
||||
x,
|
||||
y,
|
||||
list,
|
||||
emptyText,
|
||||
title,
|
||||
opts,
|
||||
canAdd,
|
||||
canRemove,
|
||||
canClear,
|
||||
addCallback,
|
||||
removeCallback,
|
||||
applyCallback,
|
||||
clearCallback)
|
||||
{
|
||||
InputMap = User.Map;
|
||||
|
||||
Preview = false;
|
||||
PreviewHue = TextHue;
|
||||
PreviewEffect = 1801;
|
||||
PreviewRender = EffectRender.SemiTransparent;
|
||||
PreviewName = "Preview Region";
|
||||
|
||||
ForceRecompile = true;
|
||||
}
|
||||
|
||||
protected override int GetLabelHue(int index, int pageIndex, Rectangle2D entry)
|
||||
{
|
||||
return PreviewHue;
|
||||
}
|
||||
|
||||
protected override string GetLabelText(int index, int pageIndex, Rectangle2D entry)
|
||||
{
|
||||
return entry.Start + " -> " + entry.End;
|
||||
}
|
||||
|
||||
public override string GetSearchKeyFor(Rectangle2D key)
|
||||
{
|
||||
return key.Start + " -> " + key.End;
|
||||
}
|
||||
|
||||
protected override bool OnBeforeListAdd()
|
||||
{
|
||||
if (InputRect != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Minimize();
|
||||
|
||||
BoundingBoxPicker.Begin(
|
||||
User,
|
||||
(from, map, start, end, state) =>
|
||||
{
|
||||
InputMap = map;
|
||||
InputRect = new Rectangle2D(start, end.Clone2D(1, 1));
|
||||
HandleAdd();
|
||||
InputRect = null;
|
||||
|
||||
Maximize();
|
||||
},
|
||||
null);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override Rectangle2D GetListAddObject()
|
||||
{
|
||||
return InputRect ?? default(Rectangle2D);
|
||||
}
|
||||
|
||||
protected override void OnSend()
|
||||
{
|
||||
base.OnSend();
|
||||
|
||||
DisplayPreview();
|
||||
}
|
||||
|
||||
protected override void OnRefreshed()
|
||||
{
|
||||
base.OnRefreshed();
|
||||
|
||||
DisplayPreview();
|
||||
}
|
||||
|
||||
protected override void OnClosed(bool all)
|
||||
{
|
||||
base.OnClosed(all);
|
||||
|
||||
ClearPreview();
|
||||
}
|
||||
|
||||
protected override void OnDispose()
|
||||
{
|
||||
base.OnDispose();
|
||||
|
||||
ClearPreview();
|
||||
}
|
||||
|
||||
protected override void CompileEntryOptions(MenuGumpOptions opts, Rectangle2D entry)
|
||||
{
|
||||
opts.AppendEntry("Go To", () => User.MoveToWorld(entry.Start.GetWorldTop(InputMap), InputMap), HighlightHue);
|
||||
|
||||
base.CompileEntryOptions(opts, entry);
|
||||
}
|
||||
|
||||
public virtual void ClearPreview()
|
||||
{
|
||||
if (_Preview == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Preview.Unregister();
|
||||
_Preview = null;
|
||||
}
|
||||
|
||||
public virtual void DisplayPreview()
|
||||
{
|
||||
if (!Preview || InputMap == null || InputMap == Map.Internal || List.Count == 0)
|
||||
{
|
||||
if (_Preview != null)
|
||||
{
|
||||
_Preview.Unregister();
|
||||
_Preview = null;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_Preview != null)
|
||||
{
|
||||
if (_Preview.Map == InputMap && _Preview.Area.GetBoundsHashCode() == List.GetBoundsHashCode())
|
||||
{
|
||||
_Preview.Refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
_Preview.Unregister();
|
||||
}
|
||||
|
||||
_Preview = RegionExtUtility.DisplayPreview(
|
||||
PreviewName,
|
||||
InputMap,
|
||||
PreviewHue,
|
||||
PreviewEffect,
|
||||
PreviewRender,
|
||||
List.ToArray());
|
||||
}
|
||||
|
||||
protected override void CompileMenuOptions(MenuGumpOptions list)
|
||||
{
|
||||
if (!Preview)
|
||||
{
|
||||
list.Replace(
|
||||
"Disable Preview",
|
||||
"Enable Preview",
|
||||
() =>
|
||||
{
|
||||
Preview = true;
|
||||
DisplayPreview();
|
||||
Refresh();
|
||||
},
|
||||
HighlightHue);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Replace(
|
||||
"Enable Preview",
|
||||
"Disable Preview",
|
||||
() =>
|
||||
{
|
||||
Preview = false;
|
||||
ClearPreview();
|
||||
Refresh();
|
||||
},
|
||||
ErrorHue);
|
||||
}
|
||||
|
||||
base.CompileMenuOptions(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
using VitaNex.Network;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public abstract class Rect3DListGump : GenericListGump<Rectangle3D>
|
||||
{
|
||||
public bool Preview { get; set; }
|
||||
public int PreviewHue { get; set; }
|
||||
public int PreviewEffect { get; set; }
|
||||
public EffectRender PreviewRender { get; set; }
|
||||
public string PreviewName { get; set; }
|
||||
|
||||
public Rectangle3D? InputRect { get; set; }
|
||||
public Map InputMap { get; set; }
|
||||
|
||||
private RegionExtUtility.PreviewRegion _Preview;
|
||||
|
||||
public Rect3DListGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<Rectangle3D> list = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null,
|
||||
bool canAdd = true,
|
||||
bool canRemove = true,
|
||||
bool canClear = true,
|
||||
Action<Rectangle3D> addCallback = null,
|
||||
Action<Rectangle3D> removeCallback = null,
|
||||
Action<List<Rectangle3D>> applyCallback = null,
|
||||
Action clearCallback = null)
|
||||
: base(
|
||||
user,
|
||||
parent,
|
||||
x,
|
||||
y,
|
||||
list,
|
||||
emptyText,
|
||||
title,
|
||||
opts,
|
||||
canAdd,
|
||||
canRemove,
|
||||
canClear,
|
||||
addCallback,
|
||||
removeCallback,
|
||||
applyCallback,
|
||||
clearCallback)
|
||||
{
|
||||
InputMap = User.Map;
|
||||
|
||||
Preview = false;
|
||||
PreviewHue = TextHue;
|
||||
PreviewEffect = 1801;
|
||||
PreviewRender = EffectRender.SemiTransparent;
|
||||
PreviewName = "Preview Region";
|
||||
|
||||
ForceRecompile = true;
|
||||
}
|
||||
|
||||
protected override int GetLabelHue(int index, int pageIndex, Rectangle3D entry)
|
||||
{
|
||||
return PreviewHue;
|
||||
}
|
||||
|
||||
protected override string GetLabelText(int index, int pageIndex, Rectangle3D entry)
|
||||
{
|
||||
return entry.Start + " -> " + entry.End;
|
||||
}
|
||||
|
||||
public override string GetSearchKeyFor(Rectangle3D key)
|
||||
{
|
||||
return key.Start + " -> " + key.End;
|
||||
}
|
||||
|
||||
protected override bool OnBeforeListAdd()
|
||||
{
|
||||
if (InputRect != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Minimize();
|
||||
|
||||
BoundingBoxPicker.Begin(
|
||||
User,
|
||||
(from, map, start, end, state) =>
|
||||
{
|
||||
InputMap = map;
|
||||
InputRect = new Rectangle3D(start, end.Clone3D(1, 1));
|
||||
HandleAdd();
|
||||
InputRect = null;
|
||||
|
||||
Maximize();
|
||||
},
|
||||
null);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override Rectangle3D GetListAddObject()
|
||||
{
|
||||
return InputRect ?? default(Rectangle3D);
|
||||
}
|
||||
|
||||
protected override void OnSend()
|
||||
{
|
||||
base.OnSend();
|
||||
|
||||
DisplayPreview();
|
||||
}
|
||||
|
||||
protected override void OnRefreshed()
|
||||
{
|
||||
base.OnRefreshed();
|
||||
|
||||
DisplayPreview();
|
||||
}
|
||||
|
||||
protected override void OnClosed(bool all)
|
||||
{
|
||||
base.OnClosed(all);
|
||||
|
||||
ClearPreview();
|
||||
}
|
||||
|
||||
protected override void OnDispose()
|
||||
{
|
||||
base.OnDispose();
|
||||
|
||||
ClearPreview();
|
||||
}
|
||||
|
||||
protected override void CompileEntryOptions(MenuGumpOptions opts, Rectangle3D entry)
|
||||
{
|
||||
base.CompileEntryOptions(opts, entry);
|
||||
|
||||
opts.AppendEntry("Go To", () => User.MoveToWorld(entry.Start, InputMap), HighlightHue);
|
||||
}
|
||||
|
||||
public virtual void ClearPreview()
|
||||
{
|
||||
if (_Preview == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Preview.Unregister();
|
||||
_Preview = null;
|
||||
}
|
||||
|
||||
public virtual void DisplayPreview()
|
||||
{
|
||||
if (!Preview || InputMap == null || InputMap == Map.Internal || List.Count == 0)
|
||||
{
|
||||
if (_Preview != null)
|
||||
{
|
||||
_Preview.Unregister();
|
||||
_Preview = null;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_Preview != null)
|
||||
{
|
||||
if (_Preview.Map == InputMap && _Preview.Area.GetBoundsHashCode() == List.GetBoundsHashCode())
|
||||
{
|
||||
_Preview.Refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
_Preview.Unregister();
|
||||
}
|
||||
|
||||
_Preview = RegionExtUtility.DisplayPreview(
|
||||
PreviewName,
|
||||
InputMap,
|
||||
PreviewHue,
|
||||
PreviewEffect,
|
||||
PreviewRender,
|
||||
List.ToArray());
|
||||
}
|
||||
|
||||
protected override void CompileMenuOptions(MenuGumpOptions list)
|
||||
{
|
||||
if (!Preview)
|
||||
{
|
||||
list.Replace(
|
||||
"Disable Preview",
|
||||
"Enable Preview",
|
||||
() =>
|
||||
{
|
||||
Preview = true;
|
||||
DisplayPreview();
|
||||
Refresh();
|
||||
},
|
||||
HighlightHue);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Replace(
|
||||
"Enable Preview",
|
||||
"Disable Preview",
|
||||
() =>
|
||||
{
|
||||
Preview = false;
|
||||
ClearPreview();
|
||||
Refresh();
|
||||
},
|
||||
ErrorHue);
|
||||
}
|
||||
|
||||
base.CompileMenuOptions(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public abstract class TypeListGump : TypeListGump<object>
|
||||
{
|
||||
public TypeListGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<Type> list = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null,
|
||||
bool canAdd = true,
|
||||
bool canRemove = true,
|
||||
bool canClear = true,
|
||||
Action<Type> addCallback = null,
|
||||
Action<Type> removeCallback = null,
|
||||
Action<List<Type>> applyCallback = null,
|
||||
Action clearCallback = null)
|
||||
: base(
|
||||
user,
|
||||
parent,
|
||||
x,
|
||||
y,
|
||||
list,
|
||||
emptyText,
|
||||
title,
|
||||
opts,
|
||||
canAdd,
|
||||
canRemove,
|
||||
canClear,
|
||||
addCallback,
|
||||
removeCallback,
|
||||
applyCallback,
|
||||
clearCallback)
|
||||
{ }
|
||||
}
|
||||
|
||||
public abstract class TypeListGump<TBase> : GenericListGump<Type>
|
||||
{
|
||||
public Type InputType { get; set; }
|
||||
|
||||
public TypeListGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<Type> list = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null,
|
||||
bool canAdd = true,
|
||||
bool canRemove = true,
|
||||
bool canClear = true,
|
||||
Action<Type> addCallback = null,
|
||||
Action<Type> removeCallback = null,
|
||||
Action<List<Type>> applyCallback = null,
|
||||
Action clearCallback = null)
|
||||
: base(
|
||||
user,
|
||||
parent,
|
||||
x,
|
||||
y,
|
||||
list,
|
||||
emptyText,
|
||||
title,
|
||||
opts,
|
||||
canAdd,
|
||||
canRemove,
|
||||
canClear,
|
||||
addCallback,
|
||||
removeCallback,
|
||||
applyCallback,
|
||||
clearCallback)
|
||||
{ }
|
||||
|
||||
public override string GetSearchKeyFor(Type key)
|
||||
{
|
||||
return key != null ? key.Name : base.GetSearchKeyFor(null);
|
||||
}
|
||||
|
||||
public override bool Validate(Type obj)
|
||||
{
|
||||
return base.Validate(obj) && obj.IsEqualOrChildOf<TBase>();
|
||||
}
|
||||
|
||||
protected override bool OnBeforeListAdd()
|
||||
{
|
||||
if (InputType != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
new InputDialogGump(User, Refresh())
|
||||
{
|
||||
Title = "Add Type by Name",
|
||||
Html = "Write the name of a Type to add it to this list.\nExample: System.String",
|
||||
Callback = (b1, text) =>
|
||||
{
|
||||
InputType = VitaNexCore.TryCatchGet(
|
||||
() => Type.GetType(text, false, true) ?? //
|
||||
ScriptCompiler.FindTypeByFullName(text, true) ?? //
|
||||
ScriptCompiler.FindTypeByName(text, true));
|
||||
|
||||
HandleAdd();
|
||||
|
||||
InputType = null;
|
||||
}
|
||||
}.Send();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override Type GetListAddObject()
|
||||
{
|
||||
return InputType;
|
||||
}
|
||||
}
|
||||
}
|
||||
446
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Lists/List.cs
Normal file
446
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Lists/List.cs
Normal file
@@ -0,0 +1,446 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class ListGump<T> : SuperGumpList<T>
|
||||
{
|
||||
public const string DefaultTitle = "List View";
|
||||
public const string DefaultEmptyText = "No entries to display.";
|
||||
|
||||
protected bool WasModal { get; set; }
|
||||
|
||||
public virtual string Title { get; set; }
|
||||
|
||||
public virtual string EmptyText { get; set; }
|
||||
|
||||
public virtual bool Minimized { get; set; }
|
||||
|
||||
public virtual T Selected { get; set; }
|
||||
|
||||
public virtual bool CanSearch { get; set; }
|
||||
public virtual string SearchText { get; set; }
|
||||
public virtual List<T> SearchResults { get; set; }
|
||||
|
||||
public virtual MenuGumpOptions Options { get; set; }
|
||||
|
||||
public MenuGump Menu { get; private set; }
|
||||
|
||||
public override int EntryCount => IsSearching() ? SearchResults.Count : base.EntryCount;
|
||||
|
||||
public int EntryHeight { get; set; }
|
||||
|
||||
public int Columns { get; set; }
|
||||
public int Width { get; set; }
|
||||
|
||||
public ListGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<T> list = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null)
|
||||
: base(user, parent, x, y, list)
|
||||
{
|
||||
EmptyText = emptyText ?? DefaultEmptyText;
|
||||
Title = title ?? DefaultTitle;
|
||||
|
||||
Minimized = false;
|
||||
|
||||
CanMove = false;
|
||||
CanSearch = true;
|
||||
|
||||
EntryHeight = 30;
|
||||
|
||||
Width = 400;
|
||||
Columns = 1;
|
||||
|
||||
Options = new MenuGumpOptions(opts);
|
||||
}
|
||||
|
||||
public override void AssignCollections()
|
||||
{
|
||||
if (SearchResults == null)
|
||||
{
|
||||
SearchResults = new List<T>(0x20);
|
||||
}
|
||||
|
||||
base.AssignCollections();
|
||||
}
|
||||
|
||||
public virtual bool IsSearching()
|
||||
{
|
||||
return CanSearch && !String.IsNullOrWhiteSpace(SearchText);
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
base.Compile();
|
||||
|
||||
if (Options == null)
|
||||
{
|
||||
Options = new MenuGumpOptions();
|
||||
}
|
||||
else
|
||||
{
|
||||
Options.Clear();
|
||||
}
|
||||
|
||||
CompileMenuOptions(Options);
|
||||
}
|
||||
|
||||
protected override void CompileList(List<T> list)
|
||||
{
|
||||
SearchResults.Clear();
|
||||
|
||||
if (IsSearching())
|
||||
{
|
||||
SearchResults.AddRange(
|
||||
list.Where(
|
||||
o => o != null && Regex.IsMatch(GetSearchKeyFor(o), Regex.Escape(SearchText), RegexOptions.IgnoreCase)));
|
||||
|
||||
if (Sorted)
|
||||
{
|
||||
SearchResults.Sort(SortCompare);
|
||||
}
|
||||
}
|
||||
|
||||
base.CompileList(list);
|
||||
}
|
||||
|
||||
public virtual string GetSearchKeyFor(T key)
|
||||
{
|
||||
return key != null ? key.ToString() : "NULL";
|
||||
}
|
||||
|
||||
protected virtual void OnClearSearch(GumpButton button)
|
||||
{
|
||||
SearchText = null;
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected virtual void OnNewSearch(GumpButton button)
|
||||
{
|
||||
new InputDialogGump(User, this)
|
||||
{
|
||||
Title = "Search",
|
||||
Html = "Search " + Title + ".\nRegular Expressions are supported.",
|
||||
Limit = 100,
|
||||
Callback = (subBtn, input) =>
|
||||
{
|
||||
SearchText = input;
|
||||
Page = 0;
|
||||
Refresh(true);
|
||||
}
|
||||
}.Send();
|
||||
}
|
||||
|
||||
protected virtual void CompileMenuOptions(MenuGumpOptions list)
|
||||
{
|
||||
if (Minimized)
|
||||
{
|
||||
list.Replace("Minimize", "Maximize", Maximize);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Replace("Maximize", "Minimize", Minimize);
|
||||
}
|
||||
|
||||
if (CanSearch)
|
||||
{
|
||||
if (IsSearching())
|
||||
{
|
||||
list.Replace("New Search", "Clear Search", OnClearSearch);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Replace("Clear Search", "New Search", OnNewSearch);
|
||||
}
|
||||
}
|
||||
|
||||
list.AppendEntry("Refresh", b => Refresh(b));
|
||||
|
||||
if (CanClose)
|
||||
{
|
||||
list.AppendEntry("Exit", b => Close(b));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 9270;
|
||||
var fillID = ec ? 87 : sup ? 40004 : 2624;
|
||||
|
||||
layout.Add(
|
||||
"background/header/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 0, Width + 20, 50, bgID);
|
||||
AddImageTiled(10, 10, Width, 30, fillID);
|
||||
//AddAlphaRegion(10, 10, Width, 30);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"button/header/options",
|
||||
() =>
|
||||
{
|
||||
AddButton(15, 15, 2008, 2007, ShowOptionMenu);
|
||||
AddTooltip(1015326);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"button/header/minimize",
|
||||
() =>
|
||||
{
|
||||
if (Minimized)
|
||||
{
|
||||
AddButton(Width - 10, 20, 10740, 10742, Maximize);
|
||||
AddTooltip(3002086);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddButton(Width - 10, 20, 10741, 10742, Minimize);
|
||||
AddTooltip(3002085);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"label/header/title",
|
||||
() =>
|
||||
{
|
||||
var title = String.IsNullOrWhiteSpace(Title) ? DefaultTitle : Title;
|
||||
|
||||
AddLabelCropped(90, 15, Width - 90, 20, GetTitleHue(), title);
|
||||
});
|
||||
|
||||
if (Minimized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
layout.Add("imagetiled/body/spacer", () => AddImageTiled(0, 50, Width + 20, 10, fillID));
|
||||
|
||||
var range = GetListRange();
|
||||
|
||||
if (range.Count > 0)
|
||||
{
|
||||
var height = (int)Math.Ceiling(range.Count / Math.Max(1.0, Columns)) * EntryHeight;
|
||||
|
||||
layout.Add(
|
||||
"background/body/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 55, Width + 20, height + 20, bgID);
|
||||
AddImageTiled(10, 65, Width, height, fillID);
|
||||
//AddAlphaRegion(10, 65, Width, height);
|
||||
});
|
||||
|
||||
CompileEntryLayout(layout, range);
|
||||
|
||||
range.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
layout.Add(
|
||||
"background/body/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 55, Width + 20, 50, bgID);
|
||||
AddImageTiled(10, 65, Width, 30, fillID);
|
||||
//AddAlphaRegion(10, 65, Width, 30);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"label/list/empty",
|
||||
() =>
|
||||
{
|
||||
var label = String.IsNullOrEmpty(EmptyText) ? DefaultEmptyText : EmptyText;
|
||||
|
||||
label = label.WrapUOHtmlCenter();
|
||||
|
||||
AddHtml(15, 72, Width - 10, 20, label, Color.IndianRed, Color.Empty);
|
||||
});
|
||||
}
|
||||
|
||||
layout.Add(
|
||||
"widget/body/scrollbar",
|
||||
() => AddScrollbarHM(10, 46, Width, PageCount, Page, PreviousPage, NextPage));
|
||||
}
|
||||
|
||||
protected virtual void CompileEntryLayout(SuperGumpLayout layout, Dictionary<int, T> range)
|
||||
{
|
||||
var i = 0;
|
||||
var h = EntryHeight;
|
||||
|
||||
foreach (var kv in range)
|
||||
{
|
||||
CompileEntryLayout(layout, range.Count, kv.Key, i, 70 + ((i++ / Columns) * h), kv.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CompileEntryLayout(
|
||||
SuperGumpLayout layout,
|
||||
int length,
|
||||
int index,
|
||||
int pIndex,
|
||||
int yOffset,
|
||||
T entry)
|
||||
{
|
||||
var wOffset = (Width - 10) / Columns;
|
||||
var xOffset = (pIndex % Columns) * wOffset;
|
||||
|
||||
layout.Add(
|
||||
"button/list/select/" + index,
|
||||
() => AddButton(xOffset + 15, yOffset, 4006, 4007, b => SelectEntry(b, entry)));
|
||||
|
||||
layout.Add(
|
||||
"label/list/entry/" + index,
|
||||
() =>
|
||||
{
|
||||
var offset = 15 + GetImageSize(4006).Width + 5;
|
||||
|
||||
var hue = GetLabelHue(index, pIndex, entry);
|
||||
var text = GetLabelText(index, pIndex, entry);
|
||||
|
||||
AddLabelCropped(xOffset + offset, yOffset + 2, wOffset - offset, EntryHeight - 2, hue, text);
|
||||
});
|
||||
}
|
||||
|
||||
public override IEnumerable<T> EnumerateListRange(int index, int length)
|
||||
{
|
||||
if (!IsSearching())
|
||||
{
|
||||
foreach (var o in base.EnumerateListRange(index, length))
|
||||
{
|
||||
yield return o;
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
index = Math.Max(0, Math.Min(EntryCount, index));
|
||||
length = Math.Max(0, Math.Min(EntryCount - index, length));
|
||||
|
||||
while (--length >= 0 && SearchResults.InBounds(index))
|
||||
{
|
||||
yield return SearchResults[index++];
|
||||
}
|
||||
}
|
||||
|
||||
public override Dictionary<int, T> GetListRange(int index, int length)
|
||||
{
|
||||
if (!IsSearching())
|
||||
{
|
||||
return base.GetListRange(index, length);
|
||||
}
|
||||
|
||||
index = Math.Max(0, Math.Min(EntryCount, index));
|
||||
length = Math.Max(0, Math.Min(EntryCount - index, length));
|
||||
|
||||
var d = new Dictionary<int, T>(length);
|
||||
|
||||
while (--length >= 0 && SearchResults.InBounds(index))
|
||||
{
|
||||
d[index] = SearchResults[index++];
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
protected virtual void Minimize(GumpButton entry = null)
|
||||
{
|
||||
Minimized = true;
|
||||
|
||||
if (Modal)
|
||||
{
|
||||
WasModal = true;
|
||||
}
|
||||
|
||||
Modal = false;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected virtual void Maximize(GumpButton entry = null)
|
||||
{
|
||||
Minimized = false;
|
||||
|
||||
if (WasModal)
|
||||
{
|
||||
Modal = true;
|
||||
}
|
||||
|
||||
WasModal = false;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected virtual int GetTitleHue()
|
||||
{
|
||||
return HighlightHue;
|
||||
}
|
||||
|
||||
protected virtual string GetLabelText(int index, int pageIndex, T entry)
|
||||
{
|
||||
return entry != null ? entry.ToString() : "NULL";
|
||||
}
|
||||
|
||||
protected virtual int GetLabelHue(int index, int pageIndex, T entry)
|
||||
{
|
||||
return entry != null ? TextHue : ErrorHue;
|
||||
}
|
||||
|
||||
protected virtual void SelectEntry(GumpButton button, T entry)
|
||||
{
|
||||
Selected = entry;
|
||||
}
|
||||
|
||||
protected virtual void ShowOptionMenu(GumpButton button)
|
||||
{
|
||||
if (User != null && !User.Deleted && Options != null && Options.Count > 0)
|
||||
{
|
||||
Send(new MenuGump(User, Refresh(), Options, button));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ListGump<T, U> : ListGump<KeyValuePair<T, U>>
|
||||
{
|
||||
public ListGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<KeyValuePair<T, U>> list = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null)
|
||||
: base(user, parent, x, y, list, emptyText, title, opts)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
119
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Lists/ListEntry.cs
Normal file
119
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Lists/ListEntry.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public struct ListGumpEntry : IEquatable<ListGumpEntry>, IEquatable<string>
|
||||
{
|
||||
public static ListGumpEntry Empty = new ListGumpEntry(String.Empty, () => { });
|
||||
|
||||
private static Action<GumpButton> Resolve(Action handler)
|
||||
{
|
||||
return b =>
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
handler();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty(ListGumpEntry entry)
|
||||
{
|
||||
return entry == null || entry == Empty;
|
||||
}
|
||||
|
||||
public string Label { get; set; }
|
||||
public int Hue { get; set; }
|
||||
public Action<GumpButton> Handler { get; set; }
|
||||
|
||||
public ListGumpEntry(string label, Action handler)
|
||||
: this(label, Resolve(handler), SuperGump.DefaultTextHue)
|
||||
{ }
|
||||
|
||||
public ListGumpEntry(string label, Action handler, int hue)
|
||||
: this(label, Resolve(handler), hue)
|
||||
{ }
|
||||
|
||||
public ListGumpEntry(string label, Action<GumpButton> handler)
|
||||
: this(label, handler, SuperGump.DefaultTextHue)
|
||||
{ }
|
||||
|
||||
public ListGumpEntry(string label, Action<GumpButton> handler, int hue)
|
||||
: this()
|
||||
{
|
||||
Label = label;
|
||||
Handler = handler;
|
||||
Hue = hue;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Label;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Label != null ? Label.GetHashCode() : 0;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is string && Equals((string)obj)) || (obj is ListGumpEntry && Equals((ListGumpEntry)obj));
|
||||
}
|
||||
|
||||
public bool Equals(ListGumpEntry other)
|
||||
{
|
||||
return Label == other.Label;
|
||||
}
|
||||
|
||||
public bool Equals(string other)
|
||||
{
|
||||
return Label == other;
|
||||
}
|
||||
|
||||
public static bool operator ==(ListGumpEntry l, ListGumpEntry r)
|
||||
{
|
||||
return l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(ListGumpEntry l, ListGumpEntry r)
|
||||
{
|
||||
return !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator ==(ListGumpEntry l, string r)
|
||||
{
|
||||
return l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(ListGumpEntry l, string r)
|
||||
{
|
||||
return !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator ==(string l, ListGumpEntry r)
|
||||
{
|
||||
return r.Equals(l);
|
||||
}
|
||||
|
||||
public static bool operator !=(string l, ListGumpEntry r)
|
||||
{
|
||||
return !r.Equals(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class EnumMenuGump<TEnum> : MenuGump
|
||||
where TEnum : struct, IComparable, IFormattable, IConvertible
|
||||
{
|
||||
public Action<TEnum> Callback { get; set; }
|
||||
|
||||
public TEnum DefaultValue { get; set; }
|
||||
|
||||
public EnumMenuGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
GumpButton clicked = null,
|
||||
TEnum def = default(TEnum),
|
||||
Action<TEnum> callback = null)
|
||||
: base(user, parent, null, clicked)
|
||||
{
|
||||
DefaultValue = def;
|
||||
Callback = callback;
|
||||
}
|
||||
|
||||
protected virtual void OnSelected(TEnum val)
|
||||
{
|
||||
if (Callback != null)
|
||||
{
|
||||
Callback(val);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CompileOptions(MenuGumpOptions list)
|
||||
{
|
||||
if (typeof(TEnum).IsEnum)
|
||||
{
|
||||
foreach (var val in EnumerateValues())
|
||||
{
|
||||
var e = new ListGumpEntry(GetOptionLabel(val), b => OnSelected(val));
|
||||
|
||||
if (Equals(val, DefaultValue))
|
||||
{
|
||||
e.Hue = HighlightHue;
|
||||
}
|
||||
|
||||
list.AppendEntry(e);
|
||||
}
|
||||
}
|
||||
|
||||
base.CompileOptions(list);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<TEnum> EnumerateValues()
|
||||
{
|
||||
return (default(TEnum) as Enum).EnumerateValues<TEnum>(false);
|
||||
}
|
||||
|
||||
public virtual string GetOptionLabel(TEnum val)
|
||||
{
|
||||
return val.ToString().SpaceWords();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
using VitaNex.Text;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class MenuGump : SuperGumpList<ListGumpEntry>
|
||||
{
|
||||
public int GuessWidth { get; protected set; }
|
||||
|
||||
public int EntryHeight { get; set; }
|
||||
|
||||
public GumpButton Clicked { get; set; }
|
||||
|
||||
public ListGumpEntry Selected { get; set; }
|
||||
|
||||
public MenuGump(Mobile user, Gump parent = null, IEnumerable<ListGumpEntry> list = null, GumpButton clicked = null)
|
||||
: base(user, parent, DefaultX, DefaultY, list)
|
||||
{
|
||||
EntryHeight = 30;
|
||||
|
||||
Clicked = clicked;
|
||||
|
||||
if (Clicked != null)
|
||||
{
|
||||
if (Clicked.Parent != null)
|
||||
{
|
||||
X = Clicked.Parent.X + Clicked.X;
|
||||
Y = Clicked.Parent.Y + Clicked.Y;
|
||||
|
||||
if (Parent == null)
|
||||
{
|
||||
Parent = Clicked.Parent;
|
||||
}
|
||||
}
|
||||
else if (Parent != null)
|
||||
{
|
||||
X = Parent.X;
|
||||
Y = Parent.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
X = DefaultX;
|
||||
Y = DefaultY;
|
||||
}
|
||||
}
|
||||
else if (Parent != null)
|
||||
{
|
||||
X = Parent.X;
|
||||
Y = Parent.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
X = DefaultX;
|
||||
Y = DefaultY;
|
||||
}
|
||||
|
||||
ForceRecompile = true;
|
||||
CanMove = false;
|
||||
CanResize = false;
|
||||
Modal = true;
|
||||
}
|
||||
|
||||
protected virtual void InvalidateWidth()
|
||||
{
|
||||
double epp = EntriesPerPage;
|
||||
|
||||
GuessWidth = 100;
|
||||
|
||||
if (epp > 0)
|
||||
{
|
||||
var font = UOFont.Unicode[1];
|
||||
|
||||
GuessWidth += List.Select((e, i) => font.GetWidth(GetLabelText(i, (int)Math.Ceiling(i + 1 / epp), e))).Highest();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddOption(string label, Action handler)
|
||||
{
|
||||
List.Add(new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void AddOption(string label, Action handler, int hue)
|
||||
{
|
||||
List.Add(new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public void AddOption(string label, Action<GumpButton> handler)
|
||||
{
|
||||
List.Add(new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void AddOption(string label, Action<GumpButton> handler, int hue)
|
||||
{
|
||||
List.Add(new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var range = GetListRange();
|
||||
|
||||
var eh = range.Count * EntryHeight;
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 9270;
|
||||
|
||||
layout.Add(
|
||||
"background/body/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 0, GuessWidth, 30 + eh, bgID);
|
||||
|
||||
if (!sup)
|
||||
{
|
||||
AddImageTiled(10, 10, GuessWidth - 20, 10 + eh, 2624);
|
||||
//AddAlphaRegion(10, 10, GuessWidth - 20, 10 + eh);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"imagetiled/body/vsep/0",
|
||||
() =>
|
||||
{
|
||||
if (!sup || ec)
|
||||
{
|
||||
AddImageTiled(50, 20, 5, eh, bgID + 5);
|
||||
}
|
||||
});
|
||||
|
||||
CompileEntryLayout(layout, range);
|
||||
|
||||
layout.Add(
|
||||
"widget/body/scrollbar",
|
||||
() => AddScrollbarHM(10, 10, GuessWidth - 20, PageCount, Page, PreviousPage, NextPage));
|
||||
}
|
||||
|
||||
public virtual void CompileEntryLayout(SuperGumpLayout layout, Dictionary<int, ListGumpEntry> range)
|
||||
{
|
||||
range.For((i, kv) => CompileEntryLayout(layout, range.Count, kv.Key, i, 25 + (i * EntryHeight), kv.Value));
|
||||
}
|
||||
|
||||
public virtual void CompileEntryLayout(
|
||||
SuperGumpLayout layout,
|
||||
int length,
|
||||
int index,
|
||||
int pIndex,
|
||||
int yOffset,
|
||||
ListGumpEntry entry)
|
||||
{
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 9270;
|
||||
|
||||
layout.Add("button/list/select/" + index, () => AddButton(15, yOffset, 4006, 4007, b => SelectEntry(b, entry)));
|
||||
|
||||
layout.Add(
|
||||
"label/list/entry/" + index,
|
||||
() => AddLabelCropped(
|
||||
65,
|
||||
2 + yOffset,
|
||||
GuessWidth - 75,
|
||||
20,
|
||||
GetLabelHue(index, pIndex, entry),
|
||||
GetLabelText(index, pIndex, entry)));
|
||||
|
||||
if (pIndex < (length - 1))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/body/hsep/" + index,
|
||||
() =>
|
||||
{
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(10, 25 + yOffset, GuessWidth - 20, 5, bgID + 7);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected override sealed void CompileList(List<ListGumpEntry> list)
|
||||
{
|
||||
var opts = new MenuGumpOptions(list);
|
||||
|
||||
CompileOptions(opts);
|
||||
|
||||
list.Clear();
|
||||
list.AddRange(opts);
|
||||
|
||||
InvalidateWidth();
|
||||
}
|
||||
|
||||
protected virtual void CompileOptions(MenuGumpOptions list)
|
||||
{
|
||||
list.Insert(list.Count, new ListGumpEntry("Cancel", Cancel, ErrorHue));
|
||||
}
|
||||
|
||||
protected virtual string GetLabelText(int index, int pageIndex, ListGumpEntry entry)
|
||||
{
|
||||
return entry != null ? entry.Label : "NULL";
|
||||
}
|
||||
|
||||
protected virtual int GetLabelHue(int index, int pageIndex, ListGumpEntry entry)
|
||||
{
|
||||
return entry != null ? entry.Hue : ErrorHue;
|
||||
}
|
||||
|
||||
protected virtual void SelectEntry(GumpButton button, ListGumpEntry entry)
|
||||
{
|
||||
Selected = entry;
|
||||
|
||||
if (entry == null || entry.Handler == null)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
entry.Handler(button);
|
||||
}
|
||||
|
||||
protected virtual void Cancel(GumpButton button)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class MenuGumpOptions : IEnumerable<ListGumpEntry>, IEquatable<MenuGumpOptions>
|
||||
{
|
||||
private readonly List<ListGumpEntry> _Options;
|
||||
|
||||
public int Count => _Options.Count;
|
||||
|
||||
public ListGumpEntry this[int index] { get => GetEntryAt(index); set => Replace(value); }
|
||||
public ListGumpEntry this[string label] { get => GetEntry(label); set => Replace(label, value); }
|
||||
|
||||
public MenuGumpOptions()
|
||||
{
|
||||
_Options = new List<ListGumpEntry>(0x10);
|
||||
}
|
||||
|
||||
public MenuGumpOptions(IEnumerable<ListGumpEntry> options)
|
||||
: this()
|
||||
{
|
||||
AppendRange(options);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<ListGumpEntry> GetEnumerator()
|
||||
{
|
||||
return _Options.GetEnumerator();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_Options.Clear();
|
||||
}
|
||||
|
||||
public void AppendRange(IEnumerable<ListGumpEntry> options)
|
||||
{
|
||||
if (options != null)
|
||||
{
|
||||
options.ForEach(AppendEntry);
|
||||
}
|
||||
}
|
||||
|
||||
public void AppendEntry(string label, Action handler)
|
||||
{
|
||||
AppendEntry(new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void AppendEntry(string label, Action handler, int hue)
|
||||
{
|
||||
AppendEntry(new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public void AppendEntry(string label, Action<GumpButton> handler)
|
||||
{
|
||||
AppendEntry(new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void AppendEntry(string label, Action<GumpButton> handler, int hue)
|
||||
{
|
||||
AppendEntry(new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public void AppendEntry(ListGumpEntry entry)
|
||||
{
|
||||
Insert(Count, entry);
|
||||
}
|
||||
|
||||
public void PrependRange(IEnumerable<ListGumpEntry> options)
|
||||
{
|
||||
if (options != null)
|
||||
{
|
||||
options.ForEach(PrependEntry);
|
||||
}
|
||||
}
|
||||
|
||||
public void PrependEntry(string label, Action handler)
|
||||
{
|
||||
PrependEntry(new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void PrependEntry(string label, Action handler, int hue)
|
||||
{
|
||||
PrependEntry(new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public void PrependEntry(string label, Action<GumpButton> handler)
|
||||
{
|
||||
PrependEntry(new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void PrependEntry(string label, Action<GumpButton> handler, int hue)
|
||||
{
|
||||
PrependEntry(new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public void PrependEntry(ListGumpEntry entry)
|
||||
{
|
||||
Insert(0, entry);
|
||||
}
|
||||
|
||||
public bool RemoveEntry(ListGumpEntry entry)
|
||||
{
|
||||
return _Options.RemoveAll(o => o == entry) > 0;
|
||||
}
|
||||
|
||||
public bool RemoveEntry(string label)
|
||||
{
|
||||
return _Options.RemoveAll(o => o == label) > 0;
|
||||
}
|
||||
|
||||
public ListGumpEntry GetEntryAt(int index)
|
||||
{
|
||||
return _Options.ElementAtOrDefault(index);
|
||||
}
|
||||
|
||||
public ListGumpEntry GetEntry(string label)
|
||||
{
|
||||
return _Options.Find(o => o == label);
|
||||
}
|
||||
|
||||
public int IndexOfEntry(ListGumpEntry entry)
|
||||
{
|
||||
return _Options.IndexOf(o => o == entry);
|
||||
}
|
||||
|
||||
public int IndexOfLabel(string label)
|
||||
{
|
||||
return _Options.IndexOf(o => o == label);
|
||||
}
|
||||
|
||||
public void Insert(int index, ListGumpEntry entry)
|
||||
{
|
||||
if (ListGumpEntry.IsNullOrEmpty(entry))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
index = Math.Max(0, Math.Min(Count, index));
|
||||
|
||||
var i = IndexOfEntry(entry);
|
||||
|
||||
if (i != -1)
|
||||
{
|
||||
_Options.RemoveAt(i);
|
||||
|
||||
if (index > i)
|
||||
{
|
||||
--index;
|
||||
}
|
||||
}
|
||||
|
||||
_Options.Insert(index, entry);
|
||||
}
|
||||
|
||||
public void Replace(ListGumpEntry entry)
|
||||
{
|
||||
Replace(entry.Label, entry);
|
||||
}
|
||||
|
||||
public void Replace(string label, ListGumpEntry entry)
|
||||
{
|
||||
var i = IndexOfLabel(label);
|
||||
|
||||
if (i == -1 || (RemoveEntry(label) && i > Count))
|
||||
{
|
||||
i = Count;
|
||||
}
|
||||
|
||||
Insert(i, entry);
|
||||
}
|
||||
|
||||
public void Replace(string label, Action handler)
|
||||
{
|
||||
Replace(label, new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void Replace(string label, Action handler, int hue)
|
||||
{
|
||||
Replace(label, new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public void Replace(string search, string label, Action handler)
|
||||
{
|
||||
Replace(search, new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void Replace(string search, string label, Action handler, int hue)
|
||||
{
|
||||
Replace(search, new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public void Replace(string label, Action<GumpButton> handler)
|
||||
{
|
||||
Replace(label, new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void Replace(string label, Action<GumpButton> handler, int hue)
|
||||
{
|
||||
Replace(label, new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public void Replace(string search, string label, Action<GumpButton> handler)
|
||||
{
|
||||
Replace(search, new ListGumpEntry(label, handler));
|
||||
}
|
||||
|
||||
public void Replace(string search, string label, Action<GumpButton> handler, int hue)
|
||||
{
|
||||
Replace(search, new ListGumpEntry(label, handler, hue));
|
||||
}
|
||||
|
||||
public bool Contains(string label)
|
||||
{
|
||||
return IndexOfLabel(label) != -1;
|
||||
}
|
||||
|
||||
public bool Contains(ListGumpEntry entry)
|
||||
{
|
||||
return IndexOfEntry(entry) != -1;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _Options.Aggregate(Count, (hash, e) => unchecked((hash * 397) ^ e.GetHashCode()));
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is MenuGumpOptions && Equals((MenuGumpOptions)obj);
|
||||
}
|
||||
|
||||
public virtual bool Equals(MenuGumpOptions other)
|
||||
{
|
||||
return !ReferenceEquals(other, null) && GetHashCode() == other.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(MenuGumpOptions l, MenuGumpOptions r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(MenuGumpOptions l, MenuGumpOptions r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
using VitaNex.IO;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class FileExplorerGump : TreeGump
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandUtility.Register("explorer", AccessLevel.Owner, e => new FileExplorerGump(e.Mobile, null, null).Send());
|
||||
}
|
||||
|
||||
public DirectoryInfo RootDirectory { get; set; }
|
||||
|
||||
public DirectoryInfo SelectedDirectory { get; set; }
|
||||
public FileInfo SelectedFile { get; set; }
|
||||
|
||||
public FileExplorerGump(Mobile user, Gump parent, DirectoryInfo rootDirectory)
|
||||
: base(user, parent)
|
||||
{
|
||||
RootDirectory = SelectedDirectory = rootDirectory;
|
||||
|
||||
Width = 800;
|
||||
Height = 600;
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
if (RootDirectory == null)
|
||||
{
|
||||
RootDirectory = new DirectoryInfo(Core.BaseDirectory);
|
||||
}
|
||||
|
||||
while (!RootDirectory.Exists && RootDirectory.Parent != null)
|
||||
{
|
||||
RootDirectory = RootDirectory.Parent;
|
||||
}
|
||||
|
||||
if (!RootDirectory.Exists)
|
||||
{
|
||||
RootDirectory = new DirectoryInfo(Core.BaseDirectory);
|
||||
}
|
||||
|
||||
if (SelectedFile != null)
|
||||
{
|
||||
if (SelectedFile.Exists)
|
||||
{
|
||||
SelectedDirectory = SelectedFile.Directory;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedFile = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (SelectedDirectory == null)
|
||||
{
|
||||
SelectedDirectory = RootDirectory;
|
||||
}
|
||||
|
||||
while (!SelectedDirectory.Exists && SelectedDirectory.Parent != null)
|
||||
{
|
||||
SelectedDirectory = SelectedDirectory.Parent;
|
||||
}
|
||||
|
||||
if (!SelectedDirectory.Exists)
|
||||
{
|
||||
SelectedDirectory = RootDirectory;
|
||||
}
|
||||
|
||||
if (!Insensitive.StartsWith(SelectedDirectory.FullName, RootDirectory.FullName))
|
||||
{
|
||||
SelectedDirectory = RootDirectory;
|
||||
}
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
private string GetPath(FileSystemInfo info)
|
||||
{
|
||||
if (RootDirectory.Parent != null)
|
||||
{
|
||||
return info.FullName.Replace(RootDirectory.Parent.FullName, String.Empty)
|
||||
.Replace(IOUtility.PathSeparator, TreeGumpNode.Separator)
|
||||
.Trim(TreeGumpNode.Separator);
|
||||
}
|
||||
|
||||
return info.FullName.Replace(RootDirectory.FullName, String.Empty)
|
||||
.Replace(IOUtility.PathSeparator, TreeGumpNode.Separator)
|
||||
.Trim(TreeGumpNode.Separator);
|
||||
}
|
||||
|
||||
private string GetPath(TreeGumpNode node)
|
||||
{
|
||||
if (RootDirectory.Parent != null)
|
||||
{
|
||||
return Path.Combine(
|
||||
RootDirectory.Parent.FullName,
|
||||
node.FullName.Replace(TreeGumpNode.Separator, IOUtility.PathSeparator))
|
||||
.Trim(IOUtility.PathSeparator);
|
||||
}
|
||||
|
||||
return Path.Combine(RootDirectory.FullName, node.FullName.Replace(TreeGumpNode.Separator, IOUtility.PathSeparator))
|
||||
.Trim(IOUtility.PathSeparator);
|
||||
}
|
||||
|
||||
protected override void CompileNodes(Dictionary<TreeGumpNode, Action<Rectangle, int, TreeGumpNode>> list)
|
||||
{
|
||||
base.CompileNodes(list);
|
||||
|
||||
list.Clear();
|
||||
|
||||
MapTree(list, RootDirectory);
|
||||
}
|
||||
|
||||
private void MapTree(Dictionary<TreeGumpNode, Action<Rectangle, int, TreeGumpNode>> list, DirectoryInfo dir)
|
||||
{
|
||||
TreeGumpNode node = GetPath(dir);
|
||||
|
||||
list[node] = RenderPanel;
|
||||
|
||||
var dirs = dir.EnumerateDirectories();
|
||||
|
||||
foreach (var d in dirs.OrderByNatural(d => d.Name))
|
||||
{
|
||||
node = GetPath(dir);
|
||||
|
||||
if (node >= SelectedNode)
|
||||
{
|
||||
MapTree(list, d);
|
||||
}
|
||||
else
|
||||
{
|
||||
list[node] = RenderPanel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void RenderPanel(Rectangle panel, int index, TreeGumpNode node)
|
||||
{
|
||||
if (SelectedFile != null)
|
||||
{
|
||||
RenderFilePanel(panel, index, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderDirectoryPanel(panel, index, node);
|
||||
}
|
||||
}
|
||||
|
||||
// 310 x 350
|
||||
protected virtual void RenderDirectoryPanel(Rectangle panel, int index, TreeGumpNode node)
|
||||
{
|
||||
var x = panel.X + 20;
|
||||
var y = panel.Y + 20;
|
||||
|
||||
var w = panel.Width - 40;
|
||||
var h = panel.Height - 20;
|
||||
|
||||
var xx = x;
|
||||
var yy = y;
|
||||
|
||||
var subIndex = 0;
|
||||
|
||||
var xMax = w / 65;
|
||||
var yMax = h / 110;
|
||||
|
||||
var max = xMax * yMax;
|
||||
|
||||
var range = Enumerable.Empty<FileSystemInfo>()
|
||||
.Union(SelectedDirectory.EnumerateDirectories().OrderByNatural(d => d.Name))
|
||||
.Union(SelectedDirectory.EnumerateFiles().OrderByNatural(f => f.Name));
|
||||
|
||||
foreach (var info in range.Take(max))
|
||||
{
|
||||
// 65 x 110
|
||||
if (info is DirectoryInfo)
|
||||
{
|
||||
var dir = (DirectoryInfo)info;
|
||||
|
||||
// 56 x 80
|
||||
AddButton(xx, yy, 9810, 9810, b => SelectDirectory(dir)); // 56 x 50
|
||||
AddHtml(xx, yy + 50, 56, 40, info.Name.WrapUOHtmlCenter(), false, false); // 56 x 40
|
||||
}
|
||||
else if (info is FileInfo)
|
||||
{
|
||||
var file = (FileInfo)info;
|
||||
|
||||
// 56 x 80
|
||||
AddButton(xx + 5, yy, 2234, 2234, b => SelectFile(file)); // 46 x 50
|
||||
AddHtml(xx, yy + 50, 56, 40, info.Name.WrapUOHtmlCenter(), false, false); // 56 x 40
|
||||
}
|
||||
|
||||
if (++subIndex % xMax == 0)
|
||||
{
|
||||
xx = x;
|
||||
yy += 110;
|
||||
}
|
||||
else
|
||||
{
|
||||
xx += 65;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 310 x 350
|
||||
protected virtual void RenderFilePanel(Rectangle panel, int index, TreeGumpNode node)
|
||||
{
|
||||
if (FileMime.IsCommonText(SelectedFile))
|
||||
{
|
||||
var content = File.ReadAllText(SelectedFile.FullName);
|
||||
|
||||
AddHtml(panel.X, panel.Y, panel.Width, panel.Height, content, HtmlColor, Color.Black);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnSelected(TreeGumpNode oldNode, TreeGumpNode newNode)
|
||||
{
|
||||
var path = GetPath(newNode);
|
||||
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
SelectedDirectory = new DirectoryInfo(path);
|
||||
}
|
||||
|
||||
SelectedFile = null;
|
||||
|
||||
base.OnSelected(oldNode, newNode);
|
||||
}
|
||||
|
||||
public void SelectDirectory(DirectoryInfo dir)
|
||||
{
|
||||
var path = GetPath(dir);
|
||||
|
||||
var node = List.FirstOrDefault(n => n == path);
|
||||
|
||||
if (node != null)
|
||||
{
|
||||
SelectedNode = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedNode = path;
|
||||
}
|
||||
|
||||
SelectedDirectory = dir;
|
||||
SelectedFile = null;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public void SelectFile(FileInfo file)
|
||||
{
|
||||
var path = GetPath(file.Directory);
|
||||
|
||||
var node = List.FirstOrDefault(n => n == path);
|
||||
|
||||
if (node != null)
|
||||
{
|
||||
SelectedNode = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedNode = path;
|
||||
}
|
||||
|
||||
SelectedDirectory = file.Directory;
|
||||
SelectedFile = file;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
376
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Lists/Tree/Tree.cs
Normal file
376
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Lists/Tree/Tree.cs
Normal file
@@ -0,0 +1,376 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
using VitaNex.Collections;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public abstract class TreeGump : SuperGumpList<TreeGumpNode>
|
||||
{
|
||||
public static string DefaultTitle = "Tree View";
|
||||
|
||||
public string Title { get; set; }
|
||||
public Color TitleColor { get; set; }
|
||||
|
||||
public Color HtmlColor { get; set; }
|
||||
|
||||
public TreeGumpNode SelectedNode { get; set; }
|
||||
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
||||
public virtual Dictionary<TreeGumpNode, Action<Rectangle, int, TreeGumpNode>> Nodes { get; private set; }
|
||||
|
||||
public TreeGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
IEnumerable<TreeGumpNode> nodes = null,
|
||||
TreeGumpNode selected = null,
|
||||
string title = null)
|
||||
: base(user, parent, x, y, nodes)
|
||||
{
|
||||
Nodes = new Dictionary<TreeGumpNode, Action<Rectangle, int, TreeGumpNode>>();
|
||||
|
||||
Title = title ?? DefaultTitle;
|
||||
TitleColor = DefaultHtmlColor;
|
||||
|
||||
HtmlColor = DefaultHtmlColor;
|
||||
|
||||
HighlightHue = 1258;
|
||||
TextHue = 1153;
|
||||
|
||||
Width = 600;
|
||||
Height = 400;
|
||||
|
||||
SelectedNode = selected ?? String.Empty;
|
||||
|
||||
ForceRecompile = true;
|
||||
CanMove = true;
|
||||
Sorted = true;
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
Width = Math.Max(600, Width);
|
||||
Height = Math.Max(400, Height);
|
||||
|
||||
EntriesPerPage = (int)Math.Floor((Height - 88) / 22.0);
|
||||
|
||||
if (Nodes == null)
|
||||
{
|
||||
Nodes = new Dictionary<TreeGumpNode, Action<Rectangle, int, TreeGumpNode>>();
|
||||
}
|
||||
|
||||
CompileNodes(Nodes);
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
protected virtual void CompileNodes(Dictionary<TreeGumpNode, Action<Rectangle, int, TreeGumpNode>> list)
|
||||
{ }
|
||||
|
||||
protected override void CompileList(List<TreeGumpNode> list)
|
||||
{
|
||||
foreach (var n in Nodes.Keys)
|
||||
{
|
||||
list.Update(n);
|
||||
}
|
||||
|
||||
var nodes = ListPool<TreeGumpNode>.AcquireObject();
|
||||
var selected = ListPool<TreeGumpNode>.AcquireObject();
|
||||
var parents = ListPool<TreeGumpNode>.AcquireObject();
|
||||
|
||||
nodes.Capacity = list.Count;
|
||||
|
||||
foreach (var n in list)
|
||||
{
|
||||
foreach (var p in n.GetParents())
|
||||
{
|
||||
nodes.Update(p);
|
||||
}
|
||||
|
||||
nodes.Update(n);
|
||||
}
|
||||
|
||||
if (SelectedNode.HasParent)
|
||||
{
|
||||
nodes.Update(SelectedNode.Parent);
|
||||
}
|
||||
|
||||
selected.AddRange(SelectedNode.GetParents());
|
||||
|
||||
nodes.RemoveAll(
|
||||
c =>
|
||||
{
|
||||
parents.AddRange(c.GetParents());
|
||||
|
||||
var remove = false;
|
||||
|
||||
if (parents.Count > 0)
|
||||
{
|
||||
if (parents.Count <= selected.Count && c != SelectedNode && !parents.Contains(SelectedNode) &&
|
||||
!selected.Any(p => p == c || c.Parent == p))
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
else if (parents.Count > selected.Count && c.Parent != SelectedNode)
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
|
||||
parents.Clear();
|
||||
|
||||
return remove;
|
||||
});
|
||||
|
||||
list.Clear();
|
||||
list.AddRange(nodes);
|
||||
|
||||
ObjectPool.Free(ref nodes);
|
||||
ObjectPool.Free(ref selected);
|
||||
ObjectPool.Free(ref parents);
|
||||
|
||||
base.CompileList(list);
|
||||
}
|
||||
|
||||
public override int SortCompare(TreeGumpNode l, TreeGumpNode r)
|
||||
{
|
||||
var res = 0;
|
||||
|
||||
if (l.CompareNull(r, ref res))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
return Insensitive.Compare(l.FullName, r.FullName);
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 9270;
|
||||
|
||||
layout.Add(
|
||||
"body/bg",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 43, Width, Height, 9260);
|
||||
AddImage(15, 18, 1419);
|
||||
AddBackground(15, 58, 235, 50, bgID);
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(25, 68, 215, 30, 2624);
|
||||
}
|
||||
|
||||
AddImage(92, 0, 1417);
|
||||
});
|
||||
|
||||
layout.Add("body/mainbutton", () => AddButton(101, 9, 5545, 5546, MainButtonHandler));
|
||||
|
||||
layout.Add("panel/left", () => AddBackground(15, 115, 235, Height - 87, bgID));
|
||||
|
||||
layout.Add(
|
||||
"panel/left/overlay",
|
||||
() =>
|
||||
{
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(25, 125, 215, Height - 107, 2624);
|
||||
}
|
||||
});
|
||||
|
||||
CompileTreeLayout(layout);
|
||||
|
||||
layout.Add("panel/right", () => AddBackground(255, 58, Width - 270, Height - 30, bgID));
|
||||
|
||||
layout.Add(
|
||||
"panel/right/overlay",
|
||||
() =>
|
||||
{
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(265, 68, Width - 290, Height - 50, 2624);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"title",
|
||||
() => AddHtml(25, 78, 215, 40, Title.WrapUOHtmlCenter().WrapUOHtmlColor(TitleColor, false), false, false));
|
||||
|
||||
layout.Add("dragon", () => AddImage(Width - 33, 0, 10441, 0));
|
||||
|
||||
if (SelectedNode.IsEmpty)
|
||||
{
|
||||
CompileEmptyNodeLayout(layout, 265, 70, Width - 290, Height - 55, List.IndexOf(SelectedNode), SelectedNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
CompileNodeLayout(layout, 265, 70, Width - 290, Height - 55, List.IndexOf(SelectedNode), SelectedNode);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CompileTreeLayout(SuperGumpLayout layout)
|
||||
{
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 9270;
|
||||
|
||||
layout.Add(
|
||||
"tree/scrollbar",
|
||||
() => AddScrollbarVM(25, 125, Height - 107, PageCount, Page, PreviousPage, NextPage));
|
||||
|
||||
var i = 0;
|
||||
|
||||
foreach (var c in EnumerateListRange())
|
||||
{
|
||||
var offset = Math.Min(150, c.Depth * 10);
|
||||
|
||||
CompileTreeEntryLayout(layout, 55 + offset, 125 + (21 * i), 175 - offset, 20, i++, c);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CompileTreeEntryLayout(
|
||||
SuperGumpLayout layout,
|
||||
int x,
|
||||
int y,
|
||||
int w,
|
||||
int h,
|
||||
int index,
|
||||
TreeGumpNode node)
|
||||
{
|
||||
layout.Add(
|
||||
"tree/button/" + index,
|
||||
() => AddHtmlButton(x, y, w, h, btn => SelectNode(node), GetNodeName(node), GetNodeColor(node), Color.Black));
|
||||
}
|
||||
|
||||
protected virtual void CompileEmptyNodeLayout(
|
||||
SuperGumpLayout layout,
|
||||
int x,
|
||||
int y,
|
||||
int w,
|
||||
int h,
|
||||
int index,
|
||||
TreeGumpNode node)
|
||||
{ }
|
||||
|
||||
protected virtual void CompileNodeLayout(
|
||||
SuperGumpLayout layout,
|
||||
int x,
|
||||
int y,
|
||||
int w,
|
||||
int h,
|
||||
int index,
|
||||
TreeGumpNode node)
|
||||
{
|
||||
if (Nodes == null || Nodes.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (Nodes.TryGetValue(node, out var nodeLayout) && nodeLayout != null)
|
||||
{
|
||||
var o = new Rectangle(x, y, w, h);
|
||||
|
||||
layout.Add("node/page/" + index, () => nodeLayout(o, index, node));
|
||||
}
|
||||
}
|
||||
|
||||
public override void InvalidatePageCount()
|
||||
{
|
||||
PageCount = 1 + Math.Max(0, List.Count - EntriesPerPage);
|
||||
Page = Math.Max(0, Math.Min(PageCount - 1, Page));
|
||||
}
|
||||
|
||||
public override Dictionary<int, TreeGumpNode> GetListRange()
|
||||
{
|
||||
return GetListRange(Page, EntriesPerPage);
|
||||
}
|
||||
|
||||
public virtual int GetNodeHue(TreeGumpNode node)
|
||||
{
|
||||
return node != null && SelectedNode != node && !SelectedNode.IsChildOf(node) ? TextHue : HighlightHue;
|
||||
}
|
||||
|
||||
public virtual Color GetNodeColor(TreeGumpNode node)
|
||||
{
|
||||
return node != null && SelectedNode != node && !SelectedNode.IsChildOf(node) ? Color.White : Color.Gold;
|
||||
}
|
||||
|
||||
public virtual string GetNodeName(TreeGumpNode node)
|
||||
{
|
||||
return node == null || String.IsNullOrWhiteSpace(node.Name) ? "..." : node.Name;
|
||||
}
|
||||
|
||||
public void SelectNode(TreeGumpNode node)
|
||||
{
|
||||
var old = SelectedNode;
|
||||
|
||||
if (SelectedNode != node)
|
||||
{
|
||||
SelectedNode = node;
|
||||
}
|
||||
else if (SelectedNode.HasParent)
|
||||
{
|
||||
SelectedNode = SelectedNode.Parent;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedNode = TreeGumpNode.Empty;
|
||||
}
|
||||
|
||||
OnSelected(old, SelectedNode);
|
||||
}
|
||||
|
||||
protected virtual void OnSelected(TreeGumpNode oldNode, TreeGumpNode newNode)
|
||||
{
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected virtual void MainButtonHandler(GumpButton b)
|
||||
{
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected override void OnDispose()
|
||||
{
|
||||
base.OnDispose();
|
||||
|
||||
VitaNexCore.TryCatch(Nodes.Clear);
|
||||
}
|
||||
|
||||
protected override void OnDisposed()
|
||||
{
|
||||
base.OnDisposed();
|
||||
|
||||
SelectedNode = null;
|
||||
|
||||
Nodes = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class TreeGumpNode : IEquatable<TreeGumpNode>, IEquatable<string>
|
||||
{
|
||||
public static char Separator = '|';
|
||||
|
||||
public static readonly TreeGumpNode Empty = new TreeGumpNode(String.Empty);
|
||||
|
||||
public TreeGumpNode Parent { get; private set; }
|
||||
|
||||
public TreeGumpNode RootParent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!HasParent)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var p = Parent;
|
||||
|
||||
while (p.HasParent)
|
||||
{
|
||||
p = p.Parent;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get; private set; }
|
||||
public string FullName { get; private set; }
|
||||
|
||||
public bool HasParent => Parent != null;
|
||||
|
||||
public bool IsRoot => !HasParent;
|
||||
public bool IsEmpty => String.IsNullOrWhiteSpace(FullName);
|
||||
|
||||
public int Depth => IsEmpty ? 0 : GetParents().Count();
|
||||
|
||||
public TreeGumpNode(string path)
|
||||
{
|
||||
FullName = path ?? String.Empty;
|
||||
|
||||
var parents = FullName.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (parents.Length == 0)
|
||||
{
|
||||
Name = FullName;
|
||||
return;
|
||||
}
|
||||
|
||||
Name = parents.LastOrDefault() ?? FullName;
|
||||
|
||||
if (parents.Length > 1)
|
||||
{
|
||||
Parent = new TreeGumpNode(String.Join(Separator.ToString(), parents.Take(parents.Length - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsChildOf(string d)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(d) || IsEmpty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var p = Parent;
|
||||
|
||||
while (p != null)
|
||||
{
|
||||
if (p.FullName == d)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
p = p.Parent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsChildOf(TreeGumpNode d)
|
||||
{
|
||||
if (d == null || d.IsEmpty || IsEmpty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var p = Parent;
|
||||
|
||||
while (p != null)
|
||||
{
|
||||
if (p == d)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
p = p.Parent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsParentOf(TreeGumpNode d)
|
||||
{
|
||||
return d != null && d.IsChildOf(this);
|
||||
}
|
||||
|
||||
public IEnumerable<TreeGumpNode> GetParents()
|
||||
{
|
||||
if (IsEmpty)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
var c = this;
|
||||
|
||||
while (c.HasParent)
|
||||
{
|
||||
c = c.Parent;
|
||||
|
||||
yield return c;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
if (IsEmpty)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var hash = FullName.Length;
|
||||
hash = (hash * 397) ^ FullName.ToLower().GetHashCode();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is string && Equals((string)obj)) || (obj is TreeGumpNode && Equals((TreeGumpNode)obj));
|
||||
}
|
||||
|
||||
public virtual bool Equals(TreeGumpNode other)
|
||||
{
|
||||
return !ReferenceEquals(other, null) && Equals(other.FullName);
|
||||
}
|
||||
|
||||
public virtual bool Equals(string other)
|
||||
{
|
||||
return Insensitive.Equals(FullName, other);
|
||||
}
|
||||
|
||||
public static bool operator ==(TreeGumpNode l, TreeGumpNode r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(TreeGumpNode l, TreeGumpNode r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator >(TreeGumpNode l, TreeGumpNode r)
|
||||
{
|
||||
return !ReferenceEquals(l, null) && !ReferenceEquals(r, null) && r.IsChildOf(l);
|
||||
}
|
||||
|
||||
public static bool operator <(TreeGumpNode l, TreeGumpNode r)
|
||||
{
|
||||
return !ReferenceEquals(l, null) && !ReferenceEquals(r, null) && l.IsChildOf(r);
|
||||
}
|
||||
|
||||
public static bool operator >=(TreeGumpNode l, TreeGumpNode r)
|
||||
{
|
||||
return l == r || l > r;
|
||||
}
|
||||
|
||||
public static bool operator <=(TreeGumpNode l, TreeGumpNode r)
|
||||
{
|
||||
return l == r || l < r;
|
||||
}
|
||||
|
||||
public static implicit operator TreeGumpNode(string path)
|
||||
{
|
||||
return String.IsNullOrWhiteSpace(path) ? Empty : new TreeGumpNode(path);
|
||||
}
|
||||
|
||||
public static implicit operator string(TreeGumpNode node)
|
||||
{
|
||||
return ReferenceEquals(node, null) ? String.Empty : node.FullName;
|
||||
}
|
||||
}
|
||||
}
|
||||
275
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Misc/AnalogClock.cs
Normal file
275
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Misc/AnalogClock.cs
Normal file
@@ -0,0 +1,275 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class AnalogClock : SuperGump
|
||||
{
|
||||
private static readonly Numeral[] _RomanNumerals = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandUtility.Register("Clock", AccessLevel.Player, e => DisplayTo(e.Mobile));
|
||||
}
|
||||
|
||||
public static void DisplayTo(Mobile user)
|
||||
{
|
||||
var roman = EnumerateInstances<AnalogClock>(user).Any(g => g != null && !g.IsDisposed && g.RomanNumerals);
|
||||
|
||||
DisplayTo(user, !roman);
|
||||
}
|
||||
|
||||
public static void DisplayTo(Mobile user, bool roman)
|
||||
{
|
||||
if (user != null)
|
||||
{
|
||||
new AnalogClock(user)
|
||||
{
|
||||
RomanNumerals = roman
|
||||
}.Send();
|
||||
}
|
||||
}
|
||||
|
||||
public static int DefaultRadius = 40;
|
||||
|
||||
public static Color DefaultNumeralsColor = Color.Gold;
|
||||
public static Color DefaultHourHandColor = Color.Gainsboro;
|
||||
public static Color DefaultMinuteHandColor = Color.Gainsboro;
|
||||
public static Color DefaultSecondHandColor = Color.OrangeRed;
|
||||
|
||||
private TimeSpan? _LastTime;
|
||||
|
||||
public TimeSpan Time { get; set; }
|
||||
|
||||
public int Radius { get; set; }
|
||||
|
||||
public bool RomanNumerals { get; set; }
|
||||
|
||||
public bool DisplayNumerals { get; set; }
|
||||
public bool DisplayHourHand { get; set; }
|
||||
public bool DisplayMinuteHand { get; set; }
|
||||
public bool DisplaySecondHand { get; set; }
|
||||
|
||||
public Color ColorNumerals { get; set; }
|
||||
public Color ColorHourHand { get; set; }
|
||||
public Color ColorMinuteHand { get; set; }
|
||||
public Color ColorSecondHand { get; set; }
|
||||
|
||||
public bool RealTime { get; set; }
|
||||
|
||||
public AnalogClock(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
int radius = -1,
|
||||
TimeSpan? time = null)
|
||||
: base(user, parent, x, y)
|
||||
{
|
||||
Radius = radius <= 0 ? DefaultRadius : radius;
|
||||
|
||||
RomanNumerals = false;
|
||||
|
||||
DisplayNumerals = true;
|
||||
DisplayHourHand = true;
|
||||
DisplayMinuteHand = true;
|
||||
DisplaySecondHand = true;
|
||||
|
||||
ColorNumerals = DefaultNumeralsColor;
|
||||
ColorHourHand = DefaultHourHandColor;
|
||||
ColorMinuteHand = DefaultMinuteHandColor;
|
||||
ColorSecondHand = DefaultSecondHandColor;
|
||||
|
||||
if (time != null)
|
||||
{
|
||||
Time = time.Value;
|
||||
RealTime = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Time = DateTime.Now.TimeOfDay;
|
||||
RealTime = true;
|
||||
}
|
||||
|
||||
ForceRecompile = true;
|
||||
|
||||
AutoRefresh = RealTime;
|
||||
}
|
||||
|
||||
protected virtual void ComputeRefreshRate()
|
||||
{
|
||||
if (DisplaySecondHand)
|
||||
{
|
||||
AutoRefreshRate = TimeSpan.FromSeconds(1.0);
|
||||
}
|
||||
else if (DisplayMinuteHand)
|
||||
{
|
||||
AutoRefreshRate = TimeSpan.FromMinutes(1.0);
|
||||
}
|
||||
else if (DisplayHourHand)
|
||||
{
|
||||
AutoRefreshRate = TimeSpan.FromHours(1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
AutoRefresh = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnBeforeSend()
|
||||
{
|
||||
ComputeRefreshRate();
|
||||
|
||||
return base.OnBeforeSend();
|
||||
}
|
||||
|
||||
protected override void OnAutoRefresh()
|
||||
{
|
||||
if (RealTime)
|
||||
{
|
||||
Time = DateTime.Now.TimeOfDay;
|
||||
}
|
||||
else if (_LastTime == Time)
|
||||
{
|
||||
_LastTime = (Time += DateTime.UtcNow - LastAutoRefresh);
|
||||
}
|
||||
|
||||
ComputeRefreshRate();
|
||||
|
||||
base.OnAutoRefresh();
|
||||
}
|
||||
|
||||
protected virtual void GetBounds(out int x, out int y, out int w, out int h)
|
||||
{
|
||||
x = y = 15;
|
||||
w = h = Radius * 2;
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 2620;
|
||||
|
||||
GetBounds(out var x, out var y, out var w, out var h);
|
||||
|
||||
var c = new Point2D(x + (w / 2), y + (h / 2));
|
||||
|
||||
layout.Add("clock/bg", () => AddBackground(x - 15, y - 15, w + 30, h + 30, bgID));
|
||||
|
||||
if (DisplayNumerals)
|
||||
{
|
||||
CompileNumerals(layout, c);
|
||||
}
|
||||
|
||||
if (DisplayHourHand)
|
||||
{
|
||||
CompileHourHand(layout, c);
|
||||
}
|
||||
|
||||
if (DisplayMinuteHand)
|
||||
{
|
||||
CompileMinuteHand(layout, c);
|
||||
}
|
||||
|
||||
if (DisplaySecondHand)
|
||||
{
|
||||
CompileSecondHand(layout, c);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CompileHourHand(SuperGumpLayout layout, Point2D center)
|
||||
{
|
||||
layout.Add(
|
||||
"clock/hand/hour",
|
||||
() =>
|
||||
{
|
||||
var ha = 2.0f * Math.PI * (Time.Hours + Time.Minutes / 60.0f) / 12.0f;
|
||||
var hhp = center.Clone2D((int)(Radius * Math.Sin(ha) / 1.5f), (int)(-Radius * Math.Cos(ha) / 1.5f));
|
||||
|
||||
AddLine(center, hhp, ColorHourHand, 3);
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void CompileMinuteHand(SuperGumpLayout layout, Point2D center)
|
||||
{
|
||||
layout.Add(
|
||||
"clock/hand/minute",
|
||||
() =>
|
||||
{
|
||||
var ma = 2.0f * Math.PI * (Time.Minutes + Time.Seconds / 60.0f) / 60.0f;
|
||||
var mhp = center.Clone2D((int)(Radius * Math.Sin(ma)), (int)(-Radius * Math.Cos(ma)));
|
||||
|
||||
AddLine(center, mhp, ColorMinuteHand, 3);
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void CompileSecondHand(SuperGumpLayout layout, Point2D center)
|
||||
{
|
||||
layout.Add(
|
||||
"clock/hand/second",
|
||||
() =>
|
||||
{
|
||||
var sa = 2.0f * Math.PI * Time.Seconds / 60.0f;
|
||||
var shp = center.Clone2D((int)(Radius * Math.Sin(sa)), (int)(-Radius * Math.Cos(sa)));
|
||||
|
||||
AddLine(center, shp, ColorSecondHand, 1);
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void CompileNumerals(SuperGumpLayout layout, Point2D center)
|
||||
{
|
||||
for (var i = 1; i <= 12; i++)
|
||||
{
|
||||
CompileNumeral(layout, center, i);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CompileNumeral(SuperGumpLayout layout, Point2D center, int num)
|
||||
{
|
||||
layout.Add(
|
||||
"clock/numeral/" + num,
|
||||
() =>
|
||||
{
|
||||
var x = center.X - (RomanNumerals ? 20 : 10);
|
||||
x += (int)(-1 * (Radius * Math.Cos((Math.PI / 180.0f) * (num * 30 + 90))));
|
||||
|
||||
var y = center.Y - 10;
|
||||
y += (int)(-1 * (Radius * Math.Sin((Math.PI / 180.0f) * (num * 30 + 90))));
|
||||
|
||||
var n = GetNumeralString(num).WrapUOHtmlCenter().WrapUOHtmlColor(ColorNumerals);
|
||||
|
||||
AddHtml(x, y, RomanNumerals ? 40 : 20, 40, n, false, false);
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual string GetNumeralString(int num)
|
||||
{
|
||||
return (RomanNumerals ? GetRomanNumeral(num) : num.ToString()).WrapUOHtmlBold();
|
||||
}
|
||||
|
||||
protected virtual string GetRomanNumeral(int num)
|
||||
{
|
||||
return _RomanNumerals[num - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
414
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Misc/HueSelector.cs
Normal file
414
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Misc/HueSelector.cs
Normal file
@@ -0,0 +1,414 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
using Ultima;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class HueSelector : SuperGump, IEnumerable<int>
|
||||
{
|
||||
public static int DefaultIcon = 4650;
|
||||
|
||||
private readonly Grid<int> _HueGrid = new Grid<int>
|
||||
{
|
||||
DefaultValue = -1
|
||||
};
|
||||
|
||||
private int[] _Hues = new int[0];
|
||||
|
||||
public virtual int ScrollX { get; set; }
|
||||
public virtual int ScrollY { get; set; }
|
||||
|
||||
public virtual int ScrollWidth { get; set; }
|
||||
public virtual int ScrollHeight { get; set; }
|
||||
|
||||
public virtual Action<int> AcceptCallback { get; set; }
|
||||
public virtual Action<int> CancelCallback { get; set; }
|
||||
|
||||
public virtual int this[int idx] => idx >= 0 && idx < _Hues.Length ? _Hues[idx] : -1;
|
||||
|
||||
public virtual int this[int x, int y] => x >= 0 && x < _HueGrid.Width && y >= 0 && y < _HueGrid.Height ? _HueGrid[x, y] : -1;
|
||||
|
||||
public virtual int[] Hues { get => _Hues; set => SetHues(value); }
|
||||
|
||||
public virtual int Selected { get; set; }
|
||||
|
||||
public virtual string Title { get; set; }
|
||||
|
||||
public virtual int PreviewIcon { get; set; }
|
||||
|
||||
public HueSelector(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
string title = "Color Chart",
|
||||
int[] hues = null,
|
||||
int selected = -1,
|
||||
Action<int> accept = null,
|
||||
Action<int> cancel = null)
|
||||
: base(user, parent, x, y)
|
||||
{
|
||||
CanDispose = false;
|
||||
|
||||
ScrollX = ScrollY = 0;
|
||||
ScrollWidth = ScrollHeight = 5;
|
||||
|
||||
Selected = selected;
|
||||
AcceptCallback = accept;
|
||||
CancelCallback = cancel;
|
||||
|
||||
Title = title ?? "Color Chart";
|
||||
|
||||
PreviewIcon = DefaultIcon;
|
||||
|
||||
SetHues(hues);
|
||||
}
|
||||
|
||||
public void SetHues(params int[] hues)
|
||||
{
|
||||
hues = hues ?? new int[0];
|
||||
|
||||
if (hues.Length == 0)
|
||||
{
|
||||
_Hues = hues;
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<int>(hues);
|
||||
|
||||
list.Prune();
|
||||
|
||||
_Hues = list.FreeToArray(true);
|
||||
}
|
||||
|
||||
_Hues.Sort();
|
||||
|
||||
var size = (int)Math.Ceiling(Math.Sqrt(_Hues.Length));
|
||||
|
||||
_HueGrid.DefaultValue = -1;
|
||||
_HueGrid.Resize(size, size);
|
||||
|
||||
int i = 0, gx, gy;
|
||||
|
||||
for (gy = 0; gy < size; gy++)
|
||||
{
|
||||
for (gx = 0; gx < size; gx++)
|
||||
{
|
||||
_HueGrid.SetContent(gx, gy, i < _Hues.Length ? _Hues[i] : -1);
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsOpen)
|
||||
{
|
||||
Refresh(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
if (_Hues.Length <= 0)
|
||||
{
|
||||
Selected = -1;
|
||||
}
|
||||
else if (!_Hues.Contains(Selected))
|
||||
{
|
||||
Selected = _Hues[0];
|
||||
}
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var pad = ec || sup ? 15 : 10;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 2620;
|
||||
|
||||
var w = 44 + (44 * ScrollWidth);
|
||||
var h = 44 + (44 * ScrollHeight);
|
||||
|
||||
w = Math.Max(176, w);
|
||||
h = Math.Max(176, h);
|
||||
|
||||
w += pad * 2;
|
||||
h += pad * 2;
|
||||
|
||||
/* Layout:
|
||||
* ___________
|
||||
* [___________|<]
|
||||
* | |O O O O |^|
|
||||
* | |O O O O | |
|
||||
* | |O O O O | |
|
||||
* | |________|v|
|
||||
* |__|<______>|>]
|
||||
*/
|
||||
|
||||
var width = 135 + w;
|
||||
var height = 70 + h;
|
||||
|
||||
layout.Add(
|
||||
"bg",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 0, width, height, bgID);
|
||||
AddBackground(0, 35, 100, height - 35, bgID);
|
||||
AddBackground(100, 35, width - 135, height - 70, bgID);
|
||||
AddImageTiled(100 + pad, 35 + pad, width - (135 + (pad * 2)), height - (70 + (pad * 2)), bgID + 4);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"title",
|
||||
() =>
|
||||
{
|
||||
var title = Title;
|
||||
|
||||
title = title.WrapUOHtmlBig();
|
||||
title = title.WrapUOHtmlColor(Color.Gold, false);
|
||||
|
||||
AddHtml(pad, pad, width - (pad * 2), 40, title, false, false);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"preview",
|
||||
() =>
|
||||
{
|
||||
var label = GetHueLabel(Selected);
|
||||
|
||||
label = label.WrapUOHtmlBig();
|
||||
label = label.WrapUOHtmlCenter();
|
||||
label = label.WrapUOHtmlColor(Color.Gold, false);
|
||||
|
||||
AddHtml(pad, 35 + pad, 100 - (pad * 2), 40, label, false, false);
|
||||
|
||||
if (PreviewIcon >= 0)
|
||||
{
|
||||
var s = ArtExtUtility.GetImageSize(PreviewIcon);
|
||||
|
||||
if (Selected > 0)
|
||||
{
|
||||
AddItem((100 - s.Width) / 2, 35 + pad + 40, PreviewIcon, Selected);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddItem((100 - s.Width) / 2, 35 + pad + 40, PreviewIcon);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CompileEntries(layout, 100 + pad, 35 + pad);
|
||||
|
||||
layout.Add(
|
||||
"scrollY",
|
||||
() =>
|
||||
{
|
||||
var value = Math.Max(0, (_HueGrid.Height + 1) - ScrollHeight);
|
||||
|
||||
AddScrollbarV(
|
||||
width - (16 + pad),
|
||||
35 + pad,
|
||||
value,
|
||||
ScrollY,
|
||||
b => ScrollUp(),
|
||||
b => ScrollDown(),
|
||||
new Rectangle(0, 20, 16, height - (110 + (pad * 2))),
|
||||
new Rectangle(0, 0, 16, 16),
|
||||
new Rectangle(0, 20 + (height - (110 + (pad * 2))) + 4, 16, 16),
|
||||
Tuple.Create(9354, 9304),
|
||||
Tuple.Create(5604, 5600, 5604),
|
||||
Tuple.Create(5606, 5602, 5606));
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"scrollX",
|
||||
() =>
|
||||
{
|
||||
var value = Math.Max(0, (_HueGrid.Width + 1) - ScrollWidth);
|
||||
|
||||
AddScrollbarH(
|
||||
100 + pad,
|
||||
height - (16 + pad),
|
||||
value,
|
||||
ScrollX,
|
||||
b => ScrollLeft(),
|
||||
b => ScrollRight(),
|
||||
new Rectangle(20, 0, width - (175 + (pad * 2)), 16),
|
||||
new Rectangle(0, 0, 16, 16),
|
||||
new Rectangle(20 + (width - (175 + (pad * 2))) + 4, 0, 16, 16),
|
||||
Tuple.Create(9354, 9304),
|
||||
Tuple.Create(5607, 5603, 5607),
|
||||
Tuple.Create(5605, 5601, 5605));
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"cancel",
|
||||
() =>
|
||||
{
|
||||
AddButton(width - (15 + pad), pad, 11410, 11411, OnCancel);
|
||||
AddTooltip(1006045);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"accept",
|
||||
() =>
|
||||
{
|
||||
AddButton(width - (15 + pad), height - (15 + pad), 11400, 11401, OnAccept);
|
||||
AddTooltip(1006044);
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void CompileEntries(SuperGumpLayout layout, int x, int y)
|
||||
{
|
||||
var cells = _HueGrid.SelectCells(ScrollX, ScrollY, ScrollWidth, ScrollHeight);
|
||||
|
||||
int i = 0, gx, gy, xx, yy;
|
||||
|
||||
for (gy = 0, yy = y; gy < ScrollHeight; gy++, yy += 44)
|
||||
{
|
||||
for (gx = 0, xx = x; gx < ScrollWidth; gx++, xx += 44)
|
||||
{
|
||||
CompileEntry(layout, xx, yy, gx, gy, i++, cells.InBounds(gx, gy) ? cells[gx][gy] : -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CompileEntry(SuperGumpLayout layout, int x, int y, int gx, int gy, int idx, int hue)
|
||||
{
|
||||
if (hue <= -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var fillID = ec ? 87 : sup ? 40004 : 2624;
|
||||
|
||||
layout.Add(
|
||||
"entry/" + idx,
|
||||
() =>
|
||||
{
|
||||
const int itemID = 4011;
|
||||
|
||||
var s = Selected == hue;
|
||||
|
||||
AddButton(x, y, 2240, 2240, b => SelectEntry(gx, gy, idx, hue));
|
||||
AddImageTiled(x, y, 44, 44, fillID);
|
||||
|
||||
var o = ArtExtUtility.GetImageOffset(itemID);
|
||||
|
||||
if (s)
|
||||
{
|
||||
AddItem(x + o.X, y + o.Y + 5, itemID, 2050);
|
||||
AddItem(x + o.X, y + o.Y + 2, itemID, 2999);
|
||||
}
|
||||
else if (sup)
|
||||
{
|
||||
AddItem(x + o.X, y + o.Y + 5, itemID, 2999);
|
||||
}
|
||||
|
||||
if (hue > 0)
|
||||
{
|
||||
AddItem(x + o.X, y + o.Y, itemID, hue);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddItem(x + o.X, y + o.Y, itemID);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void SelectEntry(int gx, int gy, int idx, int hue)
|
||||
{
|
||||
Selected = hue;
|
||||
|
||||
OnSelected(gx, gy, idx, hue);
|
||||
}
|
||||
|
||||
protected virtual void OnSelected(int gx, int gy, int idx, int hue)
|
||||
{
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual void OnCancel(GumpButton b)
|
||||
{
|
||||
if (CancelCallback != null)
|
||||
{
|
||||
CancelCallback(Selected);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnAccept(GumpButton b)
|
||||
{
|
||||
if (AcceptCallback != null)
|
||||
{
|
||||
AcceptCallback(Selected);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ScrollLeft()
|
||||
{
|
||||
ScrollX--;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual void ScrollRight()
|
||||
{
|
||||
ScrollX++;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual void ScrollUp()
|
||||
{
|
||||
ScrollY--;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual void ScrollDown()
|
||||
{
|
||||
ScrollY++;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
public virtual string GetHueLabel(int hue)
|
||||
{
|
||||
return hue <= 0 ? (Utility.RandomBool() ? "Cillit Bang" : "Industrial Bleach") : "N°. " + hue;
|
||||
}
|
||||
|
||||
public virtual IEnumerator<int> GetEnumerator()
|
||||
{
|
||||
return _Hues.GetEnumerator<int>();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using Server;
|
||||
using Server.Accounting;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class OffsetSelectorGump : SuperGump
|
||||
{
|
||||
public static Point DefaultOffset = Point.Empty;
|
||||
|
||||
private Point _Value;
|
||||
|
||||
public Point Value
|
||||
{
|
||||
get => _Value;
|
||||
set
|
||||
{
|
||||
if (_Value == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldValue = _Value;
|
||||
|
||||
_Value = value;
|
||||
|
||||
OnValueChanged(oldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public int Cols { get; private set; }
|
||||
public int Rows { get; private set; }
|
||||
|
||||
public virtual Action<OffsetSelectorGump, Point> ValueChanged { get; set; }
|
||||
|
||||
public OffsetSelectorGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
Point? value = null,
|
||||
Action<OffsetSelectorGump, Point> valueChanged = null)
|
||||
: base(user, parent, 0, 0)
|
||||
{
|
||||
ForceRecompile = true;
|
||||
|
||||
CanMove = false;
|
||||
CanClose = true;
|
||||
CanDispose = true;
|
||||
|
||||
_Value = value ?? DefaultOffset;
|
||||
ValueChanged = valueChanged;
|
||||
|
||||
var hi = User.Account is Account ? ((Account)User.Account).HardwareInfo : null;
|
||||
|
||||
Cols = (hi != null ? hi.ScreenWidth : 1920) / 20;
|
||||
Rows = (hi != null ? hi.ScreenHeight : 1080) / 20;
|
||||
}
|
||||
|
||||
public override void AssignCollections()
|
||||
{
|
||||
var capacity = Cols * Rows;
|
||||
|
||||
if (Entries != null && Entries.Capacity < 0x20 + capacity)
|
||||
{
|
||||
Entries.Capacity = 0x20 + capacity;
|
||||
}
|
||||
|
||||
if (Buttons == null)
|
||||
{
|
||||
Buttons = new Dictionary<GumpButton, Action<GumpButton>>(capacity);
|
||||
}
|
||||
|
||||
base.AssignCollections();
|
||||
}
|
||||
|
||||
protected override bool OnBeforeSend()
|
||||
{
|
||||
User.SendMessage(0x55, "Generating Offset Selection Interface, please wait...");
|
||||
|
||||
return base.OnBeforeSend();
|
||||
}
|
||||
|
||||
protected virtual void OnValueChanged(Point oldValue)
|
||||
{
|
||||
if (ValueChanged != null)
|
||||
{
|
||||
ValueChanged(this, oldValue);
|
||||
}
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
layout.Add(
|
||||
"buttongrid/base",
|
||||
() =>
|
||||
{
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < Rows; y++)
|
||||
{
|
||||
for (x = 0; x < Cols; x++)
|
||||
{
|
||||
AddButton(x * 20, y * 20, 9028, 9021, OnSelectPoint);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add("image/marker", () => AddImage(Value.X + 5, Value.Y, 9009));
|
||||
}
|
||||
|
||||
protected virtual void OnSelectPoint(GumpButton b)
|
||||
{
|
||||
Value = new Point(b.X, b.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class SkillSelectionGump : ListGump<SkillName>
|
||||
{
|
||||
private static readonly SkillName[] _Skills = ((SkillName)0).GetValues<SkillName>();
|
||||
|
||||
public int Limit { get; set; }
|
||||
|
||||
public virtual Action<GumpButton> AcceptHandler { get; set; }
|
||||
public virtual Action<GumpButton> CancelHandler { get; set; }
|
||||
|
||||
public virtual Action<SkillName[]> Callback { get; set; }
|
||||
|
||||
public List<SkillName> SelectedSkills { get; set; }
|
||||
public List<SkillName> IgnoredSkills { get; set; }
|
||||
|
||||
public SkillSelectionGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int limit = 1,
|
||||
Action<GumpButton> onAccept = null,
|
||||
Action<GumpButton> onCancel = null,
|
||||
Action<SkillName[]> callback = null,
|
||||
params SkillName[] ignoredSkills)
|
||||
: base(user, parent, emptyText: "No skills to display.", title: "Skill Selection")
|
||||
{
|
||||
EntriesPerPage = 30;
|
||||
|
||||
Limit = limit;
|
||||
Callback = callback;
|
||||
SelectedSkills = new List<SkillName>();
|
||||
IgnoredSkills = new List<SkillName>(ignoredSkills);
|
||||
|
||||
if (Limit > 0)
|
||||
{
|
||||
Title += ": (" + Limit + " Max)";
|
||||
}
|
||||
|
||||
AcceptHandler = onAccept;
|
||||
CancelHandler = onCancel;
|
||||
}
|
||||
|
||||
protected override void CompileList(List<SkillName> list)
|
||||
{
|
||||
List.Clear();
|
||||
|
||||
foreach (var skill in _Skills.Where(skill => !IgnoredSkills.Contains(skill)))
|
||||
{
|
||||
List.Add(skill);
|
||||
}
|
||||
|
||||
base.CompileList(list);
|
||||
|
||||
List.Sort((a, b) => Insensitive.Compare(a.GetName(), b.GetName()));
|
||||
}
|
||||
|
||||
protected override sealed void CompileMenuOptions(MenuGumpOptions list)
|
||||
{ }
|
||||
|
||||
protected override sealed void ShowOptionMenu(GumpButton button)
|
||||
{
|
||||
OnAccept(button);
|
||||
}
|
||||
|
||||
protected virtual void OnAccept(GumpButton button)
|
||||
{
|
||||
if (AcceptHandler != null)
|
||||
{
|
||||
AcceptHandler(button);
|
||||
}
|
||||
|
||||
if (Callback != null)
|
||||
{
|
||||
Callback(SelectedSkills.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnCancel(GumpButton button)
|
||||
{
|
||||
if (CancelHandler != null)
|
||||
{
|
||||
CancelHandler(button);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
layout.Remove("button/header/options");
|
||||
|
||||
layout.Add("button/header/done", () => AddButton(15, 15, 248, 249, ShowOptionMenu));
|
||||
|
||||
if (Minimized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 9270;
|
||||
|
||||
layout.Replace("background/body/base", () => AddBackground(0, 55, 420, 330, bgID));
|
||||
layout.Remove("imagetiled/body/vsep/0");
|
||||
}
|
||||
|
||||
protected override void CompileEntryLayout(
|
||||
SuperGumpLayout layout,
|
||||
int length,
|
||||
int index,
|
||||
int pIndex,
|
||||
int yOffset,
|
||||
SkillName entry)
|
||||
{
|
||||
var sup = SupportsUltimaStore;
|
||||
var bgID = sup ? 40000 : 9270;
|
||||
|
||||
var xOffset = 0;
|
||||
|
||||
if (pIndex < EntriesPerPage - 20)
|
||||
{
|
||||
xOffset = 10;
|
||||
}
|
||||
else if (pIndex < EntriesPerPage - 10)
|
||||
{
|
||||
xOffset = 145;
|
||||
yOffset = 70 + (pIndex - 10) * 30;
|
||||
}
|
||||
else if (pIndex < EntriesPerPage)
|
||||
{
|
||||
xOffset = 280;
|
||||
yOffset = 70 + (pIndex - 20) * 30;
|
||||
}
|
||||
|
||||
layout.Replace(
|
||||
"check/list/select/" + index,
|
||||
() => AddButton(
|
||||
xOffset,
|
||||
yOffset,
|
||||
5033,
|
||||
5033,
|
||||
b =>
|
||||
{
|
||||
if (SelectedSkills.Contains(entry))
|
||||
{
|
||||
SelectedSkills.Remove(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SelectedSkills.Count < Limit)
|
||||
{
|
||||
SelectedSkills.Add(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
new NoticeDialogGump(User, Refresh(true))
|
||||
{
|
||||
Title = "Limit Reached",
|
||||
Html = "You have selected the maximum of " + Limit +
|
||||
" skills.\nIf you are happy with your selection, click the 'Okay' button."
|
||||
}.Send();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Refresh(true);
|
||||
}));
|
||||
|
||||
if (SelectedSkills.Contains(entry))
|
||||
{
|
||||
layout.Add(
|
||||
"imagetiled/list/entry/" + index,
|
||||
() =>
|
||||
{
|
||||
AddImageTiled(xOffset, yOffset, 128, 28, 3004);
|
||||
AddImageTiled(4 + xOffset, 4 + yOffset, 120, 20, bgID + 4);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
layout.Add("imagetiled/list/entry/" + index, () => AddImageTiled(xOffset, yOffset, 128, 28, bgID + 4));
|
||||
}
|
||||
|
||||
layout.Add(
|
||||
"html/list/entry/" + index,
|
||||
() => AddHtml(
|
||||
4 + xOffset,
|
||||
4 + yOffset,
|
||||
120,
|
||||
20,
|
||||
String.Format(
|
||||
"<center><big><basefont color=#{0:X6}>{1}</big></center>",
|
||||
(ushort)GetLabelHue(index, pIndex, entry),
|
||||
GetLabelText(index, pIndex, entry)),
|
||||
false,
|
||||
false));
|
||||
}
|
||||
|
||||
protected override string GetLabelText(int index, int pageIndex, SkillName entry)
|
||||
{
|
||||
return entry.GetName();
|
||||
}
|
||||
|
||||
protected override int GetLabelHue(int index, int pageIndex, SkillName entry)
|
||||
{
|
||||
return SelectedSkills.Contains(entry) ? Color.Cyan.ToRgb() : Color.White.ToRgb();
|
||||
}
|
||||
}
|
||||
}
|
||||
70
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Panels/Html.cs
Normal file
70
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Panels/Html.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
|
||||
using VitaNex.Text;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class HtmlPanelGump<T> : PanelGump<T>
|
||||
{
|
||||
public virtual string Html { get; set; }
|
||||
public virtual Color HtmlColor { get; set; }
|
||||
public virtual bool HtmlBackground { get; set; }
|
||||
|
||||
public HtmlPanelGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
int width = 420,
|
||||
int height = 420,
|
||||
string html = null,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null,
|
||||
T selected = default(T))
|
||||
: base(user, parent, x, y, width, height, emptyText, title, opts, selected)
|
||||
{
|
||||
HtmlColor = DefaultHtmlColor;
|
||||
HtmlBackground = false;
|
||||
|
||||
Html = html ?? String.Empty;
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
if (Minimized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
layout.Add(
|
||||
"html/body/base",
|
||||
() =>
|
||||
{
|
||||
var html = Html.ParseBBCode(HtmlColor);
|
||||
|
||||
AddHtml(15, 65, Width - 30, Height - 30, html, HtmlBackground, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
217
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Panels/Panel.cs
Normal file
217
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Panels/Panel.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class PanelGump<T> : SuperGump
|
||||
{
|
||||
private int _Width;
|
||||
private int _Height;
|
||||
|
||||
protected bool WasModal { get; set; }
|
||||
|
||||
public virtual string Title { get; set; }
|
||||
public virtual string EmptyText { get; set; }
|
||||
|
||||
public virtual bool Minimized { get; set; }
|
||||
|
||||
public virtual T Selected { get; set; }
|
||||
|
||||
public virtual MenuGumpOptions Options { get; set; }
|
||||
|
||||
public virtual int Width { get => _Width; set => _Width = Math.Max(250, Math.Min(1024, value)); }
|
||||
public virtual int Height { get => _Height; set => _Height = Math.Max(250, Math.Min(786, value)); }
|
||||
|
||||
public PanelGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
int width = 420,
|
||||
int height = 420,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null,
|
||||
T selected = default(T))
|
||||
: base(user, parent, x, y)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
Selected = selected;
|
||||
EmptyText = emptyText ?? "No entry to display.";
|
||||
Title = title ?? "Panel View";
|
||||
Minimized = false;
|
||||
CanMove = false;
|
||||
|
||||
if (opts != null)
|
||||
{
|
||||
Options = new MenuGumpOptions(opts);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
base.Compile();
|
||||
|
||||
if (Options == null)
|
||||
{
|
||||
Options = new MenuGumpOptions();
|
||||
}
|
||||
|
||||
CompileMenuOptions(Options);
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
var sup = SupportsUltimaStore;
|
||||
var ec = IsEnhancedClient;
|
||||
var bgID = ec ? 83 : sup ? 40000 : 9270;
|
||||
|
||||
layout.Add(
|
||||
"background/header/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 0, Width, 50, bgID);
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(10, 10, Width - 20, 30, 2624);
|
||||
//AddAlphaRegion(10, 10, Width - 20, 30);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"button/header/options",
|
||||
() =>
|
||||
{
|
||||
AddButton(15, 15, 2008, 2007, ShowOptionMenu);
|
||||
AddTooltip(1015326);
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"button/header/minimize",
|
||||
() =>
|
||||
{
|
||||
if (Minimized)
|
||||
{
|
||||
AddButton(Width - 30, 20, 10740, 10742, Maximize);
|
||||
AddTooltip(3002086);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddButton(Width - 30, 20, 10741, 10742, Minimize);
|
||||
AddTooltip(3002085);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add(
|
||||
"label/header/title",
|
||||
() => AddLabelCropped(90, 15, Width - 135, 20, GetTitleHue(), String.IsNullOrEmpty(Title) ? "Panel View" : Title));
|
||||
|
||||
if (Minimized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
layout.Add(
|
||||
"background/body/base",
|
||||
() =>
|
||||
{
|
||||
AddBackground(0, 50, Width, Height, bgID);
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
AddImageTiled(10, 60, Width - 20, Height - 20, 2624);
|
||||
//AddAlphaRegion(10, 60, Width - 20, Height - 20);
|
||||
}
|
||||
});
|
||||
|
||||
if (Selected == null)
|
||||
{
|
||||
var text = String.IsNullOrEmpty(EmptyText) ? "No entry to display." : EmptyText;
|
||||
|
||||
layout.Add("label/list/empty", () => AddLabelCropped(15, 67, Width - 30, 20, ErrorHue, text));
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Minimize(GumpButton entry = null)
|
||||
{
|
||||
Minimized = true;
|
||||
|
||||
if (Modal)
|
||||
{
|
||||
WasModal = true;
|
||||
}
|
||||
|
||||
Modal = false;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected virtual void Maximize(GumpButton entry = null)
|
||||
{
|
||||
Minimized = false;
|
||||
|
||||
if (WasModal)
|
||||
{
|
||||
Modal = true;
|
||||
}
|
||||
|
||||
WasModal = false;
|
||||
|
||||
Refresh(true);
|
||||
}
|
||||
|
||||
protected virtual int GetTitleHue()
|
||||
{
|
||||
return TextHue;
|
||||
}
|
||||
|
||||
protected virtual void ShowOptionMenu(GumpButton button)
|
||||
{
|
||||
if (User != null && !User.Deleted && Options != null && Options.Count >= 0)
|
||||
{
|
||||
Send(new MenuGump(User, Refresh(), Options, button));
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void CompileMenuOptions(MenuGumpOptions list)
|
||||
{
|
||||
if (Minimized)
|
||||
{
|
||||
list.Replace("Minimize", new ListGumpEntry("Maximize", Maximize));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Replace("Maximize", new ListGumpEntry("Minimize", Minimize));
|
||||
}
|
||||
|
||||
list.AppendEntry(new ListGumpEntry("Refresh", button => Refresh(true)));
|
||||
|
||||
if (CanClose)
|
||||
{
|
||||
list.AppendEntry(new ListGumpEntry("Exit", button => Close()));
|
||||
}
|
||||
|
||||
list.AppendEntry(new ListGumpEntry("Cancel", button => { }));
|
||||
}
|
||||
}
|
||||
}
|
||||
124
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Panels/TextInput.cs
Normal file
124
Scripts/SubSystem/VitaNex/Core/SuperGumps/UI/Panels/TextInput.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.SuperGumps.UI
|
||||
{
|
||||
public class TextInputPanelGump<T> : PanelGump<T>
|
||||
{
|
||||
private int _Limit;
|
||||
|
||||
public virtual int Limit
|
||||
{
|
||||
get => _Limit;
|
||||
set
|
||||
{
|
||||
value = Math.Max(0, value);
|
||||
|
||||
if (_Limit == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Limit = value;
|
||||
Refresh(true);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string Input { get; set; }
|
||||
public virtual bool InputBackground { get; set; }
|
||||
|
||||
public bool Limited => (Limit > 0);
|
||||
|
||||
public Action<string> Callback { get; set; }
|
||||
|
||||
public TextInputPanelGump(
|
||||
Mobile user,
|
||||
Gump parent = null,
|
||||
int? x = null,
|
||||
int? y = null,
|
||||
int width = 420,
|
||||
int height = 420,
|
||||
string emptyText = null,
|
||||
string title = null,
|
||||
IEnumerable<ListGumpEntry> opts = null,
|
||||
T selected = default(T),
|
||||
string input = null,
|
||||
int limit = 0,
|
||||
Action<string> callback = null)
|
||||
: base(user, parent, x, y, width, height, emptyText, title, opts, selected)
|
||||
{
|
||||
InputBackground = true;
|
||||
|
||||
Input = input ?? String.Empty;
|
||||
_Limit = limit;
|
||||
Callback = callback;
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
if (Minimized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (InputBackground)
|
||||
{
|
||||
layout.Add("background/input/base", () => AddBackground(15, 65, Width - 30, Height - 30, 9350));
|
||||
}
|
||||
|
||||
if (Limited)
|
||||
{
|
||||
layout.Add(
|
||||
"textentry/body/base",
|
||||
() => AddTextEntryLimited(25, 75, Width - 40, Height - 40, TextHue, Input, Limit, ParseInput));
|
||||
}
|
||||
else
|
||||
{
|
||||
layout.Add("textentry/body/base", () => AddTextEntry(25, 75, Width - 40, Height - 40, TextHue, Input, ParseInput));
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ParseInput(GumpTextEntry entry, string text)
|
||||
{
|
||||
ParseInput(text);
|
||||
}
|
||||
|
||||
protected virtual void ParseInput(GumpTextEntryLimited entry, string text)
|
||||
{
|
||||
ParseInput(text);
|
||||
}
|
||||
|
||||
protected virtual void ParseInput(string text)
|
||||
{
|
||||
Input = text ?? String.Empty;
|
||||
}
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
base.OnClick();
|
||||
|
||||
if (Callback != null)
|
||||
{
|
||||
Callback(Input);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user