UiStartMenuComponent.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <Multiplayer/IMultiplayer.h>
  11. namespace MultiplayerSample
  12. {
  13. /*!
  14. * \class UiStartMenuComponent
  15. * \brief Ui component used for allowing game launcher applications to enter an IP address for connecting to a host.
  16. * UnifiedLaunchers, which may either host or join a multiplayer game, will have a button option to host a game.
  17. */
  18. class UiStartMenuComponent
  19. : public AZ::Component
  20. {
  21. public:
  22. // The level a server or unified launcher will need to load once it begins hosting
  23. static constexpr char MultiplayerLevelName[] = "NewStarbase";
  24. AZ_COMPONENT(MultiplayerSample::UiStartMenuComponent, "{2F9DA138-1750-4FC9-B1AE-7945D2C1AB4D}");
  25. /*
  26. * Reflects component data into the reflection contexts, including the serialization, edit, and behavior contexts.
  27. */
  28. static void Reflect(AZ::ReflectContext* context);
  29. protected:
  30. void Activate() override;
  31. void Deactivate() override;
  32. private:
  33. // Listen for disconnect events to know if connecting to the host server failed
  34. void OnConnectToHostFailed();
  35. Multiplayer::EndpointDisconnectedEvent::Handler m_onConnectToHostFailed{[this]([[maybe_unused]] Multiplayer::MultiplayerAgentType agent) { OnConnectToHostFailed(); }};
  36. void OnButtonClicked(AZ::EntityId buttonEntityId) const;
  37. AZ::EntityId m_hostButtonUi;
  38. AZ::EntityId m_joinButtonUi;
  39. AZ::EntityId m_exitButtonUi;
  40. AZ::EntityId m_ipAddressTextInputUi;
  41. AZ::EntityId m_attemptConnectionBlockerUi;
  42. AZ::EntityId m_connectToHostFailedUi;
  43. };
  44. } // namespace MultiplayerSample