Merge branch 'Menu-Tobias' into ResolutionChange
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#include "GUI/ButtonSystem.h"
|
||||
|
||||
ButtonSystem::ButtonSystem(SystemParams params, IRenderer* renderer)
|
||||
: System(params)
|
||||
, PureSystem("Button")
|
||||
, m_Renderer(renderer)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &ButtonSystem::OnMousePress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &ButtonSystem::OnMouseRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseLock, &ButtonSystem::OnMouseLock);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseUnlock, &ButtonSystem::OnMouseUnlock);
|
||||
}
|
||||
|
||||
|
||||
bool ButtonSystem::OnMouseLock(const Events::LockMouse& e)
|
||||
{
|
||||
m_MouseIsLocked = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ButtonSystem::OnMouseUnlock(const Events::UnlockMouse& e)
|
||||
{
|
||||
m_MouseIsLocked = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ButtonSystem::OnMousePress(const Events::MousePress& e)
|
||||
{
|
||||
if (e.Button == GLFW_MOUSE_BUTTON_1 && !m_MouseIsLocked) {
|
||||
m_PickData = m_Renderer->Pick(glm::vec2(e.X, e.Y));
|
||||
if (m_PickData.Entity != EntityID_Invalid && m_PickData.World == m_World) {
|
||||
if(m_World->HasComponent(m_PickData.Entity, "Button")) {
|
||||
//Entity is a button, save it and send pressed event.
|
||||
|
||||
m_PickEntity = EntityWrapper(m_World, m_PickData.Entity);
|
||||
|
||||
//You have clicked on a button entity, send pressed event.
|
||||
Events::ButtonPressed ePressed;
|
||||
ePressed.EntityName = m_PickEntity.Name();
|
||||
m_EventBroker->Publish(ePressed);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ButtonSystem::OnMouseRelease(const Events::MouseRelease& e)
|
||||
{
|
||||
if(!m_MouseIsLocked) {
|
||||
//Mouse is not locked, send release event.
|
||||
Events::ButtonReleased eReleased;
|
||||
m_EventBroker->Publish(eReleased);
|
||||
m_PickData = m_Renderer->Pick(glm::vec2(e.X, e.Y));
|
||||
if(m_PickData.Entity != EntityID_Invalid && m_PickData.World == m_World) {
|
||||
if(m_World->HasComponent(m_PickData.Entity, "Button")) {
|
||||
EntityWrapper ent = EntityWrapper(m_World, m_PickData.Entity);
|
||||
if (ent == m_PickEntity) {
|
||||
//The entity you released the mouse button on is the same as you pressed it on. "Clicked"
|
||||
Events::ButtonClicked eClicked;
|
||||
eClicked.EntityName = m_PickEntity.Name();
|
||||
m_EventBroker->Publish(eClicked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ButtonSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cHealth, double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "GUI/MainMenuSystem.h"
|
||||
|
||||
MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer)
|
||||
: System(params)
|
||||
, ImpureSystem()
|
||||
, m_Renderer(renderer)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick);
|
||||
}
|
||||
|
||||
void MainMenuSystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e)
|
||||
{
|
||||
if(e.EntityName == "Play") {
|
||||
//Run play code
|
||||
} else if(e.EntityName == "Connect") {
|
||||
//Run connect code
|
||||
} else if(e.EntityName == "Host") {
|
||||
//Run host code
|
||||
} else if(e.EntityName == "Quit") {
|
||||
printf("No, you stay");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MainMenuSystem::OnButtonRelease(const Events::ButtonReleased& e)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -689,9 +689,6 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
|
||||
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// m_SpriteProgram->Unbind();
|
||||
}
|
||||
|
||||
@@ -738,6 +735,8 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<E
|
||||
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), job->FillPercentage);
|
||||
GLERROR("Bind 19 uniform");
|
||||
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
|
||||
GLERROR("Bind 20 uniform");
|
||||
glUniform1f(glGetUniformLocation(shaderHandle, "GlowIntensity"), job->GlowIntencity);
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
@@ -773,6 +772,11 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<Model
|
||||
GLint Location_AmbientColor = glGetUniformLocation(shaderHandle, "AmbientColor");
|
||||
glUniform4fv(Location_AmbientColor, 1, glm::value_ptr(scene.AmbientColor));
|
||||
|
||||
GLERROR("Bind 10 uniform");
|
||||
GLint Location_GlowIntensity = glGetUniformLocation(shaderHandle, "GlowIntensity");
|
||||
|
||||
glUniform1f(Location_GlowIntensity, job->GlowIntencity);
|
||||
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
|
||||
@@ -234,6 +234,52 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& job : scene.Jobs.SpriteJob) {
|
||||
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
|
||||
if (!spriteJob->Pickable) {
|
||||
continue;
|
||||
}
|
||||
RenderState jobState;
|
||||
|
||||
if (spriteJob) {
|
||||
if (spriteJob->Depth == 0) {
|
||||
jobState.Disable(GL_DEPTH_TEST);
|
||||
}
|
||||
int pickColor[2] = { m_ColorCounter[0], m_ColorCounter[1] };
|
||||
|
||||
PickingInfo pickInfo;
|
||||
pickInfo.Entity = spriteJob->Entity;
|
||||
pickInfo.World = spriteJob->World;
|
||||
pickInfo.Camera = scene.Camera;
|
||||
|
||||
auto color = m_EntityColors.find(std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera));
|
||||
if (color != m_EntityColors.end()) {
|
||||
pickColor[0] = color->second[0];
|
||||
pickColor[1] = color->second[1];
|
||||
} else {
|
||||
m_EntityColors[std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera)] = glm::ivec2(pickColor[0], pickColor[1]);
|
||||
if (m_ColorCounter[0] > 255) {
|
||||
m_ColorCounter[0] = 0;
|
||||
m_ColorCounter[1] += 1;
|
||||
} else {
|
||||
m_ColorCounter[0] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
|
||||
|
||||
m_PickingProgram->Bind();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
glBindVertexArray(spriteJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
|
||||
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex * sizeof(unsigned int)));
|
||||
}
|
||||
}
|
||||
|
||||
/* for (auto &job : scene.Jobs.TransparentShieldedObjects) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
|
||||
@@ -306,8 +352,6 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
delete state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PickingPass::ClearPicking()
|
||||
{
|
||||
m_PickingColorsToEntity.clear();
|
||||
|
||||
+4
-6
@@ -26,6 +26,8 @@
|
||||
#include "Network/MultiplayerSnapshotFilter.h"
|
||||
#include "Game/Systems/AmmunitionHUDSystem.h"
|
||||
#include "Game/Systems/KillFeedSystem.h"
|
||||
#include "GUI/ButtonSystem.h"
|
||||
#include "GUI/MainMenuSystem.h"
|
||||
|
||||
|
||||
Game::Game(int argc, char* argv[])
|
||||
@@ -72,11 +74,6 @@ Game::Game(int argc, char* argv[])
|
||||
m_InputProxy->AddHandler<MouseInputHandler>();
|
||||
m_InputProxy->LoadBindings("Input.ini");
|
||||
|
||||
// Create the root level GUI frame
|
||||
m_FrameStack = new GUI::Frame(m_EventBroker);
|
||||
m_FrameStack->Width = m_Renderer->Resolution().Width;
|
||||
m_FrameStack->Height = m_Renderer->Resolution().Height;
|
||||
|
||||
// Create a world
|
||||
m_World = new World(m_EventBroker);
|
||||
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", "");
|
||||
@@ -132,6 +129,8 @@ Game::Game(int argc, char* argv[])
|
||||
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<AmmunitionHUDSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
|
||||
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
|
||||
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
|
||||
// Populate Octree with collidables
|
||||
++updateOrderLevel;
|
||||
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
|
||||
@@ -168,7 +167,6 @@ Game::~Game()
|
||||
delete m_NetworkServer;
|
||||
}
|
||||
delete m_World;
|
||||
delete m_FrameStack;
|
||||
delete m_InputProxy;
|
||||
delete m_InputManager;
|
||||
delete m_RenderFrame;
|
||||
|
||||
Reference in New Issue
Block a user