]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Adds Support for Guidebook Buttons in UIs (#27891)
authorike709 <ike709@users.noreply.github.com>
Sat, 11 May 2024 02:21:18 +0000 (19:21 -0700)
committerGitHub <noreply@github.com>
Sat, 11 May 2024 02:21:18 +0000 (22:21 -0400)
* Adds Support for Guidebook Buttons in UIs

* read it from the component

* the code is perfect

* moony review

---------

Co-authored-by: ike709 <ike709@github.com>
Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs
Content.Client/Guidebook/GuidebookSystem.cs
Content.Client/Stylesheets/StyleBase.cs
Content.Client/Stylesheets/StyleNano.cs
Content.Client/UserInterface/Controls/FancyWindow.xaml
Content.Client/UserInterface/Controls/FancyWindow.xaml.cs
Resources/Textures/Interface/Nano/help.png [new file with mode: 0644]

index fce57a6ec5863bf10579534282c71d0888293f1e..99e5a3d39536248d153f1216ad1913ac745a6fa1 100644 (file)
@@ -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<MetaDataComponent>(Owner).EntityName,
+                HelpGuidebookIds = EntMan.GetComponent<GuideHelpComponent>(Owner).Guides
             };
 
             _window.OpenCentered();
index cb13d4ca6e5bcef858a9759031e43f3629d12f2f..0aa2c85142e0410073308ac0cfe7d5b0ec9731fa 100644 (file)
@@ -80,6 +80,11 @@ public sealed class GuidebookSystem : EntitySystem
         });
     }
 
+    public void OpenHelp(List<string> guides)
+    {
+        OnGuidebookOpen?.Invoke(guides, null, null, true, guides[0]);
+    }
+
     private void OnInteract(EntityUid uid, GuideHelpComponent component, ActivateInWorldEvent args)
     {
         if (!_timing.IsFirstTimePredicted)
index 5068f97e36fd7f739e64cb90840ea02cf86b0c37..76b77cbe63fbdd6104f991ae4ec7c938837ec99a 100644 (file)
@@ -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;
index 8707d70766037026e3df88f895d8460c994b46d9..6a5e0d82a20333bc819e4b987c8e26527096e1e6 100644 (file)
@@ -1389,6 +1389,17 @@ namespace Content.Client.Stylesheets
                 Element<PanelContainer>().Class("WindowHeadingBackgroundLight")
                     .Prop("panel", new StyleBoxTexture(BaseButtonOpenLeft) { Padding = default }),
 
+                // Window Header Help Button
+                Element<TextureButton>().Class(FancyWindow.StyleClassWindowHelpButton)
+                    .Prop(TextureButton.StylePropertyTexture, resCache.GetTexture("/Textures/Interface/Nano/help.png"))
+                    .Prop(Control.StylePropertyModulateSelf, Color.FromHex("#4B596A")),
+
+                Element<TextureButton>().Class(FancyWindow.StyleClassWindowHelpButton).Pseudo(ContainerButton.StylePseudoClassHover)
+                    .Prop(Control.StylePropertyModulateSelf, Color.FromHex("#7F3636")),
+
+                Element<TextureButton>().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<PanelContainer>().Class("PanelBackgroundBaseDark")
                     .Prop("panel", new StyleBoxTexture(BaseButtonOpenBoth) { Padding = default })
index d076a552bf2a09c3b39d01383ecf2f9ce2177d58..84d0499b3a63463888970e7f5b4dac3c6ecaecc2 100644 (file)
@@ -11,6 +11,7 @@
             <BoxContainer Margin="4 2 8 0" Orientation="Horizontal">
                 <Label Name="WindowTitle"
                        HorizontalExpand="True" VAlign="Center" StyleClasses="FancyWindowTitle" />
+                <TextureButton Name="HelpButton" StyleClasses="windowHelpButton" VerticalAlignment="Center" Disabled="True" Visible="False" Access="Public" />
                 <TextureButton Name="CloseButton" StyleClasses="windowCloseButton"
                                VerticalAlignment="Center" />
             </BoxContainer>
index 8cdfe57dba2063f837c72d7c8a724482212050a7..5912687fc358f908472a37dd17c3550eaf17cf4d 100644 (file)
@@ -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<string>? _helpGuidebookIds;
+        public List<string>? 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>();
+            _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 (file)
index 0000000..17f5283
Binary files /dev/null and b/Resources/Textures/Interface/Nano/help.png differ