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
2 parents f3404e9 + ce7792d commit 49c4bb1
Show file tree
Hide file tree
Showing 26 changed files with 218 additions and 160 deletions.
32 changes: 18 additions & 14 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace Systems {
Registry &registry = Registry::getInstance();
Clock &clock_ = registry.getClock();
Registry::components<Types::Position> arrPosition = registry.getComponents<Types::Position>();
Registry::components<Types::Health> arrHealth = registry.getComponents<Types::Health>();
Registry::components<Types::Health> arrHealth = registry.getComponents<Types::Health>();
std::vector<std::size_t> ids =
registry.getEntitiesByComponents({typeid(Types::Player), typeid(Types::Position)});

Expand Down Expand Up @@ -164,10 +164,10 @@ namespace Systems {
{
bool isKeyPressed = false;
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry &registry = Registry::getInstance();
Registry::components<Types::Position> arrPos = registry.getComponents<Types::Position>();
Registry &registry = Registry::getInstance();
Registry::components<Types::Position> arrPos = registry.getComponents<Types::Position>();
Registry::components<Types::Health> arrHealth = registry.getComponents<Types::Health>();
std::vector<std::size_t> ids = registry.getEntitiesByComponents(
std::vector<std::size_t> ids = registry.getEntitiesByComponents(
{typeid(Types::Player), typeid(Types::Position), typeid(Types::Health)});
Clock &clock_ = registry.getClock();
static std::size_t clockId = clock_.create(true);
Expand Down Expand Up @@ -223,9 +223,8 @@ namespace Systems {

static bool isGameWin()
{
Registry &registry = Registry::getInstance();
std::vector<std::size_t> idsPlayer =
registry.getEntitiesByComponents({typeid(Types::Player)});
Registry &registry = Registry::getInstance();
std::vector<std::size_t> idsPlayer = registry.getEntitiesByComponents({typeid(Types::Player)});
std::vector<std::size_t> idsOtherPlayer =
registry.getEntitiesByComponents({typeid(Types::OtherPlayer)});

Expand All @@ -237,15 +236,15 @@ namespace Systems {

static void modifEndGameText(const std::string &endGameMessage)
{
bool found = false;
const Raylib::Vector2 pos = {0, 2};
constexpr std::size_t fontSize = 2;
const std::string textKeywordWaveEnd = "WaveText";
const std::string textKeyWordGameEnd = "endGameText";
bool found = false;
const Raylib::Vector2 pos = {0, 2};
constexpr std::size_t fontSize = 2;
const std::string textKeywordWaveEnd = "WaveText";
const std::string textKeyWordGameEnd = "endGameText";

std::vector<std::size_t> ids =
Registry::getInstance().getEntitiesByComponents({typeid(Raylib::TextShared)});
auto &textArray = Registry::getInstance().getComponents<Raylib::TextShared>();
auto &textArray = Registry::getInstance().getComponents<Raylib::TextShared>();

for (auto &id : ids) {
if (textArray[id]->getKeyword() == textKeyWordGameEnd) {
Expand All @@ -259,7 +258,12 @@ namespace Systems {

if (found == false) {
Registry::getInstance().addEntity();
Raylib::TextShared endGameText = Raylib::Text::fromText(endGameMessage, pos, fontSize, Raylib::Color(Raylib::ColorDef::White), textKeyWordGameEnd);
Raylib::TextShared endGameText = Raylib::Text::fromText(
endGameMessage,
pos,
fontSize,
Raylib::Color(Raylib::ColorDef::White),
textKeyWordGameEnd);
Registry::getInstance().getComponents<Raylib::TextShared>().insertBack(endGameText);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Client/Systems/Menus/CreateLobby/CreateLobbySystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#include <algorithm>
#include <string>
// #include "CustomTypes.hpp"
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga-graphics/Raylib/Raylib.hpp"
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga/SceneManager.hpp"
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "Menu.hpp"
#include "MessageTypes.h"
#include "NitworkClient.hpp"
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "B-luga/SceneManager.hpp"
#include "ResourcesManager.hpp"
#include "Parallax.hpp"
#include "ResourcesManager.hpp"
#include "init.hpp"

namespace Systems {
Expand Down
11 changes: 5 additions & 6 deletions src/Client/Systems/Menus/CreateServer/CreateServerSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
*/

#include "CreateServerSystems.hpp"
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "B-luga/SceneManager.hpp"
#include "ResourcesManager.hpp"
#include "Parallax.hpp"
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "Menu.hpp"
#include "Parallax.hpp"
#include "ResourcesManager.hpp"
#include "init.hpp"


namespace Systems::CreateServerSystems {
void initCreateServer(std::size_t managerId, std::size_t systemId)
{
Expand All @@ -27,7 +26,7 @@ namespace Systems::CreateServerSystems {
ResourcesManager::getPathByJsonType(JsonType::CREATE_SERVER),
"createServerMenu");
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));
Json::getInstance().getDatasFromList(jsonData));
} catch (std::runtime_error &err) {
Logger::info(err.what());
}
Expand All @@ -38,4 +37,4 @@ namespace Systems::CreateServerSystems {
{
return {initCreateServer};
}
}
} // namespace Systems::CreateServerSystems
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

namespace Systems::CreateServerSystems {
std::vector<std::function<void(std::size_t /*unused*/, std::size_t /*unused*/)>>
getCreateServerSystems();
getCreateServerSystems();
}
15 changes: 7 additions & 8 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

#include "ButtonCallbacks.hpp"
#include "B-luga/Logger.hpp"
#include "NitworkClient.hpp"
#include "B-luga-graphics/GraphicsCustomTypes.hpp"
#include "B-luga-graphics/Raylib/Raylib.hpp"
#include "B-luga/Logger.hpp"
#include "B-luga/SceneManager.hpp"
#include "SelectLobbySystems.hpp"
#include "B-luga-graphics/GraphicsCustomTypes.hpp"
#include "NitworkClient.hpp"
#include "ResourcesManager.hpp"
#include "SelectLobbySystems.hpp"
#include "init.hpp"

namespace Menu {
Expand Down Expand Up @@ -162,8 +162,8 @@ namespace Menu {
for (auto &id : idsButton) {
Registry::getInstance().removeEntity(id);
}
auto &arrText = Registry::getInstance().getComponents<Raylib::TextShared>();
auto idsText = Registry::getInstance().getEntitiesByComponents({typeid(Raylib::TextShared)});
auto &arrText = Registry::getInstance().getComponents<Raylib::TextShared>();
auto idsText = Registry::getInstance().getEntitiesByComponents({typeid(Raylib::TextShared)});
for (auto &id : idsText) {
if (arrText[id]->getCurrentText() == "READY !") {
Registry::getInstance().removeEntity(id);
Expand All @@ -184,8 +184,7 @@ namespace Menu {
void createServer()
{
auto arrInputBox = Registry::getInstance().getComponents<Types::InputBox>();
auto ids = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::InputBox)});
auto ids = Registry::getInstance().getEntitiesByComponents({typeid(Types::InputBox)});

for (auto id : ids) {
if (arrInputBox[id].name == "port") {
Expand Down
25 changes: 24 additions & 1 deletion src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Menu {
{SEND_READY, "sendReadyPacket" },
{GO_CREATE_SERVER, "goCreateServer" },
{CREATE_SERVER, "createServer" },
{GO_MENU, "goToMenu" }
{GO_MENU, "goToMenu" },
});

void initConnection();
Expand Down Expand Up @@ -71,6 +71,7 @@ namespace Menu {
void createServer();

const std::unordered_map<CallbackType, std::function<void()>> callbacks = {
<<<<<<< HEAD
{CallbackType::DEFAULT_CALLBACK, &defaultCallBack },
{CallbackType::INIT_CONNECTION, &initConnection },
{CallbackType::CONNECT, &connectLobbySelected },
Expand All @@ -83,6 +84,28 @@ namespace Menu {
{CallbackType::GO_CREATE_SERVER, &goCreateServer },
{CallbackType::CREATE_SERVER, &createServer },
{CallbackType::GO_MENU, &goMenu, }
=======
{CallbackType::DEFAULT_CALLBACK, &defaultCallBack},
{CallbackType::INIT_CONNECTION, &initConnection},
{CallbackType::CONNECT, &connectLobbySelected},
{CallbackType::CREATE, &onButtonGotoCreateLobbyClicked},
{CallbackType::GO_SELECT_LOBBY, &gotToSelectLobby},
{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,
}
>>>>>>> ce7792df03b6132b68c41482bd45eb67351b538d
};
} // namespace Callback
} // namespace Menu
17 changes: 9 additions & 8 deletions src/Client/Systems/Menus/Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Menu {
? Json::getInstance().getDataFromJson<std::string>(elem, "name")
: "";
Types::FontSize fsz({Json::getInstance().getDataFromJson<float>(elem, "textSize")});
auto textComp = Raylib::Text::fromText(text);
auto textComp = Raylib::Text::fromText(text);
std::size_t maxChar(Json::getInstance().getDataFromJson<std::size_t>(elem, "maxChar"));
Types::InputBox inputBox(text, name, maxChar);
auto search =
Expand Down Expand Up @@ -166,10 +166,10 @@ namespace Menu {

static std::size_t initText(nlohmann::json &elem)
{
std::size_t id = Registry::getInstance().addEntity();
std::string text = Json::isDataExist(elem, "text")
? Json::getInstance().getDataFromJson<std::string>(elem, "text")
: "";
std::size_t id = Registry::getInstance().addEntity();
std::string text = Json::isDataExist(elem, "text")
? Json::getInstance().getDataFromJson<std::string>(elem, "text")
: "";
Raylib::TextShared textComp = Raylib::Text::fromText(text);
if (Json::isDataExist(elem, "size")) {
Types::FontSize fsz({Json::getInstance().getDataFromJson<float>(elem, "size")});
Expand All @@ -178,9 +178,10 @@ namespace Menu {
if (Json::isDataExist(elem, "color")) {
auto search = Types::colorMatchStrings.find(
Json::getInstance().getDataFromJson<std::string>(elem, "color"));
Raylib::Color color = search != Types::colorMatchStrings.end() ? Types::colorMatchStrings.at(
Json::getInstance().getDataFromJson<std::string>(elem, "color"))
: Raylib::Color(Raylib::ColorDef::White);
Raylib::Color color = search != Types::colorMatchStrings.end()
? Types::colorMatchStrings.at(
Json::getInstance().getDataFromJson<std::string>(elem, "color"))
: Raylib::Color(Raylib::ColorDef::White);
Registry::getInstance().getComponents<Raylib::Color>().insertBack(color);
}
if (Json::isDataExist(elem, "position")) {
Expand Down
21 changes: 8 additions & 13 deletions src/Client/Systems/Menus/Menu/MenuSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
*/

#include "MenuSystems.hpp"
#include "B-luga-graphics/Raylib/Graphics/Graphics.hpp"
#include "B-luga-graphics/AnimRect.hpp"
#include "B-luga-graphics/GraphicsCustomTypes.hpp"
#include "B-luga-graphics/Raylib/Graphics/Graphics.hpp"
#include "B-luga-physics/ECSCustomTypes.hpp"
#include "B-luga/Maths/Maths.hpp"
#include "B-luga/SceneManager.hpp"
#include "Menu.hpp"
#include "SelectLobbySystems.hpp"
#include "Parallax.hpp"
#include "ResourcesManager.hpp"
#include "SelectLobbySystems.hpp"
#include "init.hpp"

namespace Systems {
Expand Down Expand Up @@ -194,8 +194,9 @@ namespace Systems {
}
try {
Parallax::initParalax();
nlohmann::json jsonData =
Json::getInstance().getDataByJsonType<nlohmann::json>(ResourcesManager::getPathByJsonType(JsonType::MENU), "menu");
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>(
ResourcesManager::getPathByJsonType(JsonType::MENU),
"menu");
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));
} catch (std::runtime_error &err) {
Expand All @@ -212,15 +213,9 @@ namespace Systems {
case CREATE_LOBBY_SCENE:
Scene::SceneManager::getInstance().changeScene(SELECT_LOBBY);
break;
case SELECT_LOBBY:
Scene::SceneManager::getInstance().changeScene(MENU);
break;
case CREATE_SERVER_SCENE:
Scene::SceneManager::getInstance().changeScene(MENU);
break;
case GAME:
Scene::SceneManager::getInstance().changeScene(SELECT_LOBBY);
break;
case SELECT_LOBBY: Scene::SceneManager::getInstance().changeScene(MENU); break;
case CREATE_SERVER_SCENE: Scene::SceneManager::getInstance().changeScene(MENU); break;
case GAME: Scene::SceneManager::getInstance().changeScene(SELECT_LOBBY); break;
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/Client/Systems/Menus/SelectLobby/SelectLobbySystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "Menu.hpp"
#include "MessageTypes.h"
#include "Parallax.hpp"
#include "NitworkClient.hpp"
#include "Parallax.hpp"
#include "ResourcesManager.hpp"
#include "init.hpp"

Expand All @@ -37,8 +37,9 @@ namespace Systems::SelectLobbySystems {
}
try {
Parallax::initParalax();
nlohmann::json jsonData =
Json::getInstance().getDataByJsonType<nlohmann::json>(ResourcesManager::getPathByJsonType(JsonType::SELECT_LOBBY), "lobbyMenu");
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>(
ResourcesManager::getPathByJsonType(JsonType::SELECT_LOBBY),
"lobbyMenu");
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));
} catch (const std::exception &err) {
Expand Down Expand Up @@ -88,7 +89,9 @@ namespace Systems::SelectLobbySystems {
arrPosition[id].y += offset * i;
}
if (arrLobbyText.exist(id)) {
Raylib::Vector2 pos(arrLobbyText[id]->getPosition().x, arrLobbyText[id]->getPosition().y);
Raylib::Vector2 pos(
arrLobbyText[id]->getPosition().x,
arrLobbyText[id]->getPosition().y);
pos.y += Maths::intToFloatConservingDecimals(offset) * i;
arrLobbyText[id]->setPosition(pos);
}
Expand Down Expand Up @@ -120,7 +123,7 @@ namespace Systems::SelectLobbySystems {
+ gameTypeToString(arrLobby[ids[index]].gameType);
arrLobbyStatus[lobbyStatusId].ip = std::string(arrLobby[ids[index]].lobbyInfos.ip);
arrLobbyStatus[lobbyStatusId].port = arrLobby[ids[index]].lobbyInfos.port;
Raylib::TextShared text = Raylib::Text::fromText(text_t);
Raylib::TextShared text = Raylib::Text::fromText(text_t);
if (arrLobbyText.exist(lobbyStatusId)) {
arrLobbyText[lobbyStatusId]->setCurrentText(text_t);
}
Expand All @@ -143,8 +146,8 @@ namespace Systems::SelectLobbySystems {
}
Registry::getInstance().getClock().decreaseSeconds(clockId, 1);
// list of all lobby
auto idsLobbyStatus =
Registry::getInstance().getEntitiesByComponents({typeid(LobbyStatus), typeid(Raylib::TextShared)});
auto idsLobbyStatus = Registry::getInstance().getEntitiesByComponents(
{typeid(LobbyStatus), typeid(Raylib::TextShared)});
auto idsClickableLobbys = Registry::getInstance().getEntitiesByComponents(
{typeid(LobbyStatus), typeid(Raylib::TextShared), typeid(Types::InputBox)});
auto ids = Registry::getInstance().getEntitiesByComponents({typeid(struct lobby_s)});
Expand Down
Loading

0 comments on commit 49c4bb1

Please sign in to comment.