Skip to content

Commit

Permalink
Cooler Better and Badder Guidebooks (space-wizards#78)
Browse files Browse the repository at this point in the history
* A better revised guidebook!

* A better revised guidebook!

* funny
  • Loading branch information
Just-a-Unity-Dev authored Jul 16, 2023
1 parent b37ac0c commit 2a5faf1
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 25 deletions.
8 changes: 8 additions & 0 deletions Content.Client/Guidebook/Controls/GuideColorLabelBand.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<BoxContainer xmlns="https://spacestation14.io"
Orientation="Vertical"
Margin="5 5 5 5">
<SpriteView Name="View"/>
<PanelContainer Name="NameBackground" HorizontalExpand="True" VerticalExpand="False">
<RichTextLabel Name="NameLabel" HorizontalAlignment="Center"/>
</PanelContainer>
</BoxContainer>
119 changes: 119 additions & 0 deletions Content.Client/Guidebook/Controls/GuideColorLabelBand.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Content.Client.ContextMenu.UI;
using Content.Client.Examine;
using Content.Client.Guidebook.Richtext;
using Content.Client.Message;
using Content.Client.Verbs;
using Content.Client.Verbs.UI;
using Content.Shared.Input;
using Content.Shared.Tag;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Input;
using Robust.Shared.Map;
using Serilog;

namespace Content.Client.Guidebook.Controls;

/// <summary>
/// Adds a singular band of color alongside a caption.
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class GuideColorLabelBand : BoxContainer, IDocumentTag
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _systemManager = default!;
[Dependency] private readonly IUserInterfaceManager _ui = default!;

private readonly TagSystem _tagSystem;
private readonly GuidebookSystem _guidebookSystem;

public SpriteComponent? Sprite
{
get => View.Sprite;
set => View.Sprite = value;
}

public Vector2 Scale
{
get => View.Scale;
set => View.Scale = value;
}

public GuideColorLabelBand()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_tagSystem = _systemManager.GetEntitySystem<TagSystem>();
_guidebookSystem = _systemManager.GetEntitySystem<GuidebookSystem>();
MouseFilter = MouseFilterMode.Stop;
}

public GuideColorLabelBand(string caption, Color color, float? height) : this()
{
NameLabel.SetMarkup(caption);
NameBackground.PanelOverride = new StyleBoxFlat
{
BackgroundColor = color
};
if (height.HasValue)
NameBackground.MinHeight = height.Value;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (Sprite is not null)
_entityManager.DeleteEntity(Sprite.Owner);
}

public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out Control? control)
{
control = null;
if (!args.TryGetValue("Caption", out var caption))
{
Logger.Error("Caption doesn't exist!");
return false;
}

if (!args.TryGetValue("Color", out var colorString))
{
Logger.Error($"Specified color \"{colorString}\" is not a valid color!");
return false;
}

if (args.TryGetValue("Height", out var desiredHeight))
{
NameBackground.MinHeight = float.Parse(desiredHeight);
}

// set background
var color = Color.FromHex(colorString);

NameBackground.PanelOverride = new StyleBoxFlat
{
BackgroundColor = color
};
// sssttttttrrrrrrreeeeeeeeeeeeettttttttttcccccccccchhhhhhhhhhh
NameBackground.MinWidth = 10000000f;
NameBackground.HorizontalAlignment = HAlignment.Stretch;

// center text
NameLabel.HorizontalAlignment = HAlignment.Center;
NameLabel.VerticalAlignment = VAlignment.Center;

// make text darker if we have a bright background
if ((color.R + color.G + color.B) > 1.5f)
NameLabel.SetMarkup("[color=#000000]" + caption);
else
NameLabel.SetMarkup(caption);
control = this;
return true;
}
}
8 changes: 7 additions & 1 deletion Content.Client/Guidebook/Controls/GuideEntityEmbed.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out

var ent = _entityManager.SpawnEntity(proto, MapCoordinates.Nullspace);

_tagSystem.AddTag(ent, GuidebookSystem.GuideEmbedTag);
if (args.TryGetValue("AllowGuideHelp", out var allowed))
{
if (!bool.Parse(allowed))
{
_tagSystem.AddTag(ent, GuidebookSystem.GuideEmbedTag);
}
}
Sprite = _entityManager.GetComponent<SpriteComponent>(ent);

