/// </summary>
[DataField]
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg");
-
- public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key);
}
}
comp.UIUpdateAccumulator -= UIUpdateInterval;
- if (comp.UserInterface is { } ui && ui.SubscribedSessions.Count > 0)
- UpdateCommsConsoleInterface(uid, comp);
+ if (_uiSystem.TryGetUi(uid, CommunicationsConsoleUiKey.Key, out var ui) && ui.SubscribedSessions.Count > 0)
+ UpdateCommsConsoleInterface(uid, comp, ui);
}
base.Update(frameTime);
/// <summary>
/// Updates the UI for a particular comms console.
/// </summary>
- /// <param name="comp"></param>
- public void UpdateCommsConsoleInterface(EntityUid uid, CommunicationsConsoleComponent comp)
+ public void UpdateCommsConsoleInterface(EntityUid uid, CommunicationsConsoleComponent comp, PlayerBoundUserInterface? ui = null)
{
+ if (ui == null && !_uiSystem.TryGetUi(uid, CommunicationsConsoleUiKey.Key, out ui))
+ return;
+
var stationUid = _stationSystem.GetOwningStation(uid);
List<string>? levels = null;
string currentLevel = default!;
}
}
- if (comp.UserInterface is not null)
- _uiSystem.SetUiState(comp.UserInterface, new CommunicationsConsoleInterfaceState(
- CanAnnounce(comp),
- CanCallOrRecall(comp),
- levels,
- currentLevel,
- currentDelay,
- _roundEndSystem.ExpectedCountdownEnd
- ));
+ _uiSystem.SetUiState(ui, new CommunicationsConsoleInterfaceState(
+ CanAnnounce(comp),
+ CanCallOrRecall(comp),
+ levels,
+ currentLevel,
+ currentDelay,
+ _roundEndSystem.ExpectedCountdownEnd
+ ));
}
private static bool CanAnnounce(CommunicationsConsoleComponent comp)
private void OnSelectAlertLevelMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleSelectAlertLevelMessage message)
{
- if (message.Session.AttachedEntity is not { Valid: true } mob) return;
+ if (message.Session.AttachedEntity is not { Valid: true } mob)
+ return;
+
if (!CanUse(mob, uid))
{
_popupSystem.PopupCursor(Loc.GetString("comms-console-permission-denied"), message.Session, PopupType.Medium);
private void OnCallShuttleMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleCallEmergencyShuttleMessage message)
{
- if (!CanCallOrRecall(comp)) return;
- if (message.Session.AttachedEntity is not { Valid: true } mob) return;
+ if (!CanCallOrRecall(comp))
+ return;
+
+ if (message.Session.AttachedEntity is not { Valid: true } mob)
+ return;
+
if (!CanUse(mob, uid))
{
_popupSystem.PopupEntity(Loc.GetString("comms-console-permission-denied"), uid, message.Session);
private void OnRecallShuttleMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleRecallEmergencyShuttleMessage message)
{
- if (!CanCallOrRecall(comp)) return;
- if (message.Session.AttachedEntity is not { Valid: true } mob) return;
+ if (!CanCallOrRecall(comp))
+ return;
+
+ if (message.Session.AttachedEntity is not { Valid: true } mob)
+ return;
+
if (!CanUse(mob, uid))
{
_popupSystem.PopupEntity(Loc.GetString("comms-console-permission-denied"), uid, message.Session);
[ViewVariables(VVAccess.ReadWrite)]
[DataField("deleteEmpty")]
public bool DeleteEmpty = true;
-
- [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
}
}
// Decrease "Ammo"
component.Charges--;
- Dirty(component);
+ Dirty(uid, component);
+
_adminLogger.Add(LogType.CrayonDraw, LogImpact.Low, $"{EntityManager.ToPrettyString(args.User):user} drew a {component.Color:color} {component.SelectedState}");
args.Handled = true;
return;
if (!TryComp<ActorComponent>(args.User, out var actor) ||
- component.UserInterface == null)
+ !_uiSystem.TryGetUi(uid, SharedCrayonComponent.CrayonUiKey.Key, out var ui))
{
return;
}
- _uiSystem.ToggleUi(component.UserInterface, actor.PlayerSession);
-
- if (component.UserInterface?.SubscribedSessions.Contains(actor.PlayerSession) == true)
+ _uiSystem.ToggleUi(ui, actor.PlayerSession);
+ if (ui.SubscribedSessions.Contains(actor.PlayerSession))
{
// Tell the user interface the selected stuff
- _uiSystem.SetUiState(component.UserInterface, new CrayonBoundUserInterfaceState(component.SelectedState, component.SelectableColor, component.Color));
+ _uiSystem.SetUiState(ui, new CrayonBoundUserInterfaceState(component.SelectedState, component.SelectableColor, component.Color));
}
args.Handled = true;
private void OnCrayonBoundUI(EntityUid uid, CrayonComponent component, CrayonSelectMessage args)
{
// Check if the selected state is valid
- if (!_prototypeManager.TryIndex<DecalPrototype>(args.State, out var prototype) || !prototype.Tags.Contains("crayon")) return;
+ if (!_prototypeManager.TryIndex<DecalPrototype>(args.State, out var prototype) || !prototype.Tags.Contains("crayon"))
+ return;
component.SelectedState = args.State;
- Dirty(component);
+ Dirty(uid, component);
}
private void OnCrayonBoundUIColor(EntityUid uid, CrayonComponent component, CrayonColorMessage args)
{
// you still need to ensure that the given color is a valid color
- if (component.SelectableColor && args.Color != component.Color)
- {
- component.Color = args.Color;
+ if (!component.SelectableColor || args.Color == component.Color)
+ return;
- Dirty(component);
- }
+ component.Color = args.Color;
+ Dirty(uid, component);
}
// Get the first one from the catalog and set it as default
var decal = _prototypeManager.EnumeratePrototypes<DecalPrototype>().FirstOrDefault(x => x.Tags.Contains("crayon"));
component.SelectedState = decal?.ID ?? string.Empty;
- Dirty(component);
+ Dirty(uid, component);
}
private void OnCrayonDropped(EntityUid uid, CrayonComponent component, DroppedEvent args)
public IPlayerSession? InstrumentPlayer =>
_entMan.GetComponentOrNull<ActivatableUIComponent>(Owner)?.CurrentSingleUser
?? _entMan.GetComponentOrNull<ActorComponent>(Owner)?.PlayerSession;
-
- [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key);
}
[RegisterComponent]
using Content.Shared.Administration;
using Content.Shared.Instruments;
using Content.Shared.Instruments.UI;
-using Content.Shared.Interaction;
using Content.Shared.Physics;
using Content.Shared.Popups;
using JetBrains.Annotations;
using Robust.Shared.Console;
using Robust.Shared.GameStates;
using Robust.Shared.Timing;
-using Robust.Shared.Utility;
namespace Content.Server.Instruments;
// Just in case
Clean(uid);
-
- if (instrument.UserInterface is not null)
- _bui.CloseAll(instrument.UserInterface);
+ _bui.TryCloseAll(uid, InstrumentUiKey.Key);
}
instrument.Timer += frameTime;
[DataField("scanDelay")]
public float ScanDelay = 0.8f;
- public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
-
/// <summary>
/// Sound played on scanning begin
/// </summary>
args.Handled = true;
}
- private void OpenUserInterface(EntityUid user, HealthAnalyzerComponent healthAnalyzer)
+ private void OpenUserInterface(EntityUid user, EntityUid analyzer)
{
- if (!TryComp<ActorComponent>(user, out var actor) || healthAnalyzer.UserInterface == null)
+ if (!TryComp<ActorComponent>(user, out var actor) || !_uiSystem.TryGetUi(analyzer, HealthAnalyzerUiKey.Key, out var ui))
return;
- _uiSystem.OpenUi(healthAnalyzer.UserInterface ,actor.PlayerSession);
+ _uiSystem.OpenUi(ui ,actor.PlayerSession);
}
public void UpdateScannedUser(EntityUid uid, EntityUid user, EntityUid? target, HealthAnalyzerComponent? healthAnalyzer)
if (!Resolve(uid, ref healthAnalyzer))
return;
- if (target == null || healthAnalyzer.UserInterface == null)
+ if (target == null || !_uiSystem.TryGetUi(uid, HealthAnalyzerUiKey.Key, out var ui))
return;
if (!HasComp<DamageableComponent>(target))
TryComp<TemperatureComponent>(target, out var temp);
TryComp<BloodstreamComponent>(target, out var bloodstream);
- OpenUserInterface(user, healthAnalyzer);
+ OpenUserInterface(user, uid);
- _uiSystem.SendUiMessage(healthAnalyzer.UserInterface, new HealthAnalyzerScannedUserMessage(GetNetEntity(target), temp != null ? temp.CurrentTemperature : float.NaN,
+ _uiSystem.SendUiMessage(ui, new HealthAnalyzerScannedUserMessage(GetNetEntity(target), temp != null ? temp.CurrentTemperature : float.NaN,
bloodstream != null ? bloodstream.BloodSolution.FillFraction : float.NaN));
}
}
[ViewVariables]
public Enum? Key { get; set; }
- [ViewVariables] public PlayerBoundUserInterface? UserInterface => (Key != null) ? Owner.GetUIOrNull(Key) : null;
-
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool InHandsOnly { get; set; } = false;
return;
ActivationVerb verb = new();
- verb.Act = () => InteractUI(args.User, component);
+ verb.Act = () => InteractUI(args.User, uid, component);
verb.Text = Loc.GetString(component.VerbText);
// TODO VERBS add "open UI" icon?
args.Verbs.Add(verb);
private void OnActivate(EntityUid uid, ActivatableUIComponent component, ActivateInWorldEvent args)
{
- if (args.Handled) return;
- if (component.InHandsOnly) return;
- args.Handled = InteractUI(args.User, component);
+ if (args.Handled)
+ return;
+
+ if (component.InHandsOnly)
+ return;
+
+ args.Handled = InteractUI(args.User, uid, component);
}
private void OnUseInHand(EntityUid uid, ActivatableUIComponent component, UseInHandEvent args)
{
- if (args.Handled) return;
- if (component.rightClickOnly) return;
- args.Handled = InteractUI(args.User, component);
+ if (args.Handled)
+ return;
+
+ if (component.rightClickOnly)
+ return;
+
+ args.Handled = InteractUI(args.User, uid, component);
}
private void OnParentChanged(EntityUid uid, ActivatableUIComponent aui, ref EntParentChangedMessage args)
private void OnUIClose(EntityUid uid, ActivatableUIComponent component, BoundUIClosedEvent args)
{
- if (args.Session != component.CurrentSingleUser) return;
- if (args.UiKey != component.Key) return;
+ if (args.Session != component.CurrentSingleUser)
+ return;
+
+ if (!Equals(args.UiKey, component.Key))
+ return;
+
SetCurrentSingleUser(uid, null, component);
}
- private bool InteractUI(EntityUid user, ActivatableUIComponent aui)
+ private bool InteractUI(EntityUid user, EntityUid uiEntity, ActivatableUIComponent aui)
{
- if (!_blockerSystem.CanInteract(user, aui.Owner) && (!aui.AllowSpectator || !HasComp<GhostComponent>(user)))
+ if (!_blockerSystem.CanInteract(user, uiEntity) && (!aui.AllowSpectator || !HasComp<GhostComponent>(user)))
return false;
if (aui.RequireHands && !HasComp<HandsComponent>(user))
return false;
- if (!EntityManager.TryGetComponent(user, out ActorComponent? actor)) return false;
+ if (!EntityManager.TryGetComponent(user, out ActorComponent? actor))
+ return false;
+
+ if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession))
+ return false;
- if (aui.AdminOnly && !_adminManager.IsAdmin(actor.PlayerSession)) return false;
+ if (aui.Key == null)
+ return false;
- var ui = aui.UserInterface;
- if (ui == null) return false;
+ if (!_uiSystem.TryGetUi(uiEntity, aui.Key, out var ui))
+ return false;
if (aui.SingleUser && (aui.CurrentSingleUser != null) && (actor.PlayerSession != aui.CurrentSingleUser))
{
// If we get here, supposedly, the object is in use.
// Check with BUI that it's ACTUALLY in use just in case.
// Since this could brick the object if it goes wrong.
- if (ui.SubscribedSessions.Count != 0) return false;
+ if (ui.SubscribedSessions.Count != 0)
+ return false;
}
// If we've gotten this far, fire a cancellable event that indicates someone is about to activate this.
// This is so that stuff can require further conditions (like power).
var oae = new ActivatableUIOpenAttemptEvent(user);
- var uae = new UserOpenActivatableUIAttemptEvent(user, aui.Owner);
- RaiseLocalEvent(user, uae, false);
- RaiseLocalEvent((aui).Owner, oae, false);
- if (oae.Cancelled || uae.Cancelled) return false;
+ var uae = new UserOpenActivatableUIAttemptEvent(user, uiEntity);
+ RaiseLocalEvent(user, uae);
+ RaiseLocalEvent(uiEntity, oae);
+ if (oae.Cancelled || uae.Cancelled)
+ return false;
// Give the UI an opportunity to prepare itself if it needs to do anything
// before opening
var bae = new BeforeActivatableUIOpenEvent(user);
- RaiseLocalEvent((aui).Owner, bae, false);
+ RaiseLocalEvent(uiEntity, bae);
- SetCurrentSingleUser((aui).Owner, actor.PlayerSession, aui);
+ SetCurrentSingleUser(uiEntity, actor.PlayerSession, aui);
_uiSystem.ToggleUi(ui, actor.PlayerSession);
//Let the component know a user opened it so it can do whatever it needs to do
var aae = new AfterActivatableUIOpenEvent(user, actor.PlayerSession);
- RaiseLocalEvent((aui).Owner, aae, false);
+ RaiseLocalEvent(uiEntity, aae);
return true;
}
aui.CurrentSingleUser = v;
- RaiseLocalEvent(uid, new ActivatableUIPlayerChangedEvent(), false);
+ RaiseLocalEvent(uid, new ActivatableUIPlayerChangedEvent());
}
public void CloseAll(EntityUid uid, ActivatableUIComponent? aui = null)
{
if (!Resolve(uid, ref aui, false))
return;
- if (aui.UserInterface is null)
+
+ if (aui.Key == null || !_uiSystem.TryGetUi(uid, aui.Key, out var ui))
return;
- _uiSystem.CloseAll(aui.UserInterface);
+ _uiSystem.CloseAll(ui);
}
private void OnHandDeselected(EntityUid uid, ActivatableUIComponent? aui, HandDeselectedEvent args)
{
- if (!Resolve(uid, ref aui, false)) return;
+ if (!Resolve(uid, ref aui, false))
+ return;
+
if (!aui.CloseOnHandDeselect)
return;
+
CloseAll(uid, aui);
}
}
using Content.Server.Actions;
-using Content.Shared.Actions;
using Content.Shared.UserInterface;
using Robust.Server.GameObjects;
if (key is null)
{
- Logger.ErrorS("bui", $"Entity {ToPrettyString(uid)} has an invalid intrinsic UI.");
+ Log.Error($"Entity {ToPrettyString(uid)} has an invalid intrinsic UI.");
}
var ui = GetUIOrNull(uid, key, iui);
if (ui is null)
{
- Logger.ErrorS("bui", $"Couldn't get UI {key} on {ToPrettyString(uid)}");
+ Log.Error($"Couldn't get UI {key} on {ToPrettyString(uid)}");
return false;
}
var attempt = new IntrinsicUIOpenAttemptEvent(uid, key);
- RaiseLocalEvent(uid, attempt, false);
+ RaiseLocalEvent(uid, attempt);
if (attempt.Cancelled)
return false;
if (!Resolve(uid, ref component))
return null;
- return key is null ? null : uid.GetUIOrNull(key);
+ return key is null ? null : _uiSystem.GetUiOrNull(uid, key);
}
}
+++ /dev/null
-using Robust.Server.GameObjects;
-
-namespace Content.Server.UserInterface
-{
- public static class UserInterfaceHelpers
- {
- [Obsolete("Use UserInterfaceSystem")]
- public static PlayerBoundUserInterface? GetUIOrNull(this EntityUid entity, Enum uiKey)
- {
- return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<UserInterfaceSystem>().GetUiOrNull(entity, uiKey);
- }
- }
-}