Compare commits
7 Commits
bugfix
...
FrameAttempt
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f83ef7e89 | |||
| 66abc11735 | |||
| f6721986c7 | |||
| 53a9cbd4d8 | |||
| b3335cff05 | |||
| dcb23bd199 | |||
| 47ad5e31ea |
+10
-6
@@ -156,14 +156,15 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Top Wall
|
||||||
{
|
{
|
||||||
auto topWall = m_World->CreateEntity();
|
auto topWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
|
||||||
transform->Position = glm::vec3(0.f, 6.f, -10.f);
|
transform->Position = glm::vec3(0.f, 6.f, -10.f);
|
||||||
transform->Scale = glm::vec3(18.f, 0.5f, 1.f);
|
transform->Scale = glm::vec3(18.f, 0.5f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
|
|
||||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(topWall);
|
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(topWall);
|
||||||
|
|
||||||
@@ -172,14 +173,15 @@ public:
|
|||||||
|
|
||||||
m_World->CommitEntity(topWall);
|
m_World->CommitEntity(topWall);
|
||||||
}
|
}
|
||||||
|
// Left Wall
|
||||||
{
|
{
|
||||||
auto leftWall = m_World->CreateEntity();
|
auto leftWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
|
||||||
transform->Position = glm::vec3(-9.f, 1.f, -10.f);
|
transform->Position = glm::vec3(-9.f, 1.f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
|
|
||||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(leftWall);
|
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(leftWall);
|
||||||
|
|
||||||
@@ -188,14 +190,15 @@ public:
|
|||||||
|
|
||||||
m_World->CommitEntity(leftWall);
|
m_World->CommitEntity(leftWall);
|
||||||
}
|
}
|
||||||
|
// Right Wall.
|
||||||
{
|
{
|
||||||
auto rightWall = m_World->CreateEntity();
|
auto rightWall = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
|
||||||
transform->Position = glm::vec3(9.f, 1.f, -10.f);
|
transform->Position = glm::vec3(9.f, 1.f, -10.f);
|
||||||
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
|
|
||||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(rightWall);
|
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(rightWall);
|
||||||
|
|
||||||
@@ -408,6 +411,7 @@ private:
|
|||||||
std::shared_ptr<InputManager> m_InputManager;
|
std::shared_ptr<InputManager> m_InputManager;
|
||||||
std::shared_ptr<World> m_World;
|
std::shared_ptr<World> m_World;
|
||||||
|
|
||||||
|
|
||||||
double m_LastTime;
|
double m_LastTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,23 @@ struct RenderQueueCollection
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RenderQueuePair
|
||||||
|
|
||||||
|
{
|
||||||
|
RenderQueue Deferred;
|
||||||
|
RenderQueue Forward;
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
Deferred.Clear();
|
||||||
|
Forward.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sort() {
|
||||||
|
Deferred.Sort();
|
||||||
|
Forward.Sort();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // RenderQueue_h__
|
#endif // RenderQueue_h__
|
||||||
@@ -39,8 +39,8 @@ public:
|
|||||||
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
||||||
bool VSYNC() const { return m_VSYNC; }
|
bool VSYNC() const { return m_VSYNC; }
|
||||||
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
||||||
//void SetViewport(const Rectangle& viewport) { m_Viewport = viewport; }
|
void SetViewport(const Rectangle& viewport) { m_Viewport = viewport; }
|
||||||
//void SetScissor(const Rectangle& scissor) { m_Scissor = scissor; }
|
void SetScissor(const Rectangle& scissor) { m_Scissor = scissor; }
|
||||||
const dd::Camera* Camera() const { return m_Camera; }
|
const dd::Camera* Camera() const { return m_Camera; }
|
||||||
void SetCamera(const dd::Camera* camera)
|
void SetCamera(const dd::Camera* camera)
|
||||||
{
|
{
|
||||||
@@ -53,14 +53,16 @@ public:
|
|||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Draw(RenderQueueCollection& rq);
|
void Draw(RenderQueueCollection& rq);
|
||||||
|
void DrawFrame(RenderQueuePair& rq);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Rectangle m_Resolution = Rectangle(1280, 720);
|
Rectangle m_Resolution = Rectangle(1280, 720);
|
||||||
bool m_Fullscreen = false;
|
bool m_Fullscreen = false;
|
||||||
bool m_VSYNC = false;
|
bool m_VSYNC = false;
|
||||||
//Rectangle m_Viewport;
|
Rectangle m_Viewport;
|
||||||
//Rectangle m_Scissor;
|
Rectangle m_Scissor;
|
||||||
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
|
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
|
||||||
|
|
||||||
const dd::Camera* m_Camera = nullptr;
|
const dd::Camera* m_Camera = nullptr;
|
||||||
|
|
||||||
int m_GLVersion[2];
|
int m_GLVersion[2];
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ public:
|
|||||||
@tparam T Resource type.
|
@tparam T Resource type.
|
||||||
@param resourceName Fully qualified name of the resource to fetch.
|
@param resourceName Fully qualified name of the resource to fetch.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static T* Fetch(std::string resourceName);
|
static T* Fetch(std::string resourceName);
|
||||||
|
|
||||||
@@ -142,6 +143,7 @@ private:
|
|||||||
// Internal: Create a resource and cache it
|
// Internal: Create a resource and cache it
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static T* CreateResource(std::string resourceName, Resource* parent);
|
static T* CreateResource(std::string resourceName, Resource* parent);
|
||||||
|
Resource* CreateResource(std::string resourceType, std::string resourceName);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
@@ -0,0 +1,258 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_FRAME_H
|
||||||
|
#define DAYDREAM_FRAME_H
|
||||||
|
|
||||||
|
#include "Core/Util/Rectangle.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/EKeyDown.h"
|
||||||
|
#include "Core/EKeyUp.h"
|
||||||
|
#include "Core/ResourceManager.h"
|
||||||
|
#include "Core/Renderer.h"
|
||||||
|
#include "Core/RenderQueue.h"
|
||||||
|
#include "Core/Texture.h"
|
||||||
|
#include "Input/EInputCommand.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
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(std::shared_ptr<dd::EventBroker> eventBroker, std::shared_ptr<dd::ResourceManager> resourceManager)
|
||||||
|
: EventBroker(eventBroker)
|
||||||
|
, ResourceManager(resourceManager)
|
||||||
|
, Rectangle()
|
||||||
|
, m_Parent(nullptr)
|
||||||
|
, m_Name("UIParent")
|
||||||
|
, m_Layer(0)
|
||||||
|
, m_Hidden(false)
|
||||||
|
{ Initialize(); }
|
||||||
|
|
||||||
|
// Create a frame as a child
|
||||||
|
Frame(Frame* parent, std::string name)
|
||||||
|
: m_Name(name)
|
||||||
|
, m_Layer(0)
|
||||||
|
, m_Hidden(false)
|
||||||
|
{ SetParent(parent); Initialize(); }
|
||||||
|
|
||||||
|
~Frame()
|
||||||
|
{
|
||||||
|
/*for (auto layer : m_Children)
|
||||||
|
{
|
||||||
|
for (auto child : layer.second)
|
||||||
|
{
|
||||||
|
delete child.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_Parent)
|
||||||
|
{
|
||||||
|
m_Parent->RemoveChild(this);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
dd::RenderQueuePair RenderQueue;
|
||||||
|
|
||||||
|
Frame* Parent() const { return m_Parent; }
|
||||||
|
void SetParent(Frame* parent)
|
||||||
|
{
|
||||||
|
if (parent == nullptr)
|
||||||
|
{
|
||||||
|
LOG_ERROR("Failed to create frame \"%s\": Invalid parent", m_Name.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Width = parent->Width;
|
||||||
|
Height = parent->Height;
|
||||||
|
m_Layer = parent->Layer() + 1;
|
||||||
|
parent->AddChild(this);
|
||||||
|
m_Parent = parent;
|
||||||
|
EventBroker = parent->EventBroker;
|
||||||
|
ResourceManager = parent->ResourceManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
int Right() const override
|
||||||
|
{
|
||||||
|
if (m_Parent)
|
||||||
|
return std::min(m_Parent->Right(), Left() + Width);
|
||||||
|
else
|
||||||
|
return Left() + Width;
|
||||||
|
}
|
||||||
|
int Top() const override
|
||||||
|
{
|
||||||
|
if (m_Parent)
|
||||||
|
return m_Parent->Top() + Y;
|
||||||
|
else
|
||||||
|
return Y;
|
||||||
|
}
|
||||||
|
int Bottom() const override
|
||||||
|
{
|
||||||
|
if (m_Parent)
|
||||||
|
return std::min(m_Parent->Bottom(), Top() + Height);
|
||||||
|
else
|
||||||
|
return Top() + 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(std::shared_ptr<Renderer> renderer)
|
||||||
|
{
|
||||||
|
if (this->Hidden())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Draw ourselves
|
||||||
|
renderer->SetScissor(AbsoluteRectangle());
|
||||||
|
this->Draw(renderer);
|
||||||
|
|
||||||
|
// Draw children
|
||||||
|
for (auto &pairLayer : m_Children)
|
||||||
|
{
|
||||||
|
auto children = pairLayer.second;
|
||||||
|
for (auto &pairChild : children)
|
||||||
|
{
|
||||||
|
auto child = pairChild.second;
|
||||||
|
if (child->Hidden())
|
||||||
|
continue;
|
||||||
|
Rectangle rect = child->AbsoluteRectangle();
|
||||||
|
renderer->SetScissor(rect);
|
||||||
|
child->Draw(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Draw(std::shared_ptr<Renderer> renderer) { }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<dd::EventBroker> EventBroker;
|
||||||
|
std::shared_ptr<dd::ResourceManager> ResourceManager;
|
||||||
|
|
||||||
|
std::string m_Name;
|
||||||
|
int m_Layer;
|
||||||
|
bool m_Hidden;
|
||||||
|
|
||||||
|
Frame* m_Parent;
|
||||||
|
typedef std::multimap<std::string, Frame*> Children_t; // name -> frame
|
||||||
|
std::map<int, Children_t> m_Children; // layer -> Children_t
|
||||||
|
|
||||||
|
virtual bool OnKeyDown(const dd::Events::KeyDown &event) { return false; }
|
||||||
|
virtual bool OnKeyUp(const dd::Events::KeyUp &event) { return false; }
|
||||||
|
//virtual bool OnMouseDown(const Events::KeyDown &event) { }
|
||||||
|
//virtual bool OnMouseUp(const Events::KeyDown &event) { }
|
||||||
|
virtual bool OnCommand(const dd::Events::InputCommand &event) { return false; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
EventRelay<Frame, dd::Events::KeyDown> m_EKeyDown;
|
||||||
|
EventRelay<Frame, dd::Events::KeyUp> m_EKeyUp;
|
||||||
|
EventRelay<Frame, dd::Events::InputCommand> m_EInputCommand;
|
||||||
|
|
||||||
|
void Initialize()
|
||||||
|
{
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_FRAME_H
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
//
|
||||||
|
// Created by Administrator on 2015-09-17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_MAINMENUFRAME_H
|
||||||
|
#define DAYDREAM_MAINMENUFRAME_H
|
||||||
|
|
||||||
|
#include "GUI/Frame.h"
|
||||||
|
#include "GUI/TextureFrame.h"
|
||||||
|
|
||||||
|
#include "Game/EGameStart.h"
|
||||||
|
//#include "Events/PlayBGM.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
class MainMenuFrame : public Frame {
|
||||||
|
public:
|
||||||
|
MainMenuFrame(Frame *parent, std::string name)
|
||||||
|
: Frame(parent, name) {
|
||||||
|
m_CurrentSelection = 0;
|
||||||
|
|
||||||
|
//Hide();
|
||||||
|
m_Background = new TextureFrame(this, "Background");
|
||||||
|
m_Background->SetTexture("Textures/GUI/MainMenu/BackGround.png");
|
||||||
|
|
||||||
|
m_Buttons = new TextureFrame(this, "Message");
|
||||||
|
m_Buttons->SetTexture("Textures/GUI/MainMenu/Buttons.png");
|
||||||
|
m_CurrentCoordinate = -m_SelectionCoordinates[0] * Scale();
|
||||||
|
m_TargetCoordinate = m_CurrentCoordinate;
|
||||||
|
m_Buttons->X = m_CurrentCoordinate.x;
|
||||||
|
m_Buttons->Y = m_CurrentCoordinate.y;
|
||||||
|
|
||||||
|
/*Events::PlayBGM e;
|
||||||
|
e.Resource = "Sounds/BGM/DiesIrae.mp3";
|
||||||
|
EventBroker->Publish(e);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update(double dt) override {
|
||||||
|
if (Hidden())
|
||||||
|
return;
|
||||||
|
|
||||||
|
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
|
||||||
|
m_CurrentCoordinate += posDiff * 4.f * (float) dt;
|
||||||
|
|
||||||
|
m_Buttons->X = m_CurrentCoordinate.x;
|
||||||
|
m_Buttons->Y = m_CurrentCoordinate.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool m_Victory;
|
||||||
|
TextureFrame *m_Background;
|
||||||
|
TextureFrame *m_Buttons;
|
||||||
|
|
||||||
|
int m_CurrentSelection;
|
||||||
|
static glm::vec2 m_SelectionCoordinates[2];
|
||||||
|
glm::vec2 m_CurrentCoordinate;
|
||||||
|
glm::vec2 m_TargetCoordinate;
|
||||||
|
|
||||||
|
bool OnCommand(const Events::InputCommand &event) override {
|
||||||
|
if (Hidden())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const float deadzone = 0.5f;
|
||||||
|
|
||||||
|
if (event.Command == "interface_horizontal") {
|
||||||
|
if (event.Value > deadzone)
|
||||||
|
m_CurrentSelection++;
|
||||||
|
else if (event.Value < -deadzone)
|
||||||
|
m_CurrentSelection--;
|
||||||
|
}
|
||||||
|
m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 1) ? 1 : m_CurrentSelection);
|
||||||
|
m_TargetCoordinate = -m_SelectionCoordinates[m_CurrentSelection] * Scale();
|
||||||
|
|
||||||
|
if (event.Command == "interface_confirm" && event.Value > 0) {
|
||||||
|
// Play
|
||||||
|
if (m_CurrentSelection == 0) {
|
||||||
|
Hide();
|
||||||
|
Events::GameStart e1;
|
||||||
|
EventBroker->Publish(e1);
|
||||||
|
/*Events::PlayBGM e2;
|
||||||
|
e2.Resource = "Sounds/BGM/FlightOfTheBumblebee.mp3";
|
||||||
|
EventBroker->Publish(e2);*/
|
||||||
|
}
|
||||||
|
// Quit
|
||||||
|
else if (m_CurrentSelection == 1) {
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
glm::vec2 MainMenuFrame::m_SelectionCoordinates[2] =
|
||||||
|
{
|
||||||
|
glm::vec2(0, 0),
|
||||||
|
glm::vec2(193, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_MAINMENUFRAME_H
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
//
|
||||||
|
// Created by Administrator on 2015-09-17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_TEXTUREFRAME_H
|
||||||
|
#define DAYDREAM_TEXTUREFRAME_H
|
||||||
|
|
||||||
|
#include <glm/detail/type_vec.hpp>
|
||||||
|
#include <glm/detail/type_vec4.hpp>
|
||||||
|
#include "GUI/Frame.h"
|
||||||
|
#include "Core/Texture.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
class TextureFrame : public Frame {
|
||||||
|
public:
|
||||||
|
TextureFrame(Frame *parent, std::string name)
|
||||||
|
: Frame(parent, name), m_Texture(nullptr), m_FadeTexture(nullptr), m_Color(glm::vec4(1.f, 1.f, 1.f, 1.f)),
|
||||||
|
m_FadeDuration(0.f), m_CurrentFade(1.f) { }
|
||||||
|
|
||||||
|
void Draw(std::shared_ptr<Renderer> renderer) override {
|
||||||
|
if (m_Texture == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RenderQueue.Clear();
|
||||||
|
|
||||||
|
// Main texture
|
||||||
|
{
|
||||||
|
SpriteJob job;
|
||||||
|
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);
|
||||||
|
RenderQueue.Forward.Add(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Texture while fading
|
||||||
|
if (m_FadeTexture && m_CurrentFade < 1) {
|
||||||
|
SpriteJob job;
|
||||||
|
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);
|
||||||
|
RenderQueue.Forward.Add(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer->SetCamera(nullptr);
|
||||||
|
renderer->SetViewport(Rectangle(Left(), Top(), Width, Height));
|
||||||
|
renderer->DrawFrame(RenderQueue);
|
||||||
|
}
|
||||||
|
|
||||||
|
dd::Texture *Texture() const { return m_Texture; }
|
||||||
|
|
||||||
|
void SetTexture(std::string resourceName) {
|
||||||
|
m_Texture = ResourceManager->Load<dd::Texture>("Texture", resourceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
dd::Texture *m_Texture;
|
||||||
|
dd::Texture *m_FadeTexture;
|
||||||
|
glm::vec4 m_Color;
|
||||||
|
float m_FadeDuration;
|
||||||
|
float m_CurrentFade;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_TEXTUREFRAME_H
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by Administrator on 2015-09-17.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_EGAMEOVER_H
|
||||||
|
#define DAYDREAM_EGAMEOVER_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
struct GameOver : Event
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_EGAMEOVER_H
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by Administrator on 2015-09-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_EGAMESTART_H
|
||||||
|
#define DAYDREAM_EGAMESTART_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
struct GameStart : Event
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_EGAMESTART_H
|
||||||
@@ -75,7 +75,7 @@ set(SOURCE_FILES
|
|||||||
${SOURCE_FILES_Rendering}
|
${SOURCE_FILES_Rendering}
|
||||||
${SOURCE_FILES_Transform}
|
${SOURCE_FILES_Transform}
|
||||||
${SOURCE_FILES_Physics}
|
${SOURCE_FILES_Physics}
|
||||||
${SOURCE_FILES_Game})
|
${SOURCE_FILES_Game} ../../include/GUI/Frame.h ../../include/GUI/MainMenuFrame.h ../../include/GUI/TextureFrame.h)
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||||
|
|||||||
@@ -473,3 +473,9 @@ void dd::Renderer::DebugKeys()
|
|||||||
m_CurrentScreenBuffer = m_tLighting;
|
m_CurrentScreenBuffer = m_tLighting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dd::Renderer::DrawFrame(RenderQueuePair &rq)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,4 +82,4 @@ void dd::ResourceManager::fileWatcherCallback(std::string path, FileWatcher::Fil
|
|||||||
void dd::ResourceManager::Update()
|
void dd::ResourceManager::Update()
|
||||||
{
|
{
|
||||||
m_FileWatcher.Check();
|
m_FileWatcher.Check();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user