Overwrite

Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
Unstable Kitsune
2023-11-28 23:20:26 -05:00
parent 3cd54811de
commit b918192e4e
11608 changed files with 2644205 additions and 47 deletions

View File

@@ -0,0 +1,300 @@
#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.Commands;
using Server.Gumps;
using VitaNex.SuperGumps;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.Toolbar
{
public class ToolbarCommand : ToolbarEntry, IEquatable<ToolbarCommand>
{
[CommandProperty(Toolbars.Access)]
public AccessLevel? MinAccess { get; set; }
public List<string> Args { get; set; }
[CommandProperty(Toolbars.Access)]
public override string FullValue => String.Format(
"{0}{1} {2}",
CommandSystem.Prefix,
base.FullValue,
String.Join(" ", Args ?? (Args = new List<string>())));
public ToolbarCommand()
{
Args = new List<string>();
}
public ToolbarCommand(
string cmd,
string label = null,
bool canDelete = true,
bool canEdit = true,
bool highlight = false,
Color? labelColor = null,
AccessLevel? minAccess = null,
params string[] args)
: base(cmd, label, canDelete, canEdit, highlight, labelColor)
{
MinAccess = minAccess;
Args = args != null && args.Length > 0 ? new List<string>(args) : new List<string>();
}
public ToolbarCommand(GenericReader reader)
: base(reader)
{ }
protected override void CompileOptions(ToolbarGump toolbar, GumpButton clicked, Point loc, MenuGumpOptions opts)
{
if (toolbar == null)
{
return;
}
base.CompileOptions(toolbar, clicked, loc, opts);
var user = toolbar.User;
if (!CanEdit && user.AccessLevel < Toolbars.Access)
{
return;
}
opts.Replace(
"Set Value",
new ListGumpEntry(
"Set Command",
b => SuperGump.Send(
new InputDialogGump(user, toolbar)
{
Title = "Set Command",
Html = "Set the command for this Command entry.",
InputText = Value,
Callback = (cb, text) =>
{
Value = text;
toolbar.Refresh(true);
}
}),
toolbar.HighlightHue));
opts.AppendEntry(
new ListGumpEntry(
"Set Args",
b => SuperGump.Send(
new InputDialogGump(user, toolbar)
{
Title = "Set Command Arguments",
Html = "Set the Arguments for this Command entry.\nSeparate your entries with a semi-colon- ;",
InputText = String.Join(";", Args),
Callback = (cb, text) =>
{
Args.Clear();
Args.AddRange(text.Split(';'));
toolbar.Refresh(true);
}
}),
toolbar.HighlightHue));
}
public override bool ValidateState(ToolbarState state)
{
if (!base.ValidateState(state))
{
return false;
}
var user = state.User;
if (MinAccess != null && user.AccessLevel < MinAccess)
{
return false;
}
if (String.IsNullOrEmpty(Value))
{
return false;
}
if (!CommandSystem.Entries.TryGetValue(Value, out var cmd))
{
return false;
}
if (cmd == null || cmd.AccessLevel > (MinAccess ?? user.AccessLevel))
{
return false;
}
return true;
}
protected override void OnCloned(ToolbarEntry clone)
{
base.OnCloned(clone);
var cmd = clone as ToolbarCommand;
if (cmd == null)
{
return;
}
cmd.Args = (Args != null && Args.Count > 0) ? Args.ToList() : new List<string>();
cmd.MinAccess = MinAccess;
}
public override void Invoke(ToolbarState state)
{
if (state == null)
{
return;
}
var user = state.User;
if (user == null || user.Deleted || user.NetState == null)
{
return;
}
VitaNexCore.TryCatch(
() => CommandSystem.Handle(user, FullValue),
ex =>
{
Console.WriteLine("{0} => {1} => ({2}) => {3}", user, GetType().Name, FullValue, ex);
Toolbars.CMOptions.ToConsole(ex);
});
}
public override void Reset(ToolbarGump toolbar)
{
base.Reset(toolbar);
if (toolbar == null)
{
return;
}
var user = toolbar.User;
if (CanEdit || user.AccessLevel >= Toolbars.Access)
{
Args.Clear();
}
}
public override int GetHashCode()
{
unchecked
{
var hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^
(Args != null ? Args.Aggregate(Args.Count, (c, h) => (c * 397) ^ h.GetHashCode()) : 0);
hashCode = (hashCode * 397) ^ (MinAccess.HasValue ? MinAccess.Value.GetHashCode() : 0);
return hashCode;
}
}
public override bool Equals(object obj)
{
return obj is ToolbarCommand && Equals((ToolbarCommand)obj);
}
public bool Equals(ToolbarCommand other)
{
return !ReferenceEquals(other, null) && base.Equals(other) && MinAccess == other.MinAccess &&
String.Join("", Args) == String.Join("", other.Args);
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
var version = writer.SetVersion(1);
switch (version)
{
case 1:
case 0:
{
writer.Write((MinAccess != null) ? (int)MinAccess : -1);
if (version > 0)
{
writer.WriteList(Args, writer.Write);
}
else
{
writer.Write(Args.Count);
Args.ForEach(writer.Write);
}
}
break;
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
var version = reader.GetVersion();
switch (version)
{
case 1:
case 0:
{
var minAccess = reader.ReadInt();
MinAccess = (minAccess < 0) ? null : (AccessLevel?)minAccess;
if (version > 0)
{
Args = reader.ReadList(reader.ReadString);
}
else
{
var count = reader.ReadInt();
Args = new List<string>(count);
for (var i = 0; i < count; i++)
{
Args.Add(reader.ReadString());
}
}
}
break;
}
}
public static bool operator ==(ToolbarCommand l, ToolbarCommand r)
{
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
}
public static bool operator !=(ToolbarCommand l, ToolbarCommand r)
{
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
}
}
}

View File

@@ -0,0 +1,510 @@
#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;
using VitaNex.SuperGumps;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.Toolbar
{
[PropertyObject]
public abstract class ToolbarEntry : IEquatable<ToolbarEntry>
{
public ToolbarEntry()
: this(String.Empty)
{ }
public ToolbarEntry(
string value,
string label = null,
bool canDelete = true,
bool canEdit = true,
bool highlight = false,
Color? labelColor = null)
{
Value = value;
Label = String.IsNullOrEmpty(label) ? Value : label;
CanDelete = canDelete;
CanEdit = canEdit;
Highlight = highlight;
LabelColor = labelColor;
}
public ToolbarEntry(GenericReader reader)
{
Deserialize(reader);
}
[CommandProperty(Toolbars.Access)]
public virtual string Value { get; set; }
[CommandProperty(Toolbars.Access)]
public virtual string Label { get; set; }
[CommandProperty(Toolbars.Access)]
public virtual Color? LabelColor { get; set; }
[CommandProperty(Toolbars.Access)]
public virtual bool CanEdit { get; set; }
[CommandProperty(Toolbars.Access)]
public virtual bool CanDelete { get; set; }
[CommandProperty(Toolbars.Access)]
public virtual bool Highlight { get; set; }
[CommandProperty(Toolbars.Access)]
public virtual string FullValue => String.Format("{0}", Value);
public virtual string GetDisplayLabel()
{
if (!String.IsNullOrWhiteSpace(Label))
{
return Label;
}
if (!String.IsNullOrWhiteSpace(Value))
{
return Value;
}
return "*Empty*";
}
public virtual ToolbarEntry Clone()
{
var clone = Activator.CreateInstance(GetType()) as ToolbarEntry;
if (clone != null)
{
OnCloned(clone);
}
return clone;
}
protected virtual void OnCloned(ToolbarEntry clone)
{
if (clone == null)
{
return;
}
clone.Value = Value;
clone.Label = Label;
clone.CanDelete = CanDelete;
clone.CanEdit = CanEdit;
clone.LabelColor = LabelColor;
clone.Highlight = Highlight;
}
public virtual MenuGumpOptions GetOptions(ToolbarGump toolbar, GumpButton clicked, Point loc)
{
var opts = new MenuGumpOptions();
if (toolbar == null)
{
return opts;
}
CompileOptions(toolbar, clicked, loc, opts);
return opts;
}
protected virtual void CompileOptions(ToolbarGump toolbar, GumpButton clicked, Point loc, MenuGumpOptions opts)
{
if (toolbar == null)
{
return;
}
var user = toolbar.User;
if (CanEdit || user.AccessLevel >= Toolbars.Access)
{
if (!toolbar.GlobalEdit)
{
opts.AppendEntry(
new ListGumpEntry(
"Load Default",
b => SuperGump.Send(
new ConfirmDialogGump(user, toolbar)
{
Title = "Load Default",
Html = "Loading the default entry will overwrite your custom entry.\n\nDo you want to continue?",
AcceptHandler = db =>
{
var def = Toolbars.DefaultEntries.GetContent(loc.X, loc.Y);
toolbar.State.SetContent(loc.X, loc.Y, def != null ? def.Clone() : null);
toolbar.Refresh(true);
}
}),
toolbar.HighlightHue));
}
opts.AppendEntry(
new ListGumpEntry(
"Reset",
b =>
{
Reset(toolbar);
toolbar.Refresh(true);
},
toolbar.HighlightHue));
}
if (CanDelete || user.AccessLevel >= Toolbars.Access)
{
opts.AppendEntry(
new ListGumpEntry(
"Delete",
b =>
{
toolbar.State.SetContent(loc.X, loc.Y, null);
toolbar.Refresh(true);
},
toolbar.HighlightHue));
}
if (CanEdit || user.AccessLevel >= Toolbars.Access)
{
opts.AppendEntry(
new ListGumpEntry(
"Set Value",
b => SuperGump.Send(
new InputDialogGump(user, toolbar)
{
Title = "Set Value",
Html = "Set the value of this entry.",
InputText = Value,
Callback = (cb, text) =>
{
Value = text;
toolbar.Refresh(true);
}
}),
toolbar.HighlightHue));
opts.AppendEntry(
new ListGumpEntry(
"Set Label",
b => SuperGump.Send(
new InputDialogGump(user, toolbar)
{
Title = "Set Label",
Html = "Set the label of this entry.",
InputText = Label,
Callback = (cb, text) =>
{
Label = text;
toolbar.Refresh(true);
}
}),
toolbar.HighlightHue));
opts.AppendEntry(
new ListGumpEntry(
"Set Label Color",
b =>
{
int rrr = 255, ggg = 255, bbb = 255;
if (LabelColor != null)
{
rrr = LabelColor.Value.R;
ggg = LabelColor.Value.G;
bbb = LabelColor.Value.B;
}
SuperGump.Send(
new InputDialogGump(user, toolbar)
{
Title = "Set Label Color",
Html = "Set the label color for this entry.\nFormat 1: NamedColor (EG; Red)\nFormat 2: RRR,GGG,BBB",
InputText = String.Format("{0:D3},{1:D3},{2:D3}", rrr, ggg, bbb),
Callback = (cb, text) =>
{
if (!String.IsNullOrWhiteSpace(text))
{
if (text.IndexOf(',') != -1)
{
var args = text.Split(',');
if (args.Length >= 3)
{
Int32.TryParse(args[0], out rrr);
Int32.TryParse(args[1], out ggg);
Int32.TryParse(args[2], out bbb);
rrr = Math.Min(255, Math.Max(0, rrr));
ggg = Math.Min(255, Math.Max(0, ggg));
bbb = Math.Min(255, Math.Max(0, bbb));
LabelColor = Color.FromArgb(rrr, ggg, bbb);
}
}
else
{
try
{
LabelColor = Color.FromName(text);
}
catch
{ }
}
}
toolbar.Refresh(true);
}
});
},
toolbar.HighlightHue));
if (Highlight)
{
opts.Replace(
"Highlight",
new ListGumpEntry(
"Unhighlight",
b =>
{
Highlight = false;
toolbar.Refresh(true);
},
toolbar.ErrorHue));
}
else
{
opts.Replace(
"Unhighlight",
new ListGumpEntry(
"Highlight",
b =>
{
Highlight = true;
toolbar.Refresh(true);
},
toolbar.HighlightHue));
}
}
if (user.AccessLevel < Toolbars.Access)
{
return;
}
opts.AppendEntry(
new ListGumpEntry(
"Open Props",
b => SuperGump.Send(
new NoticeDialogGump(user, toolbar)
{
Title = "Props Note",
Html =
"Editing the properties of an entry this way requires a hard refresh.\nExit and re-open the Toolbar when you make any changes.",
AcceptHandler = cb =>
{
toolbar.Refresh(true);
var pg = new PropertiesGump(user, this)
{
X = b.X,
Y = b.Y
};
user.SendGump(pg);
}
}),
toolbar.HighlightHue));
if (toolbar.GlobalEdit && toolbar.CanGlobalEdit())
{
opts.AppendEntry(
new ListGumpEntry(
"Global Apply",
b => SuperGump.Send(
new ConfirmDialogGump(user, toolbar)
{
Title = "Global Apply",
Html =
"Applying this entry globally will overwrite any custom entries at the entry location on all existing toolbars.\n\nDo you want to continue?",
AcceptHandler = db =>
{
var def = Toolbars.DefaultEntries.GetContent(loc.X, loc.Y);
foreach (var tbs in Toolbars.Profiles.Values)
{
try
{
tbs.SetContent(loc.X, loc.Y, def != null ? def.Clone() : null);
var tb = tbs.GetToolbarGump();
if (tb != null && tb.IsOpen)
{
tb.Refresh(true);
}
}
catch
{ }
}
}
}),
toolbar.HighlightHue));
}
}
public virtual void Edit(ToolbarGump toolbar, Point loc, GumpButton clicked)
{
if (toolbar == null)
{
return;
}
var user = toolbar.State.User;
if (user == null || user.Deleted || user.NetState == null)
{
return;
}
if (CanEdit || user.AccessLevel >= Toolbars.Access)
{
SuperGump.Send(new MenuGump(user, toolbar.Refresh(), GetOptions(toolbar, clicked, loc), clicked));
}
}
public virtual void Reset(ToolbarGump state)
{
if (state == null)
{
return;
}
var user = state.User;
if (!CanEdit && user.AccessLevel < Toolbars.Access)
{
return;
}
Value = String.Empty;
Label = null;
LabelColor = null;
}
public virtual bool ValidateState(ToolbarState state)
{
return state != null && state.User != null && !state.User.Deleted;
}
public abstract void Invoke(ToolbarState state);
public override string ToString()
{
return FullValue;
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (Value != null ? Value.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Label != null ? Label.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ LabelColor.GetHashCode();
hashCode = (hashCode * 397) ^ CanEdit.GetHashCode();
hashCode = (hashCode * 397) ^ CanDelete.GetHashCode();
hashCode = (hashCode * 397) ^ Highlight.GetHashCode();
return hashCode;
}
}
public override bool Equals(object obj)
{
return obj is ToolbarEntry && Equals((ToolbarEntry)obj);
}
public bool Equals(ToolbarEntry other)
{
return !ReferenceEquals(other, null) && Value == other.Value && Label == other.Label &&
LabelColor == other.LabelColor && CanEdit == other.CanEdit && CanDelete == other.CanDelete &&
Highlight == other.Highlight;
}
public virtual void Serialize(GenericWriter writer)
{
var version = writer.SetVersion(0);
switch (version)
{
case 0:
{
writer.Write(Value);
writer.Write(Label);
writer.Write(CanDelete);
writer.Write(CanEdit);
writer.Write(Highlight);
if (LabelColor != null)
{
writer.Write(true);
writer.Write(LabelColor.Value.ToArgb());
}
else
{
writer.Write(false);
}
}
break;
}
}
public virtual void Deserialize(GenericReader reader)
{
var version = reader.GetVersion();
switch (version)
{
case 0:
{
Value = reader.ReadString();
Label = reader.ReadString();
CanDelete = reader.ReadBool();
CanEdit = reader.ReadBool();
Highlight = reader.ReadBool();
if (reader.ReadBool())
{
LabelColor = Color.FromArgb(reader.ReadInt());
}
}
break;
}
}
public static bool operator ==(ToolbarEntry l, ToolbarEntry r)
{
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
}
public static bool operator !=(ToolbarEntry l, ToolbarEntry r)
{
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
}
}
}

View File

@@ -0,0 +1,149 @@
#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;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.Toolbar
{
public class ToolbarLink : ToolbarEntry, IEquatable<ToolbarLink>
{
public ToolbarLink()
{ }
public ToolbarLink(
string url,
string label = null,
bool canDelete = true,
bool canEdit = true,
bool highlight = false,
Color? labelColor = null)
: base(url, label, canDelete, canEdit, highlight, labelColor)
{ }
public ToolbarLink(GenericReader reader)
: base(reader)
{ }
public override string GetDisplayLabel()
{
return "<u>" + base.GetDisplayLabel() + "</u>";
}
protected override void CompileOptions(ToolbarGump toolbar, GumpButton clicked, Point loc, MenuGumpOptions opts)
{
if (toolbar == null)
{
return;
}
base.CompileOptions(toolbar, clicked, loc, opts);
var user = toolbar.State.User;
if (!CanEdit && user.AccessLevel < Toolbars.Access)
{
return;
}
opts.Replace(
"Set Value",
new ListGumpEntry(
"Set URL",
b => new InputDialogGump(user, toolbar)
{
Title = "Set URL",
Html = "Set the URL for this Link entry.",
InputText = Value,
Callback = (cb, text) =>
{
Value = text;
toolbar.Refresh(true);
}
}.Send(),
toolbar.HighlightHue));
}
public override bool ValidateState(ToolbarState state)
{
return base.ValidateState(state) && !String.IsNullOrWhiteSpace(Value);
}
public override void Invoke(ToolbarState state)
{
if (state == null)
{
return;
}
var user = state.User;
if (user == null || user.Deleted || user.NetState == null)
{
return;
}
VitaNexCore.TryCatch(
() => user.LaunchBrowser(FullValue),
ex =>
{
Console.WriteLine("{0} => {1} => ({2}) => {3}", user, GetType().Name, FullValue, ex);
Toolbars.CMOptions.ToConsole(ex);
});
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is ToolbarLink && Equals((ToolbarLink)obj);
}
public bool Equals(ToolbarLink other)
{
return !ReferenceEquals(other, null) && base.Equals(other);
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.SetVersion(0);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
reader.GetVersion();
}
public static bool operator ==(ToolbarLink l, ToolbarLink r)
{
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
}
public static bool operator !=(ToolbarLink l, ToolbarLink r)
{
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
}
}
}

View File

@@ -0,0 +1,286 @@
#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;
using Server.Network;
using VitaNex.SuperGumps;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.Toolbar
{
public class ToolbarPhrase : ToolbarEntry, IEquatable<ToolbarPhrase>
{
[CommandProperty(Toolbars.Access)]
public virtual MessageType TextType { get; set; }
[CommandProperty(Toolbars.Access)]
public TimeSpan SpamDelay { get; set; }
public ToolbarPhrase()
{
SpamDelay = TimeSpan.FromSeconds(3.0);
TextType = MessageType.Regular;
}
public ToolbarPhrase(
string phrase,
string label = null,
bool canDelete = true,
bool canEdit = true,
bool highlight = false,
Color? labelColor = null,
MessageType type = MessageType.Regular)
: base(phrase, label, canDelete, canEdit, highlight, labelColor)
{
SpamDelay = TimeSpan.FromSeconds(3.0);
TextType = type;
}
public ToolbarPhrase(GenericReader reader)
: base(reader)
{ }
public override string GetDisplayLabel()
{
return "\"" + base.GetDisplayLabel() + "\"";
}
protected override void CompileOptions(ToolbarGump toolbar, GumpButton clicked, Point loc, MenuGumpOptions opts)
{
if (toolbar == null)
{
return;
}
base.CompileOptions(toolbar, clicked, loc, opts);
var user = toolbar.State.User;
if (!CanEdit && user.AccessLevel < Toolbars.Access)
{
return;
}
opts.AppendEntry(
new ListGumpEntry(
"Set Type",
b =>
{
var tOpts = new MenuGumpOptions();
if (TextType != MessageType.Regular)
{
tOpts.AppendEntry(
new ListGumpEntry(
"Regular",
tb =>
{
TextType = MessageType.Regular;
toolbar.Refresh(true);
}));
}
if (TextType != MessageType.Whisper)
{
tOpts.AppendEntry(
new ListGumpEntry(
"Whisper",
tb =>
{
TextType = MessageType.Whisper;
toolbar.Refresh(true);
}));
}
if (TextType != MessageType.Yell)
{
tOpts.AppendEntry(
new ListGumpEntry(
"Yell",
tb =>
{
TextType = MessageType.Yell;
toolbar.Refresh(true);
}));
}
SuperGump.Send(new MenuGump(user, clicked.Parent, tOpts, clicked));
},
toolbar.HighlightHue));
opts.Replace(
"Set Value",
new ListGumpEntry(
"Set Phrase",
b => SuperGump.Send(
new InputDialogGump(
user,
toolbar,
title: "Set Phrase",
html: "Set the text for this Phrase entry.",
input: Value,
callback: (cb, text) =>
{
Value = text;
toolbar.Refresh(true);
})),
toolbar.HighlightHue));
}
public override bool ValidateState(ToolbarState state)
{
return base.ValidateState(state) && !String.IsNullOrWhiteSpace(Value);
}
protected override void OnCloned(ToolbarEntry clone)
{
base.OnCloned(clone);
var phrase = clone as ToolbarPhrase;
if (phrase == null)
{
return;
}
phrase.SpamDelay = SpamDelay;
phrase.TextType = TextType;
}
public override void Invoke(ToolbarState state)
{
if (state == null)
{
return;
}
var user = state.User;
if (user == null || user.Deleted || user.NetState == null)
{
return;
}
VitaNexCore.TryCatch(
() =>
{
if (!user.BeginAction(this, SpamDelay))
{
return;
}
switch (TextType)
{
case MessageType.Whisper:
user.DoSpeech(FullValue, new int[0], TextType, user.WhisperHue);
break;
case MessageType.Yell:
user.DoSpeech(FullValue, new int[0], TextType, user.YellHue);
break;
default:
user.DoSpeech(FullValue, new int[0], TextType, user.SpeechHue);
break;
}
},
ex =>
{
Console.WriteLine("{0} => {1} => ({2}) => {3}", user, GetType().Name, FullValue, ex);
Toolbars.CMOptions.ToConsole(ex);
});
}
public override int GetHashCode()
{
unchecked
{
var hashCode = base.GetHashCode();
hashCode = (hashCode * 397) ^ (int)TextType;
hashCode = (hashCode * 397) ^ SpamDelay.GetHashCode();
return hashCode;
}
}
public override bool Equals(object obj)
{
return obj is ToolbarPhrase && Equals((ToolbarPhrase)obj);
}
public bool Equals(ToolbarPhrase other)
{
return !ReferenceEquals(other, null) && base.Equals(other) && TextType == other.TextType &&
SpamDelay == other.SpamDelay;
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
var version = writer.SetVersion(1);
switch (version)
{
case 1:
case 0:
{
writer.Write(SpamDelay);
if (version > 0)
{
writer.WriteFlag(TextType);
}
else
{
writer.Write((int)TextType);
}
}
break;
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
switch (version)
{
case 1:
case 0:
{
SpamDelay = reader.ReadTimeSpan();
var mt = version > 0 ? reader.ReadFlag<MessageType>() : (MessageType)reader.ReadInt();
TextType = mt;
}
break;
}
}
public static bool operator ==(ToolbarPhrase l, ToolbarPhrase r)
{
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
}
public static bool operator !=(ToolbarPhrase l, ToolbarPhrase r)
{
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
}
}
}

View File

@@ -0,0 +1,214 @@
#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;
using Server.Items;
using Server.Spells;
using VitaNex.SuperGumps;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.Toolbar
{
public class ToolbarSpell : ToolbarEntry, IEquatable<ToolbarSpell>
{
[CommandProperty(Toolbars.Access)]
public virtual int SpellID { get; set; }
public ToolbarSpell()
{
SpellID = -1;
}
public ToolbarSpell(
int spellID = -1,
string label = null,
bool canDelete = true,
bool canEdit = true,
bool highlight = false,
Color? labelColor = null)
: base(String.Empty, label, canDelete, canEdit, highlight, labelColor)
{
SpellID = spellID;
}
public ToolbarSpell(GenericReader reader)
: base(reader)
{ }
public override string GetDisplayLabel()
{
return "*" + base.GetDisplayLabel() + "*";
}
protected override void CompileOptions(ToolbarGump toolbar, GumpButton clicked, Point loc, MenuGumpOptions opts)
{
if (toolbar == null)
{
return;
}
base.CompileOptions(toolbar, clicked, loc, opts);
var user = toolbar.State.User;
if (CanEdit || user.AccessLevel >= Toolbars.Access)
{
opts.Replace(
"Set Value",
new ListGumpEntry(
"Set Spell",
b =>
{
toolbar.Refresh(true);
MenuGump menu1 = null;
var menuOpts1 = new MenuGumpOptions();
foreach (var kvp1 in SpellUtility.TreeStructure)
{
var circle = kvp1.Key;
var types = kvp1.Value;
menuOpts1.AppendEntry(
new ListGumpEntry(
circle,
b2 =>
{
var menuOpts2 = new MenuGumpOptions();
foreach (var kvp2 in types)
{
var id = SpellRegistry.GetRegistryNumber(kvp2.Key);
var si = kvp2.Value;
var book = Spellbook.Find(user, id);
if (book != null && book.HasSpell(id))
{
menuOpts2.AppendEntry(
new ListGumpEntry(
si.Name,
menu2Button =>
{
SpellID = id;
Value = si.Name;
Label = String.Empty;
toolbar.Refresh(true);
},
(SpellID == id) ? toolbar.HighlightHue : toolbar.TextHue));
}
}
if (menu1 != null)
{
SuperGump.Send(new MenuGump(user, clicked.Parent, menuOpts2, clicked));
}
}));
}
menu1 = new MenuGump(user, clicked.Parent, menuOpts1, clicked);
SuperGump.Send(menu1);
},
toolbar.HighlightHue));
}
}
protected override void OnCloned(ToolbarEntry clone)
{
base.OnCloned(clone);
var spell = clone as ToolbarSpell;
if (spell == null)
{
return;
}
spell.SpellID = SpellID;
}
public override void Invoke(ToolbarState state)
{
if (state == null || SpellID < 0 || SpellID >= SpellRegistry.Types.Length)
{
return;
}
var user = state.User;
if (user != null && !user.Deleted && user.NetState != null)
{
EventSink.InvokeCastSpellRequest(new CastSpellRequestEventArgs(user, SpellID, null));
}
}
public override int GetHashCode()
{
unchecked
{
return (base.GetHashCode() * 397) ^ SpellID;
}
}
public override bool Equals(object obj)
{
return obj is ToolbarSpell && Equals((ToolbarSpell)obj);
}
public bool Equals(ToolbarSpell other)
{
return !ReferenceEquals(other, null) && base.Equals(other) && SpellID == other.SpellID;
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
var version = writer.SetVersion(0);
switch (version)
{
case 0:
writer.Write(SpellID);
break;
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
switch (version)
{
case 0:
SpellID = reader.ReadInt();
break;
}
}
public static bool operator ==(ToolbarSpell l, ToolbarSpell r)
{
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
}
public static bool operator !=(ToolbarSpell l, ToolbarSpell r)
{
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
}
}
}

View File

@@ -0,0 +1,221 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System;
using Server;
using Server.Mobiles;
using VitaNex.SuperGumps;
#endregion
namespace VitaNex.Modules.Toolbar
{
public class ToolbarState : Grid<ToolbarEntry>
{
public static ToolbarState NewEmpty => new ToolbarState();
private SuperGump _ToolbarGump;
[CommandProperty(Toolbars.Access)]
public int X { get; set; }
[CommandProperty(Toolbars.Access)]
public int Y { get; set; }
[CommandProperty(Toolbars.Access)]
public PlayerMobile User { get; set; }
[CommandProperty(Toolbars.Access)]
public bool Minimized { get; set; }
[CommandProperty(Toolbars.Access)]
public ToolbarTheme Theme { get; set; }
private ToolbarState()
: this(
null,
Toolbars.CMOptions.DefaultX,
Toolbars.CMOptions.DefaultY,
Toolbars.CMOptions.DefaultWidth,
Toolbars.CMOptions.DefaultHeight,
Toolbars.CMOptions.DefaultTheme)
{ }
public ToolbarState(PlayerMobile user)
: this(
user,
Toolbars.CMOptions.DefaultX,
Toolbars.CMOptions.DefaultY,
Toolbars.CMOptions.DefaultWidth,
Toolbars.CMOptions.DefaultHeight,
Toolbars.CMOptions.DefaultTheme)
{ }
public ToolbarState(PlayerMobile user, int x, int y, int cols, int rows, ToolbarTheme theme)
: base(cols, rows)
{
User = user;
X = x;
Y = y;
Theme = theme;
if (User != null)
{
SetDefaultEntries();
}
}
public ToolbarState(GenericReader reader)
: base(reader)
{ }
public virtual void SetToolbarGump(SuperGump tb)
{
_ToolbarGump = tb;
}
public virtual SuperGump GetToolbarGump()
{
if (User == null || User.Deleted || User.NetState == null)
{
if (_ToolbarGump != null)
{
_ToolbarGump.Dispose();
}
return _ToolbarGump = null;
}
return _ToolbarGump == null || _ToolbarGump.IsDisposed ? (_ToolbarGump = new ToolbarGump(this)) : _ToolbarGump;
}
public void SetDefaults()
{
SetDefaultPosition();
SetDefaultSize();
SetDefaultTheme();
SetDefaultEntries();
}
public virtual void SetDefaultPosition()
{
X = Toolbars.CMOptions.DefaultX;
Y = Toolbars.CMOptions.DefaultY;
}
public virtual void SetDefaultSize()
{
Resize(Toolbars.CMOptions.DefaultWidth, Toolbars.CMOptions.DefaultHeight);
}
public virtual void SetDefaultTheme()
{
Theme = Toolbars.CMOptions.DefaultTheme;
}
public virtual void SetDefaultEntries()
{
SetDefaultSize();
if (this == Toolbars.DefaultEntries)
{
Toolbars.LoadDefaultEntries();
return;
}
for (var x = 0; x < Toolbars.DefaultEntries.Width; x++)
{
for (var y = 0; y < Toolbars.DefaultEntries.Height; y++)
{
var entry = Toolbars.DefaultEntries[x, y];
if (entry != null && entry.ValidateState(this))
{
SetContent(x, y, entry.Clone());
}
}
}
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
var version = writer.SetVersion(0);
switch (version)
{
case 0:
{
if (this == Toolbars.DefaultEntries)
{
writer.Write(false);
}
else
{
writer.Write(true);
writer.Write(User);
}
writer.Write(Minimized);
writer.Write(X);
writer.Write(Y);
writer.WriteFlag(Theme);
}
break;
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
var version = reader.GetVersion();
switch (version)
{
case 0:
{
if (reader.ReadBool())
{
User = reader.ReadMobile<PlayerMobile>();
}
Minimized = reader.ReadBool();
X = reader.ReadInt();
Y = reader.ReadInt();
Theme = reader.ReadFlag<ToolbarTheme>();
}
break;
}
}
public override void SerializeContent(GenericWriter writer, ToolbarEntry content, int x, int y)
{
writer.WriteType(
content,
t =>
{
if (t != null)
{
content.Serialize(writer);
}
});
}
public override ToolbarEntry DeserializeContent(GenericReader reader, Type type, int x, int y)
{
return reader.ReadTypeCreate<ToolbarEntry>(reader);
}
}
}

View File

@@ -0,0 +1,271 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System;
using Server;
using Server.Commands;
using Server.Mobiles;
using VitaNex.SuperGumps;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.Toolbar
{
public sealed class ToolbarsOptions : CoreModuleOptions
{
private int _DefaultX;
private int _DefaultY;
private int _DefaultHeight;
private int _DefaultWidth;
private string _PopupCommand;
private string _PositionCommand;
[CommandProperty(Toolbars.Access)]
public int DefaultX { get => _DefaultX; set => _DefaultX = Math.Max(0, value); }
[CommandProperty(Toolbars.Access)]
public int DefaultY { get => _DefaultY; set => _DefaultY = Math.Max(0, value); }
[CommandProperty(Toolbars.Access)]
public int DefaultWidth { get => _DefaultWidth; set => _DefaultWidth = Math.Max(1, value); }
[CommandProperty(Toolbars.Access)]
public int DefaultHeight { get => _DefaultHeight; set => _DefaultHeight = Math.Max(1, value); }
[CommandProperty(Toolbars.Access)]
public ToolbarTheme DefaultTheme { get; set; }
[CommandProperty(Toolbars.Access)]
public string PositionCommand
{
get => _PositionCommand;
set => CommandUtility.Replace(_PositionCommand, AccessLevel.Player, HandlePositionCommand, (_PositionCommand = value));
}
[CommandProperty(Toolbars.Access)]
public string PopupCommand
{
get => _PopupCommand;
set => CommandUtility.Replace(_PopupCommand, AccessLevel.Player, HandlePopupCommand, (_PopupCommand = value));
}
[CommandProperty(Toolbars.Access)]
public bool LoginPopup { get; set; }
[CommandProperty(Toolbars.Access)]
public AccessLevel Access { get; set; }
public ToolbarsOptions()
: base(typeof(Toolbars))
{
DefaultX = 0;
DefaultY = 28;
DefaultWidth = 6;
DefaultHeight = 4;
DefaultTheme = ToolbarTheme.Default;
PositionCommand = "ToolbarPos";
PopupCommand = "Toolbar";
LoginPopup = false;
Access = Toolbars.Access;
}
public ToolbarsOptions(GenericReader reader)
: base(reader)
{ }
public void HandlePositionCommand(CommandEventArgs e)
{
var user = e.Mobile as PlayerMobile;
if (user == null || user.Deleted || user.NetState == null || !ModuleEnabled)
{
return;
}
if (user.AccessLevel < Access)
{
if (user.AccessLevel > AccessLevel.Player)
{
user.SendMessage("You do not have access to that command.");
}
return;
}
var tb = Toolbars.EnsureState(user).GetToolbarGump();
SuperGump.Send(
new OffsetSelectorGump(
user,
tb.Refresh(true),
Toolbars.GetOffset(user),
(self, oldValue) =>
{
Toolbars.SetOffset(user, self.Value);
tb.X = self.Value.X;
tb.Y = self.Value.Y;
tb.Refresh(true);
}));
}
public void HandlePopupCommand(CommandEventArgs e)
{
var user = e.Mobile as PlayerMobile;
if (user == null || user.Deleted || user.NetState == null || !ModuleEnabled)
{
return;
}
if (user.AccessLevel < Access)
{
if (user.AccessLevel > AccessLevel.Player)
{
user.SendMessage("You do not have access to that command.");
}
return;
}
SuperGump.Send(Toolbars.EnsureState(user).GetToolbarGump());
}
public override void Clear()
{
base.Clear();
DefaultX = 0;
DefaultY = 28;
DefaultWidth = 1;
DefaultHeight = 1;
DefaultTheme = ToolbarTheme.Default;
PositionCommand = null;
PopupCommand = null;
LoginPopup = false;
Access = Toolbars.Access;
}
public override void Reset()
{
base.Reset();
DefaultX = 0;
DefaultY = 28;
DefaultWidth = 6;
DefaultHeight = 4;
DefaultTheme = ToolbarTheme.Default;
PositionCommand = "ToolbarPos";
PopupCommand = "Toolbar";
LoginPopup = false;
Access = Toolbars.Access;
}
public override string ToString()
{
return "Toolbars Config";
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
var version = writer.SetVersion(2);
switch (version)
{
case 2:
{
writer.WriteFlag(DefaultTheme);
writer.Write(DefaultX);
writer.Write(DefaultY);
}
goto case 1;
case 1:
{
writer.WriteFlag(Access);
writer.Write(LoginPopup);
}
goto case 0;
case 0:
{
writer.Write(DefaultWidth);
writer.Write(DefaultHeight);
writer.Write(PositionCommand);
writer.Write(PopupCommand);
writer.WriteBlock(Toolbars.DefaultEntries.Serialize);
}
break;
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
var version = reader.GetVersion();
switch (version)
{
case 2:
{
DefaultTheme = reader.ReadFlag<ToolbarTheme>();
DefaultX = reader.ReadInt();
DefaultY = reader.ReadInt();
}
goto case 1;
case 1:
{
Access = reader.ReadFlag<AccessLevel>();
LoginPopup = reader.ReadBool();
}
goto case 0;
case 0:
{
DefaultWidth = reader.ReadInt();
DefaultHeight = reader.ReadInt();
PositionCommand = reader.ReadString();
PopupCommand = reader.ReadString();
reader.ReadBlock(Toolbars.DefaultEntries.Deserialize);
}
break;
}
if (version < 2)
{
DefaultTheme = ToolbarTheme.Default;
DefaultX = 0;
DefaultY = 28;
}
if (version < 1)
{
Access = Toolbars.Access;
}
}
}
}

View File

@@ -0,0 +1,116 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System.Drawing;
#endregion
namespace VitaNex.Modules.Toolbar
{
public enum ToolbarTheme
{
Default = 0,
Paper,
Stone
}
public static class ToolbarThemes
{
public static ToolbarThemeBase GetTheme(ToolbarTheme theme)
{
switch (theme)
{
case ToolbarTheme.Paper:
return ToolbarThemePaper.Instance;
case ToolbarTheme.Stone:
return ToolbarThemeStone.Instance;
default:
return ToolbarThemeDefault.Instance;
}
}
}
public abstract class ToolbarThemeBase
{
public abstract ToolbarTheme ThemeID { get; }
public abstract string Name { get; }
public abstract Color TitleLabelColor { get; }
public abstract int TitleBackground { get; }
public abstract int EntrySeparator { get; }
public abstract int EntryBackgroundN { get; }
public abstract Color EntryLabelColorN { get; }
public abstract int EntryBackgroundH { get; }
public abstract Color EntryLabelColorH { get; }
public abstract int EntryOptionsN { get; }
public abstract int EntryOptionsP { get; }
}
public sealed class ToolbarThemeDefault : ToolbarThemeBase
{
private static readonly ToolbarThemeDefault _Instance = new ToolbarThemeDefault();
public static ToolbarThemeDefault Instance => _Instance;
public override ToolbarTheme ThemeID => ToolbarTheme.Default;
public override string Name => "Default";
public override int TitleBackground => 9274;
public override Color TitleLabelColor => Color.Gold;
public override int EntrySeparator => 9790;
public override int EntryBackgroundN => 9274;
public override Color EntryLabelColorN => Color.Gold;
public override int EntryBackgroundH => 9204;
public override Color EntryLabelColorH => Color.LightBlue;
public override int EntryOptionsN => 9791;
public override int EntryOptionsP => 9790;
}
public sealed class ToolbarThemePaper : ToolbarThemeBase
{
private static readonly ToolbarThemePaper _Instance = new ToolbarThemePaper();
public static ToolbarThemePaper Instance => _Instance;
public override ToolbarTheme ThemeID => ToolbarTheme.Paper;
public override string Name => "Paper";
public override int TitleBackground => 9394;
public override Color TitleLabelColor => Color.DarkSlateGray;
public override int EntrySeparator => 11340;
public override int EntryBackgroundN => 9394;
public override Color EntryLabelColorN => Color.DarkSlateGray;
public override int EntryBackgroundH => 9384;
public override Color EntryLabelColorH => Color.Chocolate;
public override int EntryOptionsN => 11350;
public override int EntryOptionsP => 11340;
}
public sealed class ToolbarThemeStone : ToolbarThemeBase
{
private static readonly ToolbarThemeStone _Instance = new ToolbarThemeStone();
public static ToolbarThemeStone Instance => _Instance;
public override ToolbarTheme ThemeID => ToolbarTheme.Stone;
public override string Name => "Stone";
public override int TitleBackground => 5124;
public override Color TitleLabelColor => Color.GhostWhite;
public override int EntrySeparator => 11340;
public override int EntryBackgroundN => 5124;
public override Color EntryLabelColorN => Color.GhostWhite;
public override int EntryBackgroundH => 9204;
public override Color EntryLabelColorH => Color.Cyan;
public override int EntryOptionsN => 11374;
public override int EntryOptionsP => 11340;
}
}

View File

@@ -0,0 +1,245 @@
#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.Mobiles;
using VitaNex.IO;
using VitaNex.SuperGumps;
#endregion
namespace VitaNex.Modules.Toolbar
{
public static partial class Toolbars
{
public const AccessLevel Access = AccessLevel.Administrator;
public static Type[] EntryTypes { get; private set; }
public static ToolbarsOptions CMOptions { get; private set; }
public static BinaryDataStore<PlayerMobile, ToolbarState> Profiles { get; private set; }
public static ToolbarState DefaultEntries { get; set; }
public static Action LoadDefaultEntries { get; set; }
public static Action ClearDefaultEntries { get; set; }
public static void RegisterEntry(int x, int y, ToolbarEntry entry)
{
DefaultEntries.SetContent(x, y, entry);
}
private static void ClearDefaults()
{
DefaultEntries = ToolbarState.NewEmpty;
}
private static void LoadDefaults()
{
ClearDefaults();
RegisterEntry(0, 0, new ToolbarLink("http://core.vita-nex.com", "VitaNexCore", true, true, true));
RegisterEntry(1, 0, new ToolbarCommand("MyCommands", "Command List"));
RegisterEntry(2, 0, new ToolbarCommand("Pages", "View Pages", minAccess: AccessLevel.Counselor));
RegisterEntry(3, 0, new ToolbarCommand("Go", "Go To...", minAccess: AccessLevel.Counselor));
RegisterEntry(4, 0, new ToolbarCommand("Who", "Online List", minAccess: AccessLevel.Counselor));
RegisterEntry(5, 0, new ToolbarCommand("Where", minAccess: AccessLevel.Counselor));
RegisterEntry(0, 1, new ToolbarCommand("Self", "Hide", minAccess: AccessLevel.Counselor, args: "Hide"));
RegisterEntry(1, 1, new ToolbarCommand("Self", "Unhide", minAccess: AccessLevel.Counselor, args: "Unhide"));
RegisterEntry(2, 1, new ToolbarCommand("Tele", "Teleport", minAccess: AccessLevel.Counselor));
RegisterEntry(3, 1, new ToolbarCommand("M", "Multi Teleport", minAccess: AccessLevel.Counselor, args: "Tele"));
RegisterEntry(4, 1, new ToolbarCommand("Remove", minAccess: AccessLevel.GameMaster));
RegisterEntry(5, 1, new ToolbarCommand("M", "Multi Remove", minAccess: AccessLevel.GameMaster, args: "Remove"));
RegisterEntry(0, 2, new ToolbarCommand("Props", "Properties", minAccess: AccessLevel.Counselor));
RegisterEntry(1, 2, new ToolbarCommand("Kill", minAccess: AccessLevel.GameMaster));
RegisterEntry(2, 2, new ToolbarCommand("Admin", "Admin Panel", minAccess: AccessLevel.Administrator));
}
public static void OpenAll()
{
foreach (var p in Profiles.Where(
p => p.Key != null && p.Value != null && p.Key.IsOnline() && p.Key.AccessLevel >= CMOptions.Access))
{
VitaNexCore.TryCatch(() => p.Value.GetToolbarGump().Send(), CMOptions.ToConsole);
}
}
public static void CloseAll()
{
foreach (var p in Profiles.Where(p => p.Key != null && p.Value != null && p.Key.IsOnline()))
{
VitaNexCore.TryCatch(() => p.Value.GetToolbarGump().Close(true), CMOptions.ToConsole);
}
}
private static void OnLogin(LoginEventArgs e)
{
var user = e.Mobile as PlayerMobile;
if (user != null && !user.Deleted && user.NetState != null && user.AccessLevel >= CMOptions.Access &&
CMOptions.LoginPopup)
{
SuperGump.Send(EnsureState(user).GetToolbarGump());
}
}
public static Point GetOffset(PlayerMobile user)
{
var loc = new Point(0, 28);
if (user == null || user.Deleted)
{
return loc;
}
if (Profiles.ContainsKey(user))
{
loc = new Point(Profiles[user].X, Profiles[user].Y);
}
return loc;
}
public static void SetOffset(PlayerMobile user, Point loc)
{
if (user == null || user.Deleted || !Profiles.ContainsKey(user))
{
return;
}
Profiles[user].X = loc.X;
Profiles[user].Y = loc.Y;
}
public static void SetGlobalPosition()
{
VitaNexCore.TryCatch(
() => Profiles.Values.ForEach(
state => VitaNexCore.TryCatch(
() =>
{
state.SetDefaultPosition();
var tb = state.GetToolbarGump();
if (tb != null && tb.IsOpen)
{
tb.Refresh(true);
}
},
CMOptions.ToConsole)),
CMOptions.ToConsole);
}
public static void SetGlobalSize()
{
VitaNexCore.TryCatch(
() => Profiles.Values.ForEach(
state => VitaNexCore.TryCatch(
() =>
{
state.SetDefaultSize();
var tb = state.GetToolbarGump();
if (tb != null && tb.IsOpen)
{
tb.Refresh(true);
}
},
CMOptions.ToConsole)),
CMOptions.ToConsole);
}
public static void SetGlobalTheme()
{
VitaNexCore.TryCatch(
() => Profiles.Values.ForEach(
state => VitaNexCore.TryCatch(
() =>
{
state.SetDefaultTheme();
var tb = state.GetToolbarGump();
if (tb != null && tb.IsOpen)
{
tb.Refresh(true);
}
},
CMOptions.ToConsole)),
CMOptions.ToConsole);
}
public static void SetGlobalEntries()
{
VitaNexCore.TryCatch(
() => Profiles.Values.ForEach(
state => VitaNexCore.TryCatch(
() =>
{
state.SetDefaultEntries();
var tb = state.GetToolbarGump();
if (tb != null && tb.IsOpen)
{
tb.Refresh(true);
}
},
CMOptions.ToConsole)),
CMOptions.ToConsole);
}
public static void SetGlobalDefaults()
{
VitaNexCore.TryCatch(
() => Profiles.Values.ForEach(
state => VitaNexCore.TryCatch(
() =>
{
state.SetDefaults();
var tb = state.GetToolbarGump();
if (tb != null && tb.IsOpen)
{
tb.Refresh(true);
}
},
CMOptions.ToConsole)),
CMOptions.ToConsole);
}
public static ToolbarState EnsureState(PlayerMobile user)
{
if (user == null)
{
return null;
}
if (!Profiles.TryGetValue(user, out var state) || state == null)
{
Profiles[user] = state = new ToolbarState(user);
}
return state;
}
}
}

View File

@@ -0,0 +1,166 @@
#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.Mobiles;
using VitaNex.IO;
#endregion
namespace VitaNex.Modules.Toolbar
{
[CoreModule("Toolbars", "1.0.0.1")]
public static partial class Toolbars
{
static Toolbars()
{
EntryTypes = typeof(ToolbarEntry).GetConstructableChildren();
CMOptions = new ToolbarsOptions();
Profiles = new BinaryDataStore<PlayerMobile, ToolbarState>(VitaNexCore.SavesDirectory + "/Toolbars", "States")
{
Async = true,
OnSerialize = Serialize,
OnDeserialize = Deserialize
};
DefaultEntries = ToolbarState.NewEmpty;
}
private static void CMConfig()
{
EventSink.Login += OnLogin;
LoadDefaultEntries = LoadDefaults;
ClearDefaultEntries = ClearDefaults;
}
private static void CMEnabled()
{
EventSink.Login += OnLogin;
CommandUtility.Register(CMOptions.PopupCommand, AccessLevel.Player, CMOptions.HandlePopupCommand);
CommandUtility.Register(CMOptions.PositionCommand, AccessLevel.Player, CMOptions.HandlePositionCommand);
if (CMOptions.LoginPopup)
{
OpenAll();
}
}
private static void CMDisabled()
{
EventSink.Login -= OnLogin;
CommandUtility.Unregister(CMOptions.PopupCommand);
CommandUtility.Unregister(CMOptions.PositionCommand);
CloseAll();
}
private static void CMSave()
{
VitaNexCore.TryCatch(
() =>
{
var result = Profiles.Export();
CMOptions.ToConsole("{0} profiles saved, {1}", Profiles.Count > 0 ? Profiles.Count.ToString("#,#") : "0", result);
},
CMOptions.ToConsole);
}
private static void CMLoad()
{
VitaNexCore.TryCatch(
() =>
{
var result = Profiles.Import();
CMOptions.ToConsole(
"{0} profiles loaded, {1}.",
Profiles.Count > 0 ? Profiles.Count.ToString("#,#") : "0",
result);
},
CMOptions.ToConsole);
}
public static bool Serialize(GenericWriter writer)
{
var version = writer.SetVersion(0);
switch (version)
{
case 0:
{
if (DefaultEntries == null)
{
writer.Write(false);
}
else
{
writer.Write(true);
DefaultEntries.Serialize(writer);
}
writer.WriteBlockDictionary(
Profiles,
(w, k, v) =>
{
w.Write(k);
v.Serialize(w);
});
}
break;
}
return true;
}
public static bool Deserialize(GenericReader reader)
{
var version = reader.GetVersion();
switch (version)
{
case 0:
{
if (reader.ReadBool())
{
if (DefaultEntries != null)
{
DefaultEntries.Deserialize(reader);
}
else
{
DefaultEntries = new ToolbarState(reader);
}
}
reader.ReadBlockDictionary(
r =>
{
var k = r.ReadMobile<PlayerMobile>();
var v = new ToolbarState(r);
return new KeyValuePair<PlayerMobile, ToolbarState>(k, v);
},
Profiles);
}
break;
}
return true;
}
}
}

View File

@@ -0,0 +1,577 @@
#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.Gumps;
using Server.Mobiles;
using VitaNex.SuperGumps;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.Toolbar
{
public class ToolbarGump : ListGump<ToolbarEntry>
{
public static string DefaultToolbarTitle = "Toolbar";
public ToolbarState State { get; protected set; }
public bool GlobalEdit { get; protected set; }
public ToolbarThemeBase Theme { get; set; }
public Color HeaderColor { get; set; }
public override bool Minimized
{
get => State != null ? State.Minimized : base.Minimized;
set
{
if (State != null)
{
State.Minimized = value;
}
base.Minimized = value;
}
}
public ToolbarGump(ToolbarState state, Color? headerColor = null, ToolbarTheme theme = ToolbarTheme.Default)
: base(state.User, null, state.X, state.Y, null, null, DefaultToolbarTitle)
{
State = state;
HeaderColor = headerColor ?? Color.DarkBlue;
GlobalEdit = false;
Theme = ToolbarThemes.GetTheme(theme);
CanSearch = false;
CanMove = false;
CanDispose = false;
CanClose = false;
CanResize = false;
}
public virtual bool CanGlobalEdit()
{
return (User is PlayerMobile && User.AccessLevel >= Toolbars.Access &&
(Toolbars.DefaultEntries.User == User || Toolbars.DefaultEntries.User == null));
}
public virtual void BeginGlobalEdit()
{
if (CanGlobalEdit())
{
if (!GlobalEdit || State != Toolbars.DefaultEntries)
{
GlobalEdit = true;
State = Toolbars.DefaultEntries;
State.User = User as PlayerMobile;
}
Refresh(true);
}
else
{
EndGlobalEdit();
}
}
public virtual void EndGlobalEdit()
{
if (State == Toolbars.DefaultEntries)
{
State.User = null;
State = Toolbars.EnsureState(User as PlayerMobile);
}
GlobalEdit = false;
Refresh(true);
}
protected virtual void ShowPositionSelect(GumpButton b)
{
if (!(User is PlayerMobile))
{
return;
}
var user = (PlayerMobile)User;
new OffsetSelectorGump(
user,
Refresh(true),
Toolbars.GetOffset(user),
(self, oldValue) =>
{
Toolbars.SetOffset(user, self.Value);
X = self.Value.X;
Y = self.Value.Y;
Refresh(true);
}).Send();
}
public override SuperGump Refresh(bool recompile)
{
if (!CanGlobalEdit())
{
GlobalEdit = false;
}
return base.Refresh(recompile);
}
protected override void SelectEntry(GumpButton button, ToolbarEntry entry)
{
base.SelectEntry(button, entry);
if (entry != null && entry.ValidateState(State))
{
entry.Invoke(State);
}
Refresh();
}
protected virtual void SelectEntryMenu(GumpButton button, Point loc, ToolbarEntry entry)
{
if (entry != null)
{
entry.Edit(this, loc, button);
}
else
{
var opts = new MenuGumpOptions();
if (!GlobalEdit)
{
opts.AppendEntry(
"Load Default",
b => new ConfirmDialogGump(User, this)
{
Title = "Load Default",
Html = "Loading the default entry will overwrite your custom entry.\n\nDo you want to continue?",
AcceptHandler = db =>
{
var def = Toolbars.DefaultEntries.GetContent(loc.X, loc.Y);
State.SetContent(loc.X, loc.Y, def != null ? def.Clone() : null);
Refresh(true);
}
}.Send(),
HighlightHue);
}
foreach (var eType in Toolbars.EntryTypes)
{
var eName = "New " + eType.Name.Replace("Toolbar", String.Empty);
var type = eType;
opts.AppendEntry(
eName,
b =>
{
State.SetContent(loc.X, loc.Y, CreateToolbarEntry(type));
Refresh(true);
},
HighlightHue);
}
new MenuGump(User, this, opts, button).Send();
}
}
protected virtual ToolbarEntry CreateToolbarEntry(Type type)
{
return type.CreateInstanceSafe<ToolbarEntry>();
}
protected override void Compile()
{
Theme = ToolbarThemes.GetTheme(State.Theme);
base.Compile();
}
protected override void CompileMenuOptions(MenuGumpOptions list)
{
list.Clear();
if (CanGlobalEdit())
{
if (GlobalEdit)
{
list.AppendEntry("End Global Edit", b => EndGlobalEdit(), ErrorHue);
list.AppendEntry("Edit Defaults", b => User.SendGump(new PropertiesGump(User, Toolbars.CMOptions)), HighlightHue);
list.AppendEntry(
"Reset Global Entries",
b => new ConfirmDialogGump(User, this)
{
Title = "Reset Global Entries",
Html = "Applying global defaults will copy the global toolbar to all existing toolbars.\n" +
"This will overwrite any custom entries that exist.\n\nDo you want to continue?",
AcceptHandler = db =>
{
Toolbars.SetGlobalEntries();
Refresh(true);
}
}.Send(),
HighlightHue);
list.AppendEntry(
"Reset Global Themes",
b => new ConfirmDialogGump(User, this)
{
Title = "Reset Global Themes",
Html = "Applying global theme will reset the theme of all existing toolbars.\n\n" + //
"Do you want to continue?",
AcceptHandler = db =>
{
Toolbars.SetGlobalTheme();
Refresh(true);
}
}.Send(),
HighlightHue);
list.AppendEntry(
"Reset Global Positions",
b => new ConfirmDialogGump(
User,
this,
title: "Reset Global Positions",
html: "Applying global position will reset the position of all existing toolbars.\n\n" + //
"Do you want to continue?",
onAccept: db =>
{
Toolbars.SetGlobalPosition();
Refresh(true);
}).Send(),
HighlightHue);
list.AppendEntry(
"Reset Global Sizes",
b => new ConfirmDialogGump(User, this)
{
Title = "Reset Global Sizes",
Html = "Applying global size will reset the size of all existing toolbars.\n" +
"Any entries located beyond the new size will be lost.\n\n" + //
"Do you want to continue?",
AcceptHandler = db =>
{
Toolbars.SetGlobalSize();
Refresh(true);
}
}.Send(),
HighlightHue);
}
else
{
list.AppendEntry("Begin Global Edit", b => BeginGlobalEdit(), HighlightHue);
}
}
list.AppendEntry(
"Load Defaults",
b => new ConfirmDialogGump(User, this)
{
Title = "Load Defaults",
Html = "Loadng defaults will overwrite any custom entries that exist in your toolbar.\n\n" + //
"Do you want to continue?",
AcceptHandler = db =>
{
State.SetDefaultEntries();
Refresh(true);
}
}.Send(),
HighlightHue);
list.AppendEntry(
"Set Position",
b => new OffsetSelectorGump(
User,
this,
new Point(State.X, State.Y),
(self, oldValue) =>
{
X = State.X = self.Value.X;
Y = State.Y = self.Value.Y;
Refresh(true);
}).Send(),
HighlightHue);
list.AppendEntry(
"Set Size",
b =>
{
var html = String.Format(
"Set the size for your toolbar.\nFormat: Width,Height\nWidth Range: {0}\nHeight Range: {1}\n\nIf you shrink the size, any entires located beyond the new size will be lost.",
String.Format("{0}-{1}", Toolbars.CMOptions.DefaultWidth, Toolbars.DefaultEntries.Width),
String.Format("{0}-{1}", Toolbars.CMOptions.DefaultHeight, Toolbars.DefaultEntries.Height));
new InputDialogGump(User, this)
{
Title = "Set Size",
Html = html,
InputText = String.Format("{0},{1}", State.Width, State.Height),
Callback = (cb, text) =>
{
int w = State.Width, h = State.Height;
if (text.IndexOf(",", StringComparison.Ordinal) != -1)
{
var split = text.Split(',');
if (split.Length >= 2)
{
if (Int32.TryParse(split[0], out w))
{
if (w < Toolbars.CMOptions.DefaultWidth)
{
w = Toolbars.CMOptions.DefaultWidth;
}
else if (!GlobalEdit && w > Toolbars.DefaultEntries.Width)
{
w = Toolbars.DefaultEntries.Width;
}
}
else
{
w = State.Width;
}
if (Int32.TryParse(split[1], out h))
{
if (h < Toolbars.CMOptions.DefaultHeight)
{
h = Toolbars.CMOptions.DefaultHeight;
}
else if (!GlobalEdit && h > Toolbars.DefaultEntries.Height)
{
h = Toolbars.DefaultEntries.Height;
}
}
else
{
h = State.Height;
}
}
}
State.Resize(w, h);
Refresh(true);
}
}.Send();
},
HighlightHue);
list.AppendEntry(
"Set Theme",
b =>
{
var opts = new MenuGumpOptions();
var themes = default(ToolbarTheme).EnumerateValues<ToolbarTheme>(false);
foreach (var themeID in themes)
{
if (State.Theme == themeID)
{
continue;
}
var id = themeID;
var theme = ToolbarThemes.GetTheme(themeID);
opts.AppendEntry(
theme.Name,
tb =>
{
State.Theme = id;
Refresh(true);
},
HighlightHue);
}
new MenuGump(User, this, opts, b).Send();
},
HighlightHue);
base.CompileMenuOptions(list);
list.RemoveEntry("New Search");
list.RemoveEntry("Clear Search");
list.Replace("Refresh", "Exit", b => Close(b));
}
protected override string GetLabelText(int index, int pageIndex, ToolbarEntry entry)
{
string label;
if (entry != null)
{
var labelColor = (entry.LabelColor ?? (entry.Highlight ? Theme.EntryLabelColorH : Theme.EntryLabelColorN));
label = String.Format("<basefont color=#{0:X6}><center>{1}</center>", labelColor.ToRgb(), entry.GetDisplayLabel());
}
else
{
label = String.Format("<basefont color=#{0:X6}><center>{1}</center>", Theme.EntryLabelColorN.ToRgb(), "*Unused*");
}
return label;
}
protected override void CompileList(List<ToolbarEntry> list)
{
list.Clear();
list.AddRange(State.GetCells());
base.CompileList(list);
EntriesPerPage = list.Count;
}
public override string GetSearchKeyFor(ToolbarEntry key)
{
if (key == null)
{
return base.GetSearchKeyFor(null);
}
if (!String.IsNullOrWhiteSpace(key.Label))
{
return key.Label;
}
return key.Value;
}
protected override void CompileLayout(SuperGumpLayout layout)
{
layout.Replace(
"button/header/minmax",
() =>
{
if (Minimized)
{
AddButton(0, 0, 2328, 2329, Maximize);
AddTooltip(3002086);
}
else
{
AddButton(0, 0, 2328, 2329, Minimize);
AddTooltip(3002085);
}
});
layout.Add("imagetiled/header/base", () => AddImageTiled(0, 0, 84, 56, Theme.TitleBackground));
layout.Replace(
"html/header/title",
() => AddHtml(
0,
0,
84,
56,
String.Format(
"<basefont color=#{0:X6}><center><big>{1}</big></center>",
Theme.TitleLabelColor.ToRgb(),
String.Format(
"{0} {1}",
String.IsNullOrWhiteSpace(Title) ? DefaultTitle : Title,
GlobalEdit ? "[GLOBAL]" : String.Empty)),
false,
false));
layout.Replace(
"button/header/options",
() =>
{
AddButton(84, 0, Theme.EntryOptionsN, Theme.EntryOptionsP, ShowPositionSelect);
AddButton(84, 28, Theme.EntryOptionsN, Theme.EntryOptionsP, ShowOptionMenu);
});
if (Minimized)
{
return;
}
var ec = IsEnhancedClient;
var index = 0;
State.ForEach(
(x, y, entry) =>
{
var idx = index;
var loc = new Point(x, y);
if (ec)
{
layout.Add("ec/1/" + idx, AddInputEC);
}
layout.Add(
"button1/entry/" + idx,
() => AddButton(110 + (loc.X * 130), (loc.Y * 28), 2445, 2445, b => SelectEntry(b, entry)));
layout.Add(
"imagetiled/entry/" + idx,
() =>
{
AddImageTiled(
106 + (loc.X * 130),
(loc.Y * 28),
112,
28,
(entry != null && entry.Highlight) ? Theme.EntryBackgroundH : Theme.EntryBackgroundN);
AddImageTiled(106 + (loc.X * 130) + 112, (loc.Y * 28), 18, 28, Theme.EntrySeparator);
});
layout.Add(
"html/entry/" + idx,
() => AddHtml(
106 + (loc.X * 130) + 3,
(loc.Y * 28) + 3,
112 - 6,
28 - 6,
GetLabelText(idx, idx, entry),
false,
false));
layout.Add(
"button2/entry/" + idx,
() => AddButton(
106 + (loc.X * 130) + 112,
(loc.Y * 28),
Theme.EntryOptionsN,
Theme.EntryOptionsP,
b =>
{
Refresh();
SelectEntryMenu(b, loc, entry);
}));
if (ec)
{
layout.Add("ec/2/" + idx, AddInputEC);
}
index++;
});
}
}
}