[Fix] Better Close(), added OpenCenteredWithViewport() (#183)

* Better Close(), added OpenCenteredWithViewport()

* Close

* Update RadialContainer.xaml.cs
This commit is contained in:
DocNight
2023-06-29 23:58:44 +03:00
committed by Aviu00
parent a12452645f
commit cc45a18fea
3 changed files with 32 additions and 7 deletions

View File

@@ -9,7 +9,7 @@
Access="Public" Access="Public"
VerticalExpand="True" VerticalExpand="True"
HorizontalExpand="True" HorizontalExpand="True"
Content="Close" Content="{Loc 'radial-ui-close'}"
Texture="/Textures/Interface/Default/blocked.png"/> Texture="/Textures/Interface/Default/blocked.png"/>
<LayoutContainer Access="Public" Name="Layout" HorizontalExpand="True" VerticalExpand="True"></LayoutContainer> <LayoutContainer Access="Public" Name="Layout" HorizontalExpand="True" VerticalExpand="True"></LayoutContainer>
<BoxContainer Access="Public" Name="ActionBox" HorizontalExpand="True" VerticalExpand="True"> <BoxContainer Access="Public" Name="ActionBox" HorizontalExpand="True" VerticalExpand="True">

View File

@@ -1,10 +1,12 @@
using System.Linq; using System.Linq;
using Content.Client.Gameplay; using Content.Client.Gameplay;
using Content.Client.Resources; using Content.Client.Resources;
using Content.Client.Viewport;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.Animations; using Robust.Client.Animations;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
@@ -33,12 +35,10 @@ public sealed class RadialContainerCommandTest : LocalizedCommands
radial.CloseButton.Controller.OnPressed += (_) => radial.CloseButton.Controller.OnPressed += (_) =>
{ {
radial.Close(); Logger.Debug("Close event for your own logic");
radial.Dispose();
}; };
//radial.OpenCentered();
var usrMngr = IoCManager.Resolve<IUserInterfaceManager>(); radial.OpenCentered();
radial.Open(usrMngr.MousePositionScaled.Position);
} }
} }
@@ -88,6 +88,7 @@ public partial class RadialContainer : Control
public RadialContainer() : base() public RadialContainer() : base()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
} }
public void Open(Vector2 position) public void Open(Vector2 position)
@@ -107,11 +108,30 @@ public partial class RadialContainer : Control
UpdateButtons(); UpdateButtons();
} }
public void Close() public void OpenCenteredWithViewport()
{
if (UserInterfaceManager.ActiveScreen == null)
return;
var ent = IoCManager.Resolve<IPlayerManager>().LocalPlayer?.ControlledEntity;
if (ent == null)
return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ent, out TransformComponent? xform))
return;
AddToRoot();
LayoutContainer.SetPosition(this, (IoCManager.Resolve<IEyeManager>().MapToScreen(xform.MapPosition).Position * 1.5f));
UpdateButtons();
}
public void Close(bool canDispose = true)
{ {
Parent?.RemoveChild(this); Parent?.RemoveChild(this);
Visible = false; Visible = false;
_isOpened = false; _isOpened = false;
if (canDispose)
Dispose();
} }
public RadialButton AddButton(string action, string? texture = null) public RadialButton AddButton(string action, string? texture = null)
@@ -181,6 +201,10 @@ public partial class RadialContainer : Control
PlaySizeAnimation(CloseButton, _normalSize, InSizeAnimationKey, OutSizeAnimationKey); PlaySizeAnimation(CloseButton, _normalSize, InSizeAnimationKey, OutSizeAnimationKey);
ActionLabel.Visible = false; ActionLabel.Visible = false;
}; };
CloseButton.Controller.OnPressed += (_) =>
{
Close();
};
} }
private void PlayRadialAnimation(Control button, Vector2 pos, string playKey) private void PlayRadialAnimation(Control button, Vector2 pos, string playKey)

View File

@@ -0,0 +1 @@
radial-ui-close = Закрыть