ScummVM API documentation
interface.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22// Game interface module private header file
23
24#ifndef SAGA_INTERFACE_H
25#define SAGA_INTERFACE_H
26
27#include "common/keyboard.h"
28#include "common/savefile.h"
29
30#include "saga/displayinfo.h"
31#include "saga/sprite.h"
32#include "saga/script.h"
33
34namespace Saga {
35
36enum InterfaceUpdateFlags {
37 UPDATE_MOUSEMOVE = 1,
38 UPDATE_LEFTBUTTONCLICK = 2,
39 UPDATE_RIGHTBUTTONCLICK = 4,
40 UPDATE_MOUSECLICK = UPDATE_LEFTBUTTONCLICK | UPDATE_RIGHTBUTTONCLICK,
41 UPDATE_WHEELUP = 8,
42 UPDATE_WHEELDOWN = 16
43};
44
45#define CONVERSE_MAX_TEXTS 64
46#define CONVERSE_MAX_WORK_STRING 256
47
48#define ITE_INVENTORY_SIZE 24
49
50#define VERB_STRLIMIT 32
51
52#define STATUS_TEXT_LEN 128
53#define STATUS_TEXT_INPUT_MAX 256
54
55#define RID_IHNM_BOSS_SCREEN 19 // not in demo
56#define RID_ITE_TYCHO_MAP 1686
57#define RID_ITE_SPR_CROSSHAIR (73 + 9)
58#define TIMETOSAVE (1000000 * 60 * 30) // 30 minutes
59#define TIMETOBLINK_ITE (1000000 * 1)
60#define TIMETOBLINK_IHNM (1000000 / 10)
61
62// Converse-specific stuff
63
64enum PanelModes {
65 kPanelNull,
66 kPanelMain,
67 kPanelOption,
68 kPanelSave, //ex- kPanelTextBox,
69 kPanelQuit,
70 kPanelError,
71 kPanelLoad,
72 kPanelConverse,
73 kPanelProtect,
74 kPanelPlacard,
75 kPanelMap,
76 kPanelSceneSubstitute,
77 kPanelChapterSelection,
78 kPanelCutaway,
79 kPanelVideo,
80 kPanelBoss
81// kPanelInventory
82};
83
84enum FadeModes {
85 kNoFade = 0,
86 kFadeIn,
87 kFadeOut
88};
89
91 int x;
92 int y;
93 ByteArray image;
94 int imageWidth;
95 int imageHeight;
96
97 PanelButton *currentButton;
98 int buttonsCount;
99 PanelButton *buttons;
100 SpriteList sprites;
101
103 x = y = 0;
104 imageWidth = imageHeight = 0;
105 currentButton = NULL;
106 buttonsCount = 0;
107 buttons = NULL;
108 }
109
110 PanelButton *getButton(int index) {
111 if ((index >= 0) && (index < buttonsCount)) {
112 return &buttons[index];
113 }
114 return NULL;
115 }
116
117 void getRect(Rect &rect) {
118 rect.left = x;
119 rect.top = y;
120 rect.setWidth(imageWidth);
121 rect.setHeight(imageHeight);
122 }
123
124 void calcPanelButtonRect(const PanelButton* panelButton, Rect &rect) {
125 rect.left = x + panelButton->xOffset;
126 rect.right = rect.left + panelButton->width;
127 rect.top = y + panelButton->yOffset;
128 rect.bottom = rect.top + panelButton->height;
129 }
130
131 PanelButton *hitTest(const Point& mousePoint, int buttonType) {
132 PanelButton *panelButton;
133 Rect rect;
134 int i;
135 for (i = 0; i < buttonsCount; i++) {
136 panelButton = &buttons[i];
137 if (panelButton != NULL) {
138 if ((panelButton->type & buttonType) > 0) {
139 calcPanelButtonRect(panelButton, rect);
140 if (rect.contains(mousePoint)) {
141 return panelButton;
142 }
143 }
144 }
145 }
146 return NULL;
147 }
148
149 void zeroAllButtonState() {
150 int i;
151 for (i = 0; i < buttonsCount; i++) {
152 buttons[i].state = 0;
153 }
154 }
155
156
157};
158
159struct Converse {
161 int strId;
162 int stringNum;
163 int textNum;
164 int replyId;
165 int replyFlags;
166 int replyBit;
167};
168
169
170enum StatusTextInputState {
171 kStatusTextInputFirstRun,
172 kStatusTextInputEntered,
173 kStatusTextInputAborted
174};
175
177public:
179 ~Interface();
180
181 int activate();
182 int deactivate();
183 void setSaveReminderState(int state) {
184 _saveReminderState = state;
185 draw();
186 }
187 int getSaveReminderState() {
188 return _saveReminderState;
189 }
190 bool isActive() { return _active; }
191 void setMode(int mode);
192 int getMode() const { return _panelMode; }
193 void setFadeMode(int fadeMode) {
194 _fadeMode = fadeMode;
195 draw();
196 }
197 int getFadeMode() const {
198 return _fadeMode;
199 }
200 void rememberMode();
201 void restoreMode(bool draw_ = true);
202 bool isInMainMode() { return _inMainMode; }
203 void setStatusText(const char *text, int statusColor = -1);
204 void loadScenePortraits(int resourceId);
205 void setLeftPortrait(int portrait) {
206 _leftPortrait = portrait;
207 draw();
208 }
209 void setRightPortrait(int portrait) {
210 _rightPortrait = portrait;
211 draw();
212 }
213 void setPortraitBgColor(int red, int green, int blue) {
214 _portraitBgColor.red = red;
215 _portraitBgColor.green = green;
216 _portraitBgColor.blue = blue;
217 }
218
219 void draw();
220 void drawOption();
221 void drawQuit();
222 void drawLoad();
223 void drawSave();
224 void drawProtect();
225 void update(const Point& mousePoint, int updateFlag);
226 void drawStatusBar();
227 void setVerbState(int verb, int state);
228
229 bool processAscii(Common::KeyState keystate, Common::CustomEventType customType);
230
231 void keyBoss();
232 void keyBossExit();
233
234 void disableAbortSpeeches(bool d) { _disableAbortSpeeches = d; }
235
236 static void saveReminderCallback(void *refCon);
237 void updateSaveReminder();
238
239 bool _textInput;
240
241 bool _statusTextInput;
242 StatusTextInputState _statusTextInputState;
243 char _statusTextInputString[STATUS_TEXT_INPUT_MAX];
244 void enterStatusString() {
245 _statusTextInput = true;
246 _statusTextInputPos = 0;
247 _statusTextInputString[0] = 0;
248 setStatusText(_statusTextInputString);
249 }
250
251private:
252 void drawInventory();
253 void updateInventory(int pos);
254 void inventoryChangePos(int chg);
255 void inventorySetPos(int key);
256
257public:
258 void refreshInventory() {
259 updateInventory(_inventoryCount);
260 draw();
261 }
262 void addToInventory(int objectId);
263 void removeFromInventory(int objectId);
264 void clearInventory();
265 int inventoryItemPosition(int objectId);
266 int getInventoryContentByPanelButton(PanelButton * panelButton) {
267 int cell = _inventoryStart + panelButton->id;
268 if (cell >= _inventoryCount) {
269 return 0;
270 }
271 return _inventory[cell];
272 }
273
274 PanelButton *inventoryHitTest(const Point& mousePoint) {
275 return _mainPanel.hitTest(mousePoint, kPanelButtonInventory);
276 }
277 PanelButton *verbHitTest(const Point& mousePoint){
278 return _mainPanel.hitTest(mousePoint, kPanelButtonVerb);
279 }
280 void saveState(Common::OutSaveFile *out);
281 void loadState(Common::InSaveFile *in);
282
283 void mapPanelDrawCrossHair();
284
285 int32 getProtectHash() { return _protectHash; }
286
287 void resetSaveReminder();
288
289private:
290 void handleMainUpdate(const Point& mousePoint); // main panel update
291 void handleMainClick(const Point& mousePoint); // main panel click
292
293 PanelButton *converseHitTest(const Point& mousePoint) {
294 return _conversePanel.hitTest(mousePoint, kPanelAllButtons);
295 }
296 void handleConverseUpdate(const Point& mousePoint); // converse panel update
297 void handleConverseClick(const Point& mousePoint); // converse panel click
298
299 PanelButton *optionHitTest(const Point& mousePoint) {
300 return _optionPanel.hitTest(mousePoint, kPanelButtonOptionSaveFiles | kPanelButtonOption | kPanelButtonOptionSlider);
301 }
302 void handleOptionUpdate(const Point& mousePoint); // option panel update
303 void handleOptionClick(const Point& mousePoint); // option panel click
304
305 PanelButton *quitHitTest(const Point& mousePoint) {
306 return _quitPanel.hitTest(mousePoint, kPanelAllButtons);
307 }
308 void handleQuitUpdate(const Point& mousePoint); // quit panel update
309 void handleQuitClick(const Point& mousePoint); // quit panel click
310
311 PanelButton *loadHitTest(const Point& mousePoint) {
312 return _loadPanel.hitTest(mousePoint, kPanelAllButtons);
313 }
314 void handleLoadUpdate(const Point& mousePoint); // load panel update
315 void handleLoadClick(const Point& mousePoint); // load panel click
316
317 PanelButton *saveHitTest(const Point& mousePoint) {
318 return _savePanel.hitTest(mousePoint, kPanelAllButtons);
319 }
320 void handleSaveUpdate(const Point& mousePoint); // save panel update
321 void handleSaveClick(const Point& mousePoint); // save panel click
322
323 void handleChapterSelectionUpdate(const Point& mousePoint);
324 void handleChapterSelectionClick(const Point& mousePoint);
325
326 void mapPanelShow();
327 void mapPanelClean();
328
329 void lockMode() { _lockedMode = _panelMode; }
330 void unlockMode() { _panelMode = _lockedMode; }
331
332 void setOption(PanelButton *panelButton);
333 void setQuit(PanelButton *panelButton);
334 void setLoad(PanelButton *panelButton);
335 void setSave(PanelButton *panelButton);
336
337 void drawTextInput(InterfacePanel *panel, PanelButton *panelButton);
338 void drawPanelText(InterfacePanel *panel, PanelButton *panelButton);
339 void drawPanelButtonText(InterfacePanel *panel, PanelButton *panelButton, int spritenum = 0);
340 enum ButtonKind {
341 kButton,
342 kSlider,
343 kEdit
344 };
345 void drawButtonBox(const Rect &rect, ButtonKind kind, bool down);
346 void drawPanelButtonArrow(InterfacePanel *panel, PanelButton *panelButton);
347 void drawVerbPanelText(PanelButton *panelButton, KnownColor textKnownColor, KnownColor textShadowKnownColor);
348 void drawVerbPanel(PanelButton* panelButton);
349 void calcOptionSaveSlider();
350 bool processTextInput(Common::KeyState keystate);
351 void processStatusTextInput(Common::KeyState keystate);
352
353public:
354 void converseClear();
355 bool converseAddText(const char *text, int strId, int replyId, byte replyFlags, int replyBit);
356 void converseDisplayText();
357 void converseSetTextLines(int row);
358 void converseChangePos(int chg);
359 void converseSetPos(int key);
360
361private:
362 void converseDisplayTextLines();
363 PanelButton *getPanelButtonByVerbType(int verb) {
364 if ((verb < 0) || (verb >= kVerbTypeIdsMax)) {
365 error("Interface::getPanelButtonByVerbType wrong verb");
366 }
367 return _verbTypeToPanelButton[verb];
368 }
369
370 void validateOptionButtons() {
371 if (!_vm->isSaveListFull() && (_optionSaveFileTitleNumber == 0) && (_optionPanel.currentButton != NULL)) {
372 if (_optionPanel.currentButton->id == kTextLoad) {
373 _optionPanel.currentButton = NULL;
374 }
375 }
376 }
377 void validateSaveButtons() {
378 if ((_textInputStringLength == 0) && (_savePanel.currentButton != NULL)) {
379 if (_savePanel.currentButton->id == kTextSave) {
380 _savePanel.currentButton = NULL;
381 }
382 }
383 }
384
385public:
386 SpriteList _defPortraits;
387 PalEntry _portraitBgColor;
388
389private:
390 SagaEngine *_vm;
391
392 ResourceContext *_interfaceContext;
393 InterfacePanel _mainPanel;
394 PanelButton *_inventoryUpButton;
395 PanelButton *_inventoryDownButton;
396 InterfacePanel _conversePanel;
397 PanelButton *_converseUpButton;
398 PanelButton *_converseDownButton;
399 SpriteList _scenePortraits;
400 PanelButton *_verbTypeToPanelButton[kVerbTypeIdsMax];
401 InterfacePanel _optionPanel;
402 PanelButton * _optionSaveFileSlider;
403 PanelButton * _optionSaveFilePanel;
404 InterfacePanel _quitPanel;
405 InterfacePanel _loadPanel;
406 InterfacePanel _savePanel;
407 PanelButton * _saveEdit;
408 InterfacePanel _protectPanel;
409 PanelButton * _protectEdit;
410
411 bool _disableAbortSpeeches;
412
413 int _saveReminderState;
414 bool _active;
415 int _fadeMode;
416 int _panelMode;
417 int _savedMode;
418 int _lockedMode;
419 int _bossMode;
420 bool _inMainMode;
421 char _statusText[STATUS_TEXT_LEN];
422 int _statusOnceColor;
423 int _leftPortrait;
424 int _rightPortrait;
425
426 Point _lastMousePoint;
427
428 Common::Array<uint16> _inventory;
429 int _inventoryStart;
430 int _inventoryEnd;
431 int _inventoryPos;
432 int _inventoryBox;
433 int _inventoryCount;
434
435 char _converseWorkString[CONVERSE_MAX_WORK_STRING];
436 Converse _converseText[CONVERSE_MAX_TEXTS];
437 int _converseTextCount;
438 int _converseStrCount;
439 int _converseStartPos;
440 int _converseEndPos;
441 int _conversePos;
442
443 uint _optionSaveFileTop;
444 uint _optionSaveFileTitleNumber;
445 int16 _optionSaveFileMouseOff;
446 Rect _optionSaveRectTop;
447 Rect _optionSaveRectSlider;
448 Rect _optionSaveRectBottom;
449
450 char _textInputString[SAVE_TITLE_SIZE];
451 uint _textInputStringLength;
452 uint _textInputPos;
453 uint _textInputMaxWidth;
454
455 uint _statusTextInputPos;
456
457 PalEntry _mapSavedPal[PAL_ENTRIES];
458 bool _mapPanelCrossHairState;
459
460 int32 _protectHash;
461};
462
463} // End of namespace Saga
464
465#endif
Definition: savefile.h:54
Definition: stream.h:745
Definition: saga.h:464
Definition: interface.h:176
Definition: resource.h:105
Definition: saga.h:497
uint32 CustomEventType
Definition: events.h:212
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: actor.h:34
Definition: keyboard.h:294
Definition: rect.h:144
Definition: rect.h:536
Definition: interface.h:159
Definition: interface.h:90
Definition: gfx.h:81
Definition: displayinfo.h:29