Content update for UI prediction (#27214)
* Content update for UI refactor * Big update * Sharing * Remaining content updates * First big update * Prototype updates * AUGH * Fix UI comp ref * Cleanup - Fix predicted message, fix item slots, fix interaction range check. * Fix regressions * Make this predictive idk why it wasn't. * Fix slime merge * Merge conflict * Fix merge
This commit is contained in:
79
Content.Shared/UserInterface/ActivatableUISystem.Power.cs
Normal file
79
Content.Shared/UserInterface/ActivatableUISystem.Power.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Content.Shared.PowerCell;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Shared.UserInterface;
|
||||
|
||||
public sealed partial class ActivatableUISystem
|
||||
{
|
||||
[Dependency] private readonly SharedPowerCellSystem _cell = default!;
|
||||
|
||||
private void InitializePower()
|
||||
{
|
||||
SubscribeLocalEvent<ActivatableUIRequiresPowerCellComponent, ActivatableUIOpenAttemptEvent>(OnBatteryOpenAttempt);
|
||||
SubscribeLocalEvent<ActivatableUIRequiresPowerCellComponent, BoundUIOpenedEvent>(OnBatteryOpened);
|
||||
SubscribeLocalEvent<ActivatableUIRequiresPowerCellComponent, BoundUIClosedEvent>(OnBatteryClosed);
|
||||
|
||||
SubscribeLocalEvent<PowerCellDrawComponent, EntRemovedFromContainerMessage>(OnPowerCellRemoved);
|
||||
}
|
||||
|
||||
private void OnPowerCellRemoved(EntityUid uid, PowerCellDrawComponent component, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
_cell.SetPowerCellDrawEnabled(uid, false);
|
||||
|
||||
if (HasComp<ActivatableUIRequiresPowerCellComponent>(uid) &&
|
||||
TryComp<ActivatableUIComponent>(uid, out var activatable))
|
||||
{
|
||||
_uiSystem.CloseUi(uid, activatable.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBatteryOpened(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIOpenedEvent args)
|
||||
{
|
||||
var activatable = Comp<ActivatableUIComponent>(uid);
|
||||
|
||||
if (!args.UiKey.Equals(activatable.Key))
|
||||
return;
|
||||
|
||||
_cell.SetPowerCellDrawEnabled(uid, true);
|
||||
}
|
||||
|
||||
private void OnBatteryClosed(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIClosedEvent args)
|
||||
{
|
||||
var activatable = Comp<ActivatableUIComponent>(uid);
|
||||
|
||||
if (!args.UiKey.Equals(activatable.Key))
|
||||
return;
|
||||
|
||||
// Stop drawing power if this was the last person with the UI open.
|
||||
if (!_uiSystem.IsUiOpen(uid, activatable.Key))
|
||||
_cell.SetPowerCellDrawEnabled(uid, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call if you want to check if the UI should close due to a recent battery usage.
|
||||
/// </summary>
|
||||
public void CheckUsage(EntityUid uid, ActivatableUIComponent? active = null, ActivatableUIRequiresPowerCellComponent? component = null, PowerCellDrawComponent? draw = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, ref draw, ref active, false))
|
||||
return;
|
||||
|
||||
if (_cell.HasActivatableCharge(uid))
|
||||
return;
|
||||
|
||||
_uiSystem.CloseUi(uid, active.Key);
|
||||
}
|
||||
|
||||
private void OnBatteryOpenAttempt(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, ActivatableUIOpenAttemptEvent args)
|
||||
{
|
||||
if (!TryComp<PowerCellDrawComponent>(uid, out var draw))
|
||||
return;
|
||||
|
||||
// Check if we have the appropriate drawrate / userate to even open it.
|
||||
if (args.Cancelled ||
|
||||
!_cell.HasActivatableCharge(uid, draw, user: args.User) ||
|
||||
!_cell.HasDrawCharge(uid, draw, user: args.User))
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user