From 65f10191f1843076aa2ea32b9f3f5b084f6f3181 Mon Sep 17 00:00:00 2001 From: Pierson Arnold Date: Wed, 3 Jul 2024 15:07:34 -0500 Subject: [PATCH 1/2] Added consent Menu tahnsk to 0x40 --- .../Consent/ClientConsentManager.cs | 45 + Content.Client/Consent/ConsentSystem.cs | 7 + .../Consent/IClientConsentManager.cs | 13 + .../Consent/UI/ConsentUiController.cs | 102 + .../Consent/UI/Windows/ConsentWindow.xaml | 63 + .../Consent/UI/Windows/ConsentWindow.xaml.cs | 101 + Content.Client/Entry/EntryPoint.cs | 3 + Content.Client/Input/ContentContexts.cs | 1 + Content.Client/IoC/ClientContentIoC.cs | 2 + .../Options/UI/Tabs/KeyRebindTab.xaml.cs | 1 + .../MenuBar/GameTopMenuBarUIController.cs | 4 + .../MenuBar/Widgets/GameTopMenuBar.xaml | 12 +- .../20240703070917_ConsentSystem.Designer.cs | 1893 +++++++++++++++++ .../Postgres/20240703070917_ConsentSystem.cs | 22 + .../PostgresServerDbContextModelSnapshot.cs | 86 +- .../20240703071111_ConsentSystem.Designer.cs | 1818 ++++++++++++++++ .../Sqlite/20240703071111_ConsentSystem.cs | 72 + .../SqliteServerDbContextModelSnapshot.cs | 82 +- Content.Server.Database/Model.cs | 28 + Content.Server/Consent/ConsentSystem.cs | 47 + .../Consent/IServerConsentManager.cs | 21 + .../Consent/ServerConsentManager.cs | 98 + Content.Server/Database/ServerDbBase.cs | 100 + Content.Server/Database/ServerDbManager.cs | 19 + Content.Server/Database/UserDbDataManager.cs | 8 +- Content.Server/Entry/EntryPoint.cs | 2 + Content.Server/IoC/ServerContentIoC.cs | 2 + Content.Shared.Database/LogType.cs | 3 +- Content.Shared/CCVar/CCVars.cs | 6 + .../Consent/ConsentTogglePrototype.cs | 19 + Content.Shared/Consent/MsgUpdateConsent.cs | 33 + .../Consent/PlayerConsentSettings.cs | 41 + Content.Shared/Consent/SharedConsentSystem.cs | 49 + Content.Shared/Floofstation/FSCVars.cs | 13 + Content.Shared/Input/ContentKeyFunctions.cs | 1 + .../Floofstation/floofstation.toml | 2 + Resources/Locale/en-US/Blep/consent.ftl | 22 + Resources/Locale/en-US/HUD/game-hud.ftl | 1 + Resources/Prototypes/Consent/examples.yml | 3 + Resources/keybinds.yml | 6 +- 40 files changed, 4834 insertions(+), 17 deletions(-) create mode 100644 Content.Client/Consent/ClientConsentManager.cs create mode 100644 Content.Client/Consent/ConsentSystem.cs create mode 100644 Content.Client/Consent/IClientConsentManager.cs create mode 100644 Content.Client/Consent/UI/ConsentUiController.cs create mode 100644 Content.Client/Consent/UI/Windows/ConsentWindow.xaml create mode 100644 Content.Client/Consent/UI/Windows/ConsentWindow.xaml.cs create mode 100644 Content.Server.Database/Migrations/Postgres/20240703070917_ConsentSystem.Designer.cs create mode 100644 Content.Server.Database/Migrations/Postgres/20240703070917_ConsentSystem.cs create mode 100644 Content.Server.Database/Migrations/Sqlite/20240703071111_ConsentSystem.Designer.cs create mode 100644 Content.Server.Database/Migrations/Sqlite/20240703071111_ConsentSystem.cs create mode 100644 Content.Server/Consent/ConsentSystem.cs create mode 100644 Content.Server/Consent/IServerConsentManager.cs create mode 100644 Content.Server/Consent/ServerConsentManager.cs create mode 100644 Content.Shared/Consent/ConsentTogglePrototype.cs create mode 100644 Content.Shared/Consent/MsgUpdateConsent.cs create mode 100644 Content.Shared/Consent/PlayerConsentSettings.cs create mode 100644 Content.Shared/Consent/SharedConsentSystem.cs create mode 100644 Content.Shared/Floofstation/FSCVars.cs create mode 100644 Resources/ConfigPresets/Floofstation/floofstation.toml create mode 100644 Resources/Locale/en-US/Blep/consent.ftl create mode 100644 Resources/Prototypes/Consent/examples.yml diff --git a/Content.Client/Consent/ClientConsentManager.cs b/Content.Client/Consent/ClientConsentManager.cs new file mode 100644 index 00000000000..259b2dfe28e --- /dev/null +++ b/Content.Client/Consent/ClientConsentManager.cs @@ -0,0 +1,45 @@ +using Content.Shared.Consent; +using Robust.Shared.Network; + +namespace Content.Client.Consent; + +public sealed class ClientConsentManager : IClientConsentManager +{ + [Dependency] private readonly IClientNetManager _netManager = default!; + + // TODO: sync all players consent settings with ServerConsentManager, for client prediction + private PlayerConsentSettings? _consent; + + public bool HasLoaded => _consent is not null; + + public event Action? OnServerDataLoaded; + + public void Initialize() + { + _netManager.RegisterNetMessage(HandleUpdateConsent); + } + + public void UpdateConsent(PlayerConsentSettings consentSettings) + { + var msg = new MsgUpdateConsent + { + Consent = consentSettings + }; + _netManager.ClientSendMessage(msg); + } + + public PlayerConsentSettings GetConsent() + { + if (_consent is null) + throw new InvalidOperationException("Consent settings not loaded yet?"); + + return _consent; + } + + private void HandleUpdateConsent(MsgUpdateConsent message) + { + _consent = message.Consent; + + OnServerDataLoaded?.Invoke(); + } +} diff --git a/Content.Client/Consent/ConsentSystem.cs b/Content.Client/Consent/ConsentSystem.cs new file mode 100644 index 00000000000..8c3fb9c46c7 --- /dev/null +++ b/Content.Client/Consent/ConsentSystem.cs @@ -0,0 +1,7 @@ +using Content.Shared.Consent; + +namespace Content.Client.Consent; + +public sealed class ConsentSystem : SharedConsentSystem +{ +} diff --git a/Content.Client/Consent/IClientConsentManager.cs b/Content.Client/Consent/IClientConsentManager.cs new file mode 100644 index 00000000000..1f0e22d52ef --- /dev/null +++ b/Content.Client/Consent/IClientConsentManager.cs @@ -0,0 +1,13 @@ +using Content.Shared.Consent; + +namespace Content.Client.Consent; + +public interface IClientConsentManager +{ + event Action OnServerDataLoaded; + bool HasLoaded { get; } + + void Initialize(); + void UpdateConsent(PlayerConsentSettings consentSettings); + PlayerConsentSettings GetConsent(); +} diff --git a/Content.Client/Consent/UI/ConsentUiController.cs b/Content.Client/Consent/UI/ConsentUiController.cs new file mode 100644 index 00000000000..c0b91da8620 --- /dev/null +++ b/Content.Client/Consent/UI/ConsentUiController.cs @@ -0,0 +1,102 @@ +using Content.Client.Consent.UI.Windows; +using Content.Client.Gameplay; +using Content.Client.UserInterface.Controls; +using Content.Client.UserInterface.Systems.MenuBar.Widgets; +using Content.Shared.Input; +using Robust.Client.Input; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controllers; +using Robust.Client.UserInterface.Controllers.Implementations; +using Robust.Shared.Input.Binding; +using Robust.Shared.Map; +using Robust.Shared.Player; +using Robust.Shared.Utility; +using JetBrains.Annotations; +using static Robust.Client.UserInterface.Controls.BaseButton; + +namespace Content.Client.Consent.UI; + +[UsedImplicitly] +public sealed class ConsentUiController : UIController, IOnStateChanged +{ + [Dependency] private readonly IInputManager _input = default!; + + private ConsentWindow? _window; + + private MenuButton? ConsentButton => UIManager.GetActiveUIWidgetOrNull()?.ConsentButton; + + public void OnStateEntered(GameplayState state) + { + EnsureWindow(); + + _input.SetInputCommand(ContentKeyFunctions.OpenConsentWindow, + InputCmdHandler.FromDelegate(_ => ToggleWindow())); + } + + public void OnStateExited(GameplayState state) + { + if (_window != null) + { + _window.Dispose(); + _window = null; + } + } + + public void UnloadButton() + { + if (ConsentButton == null) + { + return; + } + + ConsentButton.OnPressed -= ConsentButtonPressed; + } + + public void LoadButton() + { + if (ConsentButton == null) + { + return; + } + + ConsentButton.OnPressed += ConsentButtonPressed; + } + + private void ConsentButtonPressed(ButtonEventArgs args) + { + ToggleWindow(); + } + + private void EnsureWindow() + { + if (_window is { Disposed: false }) + return; + + _window = UIManager.CreateWindow(); + _window.OnOpen += () => { + if (ConsentButton is not null) + ConsentButton.Pressed = true; + }; + _window.OnClose += () => { + if (ConsentButton is not null) + ConsentButton.Pressed = false; + _window.UpdateUi(); // Discard unsaved changes + }; + } + + private void ToggleWindow() + { + if (_window is null) + return; + + UIManager.ClickSound(); + if (_window.IsOpen != true) + { + _window.OpenCentered(); + } + else + { + _window.Close(); + } + } +} diff --git a/Content.Client/Consent/UI/Windows/ConsentWindow.xaml b/Content.Client/Consent/UI/Windows/ConsentWindow.xaml new file mode 100644 index 00000000000..09d31a88cdf --- /dev/null +++ b/Content.Client/Consent/UI/Windows/ConsentWindow.xaml @@ -0,0 +1,63 @@ + + +