if (!args.TryGetValue("Caption", out var caption))
Expand Down
11 changes: 8 additions & 3 deletions Content.Client/Guidebook/GuidebookSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Content.Client.Guidebook.Components;
using Content.Client.Light;
using Content.Client.UserInterface.Systems.Guidebook;
using Content.Client.Verbs;
using Content.Shared.Interaction;
using Content.Shared.Light.Component;
Expand Down Expand Up @@ -29,7 +30,7 @@ public sealed class GuidebookSystem : EntitySystem
[Dependency] private readonly SharedPointLightSystem _pointLightSystem = default!;
[Dependency] private readonly TagSystem _tags = default!;

public event Action<List<string>, List<string>?, string?, bool, string?>? OnGuidebookOpen;
public event Action<List<string>, List<string>?, string?, bool, string?, bool>? OnGuidebookOpen;
public const string GuideEmbedTag = "GuideEmbeded";

private EntityUid _defaultUser;
Expand Down Expand Up @@ -72,7 +73,11 @@ private void OnGetVerbs(EntityUid uid, GuideHelpComponent component, GetVerbsEve
{
Text = Loc.GetString("guide-help-verb"),
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/information.svg.192dpi.png")),
Act = () => OnGuidebookOpen?.Invoke(component.Guides, null, null, component.IncludeChildren, component.Guides[0]),
Act = () =>
{
OnGuidebookOpen?.Invoke(component.Guides, null, null, component.IncludeChildren,
component.Guides[0], true);
},
ClientExclusive = true,
CloseMenu = true
});
Expand All @@ -86,7 +91,7 @@ private void OnInteract(EntityUid uid, GuideHelpComponent component, ActivateInW
if (!component.OpenOnActivation || component.Guides.Count == 0 || _tags.HasTag(uid, GuideEmbedTag))
return;

OnGuidebookOpen?.Invoke(component.Guides, null, null, component.IncludeChildren, component.Guides[0]);
OnGuidebookOpen?.Invoke(component.Guides, null, null, component.IncludeChildren, component.Guides[0], true);
args.Handled = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ public void ToggleGuidebook(
List<string>? rootEntries = null,
string? forceRoot = null,
bool includeChildren = true,
string? selected = null)
string? selected = null,
bool forceOpen = false)
{
if (_guideWindow == null)
return;

if (_guideWindow.IsOpen)
if (_guideWindow.IsOpen && !forceOpen)
{
_guideWindow.Close();
return;
Expand Down Expand Up @@ -175,7 +176,8 @@ public void ToggleGuidebook(
List<string>? rootEntries = null,
string? forceRoot = null,
bool includeChildren = true,
string? selected = null)
string? selected = null,
bool forceOpen = false)
{
Dictionary<string, GuideEntry> guides = new();
foreach (var guideId in guideList)
Expand All @@ -188,7 +190,7 @@ public void ToggleGuidebook(
guides.Add(guideId, guide);
}

ToggleGuidebook(guides, rootEntries, forceRoot, includeChildren, selected);
ToggleGuidebook(guides, rootEntries, forceRoot, includeChildren, selected, forceOpen);
}

private void RecursivelyAddChildren(GuideEntry guide, Dictionary<string, GuideEntry> guides)
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/_ftl/guidebook.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ guide-entry-lore-factions-independent = Independent
guide-entry-guns-and-you = Guns & You
guide-entry-law = Law
guide-entry-navigation = Navigation
guide-entry-sop = Standard Operating Procedure
guide-entry-tse = Trade Station Etiquette
4 changes: 2 additions & 2 deletions Resources/Locale/en-US/guidebook/guides.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ guide-entry-cargo-bounties = Cargo Bounties
guide-entry-salvage = Salvage
guide-entry-survival = Survival
guide-entry-chemicals = Chemicals
guide-entry-ss14 = Space Station 14
guide-entry-ss14 = Main Page
guide-entry-janitorial = Janitorial
guide-entry-bartender = Bartender
guide-entry-chef = Chef
Expand All @@ -43,4 +43,4 @@ guide-entry-security = Security
guide-entry-dna = DNA
guide-entry-antagonists = Antagonists
guide-entry-nuclear-operatives = Nuclear Operatives
guide-entry-nuclear-operatives = Nuclear Operatives
4 changes: 3 additions & 1 deletion Resources/Prototypes/Guidebook/ss14.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
text: "/ServerInfo/Guidebook/SpaceStation14.xml"
children:
- Controls
- Jobs
- StandardOperatingProcedure
- Survival
- Chemicals
- Jobs
- Lore
- Antagonists
132 changes: 132 additions & 0 deletions Resources/Prototypes/_FTL/Entities/Guidebook/main_page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Used for guidebook entities

- type: entity
id: BaseGuidebookHyperlink
name: hyperlink
abstract: true

- type: entity
parent: BaseGuidebookHyperlink
noSpawn: true
id: GuidebookHyperlinkNavigation
name: navigation
description: This is a hyperlink to the navigation guide!
components:
- type: Sprite
sprite: Structures/Machines/computers.rsi
layers:
- map: ["computerLayerBody"]
state: computer
- map: ["computerLayerKeyboard"]
state: generic_keyboard
- map: ["computerLayerScreen"]
state: shuttle
- map: ["computerLayerKeys"]
state: generic_keys
- type: GuideHelp
guides:
- Navigation

- type: entity
parent: BaseGuidebookHyperlink
noSpawn: true
id: GuidebookHyperlinkCommand
name: command
description: This is a hyperlink to the command guide!
components:
- type: Sprite
sprite: Objects/Misc/id_cards.rsi
layers:
- state: gold
- state: idcaptain
- type: GuideHelp
guides:
- Jobs

- type: entity
parent: BaseGuidebookHyperlink
noSpawn: true
id: GuidebookHyperlinkEngineering
name: engineering
description: This is a hyperlink to the engineering guide!
components:
- type: GuideHelp
guides:
- Engineering
- type: Sprite
sprite: Objects/Tools/wrench.rsi
state: icon

- type: entity
parent: BaseGuidebookHyperlink
noSpawn: true
id: GuidebookHyperlinkMedical
name: medical
description: This is a hyperlink to the medical guide!
components:
- type: GuideHelp
guides:
- Medical
- type: Sprite
sprite: Objects/Specific/Medical/firstaidkits.rsi
state: firstaid

- type: entity
parent: BaseGuidebookHyperlink
noSpawn: true
id: GuidebookHyperlinkSecurity
name: security
description: This is a hyperlink to the security guide!
components:
- type: GuideHelp
guides:
- Medical
- type: Sprite
sprite: Objects/Weapons/Melee/stunbaton.rsi
layers:
- state: stunbaton_on

- type: entity
parent: BaseGuidebookHyperlink
noSpawn: true
id: GuidebookHyperlinkLaw
name: law
description: This is a hyperlink to the law guide!
components:
- type: GuideHelp
guides:
- Law
- type: Sprite
sprite: Clothing/Neck/Misc/lawyerbadge.rsi
state: icon

- type: entity
parent: BaseGuidebookHyperlink
noSpawn: true
id: GuidebookHyperlinkLore
name: lore
description: This is a hyperlink to the lore guide!
components:
- type: GuideHelp
guides:
- Lore
- type: Sprite
sprite: Objects/Misc/authorbooks.rsi
layers:
- state: book_watched

- type: entity
parent: BaseGuidebookHyperlink
noSpawn: true
id: GuidebookHyperlinkSOP
name: standard operating procedure
description: This is a hyperlink to the SoP guide!
components:
- type: GuideHelp
guides:
- StandardOperatingProcedure
- type: Sprite
sprite: Objects/Misc/books.rsi
layers:
- state: book0
map: [ "enum.DamageStateVisualLayers.Base" ]
11 changes: 11 additions & 0 deletions Resources/Prototypes/_FTL/Guidebook/sop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- type: guideEntry
id: StandardOperatingProcedure
name: guide-entry-sop
text: "/ServerInfo/Guidebook/SoP/StandardOperatingProcedure.xml"
children:
- TradeStationEtiquette

- type: guideEntry
id: TradeStationEtiquette
name: guide-entry-tse
text: "/ServerInfo/Guidebook/SoP/TradeStationEtiquette.xml"
Loading

0 comments on commit 2a5faf1

Please sign in to comment.