diff --git a/assets/Json/createLobby.json b/assets/Json/createLobby.json index 8dfff103..a8c42a57 100644 --- a/assets/Json/createLobby.json +++ b/assets/Json/createLobby.json @@ -284,6 +284,16 @@ ] } ] + }, + { + "type": "text", + "color": "red", + "size": 2, + "text": "CREATE LOBBY", + "position" : { + "x": 4150, + "y": 500 + } } ] } diff --git a/assets/Json/createServer.json b/assets/Json/createServer.json index f968a6ea..50671396 100644 --- a/assets/Json/createServer.json +++ b/assets/Json/createServer.json @@ -5,7 +5,7 @@ "spritePath": "assets/Menu/button.png", "width": 1600, "height": 1000, - "callback": "goToSelectLobby", + "callback": "goToMenu", "rect": { "x": 0.0, "y": 0.0, @@ -152,24 +152,14 @@ } ] }, - { - "type": "text", - "color": "red", - "size": 3, - "text": "CREATE WITH GAME TYPE :", - "position" : { - "x": 3000, - "y": 6500 - } - }, { "type": "text", "color": "white", "size": 2, - "text": "NORMAL", + "text": "CREATE", "position" : { - "x": 4600, - "y": 7600 + "x": 4200, + "y": 6500 } }, { @@ -185,8 +175,8 @@ "height": 406.0 }, "position": { - "x": 3750, - "y": 7100 + "x": 3400, + "y": 6000 }, "collisionRect": { "width": 2500, @@ -235,6 +225,16 @@ ] } ] + }, + { + "type": "text", + "color": "red", + "size": 2, + "text": "CREATE SERVER", + "position" : { + "x": 3800, + "y": 500 + } } ] } diff --git a/assets/Json/menu.json b/assets/Json/menu.json index 1dbe0ce0..877d2e69 100644 --- a/assets/Json/menu.json +++ b/assets/Json/menu.json @@ -261,6 +261,16 @@ "x": 4150, "y": 7950 } + }, + { + "type": "text", + "color": "red", + "size": 2, + "text": "MENU", + "position" : { + "x": 4150, + "y": 500 + } } ] } diff --git a/assets/Json/selectLobby.json b/assets/Json/selectLobby.json index 27ac8651..6c7fd317 100644 --- a/assets/Json/selectLobby.json +++ b/assets/Json/selectLobby.json @@ -259,6 +259,77 @@ "x": 7350, "y": 7250 } + }, + { + "type": "button", + "spritePath": "assets/Menu/button.png", + "width": 1600, + "height": 1000, + "callback": "goToMenu", + "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": "text", + "text": "Go Back", + "color": "red", + "size": 2, + "position": { + "x": 525, + "y": 875 + } + }, + { + "type": "text", + "color": "red", + "size": 2, + "text": "SELECT LOBBY", + "position" : { + "x": 4150, + "y": 500 + } } ], "inputBoxes" : { diff --git a/src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp b/src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp index aa7e6146..d8917a23 100644 --- a/src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp +++ b/src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp @@ -156,6 +156,7 @@ namespace Menu { void sendReadyPacket() { auto idsButton = Registry::getInstance().getEntitiesByComponents({typeid(Types::Button)}); + auto arrButton = Registry::getInstance().getComponents(); Nitwork::NitworkClient::getInstance().addReadyMsg(); for (auto &id : idsButton) { @@ -175,6 +176,11 @@ namespace Menu { Scene::SceneManager::getInstance().changeScene(CREATE_SERVER_SCENE); } + void goMenu() + { + Scene::SceneManager::getInstance().changeScene(MENU); + } + void createServer() { auto arrInputBox = Registry::getInstance().getComponents(); diff --git a/src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp b/src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp index 565e4654..9e0710b5 100644 --- a/src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp +++ b/src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp @@ -25,7 +25,8 @@ namespace Menu { CREATE_NORMAL, SEND_READY, GO_CREATE_SERVER, - CREATE_SERVER + CREATE_SERVER, + GO_MENU, }; NLOHMANN_JSON_SERIALIZE_ENUM( @@ -41,7 +42,8 @@ namespace Menu { {CREATE_NORMAL, "onButtonCreateLobbyNormalClicked"}, {SEND_READY, "sendReadyPacket" }, {GO_CREATE_SERVER, "goCreateServer" }, - {CREATE_SERVER, "createServer" } + {CREATE_SERVER, "createServer" }, + {GO_MENU, "goToMenu" } }); void initConnection(); @@ -64,6 +66,8 @@ namespace Menu { void goCreateServer(); + void goMenu(); + void createServer(); const std::unordered_map> callbacks = { @@ -75,10 +79,10 @@ namespace Menu { {CallbackType::GO_BACK, &goBackPage }, {CallbackType::GO_NEXT, &goNextPage }, {CallbackType::CREATE_NORMAL, &onButtonCreateLobbyNormalClicked}, - {CallbackType::SEND_READY, &sendReadyPacket, }, - {CallbackType::GO_CREATE_SERVER, &goCreateServer, }, - {CallbackType::CREATE_SERVER, &createServer, } + {CallbackType::SEND_READY, &sendReadyPacket }, + {CallbackType::GO_CREATE_SERVER, &goCreateServer }, + {CallbackType::CREATE_SERVER, &createServer }, + {CallbackType::GO_MENU, &goMenu, } }; - } // namespace Callback } // namespace Menu diff --git a/src/Client/Systems/Menus/Menu/Menu.cpp b/src/Client/Systems/Menus/Menu/Menu.cpp index ccee6181..358844bf 100644 --- a/src/Client/Systems/Menus/Menu/Menu.cpp +++ b/src/Client/Systems/Menus/Menu/Menu.cpp @@ -128,10 +128,11 @@ namespace Menu { static std::size_t initButtonFromSprite(nlohmann::json &elem, std::function &callback) { - Types::Button button(callback); std::size_t id = Registry::getInstance().addEntity(); initFromSprite(elem); + std::string name = Json::isDataExist(elem, "name") ? Json::getInstance().getDataFromJson(elem, "name") : ""; + Types::Button button(callback, name); Types::Position position = { Types::Position(Json::getInstance().getDataFromJson(elem, "position"))}; Types::CollisionRect collisionRect = {Types::CollisionRect( diff --git a/src/Client/Systems/Network/ClientNetwork.cpp b/src/Client/Systems/Network/ClientNetwork.cpp index e7be31fb..3c10380d 100644 --- a/src/Client/Systems/Network/ClientNetwork.cpp +++ b/src/Client/Systems/Network/ClientNetwork.cpp @@ -395,7 +395,6 @@ namespace Systems { if (Raylib::KeyboardInput::isKeyPressed(Raylib::KeyboardKey::KB_ESCAPE)) { if (Scene::SceneManager::getInstance().getCurrentScene() == static_cast(GAME)) { Nitwork::NitworkClient::getInstance().disconnectLobby(); - Scene::SceneManager::getInstance().changeScene(static_cast(SELECT_LOBBY)); } } }