[Fix] Better Close(), added OpenCenteredWithViewport() (#183)
* Better Close(), added OpenCenteredWithViewport() * Close * Update RadialContainer.xaml.cs
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
Access="Public"
|
||||
VerticalExpand="True"
|
||||
HorizontalExpand="True"
|
||||
Content="Close"
|
||||
Content="{Loc 'radial-ui-close'}"
|
||||
Texture="/Textures/Interface/Default/blocked.png"/>
|
||||
<LayoutContainer Access="Public" Name="Layout" HorizontalExpand="True" VerticalExpand="True"></LayoutContainer>
|
||||
<BoxContainer Access="Public" Name="ActionBox" HorizontalExpand="True" VerticalExpand="True">
|
||||
|
||||
@@ -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<IUserInterfaceManager>();
|
||||
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<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);
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user