mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
Use GameString in RWGame, using localised strings.
This adds: - Localised GameStrings in the menus, replacing hard-coded strings - Changes the default menu font to match the game
This commit is contained in:
parent
cdebd16532
commit
398e184cd6
@ -7,22 +7,38 @@
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
/**
|
||||
* 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<void(void)> callback;
|
||||
|
||||
Entry(const std::string& title,
|
||||
Entry(const GameString& title,
|
||||
std::function<void(void)> cb,
|
||||
float size)
|
||||
: MenuEntry(title, size), callback(cb)
|
||||
: MenuEntry(title, size)
|
||||
, callback(cb)
|
||||
{
|
||||
}
|
||||
|
||||
@ -68,10 +85,15 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static std::shared_ptr<MenuEntry> lambda(const std::string& n, std::function<void (void)> callback, float size = 30.f)
|
||||
static std::shared_ptr<MenuEntry> lambda(const GameString& n, std::function<void (void)> callback, float size = 30.f)
|
||||
{
|
||||
return std::shared_ptr<MenuEntry>(new Entry(n, callback, size));
|
||||
}
|
||||
|
||||
static std::shared_ptr<MenuEntry> lambda(const std::string& n, std::function<void (void)> callback, float size = 30.f)
|
||||
{
|
||||
return lambda(GameStringUtil::fromString(n), callback, size);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<MenuEntry>> entries;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user