quick fixes

This commit is contained in:
EnefFlow
2024-01-27 16:02:34 +03:00
committed by Aviu00
parent 2e8ce99380
commit 63c354eadb
24 changed files with 75 additions and 420 deletions

View File

@@ -1,3 +1,4 @@
using Content.Client._White.UserInterface.Radial;
using Content.Client.White.UserInterface.Controls;
using Content.Shared.White.CheapSurgery;
using Robust.Client.GameObjects;

View File

@@ -1,4 +1,5 @@
using System.Linq;
using Content.Client._White.UserInterface.Radial;
using Content.Client.CombatMode;
using Content.Client.ContextMenu.UI;
using Content.Client.Gameplay;

View File

@@ -1,18 +0,0 @@
<Control
xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.White.UserInterface.Controls">
<BoxContainer>
<TextureButton
Name="Controller"
Access="Public"
VerticalExpand="True"
HorizontalExpand="True">
<TextureRect Access="Public" Name="BackgroundTexture"
VerticalExpand="True"
HorizontalExpand="True"
VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="KeepAspect">
</TextureRect>
</TextureButton>
</BoxContainer>
</Control>

View File

@@ -1,40 +0,0 @@
using System.Numerics;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Animations;
using Robust.Shared.Timing;
namespace Content.Client.White.UserInterface.Controls;
[GenerateTypedNameReferences, Virtual, PublicAPI]
public sealed partial class RadialButton : Control
{
[Animatable] public Vector2 Offset { get; set; }
public string? Content { get; set; }
public string Texture
{
set => Controller.TexturePath = value;
}
[Animatable]
public Vector2 ButtonSize
{
get => this.Size;
set => this.SetSize = value;
}
public RadialButton()
{
RobustXamlLoader.Load(this);
Offset = Vector2.Zero;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
}
}

View File

@@ -1,19 +0,0 @@
<controls:RadialContainer
xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.White.UserInterface.Controls"
Visible="False"
MaxSize="0 0">
<BoxContainer>
<controls:RadialButton
Name="CloseButton"
Access="Public"
VerticalExpand="True"
HorizontalExpand="True"
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">
<Label Access="Public" Name="ActionLabel" HorizontalExpand="True" Visible="False"/>
</BoxContainer>
</BoxContainer>
</controls:RadialContainer>

View File

