Interface input revised
This commit is contained in:
+11
-5
@@ -6,6 +6,9 @@
|
||||
|
||||
#include "Util/Rectangle.h"
|
||||
#include "EventBroker.h"
|
||||
#include "Events/KeyDown.h"
|
||||
#include "Events/KeyUp.h"
|
||||
#include "Events/InputCommand.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "Renderer.h"
|
||||
#include "RenderQueue.h"
|
||||
@@ -129,11 +132,6 @@ public:
|
||||
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)
|
||||
{
|
||||
if (this->Hidden())
|
||||
@@ -196,14 +194,22 @@ protected:
|
||||
typedef std::multimap<std::string, std::shared_ptr<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 OnMouseDown(const Events::KeyDown &event) { }
|
||||
//virtual bool OnMouseUp(const Events::KeyDown &event) { }
|
||||
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;
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ public:
|
||||
vp1 = new Viewport(worldFrame, "Viewport1", m_World);
|
||||
vp1->X = 0;
|
||||
vp1->Width = this->Width / 2.f;
|
||||
new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
|
||||
//new VehicleSelection(vp1, "VehicleSelection", 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->X = vp1->Right();
|
||||
|
||||
+50
-23
@@ -37,30 +37,9 @@ namespace GUI
|
||||
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 scale = Scale();
|
||||
glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection];
|
||||
m_TargetCoordinate = coord * scale + glm::vec2(Width / 2.f, Height / 2.f);
|
||||
glm::vec2 size = m_SelectionSizes[m_CurrentSelection];
|
||||
m_TargetSize = size * scale;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Update(double dt) override
|
||||
{
|
||||
@@ -94,6 +73,54 @@ namespace GUI
|
||||
float m_CurrentAlpha;
|
||||
|
||||
TextureFrame* m_Background;
|
||||
|
||||
bool OnCommand(const Events::InputCommand &event) override
|
||||
{
|
||||
// Menu movement
|
||||
if (event.Command == "interface_horizontal" || event.Command == "interface_vertical")
|
||||
{
|
||||
// Horizontal scrolling
|
||||
if (event.Command == "interface_horizontal")
|
||||
{
|
||||
if (event.Value > 0)
|
||||
m_CurrentSelection++;
|
||||
else if (event.Value < 0)
|
||||
m_CurrentSelection--;
|
||||
}
|
||||
// Vertical scrolling to switch between "rows" in an intuitive way
|
||||
else if (event.Command == "interface_vertical")
|
||||
{
|
||||
if (event.Value > 0)
|
||||
{
|
||||
if (m_CurrentSelection == 0)
|
||||
m_CurrentSelection++;
|
||||
else if (m_CurrentSelection == 3)
|
||||
m_CurrentSelection--;
|
||||
}
|
||||
else if (event.Value < 0)
|
||||
{
|
||||
if (m_CurrentSelection == 1)
|
||||
m_CurrentSelection--;
|
||||
else if (m_CurrentSelection == 2)
|
||||
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 scale = Scale();
|
||||
glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection];
|
||||
m_TargetCoordinate = coord * scale + glm::vec2(Width / 2.f, Height / 2.f);
|
||||
glm::vec2 size = m_SelectionSizes[m_CurrentSelection];
|
||||
m_TargetSize = size * scale;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
glm::vec2 VehicleSelection::m_SelectionCoordinates[4] = {
|
||||
|
||||
@@ -8,6 +8,22 @@ void GameWorld::Initialize()
|
||||
ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj");
|
||||
ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj");
|
||||
|
||||
// Interface
|
||||
BindKey(GLFW_KEY_A, "interface_horizontal", -1.f);
|
||||
BindKey(GLFW_KEY_D, "interface_horizontal", 1.f);
|
||||
BindGamepadAxis(Gamepad::Axis::LeftX, "interface_horizontal", 1.f);
|
||||
BindGamepadButton(Gamepad::Button::Left, "interface_horizontal", -1.f);
|
||||
BindGamepadButton(Gamepad::Button::Right, "interface_horizontal", 1.f);
|
||||
BindKey(GLFW_KEY_W, "interface_vertical", 1.f);
|
||||
BindKey(GLFW_KEY_S, "interface_vertical", -1.f);
|
||||
BindGamepadAxis(Gamepad::Axis::LeftY, "interface_vertical", 1.f);
|
||||
BindGamepadButton(Gamepad::Button::Up, "interface_vertical", 1.f);
|
||||
BindGamepadButton(Gamepad::Button::Down, "interface_vertical", -1.f);
|
||||
BindKey(GLFW_KEY_SPACE, "interface_accept", 1.f);
|
||||
BindGamepadButton(Gamepad::Button::A, "interface_accept", 1.f);
|
||||
|
||||
|
||||
|
||||
BindKey(GLFW_KEY_W, "vertical", 1.f);
|
||||
BindKey(GLFW_KEY_S, "vertical", -1.f);
|
||||
BindKey(GLFW_KEY_A, "horizontal", -1.f);
|
||||
|
||||
Reference in New Issue
Block a user