Skip to content

Commit

Permalink
CLIENT-MENU: Now users can click on a button to exit programm
Browse files Browse the repository at this point in the history
MINOR
  • Loading branch information
KitetsuK committed Nov 5, 2023
1 parent a1fda4e commit 8de5072
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
61 changes: 61 additions & 0 deletions assets/Json/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,67 @@
}
]
},
{
"type": "text",
"text": "Go Back ('ESC')",
"color": "red",
"size": 1.5,
"position": {
"x": 350,
"y": 875
}
},
{
"type": "button",
"spritePath": "assets/Menu/button.png",
"width": 1600,
"height": 1000,
"callback": "exitGame",
"rect": {
"x": 0.0,
"y": 0.0,
"width": 1366.0,
"height": 406.0
},
"position": {
"x": 100,
"y": 500
},
"collisionRect": {
"width": 1600,
"height": 1000,
"offsetX": 0,
"offsetY": 0
},
"animRect": [
{
"type": "hover",
"time": 80,
"noIncr": true,
"list": [
{
"x": 1366.0,
"y": 0.0,
"width": 1366.0,
"height": 406.0
}
]
},
{
"type": "selected",
"time": 80,
"noIncr": true,
"list": [
{
"x" : 2732.0,
"y": 0.0,
"width": 1366.0,
"height": 406.0
}
]
}
]
},
{
"type": "button",
"callback": "changeParallax",
Expand Down
6 changes: 6 additions & 0 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ namespace Menu {
Scene::SceneManager::getInstance().changeScene(MENU);
}


void exitGame()
{
Scene::SceneManager::getInstance().stop();
}

void createServer()
{
auto arrInputBox = Registry::getInstance().getComponents<Types::InputBox>();
Expand Down
9 changes: 7 additions & 2 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace Menu {
GO_CREATE_SERVER,
CREATE_SERVER,
GO_MENU,
CHANGE_PARALLAX
CHANGE_PARALLAX,
EXIT_GAME
};

NLOHMANN_JSON_SERIALIZE_ENUM(
Expand All @@ -45,7 +46,8 @@ namespace Menu {
{GO_CREATE_SERVER, "goCreateServer" },
{CREATE_SERVER, "createServer" },
{GO_MENU, "goToMenu" },
{CHANGE_PARALLAX, "changeParallax" }
{CHANGE_PARALLAX, "changeParallax" },
{EXIT_GAME, "exitGame" },
});

void initConnection();
Expand Down Expand Up @@ -74,6 +76,8 @@ namespace Menu {

void changeParallax();

void exitGame();

const std::unordered_map<CallbackType, std::function<void()>> callbacks = {
{CallbackType::DEFAULT_CALLBACK, &defaultCallBack},
{CallbackType::INIT_CONNECTION, &initConnection},
Expand All @@ -86,6 +90,7 @@ namespace Menu {
{CallbackType::SEND_READY, &sendReadyPacket},
{CallbackType::GO_CREATE_SERVER, &goCreateServer},
{CallbackType::CREATE_SERVER, &createServer},
{CallbackType::EXIT_GAME, &exitGame},
{
CallbackType::GO_MENU,
&goMenu,
Expand Down

0 comments on commit 8de5072

Please sign in to comment.