- 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:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user