Skip to content

Commit b7ef2fa

Browse files
In-game scent editor (Floof-Station#383)
* Fix some coyote blunders * Scent editor * Dont SendOnlyToOwner, tis be causing issues for aghosts * Ignore abstract prototypes * Minor fixes * Check for scent source being deleted - coyote didn't doo it * Remove unnecessary whitespace Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> --------- Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com>
1 parent ebe645b commit b7ef2fa

21 files changed

Lines changed: 953 additions & 17 deletions

Content.Client/_Common/Consent/ClientConsentManager.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Content.Shared._Common.Consent;
55
using Robust.Client.Player;
66
using Robust.Shared.Network;
7+
using Robust.Shared.Prototypes;
78

89
namespace Content.Client._Common.Consent;
910

@@ -36,7 +37,10 @@ public PlayerConsentSettings GetConsentSettings()
3637
{
3738
if (_consent is null)
3839
{
39-
throw new InvalidOperationException("Player doesn't have a session yet?");
40+
// Floofstation - who thought it's a good idea?
41+
// throw new InvalidOperationException("Player doesn't have a session yet?");
42+
Logger.GetSawmill("consent").Error("Attempt to access consent data before session data has been loaded.");
43+
return new();
4044
}
4145

4246
return _consent;
@@ -48,4 +52,14 @@ private void HandleUpdateConsent(MsgUpdateConsent message)
4852

4953
OnServerDataLoaded?.Invoke();
5054
}
55+
56+
// Floofstation - copypaste from server consent manager. Update if that ever changes.
57+
/// <summary>
58+
/// Checks if the local player has the specified consent.
59+
/// </summary>
60+
public bool HasConsent(ProtoId<ConsentTogglePrototype> consentId)
61+
{
62+
var consent = GetConsentSettings();
63+
return consent.Toggles.TryGetValue(consentId, out var val) && val == "on";
64+
}
5165
}

Content.Client/_Common/Consent/IClientConsentManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: MIT
33

44
using Content.Shared._Common.Consent;
5+
using Robust.Shared.Prototypes;
56

67
namespace Content.Client._Common.Consent;
78

@@ -13,4 +14,5 @@ public interface IClientConsentManager
1314
void Initialize();
1415
void UpdateConsent(PlayerConsentSettings consentSettings);
1516
PlayerConsentSettings GetConsentSettings();
17+
bool HasConsent(ProtoId<ConsentTogglePrototype> consentId); // Floofstation
1618
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Content.Shared._Floof.Scent;
2+
using Content.Shared.Verbs;
3+
using Robust.Client.GameObjects;
4+
using Robust.Client.UserInterface;
5+
using Robust.Shared.Player;
6+
using Robust.Shared.Utility;
7+
using ScentData = Content.Shared._Coyote.SniffAndSmell.Scent;
8+
9+
namespace Content.Client._Floof.Scent;
10+
11+
public sealed class ScentEditingSystem : SharedScentEditingSystem
12+
{
13+
[Dependency] private readonly ISharedPlayerManager _playerManager = default!;
14+
[Dependency] private readonly IUserInterfaceManager _ui = default!;
15+
16+
public override void Initialize()
17+
{
18+
SubscribeLocalEvent<GetVerbsEvent<Verb>>(OnGetVerbs);
19+
}
20+
21+
private void OnGetVerbs(GetVerbsEvent<Verb> args)
22+
{
23+
if (_playerManager.LocalSession is not {} localSession || !CanEditScent(localSession, args.Target))
24+
return;
25+
26+
// No tryX method for controllers
27+
ScentsUIController scentsUi;
28+
try { scentsUi = _ui.GetUIController<ScentsUIController>(); }
29+
catch (Exception e) { return; }
30+
31+
var verb = new Verb
32+
{
33+
Text = Loc.GetString("scent-editor-verb"),
34+
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/pencil.png")), // I love putting this everywhere
35+
Priority = -21, // Below "ignore scent"
36+
Category = VerbCategory.Interaction, // This also doesn't belong here, but I'm keeping it here for consistency. TODO: own category?
37+
Act = () => { scentsUi.ShowScentEditor(args.Target); },
38+
ClientExclusive = true, // Prediction bad
39+
};
40+
args.Verbs.Add(verb);
41+
}
42+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<controls:FancyWindow
2+
xmlns="https://spacestation14.io"
3+
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
4+
xmlns:ui="clr-namespace:Content.Client._Floof.UI"
5+
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
6+
MinSize="500, 300"
7+
Title="{Loc 'scent-editor-title'}">
8+
9+
<BoxContainer Orientation="Vertical">
10+
<SplitContainer
11+
Orientation="Horizontal"
12+
HorizontalExpand="True"
13+
VerticalExpand="True"
14+
Margin="8">
15+
16+
<!-- Left side - current scents and scent addition dropdown -->
17+
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
18+
<BoxContainer
19+
Orientation="Vertical"
20+
Name="PrimaryContainer"
21+
MinWidth="100"
22+
HorizontalExpand="True">
23+
24+
<Label Text="{Loc 'scent-editor-current-header'}"></Label>
25+
26+
<ScrollContainer
27+
HScrollEnabled="False"
28+
VScrollEnabled="True"
29+
HorizontalExpand="True"
30+
VerticalExpand="True">
31+
32+
<BoxContainer Name="CurrentScentsContainer" Orientation="Vertical"/>
33+
</ScrollContainer>
34+
35+
<!-- Scent dropdown added in code -->
36+
</BoxContainer>
37+
38+
<!-- Dont you love having to add a fake separator? Because SplitContainer doesn't support drawing a separator on its own. -->
39+
<customControls:VSeparator
40+
StyleClasses="LowDivider"
41+
Margin="2 0"
42+
MouseFilter="Pass"/>
43+
</BoxContainer>
44+
45+
<!-- Right side - presets -->
46+
<BoxContainer
47+
Orientation="Vertical"
48+
MinWidth="100">
49+
50+
<Label Text="{Loc 'scent-editor-presets'}"></Label>
51+
52+
<ScrollContainer
53+
HScrollEnabled="False"
54+
VScrollEnabled="True"
55+
HorizontalExpand="True"
56+
VerticalExpand="True">
57+
58+
<BoxContainer Name="PresetsContainer" Orientation="Vertical"/>
59+
60+
</ScrollContainer>
61+
62+
<!-- Option to save the current settings as a preset at the bottom. -->
63+
<Label Text="{Loc 'scent-editor-save-preset-header'}"></Label>
64+
65+
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
66+
<LineEdit Name="PresetNameEdit" HorizontalExpand="True"/>
67+
68+
<TextureButton Name="SavePresetButton" TexturePath="/Textures/Interface/VerbIcons/group.svg.192dpi.png" SetSize="32 32"/>
69+
</BoxContainer>
70+
</BoxContainer>
71+
</SplitContainer>
72+
73+
<controls:HLine Color="#404040" Thickness="2" Margin="0 5 0 5"/>
74+
75+
<!-- I took this from QuickDialog, again, sue me -->
76+
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Center">
77+
<Button Name="SaveButton" Text="{Loc 'quick-dialog-ui-ok'}"/>
78+
<Button Name="CancelButton" Text="{Loc 'quick-dialog-ui-cancel'}"/>
79+
</BoxContainer>
80+
</BoxContainer>
81+
</controls:FancyWindow>

0 commit comments

Comments
 (0)