diff --git a/Content.Client/UserInterface/Controls/DialogWindow.xaml.cs b/Content.Client/UserInterface/Controls/DialogWindow.xaml.cs index f50aca581b..41c6e4ba1b 100644 --- a/Content.Client/UserInterface/Controls/DialogWindow.xaml.cs +++ b/Content.Client/UserInterface/Controls/DialogWindow.xaml.cs @@ -2,6 +2,9 @@ using Content.Shared.Administration; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Sandboxing; +using Robust.Client.UserInterface; +using System.Linq; namespace Content.Client.UserInterface.Controls; @@ -31,7 +34,9 @@ public sealed partial class DialogWindow : FancyWindow /// private bool _finished; - private List<(string, LineEdit)> _promptLines; + private List<(string, Func)> _promptLines; + + private delegate (Control, Func) ControlConstructor(Func verifier, string name, QuickDialogEntry entry, bool last);// are you feeling it now mr krabs? /// /// Create and open a new dialog with some prompts. @@ -61,29 +66,38 @@ public sealed partial class DialogWindow : FancyWindow var box = new BoxContainer(); box.AddChild(new Label() { Text = entry.Prompt, HorizontalExpand = true, SizeFlagsStretchRatio = 0.5f }); - var edit = new LineEdit() { HorizontalExpand = true }; + //var edit = new LineEdit() { HorizontalExpand = true }; - (Func, string) pair = entry.Type switch + + // walkthrough: + // second item in this tuple is a verifier function for controls who have that option + // third item is a backup name in case we have not been provided with one from the server + // first item is a function that takes the other two, the QuickDialogEntry for it, a bool of whether it's the last control in the window, + // and returns another tuple: + // item 1 is the control itself + // item 2 is a Func, a """generic""" function that returns whatever user has done with the control + (ControlConstructor, Func?, string) notapairanymore = entry.Type switch { - QuickDialogEntryType.Integer => (VerifyInt, "integer"), - QuickDialogEntryType.Float => (VerifyFloat, "float"), - QuickDialogEntryType.ShortText => (VerifyShortText, "short-text"), - QuickDialogEntryType.LongText => (VerifyLongText, "long-text"), + QuickDialogEntryType.Integer => (SetupLineEditNumber, VerifyInt, "integer"), + QuickDialogEntryType.Float => (SetupLineEditNumber, VerifyFloat, "float"), + QuickDialogEntryType.ShortText => (SetupLineEdit, VerifyShortText, "short-text"), + QuickDialogEntryType.LongText => (SetupLineEdit, VerifyLongText, "long-text"), + QuickDialogEntryType.Hex16 => (SetupLineEditHex, VerifyHex16, "hex16"), + QuickDialogEntryType.Boolean => (SetupCheckBox, null, "boolean"), + QuickDialogEntryType.Void => (SetupVoid, null, "void"), + _ => throw new ArgumentOutOfRangeException() }; - var (valid, name) = pair; + var (setup, valid, name) = notapairanymore; - edit.IsValid += valid; - // try use placeholder from the caller, fall back to the generic one for whatever type is being validated. - edit.PlaceHolder = entry.Placeholder ?? Loc.GetString($"quick-dialog-ui-{name}"); - // Last text box gets enter confirmation. - // Only the last so you don't accidentally confirm early. - if (i == entries.Count - 1) - edit.OnTextEntered += _ => Confirm(); + var (control, returner) = setup(valid!, entry.Placeholder ?? Loc.GetString($"quick-dialog-ui-{name}"), entry, i == entries.Count - 1); // ARE YOU FEELING IT NOW MR KRABS? + // yes, valid can be null + // yes, i am just going to ignore that + // go fuck yourself + _promptLines.Add((entry.FieldId, returner)); - _promptLines.Add((entry.FieldId, edit)); - box.AddChild(edit); + box.AddChild(control); Prompts.AddChild(box); } @@ -110,9 +124,9 @@ public sealed partial class DialogWindow : FancyWindow private void Confirm() { var results = new Dictionary(); - foreach (var (field, edit) in _promptLines) + foreach (var (field, returner) in _promptLines) { - results[field] = edit.Text; + results[field] = returner(); } _finished = true; @@ -143,5 +157,57 @@ public sealed partial class DialogWindow : FancyWindow return input.Length <= 2000; } + private bool VerifyHex16(string input) + { + return input.Length <= 4 && int.TryParse(input, System.Globalization.NumberStyles.HexNumber, null, out int _); + } + + + + + private (Control, Func) SetupLineEdit(Func valid, string name, QuickDialogEntry entry, bool last) // oh shit i'm feeling it + { + var edit = new LineEdit() { HorizontalExpand = true }; + edit.IsValid += valid; + // try use placeholder from the caller, fall back to the generic one for whatever type is being validated. + edit.PlaceHolder = name; + // Last text box gets enter confirmation. + // Only the last so you don't accidentally confirm early. + if (last) + edit.OnTextEntered += _ => Confirm(); + + return (edit, () => {return edit.Text;} ); + } + private (Control, Func) SetupLineEditNumber(Func valid, string name, QuickDialogEntry entry, bool last) + { + var (control, returner) = SetupLineEdit(valid, name, entry, last); + var le = (LineEdit) control; + le.Text = "0"; + return (control, ()=> le.Text.Length > 0 ? le.Text : "0"); // Otherwise you'll get kicked for malformed data + } + private (Control, Func) SetupLineEditHex(Func valid, string name, QuickDialogEntry entry, bool last) + { + var (control, returner) = SetupLineEditNumber(valid, name, entry, last); + ((LineEdit) control).OnTextChanged += e => { e.Control.Text = e.Text.ToUpper(); }; + return (control, returner); + } + + private (Control, Func) SetupCheckBox(Func _, string name, QuickDialogEntry entry, bool last) + { + var check = new CheckBox() { HorizontalExpand = true, HorizontalAlignment = HAlignment.Right }; + check.Text = name; + + return (check, () => { return check.Pressed ? "true" : "false"; }); + } + + private (Control, Func) SetupVoid(Func _, string __, QuickDialogEntry ___, bool ____) + { + var control = new Control(); + control.Visible = false; + return (control, () => "" ); + } + + + #endregion } diff --git a/Content.Server/Administration/QuickDialogSystem.OpenDialog.cs b/Content.Server/Administration/QuickDialogSystem.OpenDialog.cs index 1bbc8a6c9e..c98e152cd2 100644 --- a/Content.Server/Administration/QuickDialogSystem.OpenDialog.cs +++ b/Content.Server/Administration/QuickDialogSystem.OpenDialog.cs @@ -4,6 +4,7 @@ using Robust.Shared.Player; namespace Content.Server.Administration; +//res().System().TryGetSession(new EntityUid(X), out var seks);res().System().OpenDialog(seks, "Заголовок", "Серийный код твоей матери", "Селёдкой пахнет?", "Сосал?", "Сколько ванотян жрал хуёв:", "тыгыдык тыгыдык тыгыдык тыгыдык" ," ", "Вскрываем байты", (_,_,_,_,_,_,_)=>{}); public sealed partial class QuickDialogSystem { /// @@ -173,4 +174,379 @@ public sealed partial class QuickDialogSystem cancelAction ?? (() => { }) ); } + + /// + /// Opens a dialog for the given client, allowing them to enter in the desired data. + /// + /// Client to show a dialog for. + /// Title of the dialog. + /// The first prompt. + /// The second prompt. + /// The third prompt. + /// The fourth prompt. + /// The fifth prompt. + /// The action to execute upon Ok being pressed. + /// The action to execute upon the dialog being cancelled. + /// Type of the first input. + /// Type of the second input. + /// Type of the third input. + /// Type of the fourth input. + /// Type of the fifth input. + [PublicAPI] + public void OpenDialog(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, Action okAction, Action? cancelAction = null) + { + OpenDialogInternal( + session, + title, + new List + { + new("1", TypeToEntryType(typeof(T1)), prompt1), + new("2", TypeToEntryType(typeof(T2)), prompt2), + new("3", TypeToEntryType(typeof(T3)), prompt3), + new("4", TypeToEntryType(typeof(T4)), prompt4), + new("5", TypeToEntryType(typeof(T5)), prompt5), + }, + QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton, + (ev => + { + if ( + TryParseQuickDialog(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) && + TryParseQuickDialog(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) && + TryParseQuickDialog(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) && + TryParseQuickDialog(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) && + TryParseQuickDialog(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) + ) + okAction.Invoke(v1, v2, v3, v4, v5); + else + { + session.Channel.Disconnect("Replied with invalid quick dialog data."); + cancelAction?.Invoke(); + } + }), + cancelAction ?? (() => { }) + ); + } + + + /// + /// Opens a dialog for the given client, allowing them to enter in the desired data. + /// + /// Client to show a dialog for. + /// Title of the dialog. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The action to execute upon Ok being pressed. + /// The action to execute upon the dialog being cancelled. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + [PublicAPI] + public void OpenDialog(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, Action okAction, Action? cancelAction = null) + { + OpenDialogInternal( + session, + title, + new List + { + new("1", TypeToEntryType(typeof(T1)), prompt1), + new("2", TypeToEntryType(typeof(T2)), prompt2), + new("3", TypeToEntryType(typeof(T3)), prompt3), + new("4", TypeToEntryType(typeof(T4)), prompt4), + new("5", TypeToEntryType(typeof(T5)), prompt5), + new("6", TypeToEntryType(typeof(T6)), prompt6), + }, + QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton, + (ev => + { + if ( + TryParseQuickDialog(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) && + TryParseQuickDialog(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) && + TryParseQuickDialog(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) && + TryParseQuickDialog(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) && + TryParseQuickDialog(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) && + TryParseQuickDialog(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) + ) + okAction.Invoke(v1, v2, v3, v4, v5, v6); + else + { + session.Channel.Disconnect("Replied with invalid quick dialog data."); + cancelAction?.Invoke(); + } + }), + cancelAction ?? (() => { }) + ); + } + + + /// + /// Opens a dialog for the given client, allowing them to enter in the desired data. + /// + /// Client to show a dialog for. + /// Title of the dialog. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The action to execute upon Ok being pressed. + /// The action to execute upon the dialog being cancelled. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + [PublicAPI] + public void OpenDialog(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, string prompt7, Action okAction, Action? cancelAction = null) + { + OpenDialogInternal( + session, + title, + new List + { + new("1", TypeToEntryType(typeof(T1)), prompt1), + new("2", TypeToEntryType(typeof(T2)), prompt2), + new("3", TypeToEntryType(typeof(T3)), prompt3), + new("4", TypeToEntryType(typeof(T4)), prompt4), + new("5", TypeToEntryType(typeof(T5)), prompt5), + new("6", TypeToEntryType(typeof(T6)), prompt6), + new("7", TypeToEntryType(typeof(T7)), prompt7), + }, + QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton, + (ev => + { + if ( + TryParseQuickDialog(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) && + TryParseQuickDialog(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) && + TryParseQuickDialog(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) && + TryParseQuickDialog(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) && + TryParseQuickDialog(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) && + TryParseQuickDialog(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) && + TryParseQuickDialog(TypeToEntryType(typeof(T7)), ev.Responses["7"], out var v7) + ) + okAction.Invoke(v1, v2, v3, v4, v5, v6, v7); + else + { + session.Channel.Disconnect("Replied with invalid quick dialog data."); + cancelAction?.Invoke(); + } + }), + cancelAction ?? (() => { }) + ); + } + + + /// + /// Opens a dialog for the given client, allowing them to enter in the desired data. + /// + /// Client to show a dialog for. + /// Title of the dialog. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The action to execute upon Ok being pressed. + /// The action to execute upon the dialog being cancelled. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + [PublicAPI] + public void OpenDialog(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, string prompt7, string prompt8, Action okAction, Action? cancelAction = null) + { + OpenDialogInternal( + session, + title, + new List + { + new("1", TypeToEntryType(typeof(T1)), prompt1), + new("2", TypeToEntryType(typeof(T2)), prompt2), + new("3", TypeToEntryType(typeof(T3)), prompt3), + new("4", TypeToEntryType(typeof(T4)), prompt4), + new("5", TypeToEntryType(typeof(T5)), prompt5), + new("6", TypeToEntryType(typeof(T6)), prompt6), + new("7", TypeToEntryType(typeof(T7)), prompt7), + new("8", TypeToEntryType(typeof(T8)), prompt8), + }, + QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton, + (ev => + { + if ( + TryParseQuickDialog(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) && + TryParseQuickDialog(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) && + TryParseQuickDialog(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) && + TryParseQuickDialog(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) && + TryParseQuickDialog(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) && + TryParseQuickDialog(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) && + TryParseQuickDialog(TypeToEntryType(typeof(T7)), ev.Responses["7"], out var v7) && + TryParseQuickDialog(TypeToEntryType(typeof(T8)), ev.Responses["8"], out var v8) + ) + okAction.Invoke(v1, v2, v3, v4, v5, v6, v7, v8); + else + { + session.Channel.Disconnect("Replied with invalid quick dialog data."); + cancelAction?.Invoke(); + } + }), + cancelAction ?? (() => { }) + ); + } + + /// + /// Opens a dialog for the given client, allowing them to enter in the desired data. + /// + /// Client to show a dialog for. + /// Title of the dialog. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The action to execute upon Ok being pressed. + /// The action to execute upon the dialog being cancelled. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + [PublicAPI] + public void OpenDialog(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, string prompt7, string prompt8, string prompt9, Action okAction, Action? cancelAction = null) + { + OpenDialogInternal( + session, + title, + new List + { + new("1", TypeToEntryType(typeof(T1)), prompt1), + new("2", TypeToEntryType(typeof(T2)), prompt2), + new("3", TypeToEntryType(typeof(T3)), prompt3), + new("4", TypeToEntryType(typeof(T4)), prompt4), + new("5", TypeToEntryType(typeof(T5)), prompt5), + new("6", TypeToEntryType(typeof(T6)), prompt6), + new("7", TypeToEntryType(typeof(T7)), prompt7), + new("8", TypeToEntryType(typeof(T8)), prompt8), + new("9", TypeToEntryType(typeof(T9)), prompt9), + }, + QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton, + (ev => + { + if ( + TryParseQuickDialog(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) && + TryParseQuickDialog(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) && + TryParseQuickDialog(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) && + TryParseQuickDialog(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) && + TryParseQuickDialog(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) && + TryParseQuickDialog(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) && + TryParseQuickDialog(TypeToEntryType(typeof(T7)), ev.Responses["7"], out var v7) && + TryParseQuickDialog(TypeToEntryType(typeof(T8)), ev.Responses["8"], out var v8) && + TryParseQuickDialog(TypeToEntryType(typeof(T9)), ev.Responses["9"], out var v9) + ) + okAction.Invoke(v1, v2, v3, v4, v5, v6, v7, v8, v9); + else + { + session.Channel.Disconnect("Replied with invalid quick dialog data."); + cancelAction?.Invoke(); + } + }), + cancelAction ?? (() => { }) + ); + } + + /// + /// Opens a dialog for the given client, allowing them to enter in the desired data. + /// + /// Client to show a dialog for. + /// Title of the dialog. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The Nth prompt. + /// The action to execute upon Ok being pressed. + /// The action to execute upon the dialog being cancelled. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + /// Type of the Nth input. + [PublicAPI] + public void OpenDialog(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, string prompt7, string prompt8, string prompt9, string prompt10, Action okAction, Action? cancelAction = null) + { + OpenDialogInternal( + session, + title, + new List + { + new("1", TypeToEntryType(typeof(T1)), prompt1), + new("2", TypeToEntryType(typeof(T2)), prompt2), + new("3", TypeToEntryType(typeof(T3)), prompt3), + new("4", TypeToEntryType(typeof(T4)), prompt4), + new("5", TypeToEntryType(typeof(T5)), prompt5), + new("6", TypeToEntryType(typeof(T6)), prompt6), + new("7", TypeToEntryType(typeof(T7)), prompt7), + new("8", TypeToEntryType(typeof(T8)), prompt8), + new("9", TypeToEntryType(typeof(T9)), prompt9), + new("10", TypeToEntryType(typeof(T10)), prompt10), + }, + QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton, + (ev => + { + if ( + TryParseQuickDialog(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) && + TryParseQuickDialog(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) && + TryParseQuickDialog(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) && + TryParseQuickDialog(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) && + TryParseQuickDialog(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) && + TryParseQuickDialog(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) && + TryParseQuickDialog(TypeToEntryType(typeof(T7)), ev.Responses["7"], out var v7) && + TryParseQuickDialog(TypeToEntryType(typeof(T8)), ev.Responses["8"], out var v8) && + TryParseQuickDialog(TypeToEntryType(typeof(T9)), ev.Responses["9"], out var v9) && + TryParseQuickDialog(TypeToEntryType(typeof(T10)), ev.Responses["10"], out var v10) + ) + okAction.Invoke(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10); + else + { + session.Channel.Disconnect("Replied with invalid quick dialog data."); + cancelAction?.Invoke(); + } + }), + cancelAction ?? (() => { }) + ); + } } diff --git a/Content.Server/Administration/QuickDialogSystem.cs b/Content.Server/Administration/QuickDialogSystem.cs index df2953f98d..89f0db3c16 100644 --- a/Content.Server/Administration/QuickDialogSystem.cs +++ b/Content.Server/Administration/QuickDialogSystem.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using Content.Shared.Administration; +using Content.Shared.Chemistry; using Robust.Server.Player; using Robust.Shared.Enums; using Robust.Shared.Network; @@ -7,6 +8,8 @@ using Robust.Shared.Player; namespace Content.Server.Administration; + + /// /// This handles the server portion of quick dialogs, including opening them. /// @@ -144,6 +147,35 @@ public sealed partial class QuickDialogSystem : EntitySystem output = (T?) (object?) longString; return output is not null; } + case QuickDialogEntryType.Boolean: + { + switch (input) + { + case "true": + output = (T)(object)true; + return true; + case "false": + output = (T)(object)false; + return true; + default: + output = default; + return false; + } + } + case QuickDialogEntryType.Hex16: + { + bool ret = int.TryParse(input, System.Globalization.NumberStyles.HexNumber, null, out var res) && input.Length <= 4 && input == input.ToUpper(); + if (ret) + output = (T?) (object?) (Hex16) res; + else + output = default; + return ret; + } + case QuickDialogEntryType.Void: + { + output = default; + return input == ""; + } default: throw new ArgumentOutOfRangeException(nameof(entryType), entryType, null); } @@ -151,6 +183,7 @@ public sealed partial class QuickDialogSystem : EntitySystem private QuickDialogEntryType TypeToEntryType(Type T) { + // yandere station much? if (T == typeof(int) || T == typeof(uint) || T == typeof(long) || T == typeof(ulong)) return QuickDialogEntryType.Integer; @@ -163,6 +196,19 @@ public sealed partial class QuickDialogSystem : EntitySystem if (T == typeof(LongString)) return QuickDialogEntryType.LongText; + if (T == typeof(Hex16)) + return QuickDialogEntryType.Hex16; + + if (T == typeof(bool)) + return QuickDialogEntryType.Boolean; + + if (T == typeof(VoidOption)) + return QuickDialogEntryType.Void; + + + + + throw new ArgumentException($"Tried to open a dialog with unsupported type {T}."); } } @@ -182,3 +228,27 @@ public record struct LongString(string String) return new(s); } } + +/// +/// A type used with quick dialogs to indicate you want the user to enter a 0-65535 int as a hexadecimal value,.. +/// +/// The int retrieved. +public record struct Hex16(int number) +{ + public static implicit operator int(Hex16 hex16) + { + return hex16.number; + } + public static explicit operator Hex16(int num) + { + return new(num); + } +} + +/// +/// A type used with quick dialogs for putting only a label, without any controls. +/// +public record struct VoidOption() +{ + +} diff --git a/Content.Shared/Administration/QuickDialogOpenEvent.cs b/Content.Shared/Administration/QuickDialogOpenEvent.cs index f4e77ab999..71a292474b 100644 --- a/Content.Shared/Administration/QuickDialogOpenEvent.cs +++ b/Content.Shared/Administration/QuickDialogOpenEvent.cs @@ -1,4 +1,4 @@ -using Robust.Shared.Serialization; +using Robust.Shared.Serialization; namespace Content.Shared.Administration; @@ -125,6 +125,10 @@ public enum QuickDialogEntryType /// Float, /// + /// Any integer from 0 to 65535, but the user has to enter it in a hexadecimal format. + /// + Hex16, + /// /// Maximum of 100 characters string. /// ShortText, @@ -132,4 +136,12 @@ public enum QuickDialogEntryType /// Maximum of 2,000 characters string. /// LongText, + /// + /// You'll never guess this one. + /// + Boolean, + /// + /// No control will be shown, only the prompt label. + /// + Void } diff --git a/Resources/Locale/en-US/quick-dialog/quick-dialog.ftl b/Resources/Locale/en-US/quick-dialog/quick-dialog.ftl index f2b6f7f9a9..3ece64bc5e 100644 --- a/Resources/Locale/en-US/quick-dialog/quick-dialog.ftl +++ b/Resources/Locale/en-US/quick-dialog/quick-dialog.ftl @@ -3,4 +3,6 @@ quick-dialog-ui-float = Float.. quick-dialog-ui-short-text = Short text.. quick-dialog-ui-long-text = Long text.. quick-dialog-ui-ok = Ok +quick-dialog-ui-hex16 = 0000-FFFF +quick-dialog-ui-boolean = ​ quick-dialog-ui-cancel = Cancel diff --git a/Resources/Locale/ru-RU/quick-dialog/quick-dialog.ftl b/Resources/Locale/ru-RU/quick-dialog/quick-dialog.ftl index 5600dd725a..616ef71af0 100644 --- a/Resources/Locale/ru-RU/quick-dialog/quick-dialog.ftl +++ b/Resources/Locale/ru-RU/quick-dialog/quick-dialog.ftl @@ -1,6 +1,8 @@ -quick-dialog-ui-integer = Integer.. -quick-dialog-ui-float = Float.. +quick-dialog-ui-integer = Целое число.. +quick-dialog-ui-float = Число.. quick-dialog-ui-short-text = Короткий текст.. quick-dialog-ui-long-text = Длинный текст.. +quick-dialog-ui-hex16 = 0000-FFFF +quick-dialog-ui-boolean = ​ quick-dialog-ui-ok = Принять quick-dialog-ui-cancel = Отмена