2016-07-02 20:49:31 +02:00
|
|
|
#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
|
|
|
|
2015-06-14 19:08:55 +02:00
|
|
|
#include <engine/SaveGame.hpp>
|
2018-06-21 16:49:05 +02:00
|
|
|
#include <rw/debug.hpp>
|
2016-09-09 22:13:20 +02:00
|
|
|
#include "RWGame.hpp"
|
2014-09-16 20:22:43 +02:00
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
MenuState::MenuState(RWGame* game) : State(game) {
|
|
|
|
enterMainMenu();
|
2015-06-14 19:08:55 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
void MenuState::enterMainMenu() {
|
2016-10-16 21:37:07 +02:00
|
|
|
auto& t = game->getGameData().texts;
|
2016-08-16 01:28:35 +02:00
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
auto menu = Menu::create(
|
|
|
|
{{t.text(MenuDefaults::kStartGameId),
|
|
|
|
[=] { StateManager::get().enter<IngameState>(game); }},
|
|
|
|
{t.text(MenuDefaults::kLoadGameId), [=] { enterLoadMenu(); }},
|
|
|
|
{t.text(MenuDefaults::kDebugId),
|
|
|
|
[=] { StateManager::get().enter<IngameState>(game, true, "test"); }},
|
|
|
|
{t.text(MenuDefaults::kOptionsId),
|
|
|
|
[] { RW_UNIMPLEMENTED("Options Menu"); }},
|
|
|
|
{t.text(MenuDefaults::kQuitGameId),
|
|
|
|
[] { StateManager::get().clear(); }}});
|
|
|
|
menu->offset = glm::vec2(200.f, 200.f);
|
|
|
|
|
|
|
|
enterMenu(menu);
|
2014-05-26 06:34:49 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
void MenuState::enterLoadMenu() {
|
2016-10-18 23:00:53 +02:00
|
|
|
auto menu = Menu::create({{"BACK", [=] { enterMainMenu(); }}});
|
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
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 << " ";
|
2017-09-07 19:00:16 +02:00
|
|
|
auto name = GameStringUtil::fromString(ss.str(), FONT_ARIAL);
|
2016-09-09 22:13:20 +02:00
|
|
|
name += save.basicState.saveName;
|
2016-10-17 00:56:51 +02:00
|
|
|
auto loadsave = [=] {
|
|
|
|
StateManager::get().enter<IngameState>(game, false);
|
|
|
|
game->loadGame(save.savePath);
|
|
|
|
};
|
2016-10-18 23:00:53 +02:00
|
|
|
menu->lambda(name, loadsave);
|
2016-09-09 22:13:20 +02:00
|
|
|
} else {
|
2016-10-18 23:00:53 +02:00
|
|
|
menu->lambda("CORRUPT", [=] {});
|
2016-09-09 22:13:20 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-18 23:00:53 +02:00
|
|
|
menu->offset = glm::vec2(20.f, 30.f);
|
|
|
|
|
|
|
|
enterMenu(menu);
|
2015-06-14 19:08:55 +02:00
|
|
|
}
|
|
|
|
|
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:
|
2016-10-17 00:56:51 +02:00
|
|
|
done();
|
2016-09-09 22:13:20 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
State::handleEvent(e);
|
2014-05-26 06:34:49 +02:00
|
|
|
}
|