Skip to content

Commit

Permalink
CLIENT-GAME: Add ready button to click on it
Browse files Browse the repository at this point in the history
MINOR'
  • Loading branch information
KitetsuK committed Nov 2, 2023
1 parent 4f393fe commit 134106a
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 19 deletions.
63 changes: 63 additions & 0 deletions assets/Json/HUD.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"gameHud": [
{
"type": "button",
"callback": "sendReadyPacket",
"spritePath": "assets/Menu/button.png",
"width": 3000,
"height" : 1500,
"rect": {
"x": 51.0,
"y": 51.0,
"width": 1265.0,
"height": 305.0
},
"position" : {
"x": 3100,
"y": 6500
},
"collisionRect": {
"width": 3000,
"height": 1500
},
"animRect": [
{
"type": "hover",
"time": 80,
"noIncr": true,
"list": [
{
"x" : 1416.0,
"y": 49.0,
"width": 1267.0,
"height": 307.0
}
]
},
{
"type": "selected",
"time": 80,
"noIncr": true,
"list": [
{
"x" : 2759.0,
"y": 31.0,
"width": 1303.0,
"height": 340.0
}
]
}
]
},
{
"type": "text",
"color": "red",
"size": 3,
"text": "READY !",
"position" : {
"x": 4000,
"y": 7000
}
}
]
}
3 changes: 2 additions & 1 deletion src/Client/SceneManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace Scene {
SystemManagers::GAME,
SystemManagers::DISPLAY,
SystemManagers::PARALLAX,
SystemManagers::NETWORK},
SystemManagers::NETWORK,
SystemManagers::MENU},
{SystemManagers::DISPLAY,
SystemManagers::PARALLAX,
SystemManagers::NETWORK,
Expand Down
10 changes: 1 addition & 9 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ namespace Systems {
return newPos;
}

void sendReadyPacket(std::size_t managerId, std::size_t systemId)
{
if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_R)) {
Nitwork::NitworkClient::getInstance().addReadyMsg();
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
}
}

void playerShootBullet(std::size_t /*unused*/, std::size_t /*unused*/)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Expand Down Expand Up @@ -219,6 +211,6 @@ namespace Systems {

std::vector<std::function<void(std::size_t, std::size_t)>> EventsSystems::getEventSystems()
{
return {playerMovement, changeScene, playerShootBullet, sendReadyPacket};
return {playerMovement, changeScene, playerShootBullet};
}
} // namespace Systems
16 changes: 16 additions & 0 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,21 @@ namespace Menu {
resetSelectedLobby();
::Systems::SelectLobbySystems::LobbyStatus::pageNbr += 1;
}

void sendReadyPacket()
{
auto idsButton = Registry::getInstance().getEntitiesByComponents({typeid(Types::Button)});
auto idsText = Registry::getInstance().getEntitiesByComponents({typeid(Raylib::Text)});
auto arrText = Registry::getInstance().getComponents<Raylib::Text>();

Nitwork::NitworkClient::getInstance().addReadyMsg();
for (auto &id : idsButton) {
Registry::getInstance().removeEntity(id);
}
for (auto &id : idsText) {
Logger::info("Je remove : " + std::to_string(id));
Registry::getInstance().removeEntity(id);
}
}
} // namespace Callback
} // namespace Menu
11 changes: 8 additions & 3 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace Menu {
GO_BACK,
GO_NEXT,
GO_SELECT_LOBBY,
CREATE_NORMAL
CREATE_NORMAL,
SEND_READY
};

NLOHMANN_JSON_SERIALIZE_ENUM(
Expand All @@ -35,7 +36,8 @@ namespace Menu {
{GO_BACK, "goBackPage" },
{GO_NEXT, "goNextPage" },
{GO_SELECT_LOBBY, "goToSelectLobby" },
{CREATE_NORMAL, "onButtonCreateLobbyNormalClicked"}
{CREATE_NORMAL, "onButtonCreateLobbyNormalClicked"},
{SEND_READY, "sendReadyPacket"}
});

