From 5ccd0aee40f9c5305792d7e63c69184ffff1ea32 Mon Sep 17 00:00:00 2001 From: Spatison <137375981+Spatison@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:20:17 +0300 Subject: [PATCH] rewiew --- .../MenuBar/GameTopMenuBarUIController.cs | 2 +- .../UI/Emotions/EmotionsUIController.cs | 71 +++++++++++++------ .../UI/Emotions/Windows/EmotionsWindow.xaml | 12 ---- .../Emotions/Windows/EmotionsWindow.xaml.cs | 14 ---- 4 files changed, 49 insertions(+), 50 deletions(-) delete mode 100644 Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml delete mode 100644 Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml.cs diff --git a/Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs b/Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs index 29cb974843..4e3420d5c0 100644 --- a/Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs +++ b/Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs @@ -49,7 +49,7 @@ public void UnloadButtons() _action.UnloadButton(); _sandbox.UnloadButton(); _language.UnloadButton(); - _emotions.LoadButton(); // WD EDIT + _emotions.UnloadButton(); // WD EDIT } public void LoadButtons() diff --git a/Content.Client/_White/UI/Emotions/EmotionsUIController.cs b/Content.Client/_White/UI/Emotions/EmotionsUIController.cs index d11b27e88c..0151c6b44c 100644 --- a/Content.Client/_White/UI/Emotions/EmotionsUIController.cs +++ b/Content.Client/_White/UI/Emotions/EmotionsUIController.cs @@ -1,5 +1,4 @@ using System.Linq; -using Content.Client._White.UI.Emotions.Windows; using Content.Client.Chat.Managers; using Content.Client.Gameplay; using Content.Client.UserInterface.Controls; @@ -8,6 +7,7 @@ using Content.Shared.Input; using Robust.Client.UserInterface.Controllers; using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Input.Binding; using Robust.Shared.Prototypes; using Robust.Shared.Random; @@ -20,8 +20,7 @@ public sealed class EmotionsUIController : UIController, IOnStateChanged UIManager.GetActiveUIWidgetOrNull()?.EmotionsButton; private DateTime _lastEmotionTimeUse = DateTime.Now; @@ -29,28 +28,16 @@ public sealed class EmotionsUIController : UIController, IOnStateChanged(); + _window = FormMenu(); _window.OnOpen += OnWindowOpened; _window.OnClose += OnWindowClosed; - var emotions = _prototypeManager.EnumeratePrototypes().ToList(); - emotions.Sort((a,b) => string.Compare(Loc.GetString(a.ButtonText), Loc.GetString(b.ButtonText.ToString()), StringComparison.Ordinal)); - - foreach (var emote in emotions) - { - if (!emote.AllowToEmotionsMenu) - continue; - - var button = CreateEmoteButton(emote); - _window.EmotionsContainer.AddChild(button); - } - CommandBinds.Builder .Bind(ContentKeyFunctions.OpenEmotionsMenu, InputCmdHandler.FromDelegate(_ => ToggleWindow())) .Register(); - } + } public void OnStateExited(GameplayState state) { @@ -125,13 +112,51 @@ private void UseEmote(string emote) private Button CreateEmoteButton(EmotePrototype emote) { - var control = new Button(); + var control = new Button + { + ClipText = true, + HorizontalExpand = true, + VerticalExpand = true, + MinWidth = 120, + MaxWidth = 250, + MaxHeight = 35, + TextAlign = Label.AlignMode.Left, + Text = Loc.GetString(emote.ButtonText) + }; + control.OnPressed += _ => UseEmote(Loc.GetString(_random.Pick(emote.ChatMessages))); - control.Text = Loc.GetString(emote.ButtonText); - control.HorizontalExpand = true; - control.VerticalExpand = true; - control.MaxWidth = 250; - control.MaxHeight = 50; return control; } + + private DefaultWindow FormMenu() + { + var window = new DefaultWindow + { + Title = Loc.GetString("emotions-menu-title"), + VerticalExpand = true, + HorizontalExpand = true, + MinHeight = 250, + MinWidth = 300 + }; + + var grid = new GridContainer + { + Columns = 3 + }; + + var emotions = _prototypeManager.EnumeratePrototypes().ToList(); + emotions.Sort((a,b) => string.Compare(Loc.GetString(a.ButtonText), Loc.GetString(b.ButtonText.ToString()), StringComparison.Ordinal)); + + foreach (var emote in emotions) + { + if (!emote.AllowToEmotionsMenu) + continue; + + var button = CreateEmoteButton(emote); + grid.AddChild(button); + } + + window.Contents.AddChild(grid); + return window; + } } diff --git a/Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml b/Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml deleted file mode 100644 index 11c379ba61..0000000000 --- a/Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml.cs b/Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml.cs deleted file mode 100644 index 0e3961990a..0000000000 --- a/Content.Client/_White/UI/Emotions/Windows/EmotionsWindow.xaml.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Robust.Client.AutoGenerated; -using Robust.Client.UserInterface.CustomControls; -using Robust.Client.UserInterface.XAML; - -namespace Content.Client._White.UI.Emotions.Windows; - -[GenerateTypedNameReferences] -public sealed partial class EmotionsWindow : DefaultWindow -{ - public EmotionsWindow() - { - RobustXamlLoader.Load(this); - } -}