This commit is contained in:
Tleety
2016-03-08 16:15:54 +01:00
parent a0ca4df3be
commit f8ab52c72c
4 changed files with 120 additions and 44 deletions
+6
View File
@@ -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<MainMenuSystem, Events::ButtonPressed> m_EPressed;
bool OnButtonPress(const Events::ButtonPressed& e);
EventRelay<MainMenuSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
std::string m_CurrentCommand = "";
};
+40
View File
@@ -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<MainMenuSystem, Events::ButtonClicked> m_EClicked;
bool OnButtonClick(const Events::ButtonClicked& e);
EventRelay<MainMenuSystem, Events::ButtonReleased> m_EReleased;
bool OnButtonRelease(const Events::ButtonReleased& e);
EventRelay<MainMenuSystem, Events::ButtonPressed> m_EPressed;
bool OnButtonPress(const Events::ButtonPressed& e);
EventRelay<MainMenuSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
std::string m_CurrentCommand = "";
EntityWrapper m_OpenSubMenu = EntityWrapper::Invalid;
};
#endif
+42 -42
View File
@@ -17,6 +17,47 @@
</c:Transform>
</Components>
<Children>
<Entity name="ButtonPos_3">
<Components>
<c:Transform>
<Position X="0" Y="-0.140000001" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="Button_3">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/White.png</DiffuseTexture>
<BlurBackground>true</BlurBackground>
<GlowMap></GlowMap>
<Color A="0.588235319" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
<Scale X="0.200000003" Y="0.0500000007" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Text">
<Components>
<c:Text>
<Content>Credits</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="0" R="0"/>
<Alignment>
<Left/>
</Alignment>
</c:Text>
<c:Transform>
<Position X="-0.075000003" Y="-0.0150000006" Z="0.00100000005"/>
<Scale X="0.0199999996" Y="0.0199999996" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="ButtonPos_1">
<Components>
<c:Transform/>
@@ -101,47 +142,6 @@
</Entity>
</Children>
</Entity>
<Entity name="ButtonPos_3">
<Components>
<c:Transform>
<Position X="0" Y="-0.140000001" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="Button_3">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/White.png</DiffuseTexture>
<BlurBackground>true</BlurBackground>
<GlowMap></GlowMap>
<Color A="0.588235319" B="1" G="1" R="1"/>
</c:Sprite>
<c:Transform>
<Scale X="0.200000003" Y="0.0500000007" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Text">
<Components>
<c:Text>
<Content>Credits</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Color A="1" B="0" G="0" R="0"/>
<Alignment>
<Left/>
</Alignment>
</c:Text>
<c:Transform>
<Position X="-0.075000003" Y="-0.0150000006" Z="0.00100000005"/>
<Scale X="0.0199999996" Y="0.0199999996" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="ButtonPos_4">
<Components>
<c:Transform>
@@ -192,7 +192,7 @@
</c:Transform>
</Components>
<Children>
<Entity name="ServerListSpawner">
<Entity name="PlaySpawner">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/ServerList.xml</EntityFile>
@@ -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;
}