diff --git a/rwgame/MenuSystem.hpp b/rwgame/MenuSystem.hpp index 160eb362..30e9bd76 100644 --- a/rwgame/MenuSystem.hpp +++ b/rwgame/MenuSystem.hpp @@ -7,22 +7,38 @@ #include #include +/** + * Default values for menus that should match the look and feel of the original + */ +namespace MenuDefaults +{ +constexpr int kFont = 1; + +constexpr const char* kStartGameId = "FET_SAN"; +constexpr const char* kResumeGameId = "FEM_RES"; +constexpr const char* kLoadGameId = "FET_LG"; +constexpr const char* kDebugId = "FEM_DBG"; +constexpr const char* kOptionsId = "FET_OPT"; +constexpr const char* kQuitGameId = "FET_QG"; +} + class Menu { int font; public: - Menu(int font) + Menu(int font = MenuDefaults::kFont) : font(font), activeEntry(-1) {} struct MenuEntry { - std::string name; + GameString text; float _size; - MenuEntry(const std::string& n, float size = 30.f) : name(n), _size(size) + MenuEntry(const GameString& n, float size = 30.f) + : text(n) + , _size(size) { - std::transform(name.begin(), name.end(), name.begin(), toupper); } float getHeight() { return _size; } @@ -32,7 +48,7 @@ public: TextRenderer::TextInfo ti; ti.font = font; ti.screenPosition = basis; - ti.text = GameStringUtil::fromString(name); + ti.text = text; ti.size = getHeight(); if( ! active ) { @@ -53,10 +69,11 @@ public: { std::function callback; - Entry(const std::string& title, + Entry(const GameString& title, std::function cb, float size) - : MenuEntry(title, size), callback(cb) + : MenuEntry(title, size) + , callback(cb) { } @@ -68,10 +85,15 @@ public: } }; - static std::shared_ptr lambda(const std::string& n, std::function callback, float size = 30.f) + static std::shared_ptr lambda(const GameString& n, std::function callback, float size = 30.f) { return std::shared_ptr(new Entry(n, callback, size)); } + + static std::shared_ptr lambda(const std::string& n, std::function callback, float size = 30.f) + { + return lambda(GameStringUtil::fromString(n), callback, size); + } std::vector> entries; diff --git a/rwgame/states/MenuState.cpp b/rwgame/states/MenuState.cpp index d79337c4..325ef627 100644 --- a/rwgame/states/MenuState.cpp +++ b/rwgame/states/MenuState.cpp @@ -14,26 +14,29 @@ MenuState::MenuState(RWGame* game) void MenuState::enterMainMenu() { - Menu *m = new Menu(2); + auto data = game->getGameData(); + auto& t = data->texts; + + Menu *m = new Menu; m->offset = glm::vec2(200.f, 200.f); - m->addEntry(Menu::lambda("Start", [=] { StateManager::get().enter(new IngameState(game)); })); - m->addEntry(Menu::lambda("Load Game", [=] { enterLoadMenu(); })); - m->addEntry(Menu::lambda("Test", [=] { StateManager::get().enter(new IngameState(game, true, "test")); })); - m->addEntry(Menu::lambda("Options", [] { RW_UNIMPLEMENTED("Options Menu"); })); - m->addEntry(Menu::lambda("Exit", [] { StateManager::get().clear(); })); + m->addEntry(Menu::lambda(t.text(MenuDefaults::kStartGameId), [=] { StateManager::get().enter(new IngameState(game)); })); + m->addEntry(Menu::lambda(t.text(MenuDefaults::kLoadGameId), [=] { enterLoadMenu(); })); + m->addEntry(Menu::lambda(t.text(MenuDefaults::kDebugId), [=] { StateManager::get().enter(new IngameState(game, true, "test")); })); + m->addEntry(Menu::lambda(t.text(MenuDefaults::kOptionsId), [] { RW_UNIMPLEMENTED("Options Menu"); })); + m->addEntry(Menu::lambda(t.text(MenuDefaults::kQuitGameId), [] { StateManager::get().clear(); })); this->enterMenu(m); } void MenuState::enterLoadMenu() { - Menu *m = new Menu(2); + Menu *m = new Menu; m->offset = glm::vec2(20.f, 30.f); - m->addEntry(Menu::lambda("Back", [=] { enterMainMenu(); })); + m->addEntry(Menu::lambda("BACK", [=] { enterMainMenu(); })); auto saves = SaveGame::getAllSaveGameInfo(); for(SaveGameInfo& save : saves) { if (save.valid) { std::stringstream ss; - ss << save.basicState.saveTime.year << "/" << save.basicState.saveTime.month << "/" << save.basicState.saveTime.day + ss << save.basicState.saveTime.year << " " << save.basicState.saveTime.month << " " << save.basicState.saveTime.day << " " << save.basicState.saveTime.hour << ":" << save.basicState.saveTime.minute << " "; auto name = GameStringUtil::fromString(ss.str()); name += save.basicState.saveName; @@ -43,7 +46,7 @@ void MenuState::enterLoadMenu() }, 20.f)); } else { - m->addEntry(Menu::lambda("Corrupt", [=] { })); + m->addEntry(Menu::lambda("CORRUPT", [=] { })); } } this->enterMenu(m); diff --git a/rwgame/states/PauseState.cpp b/rwgame/states/PauseState.cpp index 95139007..2e59db60 100644 --- a/rwgame/states/PauseState.cpp +++ b/rwgame/states/PauseState.cpp @@ -6,11 +6,14 @@ PauseState::PauseState(RWGame* game) : State(game) { - Menu *m = new Menu(2); + auto data = game->getGameData(); + auto& t = data->texts; + + Menu *m = new Menu; m->offset = glm::vec2( 200.f, 200.f ); - m->addEntry(Menu::lambda("Continue", [] { StateManager::get().exit(); })); - m->addEntry(Menu::lambda("Options", [] { std::cout << "Options" << std::endl; })); - m->addEntry(Menu::lambda("Exit", [] { StateManager::get().clear(); })); + m->addEntry(Menu::lambda(t.text(MenuDefaults::kResumeGameId), [] { StateManager::get().exit(); })); + m->addEntry(Menu::lambda(t.text(MenuDefaults::kOptionsId), [] { std::cout << "Options" << std::endl; })); + m->addEntry(Menu::lambda(t.text(MenuDefaults::kQuitGameId), [] { StateManager::get().clear(); })); this->enterMenu(m); }