From cc45a18fea39018865f6eb9c0bc4c8f0761dfc39 Mon Sep 17 00:00:00 2001 From: DocNight Date: Thu, 29 Jun 2023 23:58:44 +0300 Subject: [PATCH] [Fix] Better Close(), added OpenCenteredWithViewport() (#183) * Better Close(), added OpenCenteredWithViewport() * Close * Update RadialContainer.xaml.cs --- .../Controls/RadialContainer.xaml | 2 +- .../Controls/RadialContainer.xaml.cs | 36 +++++++++++++++---- Resources/Locale/ru-RU/white/radial-menu.ftl | 1 + 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 Resources/Locale/ru-RU/white/radial-menu.ftl diff --git a/Content.Client/White/UserInterface/Controls/RadialContainer.xaml b/Content.Client/White/UserInterface/Controls/RadialContainer.xaml index 717e186c3b..f3897f34ea 100644 --- a/Content.Client/White/UserInterface/Controls/RadialContainer.xaml +++ b/Content.Client/White/UserInterface/Controls/RadialContainer.xaml @@ -9,7 +9,7 @@ Access="Public" VerticalExpand="True" HorizontalExpand="True" - Content="Close" + Content="{Loc 'radial-ui-close'}" Texture="/Textures/Interface/Default/blocked.png"/> diff --git a/Content.Client/White/UserInterface/Controls/RadialContainer.xaml.cs b/Content.Client/White/UserInterface/Controls/RadialContainer.xaml.cs index 46f16c8002..c24d825d6f 100644 --- a/Content.Client/White/UserInterface/Controls/RadialContainer.xaml.cs +++ b/Content.Client/White/UserInterface/Controls/RadialContainer.xaml.cs @@ -1,10 +1,12 @@ using System.Linq; using Content.Client.Gameplay; using Content.Client.Resources; +using Content.Client.Viewport; using JetBrains.Annotations; using Robust.Client.Animations; using Robust.Client.AutoGenerated; using Robust.Client.Graphics; +using Robust.Client.Player; using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -33,12 +35,10 @@ public sealed class RadialContainerCommandTest : LocalizedCommands radial.CloseButton.Controller.OnPressed += (_) => { - radial.Close(); - radial.Dispose(); + Logger.Debug("Close event for your own logic"); }; - //radial.OpenCentered(); - var usrMngr = IoCManager.Resolve(); - radial.Open(usrMngr.MousePositionScaled.Position); + + radial.OpenCentered(); } } @@ -88,6 +88,7 @@ public partial class RadialContainer : Control public RadialContainer() : base() { RobustXamlLoader.Load(this); + IoCManager.InjectDependencies(this); } public void Open(Vector2 position) @@ -107,11 +108,30 @@ public partial class RadialContainer : Control UpdateButtons(); } - public void Close() + public void OpenCenteredWithViewport() + { + if (UserInterfaceManager.ActiveScreen == null) + return; + + var ent = IoCManager.Resolve().LocalPlayer?.ControlledEntity; + if (ent == null) + return; + + if (!IoCManager.Resolve().TryGetComponent(ent, out TransformComponent? xform)) + return; + + AddToRoot(); + LayoutContainer.SetPosition(this, (IoCManager.Resolve().MapToScreen(xform.MapPosition).Position * 1.5f)); + UpdateButtons(); + } + + public void Close(bool canDispose = true) { Parent?.RemoveChild(this); Visible = false; _isOpened = false; + if (canDispose) + Dispose(); } public RadialButton AddButton(string action, string? texture = null) @@ -181,6 +201,10 @@ public partial class RadialContainer : Control PlaySizeAnimation(CloseButton, _normalSize, InSizeAnimationKey, OutSizeAnimationKey); ActionLabel.Visible = false; }; + CloseButton.Controller.OnPressed += (_) => + { + Close(); + }; } private void PlayRadialAnimation(Control button, Vector2 pos, string playKey) diff --git a/Resources/Locale/ru-RU/white/radial-menu.ftl b/Resources/Locale/ru-RU/white/radial-menu.ftl new file mode 100644 index 0000000000..23ec1870f5 --- /dev/null +++ b/Resources/Locale/ru-RU/white/radial-menu.ftl @@ -0,0 +1 @@ +radial-ui-close = Закрыть