1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-26 04:12:41 +01:00
openrw/rwgame/states/MenuState.cpp

89 lines
2.7 KiB
C++
Raw Normal View History

#include "MenuState.hpp"
#include "IngameState.hpp"
2016-09-09 22:13:20 +02:00
#include "game.hpp"
2014-05-26 06:34:49 +02:00
#include <engine/SaveGame.hpp>
#include <rw/defines.hpp>
2016-09-09 22:13:20 +02:00
#include "RWGame.hpp"
2016-09-09 22:13:20 +02:00
MenuState::MenuState(RWGame* game) : State(game) {
enterMainMenu();
}
2016-09-09 22:13:20 +02:00
void MenuState::enterMainMenu() {
auto data = game->getGameData();
auto& t = data->texts;
2016-09-09 22:13:20 +02:00
Menu* m = new Menu;
m->offset = glm::vec2(200.f, 200.f);
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);
2014-05-26 06:34:49 +02:00
}
2016-09-09 22:13:20 +02:00
void MenuState::enterLoadMenu() {
Menu* m = new Menu;
m->offset = glm::vec2(20.f, 30.f);
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 << " "
<< save.basicState.saveTime.hour << ":"
<< save.basicState.saveTime.minute << " ";
auto name = GameStringUtil::fromString(ss.str());
name += save.basicState.saveName;
m->addEntry(Menu::lambda(name,
[=] {
StateManager::get().enter(
new IngameState(game, false));
game->loadGame(save.savePath);
},
20.f));
} else {
m->addEntry(Menu::lambda("CORRUPT", [=] {}));
}
}
this->enterMenu(m);
}
2016-09-09 22:13:20 +02:00
void MenuState::enter() {
getWindow().showCursor();
2014-05-26 06:34:49 +02:00
}
2016-09-09 22:13:20 +02:00
void MenuState::exit() {
2014-05-26 06:34:49 +02:00
}
2016-09-09 22:13:20 +02:00
void MenuState::tick(float dt) {
RW_UNUSED(dt);
2014-05-26 06:34:49 +02:00
}
2016-09-09 22:13:20 +02:00
void MenuState::handleEvent(const SDL_Event& e) {
switch (e.type) {
case SDL_KEYUP:
switch (e.key.keysym.sym) {
case SDLK_ESCAPE:
StateManager::get().exit();
default:
break;
}
break;
default:
break;
}
State::handleEvent(e);
2014-05-26 06:34:49 +02:00
}