- add: new lobby and ui tweaks. (#7)

* base

* arrow pointer for buttons

* some progress for text buttons, need cleaning

* fixed observe button, remove fraction

* just for now

* ui tweaks

* more ui tweaks

* feat: ченджлог в лобби

---------

Co-authored-by: Remuchi <RemuchiOfficial@gmail.com>
This commit is contained in:
rhailrake
2024-01-31 12:54:38 +00:00
committed by GitHub
parent 7c6beaa70f
commit 7872502bf8
97 changed files with 1187 additions and 339 deletions

View File

@@ -0,0 +1,34 @@
using Robust.Client.Console;
namespace Content.Client._Ohio.Buttons;
[Virtual]
public class OhioCommandButton : OhioLobbyTextButton
{
public string? Command { get; set; }
public OhioCommandButton()
{
OnPressed += Execute;
}
private bool CanPress()
{
return string.IsNullOrEmpty(Command) ||
IoCManager.Resolve<IClientConGroupController>().CanCommand(Command.Split(' ')[0]);
}
protected override void EnteredTree()
{
if (!CanPress())
{
Visible = false;
}
}
protected virtual void Execute(ButtonEventArgs obj)
{
if (!string.IsNullOrEmpty(Command))
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(Command);
}
}

View File

@@ -0,0 +1,211 @@
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
namespace Content.Client._Ohio.Buttons;
[Virtual]
public class OhioLobbyButton : BaseButton
{
private Vector2 _scale = new(1, 1);
private Texture? _texture;
private Texture? _textureDefault;
private Texture? _textureHighLighted;
private Texture? _texturePressed;
private Texture? _textureDisabled;
private string? _texturePath;
private string? _textureHighLightedPath;
private string? _texturePressedPath;
private string? _textureDisabledPath;
private Texture? _arrowTexture;
private string? _arrowTexturePath = "/Textures/Ohio/Lobby/arrow.png";
public OhioLobbyButton()
{
_arrowTexture = Theme.ResolveTexture(_arrowTexturePath);
DrawModeChanged();
}
// Textures GET-SET Start
[ViewVariables]
private Texture? TextureNormal
{
get => _texture;
set
{
_texture = value;
InvalidateMeasure();
}
}
[ViewVariables]
public Texture? TextureDefault
{
get => _textureDefault;
set
{
_textureDefault = value;
InvalidateMeasure();
}
}
[ViewVariables]
public Texture? TextureHighLighted
{
get => _textureHighLighted;
set
{
_textureHighLighted = value;
InvalidateMeasure();
}
}
[ViewVariables]
public Texture? TexturePressed
{
get => _texturePressed;
set
{
_texturePressed = value;
InvalidateMeasure();
}
}
[ViewVariables]
public Texture? TextureDisabled
{
get => _textureDisabled;
set
{
_textureDisabled = value;
InvalidateMeasure();
}
}
// Textures GET-SET END
// Textures Path GET-SET START
public string TexturePath
{
set
{
_texturePath = value;
TextureNormal = Theme.ResolveTexture(_texturePath);
TextureDefault = TextureNormal;
}
}
public string TextureHighLightedPath
{
set
{
_textureHighLightedPath = value;
TextureHighLighted = Theme.ResolveTexture(_textureHighLightedPath);
}
}
public string TexturePressedPath
{
set
{
_texturePressedPath = value;
TexturePressed = Theme.ResolveTexture(_texturePressedPath);
}
}
public string TextureDisabledPath
{
set
{
_textureDisabledPath = value;
TextureDisabled = Theme.ResolveTexture(_textureDisabledPath);
}
}
// Textures Path GET-SET END
// Arrow Texture GET-SET START
public Texture? ArrowTexture
{
get => _arrowTexture;
set
{
_arrowTexture = value;
InvalidateMeasure();
}
}
public string ArrowTexturePath
{
set
{
_arrowTexturePath = value;
ArrowTexture = Theme.ResolveTexture(_arrowTexturePath);
}
}
// Arrow Texture GET-SET END
public Vector2 Scale
{
get => _scale;
set
{
_scale = value;
InvalidateMeasure();
}
}
protected override void DrawModeChanged()
{
_texture = DrawMode switch
{
DrawModeEnum.Normal => _textureDefault,
DrawModeEnum.Pressed => _texturePressed,
DrawModeEnum.Hover => _textureHighLighted,
DrawModeEnum.Disabled => _textureDisabled,
_ => _textureDefault
};
}
protected override void Draw(DrawingHandleScreen handle)
{
var texture = TextureNormal;
if (texture == null)
return;
handle.DrawTextureRectRegion(texture, PixelSizeBox);
// Draw the arrow indicator when selected
if (IsHovered)
{
var arrowTexture = _arrowTexture;
if (arrowTexture == null)
{
return;
}
var arrowPosition = new Vector2(SizeBox.Right - 150, SizeBox.Top + (SizeBox.Height - arrowTexture.Size.Y) / 2);
handle.DrawTextureRectRegion(arrowTexture, UIBox2.FromDimensions(arrowPosition, arrowTexture.Size));
}
}
protected override Vector2 MeasureOverride(Vector2 availableSize)
{
var texture = TextureNormal;
return Scale * (texture?.Size ?? Vector2.Zero);
}
}

View File

@@ -0,0 +1,132 @@
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using Color = Robust.Shared.Maths.Color;
namespace Content.Client._Ohio.Buttons;
[Virtual]
public class OhioLobbyTextButton : TextureButton // ShitCode Edition
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
private readonly Font _font;
private string? _buttonText;
public string ButtonText
{
set => _buttonText = value;
}
public OhioLobbyTextButton()
{
IoCManager.InjectDependencies(this);
_font = new VectorFont(_resourceCache.GetResource<FontResource>("/Fonts/Bedstead/Bedstead.otf"), 15);
}
private void RebuildTexture()
{
if (_buttonText == null)
return;
var fontMeasure = MeasureText(_font, _buttonText);
var blank = new Image<Rgba32>((int)fontMeasure.X, (int)fontMeasure.Y);
blank[0, 0] = new Rgba32(0, 0, 0, 0);
var texture = Texture.LoadFromImage(blank);
TextureNormal = texture;
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
switch (DrawMode)
{
case DrawModeEnum.Normal:
DrawNormal(handle);
break;
case DrawModeEnum.Pressed:
DrawPressed(handle);
break;
case DrawModeEnum.Hover:
DrawHover(handle);
break;
case DrawModeEnum.Disabled:
DrawDisabled(handle);
break;
}
}
private void DrawNormal(DrawingHandleScreen handle)
{
if (string.IsNullOrEmpty(_buttonText))
return;
var color = Color.White;
if (ToggleMode)
{
color = Color.Red;
}
DrawText(handle, color);
}
private void DrawHover(DrawingHandleScreen handle)
{
if (string.IsNullOrEmpty(_buttonText))
return;
DrawText(handle, Color.Yellow);
}
private void DrawDisabled(DrawingHandleScreen handle)
{
if (string.IsNullOrEmpty(_buttonText))
return;
DrawText(handle, Color.Gray);
}
private void DrawPressed(DrawingHandleScreen handle)
{
if (string.IsNullOrEmpty(_buttonText))
return;
var color = Pressed
? Color.Green
: Color.Red;
DrawText(handle, color);
}
private void DrawText(DrawingHandleScreen handle, Color color)
{
if (string.IsNullOrEmpty(_buttonText))
return;
RebuildTexture();
handle.DrawString(
_font,
Vector2.Zero,
_buttonText!,
color
);
}
private Vector2 MeasureText(Font font, string text)
{
var textSize = font.GetHeight(0.9f);
var width = textSize * text.Length / 1.5f;
return new Vector2(width, textSize);
}
}

