diff --git a/Content.Client/UserInterface/GameHud.cs b/Content.Client/UserInterface/GameHud.cs index a147d828bd..cb3e8169e9 100644 --- a/Content.Client/UserInterface/GameHud.cs +++ b/Content.Client/UserInterface/GameHud.cs @@ -1,10 +1,13 @@ using System; using Content.Client.Utility; +using Robust.Client.Graphics; +using Robust.Client.Graphics.Drawing; using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Maths; namespace Content.Client.UserInterface { @@ -22,9 +25,7 @@ namespace Content.Client.UserInterface /// internal sealed class GameHud : IGameHud { - public const string StyleClassTopMenuButton = "topMenuButton"; - - private TextureButton _buttonEscapeMenu; + private TopButton _buttonEscapeMenu; #pragma warning disable 649 [Dependency] private readonly IResourceCache _resourceCache; @@ -37,19 +38,17 @@ namespace Content.Client.UserInterface RootControl.SetAnchorPreset(Control.LayoutPreset.Wide); - _buttonEscapeMenu = new TextureButton + var escapeTexture = _resourceCache.GetTexture("/Textures/UserInterface/hamburger.svg.96dpi.png"); + + _buttonEscapeMenu = new TopButton(escapeTexture, "esc") { - TextureNormal = _resourceCache.GetTexture("/Textures/UserInterface/hamburger.svg.96dpi.png"), - ToggleMode = true, ToolTip = _localizationManager.GetString("Open escape menu.") }; - _buttonEscapeMenu.OnToggled += args => { EscapeButtonToggled?.Invoke(args.Pressed); }; - - _buttonEscapeMenu.AddStyleClass(StyleClassTopMenuButton); + _buttonEscapeMenu.OnToggled += args => EscapeButtonToggled?.Invoke(args.Pressed); RootControl.AddChild(_buttonEscapeMenu); - _buttonEscapeMenu.SetAnchorAndMarginPreset(Control.LayoutPreset.TopLeft, margin: 20); + _buttonEscapeMenu.SetAnchorAndMarginPreset(Control.LayoutPreset.TopLeft, margin: 10); } public Control RootControl { get; private set; } @@ -61,5 +60,108 @@ namespace Content.Client.UserInterface } public Action EscapeButtonToggled { get; set; } + + + public sealed class TopButton : BaseButton + { + private static readonly Color ColorNormal = Color.FromHex("#7b7e9e"); + private static readonly Color ColorHovered = Color.FromHex("#9699bb"); + private static readonly Color ColorPressed = Color.FromHex("#00b061"); + + private readonly VBoxContainer _container; + private readonly TextureRect _textureRect; + private readonly Label _label; + + public TopButton(Texture texture, string keyName) + { + ToggleMode = true; + + _container = new VBoxContainer {MouseFilter = MouseFilterMode.Ignore}; + AddChild(_container); + _container.AddChild(_textureRect = new TextureRect + { + Texture = texture, + SizeFlagsHorizontal = SizeFlags.ShrinkCenter, + MouseFilter = MouseFilterMode.Ignore, + ModulateSelfOverride = ColorNormal + }); + + _container.AddChild(_label = new Label + { + Text = keyName, + SizeFlagsHorizontal = SizeFlags.ShrinkCenter, + MouseFilter = MouseFilterMode.Ignore, + ModulateSelfOverride = ColorNormal + }); + + _container.SetAnchorAndMarginPreset(LayoutPreset.Wide); + + DrawModeChanged(); + } + + protected override Vector2 CalculateMinimumSize() + { + var styleSize = ActualStyleBox?.MinimumSize ?? Vector2.Zero; + return (0, 4) + styleSize + _container?.CombinedMinimumSize ?? Vector2.Zero; + } + + protected override void Draw(DrawingHandleScreen handle) + { + ActualStyleBox?.Draw(handle, PixelSizeBox); + } + + private StyleBox ActualStyleBox + { + get + { + TryGetStyleProperty(Button.StylePropertyStyleBox, out StyleBox ret); + return ret; + } + } + + protected override void DrawModeChanged() + { + switch (DrawMode) + { + case DrawModeEnum.Normal: + StylePseudoClass = Button.StylePseudoClassNormal; + _textureRect.ModulateSelfOverride = ColorNormal; + _label.ModulateSelfOverride = ColorNormal; + break; + + case DrawModeEnum.Pressed: + StylePseudoClass = Button.StylePseudoClassPressed; + _textureRect.ModulateSelfOverride = ColorPressed; + _label.ModulateSelfOverride = ColorPressed; + break; + + case DrawModeEnum.Hover: + StylePseudoClass = Button.StylePseudoClassHover; + _textureRect.ModulateSelfOverride = ColorHovered; + _label.ModulateSelfOverride = ColorHovered; + break; + + case DrawModeEnum.Disabled: + break; + } + } + + protected override void StylePropertiesChanged() + { + base.StylePropertiesChanged(); + + if (_container == null) + { + return; + } + + var box = ActualStyleBox ?? new StyleBoxEmpty(); + + _container.MarginLeft = box.GetContentMargin(StyleBox.Margin.Left); + _container.MarginRight = -box.GetContentMargin(StyleBox.Margin.Right); + _container.MarginTop = box.GetContentMargin(StyleBox.Margin.Top) + 4; + _container.MarginBottom = -box.GetContentMargin(StyleBox.Margin.Bottom); + } + } } } diff --git a/Content.Client/UserInterface/NanoStyle.cs b/Content.Client/UserInterface/NanoStyle.cs index 926d9296fc..6956ad8e17 100644 --- a/Content.Client/UserInterface/NanoStyle.cs +++ b/Content.Client/UserInterface/NanoStyle.cs @@ -442,20 +442,23 @@ namespace Content.Client.UserInterface new StyleProperty(Label.StylePropertyFontColor, new Color(0.024f, 0.8f, 0.0f)) }), - // Those buttons on the top left. - new StyleRule(new SelectorElement(typeof(TextureButton), new []{GameHud.StyleClassTopMenuButton}, null, TextureButton.StylePseudoClassNormal), new [] + // Those top menu buttons. + new StyleRule( + new SelectorElement(typeof(GameHud.TopButton), null, null, Button.StylePseudoClassNormal), new [] { - new StyleProperty(Control.StylePropertyModulateSelf, Color.FromHex("#7b7e9e")) + new StyleProperty(Button.StylePropertyStyleBox, buttonNormal), }), - new StyleRule(new SelectorElement(typeof(TextureButton), new []{GameHud.StyleClassTopMenuButton}, null, TextureButton.StylePseudoClassHover), new [] + new StyleRule( + new SelectorElement(typeof(GameHud.TopButton), null, null, Button.StylePseudoClassPressed), new [] { - new StyleProperty(Control.StylePropertyModulateSelf, Color.FromHex("#8285a3")) + new StyleProperty(Button.StylePropertyStyleBox, buttonPressed), }), - new StyleRule(new SelectorElement(typeof(TextureButton), new []{GameHud.StyleClassTopMenuButton}, null, TextureButton.StylePseudoClassPressed), new [] + new StyleRule( + new SelectorElement(typeof(GameHud.TopButton), null, null, Button.StylePseudoClassHover), new [] { - new StyleProperty(Control.StylePropertyModulateSelf, Color.FromHex("#00b061")) + new StyleProperty(Button.StylePropertyStyleBox, buttonHover), }), }); }