diff options
Diffstat (limited to 'game/menus/endgame/EndGameSubScript.cpp')
-rw-r--r-- | game/menus/endgame/EndGameSubScript.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp index 6edfe7b..e081350 100644 --- a/game/menus/endgame/EndGameSubScript.cpp +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -3,6 +3,9 @@ #include "../../Events.h" #include "../ButtonReplaySubScript.h" #include "../IFloatingWindowScript.h" +#include "../../Config.h" +#include "ValueBroker.h" +#include "manager/SaveManager.h" #include <string> @@ -21,6 +24,9 @@ void EndGameSubScript::init() { this->subscribe<EndGameEvent>([this](const EndGameEvent e) { return this->reset_timescale(); }); + this->subscribe<ShowScoreEvent>([this](const ShowScoreEvent e) { + return this->showscore(); + }); } bool EndGameSubScript::disable_all() { @@ -53,3 +59,37 @@ bool EndGameSubScript::reset_timescale() { this->get_loop_timer().set_time_scale(1); return false; } + +bool EndGameSubScript::showscore(){ + // Gather text + Text & coins_text = this->get_components_by_name<Text>("gold_endgame").front().get(); + Text & distance_text = this->get_components_by_name<Text>("distance_endgame").front().get(); + Text & highscore_text = this->get_components_by_name<Text>("highscore_endgame").front().get(); + highscore_text.active = false; + + // Gather saved data + SaveManager & savemgr = this->get_save_manager(); + ValueBroker<std::string> coins = savemgr.get<std::string>(TOTAL_COINS_RUN, "0"); + ValueBroker<std::string> distance = savemgr.get<std::string>(DISTANCE_RUN, "0"); + int distance_run = savemgr.get<int>(DISTANCE_RUN, 0).get(); + int distance_game = savemgr.get<int>(DISTANCE_GAME, 0).get(); + + // Show highscore + if(distance_run > distance_game) highscore_text.active = true; + + const float CHAR_SIZE_DIS = 20; + // Show distance + std::string distance_string = "DISTANCE:" + distance.get(); + distance_text.text = distance_string; + crepe::vec2 size_distance = {CHAR_SIZE_DIS*distance_string.size(), (CHAR_SIZE_DIS*distance_string.size() / distance_string.size()) * 2}; + distance_text.dimensions = size_distance; + + const float CHAR_SIZE_COIN = 16; + // Show coins + std::string coins_string = "Coins:" + coins.get(); + coins_text.text = coins_string; + crepe::vec2 size_coins = {CHAR_SIZE_COIN*coins_string.size(), (CHAR_SIZE_COIN*coins_string.size() / coins_string.size()) * 2}; + coins_text.dimensions = size_coins; + + return false; +} |