Quick dialog fixes (#24046)
Pressing "enter" on the last dialog box now confirms the dialog. Localize.
This commit is contained in:
committed by
GitHub
parent
a8bb897796
commit
8416fc746b
@@ -6,6 +6,8 @@ using Robust.Client.UserInterface.Controls;
|
|||||||
|
|
||||||
namespace Content.Client.Administration;
|
namespace Content.Client.Administration;
|
||||||
|
|
||||||
|
// mfw they ported input() from BYOND
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This handles the client portion of quick dialogs.
|
/// This handles the client portion of quick dialogs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -32,39 +34,48 @@ public sealed class QuickDialogSystem : EntitySystem
|
|||||||
|
|
||||||
var promptsDict = new Dictionary<string, LineEdit>();
|
var promptsDict = new Dictionary<string, LineEdit>();
|
||||||
|
|
||||||
foreach (var entry in ev.Prompts)
|
for (var index = 0; index < ev.Prompts.Count; index++)
|
||||||
{
|
{
|
||||||
|
var entry = ev.Prompts[index];
|
||||||
var entryBox = new BoxContainer()
|
var entryBox = new BoxContainer()
|
||||||
{
|
{
|
||||||
Orientation = BoxContainer.LayoutOrientation.Horizontal
|
Orientation = BoxContainer.LayoutOrientation.Horizontal
|
||||||
};
|
};
|
||||||
|
|
||||||
entryBox.AddChild(new Label { Text = entry.Prompt, HorizontalExpand = true, SizeFlagsStretchRatio = 0.5f });
|
entryBox.AddChild(new Label { Text = entry.Prompt, HorizontalExpand = true, SizeFlagsStretchRatio = 0.5f });
|
||||||
var edit = new LineEdit() { HorizontalExpand = true};
|
var edit = new LineEdit() { HorizontalExpand = true };
|
||||||
entryBox.AddChild(edit);
|
entryBox.AddChild(edit);
|
||||||
switch (entry.Type)
|
switch (entry.Type)
|
||||||
{
|
{
|
||||||
case QuickDialogEntryType.Integer:
|
case QuickDialogEntryType.Integer:
|
||||||
edit.IsValid += VerifyInt;
|
edit.IsValid += VerifyInt;
|
||||||
edit.PlaceHolder = "Integer..";
|
edit.PlaceHolder = Loc.GetString("quick-dialog-ui-integer");
|
||||||
break;
|
break;
|
||||||
case QuickDialogEntryType.Float:
|
case QuickDialogEntryType.Float:
|
||||||
edit.IsValid += VerifyFloat;
|
edit.IsValid += VerifyFloat;
|
||||||
edit.PlaceHolder = "Float..";
|
edit.PlaceHolder = Loc.GetString("quick-dialog-ui-float");
|
||||||
break;
|
break;
|
||||||
case QuickDialogEntryType.ShortText:
|
case QuickDialogEntryType.ShortText:
|
||||||
edit.IsValid += VerifyShortText;
|
edit.IsValid += VerifyShortText;
|
||||||
edit.PlaceHolder = "Short text..";
|
edit.PlaceHolder = Loc.GetString("quick-dialog-ui-short-text");
|
||||||
break;
|
break;
|
||||||
case QuickDialogEntryType.LongText:
|
case QuickDialogEntryType.LongText:
|
||||||
edit.IsValid += VerifyLongText;
|
edit.IsValid += VerifyLongText;
|
||||||
edit.PlaceHolder = "Long text..";
|
edit.PlaceHolder = Loc.GetString("quick-dialog-ui-long-text");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
promptsDict.Add(entry.FieldId, edit);
|
promptsDict.Add(entry.FieldId, edit);
|
||||||
entryContainer.AddChild(entryBox);
|
entryContainer.AddChild(entryBox);
|
||||||
|
|
||||||
|
if (index == ev.Prompts.Count - 1)
|
||||||
|
{
|
||||||
|
// Last text box gets enter confirmation.
|
||||||
|
// Only the last so you don't accidentally confirm early.
|
||||||
|
edit.OnTextEntered += _ => Confirm();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var buttonsBox = new BoxContainer()
|
var buttonsBox = new BoxContainer()
|
||||||
@@ -79,17 +90,10 @@ public sealed class QuickDialogSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
var okButton = new Button()
|
var okButton = new Button()
|
||||||
{
|
{
|
||||||
Text = "Ok",
|
Text = Loc.GetString("quick-dialog-ui-ok"),
|
||||||
};
|
};
|
||||||
|
|
||||||
okButton.OnPressed += _ =>
|
okButton.OnPressed += _ => Confirm();
|
||||||
{
|
|
||||||
RaiseNetworkEvent(new QuickDialogResponseEvent(ev.DialogId,
|
|
||||||
promptsDict.Select(x => (x.Key, x.Value.Text)).ToDictionary(x => x.Key, x => x.Text),
|
|
||||||
QuickDialogButtonFlag.OkButton));
|
|
||||||
alreadyReplied = true;
|
|
||||||
window.Close();
|
|
||||||
};
|
|
||||||
|
|
||||||
buttonsBox.AddChild(okButton);
|
buttonsBox.AddChild(okButton);
|
||||||
}
|
}
|
||||||
@@ -98,7 +102,7 @@ public sealed class QuickDialogSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
var cancelButton = new Button()
|
var cancelButton = new Button()
|
||||||
{
|
{
|
||||||
Text = "Cancel",
|
Text = Loc.GetString("quick-dialog-ui-cancel"),
|
||||||
};
|
};
|
||||||
|
|
||||||
cancelButton.OnPressed += _ =>
|
cancelButton.OnPressed += _ =>
|
||||||
@@ -130,6 +134,17 @@ public sealed class QuickDialogSystem : EntitySystem
|
|||||||
window.MinWidth *= 2; // Just double it.
|
window.MinWidth *= 2; // Just double it.
|
||||||
|
|
||||||
window.OpenCentered();
|
window.OpenCentered();
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
void Confirm()
|
||||||
|
{
|
||||||
|
RaiseNetworkEvent(new QuickDialogResponseEvent(ev.DialogId,
|
||||||
|
promptsDict.Select(x => (x.Key, x.Value.Text)).ToDictionary(x => x.Key, x => x.Text),
|
||||||
|
QuickDialogButtonFlag.OkButton));
|
||||||
|
alreadyReplied = true;
|
||||||
|
window.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool VerifyInt(string input)
|
private bool VerifyInt(string input)
|
||||||
|
|||||||
6
Resources/Locale/en-US/quick-dialog/quick-dialog.ftl
Normal file
6
Resources/Locale/en-US/quick-dialog/quick-dialog.ftl
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
quick-dialog-ui-integer = Integer..
|
||||||
|
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-cancel = Cancel
|
||||||
Reference in New Issue
Block a user