Skip to content

Commit

Permalink
CLIENT-MENU: Add a little text to indicate scene + fix quiGame bug
Browse files Browse the repository at this point in the history
MINOR
  • Loading branch information
KitetsuK committed Nov 5, 2023
1 parent c901b0e commit f3404e9
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 24 deletions.
10 changes: 10 additions & 0 deletions assets/Json/createLobby.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@
]
}
]
},
{
"type": "text",
"color": "red",
"size": 2,
"text": "CREATE LOBBY",
"position" : {
"x": 4150,
"y": 500
}
}
]
}
32 changes: 16 additions & 16 deletions assets/Json/createServer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"spritePath": "assets/Menu/button.png",
"width": 1600,
"height": 1000,
"callback": "goToSelectLobby",
"callback": "goToMenu",
"rect": {
"x": 0.0,
"y": 0.0,
Expand Down Expand Up @@ -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
}
},
{
Expand All @@ -185,8 +175,8 @@
"height": 406.0
},
"position": {
"x": 3750,
"y": 7100
"x": 3400,
"y": 6000
},
"collisionRect": {
"width": 2500,
Expand Down Expand Up @@ -235,6 +225,16 @@
]
}
]
},
{
"type": "text",
"color": "red",
"size": 2,
"text": "CREATE SERVER",
"position" : {
"x": 3800,
"y": 500
}
}
]
}
Expand Down
10 changes: 10 additions & 0 deletions assets/Json/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@
"x": 4150,
"y": 7950
}
},
{
"type": "text",
"color": "red",
"size": 2,
"text": "MENU",
"position" : {
"x": 4150,
"y": 500
}
}
]
}
71 changes: 71 additions & 0 deletions assets/Json/selectLobby.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
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 @@ -156,6 +156,7 @@ namespace Menu {
void sendReadyPacket()
{
auto idsButton = Registry::getInstance().getEntitiesByComponents({typeid(Types::Button)});
auto arrButton = Registry::getInstance().getComponents<Types::Button>();

Nitwork::NitworkClient::getInstance().addReadyMsg();
for (auto &id : idsButton) {
Expand All @@ -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<Types::InputBox>();
Expand Down
16 changes: 10 additions & 6 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace Menu {
CREATE_NORMAL,
SEND_READY,
GO_CREATE_SERVER,
CREATE_SERVER
CREATE_SERVER,
GO_MENU,
};

NLOHMANN_JSON_SERIALIZE_ENUM(
Expand All @@ -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();
Expand All @@ -64,6 +66,8 @@ namespace Menu {

void goCreateServer();

void goMenu();

void createServer();

const std::unordered_map<CallbackType, std::function<void()>> callbacks = {
Expand All @@ -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
3 changes: 2 additions & 1 deletion src/Client/Systems/Menus/Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ namespace Menu {

static std::size_t initButtonFromSprite(nlohmann::json &elem, std::function<void()> &callback)
{
Types::Button button(callback);

std::size_t id = Registry::getInstance().addEntity();
initFromSprite(elem);
std::string name = Json::isDataExist(elem, "name") ? Json::getInstance().getDataFromJson<std::string>(elem, "name") : "";
Types::Button button(callback, name);
Types::Position position = {
Types::Position(Json::getInstance().getDataFromJson<Types::Position>(elem, "position"))};
Types::CollisionRect collisionRect = {Types::CollisionRect(
Expand Down
1 change: 0 additions & 1 deletion src/Client/Systems/Network/ClientNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ namespace Systems {
if (Raylib::KeyboardInput::isKeyPressed(Raylib::KeyboardKey::KB_ESCAPE)) {
if (Scene::SceneManager::getInstance().getCurrentScene() == static_cast<std::size_t>(GAME)) {
Nitwork::NitworkClient::getInstance().disconnectLobby();
Scene::SceneManager::getInstance().changeScene(static_cast<std::size_t>(SELECT_LOBBY));
}
}
}
Expand Down

0 comments on commit f3404e9

Please sign in to comment.