-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuState.cpp
More file actions
204 lines (154 loc) · 5.47 KB
/
MenuState.cpp
File metadata and controls
204 lines (154 loc) · 5.47 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* MenuState.cpp
* Prototyp
*
* Created by Christian Pehle on 05.09.09.
* Copyright 2009 Orbifold. All rights reserved.
*
*/
#include "PlayState.h"
#include "MenuState.h"
#include "Game.h"
namespace Orbifold {
class Game;
class SdkTrayManager;
MenuState::MenuState():
ogre(0),
window(0),
scene(0),
tray(0),
contentSetup(false),
firstEntry(true)
{}
MenuState::~MenuState() {
if(this->instance) {
delete this->instance;
}
}
MenuState* MenuState::instance = 0;
MenuState* MenuState::getSingleton() {
if(!instance) {
instance = new MenuState();
}
return instance;
}
void MenuState::save() {}
void MenuState::restore() {}
void MenuState::initialise() {
MenuState* state = MenuState::getSingleton();
state->ogre = Ogre::Root::getSingletonPtr();
state->window = Game::getRenderWindow();
//locateResources();
Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Essential");
state->tray = new SdkTrayManager("MainMenuControls", state->window, Game::getMouse(), this);
//state->tray->showBackdrop("SdkTrays/Bands");
state->tray->getTrayContainer(TL_NONE)->hide();
createDummyScene();
loadResources();
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
setupWidgets();
state->windowResized(state->window);
}
void MenuState::shutdown() {
MenuState* state = MenuState::getSingleton();
if (state->scene) state->scene->clearScene();
if (contentSetup) state->cleanupContent();
state->contentSetup = false;
if (resourcesLoaded) state->unloadResources();
state->resourcesLoaded = false;
if (state->scene) state->ogre->destroySceneManager(state->scene);
state->scene = 0;
}
void MenuState::enter() {
MenuState* state = MenuState::getSingleton();
if (!firstEntry) {
//create dummy scene and modify controls
state->createDummyScene();
//state->tray->showBackdrop("SdkTrays/Bands");
state->tray->showAll();
} else {
state->initialise();
firstEntry = false;
}
}
void MenuState::exit() {
MenuState* state = MenuState::getSingleton();
state->tray->showBackdrop("SdkTrays/Shade");
state->tray->hideAll();
state->destroyDummyScene();
}
void MenuState::setupWidgets() {
this->tray->destroyAllWidgets();
//create main navigation tray
this->tray->showLogo(TL_RIGHT);
this->tray->createSeparator(TL_RIGHT, "LogoSep");
this->tray->createButton(TL_RIGHT, "StartStop", "Start Game");
this->tray->createButton(TL_RIGHT, "Configure", "Configure");
this->tray->createButton(TL_RIGHT, "Quit", "Quit");
// create configuration screen button tray
this->tray->createButton(TL_NONE, "Apply", "Apply Changes");
this->tray->createButton(TL_NONE, "Back", "Go Back");
// create configuration screen label and renderer menu
this->tray->createLabel(TL_NONE, "ConfigLabel", "Configuration");
this->rendererMenu = this->tray->createLongSelectMenu(TL_NONE, "RenderMenu", "Render System", 450, 240, 10);
// populate render system names
/* Ogre::StringVector rsNames;
Ogre::RenderSystemList* rsList = this->ogre->getAvailableRenderers();
for (unsigned int i = 0; i < rsList.size(); i++) {
rsNames.push_back(rsList[i]->getName());
}
this->rendererMenu->setItems(rsNames);*/
}
void MenuState::createDummyScene() {
this->window->removeAllViewports();
Ogre::SceneManager* sm = this->ogre->createSceneManager(Ogre::ST_GENERIC, "DummyScene");
Ogre::Camera* cam = sm->createCamera("DummyCamera");
Ogre::Viewport* vp = this->window->addViewport(cam);
}
void MenuState::destroyDummyScene() {
this->window->removeAllViewports();
this->ogre->destroySceneManager(this->ogre->getSceneManager("DummyScene"));
}
// Mouse / Keyboardhandling
void MenuState::setupContent(){}
void MenuState::cleanupContent(){}
void MenuState::locateResources(){}
void MenuState::loadResources(){}
void MenuState::unloadResources(){}
// A lot of stubs.
void MenuState::update() {this->tray->update();}
bool MenuState::keyPressed(const OIS::KeyEvent &evt) {return true;}
bool MenuState::keyReleased(const OIS::KeyEvent &evt) {return true;}
bool MenuState::mouseMoved(const OIS::MouseEvent &evt) {
if(this->tray->injectMouseMove(evt))
return true;
return true;
}
bool MenuState::mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID id) {
if(this->tray->injectMouseDown(evt, id))
return true;
return true;
}
bool MenuState::mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID id) {
if(this->tray->injectMouseUp(evt, id))
return true;
return true;
}
void MenuState::windowResized(Ogre::RenderWindow* rw) {}
void MenuState::windowMoved(Ogre::RenderWindow* rw) {}
bool MenuState::windowClosing(Ogre::RenderWindow* rw) {return true;}
void MenuState::windowClosed(Ogre::RenderWindow* rw) {}
void MenuState::windowFocusChange(Ogre::RenderWindow* rw) {}
void MenuState::buttonHit(SdkButton* b) {
if (b->getName() == "StartStop") {
Game::requestStateChange(PlayState::getSingleton());
} else if (b->getName() == "Quit") {
Game::stop();
} else {
;
}
}
void MenuState::yesNoDialogClosed(const Ogre::DisplayString& question, bool yesHit){;}
void MenuState::itemSelected(SelectMenu* menu){;}
void MenuState::sliderMoved(Slider* slider){;}
}