using Content.Shared.Administration; using JetBrains.Annotations; using Robust.Server.Player; namespace Content.Server.Administration; public sealed partial class QuickDialogSystem { /// /// 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 prompt. /// The action to execute upon Ok being pressed. /// The action to execute upon the dialog being cancelled. /// Type of the input. [PublicAPI] public void OpenDialog(IPlayerSession session, string title, string prompt, Action okAction, Action? cancelAction = null) { OpenDialogInternal( session, title, new List { new("1", TypeToEntryType(typeof(T1)), prompt) }, QuickDialogButtonFlag.OkButton | QuickDialogButtonFlag.CancelButton, (ev => { if (TryParseQuickDialog(TypeToEntryType(typeof(T1)), ev.Responses["1"], out var v1)) okAction.Invoke(v1); else { session.ConnectedClient.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 first prompt. /// The second 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. [PublicAPI] public void OpenDialog(IPlayerSession session, string title, string prompt1, string prompt2, Action okAction, Action? cancelAction = null) { OpenDialogInternal( session, title, new List { new("1", TypeToEntryType(typeof(T1)), prompt1), new("2", TypeToEntryType(typeof(T2)), prompt2) }, 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) ) okAction.Invoke(v1, v2); else { session.ConnectedClient.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 first prompt. /// The second prompt. /// The third 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. [PublicAPI] public void OpenDialog(IPlayerSession session, string title, string prompt1, string prompt2, string prompt3, 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) }, 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) ) okAction.Invoke(v1, v2, v3); else { session.ConnectedClient.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 first prompt. /// The second prompt. /// The third prompt. /// The fourth 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. [PublicAPI] public void OpenDialog(IPlayerSession session, string title, string prompt1, string prompt2, string prompt3, string prompt4, 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), }, 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) ) okAction.Invoke(v1, v2, v3, v4); else { session.ConnectedClient.Disconnect("Replied with invalid quick dialog data."); cancelAction?.Invoke(); } }), cancelAction ?? (() => { }) ); } }