void initConnection();
Expand All @@ -54,6 +56,8 @@ namespace Menu {

void onButtonCreateLobbyNormalClicked();

void sendReadyPacket();

const std::unordered_map<CallbackType, std::function<void()>> callbacks = {
{CallbackType::DEFAULT_CALLBACK, &defaultCallBack },
{CallbackType::INIT_CONNECTION, &initConnection },
Expand All @@ -62,7 +66,8 @@ namespace Menu {
{CallbackType::GO_SELECT_LOBBY, &gotToSelectLobby },
{CallbackType::GO_BACK, &goBackPage },
{CallbackType::GO_NEXT, &goNextPage },
{CallbackType::CREATE_NORMAL, &onButtonCreateLobbyNormalClicked}
{CallbackType::CREATE_NORMAL, &onButtonCreateLobbyNormalClicked},
{CallbackType::SEND_READY, &sendReadyPacket}
};

} // namespace Callback
Expand Down
22 changes: 21 additions & 1 deletion src/Client/Systems/Menus/Menu/MenuSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ namespace Systems {
{
Registry::components<Types::InputBox> arrInputBox =
Registry::getInstance().getComponents<Types::InputBox>();
Registry::components<::Systems::SelectLobbySystems::LobbyStatus> arrLobbyStatus =
Registry::getInstance().getComponents<::Systems::SelectLobbySystems::LobbyStatus>();
std::vector<std::size_t> ids = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::InputBox), typeid(Raylib::Text)});

for (auto id : ids) {
if (arrInputBox[id].selected == true) {
if (arrInputBox[id].selected == true && !arrLobbyStatus.exist(id)) {
insertText(id, arrInputBox);
}
}
Expand Down Expand Up @@ -218,6 +220,23 @@ namespace Systems {
}
}

// this system is not in the good file for the moment
void initHud(std::size_t managerId, std::size_t systemId)
{
if (Scene::SceneManager::getInstance().getCurrentScene() != Scene::Scene::MAIN_GAME) {
return;
}
try {
nlohmann::json jsonData =
Json::getInstance().getDataByJsonType<nlohmann::json>("gameHud", JsonType::HUD);
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));
} catch (std::runtime_error &err) {
Logger::info(err.what());
}
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
}

std::vector<std::function<void(std::size_t, std::size_t)>> getMenuSystems()
{
return {
Expand All @@ -228,6 +247,7 @@ namespace Systems {
checkTextInput,
checkInputDeletion,
Systems::moveEntities,
initHud,
quitScene};
}
} // namespace Menu
Expand Down
6 changes: 4 additions & 2 deletions src/ECS/Json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ enum class JsonType {
BULLETS,
MENU,
SELECT_LOBBY,
CREATE_LOBBY
CREATE_LOBBY,
HUD
};

const std::unordered_map<enemy_type_e, JsonType> messageTypes = {
Expand All @@ -42,7 +43,8 @@ const std::unordered_map<JsonType, std::string> pathToJson = {
{JsonType::BULLETS, "assets/Json/bullets.json" },
{JsonType::MENU, "assets/Json/menu.json" },
{JsonType::SELECT_LOBBY, "assets/Json/selectLobby.json" },
{JsonType::CREATE_LOBBY, "assets/Json/createLobby.json" }
{JsonType::CREATE_LOBBY, "assets/Json/createLobby.json" },
{JsonType::HUD, "assets/Json/HUD.json" }
};

class Json {
Expand Down
4 changes: 2 additions & 2 deletions src/ECS/Systems/BulletsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ namespace Systems {
bulletPath,
collisionRect.width,
collisionRect.height,
FRONTLAYER,
static_cast<std::size_t>(FRONT));
DEFAULTLAYER,
0);
Registry::getInstance().getComponents<Types::SpriteDatas>().insertBack(bulletDatas);
Registry::getInstance().getComponents<Types::Rect>().insertBack(spriteRect);

Expand Down
2 changes: 1 addition & 1 deletion src/Nitwork/NitworkMainServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace Nitwork {
int ownerPort)
{
#ifdef _WIN32
std::string winName = "\"" + name + "\"";
std::string winName = "'" + name + "'";
std::basic_ostringstream<TCHAR> cmdline;
cmdline << _T(ECS::ResourcesManager::convertPath(
"./r-type_server.exe",
Expand Down

0 comments on commit 134106a

Please sign in to comment.