diff --git a/Content.Client/PDA/PDAMenu.xaml.cs b/Content.Client/PDA/PDAMenu.xaml.cs index 4b80795cc1..a639c9d184 100644 --- a/Content.Client/PDA/PDAMenu.xaml.cs +++ b/Content.Client/PDA/PDAMenu.xaml.cs @@ -37,11 +37,11 @@ namespace Content.Client.PDA ViewContainer.OnChildAdded += control => control.Visible = false; - HomeButton.IconTexture = new SpriteSpecifier.Texture(new ("/Textures/Interface/home.png")); - FlashLightToggleButton.IconTexture = new SpriteSpecifier.Texture(new ("/Textures/Interface/light.png")); - EjectPenButton.IconTexture = new SpriteSpecifier.Texture(new ("/Textures/Interface/pencil.png")); - EjectIdButton.IconTexture = new SpriteSpecifier.Texture(new ("/Textures/Interface/eject.png")); - ProgramCloseButton.IconTexture = new SpriteSpecifier.Texture(new ("/Textures/Interface/Nano/cross.svg.png")); + HomeButton.IconTexture = new SpriteSpecifier.Texture(new("/Textures/Interface/home.png")); + FlashLightToggleButton.IconTexture = new SpriteSpecifier.Texture(new("/Textures/Interface/light.png")); + EjectPenButton.IconTexture = new SpriteSpecifier.Texture(new("/Textures/Interface/pencil.png")); + EjectIdButton.IconTexture = new SpriteSpecifier.Texture(new("/Textures/Interface/eject.png")); + ProgramCloseButton.IconTexture = new SpriteSpecifier.Texture(new("/Textures/Interface/Nano/cross.svg.png")); HomeButton.OnPressed += _ => ToHomeScreen(); @@ -102,8 +102,8 @@ namespace Content.Client.PDA if (state.PDAOwnerInfo.IdOwner != null || state.PDAOwnerInfo.JobTitle != null) { IdInfoLabel.SetMarkup(Loc.GetString("comp-pda-ui", - ("owner",state.PDAOwnerInfo.IdOwner ?? Loc.GetString("comp-pda-ui-unknown")), - ("jobTitle",state.PDAOwnerInfo.JobTitle ?? Loc.GetString("comp-pda-ui-unassigned")))); + ("owner", state.PDAOwnerInfo.IdOwner ?? Loc.GetString("comp-pda-ui-unknown")), + ("jobTitle", state.PDAOwnerInfo.JobTitle ?? Loc.GetString("comp-pda-ui-unassigned")))); } else { @@ -111,7 +111,7 @@ namespace Content.Client.PDA } StationNameLabel.SetMarkup(Loc.GetString("comp-pda-ui-station", - ("station",state.StationName ?? Loc.GetString("comp-pda-ui-unknown")))); + ("station", state.StationName ?? Loc.GetString("comp-pda-ui-unknown")))); var stationTime = _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan); @@ -263,7 +263,7 @@ namespace Content.Client.PDA _currentView = view; } - private BoxContainer CreateProgramListRow() + private static BoxContainer CreateProgramListRow() { return new BoxContainer() { diff --git a/Content.Client/PDA/PDAProgramItem.xaml.cs b/Content.Client/PDA/PDAProgramItem.xaml.cs index 5cc16da497..9348cc5c12 100644 --- a/Content.Client/PDA/PDAProgramItem.xaml.cs +++ b/Content.Client/PDA/PDAProgramItem.xaml.cs @@ -1,9 +1,7 @@ using Robust.Client.AutoGenerated; using Robust.Client.Graphics; -using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; -using Robust.Shared.Input; namespace Content.Client.PDA; diff --git a/Content.Client/PDA/PDASettingsButton.xaml.cs b/Content.Client/PDA/PDASettingsButton.xaml.cs index 0fb4ffb596..c62f214194 100644 --- a/Content.Client/PDA/PDASettingsButton.xaml.cs +++ b/Content.Client/PDA/PDASettingsButton.xaml.cs @@ -42,7 +42,7 @@ public sealed partial class PDASettingsButton : ContainerButton { get => OptionName.FontColorOverride; - set + set { OptionName.FontColorOverride = value; OptionDescription.FontColorOverride = value; diff --git a/Content.Client/PDA/PDASystem.cs b/Content.Client/PDA/PDASystem.cs index 37834e0723..a5de98b9cf 100644 --- a/Content.Client/PDA/PDASystem.cs +++ b/Content.Client/PDA/PDASystem.cs @@ -18,10 +18,10 @@ public sealed class PDASystem : SharedPDASystem if (args.Sprite == null) return; - if (_appearance.TryGetData(uid, UnpoweredFlashlightVisuals.LightOn, out var isFlashlightOn, args.Component)) + if (Appearance.TryGetData(uid, UnpoweredFlashlightVisuals.LightOn, out var isFlashlightOn, args.Component)) args.Sprite.LayerSetVisible(PDAVisualLayers.Flashlight, isFlashlightOn); - if (_appearance.TryGetData(uid, PDAVisuals.IDCardInserted, out var isCardInserted, args.Component)) + if (Appearance.TryGetData(uid, PDAVisuals.IDCardInserted, out var isCardInserted, args.Component)) args.Sprite.LayerSetVisible(PDAVisualLayers.IDLight, isCardInserted); } @@ -29,7 +29,7 @@ public sealed class PDASystem : SharedPDASystem { base.OnComponentInit(uid, component, args); - if(!TryComp(uid, out var sprite)) + if (!TryComp(uid, out var sprite)) return; if (component.State != null) @@ -38,11 +38,11 @@ public sealed class PDASystem : SharedPDASystem sprite.LayerSetVisible(PDAVisualLayers.Flashlight, component.FlashlightOn); sprite.LayerSetVisible(PDAVisualLayers.IDLight, component.IdSlot.StartingItem != null); } -} -enum PDAVisualLayers : byte -{ - Base, - Flashlight, - IDLight + public enum PDAVisualLayers : byte + { + Base, + Flashlight, + IDLight + } } diff --git a/Content.Client/PDA/PDAWindow.xaml.cs b/Content.Client/PDA/PDAWindow.xaml.cs index 8b39d744cd..4a7ef89c64 100644 --- a/Content.Client/PDA/PDAWindow.xaml.cs +++ b/Content.Client/PDA/PDAWindow.xaml.cs @@ -22,7 +22,7 @@ public partial class PDAWindow : BaseWindow set { - AccentH.ModulateSelfOverride = Color. FromHex(value, Color.White); + AccentH.ModulateSelfOverride = Color.FromHex(value, Color.White); AccentH.Visible = value != null; } } @@ -33,7 +33,7 @@ public partial class PDAWindow : BaseWindow set { - AccentV.ModulateSelfOverride = Color. FromHex(value, Color.White); + AccentV.ModulateSelfOverride = Color.FromHex(value, Color.White); AccentV.Visible = value != null; } } diff --git a/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs b/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs index cb638efcd9..1363fa66d1 100644 --- a/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs +++ b/Content.Client/PDA/Ringer/RingtoneMenu.xaml.cs @@ -18,20 +18,38 @@ namespace Content.Client.PDA.Ringer RingerNoteInputs = new[] { RingerNoteOneInput, RingerNoteTwoInput, RingerNoteThreeInput, RingerNoteFourInput }; - for (int i = 0; i < RingerNoteInputs.Length; i++) + for (var i = 0; i < RingerNoteInputs.Length; ++i) { var input = RingerNoteInputs[i]; - int index = i; - input.OnTextChanged += _ => //Prevents unauthorized characters from being entered into the LineEdit + var index = i; + var foo = () => // Prevents unauthorized characters from being entered into the LineEdit { input.Text = input.Text.ToUpper(); if (!IsNote(input.Text)) + { input.Text = PreviousNoteInputs[index]; + } else PreviousNoteInputs[index] = input.Text; - input.CursorPosition = input.Text.Length; //Resets caret position to the end of the typed input + input.RemoveStyleClass("Caution"); + }; + + input.OnFocusExit += _ => foo(); + input.OnTextEntered += _ => + { + foo(); + input.CursorPosition = input.Text.Length; // Resets caret position to the end of the typed input + }; + input.OnTextChanged += _ => + { + input.Text = input.Text.ToUpper(); + + if (!IsNote(input.Text)) + input.AddStyleClass("Caution"); + else + input.RemoveStyleClass("Caution"); }; } } diff --git a/Content.Server/PDA/PDASystem.cs b/Content.Server/PDA/PDASystem.cs index c38f95d5bd..7115cff963 100644 --- a/Content.Server/PDA/PDASystem.cs +++ b/Content.Server/PDA/PDASystem.cs @@ -10,6 +10,7 @@ using Content.Server.Store.Components; using Content.Server.Store.Systems; using Content.Shared.PDA; using Robust.Server.GameObjects; +using Robust.Server.Player; using Robust.Shared.Containers; using Content.Shared.Light.Component; @@ -32,20 +33,25 @@ namespace Content.Server.PDA SubscribeLocalEvent(OnLightToggle); SubscribeLocalEvent(OnGridChanged); SubscribeLocalEvent(OnAlertLevelChanged); + + // UI Events: + SubscribeLocalEvent(OnUiMessage); + SubscribeLocalEvent(OnUiMessage); + SubscribeLocalEvent(OnUiMessage); + SubscribeLocalEvent(OnUiMessage); + SubscribeLocalEvent(OnUiMessage); + SubscribeLocalEvent(OnUiMessage); } protected override void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args) { base.OnComponentInit(uid, pda, args); - if (!TryComp(uid, out ServerUserInterfaceComponent? uiComponent)) + if (!HasComp(uid)) return; UpdateAlertLevel(uid, pda); UpdateStationName(uid, pda); - - if (_ui.TryGetUi(uid, PDAUiKey.Key, out var ui, uiComponent)) - ui.OnReceiveMessage += (msg) => OnUIMessage(pda, msg); } protected override void OnItemInserted(EntityUid uid, PDAComponent pda, EntInsertedIntoContainerMessage args) @@ -116,55 +122,66 @@ namespace Content.Server.PDA _cartridgeLoader?.UpdateUiState(uid, state); } - private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg) + private void OnUiMessage(EntityUid uid, PDAComponent pda, PDARequestUpdateInterfaceMessage msg) { - var uid = pda.Owner; - // todo: move this to entity events - switch (msg.Message) + if (!PDAUiKey.Key.Equals(msg.UiKey)) + return; + + UpdatePdaUi(uid, pda); + } + + private void OnUiMessage(EntityUid uid, PDAComponent pda, PDAToggleFlashlightMessage msg) + { + if (!PDAUiKey.Key.Equals(msg.UiKey)) + return; + + if (TryComp(uid, out var flashlight)) + _unpoweredFlashlight.ToggleLight(uid, flashlight); + } + + private void OnUiMessage(EntityUid uid, PDAComponent pda, PDAShowRingtoneMessage msg) + { + if (!PDAUiKey.Key.Equals(msg.UiKey)) + return; + + if (HasComp(uid)) + _ringer.ToggleRingerUI(uid, (IPlayerSession) msg.Session); + } + + private void OnUiMessage(EntityUid uid, PDAComponent pda, PDAShowMusicMessage msg) + { + if (!PDAUiKey.Key.Equals(msg.UiKey)) + return; + + if (TryComp(uid, out var instrument)) + _instrument.ToggleInstrumentUi(uid, (IPlayerSession) msg.Session, instrument); + } + + private void OnUiMessage(EntityUid uid, PDAComponent pda, PDAShowUplinkMessage msg) + { + if (!PDAUiKey.Key.Equals(msg.UiKey)) + return; + + // check if its locked again to prevent malicious clients opening locked uplinks + if (TryComp(uid, out var store) && IsUnlocked(uid)) + _store.ToggleUi(msg.Session.AttachedEntity!.Value, uid, store); + } + + private void OnUiMessage(EntityUid uid, PDAComponent pda, PDALockUplinkMessage msg) + { + if (!PDAUiKey.Key.Equals(msg.UiKey)) + return; + + if (TryComp(uid, out var uplink)) { - case PDARequestUpdateInterfaceMessage _: - UpdatePdaUi(uid, pda); - break; - case PDAToggleFlashlightMessage _: - { - if (TryComp(uid, out var flashlight)) - _unpoweredFlashlight.ToggleLight(uid, flashlight); - break; - } - case PDAShowRingtoneMessage _: - { - if (TryComp(uid, out var ringer)) - _ringer.ToggleRingerUI(ringer, msg.Session); - break; - } - case PDAShowMusicMessage _: - { - if (TryComp(uid, out var instrument)) - _instrument.ToggleInstrumentUi(uid, msg.Session, instrument); - break; - } - case PDAShowUplinkMessage _: - { - // check if its locked again to prevent malicious clients opening locked uplinks - if (TryComp(uid, out var store) && IsUnlocked(uid)) - _store.ToggleUi(msg.Session.AttachedEntity!.Value, uid, store); - break; - } - case PDALockUplinkMessage _: - { - if (TryComp(uid, out var uplink)) - { - _ringer.LockUplink(uid, uplink); - UpdatePdaUi(uid, pda); - } - break; - } + _ringer.LockUplink(uid, uplink); + UpdatePdaUi(uid, pda); } } private bool IsUnlocked(EntityUid uid) { - return TryComp(uid, out var uplink) ? uplink.Unlocked : true; + return !TryComp(uid, out var uplink) || uplink.Unlocked; } private void UpdateStationName(EntityUid uid, PDAComponent pda) diff --git a/Content.Server/PDA/Ringer/RingerComponent.cs b/Content.Server/PDA/Ringer/RingerComponent.cs index cb569f9327..5ef26a8426 100644 --- a/Content.Server/PDA/Ringer/RingerComponent.cs +++ b/Content.Server/PDA/Ringer/RingerComponent.cs @@ -30,5 +30,7 @@ namespace Content.Server.PDA.Ringer } [RegisterComponent] - public sealed class ActiveRingerComponent : Component {} + public sealed class ActiveRingerComponent : Component + { + } } diff --git a/Content.Server/PDA/Ringer/RingerSystem.cs b/Content.Server/PDA/Ringer/RingerSystem.cs index 46c26fc190..fd171c369f 100644 --- a/Content.Server/PDA/Ringer/RingerSystem.cs +++ b/Content.Server/PDA/Ringer/RingerSystem.cs @@ -1,6 +1,5 @@ using Content.Server.Store.Components; using Content.Server.Store.Systems; -using Content.Server.UserInterface; using Content.Shared.PDA; using Content.Shared.PDA.Ringer; using Content.Shared.Store; @@ -18,8 +17,8 @@ namespace Content.Server.PDA.Ringer { [Dependency] private readonly PDASystem _pda = default!; [Dependency] private readonly IRobustRandom _random = default!; - [Dependency] private readonly StoreSystem _store = default!; [Dependency] private readonly UserInterfaceSystem _ui = default!; + [Dependency] private readonly AudioSystem _audio = default!; public override void Initialize() { @@ -49,12 +48,12 @@ namespace Content.Server.PDA.Ringer private void RingerPlayRingtone(EntityUid uid, RingerComponent ringer, RingerPlayRingtoneMessage args) { EnsureComp(uid); - UpdateRingerUserInterface(ringer); + UpdateRingerUserInterface(uid, ringer); } private void UpdateRingerUserInterfaceDriver(EntityUid uid, RingerComponent ringer, RingerRequestUpdateInterfaceMessage args) { - UpdateRingerUserInterface(ringer); + UpdateRingerUserInterface(uid, ringer); } private void OnSetRingtone(EntityUid uid, RingerComponent ringer, RingerSetRingtoneMessage args) @@ -67,12 +66,12 @@ namespace Content.Server.PDA.Ringer if (ev.Handled) return; - UpdateRingerRingtone(ringer, args.Ringtone); + UpdateRingerRingtone(uid, ringer, args.Ringtone); } private void OnSetUplinkRingtone(EntityUid uid, RingerUplinkComponent uplink, ref BeforeRingtoneSetEvent args) { - if (uplink.Code.SequenceEqual(args.Ringtone) && TryComp(uid, out var store)) + if (uplink.Code.SequenceEqual(args.Ringtone) && HasComp(uid)) { uplink.Unlocked = !uplink.Unlocked; if (TryComp(uid, out var pda)) @@ -104,7 +103,7 @@ namespace Content.Server.PDA.Ringer public void RandomizeRingtone(EntityUid uid, RingerComponent ringer, MapInitEvent args) { - UpdateRingerRingtone(ringer, GenerateRingtone()); + UpdateRingerRingtone(uid, ringer, GenerateRingtone()); } public void RandomizeUplinkCode(EntityUid uid, RingerUplinkComponent uplink, ComponentInit args) @@ -136,25 +135,25 @@ namespace Content.Server.PDA.Ringer return ringtone; } - private bool UpdateRingerRingtone(RingerComponent ringer, Note[] ringtone) + private bool UpdateRingerRingtone(EntityUid uid, RingerComponent ringer, Note[] ringtone) { // Assume validation has already happened. ringer.Ringtone = ringtone; - UpdateRingerUserInterface(ringer); + UpdateRingerUserInterface(uid, ringer); return true; } - private void UpdateRingerUserInterface(RingerComponent ringer) + private void UpdateRingerUserInterface(EntityUid uid, RingerComponent ringer) { - var ui = ringer.Owner.GetUIOrNull(RingerUiKey.Key); - ui?.SetState(new RingerUpdateState(HasComp(ringer.Owner), ringer.Ringtone)); + if (_ui.TryGetUi(uid, RingerUiKey.Key, out var bui)) + _ui.SetUiState(bui, new RingerUpdateState(HasComp(uid), ringer.Ringtone)); } - public bool ToggleRingerUI(RingerComponent ringer, IPlayerSession session) + public bool ToggleRingerUI(EntityUid uid, IPlayerSession session) { - var ui = ringer.Owner.GetUIOrNull(RingerUiKey.Key); - ui?.Toggle(session); + if (_ui.TryGetUi(uid, RingerUiKey.Key, out var bui)) + _ui.ToggleUi(bui, session); return true; } @@ -162,25 +161,31 @@ namespace Content.Server.PDA.Ringer { var remove = new RemQueue(); - foreach(var (_, ringer) in EntityManager.EntityQuery()) + var pdaQuery = EntityQueryEnumerator(); + while (pdaQuery.MoveNext(out var uid, out var ringer, out var _)) { ringer.TimeElapsed += frameTime; - if (ringer.TimeElapsed < NoteDelay) continue; + if (ringer.TimeElapsed < NoteDelay) + continue; ringer.TimeElapsed -= NoteDelay; - var ringerXform = Transform(ringer.Owner); + var ringerXform = Transform(uid); - SoundSystem.Play(GetSound(ringer.Ringtone[ringer.NoteCount]), + _audio.Play( + GetSound(ringer.Ringtone[ringer.NoteCount]), Filter.Empty().AddInRange(ringerXform.MapPosition, ringer.Range), - ringer.Owner, AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume)); + uid, + true, + AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume) + ); ringer.NoteCount++; if (ringer.NoteCount > 3) { - remove.Add(ringer.Owner); - UpdateRingerUserInterface(ringer); + remove.Add(uid); + UpdateRingerUserInterface(uid, ringer); ringer.TimeElapsed = 0; ringer.NoteCount = 0; break; @@ -193,12 +198,12 @@ namespace Content.Server.PDA.Ringer } } - private string GetSound(Note note) + private static string GetSound(Note note) { return new ResPath("/Audio/Effects/RingtoneNotes/" + note.ToString().ToLower()) + ".ogg"; } } -} -[ByRefEvent] -public record struct BeforeRingtoneSetEvent(Note[] Ringtone, bool Handled = false); + [ByRefEvent] + public record struct BeforeRingtoneSetEvent(Note[] Ringtone, bool Handled = false); +} diff --git a/Content.Shared/PDA/PDAMessagesUI.cs b/Content.Shared/PDA/PDAMessagesUI.cs index d0e32d8723..486c7e8101 100644 --- a/Content.Shared/PDA/PDAMessagesUI.cs +++ b/Content.Shared/PDA/PDAMessagesUI.cs @@ -35,5 +35,5 @@ public sealed class PDAShowMusicMessage : BoundUserInterfaceMessage [Serializable, NetSerializable] public sealed class PDARequestUpdateInterfaceMessage : BoundUserInterfaceMessage { - public PDARequestUpdateInterfaceMessage() { } + public PDARequestUpdateInterfaceMessage() { } } diff --git a/Content.Shared/PDA/Ringer/RingerMessagesUI.cs b/Content.Shared/PDA/Ringer/RingerMessagesUI.cs index 4ae5664e8f..36867284b4 100644 --- a/Content.Shared/PDA/Ringer/RingerMessagesUI.cs +++ b/Content.Shared/PDA/Ringer/RingerMessagesUI.cs @@ -4,15 +4,19 @@ namespace Content.Shared.PDA.Ringer { [Serializable, NetSerializable] - public sealed class RingerRequestUpdateInterfaceMessage : BoundUserInterfaceMessage {} + public sealed class RingerRequestUpdateInterfaceMessage : BoundUserInterfaceMessage + { + } [Serializable, NetSerializable] - public sealed class RingerPlayRingtoneMessage : BoundUserInterfaceMessage {} + public sealed class RingerPlayRingtoneMessage : BoundUserInterfaceMessage + { + } [Serializable, NetSerializable] public sealed class RingerSetRingtoneMessage : BoundUserInterfaceMessage { - public Note[] Ringtone {get;} + public Note[] Ringtone { get; } public RingerSetRingtoneMessage(Note[] ringTone) { diff --git a/Content.Shared/PDA/SharedPDASystem.cs b/Content.Shared/PDA/SharedPDASystem.cs index c0d4249ca4..ec2d98f41c 100644 --- a/Content.Shared/PDA/SharedPDASystem.cs +++ b/Content.Shared/PDA/SharedPDASystem.cs @@ -7,7 +7,7 @@ namespace Content.Shared.PDA public abstract class SharedPDASystem : EntitySystem { [Dependency] protected readonly ItemSlotsSystem ItemSlotsSystem = default!; - [Dependency] protected readonly SharedAppearanceSystem _appearance = default!; + [Dependency] protected readonly SharedAppearanceSystem Appearance = default!; public override void Initialize() { @@ -55,8 +55,7 @@ namespace Content.Shared.PDA private void UpdatePdaAppearance(EntityUid uid, PDAComponent pda) { - if (TryComp(pda.Owner, out AppearanceComponent ? appearance)) - _appearance.SetData(uid, PDAVisuals.IDCardInserted, pda.ContainedID != null, appearance); + Appearance.SetData(uid, PDAVisuals.IDCardInserted, pda.ContainedID != null); } } }