-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainMenuState.cpp
73 lines (60 loc) · 1.52 KB
/
MainMenuState.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "MainMenuState.h"
const std::string MainMenuState::s_menuID = "MENU";
void MainMenuState::update()
{
for(int i =0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->update();
}
}
void MainMenuState::render()
{
for(int i =0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->draw();
}
}
bool MainMenuState::onEnter()
{
StateParser stateParser;
stateParser.parseState("../conf/menu.xml", s_menuID, &m_gameObjects, &m_textureIDList);
m_callbacks.push_back(0); //pushback 0 so we can start from one? This author is so dum.
m_callbacks.push_back(s_menuToPlay);
m_callbacks.push_back(s_exitFromMenu);
setCallbacks(m_callbacks);
std::cout << "entering MenuState" << std::endl;
return true;
}
void MainMenuState::setCallbacks(const std::vector<Callback>& callbacks)
{
for(int i = 0; i < m_gameObjects.size(); i++)
{
if(dynamic_cast<MenuButton*>(m_gameObjects[i]))
{
MenuButton* pButton = dynamic_cast<MenuButton*>(m_gameObjects[i]);
pButton->setCallback(callbacks[pButton->getCallbackID()]);
}
}
}
bool MainMenuState::onExit()
{
for(int i = 0; i < m_gameObjects.size(); i++)
{
m_gameObjects[i]->clean();
}
m_gameObjects.clear();
for(int i = 0; i < m_textureIDList.size(); i++)
{
TheTextureManager::instance()->clearFromTextureMap(m_textureIDList[i]);
}
std::cout << "Exiting MenuState" << std::endl;
return true;
}
void MainMenuState::s_menuToPlay()
{
TheGame::instance()->getStateMachine()->changeState(new PlayState());
}
void MainMenuState::s_exitFromMenu()
{
TheGame::instance()->quit();
}