Enable mainMenu
This commit is contained in:
@@ -8,23 +8,26 @@
|
||||
}
|
||||
],
|
||||
"mainMenuScreen": [
|
||||
{
|
||||
"unique_name": "exit",
|
||||
"position": [0.4, 0.2],
|
||||
"dimensions": [0.25, 0.10],
|
||||
"texture": "data/res/textures/exit.png"
|
||||
},
|
||||
{
|
||||
"unique_name": "play",
|
||||
"position": [0.4, 0.5],
|
||||
"dimensions": [0.25, 0.1],
|
||||
"texture": "data/res/textures/play.png"
|
||||
"texture": "data/res/textures/play.png",
|
||||
"callbackId": 1
|
||||
},
|
||||
{
|
||||
"unique_name": "exit",
|
||||
"position": [0.4, 0.2],
|
||||
"dimensions": [0.25, 0.10],
|
||||
"texture": "data/res/textures/exit.png",
|
||||
"callbackId": 2
|
||||
},
|
||||
{
|
||||
"unique_name": "background",
|
||||
"position": [0.0, 0.0],
|
||||
"dimensions": [1.0, 1.0],
|
||||
"texture": "data/res/textures/mainMenu.png"
|
||||
"texture": "data/res/textures/mainMenu.png",
|
||||
"callbackId": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -169,7 +169,8 @@ void Controller::run()
|
||||
camera->updateDirectionFromMouseInput(gameEventHandler->getCursorDelta());
|
||||
}
|
||||
|
||||
gameWindow->handleActionRegister(gameEventHandler->getWindowActionRegister());
|
||||
menu->writeWindowActions(gameEventHandler->getWindowActionRegister());
|
||||
gameWindow->handleWindowActionRegister(gameEventHandler->getWindowActionRegister());
|
||||
|
||||
menu->handleMouseButtonActionRegister(gameEventHandler->getMouseButtonActionRegister(), gameWindow);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ void EventHandler::key_callback(GLFWwindow *window, int key, int scancode, int a
|
||||
(void)mods;
|
||||
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
windowActionRegister[windowActions::windowShouldClose] = 1;
|
||||
}
|
||||
|
||||
if (key == GLFW_KEY_O && action == GLFW_PRESS) {
|
||||
|
||||
@@ -249,7 +249,8 @@ std::vector<Widget*> JsonParser::getWidgetsFromScreen(const Json::Value &screenJ
|
||||
currentWidgetPosition[0].asFloat(),
|
||||
currentWidgetPosition[1].asFloat(),
|
||||
currentWidgetDimensions[0].asFloat(),
|
||||
currentWidgetDimensions[1].asFloat()
|
||||
currentWidgetDimensions[1].asFloat(),
|
||||
currentWidgetJson["callbackId"].asUInt()
|
||||
);
|
||||
temp_widgets.push_back(currentWidget);
|
||||
}
|
||||
|
||||
27
src/Menu.cpp
27
src/Menu.cpp
@@ -2,8 +2,13 @@
|
||||
#include "JsonParser.h"
|
||||
#include "eventActions.h"
|
||||
#include "helper.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void (Menu::*widgetPressedActionRegister[widgetPressedActions::WIDGET_PRESSED_ACTION_NUM_ITEMS])() = {
|
||||
&Menu::onPlayPressed,
|
||||
&Menu::onExitPressed
|
||||
};
|
||||
|
||||
Menu::Menu(Framebuffer *p_framebuffer, ShaderProgram *p_shaderProgram) :
|
||||
framebuffer(p_framebuffer), shaderProgram(p_shaderProgram)
|
||||
{
|
||||
@@ -58,7 +63,27 @@ void Menu::handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Wind
|
||||
for (auto it = widgets.begin(); it != widgets.end(); it++) {
|
||||
if ((*it)->isHovered(window)) {
|
||||
std::cout << (*it)->getUniqueName() << " clicked!" << std::endl;
|
||||
if((*it)->getCallbackId() == 1)
|
||||
resetActiveScreen();
|
||||
if((*it)->getCallbackId() == 2)
|
||||
shouldExit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::writeWindowActions(bool *windowActionRegister)
|
||||
{
|
||||
if (shouldExit)
|
||||
windowActionRegister[windowActions::windowShouldClose] = true;
|
||||
}
|
||||
|
||||
void Menu::onPlayPressed()
|
||||
{
|
||||
std::cout << "Hello, from Widget play in Menu :)" << std::endl;
|
||||
}
|
||||
|
||||
void Menu::onExitPressed()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Screen.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "JsonParser.h"
|
||||
#include "eventActions.h"
|
||||
|
||||
class Menu
|
||||
{
|
||||
@@ -16,15 +17,23 @@ public:
|
||||
void showScreenByName(const char *unique_name);
|
||||
|
||||
Screen *getActiveScreen();
|
||||
void writeWindowActions(bool *windowActionRegister);
|
||||
|
||||
void resetActiveScreen();
|
||||
|
||||
void handleMouseButtonActionRegister(bool *mouseButtonActionRegister, Window* window);
|
||||
|
||||
void onPlayPressed();
|
||||
void onExitPressed();
|
||||
|
||||
void (*widgetPressedActionRegister[widgetPressedActions::WIDGET_PRESSED_ACTION_NUM_ITEMS])();
|
||||
|
||||
private:
|
||||
Framebuffer *framebuffer;
|
||||
ShaderProgram *shaderProgram;
|
||||
|
||||
bool shouldExit = false;
|
||||
|
||||
std::vector<Screen*> screens;
|
||||
Screen *activeScreen;
|
||||
/*Screen *loadingScreen;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "Framebuffer.h"
|
||||
#include "Widget.h"
|
||||
|
||||
class Menu;
|
||||
|
||||
class Screen
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#include "Widget.h"
|
||||
#include "VertexArray.h"
|
||||
#include "Menu.h"
|
||||
|
||||
Widget::Widget(std::string &name, Texture *texture, float p_x, float p_y, float p_w, float p_h) :
|
||||
Widget::Widget(std::string &name, Texture *texture, float p_x, float p_y, float p_w, float p_h, uint16_t callbackId) :
|
||||
x(p_x),
|
||||
y(p_y),
|
||||
w(p_w),
|
||||
h(p_h),
|
||||
unique_name(name)
|
||||
unique_name(name),
|
||||
callbackId(callbackId)
|
||||
{
|
||||
widgetTextures.push_back(texture);
|
||||
|
||||
@@ -44,6 +46,11 @@ std::string Widget::getUniqueName()
|
||||
return unique_name;
|
||||
}
|
||||
|
||||
uint16_t Widget::getCallbackId()
|
||||
{
|
||||
return callbackId;
|
||||
}
|
||||
|
||||
void Widget::draw(ShaderProgram *shaderProgram)
|
||||
{
|
||||
shaderProgram->bind();
|
||||
|
||||
@@ -4,16 +4,20 @@
|
||||
#include "Mesh.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "Window.h"
|
||||
#include "eventActions.h"
|
||||
|
||||
class Menu;
|
||||
|
||||
class Widget
|
||||
{
|
||||
public:
|
||||
Widget(std::string &name, Texture *texture, float x, float y, float w, float h);
|
||||
Widget(std::string &name, Texture *texture, float x, float y, float w, float h, uint16_t callbackId);
|
||||
~Widget();
|
||||
|
||||
void draw(ShaderProgram *shaderProgram);
|
||||
|
||||
std::string getUniqueName();
|
||||
uint16_t getCallbackId();
|
||||
|
||||
bool isHovered(Window *window);
|
||||
|
||||
@@ -21,6 +25,8 @@ private:
|
||||
double x, y, w, h;
|
||||
|
||||
std::string unique_name;
|
||||
|
||||
uint16_t callbackId;
|
||||
|
||||
std::vector<Vertex> widgetVertices;
|
||||
std::vector<uint32_t> widgetIndices;
|
||||
|
||||
@@ -113,10 +113,10 @@ void Window::setCatchedCursor(bool value)
|
||||
}
|
||||
}
|
||||
|
||||
void Window::handleActionRegister(bool *windowActionRegister)
|
||||
void Window::handleWindowActionRegister(bool *windowActionRegister)
|
||||
{
|
||||
if (windowActionRegister[wireFrameToggle]) {
|
||||
windowActionRegister[wireFrameToggle] = 0;
|
||||
if (windowActionRegister[windowActions::wireFrameToggle]) {
|
||||
windowActionRegister[windowActions::wireFrameToggle] = 0;
|
||||
wireFrameMode = !wireFrameMode;
|
||||
if (wireFrameMode) {
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
@@ -125,11 +125,15 @@ void Window::handleActionRegister(bool *windowActionRegister)
|
||||
}
|
||||
}
|
||||
|
||||
if (windowActionRegister[mouseCatchToggle]) {
|
||||
windowActionRegister[mouseCatchToggle] = 0;
|
||||
if (windowActionRegister[windowActions::mouseCatchToggle]) {
|
||||
windowActionRegister[windowActions::mouseCatchToggle] = 0;
|
||||
mouseCatched = !mouseCatched;
|
||||
setCatchedCursor(mouseCatched);
|
||||
}
|
||||
|
||||
if (windowActionRegister[windowActions::windowShouldClose]) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
}
|
||||
|
||||
// GLFW error function
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
bool isWindowResized();
|
||||
void updateWindowDimensions();
|
||||
|
||||
void handleActionRegister(bool *windowActionRegister);
|
||||
void handleWindowActionRegister(bool *windowActionRegister);
|
||||
|
||||
private:
|
||||
static void glfw_error_callback(int error, const char *description);
|
||||
|
||||
@@ -19,6 +19,7 @@ enum cameraMouseActions {
|
||||
enum windowActions {
|
||||
wireFrameToggle,
|
||||
mouseCatchToggle,
|
||||
windowShouldClose,
|
||||
WINDOW_ACTION_NUM_ITEMS
|
||||
};
|
||||
|
||||
@@ -28,3 +29,9 @@ enum mouseButtonActions {
|
||||
middleClicked,
|
||||
MOUSE_BUTTON_ACTION_NUM_ITEMS
|
||||
};
|
||||
|
||||
enum widgetPressedActions {
|
||||
playClicked,
|
||||
exitClicked,
|
||||
WIDGET_PRESSED_ACTION_NUM_ITEMS
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user