2016-07-02 20:49:31 +02:00
|
|
|
#include "MenuState.hpp"
|
2014-05-26 06:34:49 +02:00
|
|
|
#include "game.hpp"
|
2016-07-02 20:49:31 +02:00
|
|
|
#include "IngameState.hpp"
|
2014-05-26 06:34:49 +02:00
|
|
|
|
2014-09-16 20:22:43 +02:00
|
|
|
#include "RWGame.hpp"
|
2015-06-14 19:08:55 +02:00
|
|
|
#include <engine/SaveGame.hpp>
|
2016-04-09 02:28:33 +02:00
|
|
|
#include <rw/defines.hpp>
|
2014-09-16 20:22:43 +02:00
|
|
|
|
|
|
|
MenuState::MenuState(RWGame* game)
|
|
|
|
: State(game)
|
2015-06-14 19:08:55 +02:00
|
|
|
{
|
|
|
|
enterMainMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuState::enterMainMenu()
|
2014-05-26 06:34:49 +02:00
|
|
|
{
|
2015-02-07 23:55:06 +01:00
|
|
|
Menu *m = new Menu(2);
|
|
|
|
m->offset = glm::vec2(200.f, 200.f);
|
2015-06-14 19:08:55 +02:00
|
|
|
m->addEntry(Menu::lambda("Start", [=] { StateManager::get().enter(new IngameState(game)); }));
|
|
|
|
m->addEntry(Menu::lambda("Load Game", [=] { enterLoadMenu(); }));
|
2016-04-10 19:58:18 +02:00
|
|
|
m->addEntry(Menu::lambda("Test", [=] { StateManager::get().enter(new IngameState(game, true, "test")); }));
|
2016-04-09 02:28:33 +02:00
|
|
|
m->addEntry(Menu::lambda("Options", [] { RW_UNIMPLEMENTED("Options Menu"); }));
|
2016-07-31 15:57:20 +02:00
|
|
|
m->addEntry(Menu::lambda("Exit", [] { StateManager::get().clear(); }));
|
2014-05-26 06:34:49 +02:00
|
|
|
this->enterMenu(m);
|
|
|
|
}
|
|
|
|
|
2015-06-14 19:08:55 +02:00
|
|
|
void MenuState::enterLoadMenu()
|
|
|
|
{
|
|
|
|
Menu *m = new Menu(2);
|
2016-04-09 03:21:22 +02:00
|
|
|
m->offset = glm::vec2(20.f, 30.f);
|
2015-06-14 19:08:55 +02:00
|
|
|
m->addEntry(Menu::lambda("Back", [=] { enterMainMenu(); }));
|
|
|
|
auto saves = SaveGame::getAllSaveGameInfo();
|
|
|
|
for(SaveGameInfo& save : saves) {
|
2016-04-09 03:21:22 +02:00
|
|
|
if (save.valid) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << save.basicState.saveTime.year << "/" << save.basicState.saveTime.month << "/" << save.basicState.saveTime.day
|
2016-08-16 03:31:58 +02:00
|
|
|
<< " " << save.basicState.saveTime.hour << ":" << save.basicState.saveTime.minute << " ";
|
|
|
|
auto name = GameStringUtil::fromString(ss.str());
|
|
|
|
name += save.basicState.saveName;
|
|
|
|
m->addEntry(Menu::lambda(name, [=] {
|
2016-04-09 03:21:22 +02:00
|
|
|
StateManager::get().enter(new IngameState(game, false));
|
|
|
|
game->loadGame(save.savePath);
|
|
|
|
}, 20.f));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m->addEntry(Menu::lambda("Corrupt", [=] { }));
|
|
|
|
}
|
2015-06-14 19:08:55 +02:00
|
|
|
}
|
|
|
|
this->enterMenu(m);
|
|
|
|
}
|
|
|
|
|
2014-05-26 06:34:49 +02:00
|
|
|
void MenuState::enter()
|
|
|
|
{
|
2016-06-22 12:29:39 +02:00
|
|
|
getWindow().showCursor();
|
2014-05-26 06:34:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuState::exit()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuState::tick(float dt)
|
|
|
|
{
|
2016-08-02 13:00:05 +02:00
|
|
|
RW_UNUSED(dt);
|
2014-05-26 06:34:49 +02:00
|
|
|
}
|
|
|
|
|
2016-06-22 12:29:39 +02:00
|
|
|
void MenuState::handleEvent(const SDL_Event& e)
|
2014-05-26 06:34:49 +02:00
|
|
|
{
|
|
|
|
switch(e.type) {
|
2016-06-22 12:29:39 +02:00
|
|
|
case SDL_KEYUP:
|
|
|
|
switch(e.key.keysym.sym) {
|
|
|
|
case SDLK_ESCAPE:
|
2014-05-26 06:34:49 +02:00
|
|
|
StateManager::get().exit();
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
State::handleEvent(e);
|
|
|
|
}
|