mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-16 21:17:39 +03:00
Make APC UI work correctly with multiple users (#32465)
* Make APC UI work correctly with multiple users * Check access only on client, when constructing UI * Do TODO (Thanks, Robust 236.1) --------- Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es> (cherry picked from commit 70b7747fddd58d556c1408464dcf969cdeb4a71a)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using Content.Client.Power.APC.UI;
|
||||
using Content.Client.Power.APC.UI;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.APC;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Client.Power.APC
|
||||
{
|
||||
@@ -22,6 +23,14 @@ namespace Content.Client.Power.APC
|
||||
|
||||
_menu = this.CreateWindow<ApcMenu>();
|
||||
_menu.OnBreaker += BreakerPressed;
|
||||
|
||||
var hasAccess = false;
|
||||
if (PlayerManager.LocalEntity != null)
|
||||
{
|
||||
var accessReader = EntMan.System<AccessReaderSystem>();
|
||||
hasAccess = accessReader.IsAllowed((EntityUid)PlayerManager.LocalEntity, Owner);
|
||||
}
|
||||
_menu?.SetAccessEnabled(hasAccess);
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -37,19 +37,9 @@ namespace Content.Client.Power.APC.UI
|
||||
{
|
||||
var castState = (ApcBoundInterfaceState) state;
|
||||
|
||||
if (BreakerButton != null)
|
||||
if (!BreakerButton.Disabled)
|
||||
{
|
||||
if(castState.HasAccess == false)
|
||||
{
|
||||
BreakerButton.Disabled = true;
|
||||
BreakerButton.ToolTip = Loc.GetString("apc-component-insufficient-access");
|
||||
}
|
||||
else
|
||||
{
|
||||
BreakerButton.Disabled = false;
|
||||
BreakerButton.ToolTip = null;
|
||||
BreakerButton.Pressed = castState.MainBreaker;
|
||||
}
|
||||
BreakerButton.Pressed = castState.MainBreaker;
|
||||
}
|
||||
|
||||
if (PowerLabel != null)
|
||||
@@ -87,6 +77,20 @@ namespace Content.Client.Power.APC.UI
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAccessEnabled(bool hasAccess)
|
||||
{
|
||||
if(hasAccess)
|
||||
{
|
||||
BreakerButton.Disabled = false;
|
||||
BreakerButton.ToolTip = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
BreakerButton.Disabled = true;
|
||||
BreakerButton.ToolTip = Loc.GetString("apc-component-insufficient-access");
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateChargeBarColor(float charge)
|
||||
{
|
||||
if (ChargeBar == null)
|
||||
|
||||
@@ -29,9 +29,6 @@ public sealed partial class ApcComponent : BaseApcNetComponent
|
||||
|
||||
[DataField("enabled")]
|
||||
public bool MainBreakerEnabled = true;
|
||||
// TODO: remove this since it probably breaks when 2 people use it
|
||||
[DataField("hasAccess")]
|
||||
public bool HasAccess = false;
|
||||
|
||||
public const float HighPowerThreshold = 0.9f;
|
||||
public static TimeSpan VisualsChangeDelay = TimeSpan.FromSeconds(1);
|
||||
|
||||
@@ -2,7 +2,6 @@ using Content.Server.Emp;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.Pow3r;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.APC;
|
||||
using Content.Shared.Emag.Components;
|
||||
@@ -66,11 +65,8 @@ public sealed class ApcSystem : EntitySystem
|
||||
UpdateApcState(uid, component);
|
||||
}
|
||||
|
||||
//Update the HasAccess var for UI to read
|
||||
private void OnBoundUiOpen(EntityUid uid, ApcComponent component, BoundUIOpenedEvent args)
|
||||
{
|
||||
// TODO: this should be per-player not stored on the apc
|
||||
component.HasAccess = _accessReader.IsAllowed(args.Actor, uid);
|
||||
UpdateApcState(uid, component);
|
||||
}
|
||||
|
||||
@@ -155,7 +151,7 @@ public sealed class ApcSystem : EntitySystem
|
||||
// TODO: Fix ContentHelpers or make a new one coz this is cooked.
|
||||
var charge = ContentHelpers.RoundToNearestLevels(battery.CurrentStorage / battery.Capacity, 1.0, 100 / ChargeAccuracy) / 100f * ChargeAccuracy;
|
||||
|
||||
var state = new ApcBoundInterfaceState(apc.MainBreakerEnabled, apc.HasAccess,
|
||||
var state = new ApcBoundInterfaceState(apc.MainBreakerEnabled,
|
||||
(int) MathF.Ceiling(battery.CurrentSupply), apc.LastExternalState,
|
||||
charge);
|
||||
|
||||
|
||||
@@ -178,15 +178,13 @@ namespace Content.Shared.APC
|
||||
public sealed class ApcBoundInterfaceState : BoundUserInterfaceState, IEquatable<ApcBoundInterfaceState>
|
||||
{
|
||||
public readonly bool MainBreaker;
|
||||
public readonly bool HasAccess;
|
||||
public readonly int Power;
|
||||
public readonly ApcExternalPowerState ApcExternalPower;
|
||||
public readonly float Charge;
|
||||
|
||||
public ApcBoundInterfaceState(bool mainBreaker, bool hasAccess, int power, ApcExternalPowerState apcExternalPower, float charge)
|
||||
public ApcBoundInterfaceState(bool mainBreaker, int power, ApcExternalPowerState apcExternalPower, float charge)
|
||||
{
|
||||
MainBreaker = mainBreaker;
|
||||
HasAccess = hasAccess;
|
||||
Power = power;
|
||||
ApcExternalPower = apcExternalPower;
|
||||
Charge = charge;
|
||||
@@ -197,7 +195,6 @@ namespace Content.Shared.APC
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return MainBreaker == other.MainBreaker &&
|
||||
HasAccess == other.HasAccess &&
|
||||
Power == other.Power &&
|
||||
ApcExternalPower == other.ApcExternalPower &&
|
||||
MathHelper.CloseTo(Charge, other.Charge);
|
||||
@@ -210,7 +207,7 @@ namespace Content.Shared.APC
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(MainBreaker, HasAccess, Power, (int) ApcExternalPower, Charge);
|
||||
return HashCode.Combine(MainBreaker, Power, (int) ApcExternalPower, Charge);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,6 @@
|
||||
type: ApcBoundUserInterface
|
||||
- type: ActivatableUI
|
||||
inHandsOnly: false
|
||||
singleUser: true
|
||||
key: enum.ApcUiKey.Key
|
||||
- type: Construction
|
||||
graph: APC
|
||||
|
||||
Reference in New Issue
Block a user