Skip to content

Commit af4c637

Browse files
ike709ike709
andauthored
Adds Support for Guidebook Buttons in UIs (space-wizards#27891)
* 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>
1 parent 9845d8b commit af4c637

File tree

7 files changed

+47
-0
lines changed

7 files changed

+47
-0
lines changed

‎Content.Client/Chemistry/UI/ReagentDispenserBoundUserInterface.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Content.Client.Guidebook.Components;
12
using Content.Shared.Chemistry;
23
using Content.Shared.Containers.ItemSlots;
34
using JetBrains.Annotations;
@@ -34,6 +35,7 @@ protected override void Open()
3435
_window = new()
3536
{
3637
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
38+
HelpGuidebookIds = EntMan.GetComponent<GuideHelpComponent>(Owner).Guides
3739
};
3840

3941
_window.OpenCentered();

‎Content.Client/Guidebook/GuidebookSystem.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ private void OnGetVerbs(EntityUid uid, GuideHelpComponent component, GetVerbsEve
8080
});
8181
}
8282

83+
public void OpenHelp(List<string> guides)
84+
{
85+
OnGuidebookOpen?.Invoke(guides, null, null, true, guides[0]);
86+
}
87+
8388
private void OnInteract(EntityUid uid, GuideHelpComponent component, ActivateInWorldEvent args)
8489
{
8590
if (!_timing.IsFirstTimePredicted)

‎Content.Client/Stylesheets/StyleBase.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Numerics;
22
using Content.Client.Resources;
3+
using Content.Client.UserInterface.Controls;
34
using Robust.Client.Graphics;
45
using Robust.Client.ResourceManagement;
56
using Robust.Client.UserInterface;

‎Content.Client/Stylesheets/StyleNano.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,17 @@ public StyleNano(IResourceCache resCache) : base(resCache)
13891389
Element<PanelContainer>().Class("WindowHeadingBackgroundLight")
13901390
.Prop("panel", new StyleBoxTexture(BaseButtonOpenLeft) { Padding = default }),
13911391

1392+
// Window Header Help Button
1393+
Element<TextureButton>().Class(FancyWindow.StyleClassWindowHelpButton)
1394+
.Prop(TextureButton.StylePropertyTexture, resCache.GetTexture("/Textures/Interface/Nano/help.png"))
1395+
.Prop(Control.StylePropertyModulateSelf, Color.FromHex("#4B596A")),
1396+
1397+
Element<TextureButton>().Class(FancyWindow.StyleClassWindowHelpButton).Pseudo(ContainerButton.StylePseudoClassHover)
1398+
.Prop(Control.StylePropertyModulateSelf, Color.FromHex("#7F3636")),
1399+
1400+
Element<TextureButton>().Class(FancyWindow.StyleClassWindowHelpButton).Pseudo(ContainerButton.StylePseudoClassPressed)
1401+
.Prop(Control.StylePropertyModulateSelf, Color.FromHex("#753131")),
1402+
13921403
//The lengths you have to go through to change a background color smh
13931404
Element<PanelContainer>().Class("PanelBackgroundBaseDark")
13941405
.Prop("panel", new StyleBoxTexture(BaseButtonOpenBoth) { Padding = default })

‎Content.Client/UserInterface/Controls/FancyWindow.xaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<BoxContainer Margin="4 2 8 0" Orientation="Horizontal">
1212
<Label Name="WindowTitle"
1313
HorizontalExpand="True" VAlign="Center" StyleClasses="FancyWindowTitle" />
14+
<TextureButton Name="HelpButton" StyleClasses="windowHelpButton" VerticalAlignment="Center" Disabled="True" Visible="False" Access="Public" />
1415
<TextureButton Name="CloseButton" StyleClasses="windowCloseButton"
1516
VerticalAlignment="Center" />
1617
</BoxContainer>

‎Content.Client/UserInterface/Controls/FancyWindow.xaml.cs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
using System.Numerics;
2+
using Content.Client.Guidebook;
3+
using Content.Client.Guidebook.Components;
24
using Robust.Client.AutoGenerated;
35
using Robust.Client.UserInterface.CustomControls;
46
using Robust.Client.UserInterface.XAML;
7+
using Robust.Shared.Prototypes;
58

69
namespace Content.Client.UserInterface.Controls
710
{
811
[GenerateTypedNameReferences]
912
[Virtual]
1013
public partial class FancyWindow : BaseWindow
1114
{
15+
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
16+
private GuidebookSystem? _guidebookSystem;
1217
private const int DRAG_MARGIN_SIZE = 7;
18+
public const string StyleClassWindowHelpButton = "windowHelpButton";
1319

1420
public FancyWindow()
1521
{
1622
RobustXamlLoader.Load(this);
1723

1824
CloseButton.OnPressed += _ => Close();
25+
HelpButton.OnPressed += _ => Help();
1926
XamlChildren = ContentsContainer.Children;
2027
}
2128

@@ -25,6 +32,26 @@ public string? Title
2532
set => WindowTitle.Text = value;
2633
}
2734

35+
private List<string>? _helpGuidebookIds;
36+
public List<string>? HelpGuidebookIds
37+
{
38+
get => _helpGuidebookIds;
39+
set
40+
{
41+
_helpGuidebookIds = value;
42+
HelpButton.Disabled = _helpGuidebookIds == null;
43+
HelpButton.Visible = !HelpButton.Disabled;
44+
}
45+
}
46+
47+
public void Help()
48+
{
49+
if (HelpGuidebookIds is null)
50+
return;
51+
_guidebookSystem ??= _sysMan.GetEntitySystem<GuidebookSystem>();
52+
_guidebookSystem.OpenHelp(HelpGuidebookIds);
53+
}
54+
2855
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
2956
{
3057
var mode = DragMode.Move;
636 Bytes
Loading

0 commit comments

Comments
 (0)