- 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:
34
Content.Client/_Ohio/Buttons/OhioCommandButton.cs
Normal file
34
Content.Client/_Ohio/Buttons/OhioCommandButton.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
211
Content.Client/_Ohio/Buttons/OhioLobbyButton.cs
Normal file
211
Content.Client/_Ohio/Buttons/OhioLobbyButton.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
132
Content.Client/_Ohio/Buttons/OhioLobbyTextButtons.cs
Normal file
132
Content.Client/_Ohio/Buttons/OhioLobbyTextButtons.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
18
Content.Client/_Ohio/Buttons/OhioUICommandButton.cs
Normal file
18
Content.Client/_Ohio/Buttons/OhioUICommandButton.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user