@@ -1,302 +0,0 @@
using System.Linq;
using System.Numerics;
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.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.Animations;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.White.UserInterface.Controls;
public sealed class RadialContainerCommandTest : LocalizedCommands
{
public override string Command => "radialtest";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var radial = new RadialContainer();
for (int i = 0; i < 24; i++)
{
var testButton = radial.AddButton("Action " + i, "/Textures/Interface/emotions.svg.192dpi.png");
testButton.Controller.OnPressed += _ => { Logger.Debug("Press gay"); };
}
radial.CloseButton.Controller.OnPressed += _ =>
{
Logger.Debug("Close event for your own logic");
};
radial.OpenCentered();
}
}
[GenerateTypedNameReferences, Virtual]
public partial class RadialContainer : Control
{
private bool _isOpened;
private Vector2 _focusSize = new(64, 64);
private Vector2 _normalSize = new(50, 50);
private IResourceCache _resourceCache;
private const int MaxButtons = 8;
private const string BackgroundTexture = "/Textures/Interface/Default/SlotBackground.png";
public const string MoveAnimationKey = "move";
public const string InSizeAnimationKey = "insize";
public const string OutSizeAnimationKey = "outsize";
public float FocusSize
{
get => _focusSize.Y;
set => _focusSize = new Vector2(value, value);
}
public float NormalSize
{
get => _normalSize.Y;
set => _normalSize = new Vector2(value, value);
}
public float MoveAnimationTime { get; set; } = 0.3f;
public float FocusAnimationTime { get; set; } = 0.25f;
public bool IsAction = true;
public RadialContainer()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_resourceCache = IoCManager.Resolve<IResourceCache>();
}
public void Open(Vector2 position)
{
AddToRoot();
LayoutContainer.SetPosition(this, position);
UpdateButtons();
}
public void OpenCentered()
{
AddToRoot();
if (Parent != null)
LayoutContainer.SetPosition(this, Parent.Size / 2 - Size / 2);
else
LayoutContainer.SetPosition(this, UserInterfaceManager.MainViewport.Size / 2 - Size / 2);
UpdateButtons();
}
public void OpenCenteredWithViewport()
{
if (UserInterfaceManager.ActiveScreen == null)
return;
var ent = IoCManager.Resolve<IPlayerManager>().LocalSession?.AttachedEntity;
if (ent == null)
return;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(ent, out TransformComponent? xform))
return;
AddToRoot();
var position = IoCManager.Resolve<TransformSystem>().GetMapCoordinates(xform);
LayoutContainer.SetPosition(this,
IoCManager.Resolve<IEyeManager>().MapToScreen(position).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)
{
var button = new RadialButton();
button.Content = action;
button.Controller.TextureNormal = _resourceCache.GetTexture(BackgroundTexture);
if (texture != null)
button.BackgroundTexture.Texture = _resourceCache.GetTexture(texture);
Layout.AddChild(button);
return button;
}
public RadialButton AddButton(string action, Texture texture)
{
var button = new RadialButton();
button.Content = action;
button.Controller.TextureNormal = _resourceCache.GetTexture(BackgroundTexture);
button.BackgroundTexture.Texture = texture;
Layout.AddChild(button);
return button;
}
private void AddToRoot()
{
if (_isOpened)
return;
UserInterfaceManager.WindowRoot.AddChild(this);
_isOpened = !_isOpened;
}
private void UpdateButtons()
{
Visible = true;
var angleDegrees = 360 / Layout.ChildCount;
var stepAngle = -angleDegrees + -90;
var distance = FocusSize * 1.2;
if (Layout.Children.Count() > MaxButtons)
{
for (int i = 0; i < (Layout.Children.Count() - MaxButtons); i++)
{
distance += (NormalSize / 3);
}
}
foreach (var child in Layout.Children)
{
var button = (RadialButton) child;
button.ButtonSize = _normalSize;
stepAngle += angleDegrees;
var pos = GetPointFromPolar(stepAngle, distance);
PlayRadialAnimation(button, pos, MoveAnimationKey);
button.Controller.OnMouseEntered += _ =>
{
PlaySizeAnimation(button, _focusSize, OutSizeAnimationKey, InSizeAnimationKey);
ActionLabel.Text = button.Content ?? string.Empty;
ActionLabel.Visible = IsAction;
};
button.Controller.OnMouseExited += _ =>
{
PlaySizeAnimation(button, _normalSize, InSizeAnimationKey, OutSizeAnimationKey);
ActionLabel.Visible = false;
};
}
CloseButton.ButtonSize = _normalSize;
CloseButton.Controller.OnMouseEntered += _ =>
{
PlaySizeAnimation(CloseButton, _focusSize, OutSizeAnimationKey, InSizeAnimationKey);
ActionLabel.Text = CloseButton.Content ?? string.Empty;
ActionLabel.Visible = true;
};
CloseButton.Controller.OnMouseExited += _ =>
{
PlaySizeAnimation(CloseButton, _normalSize, InSizeAnimationKey, OutSizeAnimationKey);
ActionLabel.Visible = false;
};
CloseButton.Controller.OnPressed += _ =>
{
Close();
};
}
private void PlayRadialAnimation(Control button, Vector2 pos, string playKey)
{
var anim = new Animation
{
Length = TimeSpan.FromMilliseconds(MoveAnimationTime * 1000),
AnimationTracks =
{
new AnimationTrackControlProperty
{
Property = nameof(RadialButton.Offset),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(new Vector2(0, 0), 0f),
new AnimationTrackProperty.KeyFrame(pos, MoveAnimationTime)
}
}
}
};
if (!button.HasRunningAnimation(playKey))
button.PlayAnimation(anim, playKey);
}
private void PlaySizeAnimation(Control button, Vector2 size, string playKey, string? stopKey)
{
var anim = new Animation
{
Length = TimeSpan.FromMilliseconds(FocusAnimationTime * 1000),
AnimationTracks =
{
new AnimationTrackControlProperty
{
Property = nameof(RadialButton.ButtonSize),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(button.Size, 0f),
new AnimationTrackProperty.KeyFrame(size, FocusAnimationTime)
}
}
}
};
if (stopKey != null && button.HasRunningAnimation(stopKey))
button.StopAnimation(stopKey);
if (!button.HasRunningAnimation(playKey))
button.PlayAnimation(anim, playKey);
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
foreach (var child in Layout.Children)
{
var button = (RadialButton) child;
LayoutContainer.SetPosition(child, button.Offset - (button.Size / 2));
}
LayoutContainer.SetPosition(CloseButton, CloseButton.Offset - (CloseButton.Size / 2));
LayoutContainer.SetPosition(ActionBox, new Vector2(0 - (ActionLabel.Size.X), FocusSize * 1.5f));
}
private static Vector2 GetPointFromPolar(double angleDegrees, double distance)
{
var angleRadians = angleDegrees * (Math.PI / 180.0);
var x = distance * Math.Cos(angleRadians);
var y = distance * Math.Sin(angleRadians);
return new Vector2((int) Math.Round(x), (int) Math.Round(y));
}
}

View File

@@ -2,6 +2,7 @@
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Player;
namespace Content.Client._White.Cult;