-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChapterController.h
165 lines (154 loc) · 2.89 KB
/
ChapterController.h
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
#pragma once
#include <CEGUI/CEGUISchemeManager.h>
#include <CEGUI/CEGUIWindowManager.h>
#include <CEGUI/CEGUIWindow.h>
#include <CEGUI/CEGUI.h>
#include <vector>
using namespace std;
//9
#define MAX_CHAPTERS 8
#define SIMPLE_TEST
class ChapterController
{
public:
ChapterController()
{
curChapter=0;
busy=0;
init=false;
}
~ChapterController()
{
}
void setPrevNextWindows(CEGUI::Window* prev,CEGUI::Window* next)
{
nextButton=next;
prevButton=prev;
}
void pushBackChapter(CEGUI::Window* win,String map)
{
chapterWindows.push_back(win);
chapterMaps.push_back(map);
}
void step(Real dt)
{
#ifndef SIMPLE_TEST
busy-=dt;
if (busy<0)
{
busy=0;
if (nextImage!=curImage)
{
LogManager::getSingleton().logMessage("Chapter changed!!!");
curImage->hide();
curImage=nextImage;
curImage->show();
}
}
if ((nextImage!=curImage))
{
CEGUI::URect ar = curImage->getArea();
CEGUI::UVector2 sz = ar.getSize();
sz=sz*CEGUI::UVector2(CEGUI::UDim(1,0),CEGUI::UDim(1-dt,0));
CEGUI::URect ne=CEGUI::URect(ar.getPosition(),ar.getPosition()+sz);
curImage->setArea(ne);
//curImage->setSize(CEGUI::UVector2(size.d_x,size.d_y));//*CEGUI::UDim(busy,busy)));
//nextImage->setSize(CEGUI::UVector2(size.d_x,size.d_y));//-size.d_y*CEGUI::UDim(busy,busy)));
}
#endif
}
String getMapToLoad()
{
return chapterMaps[curChapter];
}
void finalize()
{
vector<CEGUI::Window*>::iterator i;
for (i=chapterWindows.begin();i!=chapterWindows.end();i++)
(*i)->hide();
curImage=chapterWindows[0];
nextImage=curImage;
curImage->show();
init=true;
}
void checkNoNext()
{
if (curChapter==MAX_CHAPTERS)
{
nextButton->hide();
}
else
{
nextButton->show();
}
}
void checkNoPrev()
{
if (!curChapter)
{
prevButton->hide();
}
else
{
prevButton->show();
}
}
bool getBusy()
{
return busy!=0;
}
void nextChapter()
{
#ifdef SIMPLE_TEST
curImage->hide();
curChapter++;
if (curChapter>MAX_CHAPTERS)
curChapter=MAX_CHAPTERS;
checkNoNext();
checkNoPrev();
curImage=chapterWindows[curChapter];
curImage->show();
#else
busy=1.0f;
curChapter++;
if (curChapter>MAX_CHAPTERS)
curChapter=MAX_CHAPTERS;
checkNoNext();
checkNoPrev();
nextImage=chapterWindows[curChapter];
#endif
}
void prevChapter()
{
#ifdef SIMPLE_TEST
curImage->hide();
curChapter--;
if (curChapter<0)
curChapter=0;
checkNoPrev();
checkNoNext();
curImage=chapterWindows[curChapter];
curImage->show();
#else
busy=1.0f;
curChapter--;
if (curChapter<0)
curChapter=0;
checkNoPrev();
checkNoNext();
nextImage=chapterWindows[curChapter];
size=curImage->getSize();
#endif
}
private:
bool init;
Real busy;
CEGUI::UVector2 size;
int curChapter;
CEGUI::Window* nextButton;
CEGUI::Window* prevButton;
CEGUI::Window* curImage;
CEGUI::Window* nextImage;
vector<CEGUI::Window*> chapterWindows;
vector<String> chapterMaps;
};