-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.cpp
248 lines (195 loc) · 5.86 KB
/
panel.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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <string.h>
#include "common/file.h"
#include "kom/kom.h"
#include "kom/actor.h"
#include "kom/panel.h"
#include "kom/game.h"
#include "kom/screen.h"
#include "kom/sound.h"
using Common::File;
using Common::String;
namespace Kom {
Panel::Panel(KomEngine *vm, const char *filename) : _vm(vm),
_isEnabled(true), _isLoading(false), _suppressLoading(0),
_gotObjTime(0) {
File f;
f.open(filename);
f.seek(4);
_panelData = new byte[SCREEN_W * PANEL_H];
f.read(_panelData, SCREEN_W * PANEL_H);
f.close();
_panelBuf = new byte[SCREEN_W * PANEL_H];
memcpy(_panelBuf, _panelData, SCREEN_W * PANEL_H);
_isDirty = true;
}
Panel::~Panel() {
delete[] _panelData;
delete[] _panelBuf;
}
void Panel::clear() {
memcpy(_panelBuf, _panelData, SCREEN_W * PANEL_H);
}
void Panel::update() {
_isDirty = false;
enable(true);
clear();
// Draw texts
// FIXME - the location desc is fully centered, while the original prints it
// 4 pixels to the right.
// Actually, the original prints all text 4 pixels to the right, so we're using
// 6 as the column instead of 10 for the two bottom lines.
if (!_locationDesc.empty())
_vm->screen()->writeTextCentered(_panelBuf, _locationDesc.c_str(), 3, 31, true);
if (!_actionDesc.empty())
_vm->screen()->writeText(_panelBuf, _actionDesc.c_str(), 12, 6, 31, true);
if (!_hotspotDesc.empty())
_vm->screen()->writeText(_panelBuf, _hotspotDesc.c_str(), 22, 6, 31, true);
// FIXME: check loading in the middle of object animation
if (_isLoading)
return;
_vm->screen()->drawPanel(_panelBuf);
// Draw got and lost objects
if (_gotObjTime == 0) {
if (!_gotObjects.empty())
_gotObjTime = 24;
} else {
// Don't animate if narrator is talking
if (_vm->game()->isNarratorPlaying())
_gotObjTime = 24;
Actor *objectActor = _vm->actorMan()->getObjects();
uint16 xRatio, yRatio;
uint8 frame;
int currObj = *_gotObjects.begin();
_gotObjTime--;
// Got object
if (currObj > 0) {
// Regular object
if (currObj < 10000) {
frame = currObj + 1;
if (_gotObjTime == 16)
_vm->sound()->playSampleSFX(_vm->_swipeSample, false);
// Money
} else {
objectActor = _vm->actorMan()->getCoinage();
currObj -= 10000;
frame = currObj;
if (_gotObjTime == 16)
_vm->sound()->playSampleSFX(_vm->_cashSample, false);
}
objectActor->enable(1);
// Zoom into screen
if (_gotObjTime > 16) {
xRatio = yRatio = 0x600 - 0x600 / (24 - _gotObjTime);
objectActor->setEffect(0);
objectActor->setPos(303, 185);
objectActor->setRatio(xRatio, yRatio);
objectActor->setFrame(frame);
// Stay on screen
} else if (_gotObjTime > 8) {
objectActor->setEffect(4);
objectActor->setPos(303, 185);
objectActor->setRatio(1024, 1024);
objectActor->setFrame(frame);
// Move below screen
} else {
objectActor->setEffect(4);
objectActor->setPos(303, 185 + (8 - _gotObjTime)*(8 - _gotObjTime));
objectActor->setRatio(1024, 1024);
objectActor->setFrame(frame);
}
// Lost object
} else {
currObj = -currObj;
if (_gotObjTime == 12)
_vm->sound()->playSampleSFX(_vm->_loseItemSample, false);
// Regular object
if (currObj < 10000) {
frame = currObj + 1;
// Money
} else {
objectActor = _vm->actorMan()->getCoinage();
currObj -= 10000;
frame = currObj;
}
objectActor->enable(1);
// Move from below screen
if (_gotObjTime > 16) {
objectActor->setEffect(4);
objectActor->setPos(303, 185 + (_gotObjTime - 16)*(_gotObjTime - 16));
objectActor->setRatio(1024, 1024);
objectActor->setFrame(frame);
// Stay on screen
} else if (_gotObjTime > 8) {
objectActor->setEffect(4);
objectActor->setPos(303, 185);
objectActor->setRatio(1024, 1024);
objectActor->setFrame(frame);
// Zoom out of screen
} else {
xRatio = yRatio = 0x2710 / (24 - _gotObjTime);
objectActor->setEffect(0);
objectActor->setPos(303, 185);
objectActor->setRatio(xRatio, yRatio);
objectActor->setFrame(frame);
}
}
// Display object
objectActor->display();
objectActor->enable(0);
if (_gotObjTime == 0)
_gotObjects.pop_front();
}
}
void Panel::showLoading(bool isLoading, bool clearScreen) {
if (_suppressLoading > 0)
return;
if (_isLoading != isLoading) {
_isLoading = isLoading;
update();
_vm->screen()->drawPanel(_panelBuf);
Actor *mouse = _vm->actorMan()->getMouse();
if (_isLoading) {
mouse->enable(1);
mouse->setScope(6, 0);
mouse->setPos(303, 185);
mouse->display();
mouse->enable(0);
} else {
mouse->setPos(0, 0);
}
// The 'loading' icon should be copied directly to screen
_vm->screen()->updatePanelOnScreen(clearScreen);
}
}
void Panel::setLocationDesc(const char *desc) {
_locationDesc = desc;
_isDirty = true;
}
void Panel::setActionDesc(const char *desc) {
_actionDesc = desc;
_isDirty = true;
}
void Panel::setHotspotDesc(const char *desc) {
_hotspotDesc = desc;
_isDirty = true;
}
} // End of namespace Kom