From 78a20507d0c67262bf1c18b6a28c297494fe97bd Mon Sep 17 00:00:00 2001 From: Oursegamin Date: Sun, 6 Jul 2025 23:34:48 +0200 Subject: [PATCH] fix: hot fixs (protocol inventory / others) --- GUI/src/Game/GameState.cpp | 25 +++---------------- GUI/src/Network/Protocol.cpp | 4 ++- GUI/src/Renderer/ARenderer.hpp | 1 + GUI/src/Renderer/Raylib/Map/MapRenderer.cpp | 1 + GUI/src/Renderer/Raylib/Menu/GameMenu.cpp | 20 ++++++++++++++- GUI/src/Renderer/Raylib/RaylibRenderer.cpp | 7 ++++++ GUI/src/Renderer/Raylib/RaylibRenderer.hpp | 9 +++++++ GUI/src/Renderer/Raylib/Scene/AScene.cpp | 27 ++++++++++++--------- GUI/src/Renderer/Raylib/Scene/AScene.hpp | 1 + 9 files changed, 60 insertions(+), 35 deletions(-) diff --git a/GUI/src/Game/GameState.cpp b/GUI/src/Game/GameState.cpp index de2169e..960e46c 100644 --- a/GUI/src/Game/GameState.cpp +++ b/GUI/src/Game/GameState.cpp @@ -53,29 +53,10 @@ void zappy::game::GameState::playerExpulsion(const int &id) void zappy::game::GameState::playerBroadcast(const int &, const std::string &) {} -void zappy::game::GameState::startIncantation( - const int &, const int &, - const int &, - const std::vector &playerIds -) { - for (int id : playerIds) { - Player &player = getPlayerById(id); - player.pray(); - } -} - -void zappy::game::GameState::endIncantation(const int &x, const int &y, const bool &result) -{ - auto players = getPlayersByCoord(x, y); +void zappy::game::GameState::startIncantation(const int &, const int &, const int &, const std::vector &) {} - for (Player &player : players) { - if (!player.isPraying()) - continue; - player.stopPraying(); - if (result) - player.level += 1; - } -} +void zappy::game::GameState::endIncantation(const int &, const int &, const bool &) +{} void zappy::game::GameState::hatchEgg(const int &eggId) { diff --git a/GUI/src/Network/Protocol.cpp b/GUI/src/Network/Protocol.cpp index be3cb21..283a34b 100644 --- a/GUI/src/Network/Protocol.cpp +++ b/GUI/src/Network/Protocol.cpp @@ -395,8 +395,10 @@ void zappy::network::Protocol::handlePlayerInventory(const std::string ¶ms) std::istringstream iss(trueParams); int playerId; + size_t x; + size_t y; - iss >> playerId; + iss >> playerId >> x >> y; game::Inventory inventory; size_t resourceCount; diff --git a/GUI/src/Renderer/ARenderer.hpp b/GUI/src/Renderer/ARenderer.hpp index eb773f0..8a4698e 100644 --- a/GUI/src/Renderer/ARenderer.hpp +++ b/GUI/src/Renderer/ARenderer.hpp @@ -16,6 +16,7 @@ namespace zappy { namespace gui { constexpr float RequestMapContentTimeUnit = 20.0f; + constexpr float RequestPlayersInventoryTimeUnit = 126.0f; class ARenderer : public IRenderer { public: diff --git a/GUI/src/Renderer/Raylib/Map/MapRenderer.cpp b/GUI/src/Renderer/Raylib/Map/MapRenderer.cpp index 8a05146..e37f029 100644 --- a/GUI/src/Renderer/Raylib/Map/MapRenderer.cpp +++ b/GUI/src/Renderer/Raylib/Map/MapRenderer.cpp @@ -448,6 +448,7 @@ void zappy::gui::raylib::MapRenderer::removePlayer(const int &id) for (auto it = this->_players.begin(); it != this->_players.end(); it++) { if ((*it)->getId() == id) { this->_players.erase(it); + this->_playerActionQueues.erase(id); break; } } diff --git a/GUI/src/Renderer/Raylib/Menu/GameMenu.cpp b/GUI/src/Renderer/Raylib/Menu/GameMenu.cpp index 47cc65b..9365944 100644 --- a/GUI/src/Renderer/Raylib/Menu/GameMenu.cpp +++ b/GUI/src/Renderer/Raylib/Menu/GameMenu.cpp @@ -242,8 +242,26 @@ void zappy::gui::raylib::GameMenu::_renderBroadcasts(const int &screenWidth, con DrawText("Broadcasts", boxX + paddingX, boxY + paddingY / 2, fontSize, WHITE); int y = boxY + titleHeight; + const float maxTextWidth = static_cast(boxWidth - 2 * paddingX); for (const auto &broadcast : _broadcasts) { - DrawTextEx(GetFontDefault(), broadcast.c_str(), + std::string text = broadcast; + Vector2 textSizeVec = MeasureTextEx(GetFontDefault(), text.c_str(), static_cast(textSize), 1); + + if (textSizeVec.x > maxTextWidth) { + std::string truncated = text; + const std::string ellipsis = "..."; + const float ellipsisWidth = MeasureTextEx(GetFontDefault(), ellipsis.c_str(), static_cast(textSize), 1).x; + + while (!truncated.empty()) { + truncated.pop_back(); + Vector2 currentSize = MeasureTextEx(GetFontDefault(), truncated.c_str(), static_cast(textSize), 1); + if (currentSize.x + ellipsisWidth <= maxTextWidth) + break; + } + text = truncated + ellipsis; + } + + DrawTextEx(GetFontDefault(), text.c_str(), {static_cast(boxX + paddingX), static_cast(y)}, static_cast(textSize), 1, _textColor); y += lineHeight + paddingY; diff --git a/GUI/src/Renderer/Raylib/RaylibRenderer.cpp b/GUI/src/Renderer/Raylib/RaylibRenderer.cpp index 5c505f7..6ef19c1 100644 --- a/GUI/src/Renderer/Raylib/RaylibRenderer.cpp +++ b/GUI/src/Renderer/Raylib/RaylibRenderer.cpp @@ -62,6 +62,13 @@ void zappy::gui::RaylibRenderer::handleInput() return; } + for (auto &[key, value] : this->_defaultKeysFrequencies) { + if (this->_inputManager.isKeyReleased(key)) { + this->_protocolRequests[network::GP::TIME_UNIT_MODIFICATION](value, 0); + break; + } + } + this->_scene->handleInput(this->_inputManager); this->_pauseMenu->handleInput(this->_inputManager); diff --git a/GUI/src/Renderer/Raylib/RaylibRenderer.hpp b/GUI/src/Renderer/Raylib/RaylibRenderer.hpp index 11d7b41..f05317e 100644 --- a/GUI/src/Renderer/Raylib/RaylibRenderer.hpp +++ b/GUI/src/Renderer/Raylib/RaylibRenderer.hpp @@ -86,6 +86,15 @@ namespace zappy { { raylib::SceneType::BASIC, [](const std::shared_ptr &g) { return std::make_unique(g); } }, { raylib::SceneType::POKEMON, [](const std::shared_ptr &g) { return std::make_unique(g); } } }; + + const std::map _defaultKeysFrequencies = { + { KEY_ONE, 1 }, + { KEY_TWO, 50 }, + { KEY_THREE, 100 }, + { KEY_FOUR, 200 }, + { KEY_FIVE, 500 }, + { KEY_SEVEN, 7 }, + }; }; } } diff --git a/GUI/src/Renderer/Raylib/Scene/AScene.cpp b/GUI/src/Renderer/Raylib/Scene/AScene.cpp index 6b0b497..845d8bd 100644 --- a/GUI/src/Renderer/Raylib/Scene/AScene.cpp +++ b/GUI/src/Renderer/Raylib/Scene/AScene.cpp @@ -10,6 +10,7 @@ zappy::gui::raylib::AScene::AScene(const std::shared_ptr &gameState) : _camera(Camera()), _music(), + _isMusicPlaying(true), _gameState(gameState), _skybox(), _mapRenderer(std::make_unique(this->_gameState->getMap())) @@ -47,6 +48,16 @@ void zappy::gui::raylib::AScene::init() SetMasterVolume(0.5f); } +/** @brief Gère les entrées utilisateur. + * + * @param inputManager Le gestionnaire d'entrée. + */ +void zappy::gui::raylib::AScene::handleInput(InputManager &inputManager) +{ + if (inputManager.isKeyPressed(KEY_M)) + this->_isMusicPlaying = !this->_isMusicPlaying; +} + /** @brief Met à jour les éléments de la scène. * * Met à jour le rendu de la carte, le ciel et la musique. @@ -55,7 +66,9 @@ void zappy::gui::raylib::AScene::update() { this->_mapRenderer->update(this->_gameState->getFrequency()); this->_skybox.update(); - this->_music.update(); + + if (this->_isMusicPlaying) + this->_music.update(); } /** @brief Dessine la scène à l'écran. @@ -64,7 +77,8 @@ void zappy::gui::raylib::AScene::update() */ void zappy::gui::raylib::AScene::render() const { - this->_music.render(); + if (this->_isMusicPlaying) + this->_music.render(); BeginMode3D(getCamera()); @@ -74,15 +88,6 @@ void zappy::gui::raylib::AScene::render() const EndMode3D(); } -/** @brief Gère les entrées utilisateur. - * - * @param inputManager Le gestionnaire d'entrée. - */ -void zappy::gui::raylib::AScene::handleInput(InputManager &inputManager) -{ - (void)inputManager; -} - /** @brief Ajoute un œuf à la scène. * * @param id L'identifiant de l'œuf à ajouter. diff --git a/GUI/src/Renderer/Raylib/Scene/AScene.hpp b/GUI/src/Renderer/Raylib/Scene/AScene.hpp index 506c746..9fb8e8f 100644 --- a/GUI/src/Renderer/Raylib/Scene/AScene.hpp +++ b/GUI/src/Renderer/Raylib/Scene/AScene.hpp @@ -60,6 +60,7 @@ namespace zappy { Camera _camera; MusicGame _music; + bool _isMusicPlaying; const std::shared_ptr _gameState;