-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathScreenManager.cpp
130 lines (108 loc) · 2.96 KB
/
ScreenManager.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
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
#include "ScreenManager.h"
#include "RenderManager.h"
#include "MessageManager.h"
#include <entityx.h>
ScreenManager::~ScreenManager()
{
while (!mScreens.empty()){
mScreens.back()->leave();
mScreens.pop_back();
}
}
void ScreenManager::init(Screen *initialScreen)
{
RenderManager::getPtr()->setFrameListener(this);
MessageManager::getPtr()->subscribe<KeyPressedEvent>(*this);
MessageManager::getPtr()->subscribe<KeyReleasedEvent>(*this);
MessageManager::getPtr()->subscribe<MouseMovedEvent>(*this);
MessageManager::getPtr()->subscribe<MousePressedEvent>(*this);
MessageManager::getPtr()->subscribe<MouseReleasedEvent>(*this);
Ogre::FontManager::getSingleton().getByName("SdkTrays/Caption")->load();
pushScreen(initialScreen);
}
void ScreenManager::pushScreen(Screen *screen)
{
if(!mScreens.empty())
mScreens.back()->pause();
mScreens.push_back(screen);
screen->enter();
}
void ScreenManager::popScreen()
{
if(!mScreens.empty()){
mScreens.back()->leave();
mScreens.pop_back();
}
if(!mScreens.empty())
mScreens.back()->resume();
}
void ScreenManager::changeScreen(Screen *screen)
{
popScreen();
pushScreen(screen);
}
bool ScreenManager::frameRenderingQueued(const Ogre::FrameEvent &evt)
{
if(!mScreens.empty()){
OgreBites::SdkTrayManager *tray = mScreens.back()->getTrayMgr();
tray->frameRenderingQueued(evt);
mScreens.back()->update(evt.timeSinceLastFrame);
}
return true;
}
void ScreenManager::resetTo(Screen *screen)
{
while (!mScreens.empty()){
mScreens.back()->leave();
mScreens.pop_back();
}
pushScreen(screen);
}
entityx::ptr<entityx::EntityManager> ScreenManager::getCurrentEntities()
{
if(!mScreens.empty()){
Screen* curr = mScreens.back();
return curr->getEntities();
}
}
void ScreenManager::update(double dt)
{
if(!mScreens.empty()){
mScreens.back()->update(dt);
}
}
void ScreenManager::receive(const KeyPressedEvent &event)
{
if(event.event.key == OIS::KC_SYSRQ)
RenderManager::getPtr()->getRenderWindow()->writeContentsToTimestampedFile("Battlecity2014_",".png");
if(!mScreens.empty()){
mScreens.back()->keyPressed(event.event);
}
}
void ScreenManager::receive(const KeyReleasedEvent &event)
{
if(!mScreens.empty()){
Screen* curr = mScreens.back();
curr->keyReleased(event.event);
}
}
void ScreenManager::receive(const MouseMovedEvent &event)
{
if(!mScreens.empty()){
Screen* curr = mScreens.back();
curr->mouseMoved(event.event);
}
}
void ScreenManager::receive(const MousePressedEvent &event)
{
if(!mScreens.empty()){
Screen* curr = mScreens.back();
curr->mousePressed(event.event, event.buttonID);
}
}
void ScreenManager::receive(const MouseReleasedEvent &event)
{
if(!mScreens.empty()){
mScreens.back()->mouseReleased(event.event, event.buttonID);
}
}