From f8ab52c72c6685b0456f1b828a1098f143395c9a Mon Sep 17 00:00:00 2001 From: Tleety Date: Tue, 8 Mar 2016 16:15:54 +0100 Subject: [PATCH] WIP --- include/Engine/GUI/MainMenuSystem.h | 6 ++ include/Game/Systems/MainMenuSystem.h | 40 +++++++++ resources/Schema/Entities/MainMenu.xml | 84 +++++++++---------- .../GUI => Game/Systems}/MainMenuSystem.cpp | 34 +++++++- 4 files changed, 120 insertions(+), 44 deletions(-) create mode 100644 include/Game/Systems/MainMenuSystem.h rename src/{Engine/GUI => Game/Systems}/MainMenuSystem.cpp (53%) diff --git a/include/Engine/GUI/MainMenuSystem.h b/include/Engine/GUI/MainMenuSystem.h index ba69ff0d..7fb65828 100644 --- a/include/Engine/GUI/MainMenuSystem.h +++ b/include/Engine/GUI/MainMenuSystem.h @@ -5,11 +5,13 @@ #include "../Rendering/IRenderer.h" #include "../Core/ResourceManager.h" #include "../Core/Event.h" +#include "Systems/SpawnerSystem.h" #include "EButtonClicked.h" #include "EButtonPressed.h" #include "EButtonReleased.h" +#include "../Input/EInputCommand.h" class MainMenuSystem : public ImpureSystem @@ -27,6 +29,10 @@ private: bool OnButtonRelease(const Events::ButtonReleased& e); EventRelay m_EPressed; bool OnButtonPress(const Events::ButtonPressed& e); + EventRelay m_EInputCommand; + bool OnInputCommand(const Events::InputCommand& e); + + std::string m_CurrentCommand = ""; }; diff --git a/include/Game/Systems/MainMenuSystem.h b/include/Game/Systems/MainMenuSystem.h new file mode 100644 index 00000000..2e13b557 --- /dev/null +++ b/include/Game/Systems/MainMenuSystem.h @@ -0,0 +1,40 @@ +#ifndef MainMenuSystem_h__ +#define MainMenuSystem_h__ + +#include "Core/System.h" +#include "Rendering/IRenderer.h" +#include "Core/ResourceManager.h" +#include "Core/Event.h" +#include "Systems/SpawnerSystem.h" + + +#include "GUI/EButtonClicked.h" +#include "GUI/EButtonPressed.h" +#include "GUI/EButtonReleased.h" +#include "Input/EInputCommand.h" + + +class MainMenuSystem : public ImpureSystem +{ +public: + MainMenuSystem(SystemParams params, IRenderer* renderer); + virtual void Update(double dt) override; + +private: + IRenderer* m_Renderer; + + EventRelay m_EClicked; + bool OnButtonClick(const Events::ButtonClicked& e); + EventRelay m_EReleased; + bool OnButtonRelease(const Events::ButtonReleased& e); + EventRelay m_EPressed; + bool OnButtonPress(const Events::ButtonPressed& e); + EventRelay m_EInputCommand; + bool OnInputCommand(const Events::InputCommand& e); + + std::string m_CurrentCommand = ""; + EntityWrapper m_OpenSubMenu = EntityWrapper::Invalid; + +}; + +#endif \ No newline at end of file diff --git a/resources/Schema/Entities/MainMenu.xml b/resources/Schema/Entities/MainMenu.xml index 47292c30..cefb25e2 100644 --- a/resources/Schema/Entities/MainMenu.xml +++ b/resources/Schema/Entities/MainMenu.xml @@ -17,6 +17,47 @@ + + + + + + + + + + + + Textures/Core/White.png + true + + + + + + + + + + + + + Credits + Fonts/DroidSans.ttf,64 + + + + + + + + + + + + + + @@ -101,47 +142,6 @@ - - - - - - - - - - - - Textures/Core/White.png - true - - - - - - - - - - - - - Credits - Fonts/DroidSans.ttf,64 - - - - - - - - - - - - - - @@ -192,7 +192,7 @@ - + Schema/Entities/ServerList.xml diff --git a/src/Engine/GUI/MainMenuSystem.cpp b/src/Game/Systems/MainMenuSystem.cpp similarity index 53% rename from src/Engine/GUI/MainMenuSystem.cpp rename to src/Game/Systems/MainMenuSystem.cpp index c37aabc1..14cf7e26 100644 --- a/src/Engine/GUI/MainMenuSystem.cpp +++ b/src/Game/Systems/MainMenuSystem.cpp @@ -1,4 +1,4 @@ -#include "GUI/MainMenuSystem.h" +#include "../Game/Systems/MainMenuSystem.h" MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer) : System(params) @@ -8,6 +8,7 @@ MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer) EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress); EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease); EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick); + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &MainMenuSystem::OnInputCommand); } void MainMenuSystem::Update(double dt) @@ -18,7 +19,8 @@ void MainMenuSystem::Update(double dt) bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e) { if(e.EntityName == "Play") { - //Run play code + //OpenServerList + } else if(e.EntityName == "Connect") { //Run connect code } else if(e.EntityName == "Host") { @@ -52,3 +54,31 @@ bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e) return true; } +bool MainMenuSystem::OnInputCommand(const Events::InputCommand& e) +{ + if(e.Command == "Play") { + if (m_OpenSubMenu == EntityWrapper::Invalid) { + //No submenu is open, open one. + + } else if(!m_OpenSubMenu.HasComponent("ServerList")) { + //Menu is open, but not the right one, delete the old one and open a new one. + + } else { + //Serverlist submenu is open, close it. + } + //Create new entity through the spawner. Should also despawn all other menus. + auto menus = m_World->GetComponents("Menu"); + if(menus == nullptr) { + return 0; + } + for (auto& menu : *menus) { + EntityWrapper menuEntity = EntityWrapper(m_World, menu.EntityID); + auto serverListSpawner = menuEntity.FirstChildByName(e.Command + "Spawner"); + if(!serverListSpawner.HasComponent("Spawner")) { + return 0; + } + m_OpenSubMenu = SpawnerSystem::Spawn(serverListSpawner, serverListSpawner); + } + } + return true; +} \ No newline at end of file