-
Notifications
You must be signed in to change notification settings - Fork 2
/
ScreenList.cpp
59 lines (44 loc) · 1.29 KB
/
ScreenList.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "ScreenList.h"
#include "IGameScreen.h"
#include "IMainGame.h"
namespace NeroEngine{
ScreenList::ScreenList(IMainGame* game):_game(game){
}
IGameScreen* ScreenList::moveNext(){
IGameScreen* currentScreen = getCurrent();
if (currentScreen->getNextScreenIndex()!=SCREEN_INEDX_NO_SCREEN){
_currentScreenIndex = currentScreen->getNextScreenIndex();
}
return getCurrent();
}
IGameScreen* ScreenList::movePrevious(){
IGameScreen* currentScreen = getCurrent();
if (currentScreen->getPreviousScreenIndex() != SCREEN_INEDX_NO_SCREEN){
_currentScreenIndex = currentScreen->getPreviousScreenIndex();
}
return getCurrent();
}
void ScreenList::setScreen(int nextScreen){
_currentScreenIndex = nextScreen;
}
void ScreenList::addScreen(IGameScreen* newScreen){
newScreen->_screenIndex = _screens.size();
_screens.push_back(newScreen);
newScreen->build();
newScreen->setParentGame(_game);
}
void ScreenList::destroy(){
for (int i = 0; i < _screens.size();i++){
_screens[i]->destroy();
}
_screens.resize(0);
_currentScreenIndex = SCREEN_INEDX_NO_SCREEN;
}
ScreenList::~ScreenList(){
destroy();
}
IGameScreen* ScreenList::getCurrent(){
if (_currentScreenIndex == SCREEN_INEDX_NO_SCREEN) return nullptr;
return _screens[_currentScreenIndex];
}
}