Complete main menu without event bindings.
This commit is contained in:
+62
-17
@@ -2,6 +2,10 @@
|
||||
#define GUI_BUTTON_H__
|
||||
|
||||
#include "GUI/TextureFrame.h"
|
||||
#include "GUI/EButtonEnter.h"
|
||||
#include "GUI/EButtonLeave.h"
|
||||
#include "GUI/EButtonPress.h"
|
||||
#include "GUI/EButtonRelease.h"
|
||||
#include "Core/EMouseMove.h"
|
||||
#include "Core/EMousePress.h"
|
||||
#include "Core/EMouseRelease.h"
|
||||
@@ -22,19 +26,34 @@ public:
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Button::OnMouseRelease);
|
||||
}
|
||||
|
||||
std::string TextureHover;
|
||||
std::string TexturePressed;
|
||||
std::string TextureReleased;
|
||||
void SetTextureHover(std::string resourceName)
|
||||
{
|
||||
m_TextureHover = resourceName;
|
||||
}
|
||||
void SetTextureReleased(std::string resourceName)
|
||||
{
|
||||
m_TextureReleased = resourceName;
|
||||
SetTexture(resourceName);
|
||||
}
|
||||
void SetTexturePressed(std::string resourceName)
|
||||
{
|
||||
m_TexturePressed = resourceName;
|
||||
}
|
||||
|
||||
void Draw(RenderQueueCollection& rq) override
|
||||
{
|
||||
if (m_Texture == nullptr && !TextureReleased.empty()) {
|
||||
SetTexture(TextureReleased);
|
||||
if (m_Texture == nullptr && !m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
|
||||
TextureFrame::Draw(rq);
|
||||
}
|
||||
|
||||
virtual void OnEnter() { }
|
||||
virtual void OnLeave() { }
|
||||
virtual void OnPress() { }
|
||||
virtual void OnRelease() { }
|
||||
|
||||
protected:
|
||||
bool m_MouseIsOver = false;
|
||||
bool m_IsDown = false;
|
||||
@@ -43,15 +62,25 @@ protected:
|
||||
{
|
||||
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
|
||||
if (isOver && !m_MouseIsOver) { // Enter
|
||||
LOG_INFO("%s mouse enter", m_Name.c_str());
|
||||
if (!m_IsDown) {
|
||||
SetTexture(TextureHover);
|
||||
if (!m_TextureHover.empty()) {
|
||||
SetTexture(m_TextureHover);
|
||||
}
|
||||
}
|
||||
OnEnter();
|
||||
Events::ButtonEnter e;
|
||||
e.FrameName = m_Name;
|
||||
EventBroker->Publish(e);
|
||||
} else if (!isOver && m_MouseIsOver) { // Leave
|
||||
LOG_INFO("%s mouse left", m_Name.c_str());
|
||||
if (!m_IsDown) {
|
||||
SetTexture(TextureReleased);
|
||||
if (!m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
}
|
||||
OnLeave();
|
||||
Events::ButtonLeave e;
|
||||
e.FrameName = m_Name;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
m_MouseIsOver = isOver;
|
||||
|
||||
@@ -63,13 +92,16 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TexturePressed.empty()) {
|
||||
SetTexture(TexturePressed);
|
||||
if (!m_TexturePressed.empty()) {
|
||||
SetTexture(m_TexturePressed);
|
||||
}
|
||||
|
||||
LOG_INFO("%s mouse pressed", m_Name.c_str());
|
||||
|
||||
m_IsDown = true;
|
||||
OnPress();
|
||||
Events::ButtonPress e;
|
||||
e.FrameName = m_Name;
|
||||
e.Button = this;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -80,13 +112,22 @@ protected:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TextureReleased.empty()) {
|
||||
SetTexture(TextureReleased);
|
||||
if (m_MouseIsOver) {
|
||||
if (!m_TextureHover.empty()) {
|
||||
SetTexture(m_TextureHover);
|
||||
}
|
||||
} else {
|
||||
if (!m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO("%s mouse released", m_Name.c_str());
|
||||
|
||||
m_IsDown = false;
|
||||
OnRelease();
|
||||
Events::ButtonRelease e;
|
||||
e.FrameName = m_Name;
|
||||
e.Button = this;
|
||||
EventBroker->Publish(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -95,6 +136,10 @@ private:
|
||||
EventRelay<Frame, Events::MouseMove> m_EMouseMove;
|
||||
EventRelay<Frame, Events::MousePress> m_EMousePress;
|
||||
EventRelay<Frame, Events::MouseRelease> m_EMouseRelease;
|
||||
|
||||
std::string m_TextureHover;
|
||||
std::string m_TexturePressed;
|
||||
std::string m_TextureReleased;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef Events_ButtonEnter_h__
|
||||
#define Events_ButtonEnter_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button hover. */
|
||||
struct ButtonEnter : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // Events_ButtonEnter_h__
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef Events_ButtonLeave_h__
|
||||
#define Events_ButtonLeave_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button hover. */
|
||||
struct ButtonLeave : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // Events_ButtonLeave_h__
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef Events_ButtonPress_h__
|
||||
#define Events_ButtonPress_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace GUI { class Button; }
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button press. */
|
||||
struct ButtonPress : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
GUI::Button* Button;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // Events_ButtonPress_h__
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef Events_ButtonRelease_h__
|
||||
#define Events_ButtonRelease_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace GUI { class Button; }
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown on GUI button release. */
|
||||
struct ButtonRelease : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
GUI::Button* Button;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // Events_ButtonRelease_h__
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef Events_SliderUpdate_h__
|
||||
#define Events_SliderUpdate_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace GUI { class Slider; }
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown when GUI slider is moved. */
|
||||
struct SliderUpdate : Event
|
||||
{
|
||||
std::string FrameName;
|
||||
GUI::Slider* Slider;
|
||||
float Percentage;
|
||||
float DeltaPercentage;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // Events_SliderUpdate_h__
|
||||
+34
-10
@@ -73,8 +73,6 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
Width = parent->Width;
|
||||
Height = parent->Height;
|
||||
m_Layer = parent->Layer() + 1;
|
||||
parent->AddChild(this);
|
||||
m_Parent = parent;
|
||||
@@ -128,12 +126,25 @@ public:
|
||||
else
|
||||
return X;
|
||||
}
|
||||
void SetLeft(int absLeft) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
X = absLeft - m_Parent->Left();
|
||||
} else {
|
||||
X = absLeft;
|
||||
}
|
||||
}
|
||||
int Right() const override
|
||||
{
|
||||
if (m_Parent)
|
||||
return std::min(m_Parent->Right(), Left() + Width);
|
||||
else
|
||||
return Left() + Width;
|
||||
return Left() + Width;
|
||||
}
|
||||
void SetRight(int absRight) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
X = absRight - Width - m_Parent->Left();
|
||||
} else {
|
||||
X = absRight - Width;
|
||||
}
|
||||
}
|
||||
int Top() const override
|
||||
{
|
||||
@@ -142,12 +153,25 @@ public:
|
||||
else
|
||||
return Y;
|
||||
}
|
||||
void SetTop(int absTop) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
Y = absTop - m_Parent->Top();
|
||||
} else {
|
||||
Y = absTop;
|
||||
}
|
||||
}
|
||||
int Bottom() const override
|
||||
{
|
||||
if (m_Parent)
|
||||
return std::min(m_Parent->Bottom(), Top() + Height);
|
||||
else
|
||||
return Top() + Height;
|
||||
return Top() + Height;
|
||||
}
|
||||
void SetBottom(int absBottom) override
|
||||
{
|
||||
if (m_Parent) {
|
||||
Y = absBottom - Height - m_Parent->Top();
|
||||
} else {
|
||||
Y = absBottom - Height;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec2 Scale()
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
#ifndef GUI_GameFrame_h__
|
||||
#define GUI_GameFrame_h__
|
||||
|
||||
#include "GUI/Frame.h"
|
||||
#include "GUI/MainMenuFrame.h"
|
||||
#include "GUI/WorldFrame.h"
|
||||
#include "GUI/Viewport.h"
|
||||
#include "GUI/TextureFrame.h"
|
||||
#include "GUI/PlayerHUD.h"
|
||||
|
||||
#include "GameWorld.h"
|
||||
#include "Events/GameStart.h"
|
||||
#include "Events/GameOver.h"
|
||||
#include "Events/Dead.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class GameFrame : public Frame
|
||||
{
|
||||
public:
|
||||
GameFrame(Frame* parent, std::string name)
|
||||
: Frame(parent, name)
|
||||
, m_GameOver(false)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &GUI::GameFrame::OnGameStart);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::GameFrame::OnGameOver);
|
||||
|
||||
m_World = std::make_shared<GameWorld>(EventBroker, ResourceManager);
|
||||
m_WorldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
|
||||
{
|
||||
vp1 = new Viewport(m_WorldFrame, "Viewport1", m_World);
|
||||
vp1->X = 0;
|
||||
vp1->Width = this->Width / 2.f;
|
||||
new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
|
||||
|
||||
vp2 = new Viewport(m_WorldFrame, "Viewport2", m_World);
|
||||
vp2->X = vp1->Right();
|
||||
vp2->Width = this->Width / 2.f;
|
||||
new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
|
||||
|
||||
m_FreeCamViewport = new Viewport(m_WorldFrame, "ViewportFreeCam", m_World);
|
||||
m_FreeCamViewport->Hide();
|
||||
}
|
||||
m_WorldFrame->Hide();
|
||||
m_World->Initialize();
|
||||
|
||||
m_MainMenuFrame = new MainMenuFrame(this, "MainMenu");
|
||||
}
|
||||
|
||||
private:
|
||||
EventRelay <Frame, Events::GameStart> m_EGameStart;
|
||||
|
||||
bool OnGameStart(const Events::GameStart& event)
|
||||
{
|
||||
m_WorldFrame->Show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
EventRelay <Frame, Events::GameOver> m_EGameOver;
|
||||
|
||||
bool OnGameOver(const Events::GameOver& event)
|
||||
{
|
||||
m_GameOver = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<GameWorld> m_World;
|
||||
|
||||
MainMenuFrame* m_MainMenuFrame;
|
||||
WorldFrame* m_WorldFrame;
|
||||
Viewport* vp1;
|
||||
Viewport* vp2;
|
||||
Viewport* m_FreeCamViewport;
|
||||
|
||||
bool m_GameOver;
|
||||
|
||||
bool OnKeyUp(const Events::KeyUp& event) override
|
||||
{
|
||||
if (event.KeyCode == GLFW_KEY_1) {
|
||||
if (m_FreeCamViewport->Hidden())
|
||||
m_FreeCamViewport->Show();
|
||||
else
|
||||
m_FreeCamViewport->Hide();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // GUI_GameFrame_h__
|
||||
@@ -0,0 +1,120 @@
|
||||
#ifndef GUI_SLIDER_H__
|
||||
#define GUI_SLIDER_H__
|
||||
|
||||
#include "GUI/TextureFrame.h"
|
||||
#include "GUI/Button.h"
|
||||
#include "GUI/EButtonPress.h"
|
||||
#include "GUI/EButtonRelease.h"
|
||||
#include "GUI/ESliderUpdate.h"
|
||||
#include "Core/EMouseMove.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class Slider : public TextureFrame
|
||||
{
|
||||
public:
|
||||
Slider(Frame* parent, std::string name)
|
||||
: TextureFrame(parent, name)
|
||||
{
|
||||
m_SliderButton = new GUI::Button(this, "SliderButton");
|
||||
m_SliderButton->DisableScissor();
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EButtonPress, &Slider::OnButtonPress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EButtonRelease, &Slider::OnButtonRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &Slider::OnMouseMove);
|
||||
}
|
||||
|
||||
float Percentage() const { return m_Percentage; }
|
||||
void SetPercentage(const float percentage) { m_Percentage = percentage; }
|
||||
|
||||
void SetTextureHover(std::string resourceName)
|
||||
{
|
||||
m_SliderButton->SetTextureHover(resourceName);
|
||||
}
|
||||
void SetTextureReleased(std::string resourceName)
|
||||
{
|
||||
m_SliderButton->SetTextureReleased(resourceName);
|
||||
}
|
||||
void SetTexturePressed(std::string resourceName)
|
||||
{
|
||||
m_SliderButton->SetTexturePressed(resourceName);
|
||||
}
|
||||
|
||||
void CenterSlider()
|
||||
{
|
||||
m_SliderButton->Y = (Height / 2) - (m_SliderButton->Height / 2);
|
||||
}
|
||||
|
||||
~Slider()
|
||||
{
|
||||
if (m_SliderButton != nullptr) {
|
||||
delete m_SliderButton;
|
||||
m_SliderButton = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Update(double dt) override
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
Button* m_SliderButton = nullptr;
|
||||
bool m_IsGrabbed = false;
|
||||
float m_Percentage = 0.f;
|
||||
|
||||
EventRelay<Frame, Events::ButtonPress> m_EButtonPress;
|
||||
EventRelay<Frame, Events::ButtonRelease> m_EButtonRelease;
|
||||
EventRelay<Frame, Events::MouseMove> m_EMouseMove;
|
||||
|
||||
virtual bool OnButtonPress(const Events::ButtonPress& event)
|
||||
{
|
||||
if (event.Button == m_SliderButton) {
|
||||
m_IsGrabbed = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool OnButtonRelease(const Events::ButtonRelease& event)
|
||||
{
|
||||
if (event.Button == m_SliderButton) {
|
||||
m_IsGrabbed = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool OnMouseMove(const Events::MouseMove& event)
|
||||
{
|
||||
if (m_IsGrabbed) {
|
||||
// Set horizontal position
|
||||
m_SliderButton->X += event.DeltaX;
|
||||
if (m_SliderButton->Left() < Left()) {
|
||||
m_SliderButton->SetLeft(Left());
|
||||
} else if (m_SliderButton->Right() > Right()) {
|
||||
m_SliderButton->SetRight(Right());
|
||||
}
|
||||
|
||||
// Update percentage
|
||||
float newPercentage = m_SliderButton->X / (float)(Width - m_SliderButton->Width);
|
||||
Events::SliderUpdate e;
|
||||
e.FrameName = Name();
|
||||
e.Slider = this;
|
||||
e.Percentage = newPercentage;
|
||||
e.DeltaPercentage = newPercentage - m_Percentage;
|
||||
EventBroker->Publish(e);
|
||||
m_Percentage = newPercentage;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,9 @@ public:
|
||||
TextureFrame(Frame* parent, std::string name)
|
||||
: Frame(parent, name) { }
|
||||
|
||||
void EnableScissor() { m_ScissorEnabled = true; }
|
||||
void DisableScissor() { m_ScissorEnabled = false; }
|
||||
|
||||
void Draw(RenderQueueCollection& rq) override
|
||||
{
|
||||
if (m_Texture == nullptr)
|
||||
@@ -23,22 +26,24 @@ public:
|
||||
// Main texture
|
||||
{
|
||||
FrameJob job;
|
||||
job.Scissor = m_Parent->AbsoluteRectangle();
|
||||
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
|
||||
job.Viewport = Rectangle(Left(), Top(), Width, Height);
|
||||
job.TextureID = m_Texture->ResourceID;
|
||||
job.DiffuseTexture = *m_Texture;
|
||||
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
|
||||
job.Name = Name();
|
||||
rq.GUI.Add(job);
|
||||
}
|
||||
|
||||
// Texture while fading
|
||||
if (m_FadeTexture && m_CurrentFade < 1) {
|
||||
FrameJob job;
|
||||
job.Scissor = m_Parent->AbsoluteRectangle();
|
||||
job.Scissor = (m_ScissorEnabled) ? m_Parent->AbsoluteRectangle() : Rectangle();
|
||||
job.Viewport = Rectangle(Left(), Top(), Width, Height);
|
||||
job.TextureID = m_FadeTexture->ResourceID;
|
||||
job.DiffuseTexture = *m_FadeTexture;
|
||||
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
|
||||
job.Name = Name();
|
||||
rq.GUI.Add(job);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +56,15 @@ public:
|
||||
if (m_Texture == nullptr) {
|
||||
m_Texture = ResourceManager::Load<dd::Texture>("Textures/Core/ErrorTexture.png");
|
||||
}
|
||||
SizeToTexture();
|
||||
}
|
||||
|
||||
void SizeToTexture()
|
||||
{
|
||||
if (m_Texture != nullptr) {
|
||||
this->Width = m_Texture->Width;
|
||||
this->Height = m_Texture->Height;
|
||||
}
|
||||
}
|
||||
|
||||
void FadeToTexture(std::string resourceName, double duration)
|
||||
@@ -77,6 +91,7 @@ public:
|
||||
void SetColor(glm::vec4 val) { m_Color = val; }
|
||||
|
||||
protected:
|
||||
bool m_ScissorEnabled = true;
|
||||
dd::Texture* m_Texture = nullptr;
|
||||
dd::Texture* m_FadeTexture = nullptr;
|
||||
glm::vec4 m_Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#ifndef GUI_Viewport_h__
|
||||
#define GUI_Viewport_h__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "GUI/Frame.h"
|
||||
#include "World.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Camera.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "Camera.h"
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class Viewport : public Frame
|
||||
{
|
||||
public:
|
||||
Viewport(Frame* parent, std::string name, std::shared_ptr<World> world)
|
||||
: Frame(parent, name)
|
||||
, m_World(world)
|
||||
{ }
|
||||
|
||||
EntityID CameraEntity() const { return m_CameraEntity; }
|
||||
void SetCameraEntity(EntityID cameraEntity)
|
||||
{
|
||||
m_CameraEntity = cameraEntity;
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(cameraEntity);
|
||||
if (!transformComponent)
|
||||
return;
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(cameraEntity);
|
||||
if (!cameraComponent)
|
||||
return;
|
||||
|
||||
m_Camera = std::make_shared<Camera>(cameraComponent->FOV, cameraComponent->NearClip, cameraComponent->FarClip);
|
||||
}
|
||||
|
||||
|
||||
void Update(double dt) override
|
||||
{
|
||||
if (!m_TransformSystem)
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(m_CameraEntity);
|
||||
if (!transformComponent)
|
||||
return;
|
||||
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(m_CameraEntity);
|
||||
if (!cameraComponent)
|
||||
return;
|
||||
|
||||
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(m_CameraEntity);
|
||||
|
||||
m_Camera->SetFOV(cameraComponent->FOV);
|
||||
m_Camera->SetNearClip(cameraComponent->NearClip);
|
||||
m_Camera->SetFarClip(cameraComponent->FarClip);
|
||||
m_Camera->SetPosition(absoluteTransform.Position);
|
||||
m_Camera->SetOrientation(absoluteTransform.Orientation);
|
||||
}
|
||||
|
||||
void Draw(std::shared_ptr<Renderer> renderer) override
|
||||
{
|
||||
if (!m_Camera)
|
||||
return;
|
||||
|
||||
renderer->SetCamera(m_Camera);
|
||||
renderer->SetViewport(AbsoluteRectangle());
|
||||
renderer->DrawWorld(m_Parent->RenderQueue);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<World> m_World;
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
std::shared_ptr<Camera> m_Camera;
|
||||
EntityID m_CameraEntity;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GUI_Viewport_h__
|
||||
@@ -1,241 +0,0 @@
|
||||
#ifndef GUI_WorldFrame_h__
|
||||
#define GUI_WorldFrame_h__
|
||||
|
||||
#include "GUI/Frame.h"
|
||||
#include "GUI/Viewport.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "World.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "Events/SetViewportCamera.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Components/Sprite.h"
|
||||
#include "Components/PointLight.h"
|
||||
#include "Components/BlendMap.h"
|
||||
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class WorldFrame : public Frame
|
||||
{
|
||||
public:
|
||||
WorldFrame(Frame* parent, std::string name, std::shared_ptr<World> world)
|
||||
: Frame(parent, name)
|
||||
, m_World(world)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetViewportCamera, &WorldFrame::OnSetViewportCamera);
|
||||
}
|
||||
|
||||
void Update(double dt) override
|
||||
{
|
||||
if (!m_TransformSystem)
|
||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||
|
||||
m_World->Update(dt);
|
||||
}
|
||||
|
||||
void Draw(std::shared_ptr<Renderer> renderer) override
|
||||
{
|
||||
RenderQueue.Clear();
|
||||
renderer->ClearPointLights();
|
||||
|
||||
for (auto &pair : *m_World->GetEntities())
|
||||
{
|
||||
EntityID entity = pair.first;
|
||||
|
||||
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
|
||||
if (templateComponent)
|
||||
continue;
|
||||
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transform)
|
||||
continue;
|
||||
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
|
||||
if (modelComponent)
|
||||
{
|
||||
Model* modelAsset = nullptr;
|
||||
if (modelComponent->AverageNormals)
|
||||
{
|
||||
modelAsset = ResourceManager->Load<Model>("AveragedModel", modelComponent->ModelFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
|
||||
}
|
||||
|
||||
|
||||
if (modelAsset)
|
||||
{
|
||||
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
|
||||
* glm::toMat4(absoluteTransform.Orientation)
|
||||
* glm::scale(absoluteTransform.Scale);
|
||||
auto blendmapComponent = m_World->GetComponent<Components::BlendMap>(entity);
|
||||
if (blendmapComponent)
|
||||
{
|
||||
BlendMapTexture RedTexture;
|
||||
RedTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRed);
|
||||
RedTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRedNormal);
|
||||
RedTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRedSpecular);
|
||||
|
||||
BlendMapTexture GreenTexture;
|
||||
GreenTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreen);
|
||||
GreenTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreenNormal);
|
||||
GreenTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreenSpecular);
|
||||
|
||||
BlendMapTexture BlueTexture;
|
||||
BlueTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlue);
|
||||
BlueTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlueNormal);
|
||||
BlueTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlueSpecular);
|
||||
|
||||
float textureRepeat = blendmapComponent->TextureRepeats;
|
||||
|
||||
EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix, modelComponent->Color);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||
if (spriteComponent)
|
||||
{
|
||||
auto textureAsset = ResourceManager->Load<Texture>("Texture", spriteComponent->SpriteFile);
|
||||
if (textureAsset)
|
||||
{
|
||||
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1));
|
||||
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
|
||||
* glm::toMat4(orientation2D)
|
||||
* glm::scale(absoluteTransform.Scale);
|
||||
EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color);
|
||||
}
|
||||
}
|
||||
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
|
||||
if (pointLightComponent)
|
||||
{
|
||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
renderer->AddPointLightToDraw(
|
||||
position,
|
||||
pointLightComponent->Specular,
|
||||
pointLightComponent->Diffuse,
|
||||
pointLightComponent->specularExponent,
|
||||
pointLightComponent->ConstantAttenuation,
|
||||
pointLightComponent->LinearAttenuation,
|
||||
pointLightComponent->QuadraticAttenuation,
|
||||
pointLightComponent->Radius
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
RenderQueue.Sort();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<World> m_World;
|
||||
|
||||
private:
|
||||
struct BlendMapTexture
|
||||
{
|
||||
GLuint Diffuse;
|
||||
GLuint Normal;
|
||||
GLuint Specular;
|
||||
};
|
||||
|
||||
EventRelay<Frame, Events::SetViewportCamera> m_ESetViewportCamera;
|
||||
bool OnSetViewportCamera(const Events::SetViewportCamera &event)
|
||||
{
|
||||
// Search next layer for viewports and update cameras
|
||||
auto itpair = m_Children[m_Layer + 1].equal_range(event.ViewportFrame);
|
||||
for (auto it = itpair.first; it != itpair.second; ++it)
|
||||
{
|
||||
auto viewportFrame = dynamic_cast<GUI::Viewport*>(it->second);
|
||||
if (!viewportFrame)
|
||||
continue;
|
||||
|
||||
viewportFrame->SetCameraEntity(event.CameraEntity);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
|
||||
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color)
|
||||
{
|
||||
for (auto texGroup : model->TextureGroups)
|
||||
{
|
||||
ModelJob job;
|
||||
job.TextureID = texGroup.Texture->ResourceID;
|
||||
job.DiffuseTexture = *texGroup.Texture;
|
||||
job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0;
|
||||
job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0;
|
||||
job.VAO = model->VAO;
|
||||
job.StartIndex = texGroup.StartIndex;
|
||||
job.EndIndex = texGroup.EndIndex;
|
||||
job.ModelMatrix = modelMatrix;
|
||||
job.Transparent = transparent;
|
||||
job.Color = color;
|
||||
|
||||
if(job.Transparent)
|
||||
{
|
||||
RenderQueue.Forward.Add(job);
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderQueue.Deferred.Add(job);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix, glm::vec4 color)
|
||||
{
|
||||
for (auto texGroup : model->TextureGroups)
|
||||
{
|
||||
BlendMapModelJob job;
|
||||
job.TextureID = texGroup.Texture->ResourceID;
|
||||
job.DiffuseTexture = *texGroup.Texture;
|
||||
job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0;
|
||||
job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0;
|
||||
job.BlendMapTextureRed = textureRed.Diffuse;
|
||||
job.BlendMapTextureRedNormal = textureRed.Normal;
|
||||
job.BlendMapTextureRedSpecular = textureRed.Specular;
|
||||
job.BlendMapTextureGreen = textureGreen.Diffuse;
|
||||
job.BlendMapTextureGreenNormal = textureGreen.Normal;
|
||||
job.BlendMapTextureGreenSpecular = textureGreen.Specular;
|
||||
job.BlendMapTextureBlue = textureBlue.Diffuse;
|
||||
job.BlendMapTextureBlueNormal = textureBlue.Normal;
|
||||
job.BlendMapTextureBlueSpecular = textureBlue.Specular;
|
||||
job.TextureRepeat = textureRepeat;
|
||||
job.VAO = model->VAO;
|
||||
job.StartIndex = texGroup.StartIndex;
|
||||
job.EndIndex = texGroup.EndIndex;
|
||||
job.ModelMatrix = modelMatrix;
|
||||
job.Color = color;
|
||||
|
||||
RenderQueue.Deferred.Add(job);
|
||||
}
|
||||
}
|
||||
|
||||
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color)
|
||||
{
|
||||
SpriteJob job;
|
||||
job.TextureID = texture->ResourceID;
|
||||
job.Texture = *texture;
|
||||
job.ModelMatrix = modelMatrix;
|
||||
job.Color = color;
|
||||
|
||||
RenderQueue.Forward.Add(job);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GUI_WorldFrame_h__
|
||||
Reference in New Issue
Block a user