Actions System + UI (#2710)
Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
@@ -1,18 +1,26 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Atmos;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Clothing;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Utility;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -45,6 +53,8 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
[ViewVariables(VVAccess.ReadWrite)] public string? TurnOnFailSound;
|
||||
[ViewVariables(VVAccess.ReadWrite)] public string? TurnOffSound;
|
||||
|
||||
[ComponentDependency] private readonly ItemActionsComponent? _itemActions = null;
|
||||
|
||||
/// <summary>
|
||||
/// Client-side ItemStatus level
|
||||
/// </summary>
|
||||
@@ -98,8 +108,9 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
/// Illuminates the light if it is not active, extinguishes it if it is active.
|
||||
/// </summary>
|
||||
/// <returns>True if the light's status was toggled, false otherwise.</returns>
|
||||
private bool ToggleStatus(IEntity user)
|
||||
public bool ToggleStatus(IEntity user)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanUse(user)) return false;
|
||||
return Activated ? TurnOff() : TurnOn(user);
|
||||
}
|
||||
|
||||
@@ -112,6 +123,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
|
||||
SetState(false);
|
||||
Activated = false;
|
||||
UpdateLightAction();
|
||||
|
||||
if (makeNoise)
|
||||
{
|
||||
@@ -132,6 +144,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
if (TurnOnFailSound != null) EntitySystem.Get<AudioSystem>().PlayFromEntity(TurnOnFailSound, Owner);
|
||||
Owner.PopupMessage(user, Loc.GetString("Cell missing..."));
|
||||
UpdateLightAction();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -142,10 +155,12 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
if (TurnOnFailSound != null) EntitySystem.Get<AudioSystem>().PlayFromEntity(TurnOnFailSound, Owner);
|
||||
Owner.PopupMessage(user, Loc.GetString("Dead cell..."));
|
||||
UpdateLightAction();
|
||||
return false;
|
||||
}
|
||||
|
||||
Activated = true;
|
||||
UpdateLightAction();
|
||||
SetState(true);
|
||||
|
||||
if (TurnOnSound != null) EntitySystem.Get<AudioSystem>().PlayFromEntity(TurnOnSound, Owner);
|
||||
@@ -175,6 +190,11 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLightAction()
|
||||
{
|
||||
_itemActions?.Toggle(ItemActionType.ToggleLight, Activated);
|
||||
}
|
||||
|
||||
public void OnUpdate(float frameTime)
|
||||
{
|
||||
if (Cell == null)
|
||||
@@ -249,4 +269,17 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public class ToggleLightAction : IToggleItemAction
|
||||
{
|
||||
public void ExposeData(ObjectSerializer serializer) {}
|
||||
|
||||
public bool DoToggleAction(ToggleItemActionEventArgs args)
|
||||
{
|
||||
if (!args.Item.TryGetComponent<HandheldLightComponent>(out var lightComponent)) return false;
|
||||
if (lightComponent.Activated == args.ToggledOn) return false;
|
||||
return lightComponent.ToggleStatus(args.Performer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user