View File

@@ -0,0 +1,18 @@
using Robust.Client.UserInterface.CustomControls;
namespace Content.Client._Ohio.Buttons;
public sealed class OhioUICommandButton : OhioCommandButton
{
public Type? WindowType { get; set; }
private DefaultWindow? _window;
protected override void Execute(ButtonEventArgs obj)
{
if (WindowType == null)
return;
_window = (DefaultWindow) IoCManager.Resolve<IDynamicTypeFactory>().CreateInstance(WindowType);
_window?.OpenCentered();
}
}

View File

@@ -0,0 +1,91 @@
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Graphics.RSI;
using Robust.Shared.Timing;
namespace Content.Client._Ohio.UI;
public sealed class AnimatedBackgroundControl : TextureRect
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IClyde _clyde = default!;
private const string RsiPath = "/Textures/Ohio/Lobby/anim.rsi";
private const int States = 1;
private IRenderTexture? _buffer;
private readonly float[] _timer = new float[States];
private readonly float[][] _frameDelays = new float[States][];
private readonly int[] _frameCounter = new int[States];
private readonly Texture[][] _frames = new Texture[States][];
public AnimatedBackgroundControl()
{
IoCManager.InjectDependencies(this);
InitializeStates();
}
private void InitializeStates()
{
var rsi = _resourceCache.GetResource<RSIResource>(RsiPath).RSI;
for (var i = 0; i < States; i++)
{
if (!rsi.TryGetState((i + 1).ToString(), out var state))
continue;
_frames[i] = state.GetFrames(RsiDirection.South);
_frameDelays[i] = state.GetDelays();
_frameCounter[i] = 0;
}
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
for (var i = 0; i < _frames.Length; i++)
{
var delays = _frameDelays[i];
if (delays.Length == 0)
continue;
_timer[i] += args.DeltaSeconds * 0.20f;
var currentFrameIndex = _frameCounter[i];
if (!(_timer[i] >= delays[currentFrameIndex]))
continue;
_timer[i] -= delays[currentFrameIndex];
_frameCounter[i] = (currentFrameIndex + 1) % _frames[i].Length;
Texture = _frames[i][_frameCounter[i]];
}
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (_buffer is null)
return;
handle.DrawTextureRect(_buffer.Texture, PixelSizeBox);
}
protected override void Resized()
{
base.Resized();
_buffer?.Dispose();
_buffer = _clyde.CreateRenderTarget(PixelSize, RenderTargetColorFormat.Rgba8Srgb);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_buffer?.Dispose();
}
}

View File

@@ -0,0 +1,30 @@
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
namespace Content.Client._Ohio.UI;
public sealed class OhioRichTextLabel : RichTextLabel
{
private Texture? _moonTexture;
private string? _moonTexturePath = "/Textures/Ohio/Lobby/moon.png";
public OhioRichTextLabel()
{
_moonTexture = Theme.ResolveTexture(_moonTexturePath);
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
var moonTexture = _moonTexture;
if (moonTexture == null)
return;
var moonPosition = new Vector2(SizeBox.Right + 2, SizeBox.Top + (SizeBox.Height - moonTexture.Size.Y) / 2);
handle.DrawTextureRectRegion(moonTexture, UIBox2.FromDimensions(moonPosition, moonTexture.Size));
}
}