From af4c6373f68360ff56d6b9695b1323b3b00fe28b Mon Sep 17 00:00:00 2001 From: ike709 Date: Fri, 10 May 2024 19:21:18 -0700 Subject: [PATCH] Adds Support for Guidebook Buttons in UIs (#27891) * Adds Support for Guidebook Buttons in UIs * read it from the component * the code is perfect * moony review --------- Co-authored-by: ike709 --- .../UI/ReagentDispenserBoundUserInterface.cs | 2 ++ Content.Client/Guidebook/GuidebookSystem.cs | 5 ++++ Content.Client/Stylesheets/StyleBase.cs | 1 + Content.Client/Stylesheets/StyleNano.cs | 11 +++++++ .../UserInterface/Controls/FancyWindow.xaml | 1 + .../Controls/FancyWindow.xaml.cs | 27 ++++++++++++++++++ Resources/Textures/Interface/Nano/help.png | Bin 0 -> 636 bytes 7 files changed, 47 insertions(+) create mode 100644 Resources/Textures/Interface/Nano/help.png diff --git a/Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs b/Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs index fce57a6ec5..99e5a3d395 100644 --- a/Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs +++ b/Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs @@ -1,3 +1,4 @@ +using Content.Client.Guidebook.Components; using Content.Shared.Chemistry; using Content.Shared.Containers.ItemSlots; using JetBrains.Annotations; @@ -34,6 +35,7 @@ namespace Content.Client.Chemistry.UI _window = new() { Title = EntMan.GetComponent(Owner).EntityName, + HelpGuidebookIds = EntMan.GetComponent(Owner).Guides }; _window.OpenCentered(); diff --git a/Content.Client/Guidebook/GuidebookSystem.cs b/Content.Client/Guidebook/GuidebookSystem.cs index cb13d4ca6e..0aa2c85142 100644 --- a/Content.Client/Guidebook/GuidebookSystem.cs +++ b/Content.Client/Guidebook/GuidebookSystem.cs @@ -80,6 +80,11 @@ public sealed class GuidebookSystem : EntitySystem }); } + public void OpenHelp(List guides) + { + OnGuidebookOpen?.Invoke(guides, null, null, true, guides[0]); + } + private void OnInteract(EntityUid uid, GuideHelpComponent component, ActivateInWorldEvent args) { if (!_timing.IsFirstTimePredicted) diff --git a/Content.Client/Stylesheets/StyleBase.cs b/Content.Client/Stylesheets/StyleBase.cs index 5068f97e36..76b77cbe63 100644 --- a/Content.Client/Stylesheets/StyleBase.cs +++ b/Content.Client/Stylesheets/StyleBase.cs @@ -1,5 +1,6 @@ using System.Numerics; using Content.Client.Resources; +using Content.Client.UserInterface.Controls; using Robust.Client.Graphics; using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; diff --git a/Content.Client/Stylesheets/StyleNano.cs b/Content.Client/Stylesheets/StyleNano.cs index 8707d70766..6a5e0d82a2 100644 --- a/Content.Client/Stylesheets/StyleNano.cs +++ b/Content.Client/Stylesheets/StyleNano.cs @@ -1389,6 +1389,17 @@ namespace Content.Client.Stylesheets Element().Class("WindowHeadingBackgroundLight") .Prop("panel", new StyleBoxTexture(BaseButtonOpenLeft) { Padding = default }), + // Window Header Help Button + Element().Class(FancyWindow.StyleClassWindowHelpButton) + .Prop(TextureButton.StylePropertyTexture, resCache.GetTexture("/Textures/Interface/Nano/help.png")) + .Prop(Control.StylePropertyModulateSelf, Color.FromHex("#4B596A")), + + Element().Class(FancyWindow.StyleClassWindowHelpButton).Pseudo(ContainerButton.StylePseudoClassHover) + .Prop(Control.StylePropertyModulateSelf, Color.FromHex("#7F3636")), + + Element().Class(FancyWindow.StyleClassWindowHelpButton).Pseudo(ContainerButton.StylePseudoClassPressed) + .Prop(Control.StylePropertyModulateSelf, Color.FromHex("#753131")), + //The lengths you have to go through to change a background color smh Element().Class("PanelBackgroundBaseDark") .Prop("panel", new StyleBoxTexture(BaseButtonOpenBoth) { Padding = default }) diff --git a/Content.Client/UserInterface/Controls/FancyWindow.xaml b/Content.Client/UserInterface/Controls/FancyWindow.xaml index d076a552bf..84d0499b3a 100644 --- a/Content.Client/UserInterface/Controls/FancyWindow.xaml +++ b/Content.Client/UserInterface/Controls/FancyWindow.xaml @@ -11,6 +11,7 @@ diff --git a/Content.Client/UserInterface/Controls/FancyWindow.xaml.cs b/Content.Client/UserInterface/Controls/FancyWindow.xaml.cs index 8cdfe57dba..5912687fc3 100644 --- a/Content.Client/UserInterface/Controls/FancyWindow.xaml.cs +++ b/Content.Client/UserInterface/Controls/FancyWindow.xaml.cs @@ -1,7 +1,10 @@ using System.Numerics; +using Content.Client.Guidebook; +using Content.Client.Guidebook.Components; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Prototypes; namespace Content.Client.UserInterface.Controls { @@ -9,13 +12,17 @@ namespace Content.Client.UserInterface.Controls [Virtual] public partial class FancyWindow : BaseWindow { + [Dependency] private readonly IEntitySystemManager _sysMan = default!; + private GuidebookSystem? _guidebookSystem; private const int DRAG_MARGIN_SIZE = 7; + public const string StyleClassWindowHelpButton = "windowHelpButton"; public FancyWindow() { RobustXamlLoader.Load(this); CloseButton.OnPressed += _ => Close(); + HelpButton.OnPressed += _ => Help(); XamlChildren = ContentsContainer.Children; } @@ -25,6 +32,26 @@ namespace Content.Client.UserInterface.Controls set => WindowTitle.Text = value; } + private List? _helpGuidebookIds; + public List? HelpGuidebookIds + { + get => _helpGuidebookIds; + set + { + _helpGuidebookIds = value; + HelpButton.Disabled = _helpGuidebookIds == null; + HelpButton.Visible = !HelpButton.Disabled; + } + } + + public void Help() + { + if (HelpGuidebookIds is null) + return; + _guidebookSystem ??= _sysMan.GetEntitySystem(); + _guidebookSystem.OpenHelp(HelpGuidebookIds); + } + protected override DragMode GetDragModeFor(Vector2 relativeMousePos) { var mode = DragMode.Move; diff --git a/Resources/Textures/Interface/Nano/help.png b/Resources/Textures/Interface/Nano/help.png new file mode 100644 index 0000000000000000000000000000000000000000..17f5283334170f6dd11eb561bb9e0736d6560bbf GIT binary patch literal 636 zcmV-?0)zdDP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGxh5!H^h5=oo6M+B#02y>eSaefwW^{L9 za%BK_cXuvnZfkR6VQ^(GZ*pgw?mQX*00HbtL_t(YOWl;QN*qxXhG!Nb3F(AvBU>8M zDTtMV+9eUeq!x@%kQdlGUBJ>5K7gXwgrrGpm820-lvqTv#de8yMrQr~bAMN7XT{i9 z!?IBk`4ZPd(t-&oP)7lj{r3=`<6EK9wVX zu_}Ro;{LMhbJcyJ8Sj+5pql0AwtROe%va7ICf*i zssyb`^#wD#)?IL0?#)^y5c_UCw<>{esSnSrO3?qICV9vzfzUNoW5cQht>5m~txBjT zTwa08Q!B`=yWqZY=piv^)dlxTo5*detotF!^Eh`;Yx1X%*TA(%$IKPUB=CBO^;Bg` z&Se;SNCf=)vUPx}yb8*kI^I3`z`8#SOleTC)~B*zKS#VK9;l|R@5f)yoscT8uL485 zy1K>zYq3pi5%KR|Lapn3`=Qri(<%{9)eF8&y!2>=fBq#7(T&m