-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayManager.cpp
135 lines (120 loc) · 2.63 KB
/
DisplayManager.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
131
132
133
134
135
/*
* DisplayManager.cpp
* sfmltest1
*
* Created by Steven Hamilton on 5/07/09.
* Copyright 2009 scorch.org. All rights reserved.
*
*/
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include "Logger.h"
#include "DisplayManager.h"
#include "GameWorld.h"
#include "GfxSFML.h"
#include "UITitleScreen.h"
#include "UIEmbarkScreen.h"
#include "UIGameOverScreen.h"
#include "UIIntroScreen.h"
#include "UIMatchScreen.h"
#include "UIOptionsScreen.h"
#include "UIResultsScreen.h"
#include "Utility.h"
DisplayManager::DisplayManager(){}
DisplayManager::~DisplayManager(){}
//-----------------
//Generic Screens
//-----------------
void DisplayManager::setupScreen(screenType_t screenType)
{
switch (screenType) {
case SCREEN_EMBARK:{
screenController = new UIEmbarkScreen();
break;
}
case SCREEN_INTRO:{
screenController = new UIIntroScreen();
break;
}
case SCREEN_RESULT:{
screenController = new UIResultsScreen();
break;
}
case SCREEN_TITLE:{
screenController = new UITitleScreen();
break;
}
case SCREEN_MATCH:{
screenController = new UIMatchScreen();
break;
}
case SCREEN_GAMEOVER:{
screenController = new UIGameOverScreen();
break;
}
case SCREEN_OPTIONS:{
screenController = new UIOptionsScreen();
break;
}
default:
break;
}
//clear the screen
gfxEngine.clearScreen();
}
void DisplayManager::saveScreen()
{
previousScreen = screenController;
}
void DisplayManager::restoreScreen()
{
screenController = previousScreen;
}
void DisplayManager::drawScreen()
{
gfxEngine.clearScreen();
screenController->draw();
//render the screen
gfxEngine.renderScreen();
}
void DisplayManager::animate()
{
gfxEngine.animateProjectile();
}
void DisplayManager::deallocScreenController()
{
//deallocate screen objects.
delete screenController;
}
void DisplayManager::closeWindow()
{
DBG << "Calling close window";
gfxEngine.closeWindow();
}
bool DisplayManager::isOpen()
{
if (gfxEngine.isOpen()) return true;
else return false;
}
event_t DisplayManager::getUIEvent()
{
//get keypresses
event_t event = gfxEngine.event();
//send to processing and receive any changes.
event = screenController->process(event);
return event;
}
event_t DisplayManager::promptForEvent(std::string str)
{
MSG(str);
drawScreen();
event_t event=gfxEngine.event();
while (event==EVENT_NULL){
sf::Sleep(FRAMERATE);
//std::cout << "Waiting for event..." << std::endl;
event=gfxEngine.event();
}
return (event);
}