From 25fc23c275451ba62a7284be9733d0de46262752 Mon Sep 17 00:00:00 2001 From: AwareFoxy <135021509+AwareFoxy@users.noreply.github.com> Date: Sat, 7 Dec 2024 01:45:50 +0100 Subject: [PATCH 1/5] Audio Admin Panel (#125) * first * fix govna * forgot about using FUCK --- .../UI/Tabs/AdminTab/AdminTab.xaml | 3 + .../UI/Audio/AdminAudioPanelEui.cs | 138 ++++++++++++ .../UI/Audio/Widgets/AdminAudioPanel.xaml | 50 +++++ .../UI/Audio/Widgets/AdminAudioPanel.xaml.cs | 185 ++++++++++++++++ .../UI/Audio/AdminAudioPanelEui.cs | 121 +++++++++++ .../UI/Audio/AdminAudioPanelSystem.cs | 204 ++++++++++++++++++ .../Audio/Commands/OpenAudioPanelCommand.cs | 27 +++ .../UI/Audio/AdminAudioPanelEuiState.cs | 75 +++++++ .../audio/widgets/admin-audio-panel.ftl | 10 + .../tabs/admin-tab/player-actions-window.ftl | 1 + 10 files changed, 814 insertions(+) create mode 100644 Content.Client/_CorvaxNext/Administration/UI/Audio/AdminAudioPanelEui.cs create mode 100644 Content.Client/_CorvaxNext/Administration/UI/Audio/Widgets/AdminAudioPanel.xaml create mode 100644 Content.Client/_CorvaxNext/Administration/UI/Audio/Widgets/AdminAudioPanel.xaml.cs create mode 100644 Content.Server/_CorvaxNext/Administration/UI/Audio/AdminAudioPanelEui.cs create mode 100644 Content.Server/_CorvaxNext/Administration/UI/Audio/AdminAudioPanelSystem.cs create mode 100644 Content.Server/_CorvaxNext/Administration/UI/Audio/Commands/OpenAudioPanelCommand.cs create mode 100644 Content.Shared/_CorvaxNext/Administration/UI/Audio/AdminAudioPanelEuiState.cs create mode 100644 Resources/Locale/ru-RU/_CorvaxNext/audio/widgets/admin-audio-panel.ftl diff --git a/Content.Client/Administration/UI/Tabs/AdminTab/AdminTab.xaml b/Content.Client/Administration/UI/Tabs/AdminTab/AdminTab.xaml index 8b68487547f..796af9c5735 100644 --- a/Content.Client/Administration/UI/Tabs/AdminTab/AdminTab.xaml +++ b/Content.Client/Administration/UI/Tabs/AdminTab/AdminTab.xaml @@ -16,6 +16,9 @@ + + + diff --git a/Content.Client/_CorvaxNext/Administration/UI/Audio/AdminAudioPanelEui.cs b/Content.Client/_CorvaxNext/Administration/UI/Audio/AdminAudioPanelEui.cs new file mode 100644 index 00000000000..806d55cd407 --- /dev/null +++ b/Content.Client/_CorvaxNext/Administration/UI/Audio/AdminAudioPanelEui.cs @@ -0,0 +1,138 @@ +using Content.Client.Eui; +using Content.Client._CorvaxNext.Administration.UI.Audio.Widgets; +using Content.Shared.Eui; +using Content.Shared._CorvaxNext.Administration.UI.Audio; +using Robust.Shared.Audio.Components; +using Robust.Shared.Audio.Systems; +using Robust.Shared.Utility; + +namespace Content.Client._CorvaxNext.Administration.UI.Audio; + +public sealed partial class AdminAudioPanelEui : BaseEui +{ + [Dependency] private readonly IEntitySystemManager _entitySystem = default!; + [Dependency] private readonly IEntityManager _entity = default!; + + private SharedAudioSystem _audioSystem; + + private AdminAudioPanelEuiState? _state = null; + private AdminAudioPanel? _adminAudioPanel = null; + + public AdminAudioPanelEui() : base() + { + IoCManager.InjectDependencies(this); + _audioSystem = _entitySystem.GetEntitySystem(); + } + + public override void HandleState(EuiStateBase state) + { + if (state is AdminAudioPanelEuiState adminAudioPanelState) + { + _state = adminAudioPanelState; + UpdateUI(); + } + } + + public override void Opened() + { + _adminAudioPanel = new AdminAudioPanel(); + _adminAudioPanel.OpenCentered(); + + _adminAudioPanel.OnPlayButtonEnabled += () => Play(); + _adminAudioPanel.OnPauseButtonEnabled += () => Pause(); + _adminAudioPanel.OnStopButtonEnabled += () => Stop(); + _adminAudioPanel.OnAddTrackPressed += (track) => AddTrack(track); + _adminAudioPanel.OnPlaybackReleased += (ratio) => SetPlayback(ratio); + _adminAudioPanel.OnGlobalCheckboxToggled += (toggled) => ChangeGlobalToggled(toggled); + _adminAudioPanel.OnVolumeLineTextChanged += (volume) => SetVolume(volume); + _adminAudioPanel.OnSelectPlayer += (guid) => SelectPlayer(guid); + _adminAudioPanel.OnUnselectPlayer += (guid) => UnselectPlayer(guid); + } + + public override void Closed() + { + if (_adminAudioPanel != null) + _adminAudioPanel.Close(); + } + + public void Play() + { + var message = new AdminAudioPanelEuiMessage.Play(); + SendMessage(message); + } + + public void Stop() + { + var message = new AdminAudioPanelEuiMessage.Stop(); + SendMessage(message); + } + + public void Pause() + { + var message = new AdminAudioPanelEuiMessage.Pause(); + SendMessage(message); + } + + public void SetPlayback(float ratio) + { + var message = new AdminAudioPanelEuiMessage.SetPlaybackPosition(ratio); + SendMessage(message); + } + + public void AddTrack(string track) + { + var message = new AdminAudioPanelEuiMessage.AddTrack(track); + SendMessage(message); + } + + public void ChangeGlobalToggled(bool toggled) + { + var message = new AdminAudioPanelEuiMessage.GlobalToggled(toggled); + SendMessage(message); + } + + public void SetVolume(float volume) + { + var message = new AdminAudioPanelEuiMessage.SetVolume(volume); + SendMessage(message); + } + + private void SelectPlayer(Guid player) + { + var message = new AdminAudioPanelEuiMessage.SelectPlayer(player); + SendMessage(message); + } + + private void UnselectPlayer(Guid player) + { + var message = new AdminAudioPanelEuiMessage.UnselectPlayer(player); + SendMessage(message); + } + + private void UpdateUI() + { + if (_adminAudioPanel is not { }) + return; + + if (_state is not { }) + return; + + var audioEntity = _entity.GetEntity(_state.Audio); + + _adminAudioPanel.SetAudioStream(audioEntity); + _adminAudioPanel.UpdateGlobalToggled(_state.Global); + _adminAudioPanel.UpdatePlayersContainer(_state.Players, _state.SelectedPlayers); + _adminAudioPanel.UpdatePlayingState(_state.Playing); + _adminAudioPanel.UpdateQueue(_state.Queue); + _adminAudioPanel.UpdateVolume(_state.Volume); + + if (_entity.TryGetComponent(audioEntity, out var audio)) + { + _adminAudioPanel.UpdateCurrentTrackLabel(audio.FileName); + } + else + { + _adminAudioPanel.UpdateCurrentTrackLabel(Loc.GetString("admin-audio-panel-track-name-nothing-playing")); + } + } +} diff --git a/Content.Client/_CorvaxNext/Administration/UI/Audio/Widgets/AdminAudioPanel.xaml b/Content.Client/_CorvaxNext/Administration/UI/Audio/Widgets/AdminAudioPanel.xaml new file mode 100644 index 00000000000..79e45b2bc8d --- /dev/null +++ b/Content.Client/_CorvaxNext/Administration/UI/Audio/Widgets/AdminAudioPanel.xaml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + +