Moved menu code into GUI

Button events are now sent when you click.
This commit is contained in:
Tleety
2016-02-17 13:44:11 +01:00
parent 8f84a5ddd6
commit 657125b469
19 changed files with 273 additions and 655 deletions
-165
View File
@@ -1,165 +0,0 @@
#ifndef GUI_BUTTON_H__
#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"
namespace dd
{
namespace GUI
{
class Button : public TextureFrame
{
public:
Button(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &Button::OnMouseMove);
EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &Button::OnMousePress);
EVENT_SUBSCRIBE_MEMBER(m_EMouseRelease, &Button::OnMouseRelease);
}
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(RenderScene& rq) override
{
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;
virtual bool OnMouseMove(const Events::MouseMove& event)
{
if (Hidden()) {
return false;
}
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
if (isOver && !m_MouseIsOver) { // Enter
if (!m_IsDown) {
if (!m_TextureHover.empty()) {
SetTexture(m_TextureHover);
}
}
OnEnter();
Events::ButtonEnter e;
e.FrameName = m_Name;
EventBroker->Publish(e);
Events::PlaySound soundEvent;
soundEvent.FilePath = "Sounds/GUI/hover-n.wav";
EventBroker->Publish(soundEvent);
} else if (!isOver && m_MouseIsOver) { // Leave
if (!m_IsDown) {
if (!m_TextureReleased.empty()) {
SetTexture(m_TextureReleased);
}
}
OnLeave();
Events::ButtonLeave e;
e.FrameName = m_Name;
EventBroker->Publish(e);
}
m_MouseIsOver = isOver;
return true;
}
virtual bool OnMousePress(const Events::MousePress& event)
{
if (Hidden()) {
//LOG_DEBUG("Pressed hidden button");
return false;
}
if (!Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1))) {
return false;
}
if (!m_TexturePressed.empty()) {
SetTexture(m_TexturePressed);
}
m_IsDown = true;
OnPress();
Events::ButtonPress e;
e.FrameName = m_Name;
e.Button = this;
EventBroker->Publish(e);
return true;
}
virtual bool OnMouseRelease(const Events::MouseRelease& event)
{
if (Hidden()) {
//LOG_DEBUG("Released hidden button");
return false;
}
bool isOver = Rectangle::Intersects(AbsoluteRectangle(), Rectangle(event.X, event.Y, 1, 1));
if (!isOver && !m_IsDown) {
return false;
}
if (m_MouseIsOver) {
if (!m_TextureHover.empty()) {
SetTexture(m_TextureHover);
}
} else {
if (!m_TextureReleased.empty()) {
SetTexture(m_TextureReleased);
}
}
m_IsDown = false;
OnRelease();
Events::ButtonRelease e;
e.FrameName = m_Name;
e.Button = this;
EventBroker->Publish(e);
return true;
}
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;
};
}
}
#endif
+44
View File
@@ -0,0 +1,44 @@
#ifndef ButtonSystem_h__
#define ButtonSystem_h__
#include "../Rendering/IRenderer.h"
#include "../Core/ConfigFile.h"
#include "../Rendering/PickingPass.h"
#include "../Core/ResourceManager.h"
#include "../Core/System.h"
#include "../Core/Event.h"
#include "../Core/EMousePress.h"
#include "../Core/EMouseRelease.h"
#include "../Core/ELockMouse.h"
#include "EButtonPressed.h"
#include "EButtonReleased.h"
#include "EButtonClicked.h"
class ButtonSystem : public PureSystem
{
public:
ButtonSystem(SystemParams params, IRenderer* renderer);
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override;
private:
IRenderer* m_Renderer;
bool m_MouseIsLocked = false;
EntityWrapper m_PickEntity = EntityWrapper::Invalid;
PickData m_PickData;
EventRelay<ButtonSystem, Events::LockMouse> m_EMouseLock;
bool OnMouseLock(const Events::LockMouse& e);
EventRelay<ButtonSystem, Events::UnlockMouse> m_EMouseUnlock;
bool OnMouseUnlock(const Events::UnlockMouse& e);
EventRelay<ButtonSystem, Events::MousePress> m_EMousePress;
bool OnMousePress(const Events::MousePress& e);
EventRelay<ButtonSystem, Events::MouseRelease> m_EMouseRelease;
bool OnMouseRelease(const Events::MouseRelease& e);
};
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_ButtonClicked_h__
#define Events_ButtonClicked_h__
#include "Core/Event.h"
namespace Events
{
struct ButtonClicked : public Event {
std::string EntityName = "DEFAULT STRING USED";
};
}
#endif
-17
View File
@@ -1,17 +0,0 @@
#ifndef Events_ButtonEnter_h__
#define Events_ButtonEnter_h__
#include "../Core/EventBroker.h"
namespace Events
{
/** Thrown on GUI button hover. */
struct ButtonEnter : Event
{
std::string FrameName;
};
}
#endif
-17
View File
@@ -1,17 +0,0 @@
#ifndef Events_ButtonLeave_h__
#define Events_ButtonLeave_h__
#include "../Core/EventBroker.h"
namespace Events
{
/** Thrown on GUI button hover. */
struct ButtonLeave : Event
{
std::string FrameName;
};
}
#endif
-20
View File
@@ -1,20 +0,0 @@
#ifndef Events_ButtonPress_h__
#define Events_ButtonPress_h__
#include "../Core/EventBroker.h"
namespace GUI { class Button; }
namespace Events
{
/** Thrown on GUI button press. */
struct ButtonPress : Event
{
std::string FrameName;
GUI::Button* Button;
};
}
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_ButtonPressed_h__
#define Events_ButtonPressed_h__
#include "Core/Event.h"
namespace Events
{
struct ButtonPressed : public Event {
std::string EntityName = "DEFAULT STRING USED";
};
}
#endif
-20
View File
@@ -1,20 +0,0 @@
#ifndef Events_ButtonRelease_h__
#define Events_ButtonRelease_h__
#include "../Core/EventBroker.h"
namespace GUI { class Button; }
namespace Events
{
/** Thrown on GUI button release. */
struct ButtonRelease : Event
{
std::string FrameName;
GUI::Button* Button;
};
}
#endif
+13
View File
@@ -0,0 +1,13 @@
#ifndef Events_ButtonReleased_h__
#define Events_ButtonReleased_h__
#include "Core/Event.h"
namespace Events
{
struct ButtonReleased : public Event { };
}
#endif
-261
View File
@@ -1,261 +0,0 @@
#ifndef GUI_Frame_h__
#define GUI_Frame_h__
#include "../Common.h"
#include "../Core/Util/Rectangle.h"
#include "../Core/EventBroker.h"
#include "../Core/EKeyDown.h"
#include "../Core/EKeyUp.h"
#include "../Core/ResourceManager.h"
#include "../Rendering/RenderQueue.h"
#include "../Rendering/Texture.h"
#include "../Input/EInputCommand.h"
namespace GUI
{
class Frame : public Rectangle
{
public:
enum class Anchor
{
Left,
Right,
Top,
Bottom
};
static const int BaseWidth = 1280;
static const int BaseHeight = 720;
// Set up a base frame with an event broker
Frame(EventBroker* eventBroker)
: m_EventBroker(eventBroker)
, BaseFrame(this)
, m_Name("UIParent")
, Rectangle() { }
// Create a frame as a child
Frame(Frame* parent, std::string name)
: m_Name(name)
{
SetParent(parent);
Width = parent->Width;
Height = parent->Height;
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
}
~Frame()
{
/*for (auto layer : m_Children)
{
for (auto child : layer.second)
{
delete child.second;
}
}
if (m_Parent)
{
m_Parent->RemoveChild(this);
}*/
}
Frame* Parent() const { return m_Parent; }
void SetParent(Frame* parent)
{
if (parent == nullptr) {
LOG_ERROR("Failed to parent frame \"%s\": Invalid parent", m_Name.c_str());
return;
}
m_Layer = parent->Layer() + 1;
parent->AddChild(this);
m_Parent = parent;
m_EventBroker = parent->m_EventBroker;
BaseFrame = parent->BaseFrame;
}
void AddChild(Frame* child)
{
m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child));
if (m_Parent) {
m_Parent->AddChild(child);
}
}
void RemoveChild(Frame* child)
{
auto it = m_Children.find(child->m_Layer);
if (it != m_Children.end()) {
m_Children.erase(it);
}
if (m_Parent) {
m_Parent->RemoveChild(child);
}
}
std::string Name() const { return m_Name; }
void SetName(std::string val) { m_Name = val; }
int Layer() const { return m_Layer; }
bool Hidden() const
{
if (m_Parent)
return m_Parent->Hidden() || m_Hidden;
else
return m_Hidden;
}
bool Visible() const
{
return !Hidden();
}
virtual void Hide() { m_Hidden = true; }
virtual void Show() { m_Hidden = false; }
int Left() const override
{
if (m_Parent)
return m_Parent->Left() + X;
else
return X;
}
void SetLeft(int absLeft) override
{
if (m_Parent) {
X = absLeft - m_Parent->Left();
} else {
X = absLeft;
}
}
int Right() const override
{
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
{
if (m_Parent)
return m_Parent->Top() + Y;
else
return Y;
}
void SetTop(int absTop) override
{
if (m_Parent) {
Y = absTop - m_Parent->Top();
} else {
Y = absTop;
}
}
int Bottom() const override
{
return Top() + Height;
}
void SetBottom(int absBottom) override
{
if (m_Parent) {
Y = absBottom - Height - m_Parent->Top();
} else {
Y = absBottom - Height;
}
}
glm::vec2 Scale()
{
if (m_Parent)
return m_Parent->Scale();
else
return glm::vec2(Width, Height) / glm::vec2(BaseWidth, BaseHeight);
}
Rectangle AbsoluteRectangle()
{
int left = Left();
if (m_Parent)
left = std::max(left, m_Parent->Left());
int top = Top();
if (m_Parent)
top = std::max(top, m_Parent->Top());
int width = Right() - left;
int height = Bottom() - top;
return Rectangle(left, top, width, height);
}
void UpdateLayered(double dt)
{
// Update ourselves
this->Update(dt);
// Update children
for (auto& pairLayer : m_Children) {
auto children = pairLayer.second;
for (auto& pairChild : children) {
auto child = pairChild.second;
child->Update(dt);
}
}
}
virtual void Update(double dt) { }
void DrawLayered(RenderScene& rq)
{
if (this->Hidden())
return;
// Draw ourselves
this->Draw(rq);
// Draw children
for (auto& pairLayer : m_Children) {
auto children = pairLayer.second;
for (auto& pairChild : children) {
auto child = pairChild.second;
if (child->Hidden())
continue;
child->Draw(rq);
}
}
}
virtual void Draw(RenderScene& rq) { }
protected:
::EventBroker* m_EventBroker;
Frame* BaseFrame = nullptr;
std::string m_Name = "Unnamed";
int m_Layer = 0;
bool m_Hidden = false;
Frame* m_Parent = nullptr;
typedef std::multimap<std::string, Frame*> Children_t; // name -> frame
std::map<int, Children_t> m_Children; // layer -> Children_t
virtual bool OnKeyDown(const Events::KeyDown& event) { return false; }
virtual bool OnKeyUp(const Events::KeyUp& event) { return false; }
virtual bool OnCommand(const Events::InputCommand& event) { return false; }
private:
EventRelay<Frame, Events::KeyDown> m_EKeyDown;
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
EventRelay<Frame, Events::InputCommand> m_EInputCommand;
};
}
#endif
+32
View File
@@ -0,0 +1,32 @@
#ifndef MainMenuSystem_h__
#define MainMenuSystem_h__
#include "../Core/System.h"
#include "../Rendering/IRenderer.h"
#include "../Core/ResourceManager.h"
#include "../Core/Event.h"
#include "EButtonClicked.h"
#include "EButtonPressed.h"
#include "EButtonReleased.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);
};
#endif
-112
View File
@@ -1,112 +0,0 @@
#ifndef GUI_TextureFrame_h__
#define GUI_TextureFrame_h__
#include "Frame.h"
#include "../Rendering/Texture.h"
#include "../Rendering/Util/CommonFunctions.h"
namespace GUI
{
class TextureFrame : public Frame
{
public:
TextureFrame(Frame* parent, std::string name)
: Frame(parent, name) { }
void EnableScissor() { m_ScissorEnabled = true; }
void DisableScissor() { m_ScissorEnabled = false; }
void Draw(RenderScene& rq) override
{
if (m_Texture == nullptr)
return;
// Texture while fading
if (m_FadeTexture && m_CurrentFade < 1) {
FrameJob job;
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);
}
// Main texture
{
FrameJob job;
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);
}
}
std::string Texture() const { return m_TextureName; }
void SetTexture(std::string resourceName)
{
if (resourceName.empty()) {
m_Texture = nullptr;
return;
}
m_Texture = CommonFunctions::LoadTexture(resourceName, false);
m_TextureName = resourceName;
if (m_Texture == nullptr) {
m_Texture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false);
}
SizeToTexture();
}
void SizeToTexture()
{
if (m_Texture != nullptr) {
this->Width = m_Texture->Width;
this->Height = m_Texture->Height;
}
}
void FadeToTexture(std::string resourceName, double duration)
{
m_FadeTexture = m_Texture;
SetTexture(resourceName);
m_FadeDuration = duration;
m_CurrentFade = 0.f;
}
void Update(double dt) override
{
if (m_CurrentFade < 1) {
m_CurrentFade += dt / m_FadeDuration;
if (m_CurrentFade > 1) {
m_FadeTexture = nullptr;
m_CurrentFade = 1;
m_FadeDuration = 0;
}
}
}
glm::vec4 Color() const { return m_Color; }
void SetColor(glm::vec4 val) { m_Color = val; }
protected:
bool m_ScissorEnabled = true;
Texture* m_Texture = nullptr;
std::string m_TextureName;
Texture* m_FadeTexture = nullptr;
glm::vec4 m_Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
float m_FadeDuration = 0.f;
float m_CurrentFade = 1.f;
};
}
#endif
-2
View File
@@ -8,7 +8,6 @@
#include "Core/EventBroker.h" #include "Core/EventBroker.h"
#include "Rendering/Renderer.h" #include "Rendering/Renderer.h"
#include "Core/InputManager.h" #include "Core/InputManager.h"
#include "GUI/Frame.h"
#include "Core/World.h" #include "Core/World.h"
#include "Input/InputProxy.h" #include "Input/InputProxy.h"
#include "Input/KeyboardInputHandler.h" #include "Input/KeyboardInputHandler.h"
@@ -53,7 +52,6 @@ private:
IRenderer* m_Renderer; IRenderer* m_Renderer;
InputManager* m_InputManager; InputManager* m_InputManager;
InputProxy* m_InputProxy; InputProxy* m_InputProxy;
GUI::Frame* m_FrameStack;
World* m_World; World* m_World;
Octree<EntityAABB>* m_OctreeCollision; Octree<EntityAABB>* m_OctreeCollision;
Octree<EntityAABB>* m_OctreeTrigger; Octree<EntityAABB>* m_OctreeTrigger;
+2 -3
View File
@@ -27,17 +27,16 @@ public:
private: private:
bool m_NetworkEnabled; bool m_NetworkEnabled;
//methods which will take care of specific events // methods which will take care of specific events
EventRelay<HealthSystem, Events::PlayerDamage> m_EPlayerDamage; EventRelay<HealthSystem, Events::PlayerDamage> m_EPlayerDamage;
bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e); bool HealthSystem::OnPlayerDamaged(Events::PlayerDamage& e);
EventRelay<HealthSystem, Events::PlayerHealthPickup> m_EPlayerHealthPickup; EventRelay<HealthSystem, Events::PlayerHealthPickup> m_EPlayerHealthPickup;
bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e); bool HealthSystem::OnPlayerHealthPickup(Events::PlayerHealthPickup& e);
EventRelay<HealthSystem, Events::InputCommand> m_InputCommand; EventRelay<HealthSystem, Events::InputCommand> m_InputCommand;
bool HealthSystem::OnInputCommand(Events::InputCommand& e); bool HealthSystem::OnInputCommand(Events::InputCommand& e);
//vector which will keep track of health changes //vector which will keep track of health changes
std::vector<std::tuple<EntityID, double>> m_DeltaHealthVector; std::vector<std::tuple<EntityID, double>> m_DeltaHealthVector;
}; };
#endif #endif
+1
View File
@@ -1,6 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types"> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/> <xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Button"> <xs:element name="Button">
<xs:annotation> <xs:annotation>
<xs:documentation>Makes sprites klickable.</xs:documentation> <xs:documentation>Makes sprites klickable.</xs:documentation>
+32 -32
View File
@@ -40,7 +40,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="7877.16357" Z="0"/> <Orientation X="0" Y="8047.93604" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -105,7 +105,7 @@
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Position X="2.1529963" Y="6.59221172" Z="0.169116676"/> <Position X="2.1529963" Y="6.59221172" Z="0.169116676"/>
<Orientation X="4.16300011" Y="17713.8125" Z="0"/> <Orientation X="4.16300011" Y="17884.6152" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
@@ -180,7 +180,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="2275.49121" Z="0"/> <Orientation X="0" Y="2360.87744" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -225,7 +225,7 @@
<Axis X="1" Y="1" Z="1"/> <Axis X="1" Y="1" Z="1"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="16304.2705" Y="16304.2705" Z="16304.2705"/> <Orientation X="16475.0957" Y="16475.0957" Z="16475.0957"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -289,7 +289,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="16101.3037" Z="0"/> <Orientation X="0" Y="16272.0654" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -321,7 +321,7 @@
<Axis X="0.699999988" Y="1" Z="0.300000012"/> <Axis X="0.699999988" Y="1" Z="0.300000012"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="11816.6787" Y="16827.6992" Z="5034.95752"/> <Orientation X="11936.1904" Y="16998.502" Z="5086.18848"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -671,7 +671,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="573.163879" Z="0"/> <Orientation X="0" Y="658.550842" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -718,7 +718,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="573.163879" Z="0"/> <Orientation X="0" Y="658.550842" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -778,7 +778,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="573.163879" Z="0"/> <Orientation X="0" Y="658.550842" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -825,7 +825,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="573.163879" Z="0"/> <Orientation X="0" Y="658.550842" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -871,7 +871,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="573.163879" Z="0"/> <Orientation X="0" Y="658.550842" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -918,7 +918,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="573.163879" Z="0"/> <Orientation X="0" Y="658.550842" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -965,7 +965,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="573.163879" Z="0"/> <Orientation X="0" Y="658.550842" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -1379,7 +1379,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="1106.86328" Z="0"/> <Orientation X="0" Y="1192.24976" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -1388,7 +1388,7 @@
<c:ExplosionEffect> <c:ExplosionEffect>
<ColorByDistance>true</ColorByDistance> <ColorByDistance>true</ColorByDistance>
<Velocity X="0.800000012" Y="0.0379999988" Z="0"/> <Velocity X="0.800000012" Y="0.0379999988" Z="0"/>
<TimeSinceDeath>2.5166344949826396</TimeSinceDeath> <TimeSinceDeath>2.5333333077342104</TimeSinceDeath>
<ExplosionDuration>3.7999999523162842</ExplosionDuration> <ExplosionDuration>3.7999999523162842</ExplosionDuration>
<EndColor A="0" B="23.5294113" G="11.7647057" R="0"/> <EndColor A="0" B="23.5294113" G="11.7647057" R="0"/>
<Randomness>true</Randomness> <Randomness>true</Randomness>
@@ -1435,7 +1435,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="1106.86328" Z="0"/> <Orientation X="0" Y="1192.24976" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -1444,7 +1444,7 @@
<c:ExplosionEffect> <c:ExplosionEffect>
<Velocity X="0.5" Y="1" Z="0"/> <Velocity X="0.5" Y="1" Z="0"/>
<ExplosionOrigin X="0" Y="0.900000036" Z="0"/> <ExplosionOrigin X="0" Y="0.900000036" Z="0"/>
<TimeSinceDeath>0.35000808291962926</TimeSinceDeath> <TimeSinceDeath>0.70455028055985736</TimeSinceDeath>
</c:ExplosionEffect> </c:ExplosionEffect>
<c:Model> <c:Model>
<Resource>Models/Characters/Assault/AssaultTPose.mesh</Resource> <Resource>Models/Characters/Assault/AssaultTPose.mesh</Resource>
@@ -1487,7 +1487,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="1106.86328" Z="0"/> <Orientation X="0" Y="1192.24976" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -1498,7 +1498,7 @@
<ColorByDistance>true</ColorByDistance> <ColorByDistance>true</ColorByDistance>
<Velocity X="0.300000012" Y="2" Z="0"/> <Velocity X="0.300000012" Y="2" Z="0"/>
<ExplosionOrigin X="0" Y="1.30000007" Z="-0.200000003"/> <ExplosionOrigin X="0" Y="1.30000007" Z="-0.200000003"/>
<TimeSinceDeath>0.35000808291962926</TimeSinceDeath> <TimeSinceDeath>0.70455028055985736</TimeSinceDeath>
<EndColor A="0" B="0.333333343" G="0.933333337" R="3.92156863"/> <EndColor A="0" B="0.333333343" G="0.933333337" R="3.92156863"/>
<Randomness>true</Randomness> <Randomness>true</Randomness>
</c:ExplosionEffect> </c:ExplosionEffect>
@@ -1543,7 +1543,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="1114.64343" Z="0"/> <Orientation X="0" Y="1200.02991" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -1553,7 +1553,7 @@
<ColorByDistance>true</ColorByDistance> <ColorByDistance>true</ColorByDistance>
<Velocity X="0" Y="0.699999988" Z="0"/> <Velocity X="0" Y="0.699999988" Z="0"/>
<ExplosionOrigin X="0" Y="-1.10000002" Z="0"/> <ExplosionOrigin X="0" Y="-1.10000002" Z="0"/>
<TimeSinceDeath>9.4833086749886775</TimeSinceDeath> <TimeSinceDeath>9.1832418997049956</TimeSinceDeath>
<ExplosionDuration>10</ExplosionDuration> <ExplosionDuration>10</ExplosionDuration>
<EndColor A="1" B="0" G="0" R="1"/> <EndColor A="1" B="0" G="0" R="1"/>
<RandomnessScalar>3</RandomnessScalar> <RandomnessScalar>3</RandomnessScalar>
@@ -1601,7 +1601,7 @@
<Axis X="0" Y="1" Z="0"/> <Axis X="0" Y="1" Z="0"/>
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Orientation X="0" Y="712.784302" Z="0"/> <Orientation X="0" Y="798.171265" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -1611,7 +1611,7 @@
<ColorByDistance>true</ColorByDistance> <ColorByDistance>true</ColorByDistance>
<Velocity X="6" Y="0.100000001" Z="0"/> <Velocity X="6" Y="0.100000001" Z="0"/>
<ExplosionOrigin X="0" Y="-10" Z="0"/> <ExplosionOrigin X="0" Y="-10" Z="0"/>
<TimeSinceDeath>4.0667207575903603</TimeSinceDeath> <TimeSinceDeath>1.007708532606415</TimeSinceDeath>
<ExponentialAccelaration>true</ExponentialAccelaration> <ExponentialAccelaration>true</ExponentialAccelaration>
<ExplosionDuration>5</ExplosionDuration> <ExplosionDuration>5</ExplosionDuration>
<Randomness>true</Randomness> <Randomness>true</Randomness>
@@ -1792,7 +1792,7 @@
<c:ExplosionEffect> <c:ExplosionEffect>
<ColorByDistance>true</ColorByDistance> <ColorByDistance>true</ColorByDistance>
<Velocity X="0.800000012" Y="0.0379999988" Z="0"/> <Velocity X="0.800000012" Y="0.0379999988" Z="0"/>
<TimeSinceDeath>2.5166344949826396</TimeSinceDeath> <TimeSinceDeath>2.5333333077342104</TimeSinceDeath>
<ExplosionDuration>3.7999999523162842</ExplosionDuration> <ExplosionDuration>3.7999999523162842</ExplosionDuration>
<EndColor A="0" B="23.5294113" G="11.7647057" R="0"/> <EndColor A="0" B="23.5294113" G="11.7647057" R="0"/>
<Randomness>true</Randomness> <Randomness>true</Randomness>
@@ -2185,7 +2185,7 @@
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
<Entity name="Button"> <Entity name="Play">
<Components> <Components>
<c:Button/> <c:Button/>
<c:Sprite> <c:Sprite>
@@ -2213,7 +2213,7 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Button"> <Entity name="Host">
<Components> <Components>
<c:Button/> <c:Button/>
<c:Sprite> <c:Sprite>
@@ -2241,7 +2241,7 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Button"> <Entity name="Connecting">
<Components> <Components>
<c:Button/> <c:Button/>
<c:Sprite> <c:Sprite>
@@ -2269,7 +2269,7 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Button"> <Entity name="Settings">
<Components> <Components>
<c:Button/> <c:Button/>
<c:Sprite> <c:Sprite>
@@ -2297,7 +2297,7 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Button"> <Entity name="Quit">
<Components> <Components>
<c:Button/> <c:Button/>
<c:Sprite> <c:Sprite>
@@ -2349,7 +2349,7 @@
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
<Entity name="Button"> <Entity name="1">
<Components> <Components>
<c:Button/> <c:Button/>
<c:Sprite> <c:Sprite>
@@ -2377,7 +2377,7 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Button"> <Entity name="2">
<Components> <Components>
<c:Button/> <c:Button/>
<c:Sprite> <c:Sprite>
@@ -2405,7 +2405,7 @@
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Button"> <Entity name="3">
<Components> <Components>
<c:Button/> <c:Button/>
<c:Sprite> <c:Sprite>
+78
View File
@@ -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)
{
}
+37
View File
@@ -0,0 +1,37 @@
#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)
{
printf("\nClicked: %s", e.EntityName);
return true;
}
bool MainMenuSystem::OnButtonRelease(const Events::ButtonReleased& e)
{
printf("\nReleased");
return true;
}
bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
{
printf("\nPressed: %s", e.EntityName);
return true;
}
+4 -6
View File
@@ -26,6 +26,8 @@
#include "Network/MultiplayerSnapshotFilter.h" #include "Network/MultiplayerSnapshotFilter.h"
#include "Game/Systems/AmmunitionHUDSystem.h" #include "Game/Systems/AmmunitionHUDSystem.h"
#include "Game/Systems/KillFeedSystem.h" #include "Game/Systems/KillFeedSystem.h"
#include "GUI/ButtonSystem.h"
#include "GUI/MainMenuSystem.h"
Game::Game(int argc, char* argv[]) Game::Game(int argc, char* argv[])
@@ -72,11 +74,6 @@ Game::Game(int argc, char* argv[])
m_InputProxy->AddHandler<MouseInputHandler>(); m_InputProxy->AddHandler<MouseInputHandler>();
m_InputProxy->LoadBindings("Input.ini"); 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 // Create a world
m_World = new World(m_EventBroker); m_World = new World(m_EventBroker);
std::string mapToLoad = m_Config->Get<std::string>("Debug.LoadMap", ""); 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<DamageIndicatorSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmunitionHUDSystem>(updateOrderLevel); m_SystemPipeline->AddSystem<AmmunitionHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel); m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
// Populate Octree with collidables // Populate Octree with collidables
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable"); m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
@@ -168,7 +167,6 @@ Game::~Game()
delete m_NetworkServer; delete m_NetworkServer;
} }
delete m_World; delete m_World;
delete m_FrameStack;
delete m_InputProxy; delete m_InputProxy;
delete m_InputManager; delete m_InputManager;
delete m_RenderFrame; delete m_RenderFrame;