"""апгрейд""" QuickDialogSystem (#133)
* It's a surprise tool that will help us later * Are you feeling it now mr. krabs? * ой блять * транслате
This commit is contained in:
@@ -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
|
||||
/// </summary>
|
||||
private bool _finished;
|
||||
|
||||
private List<(string, LineEdit)> _promptLines;
|
||||
private List<(string, Func<string>)> _promptLines;
|
||||
|
||||
private delegate (Control, Func<string>) ControlConstructor(Func<string, bool> verifier, string name, QuickDialogEntry entry, bool last);// are you feeling it now mr krabs?
|
||||
|
||||
/// <summary>
|
||||
/// 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, bool>, 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<string>, a """generic""" function that returns whatever user has done with the control
|
||||
(ControlConstructor, Func<string, bool>?, 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<string, string>();
|
||||
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<string>) SetupLineEdit(Func<string, bool> 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<string>) SetupLineEditNumber(Func<string, bool> 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<string>) SetupLineEditHex(Func<string, bool> 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<string>) SetupCheckBox(Func<string, bool> _, 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<string>) SetupVoid(Func<string, bool> _, string __, QuickDialogEntry ___, bool ____)
|
||||
{
|
||||
var control = new Control();
|
||||
control.Visible = false;
|
||||
return (control, () => "" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Administration;
|
||||
|
||||
//res<IEntityManager>().System<MindSystem>().TryGetSession(new EntityUid(X), out var seks);res<IEntityManager>().System<QuickDialogSystem>().OpenDialog<string, bool, bool, int, VoidOption, VoidOption, Hex16>(seks, "Заголовок", "Серийный код твоей матери", "Селёдкой пахнет?", "Сосал?", "Сколько ванотян жрал хуёв:", "тыгыдык тыгыдык тыгыдык тыгыдык" ," ", "Вскрываем байты", (_,_,_,_,_,_,_)=>{});
|
||||
public sealed partial class QuickDialogSystem
|
||||
{
|
||||
/// <summary>
|
||||
@@ -173,4 +174,379 @@ public sealed partial class QuickDialogSystem
|
||||
cancelAction ?? (() => { })
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a dialog for the given client, allowing them to enter in the desired data.
|
||||
/// </summary>
|
||||
/// <param name="session">Client to show a dialog for.</param>
|
||||
/// <param name="title">Title of the dialog.</param>
|
||||
/// <param name="prompt1">The first prompt.</param>
|
||||
/// <param name="prompt2">The second prompt.</param>
|
||||
/// <param name="prompt3">The third prompt.</param>
|
||||
/// <param name="prompt4">The fourth prompt.</param>
|
||||
/// <param name="prompt5">The fifth prompt.</param>
|
||||
/// <param name="okAction">The action to execute upon Ok being pressed.</param>
|
||||
/// <param name="cancelAction">The action to execute upon the dialog being cancelled.</param>
|
||||
/// <typeparam name="T1">Type of the first input.</typeparam>
|
||||
/// <typeparam name="T2">Type of the second input.</typeparam>
|
||||
/// <typeparam name="T3">Type of the third input.</typeparam>
|
||||
/// <typeparam name="T4">Type of the fourth input.</typeparam>
|
||||
/// <typeparam name="T5">Type of the fifth input.</typeparam>
|
||||
[PublicAPI]
|
||||
public void OpenDialog<T1, T2, T3, T4, T5>(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, Action<T1, T2, T3, T4, T5> okAction, Action? cancelAction = null)
|
||||
{
|
||||
OpenDialogInternal(
|
||||
session,
|
||||
title,
|
||||
new List<QuickDialogEntry>
|
||||
{
|
||||
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<T1>(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) &&
|
||||
TryParseQuickDialog<T2>(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) &&
|
||||
TryParseQuickDialog<T3>(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) &&
|
||||
TryParseQuickDialog<T4>(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) &&
|
||||
TryParseQuickDialog<T5>(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 ?? (() => { })
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Opens a dialog for the given client, allowing them to enter in the desired data.
|
||||
/// </summary>
|
||||
/// <param name="session">Client to show a dialog for.</param>
|
||||
/// <param name="title">Title of the dialog.</param>
|
||||
/// <param name="prompt1">The Nth prompt.</param>
|
||||
/// <param name="prompt2">The Nth prompt.</param>
|
||||
/// <param name="prompt3">The Nth prompt.</param>
|
||||
/// <param name="prompt4">The Nth prompt.</param>
|
||||
/// <param name="prompt5">The Nth prompt.</param>
|
||||
/// <param name="prompt6">The Nth prompt.</param>
|
||||
/// <param name="okAction">The action to execute upon Ok being pressed.</param>
|
||||
/// <param name="cancelAction">The action to execute upon the dialog being cancelled.</param>
|
||||
/// <typeparam name="T1">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T2">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T3">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T4">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T5">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T6">Type of the Nth input.</typeparam>
|
||||
[PublicAPI]
|
||||
public void OpenDialog<T1, T2, T3, T4, T5, T6>(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, Action<T1, T2, T3, T4, T5, T6> okAction, Action? cancelAction = null)
|
||||
{
|
||||
OpenDialogInternal(
|
||||
session,
|
||||
title,
|
||||
new List<QuickDialogEntry>
|
||||
{
|
||||
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<T1>(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) &&
|
||||
TryParseQuickDialog<T2>(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) &&
|
||||
TryParseQuickDialog<T3>(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) &&
|
||||
TryParseQuickDialog<T4>(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) &&
|
||||
TryParseQuickDialog<T5>(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) &&
|
||||
TryParseQuickDialog<T6>(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 ?? (() => { })
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Opens a dialog for the given client, allowing them to enter in the desired data.
|
||||
/// </summary>
|
||||
/// <param name="session">Client to show a dialog for.</param>
|
||||
/// <param name="title">Title of the dialog.</param>
|
||||
/// <param name="prompt1">The Nth prompt.</param>
|
||||
/// <param name="prompt2">The Nth prompt.</param>
|
||||
/// <param name="prompt3">The Nth prompt.</param>
|
||||
/// <param name="prompt4">The Nth prompt.</param>
|
||||
/// <param name="prompt5">The Nth prompt.</param>
|
||||
/// <param name="prompt6">The Nth prompt.</param>
|
||||
/// <param name="prompt7">The Nth prompt.</param>
|
||||
/// <param name="okAction">The action to execute upon Ok being pressed.</param>
|
||||
/// <param name="cancelAction">The action to execute upon the dialog being cancelled.</param>
|
||||
/// <typeparam name="T1">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T2">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T3">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T4">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T5">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T6">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T7">Type of the Nth input.</typeparam>
|
||||
[PublicAPI]
|
||||
public void OpenDialog<T1, T2, T3, T4, T5, T6, T7>(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, string prompt7, Action<T1, T2, T3, T4, T5, T6, T7> okAction, Action? cancelAction = null)
|
||||
{
|
||||
OpenDialogInternal(
|
||||
session,
|
||||
title,
|
||||
new List<QuickDialogEntry>
|
||||
{
|
||||
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<T1>(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) &&
|
||||
TryParseQuickDialog<T2>(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) &&
|
||||
TryParseQuickDialog<T3>(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) &&
|
||||
TryParseQuickDialog<T4>(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) &&
|
||||
TryParseQuickDialog<T5>(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) &&
|
||||
TryParseQuickDialog<T6>(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) &&
|
||||
TryParseQuickDialog<T7>(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 ?? (() => { })
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Opens a dialog for the given client, allowing them to enter in the desired data.
|
||||
/// </summary>
|
||||
/// <param name="session">Client to show a dialog for.</param>
|
||||
/// <param name="title">Title of the dialog.</param>
|
||||
/// <param name="prompt1">The Nth prompt.</param>
|
||||
/// <param name="prompt2">The Nth prompt.</param>
|
||||
/// <param name="prompt3">The Nth prompt.</param>
|
||||
/// <param name="prompt4">The Nth prompt.</param>
|
||||
/// <param name="prompt5">The Nth prompt.</param>
|
||||
/// <param name="prompt6">The Nth prompt.</param>
|
||||
/// <param name="prompt7">The Nth prompt.</param>
|
||||
/// <param name="prompt8">The Nth prompt.</param>
|
||||
/// <param name="okAction">The action to execute upon Ok being pressed.</param>
|
||||
/// <param name="cancelAction">The action to execute upon the dialog being cancelled.</param>
|
||||
/// <typeparam name="T1">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T2">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T3">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T4">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T5">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T6">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T7">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T8">Type of the Nth input.</typeparam>
|
||||
[PublicAPI]
|
||||
public void OpenDialog<T1, T2, T3, T4, T5, T6, T7, T8>(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, string prompt7, string prompt8, Action<T1, T2, T3, T4, T5, T6, T7, T8> okAction, Action? cancelAction = null)
|
||||
{
|
||||
OpenDialogInternal(
|
||||
session,
|
||||
title,
|
||||
new List<QuickDialogEntry>
|
||||
{
|
||||
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<T1>(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) &&
|
||||
TryParseQuickDialog<T2>(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) &&
|
||||
TryParseQuickDialog<T3>(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) &&
|
||||
TryParseQuickDialog<T4>(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) &&
|
||||
TryParseQuickDialog<T5>(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) &&
|
||||
TryParseQuickDialog<T6>(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) &&
|
||||
TryParseQuickDialog<T7>(TypeToEntryType(typeof(T7)), ev.Responses["7"], out var v7) &&
|
||||
TryParseQuickDialog<T8>(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 ?? (() => { })
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a dialog for the given client, allowing them to enter in the desired data.
|
||||
/// </summary>
|
||||
/// <param name="session">Client to show a dialog for.</param>
|
||||
/// <param name="title">Title of the dialog.</param>
|
||||
/// <param name="prompt1">The Nth prompt.</param>
|
||||
/// <param name="prompt2">The Nth prompt.</param>
|
||||
/// <param name="prompt3">The Nth prompt.</param>
|
||||
/// <param name="prompt4">The Nth prompt.</param>
|
||||
/// <param name="prompt5">The Nth prompt.</param>
|
||||
/// <param name="prompt6">The Nth prompt.</param>
|
||||
/// <param name="prompt7">The Nth prompt.</param>
|
||||
/// <param name="prompt8">The Nth prompt.</param>
|
||||
/// <param name="prompt9">The Nth prompt.</param>
|
||||
/// <param name="okAction">The action to execute upon Ok being pressed.</param>
|
||||
/// <param name="cancelAction">The action to execute upon the dialog being cancelled.</param>
|
||||
/// <typeparam name="T1">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T2">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T3">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T4">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T5">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T6">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T7">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T8">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T9">Type of the Nth input.</typeparam>
|
||||
[PublicAPI]
|
||||
public void OpenDialog<T1, T2, T3, T4, T5, T6, T7, T8, T9>(ICommonSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, string prompt5, string prompt6, string prompt7, string prompt8, string prompt9, Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> okAction, Action? cancelAction = null)
|
||||
{
|
||||
OpenDialogInternal(
|
||||
session,
|
||||
title,
|
||||
new List<QuickDialogEntry>
|
||||
{
|
||||
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<T1>(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) &&
|
||||
TryParseQuickDialog<T2>(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) &&
|
||||
TryParseQuickDialog<T3>(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) &&
|
||||
TryParseQuickDialog<T4>(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) &&
|
||||
TryParseQuickDialog<T5>(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) &&
|
||||
TryParseQuickDialog<T6>(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) &&
|
||||
TryParseQuickDialog<T7>(TypeToEntryType(typeof(T7)), ev.Responses["7"], out var v7) &&
|
||||
TryParseQuickDialog<T8>(TypeToEntryType(typeof(T8)), ev.Responses["8"], out var v8) &&
|
||||
TryParseQuickDialog<T9>(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 ?? (() => { })
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a dialog for the given client, allowing them to enter in the desired data.
|
||||
/// </summary>
|
||||
/// <param name="session">Client to show a dialog for.</param>
|
||||
/// <param name="title">Title of the dialog.</param>
|
||||
/// <param name="prompt1">The Nth prompt.</param>
|
||||
/// <param name="prompt2">The Nth prompt.</param>
|
||||
/// <param name="prompt3">The Nth prompt.</param>
|
||||
/// <param name="prompt4">The Nth prompt.</param>
|
||||
/// <param name="prompt5">The Nth prompt.</param>
|
||||
/// <param name="prompt6">The Nth prompt.</param>
|
||||
/// <param name="prompt7">The Nth prompt.</param>
|
||||
/// <param name="prompt8">The Nth prompt.</param>
|
||||
/// <param name="prompt9">The Nth prompt.</param>
|
||||
/// <param name="prompt10">The Nth prompt.</param>
|
||||
/// <param name="okAction">The action to execute upon Ok being pressed.</param>
|
||||
/// <param name="cancelAction">The action to execute upon the dialog being cancelled.</param>
|
||||
/// <typeparam name="T1">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T2">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T3">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T4">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T5">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T6">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T7">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T8">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T9">Type of the Nth input.</typeparam>
|
||||
/// <typeparam name="T10">Type of the Nth input.</typeparam>
|
||||
[PublicAPI]
|
||||
public void OpenDialog<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(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<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> okAction, Action? cancelAction = null)
|
||||
{
|
||||
OpenDialogInternal(
|
||||
session,
|
||||
title,
|
||||
new List<QuickDialogEntry>
|
||||
{
|
||||
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<T1>(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1) &&
|
||||
TryParseQuickDialog<T2>(TypeToEntryType(typeof(T2)), ev.Responses["2"], out var v2) &&
|
||||
TryParseQuickDialog<T3>(TypeToEntryType(typeof(T3)), ev.Responses["3"], out var v3) &&
|
||||
TryParseQuickDialog<T4>(TypeToEntryType(typeof(T4)), ev.Responses["4"], out var v4) &&
|
||||
TryParseQuickDialog<T5>(TypeToEntryType(typeof(T5)), ev.Responses["5"], out var v5) &&
|
||||
TryParseQuickDialog<T6>(TypeToEntryType(typeof(T6)), ev.Responses["6"], out var v6) &&
|
||||
TryParseQuickDialog<T7>(TypeToEntryType(typeof(T7)), ev.Responses["7"], out var v7) &&
|
||||
TryParseQuickDialog<T8>(TypeToEntryType(typeof(T8)), ev.Responses["8"], out var v8) &&
|
||||
TryParseQuickDialog<T9>(TypeToEntryType(typeof(T9)), ev.Responses["9"], out var v9) &&
|
||||
TryParseQuickDialog<T10>(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 ?? (() => { })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This handles the server portion of quick dialogs, including opening them.
|
||||
/// </summary>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type used with quick dialogs to indicate you want the user to enter a 0-65535 int as a hexadecimal value,..
|
||||
/// </summary>
|
||||
/// <param name="int">The int retrieved.</param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A type used with quick dialogs for putting only a label, without any controls.
|
||||
/// </summary>
|
||||
public record struct VoidOption()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Administration;
|
||||
|
||||
@@ -125,6 +125,10 @@ public enum QuickDialogEntryType
|
||||
/// </summary>
|
||||
Float,
|
||||
/// <summary>
|
||||
/// Any integer from 0 to 65535, but the user has to enter it in a hexadecimal format.
|
||||
/// </summary>
|
||||
Hex16,
|
||||
/// <summary>
|
||||
/// Maximum of 100 characters string.
|
||||
/// </summary>
|
||||
ShortText,
|
||||
@@ -132,4 +136,12 @@ public enum QuickDialogEntryType
|
||||
/// Maximum of 2,000 characters string.
|
||||
/// </summary>
|
||||
LongText,
|
||||
/// <summary>
|
||||
/// You'll never guess this one.
|
||||
/// </summary>
|
||||
Boolean,
|
||||
/// <summary>
|
||||
/// No control will be shown, only the prompt label.
|
||||
/// </summary>
|
||||
Void
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = Отмена
|
||||
|
||||
Reference in New Issue
Block a user