Delta-v/Content.Client/Stylesheets/Sheetlets/MenuButtonSheetlet.cs

81 lines
3.3 KiB
C#

using System.Numerics;
using Content.Client.Stylesheets.Fonts;
using Content.Client.Stylesheets.SheetletConfigs;
using Content.Client.Stylesheets.Stylesheets;
using Content.Client.UserInterface.Controls;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using static Content.Client.Stylesheets.StylesheetHelpers;
namespace Content.Client.Stylesheets.Sheetlets;
[CommonSheetlet]
public sealed class MenuButtonSheetlet<T> : Sheetlet<T> where T : PalettedStylesheet, IButtonConfig, IIconConfig
{
private static MutableSelectorElement CButton()
{
return E<MenuButton>();
}
public override StyleRule[] GetRules(T sheet, object config)
{
IButtonConfig cfg = sheet;
var buttonTex = sheet.GetTextureOr(cfg.BaseButtonPath, NanotrasenStylesheet.TextureRoot);
var topButtonBase = new StyleBoxTexture
{
Texture = buttonTex,
};
topButtonBase.SetPatchMargin(StyleBox.Margin.All, 10);
topButtonBase.SetPadding(StyleBox.Margin.All, 0);
topButtonBase.SetContentMarginOverride(StyleBox.Margin.All, 0);
var topButtonOpenRight = new StyleBoxTexture(topButtonBase)
{
Texture = new AtlasTexture(buttonTex, UIBox2.FromDimensions(new Vector2(0, 0), new Vector2(14, 24))),
};
topButtonOpenRight.SetPatchMargin(StyleBox.Margin.Right, 0);
var topButtonOpenLeft = new StyleBoxTexture(topButtonBase)
{
Texture = new AtlasTexture(buttonTex, UIBox2.FromDimensions(new Vector2(10, 0), new Vector2(14, 24))),
};
topButtonOpenLeft.SetPatchMargin(StyleBox.Margin.Left, 0);
var topButtonSquare = new StyleBoxTexture(topButtonBase)
{
Texture = new AtlasTexture(buttonTex, UIBox2.FromDimensions(new Vector2(10, 0), new Vector2(3, 24))),
};
topButtonSquare.SetPatchMargin(StyleBox.Margin.Horizontal, 0);
var rules = new List<StyleRule>
{
CButton().Class(StyleClass.ButtonSquare).Box(topButtonSquare),
CButton().Class(StyleClass.ButtonOpenLeft).Box(topButtonOpenLeft),
CButton().Class(StyleClass.ButtonOpenRight).Box(topButtonOpenRight),
CButton().Box(StyleBoxHelpers.BaseStyleBox(sheet)),
CButton()
.Class(StyleClass.ButtonOpenLeft)
.Prop(ContainerButton.StylePropertyStyleBox, StyleBoxHelpers.OpenLeftStyleBox(sheet)),
CButton()
.Class(StyleClass.ButtonOpenRight)
.Prop(ContainerButton.StylePropertyStyleBox, StyleBoxHelpers.OpenRightStyleBox(sheet)),
CButton()
.Class(StyleClass.ButtonOpenBoth)
.Prop(ContainerButton.StylePropertyStyleBox, StyleBoxHelpers.SquareStyleBox(sheet)),
CButton()
.Class(StyleClass.ButtonSquare)
.Prop(ContainerButton.StylePropertyStyleBox, StyleBoxHelpers.SquareStyleBox(sheet)),
E<Label>()
.Class(MenuButton.StyleClassLabelTopButton)
.Prop(Label.StylePropertyFont, sheet.BaseFont.GetFont(14, FontKind.Bold)),
// new StyleProperty(Label.StylePropertyFont, notoSansDisplayBold14),
};
ButtonSheetlet<T>.MakeButtonRules<MenuButton>(rules, cfg.ButtonPalette, null);
return rules.ToArray();
}
}