|
| 1 | +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt |
| 2 | +using Content.Shared.Administration; |
| 3 | +using Robust.Client.AutoGenerated; |
| 4 | +using Robust.Client.UserInterface.Controls; |
| 5 | +using Robust.Client.UserInterface.CustomControls; |
| 6 | +using Robust.Client.UserInterface.XAML; |
| 7 | + |
| 8 | +namespace Content.Client.SS220.DialogWindowDescUI; |
| 9 | + |
| 10 | +[GenerateTypedNameReferences] |
| 11 | +public sealed partial class DialogWindowDesc : DefaultWindow |
| 12 | +{ |
| 13 | + private List<(string, LineEdit)> _promptLines; |
| 14 | + |
| 15 | + private bool _finished; |
| 16 | + |
| 17 | + public Action<Dictionary<string, string>>? OnConfirmed; |
| 18 | + |
| 19 | + public Action? OnCancelled; |
| 20 | + |
| 21 | + public DialogWindowDesc(string title, string dsscEntty, List<QuickDialogEntry> entries, bool ok = true) |
| 22 | + { |
| 23 | + RobustXamlLoader.Load(this); |
| 24 | + |
| 25 | + Title = title; |
| 26 | + |
| 27 | + OkButton.Visible = ok; |
| 28 | + |
| 29 | + _promptLines = new(entries.Count); |
| 30 | + |
| 31 | + for (int i = 0; i < entries.Count; i++) |
| 32 | + { |
| 33 | + var entry = entries[i]; |
| 34 | + |
| 35 | + var box = new BoxContainer(); |
| 36 | + box.AddChild(new Label() { Text = entry.Prompt, Align = Label.AlignMode.Center, HorizontalExpand = true}); |
| 37 | + Prompts.AddChild(box); |
| 38 | + |
| 39 | + var boxDesc = new BoxContainer(); |
| 40 | + boxDesc.AddChild(new Label() { Text = dsscEntty, Align = Label.AlignMode.Center, FontColorOverride = Color.Gray, HorizontalExpand = true }); |
| 41 | + Prompts.AddChild(boxDesc); |
| 42 | + |
| 43 | + var boxEmpty = new BoxContainer(); |
| 44 | + boxEmpty.AddChild(new BoxContainer() {MinHeight=20}); |
| 45 | + Prompts.AddChild(boxEmpty); |
| 46 | + |
| 47 | + var boxEdit = new BoxContainer(); |
| 48 | + var edit = new LineEdit() { HorizontalExpand = true }; |
| 49 | + boxEdit.AddChild(edit); |
| 50 | + |
| 51 | + _promptLines.Add((entry.FieldId, edit)); |
| 52 | + Prompts.AddChild(boxEdit); |
| 53 | + } |
| 54 | + |
| 55 | + OkButton.OnPressed += _ => Confirm(); |
| 56 | + |
| 57 | + OnClose += () => |
| 58 | + { |
| 59 | + if (!_finished) |
| 60 | + OnCancelled?.Invoke(); |
| 61 | + }; |
| 62 | + |
| 63 | + _promptLines[0].Item2.GrabKeyboardFocus(); |
| 64 | + |
| 65 | + MinWidth *= 2; // Just double it. |
| 66 | + |
| 67 | + OpenCentered(); |
| 68 | + } |
| 69 | + |
| 70 | + private void Confirm() |
| 71 | + { |
| 72 | + var results = new Dictionary<string, string>(); |
| 73 | + foreach (var (field, edit) in _promptLines) |
| 74 | + { |
| 75 | + results[field] = edit.Text; |
| 76 | + } |
| 77 | + |
| 78 | + _finished = true; |
| 79 | + OnConfirmed?.Invoke(results); |
| 80 | + Close(); |
| 81 | + } |
| 82 | +} |
| 83 | + |
0 commit comments