-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainMenuState.cpp
More file actions
57 lines (50 loc) · 1.4 KB
/
Copy pathMainMenuState.cpp
File metadata and controls
57 lines (50 loc) · 1.4 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
#include "MainMenuState.h"
#include "MenuButton.h"
#include "StateParser.h"
#include "TextureManager.h"
const std::string MainMenuState::s_menuID = "MENU";
bool MainMenuState::OnEnter()
{
// parse the state
StateParser stateParser;
stateParser.ParseState("./res/states.txt", s_menuID, &m_gameObjects,&m_textureIDList);
m_callbacks.push_back(0); //pushback 0 callbackID start from 1
m_callbacks.push_back(MenuToPlay);
m_callbacks.push_back(ExitFromMenu);
// set the callbacks for menu items
SetCallbacks(m_callbacks);
std::cout << "entering MenuState\n";
return true;
}
bool MainMenuState::OnExit()
{
// clear the texture manager
for (int i = 0; i < m_textureIDList.size(); i++)
{
TextureManager::Instance()->ClearFromTextureMap(m_textureIDList[i]);
}
return true;
}
void MainMenuState::SetCallbacks(const std::vector<Callback>& callbacks)
{
// go through the game objects
for (int i = 0; i < m_gameObjects.size(); i++)
{
// if they are of type MenuButton then assign a callback based on the id passed in from the file
if (dynamic_cast<MenuButton*>(m_gameObjects[i]))
{
MenuButton* pButton = dynamic_cast<MenuButton*>(m_gameObjects[i]);
pButton->SetCallback(callbacks[pButton->GetCallbackID()]);
}
}
}
void MainMenuState::Update()
{
MenuState::Update();
}
void MainMenuState::Render()
{
MenuState::Render();
}
void MainMenuState::MenuToPlay(){}
void MainMenuState::ExitFromMenu(){}