Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions GUI/src/Game/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> &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<int> &) {}

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)
{
Expand Down
4 changes: 3 additions & 1 deletion GUI/src/Network/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,10 @@ void zappy::network::Protocol::handlePlayerInventory(const std::string &params)

std::istringstream iss(trueParams);
int playerId;
size_t x;
size_t y;

iss >> playerId;
iss >> playerId >> x >> y;

game::Inventory inventory;
size_t resourceCount;
Expand Down
1 change: 1 addition & 0 deletions GUI/src/Renderer/ARenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace zappy {
namespace gui {
constexpr float RequestMapContentTimeUnit = 20.0f;
constexpr float RequestPlayersInventoryTimeUnit = 126.0f;

class ARenderer : public IRenderer {
public:
Expand Down
1 change: 1 addition & 0 deletions GUI/src/Renderer/Raylib/Map/MapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
20 changes: 19 additions & 1 deletion GUI/src/Renderer/Raylib/Menu/GameMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(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<float>(textSize), 1);

if (textSizeVec.x > maxTextWidth) {
std::string truncated = text;
const std::string ellipsis = "...";
const float ellipsisWidth = MeasureTextEx(GetFontDefault(), ellipsis.c_str(), static_cast<float>(textSize), 1).x;

while (!truncated.empty()) {
truncated.pop_back();
Vector2 currentSize = MeasureTextEx(GetFontDefault(), truncated.c_str(), static_cast<float>(textSize), 1);
if (currentSize.x + ellipsisWidth <= maxTextWidth)
break;
}
text = truncated + ellipsis;
}

DrawTextEx(GetFontDefault(), text.c_str(),
{static_cast<float>(boxX + paddingX), static_cast<float>(y)},
static_cast<float>(textSize), 1, _textColor);
y += lineHeight + paddingY;
Expand Down
7 changes: 7 additions & 0 deletions GUI/src/Renderer/Raylib/RaylibRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions GUI/src/Renderer/Raylib/RaylibRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ namespace zappy {
{ raylib::SceneType::BASIC, [](const std::shared_ptr<game::GameState> &g) { return std::make_unique<raylib::BasicScene>(g); } },
{ raylib::SceneType::POKEMON, [](const std::shared_ptr<game::GameState> &g) { return std::make_unique<raylib::PokemonScene>(g); } }
};

const std::map<int, size_t> _defaultKeysFrequencies = {
{ KEY_ONE, 1 },
{ KEY_TWO, 50 },
{ KEY_THREE, 100 },
{ KEY_FOUR, 200 },
{ KEY_FIVE, 500 },
{ KEY_SEVEN, 7 },
};
};
}
}
27 changes: 16 additions & 11 deletions GUI/src/Renderer/Raylib/Scene/AScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
zappy::gui::raylib::AScene::AScene(const std::shared_ptr<game::GameState> &gameState) :
_camera(Camera()),
_music(),
_isMusicPlaying(true),
_gameState(gameState),
_skybox(),
_mapRenderer(std::make_unique<MapRenderer>(this->_gameState->getMap()))
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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());

Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions GUI/src/Renderer/Raylib/Scene/AScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace zappy {
Camera _camera;

MusicGame _music;
bool _isMusicPlaying;

const std::shared_ptr<game::GameState> _gameState;

Expand Down