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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  *
22  * Based on the original sources
23  *   Faery Tale II -- The Halls of the Dead
24  *   (c) 1993-1996 The Wyrmkeep Entertainment Co.
25  */
26 
27 #ifndef SAGA2_INTRFACE_H
28 #define SAGA2_INTRFACE_H
29 
30 #include "saga2/button.h"
31 #include "saga2/modal.h"
32 #include "saga2/player.h"
33 
34 namespace Saga2 {
35 
36 /* ===================================================================== *
37    Prototypes
38  * ===================================================================== */
39 
40 // notes: the load/unload resource functions are to be fazed out in lieu of
41 // the newer image cache object which will handle duplicate images without
42 // all the unwieldly calls
43 
44 // the appfunc helper functions will eventually be merged into an object
45 // that will handle all of the trasitive portion of the UI.
46 
47 void SetupUserControls(void);
48 void CleanupButtonImages(void);
49 void CleanupUserControls(void);
50 void SetupContainerViews(ContainerWindow *viewWindow);
51 void **loadButtonRes(hResContext *con, int16 resID, int16 numRes);
52 void **loadButtonRes(hResContext *con, int16 resID, int16 numRes, char a, char b, char c);
53 void **loadImageRes(hResContext *con, int16 resID, int16 numRes, char a, char b, char c);
54 void unloadImageRes(void **images, int16 numRes);
55 bool isIndivMode(void);
56 
57 // temp >>>
58 uint16 getPlayerActorWeightRatio(PlayerActor *player, uint16 &maxRatio, bool bReturnMaxRatio);
59 uint16 getPlayerActorBulkRatio(PlayerActor *player, uint16 &maxRatio, bool bReturnMaxRatio);
60 template< class T > inline T GetRatio(T curUnits, T maxUnits, T ratio);
61 uint16 getBulkRatio(GameObject *obj, uint16 &maxRatio, bool bReturnMaxRatio);
62 uint16 getWeightRatio(GameObject *obj, uint16 &maxRatio, bool bReturnMaxRatio);
63 void GetTotalMassBulk(GameObject *obj, uint16 &totalMass, uint16 &totalBulk);
64 
65 // appfunc helpers
66 void setIndivBtns(uint16 broNum);
67 void setTrioBtns(void);
68 void setCenterBtns(uint16 whichBrother);
69 void setControlPanelsToIndividualMode(uint16 whichBrother);
70 void setControlPanelsToTrioMode(void);
71 void setCenterBrother(uint16 whichBrother);
72 void toggleBrotherBanding(uint16 whichBrother);
73 uint16 translatePanID(uint16 ID);
74 void updateBrotherPortrait(uint16 brotherID, int16 pType);
75 void updateBrotherAggressionButton(uint16 brotherID, bool aggressive);
76 void updateBrotherBandingButton(uint16 brotherID, bool banded);
77 void updateBrotherRadioButtons(uint16 brotherID);
78 void updateReadyContainers(void);
79 void updateBrotherArmor(uint16 brotherID);
80 
81 void updateAllUserControls(void);
82 void updateBrotherControls(PlayerActorID brotherID);
83 void enableUserControls(void);
84 void disableUserControls(void);
85 
86 bool isBrotherDead(PlayerActorID brotherID);
87 
88 // update functions
89 void updateIndicators(void);
90 
91 void initUIState(void);
92 void saveUIState(Common::OutSaveFile *outS);
93 void loadUIState(Common::InSaveFile *in);
94 void cleanupUIState(void);
95 
96 //  Varargs function to write to the status line.
97 void StatusMsg(const char *msg, ...);      // frametime def
98 
99 
100 const uint32    faceGroupID     = MKTAG('F', 'A', 'C', 'E');
101 const uint32    mentGroupID     = MKTAG('C', 'O', 'N', 'T');
102 
103 
104 /* ===================================================================== *
105    Consts
106  * ===================================================================== */
107 
108 
109 /* ===================================================================== *
110    Exports
111  * ===================================================================== */
112 extern uint16   indivBrother;
113 
114 /* ===================================================================== *
115    Class forword Declarations
116  * ===================================================================== */
117 
118 class CPlaqText;
119 class CTextWindow;
120 class gTextBox;
121 class CPortrait;
122 
123 /* ===================================================================== *
124    User controls
125  * ===================================================================== */
126 
127 // control button state structure
128 struct BtnCtrlState {
129 	bool    aggress;
130 	bool    jump;
131 	bool    center;
132 	bool    banding;
133 	int16   star;
134 };
135 
136 // name resource structure
137 struct ResName {
138 	char    a;
139 	char    b;
140 	char    c;
141 	char    d;
142 };
143 
144 enum uiBrotherName {
145 	uiJulian = 0,
146 	uiPhillip,
147 	uiKevin,
148 	uiIndiv
149 };
150 
151 // compressed button resource indexes
152 const   int16   aggressResNum       = 0;
153 const   int16   jumpResNum          = 6;
154 const   int16   centerResNum        = 4;
155 const   int16   bandingResNum       = 2;
156 const   int16   menConBtnResNum     = 18;
157 const   int16   massBulkResNum      = 0;
158 const   int16   pieIndResNum        = 0;
159 const   int16   julBtnResNum        = 22;
160 const   int16   phiBtnResNum        = 24;
161 const   int16   kevBtnResNum        = 26;
162 const   int16   optBtnResNum        = 20;
163 
164 
165 
166 // standard number of images for push-buttons
167 const   int16   numBtnImages    = 2;
168 
169 // standard number of images for portraits
170 const   uint16  numPortImages   = 8;
171 
172 // number for pie indicators
173 const   uint16  numPieIndImages = 16;
174 
175 // object pointers
176 extern CPortrait *Portrait;
177 
178 /* ===================================================================== *
179    Text Gadgets
180  * ===================================================================== */
181 
182 // plaq text writing class
183 class CPlaqText : public gControl {
184 protected:
185 
186 	enum {
187 		bufSize = 128
188 	};
189 
190 
191 	char            lineBuf[bufSize]; // text to render on button
192 	textPallete     textFacePal;    // contains info about coloring for multi-depth text rendering
193 	Rect16          textRect;       // rect for the text
194 	int16           textPosition;
195 	gFont           *buttonFont;    // pointer to font for this button
196 	gFont           *oldFont;
197 
198 public:
199 
200 	CPlaqText(gPanelList &, const Rect16 &, const char *, gFont *,
201 	          int16, textPallete &, int16, AppFunc *cmd = NULL);
202 
203 	void enable(bool);
204 	void invalidate(Rect16 *unused = nullptr);
205 
206 	void draw(void);
207 	virtual void drawClipped(gPort &,
208 	                         const Point16 &,
209 	                         const Rect16 &);
210 
211 };
212 
213 
214 /* ===================================================================== *
215     CStatusLine: Status text object, child of CPlaqText
216  * ===================================================================== */
217 
218 
219 // takes a string and displays it in the status for
220 // a length of time, and then disappears
221 class CStatusLine : public CPlaqText {
222 private:
223 
224 	Alarm   waitAlarm,
225 	        minWaitAlarm;
226 
227 	struct {
228 		char    *text;
229 		uint32  frameTime;
230 	} lineQueue[12];
231 
232 	uint8       queueHead,
233 	            queueTail;
234 	bool        lineDisplayed;
235 
bump(uint8 i)236 	static uint8 bump(uint8 i) {
237 		return (i + 1) % 12;
238 	}
239 
240 public:
241 	CStatusLine(gPanelList &, const Rect16 &, const char *, gFont *,
242 	            int16, textPallete, int32, int16, AppFunc *cmd = NULL);
243 	~CStatusLine(void);
244 
245 	void setLine(char *, uint32 frameTime);
246 	void experationCheck(void);
247 
248 	void clear(void);
249 };
250 
251 
252 /* ===================================================================== *
253     Portrait control class
254  * ===================================================================== */
255 
256 enum PortraitType {
257 	kPortraitNormal,
258 	kPortraitAngry,
259 	kPortraitConfused,
260 	kPortraitOuch,
261 	kPortraitSick,
262 	kPortraitWounded,
263 	kPortraitAsleep,
264 	kPortraitDead
265 };
266 
267 class CPortrait {
268 private:
269 	PortraitType    currentState[kNumViews + 1];
270 	uint16          numButtons;
271 	uint16          _numViews;
272 	GfxMultCompButton **buttons;
273 	GfxMultCompButton *indivButton;
274 
275 	void setPortrait(uint16);
276 
277 public:
278 	// button array, number of buttons per view, num views
279 	CPortrait(GfxMultCompButton *[], GfxMultCompButton *, const uint16, uint16);
280 
281 	void ORset(uint16, PortraitType type);
282 	void set(uint16 brotherID, PortraitType type);
getCurrentState(uint16 brotherID)283 	PortraitType getCurrentState(uint16 brotherID) {
284 		return currentState[brotherID];
285 	}
286 	void getStateString(char buf[], int8 size, uint16 brotherID);
287 };
288 
289 
290 /* ===================================================================== *
291     CInterface: Class that handles indicators for the interface
292  * ===================================================================== */
293 
294 class CMassWeightIndicator {
295 private:
296 	GameObject *containerObject;
297 
298 public:
299 	static  bool bRedraw;
300 
301 private:
302 	enum {
303 		// background image coords
304 		backImageXSize  = 88,
305 		backImageYSize  = 43,
306 
307 		// pie image coords
308 		massPieXOffset  = 8,
309 		massPieYOffset  = 9,
310 		bulkPieXOffset  = 53,
311 		bulkPieYOffset  = 9,
312 		pieXSize        = 28,
313 		pieYSize        = 26
314 	};
315 
316 	// xy positions of this indicator
317 	Point16 backImagePos;
318 	Point16 massPiePos;
319 	Point16 bulkPiePos;
320 
321 	// memory for update
322 	uint16 currentMass;
323 	uint16 currentBulk;
324 
325 	// resource context pointer
326 	hResContext *containerRes;
327 
328 	// indicator images
329 	void *massBulkImag;
330 
331 	// array of pointers to images
332 	void **pieIndImag;
333 
334 	// image control buttons
335 	GfxCompImage          *pieMass;
336 	GfxCompImage          *pieBulk;
337 
338 
339 public:
340 	void invalidate(Rect16 *unused = nullptr) {
341 		pieMass->invalidate();
342 		pieBulk->invalidate();
343 	}
344 
345 	CMassWeightIndicator(gPanelList *, const Point16 &, uint16 type = 1, bool death = false);
346 	~CMassWeightIndicator(void);
347 
getMassPieDiv(void)348 	uint16 getMassPieDiv(void) {
349 		return pieMass->getMax();
350 	}
getBulkPieDiv(void)351 	uint16 getBulkPieDiv(void) {
352 		return pieBulk->getMax();
353 	}
354 
setMassPie(uint16 val)355 	void setMassPie(uint16 val) {
356 		pieMass->setCurrent(val);
357 	}
setBulkPie(uint16 val)358 	void setBulkPie(uint16 val) {
359 		pieBulk->setCurrent(val);
360 	}
361 	void recalculate(void);
362 	static void update(void);
363 };
364 
365 
366 class CManaIndicator : public GfxCompImage {
367 public:
368 
369 	// sizes of the mana star images
370 	enum startSize {
371 		star1XSize = 10,
372 		star1YSize = 9,
373 		star2XSize = 16,
374 		star2YSize = 15,
375 		star3XSize = 20,
376 		star3YSize = 19,
377 		star4XSize = 28,
378 		star4YSize = 27,
379 		star5XSize = 32,
380 		star5YSize = 31,
381 		star6XSize = 36,
382 		star6YSize = 35,
383 		star7XSize = 46,
384 		star7YSize = 45
385 	};
386 
387 	// sizes of the rings
388 	enum ringSize {
389 		ring1XSize = 8,
390 		ring1YSize = 7,
391 		ring2XSize = 12,
392 		ring2YSize = 11,
393 		ring3XSize = 16,
394 		ring3YSize = 15,
395 		ring4XSize = 22,
396 		ring4YSize = 21,
397 		ring5XSize = 26,
398 		ring5YSize = 25,
399 		ring6XSize = 32,
400 		ring6YSize = 31,
401 		ring7XSize = 40,
402 		ring7YSize = 39
403 	};
404 
405 	// area of control
406 	enum area {
407 		x       = 475,
408 		y       = 315,
409 		xSize   = 152,
410 		ySize   = 135
411 	};
412 
413 	// coordinates
414 	enum {
415 		centerX     = x + xSize / 2,
416 		centerY     = y + ySize / 2,
417 		wellXSize   = 108,
418 		wellYSize   = 123,
419 		wellX       = (xSize / 2 - wellXSize / 2) + 1,
420 		wellY       = ySize / 2 - wellYSize / 2
421 	};
422 
423 	// manas end points
424 
425 	enum manaEndCoordsBase { // based on quadrants
426 		xOffset = 9,
427 		yOffset = -10,
428 
429 		upperLeftX  = 16    + xOffset,
430 		upperLeftY  = 45    + yOffset,
431 		upperMidX   = 70    + xOffset,
432 		upperMidY   = 13    + yOffset,
433 		upperRightX = 122   + xOffset,
434 		upperRightY = 45    + yOffset,
435 		lowerLeftX  = 16    + xOffset,
436 		lowerLeftY  = 106   + yOffset,
437 		lowerMidX   = 70    + xOffset,
438 		lowerMidY   = 135   + yOffset,
439 		lowerRightX = 122   + xOffset,
440 		lowerRightY = 106   + yOffset
441 	};
442 
443 	enum manaEndCoords {
444 		redEndX         = upperLeftX,   //a // these are just dup tags
445 		redEndY         = upperLeftY,   //b
446 		orangeEndX      = upperMidX,    //c
447 		orangeEndY      = upperMidY,
448 		yellowEndX      = upperRightX,  //d
449 		yellowEndY      = upperRightY,  //b
450 		greenEndX       = lowerLeftX,   //a
451 		greenEndY       = lowerLeftY,   //e
452 		blueEndX        = lowerMidX,    //c
453 		blueEndY        = lowerMidY,
454 		violetEndX      = lowerRightX,  //d
455 		violetEndY      = lowerRightY,  //e
456 		numXYCoords     = 12,
457 		numManaTypes    = numXYCoords / 2
458 	};
459 
460 	// mana star display offset from well center
461 	enum startOffset {
462 		startOffset = 12
463 	};
464 
465 	// mana information
466 	enum manainfo {
467 		maxLevel = 200,
468 		numManaRegions = numManaTypes
469 	};
470 
471 	// resource data
472 	enum resourceInfo {
473 		numStars        = 7,
474 		numRings        = 7,
475 		starResNum      = 0,
476 		ringResNum      = 0,
477 		numManaColors   = 13
478 	};
479 
480 	// this describes a star
481 	// ... via image number and position on screen
482 	struct manaLineInfo {
483 		Point16 starPos;
484 		Point16 ringPos;
485 		uint8   starImageIndex;
486 		uint8   ringImageIndex;
487 	};
488 
489 private:
490 
491 	// resource handle
492 	hResContext     *resContext;
493 
494 	// array of image pointers
495 	void            **starImages;
496 	void            **ringImages;
497 
498 	// background image pointer
499 	void            *backImage;
500 	void            *wellImage;
501 
502 	// image maps
503 	gPixelMap   savedMap;
504 
505 	// array of manaLine infos for blitting
506 	manaLineInfo manaLines[numManaTypes];
507 
508 	// array of ring and star end positions
509 	// this is initialized via constructor
510 	Point16 starRingEndPos[numManaTypes];
511 
512 	Point16 starSizes[numStars];
513 	Point16 ringSizes[numRings];
514 
515 	// these are checks against redundent updates
516 	int32   currentMana[numManaTypes], currentBaseMana[numManaTypes];
517 protected:
518 
519 	// these do line and position calculations
520 	int16   bresLine(Point16 from, Point16 to);
521 	Point16 bresLine(Point16 from, Point16 to, int16 steps);
522 
523 	// this gets the star/ring positions and image indexes
524 	void getManaLineInfo(uint16 index, int16 manaAmount, int16 baseManaAmount, manaLineInfo *info);
525 
526 public:
527 	CManaIndicator(gPanelList &list);
528 	~CManaIndicator(void);
529 
530 	// this updates the star and ring position info
531 	bool update(PlayerActor *player);
532 
533 	// checks to see if the mana indicator needs to draw
534 	bool needUpdate(PlayerActor *player);
535 
536 	// this method provides a rect for any of the six mana regions of the control
537 	// region numbers:
538 	//  -------
539 	//  |0 1 2|
540 	//  |3 4 5|
541 	//  -------
542 	Rect16  getManaRegionRect(int8 region);
getNumManaRegions(void)543 	int     getNumManaRegions(void) {
544 		return numManaRegions;
545 	}
546 
547 	// drawing routines
548 	void draw(void);
549 	virtual void drawClipped(gPort &, const Point16 &, const Rect16 &);
550 };
551 
552 /* ===================================================================== *
553     CHealthIndicator: Health star indicator
554  * ===================================================================== */
555 
556 class CHealthIndicator {
557 private:
558 
559 	static const char *hintText;
560 
561 	enum {
562 		starFrameResNum     = 14,
563 		starFrameNum        = 1,
564 		starStart           = 0,
565 		starNum             = 23,
566 		starInitial         = 0,
567 		starLevels          = 24,
568 		numControls         = kNumViews
569 	};
570 
571 	enum {
572 		starXPos    = 572,
573 		starYPos    = 21,
574 		starXSize   = 32,
575 		starYSize   = 32,
576 		starYOffset = 150,
577 		frameXPos   = 571,
578 		frameYPos   = 20,
579 		frameXSize  = 32,
580 		frameYSize  = 32
581 	};
582 
583 	// resource handle
584 	hResContext *healthRes;
585 
586 	// buttons
587 	GfxCompImage          *starBtns[numControls];
588 	GfxCompImage          *indivStarBtn;
589 
590 	// array of pointer to the star imagery
591 	void **starImag;
592 
593 	// health star frame imagery
594 	void *starFrameImag;
595 
596 	void updateStar(GfxCompImage *starCtl, int32 bro, int32 baseVitality, int32 curVitality);
597 
598 public:
599 	uint16  starIDs[3];
600 	int16   imageIndexMemory[4];
601 
602 public:
603 
604 	CHealthIndicator(AppFunc *cmd);
605 	~CHealthIndicator(void);
606 
607 
608 	void update(void);
609 };
610 
611 
612 /* ===================================================================== *
613     Global classes
614  * ===================================================================== */
615 
616 extern CStatusLine              *StatusLine;
617 extern CMassWeightIndicator     *MassWeightIndicator;
618 extern CHealthIndicator         *HealthIndicator;
619 extern CManaIndicator           *ManaIndicator;
620 
621 } // end of namespace Saga2
622 
623 #endif
624