UiSettingsComponent.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <AzCore/Component/Component.h>
  9. #include <AzFramework/Windowing/WindowBus.h>
  10. #include <Source/UserSettings/MultiplayerSampleUserSettings.h>
  11. namespace MultiplayerSample
  12. {
  13. struct UiToggle
  14. {
  15. AZ_TYPE_INFO(UiToggle, "{60AD7DDE-1730-41D8-BB82-630FF8008370}");
  16. static void Reflect(AZ::ReflectContext* context);
  17. AZ::EntityId m_labelEntity;
  18. AZ::EntityId m_leftButtonEntity;
  19. AZ::EntityId m_rightButtonEntity;
  20. };
  21. // This component is attached to the UI Settings screen and handles the logic for changing the user setting values
  22. // when the UI toggles are toggled. It activates on level load, not on settings screen navigation as one might think.
  23. // On activation, it reapplies all of the MPS user settings while initializing the toggles to help ensure that the
  24. // previously-applied settings weren't overridden by the server or by level loads.
  25. class UiSettingsComponent
  26. : public AZ::Component
  27. , public AzFramework::WindowNotificationBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(UiSettingsComponent, "{6F0F5495-E766-444C-808E-4EB91AD891D6}");
  31. static void Reflect(AZ::ReflectContext* context);
  32. void Activate() override;
  33. void Deactivate() override;
  34. private:
  35. // WindowNotificationBus overrides
  36. void OnFullScreenModeChanged(bool fullscreen) override;
  37. static AzFramework::NativeWindowHandle GetWindowHandle();
  38. enum class ToggleDirection
  39. {
  40. None,
  41. Left,
  42. Right
  43. };
  44. void InitializeToggle(UiToggle& toggle, AZStd::function<void(UiToggle&, ToggleDirection)> toggleUpdateFn);
  45. static void OnGraphicsApiToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  46. static void OnTextureQualityToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  47. static void OnMasterVolumeToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  48. static void OnMusicVolumeToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  49. static void OnSfxVolumeToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  50. static void OnVolumeToggle(VolumeChannel volumeChannel, UiToggle& toggle, ToggleDirection toggleDirection);
  51. static void OnFullscreenToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  52. static void OnResolutionToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  53. static void OnReflectionToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  54. static void OnMsaaToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  55. static void OnTaaToggle(UiToggle& toggle, ToggleDirection toggleDirection);
  56. template<typename ValueType>
  57. static uint32_t GetRotatedIndex(
  58. const AZStd::span<const AZStd::pair<ValueType, AZStd::string_view>> valuesToLabels,
  59. const ValueType& value, ToggleDirection toggleDirection);
  60. UiToggle m_graphicsApiToggle;
  61. UiToggle m_textureQualityToggle;
  62. UiToggle m_fullscreenToggle;
  63. UiToggle m_resolutionToggle;
  64. UiToggle m_reflectionToggle;
  65. UiToggle m_msaaToggle;
  66. UiToggle m_taaToggle;
  67. UiToggle m_masterVolumeToggle;
  68. UiToggle m_musicVolumeToggle;
  69. UiToggle m_sfxVolumeToggle;
  70. };
  71. }