-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenList.cpp
More file actions
102 lines (90 loc) · 2.83 KB
/
Copy pathScreenList.cpp
File metadata and controls
102 lines (90 loc) · 2.83 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "ScreenList.h"
#include "IGameScreen.h"
#include "IMainGame.h"
namespace CGameEngine
{
ScreenList::ScreenList(IMainGame* game) : m_game(game) {} // empty
/**
* Break down the game screens on the way to closing the application
*/
ScreenList::~ScreenList()
{
destroy();
}
/**
* Return the active or current IGameScreen object
*
* @return pointer to the current IGameScreen
*/
IGameScreen* ScreenList::getCurrentScreen()
{
// if no screens (somehow), return nullptr
if(m_currentScreenIndex == SCREEN_INDEX_NO_SCREEN) { return nullptr; }
// else, return screenIndex
return m_screens[m_currentScreenIndex];
}
/**
* Advance screen index and return 'next' IGameScreen object
*
* @return pointer to the 'new' currentScreen IGameScreen
*/
IGameScreen* ScreenList::moveNext()
{
IGameScreen* currentScreen = getCurrentScreen();
if(currentScreen->getNextScreenIndex() != SCREEN_INDEX_NO_SCREEN)
{
// if next screen is set, go there
m_currentScreenIndex = currentScreen->getNextScreenIndex();
}
return getCurrentScreen();
}
/**
* Backtrack screen index and return 'previous' IGameScreen object
*
* @return pointer to the 'old' currentScreen IGameScreen
*/
IGameScreen* ScreenList::movePrevious()
{
IGameScreen* currentScreen = getCurrentScreen();
if(currentScreen->getPreviousScreenIndex() != SCREEN_INDEX_NO_SCREEN)
{
// if next screen is set, go there
m_currentScreenIndex = currentScreen->getPreviousScreenIndex();
}
return getCurrentScreen();
}
/**
* Add a created IGameScreen object to the list and inform the IMainGame object
*
* @param newScreen Created/configured IGameScreen object
*/
void ScreenList::addScreen(IGameScreen* newScreen)
{
newScreen->m_screenIndex = m_screens.size();
m_screens.push_back(newScreen);
newScreen->build();
newScreen->setParentGame(m_game);
}
/**
* Called within the deconstructor, actually deletes each IGameScreen object it holds
*/
void ScreenList::destroy()
{
for(unsigned int i = 0; i < m_screens.size(); i++)
{
if(m_screens[i] && m_screens[i] != nullptr) { delete m_screens[i]; } //[i]->destroy(); }
}
m_screens.clear();
m_currentScreenIndex = SCREEN_INDEX_NO_SCREEN;
}
/**
* Used to change a passed screen index (int) to the current screen
*
* @param nextScreen index of the screen to make active
*/
void ScreenList::setScreen(int nextScreen)
{
/// \TODO ADD VALIDATION TO ENSURE INDEX EXISTS!!!
m_currentScreenIndex = nextScreen;
}
}