2016-10-17 00:56:51 +02:00
|
|
|
#ifndef RWGAME_STATE_HPP
|
|
|
|
#define RWGAME_STATE_HPP
|
2014-08-12 22:15:26 +02:00
|
|
|
#include <render/ViewCamera.hpp>
|
2016-09-09 22:13:20 +02:00
|
|
|
#include "GameWindow.hpp"
|
2013-12-27 00:18:55 +01:00
|
|
|
#include "MenuSystem.hpp"
|
2016-08-08 17:27:17 +02:00
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_events.h"
|
2013-12-27 00:18:55 +01:00
|
|
|
|
2014-09-16 20:22:43 +02:00
|
|
|
class RWGame;
|
|
|
|
class GameWorld;
|
2016-10-17 00:56:51 +02:00
|
|
|
class StateManager;
|
2014-09-16 20:22:43 +02:00
|
|
|
|
2016-10-17 00:56:51 +02:00
|
|
|
class State {
|
|
|
|
public:
|
2016-09-09 22:13:20 +02:00
|
|
|
// Helper for global menu behaviour
|
|
|
|
Menu* currentMenu;
|
|
|
|
Menu* nextMenu;
|
|
|
|
|
|
|
|
RWGame* game;
|
|
|
|
|
|
|
|
State(RWGame* game) : currentMenu(nullptr), nextMenu(nullptr), game(game) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void enter() = 0;
|
|
|
|
virtual void exit() = 0;
|
|
|
|
|
|
|
|
virtual void tick(float dt) = 0;
|
|
|
|
|
|
|
|
virtual void draw(GameRenderer* r) {
|
|
|
|
if (getCurrentMenu()) {
|
|
|
|
getCurrentMenu()->draw(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~State() {
|
|
|
|
if (getCurrentMenu()) {
|
|
|
|
delete getCurrentMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void enterMenu(Menu* menu) {
|
|
|
|
nextMenu = menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
Menu* getCurrentMenu() {
|
|
|
|
if (nextMenu) {
|
|
|
|
if (currentMenu) {
|
|
|
|
delete currentMenu;
|
|
|
|
}
|
|
|
|
currentMenu = nextMenu;
|
|
|
|
nextMenu = nullptr;
|
|
|
|
}
|
|
|
|
return currentMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void handleEvent(const SDL_Event& e);
|
|
|
|
|
|
|
|
virtual const ViewCamera& getCamera();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns false if the game world should not should
|
|
|
|
* not update while this state is active
|
|
|
|
*/
|
|
|
|
virtual bool shouldWorldUpdate();
|
|
|
|
|
|
|
|
GameWorld* getWorld();
|
|
|
|
GameWindow& getWindow();
|
|
|
|
|
2016-10-17 00:56:51 +02:00
|
|
|
bool hasExited() const {
|
|
|
|
return hasexited_;
|
2016-09-09 22:13:20 +02:00
|
|
|
}
|
|
|
|
|
2016-10-17 00:56:51 +02:00
|
|
|
private:
|
|
|
|
bool hasexited_ = false;
|
|
|
|
protected:
|
|
|
|
void done() { hasexited_ = true; }
|
2013-12-27 00:18:55 +01:00
|
|
|
};
|
|
|
|
|
2014-05-25 23:30:50 +02:00
|
|
|
#endif
|