Convert ghost toggle button into an action (#12658)

* Convert ghost toggle button into an action

* figs
This commit is contained in:
Kara
2022-11-18 16:30:53 -06:00
committed by GitHub
parent f12eb55153
commit c71850a53f
8 changed files with 28 additions and 14 deletions

View File

@@ -20,7 +20,19 @@ namespace Content.Client.Ghost
CheckCanInteract = false, CheckCanInteract = false,
Event = new DisableLightingActionEvent(), Event = new DisableLightingActionEvent(),
}; };
public InstantAction ToggleGhostsAction = new()
{
Icon = new SpriteSpecifier.Rsi(new ResourcePath("Mobs/Ghosts/ghost_human.rsi"), "icon"),
DisplayName = "ghost-gui-toggle-ghost-visibility-name",
Description = "ghost-gui-toggle-ghost-visibility-desc",
ClientExclusive = true,
CheckCanInteract = false,
Event = new ToggleGhostsActionEvent(),
};
} }
public sealed class DisableLightingActionEvent : InstantActionEvent { }; public sealed class DisableLightingActionEvent : InstantActionEvent { };
public sealed class ToggleGhostsActionEvent : InstantActionEvent { };
} }

View File

@@ -67,6 +67,7 @@ namespace Content.Client.Ghost
SubscribeNetworkEvent<GhostUpdateGhostRoleCountEvent>(OnUpdateGhostRoleCount); SubscribeNetworkEvent<GhostUpdateGhostRoleCountEvent>(OnUpdateGhostRoleCount);
SubscribeLocalEvent<GhostComponent, DisableLightingActionEvent>(OnActionPerform); SubscribeLocalEvent<GhostComponent, DisableLightingActionEvent>(OnActionPerform);
SubscribeLocalEvent<GhostComponent, ToggleGhostsActionEvent>(OnToggleGhosts);
} }
private void OnGhostInit(EntityUid uid, GhostComponent component, ComponentInit args) private void OnGhostInit(EntityUid uid, GhostComponent component, ComponentInit args)
@@ -77,6 +78,7 @@ namespace Content.Client.Ghost
} }
_actions.AddAction(uid, component.DisableLightingAction, null); _actions.AddAction(uid, component.DisableLightingAction, null);
_actions.AddAction(uid, component.ToggleGhostsAction, null);
} }
private void OnActionPerform(EntityUid uid, GhostComponent component, DisableLightingActionEvent args) private void OnActionPerform(EntityUid uid, GhostComponent component, DisableLightingActionEvent args)
@@ -88,9 +90,19 @@ namespace Content.Client.Ghost
args.Handled = true; args.Handled = true;
} }
private void OnToggleGhosts(EntityUid uid, GhostComponent component, ToggleGhostsActionEvent args)
{
if (args.Handled)
return;
ToggleGhostVisibility();
args.Handled = true;
}
private void OnGhostRemove(EntityUid uid, GhostComponent component, ComponentRemove args) private void OnGhostRemove(EntityUid uid, GhostComponent component, ComponentRemove args)
{ {
_actions.RemoveAction(uid, component.DisableLightingAction); _actions.RemoveAction(uid, component.DisableLightingAction);
_actions.RemoveAction(uid, component.ToggleGhostsAction);
_lightManager.Enabled = true; _lightManager.Enabled = true;
if (uid != _playerManager.LocalPlayer?.ControlledEntity) if (uid != _playerManager.LocalPlayer?.ControlledEntity)

View File

@@ -99,7 +99,6 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
Gui.RequestWarpsPressed += RequestWarps; Gui.RequestWarpsPressed += RequestWarps;
Gui.ReturnToBodyPressed += ReturnToBody; Gui.ReturnToBodyPressed += ReturnToBody;
Gui.GhostRolesPressed += GhostRolesPressed; Gui.GhostRolesPressed += GhostRolesPressed;
Gui.ToggleGhostVisibility += ToggleGhostVisibility;
Gui.TargetWindow.WarpClicked += OnWarpClicked; Gui.TargetWindow.WarpClicked += OnWarpClicked;
UpdateGui(); UpdateGui();
@@ -113,7 +112,6 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
Gui.RequestWarpsPressed -= RequestWarps; Gui.RequestWarpsPressed -= RequestWarps;
Gui.ReturnToBodyPressed -= ReturnToBody; Gui.ReturnToBodyPressed -= ReturnToBody;
Gui.GhostRolesPressed -= GhostRolesPressed; Gui.GhostRolesPressed -= GhostRolesPressed;
Gui.ToggleGhostVisibility -= ToggleGhostVisibility;
Gui.TargetWindow.WarpClicked -= OnWarpClicked; Gui.TargetWindow.WarpClicked -= OnWarpClicked;
Gui.Hide(); Gui.Hide();
@@ -135,9 +133,4 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
{ {
_system?.OpenGhostRoles(); _system?.OpenGhostRoles();
} }
private void ToggleGhostVisibility()
{
_system?.ToggleGhostVisibility();
}
} }

View File

@@ -5,6 +5,5 @@
<Button Name="ReturnToBodyButton" Text="{Loc ghost-gui-return-to-body-button}" /> <Button Name="ReturnToBodyButton" Text="{Loc ghost-gui-return-to-body-button}" />
<Button Name="GhostWarpButton" Text="{Loc ghost-gui-ghost-warp-button}" /> <Button Name="GhostWarpButton" Text="{Loc ghost-gui-ghost-warp-button}" />
<Button Name="GhostRolesButton" /> <Button Name="GhostRolesButton" />
<Button Name="ToggleGhostVisibilityButton" Text="{Loc ghost-gui-toggle-ghost-visibility-button}" />
</BoxContainer> </BoxContainer>
</widgets:GhostGui> </widgets:GhostGui>

View File

@@ -14,7 +14,6 @@ public sealed partial class GhostGui : UIWidget
public event Action? RequestWarpsPressed; public event Action? RequestWarpsPressed;
public event Action? ReturnToBodyPressed; public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed; public event Action? GhostRolesPressed;
public event Action? ToggleGhostVisibility;
public GhostGui() public GhostGui()
{ {
@@ -27,7 +26,6 @@ public sealed partial class GhostGui : UIWidget
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke(); GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke(); ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke(); GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
ToggleGhostVisibilityButton.OnPressed += _ => ToggleGhostVisibility?.Invoke();
} }
public void Hide() public void Hide()

View File

@@ -1,7 +1,8 @@
ghost-gui-return-to-body-button = Return to body ghost-gui-return-to-body-button = Return to body
ghost-gui-ghost-warp-button = Ghost Warp ghost-gui-ghost-warp-button = Ghost Warp
ghost-gui-ghost-roles-button = Ghost Roles ({$count}) ghost-gui-ghost-roles-button = Ghost Roles ({$count})
ghost-gui-toggle-ghost-visibility-button = Toggle Ghosts ghost-gui-toggle-ghost-visibility-name = Toggle Ghosts
ghost-gui-toggle-ghost-visibility-desc = Toggle the visibility of other ghosts.
ghost-gui-toggle-lighting-manager-name = Toggle Lighting ghost-gui-toggle-lighting-manager-name = Toggle Lighting
ghost-gui-toggle-lighting-manager-desc = Toggle light rendering to better observe dark areas or to see what players see. ghost-gui-toggle-lighting-manager-desc = Toggle light rendering to better observe dark areas or to see what players see.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 654 B

After

Width:  |  Height:  |  Size: 308 B

View File

@@ -12,8 +12,7 @@
"directions": 4 "directions": 4
}, },
{ {
"name": "icon", "name": "icon"
"directions": 4
} }
] ]
} }