Vehicle selection!

This commit is contained in:
2014-05-31 03:45:37 +02:00
parent 55db057e50
commit a6906886f5
12 changed files with 206 additions and 24 deletions
+1 -1
Submodule assets updated: fe035e74bd...d5991da346
+1 -5
View File
@@ -139,11 +139,7 @@ template <typename ContextType>
void EventBroker::UnsubscribeAll() void EventBroker::UnsubscribeAll()
{ {
const std::string contextTypeName = typeid(ContextType).name(); const std::string contextTypeName = typeid(ContextType).name();
auto contextIt = m_ContextRelays.find(contextTypeName); m_ContextRelays.erase(contextTypeName);
if (contextIt != m_ContextRelays.end())
{
m_ContextRelays.erase(contextIt);
}
} }
#endif // MessageRelay_h__ #endif // MessageRelay_h__
+31 -7
View File
@@ -33,14 +33,14 @@ public:
, m_Name("UIParent") , m_Name("UIParent")
, m_Layer(0) , m_Layer(0)
, m_Hidden(false) , m_Hidden(false)
{ } { Initialize(); }
// Create a frame as a child // Create a frame as a child
Frame(Frame* parent, std::string name) Frame(Frame* parent, std::string name)
: m_Name(name) : m_Name(name)
, m_Layer(0) , m_Layer(0)
, m_Hidden(false) , m_Hidden(false)
{ SetParent(std::shared_ptr<Frame>(parent)); } { SetParent(std::shared_ptr<Frame>(parent)); Initialize(); }
::RenderQueue RenderQueue; ::RenderQueue RenderQueue;
@@ -89,7 +89,10 @@ public:
} }
int Right() const override int Right() const override
{ {
return Left() + Width; if (m_Parent)
return std::min(m_Parent->Right(), Left() + Width);
else
return Left() + Width;
} }
int Top() const override int Top() const override
{ {
@@ -100,14 +103,26 @@ public:
} }
int Bottom() const override int Bottom() const override
{ {
return Top() + Height; if (m_Parent)
return std::min(m_Parent->Bottom(), Top() + Height);
else
return Top() + Height;
} }
Rectangle AbsoluteRectangle() Rectangle AbsoluteRectangle()
{ {
return Rectangle(Left(), Top(), Width, Height); int left = Left();
int top = Top();
int width = Right() - left;
int height = Bottom() - top;
return Rectangle(left, top, width, height);
} }
virtual bool OnKeyDown(const Events::KeyDown &event) { return false; }
virtual bool OnKeyUp(const Events::KeyUp &event) { return false; }
//virtual bool OnMouseDown(const Events::KeyDown &event) { }
//virtual bool OnMouseUp(const Events::KeyDown &event) { }
void UpdateLayered(double dt) void UpdateLayered(double dt)
{ {
if (this->Hidden()) if (this->Hidden())
@@ -137,7 +152,7 @@ public:
return; return;
// Draw ourselves // Draw ourselves
renderer->SetViewport(AbsoluteRectangle()); renderer->SetScissor(AbsoluteRectangle());
this->Draw(renderer); this->Draw(renderer);
// Draw children // Draw children
@@ -150,7 +165,7 @@ public:
if (child->Hidden()) if (child->Hidden())
continue; continue;
Rectangle rect = child->AbsoluteRectangle(); Rectangle rect = child->AbsoluteRectangle();
renderer->SetViewport(rect); renderer->SetScissor(rect);
child->Draw(renderer); child->Draw(renderer);
} }
} }
@@ -170,6 +185,15 @@ protected:
typedef std::multimap<std::string, std::shared_ptr<Frame>> Children_t; // name -> frame typedef std::multimap<std::string, std::shared_ptr<Frame>> Children_t; // name -> frame
std::map<int, Children_t> m_Children; // layer -> Children_t std::map<int, Children_t> m_Children; // layer -> Children_t
private:
EventRelay<Frame, Events::KeyDown> m_EKeyDown;
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
void Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
}
}; };
} }
+3 -1
View File
@@ -6,6 +6,7 @@
#include "GUI/Viewport.h" #include "GUI/Viewport.h"
#include "GUI/TextureFrame.h" #include "GUI/TextureFrame.h"
#include "GUI/PlayerHUD.h" #include "GUI/PlayerHUD.h"
#include "VehicleSelection.h"
#include "GameWorld.h" #include "GameWorld.h"
@@ -26,7 +27,8 @@ public:
vp1 = new Viewport(worldFrame, "Viewport1", m_World); vp1 = new Viewport(worldFrame, "Viewport1", m_World);
vp1->X = 0; vp1->X = 0;
vp1->Width = 640; vp1->Width = 640;
new PlayerHUD(vp1, "PlayerHUD", m_World, 1); //new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
new VehicleSelection(vp1, "VehicleSelection", m_World, 1);
vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2->X = vp1->Right(); vp2->X = vp1->Right();
+3 -3
View File
@@ -1,9 +1,9 @@
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
#ifndef GUI_PlayerHUD_h__ #ifndef GUI_PlayerHUD_h__
#define GUI_PlayerHUD_h__ #define GUI_PlayerHUD_h__
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
namespace GUI namespace GUI
{ {
+48 -5
View File
@@ -13,7 +13,10 @@ public:
TextureFrame(Frame* parent, std::string name) TextureFrame(Frame* parent, std::string name)
: Frame(parent, name) : Frame(parent, name)
, m_Texture(nullptr) , m_Texture(nullptr)
, m_FadeTexture(nullptr)
, m_Color(glm::vec4(1.f, 1.f, 1.f, 1.f)) , 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 void Draw(std::shared_ptr<Renderer> renderer) override
@@ -22,13 +25,28 @@ public:
return; return;
RenderQueue.Clear(); RenderQueue.Clear();
SpriteJob job;
job.TextureID = m_Texture->ResourceID; // Main texture
job.Texture = *m_Texture; {
job.Color = m_Color; SpriteJob job;
RenderQueue.Add(job); job.TextureID = m_Texture->ResourceID;
job.Texture = *m_Texture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
RenderQueue.Add(job);
}
// Texture while fading
if (m_FadeTexture && m_CurrentFade < 1)
{
SpriteJob job;
job.TextureID = m_FadeTexture->ResourceID;
job.Texture = *m_FadeTexture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
RenderQueue.Add(job);
}
renderer->SetCamera(nullptr); renderer->SetCamera(nullptr);
renderer->SetViewport(Rectangle(Left(), Top(), Width, Height));
renderer->DrawFrame(RenderQueue); renderer->DrawFrame(RenderQueue);
} }
@@ -38,12 +56,37 @@ public:
m_Texture = ResourceManager->Load<::Texture>("Texture", resourceName); m_Texture = ResourceManager->Load<::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; } glm::vec4 Color() const { return m_Color; }
void SetColor(glm::vec4 val) { m_Color = val; } void SetColor(glm::vec4 val) { m_Color = val; }
protected: protected:
::Texture* m_Texture; ::Texture* m_Texture;
::Texture* m_FadeTexture;
glm::vec4 m_Color; glm::vec4 m_Color;
float m_FadeDuration;
float m_CurrentFade;
}; };
+106
View File
@@ -0,0 +1,106 @@
#ifndef GUI_VehicleSelection_h__
#define GUI_VehicleSelection_h__
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
namespace GUI
{
class VehicleSelection : public Frame
{
public:
VehicleSelection(Frame* parent, std::string name, std::shared_ptr<World> world, int playerID)
: Frame(parent, name)
, m_World(world)
, m_PlayerID(playerID)
{
m_CurrentSelection = 0;
m_CurrentCoordinate = -m_SelectionCoordinates[0] + glm::vec2(Width / 2.f, Height / 2.f);
m_TargetCoordinate = m_CurrentCoordinate;
m_CurrentSize = m_SelectionSizes[0];
m_TargetSize = m_CurrentSize;
m_CurrentAlpha = 0.f;
m_Background = new TextureFrame(this, "VehicleSelectImage1");
m_Background->X = m_CurrentCoordinate.x;
m_Background->Y = m_CurrentCoordinate.y;
m_Background->Width = m_CurrentSize.x;
m_Background->Height = m_CurrentSize.y;
m_Background->SetTexture("Textures/GUI/VehicleSelection/1.png");
}
bool OnKeyUp(const Events::KeyUp &event) override
{
if (event.KeyCode == GLFW_KEY_LEFT)
{
m_CurrentSelection--;
}
else if (event.KeyCode == GLFW_KEY_RIGHT)
{
m_CurrentSelection++;
}
m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 3) ? 3 : m_CurrentSelection);
std::stringstream ss;
ss << "Textures/GUI/VehicleSelection/" << m_CurrentSelection + 1 << ".png";
m_Background->FadeToTexture(ss.str(), 1.f);
glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection];
m_TargetCoordinate = coord + glm::vec2(Width / 2.f, Height / 2.f);
glm::vec2 size = m_SelectionSizes[m_CurrentSelection];
m_TargetSize = size;
return true;
}
void Update(double dt) override
{
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
m_CurrentCoordinate += posDiff * 2.f * (float)dt;
glm::vec2 sizeDiff = m_TargetSize - m_CurrentSize;
m_CurrentSize += sizeDiff * 3.f * (float)dt;
m_CurrentAlpha += (1 - m_CurrentAlpha) * 3.f * (float)dt;
m_Background->X = m_CurrentCoordinate.x;
m_Background->Y = m_CurrentCoordinate.y;
m_Background->Width = m_CurrentSize.x;
m_Background->Height = m_CurrentSize.y;
}
protected:
std::shared_ptr<World> m_World;
int m_PlayerID;
int m_CurrentSelection;
static glm::vec2 m_SelectionCoordinates[4];
static glm::vec2 m_SelectionSizes[4];
glm::vec2 m_CurrentCoordinate;
glm::vec2 m_TargetCoordinate;
glm::vec2 m_CurrentSize;
glm::vec2 m_TargetSize;
float m_CurrentAlpha;
TextureFrame* m_Background;
};
glm::vec2 VehicleSelection::m_SelectionCoordinates[4] = {
glm::vec2(339, 506),
glm::vec2(639, 377),
glm::vec2(1249, 399),
glm::vec2(1535, 628)
};
glm::vec2 VehicleSelection::m_SelectionSizes[4] = {
glm::vec2(1632, 918),
glm::vec2(1793, 1009),
glm::vec2(1793, 1009),
glm::vec2(1854, 1043)
};
}
#endif // GUI_VehicleSelection_h__
+1
View File
@@ -65,6 +65,7 @@ public:
return; return;
renderer->SetCamera(m_Camera); renderer->SetCamera(m_Camera);
renderer->SetViewport(AbsoluteRectangle());
renderer->DrawWorld(m_Parent->RenderQueue); renderer->DrawWorld(m_Parent->RenderQueue);
} }
+2 -2
View File
@@ -260,7 +260,7 @@ void Renderer::DrawFrame(RenderQueue &rq)
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClearColor(0.0f, 0.5f, 0.0f, 1.0f); //glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
@@ -364,7 +364,7 @@ void Renderer::DrawWorld(RenderQueue &rq)
*/ */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
//glViewport(0, 0, m_Width, m_Height); //glViewport(0, 0, m_Width, m_Height);
// Clear G-buffer // Clear G-buffer
+6
View File
@@ -48,6 +48,11 @@ public:
m_Viewport = viewport; m_Viewport = viewport;
} }
void SetScissor(const Rectangle &scissor)
{
m_Scissor = scissor;
}
void SetCamera(std::shared_ptr<Camera> camera) void SetCamera(std::shared_ptr<Camera> camera)
{ {
m_Camera = camera; m_Camera = camera;
@@ -109,6 +114,7 @@ private:
std::unordered_map<int, std::shared_ptr<Camera>> m_Cameras; std::unordered_map<int, std::shared_ptr<Camera>> m_Cameras;
Rectangle m_Viewport; Rectangle m_Viewport;
Rectangle m_Scissor;
std::shared_ptr<Camera> m_Camera; std::shared_ptr<Camera> m_Camera;
struct Light struct Light
+1
View File
@@ -198,6 +198,7 @@
<ClInclude Include="..\..\src\GUI\GameFrame.h" /> <ClInclude Include="..\..\src\GUI\GameFrame.h" />
<ClInclude Include="..\..\src\GUI\HealthOverlay.h" /> <ClInclude Include="..\..\src\GUI\HealthOverlay.h" />
<ClInclude Include="..\..\src\GUI\PlayerHUD.h" /> <ClInclude Include="..\..\src\GUI\PlayerHUD.h" />
<ClInclude Include="..\..\src\GUI\VehicleSelection.h" />
<ClInclude Include="..\..\src\GUI\WorldFrame.h" /> <ClInclude Include="..\..\src\GUI\WorldFrame.h" />
<ClInclude Include="..\..\src\GUI\TextureFrame.h" /> <ClInclude Include="..\..\src\GUI\TextureFrame.h" />
<ClInclude Include="..\..\src\GUI\Viewport.h" /> <ClInclude Include="..\..\src\GUI\Viewport.h" />
@@ -482,6 +482,9 @@
<ClInclude Include="..\..\src\Systems\WheelPairSystem.h"> <ClInclude Include="..\..\src\Systems\WheelPairSystem.h">
<Filter>Physics\Systems</Filter> <Filter>Physics\Systems</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\GUI\VehicleSelection.h">
<Filter>GUI</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl"> <None Include="..\..\src\Shaders\Fragment2.glsl">