ScummVM API documentation
contain.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  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_CONTAIN_H
27 #define SAGA2_CONTAIN_H
28 
29 #include "saga2/floating.h"
30 
31 namespace Saga2 {
32 
33 // gPanel
34 // gControl
35 class ContainerView;
36 class ScrollingContainerView;
37 class ActorContainerView;
38 class ReadyContainerView;
39 class SmallContainerView;
40 class EnchantContainerView;
41 // gWindow
42 // DecoratedWindow
43 // FloatingWindow
44 class ContainerWindow;
45 class ContainerNode;
46 class ContainerManager;
47 struct ContainerAppearanceDef;
48 
49 class CMassWeightIndicator;
50 class ProtoObj;
51 
52 class GfxCompButton;
53 class GfxCompImage;
54 class GfxMultCompButton;
55 struct TilePoint;
56 
57 /* ===================================================================== *
58  Class definitions
59  * ===================================================================== */
60 
61 // The base class for all container panels
62 
63 class ContainerView : public gControl {
64 
65  friend class ContainerWindow;
66  friend class TangibleContainerWindow;
67  friend class IntangibleContainerWindow;
68 
69 protected:
70 
71  enum imageData {
72  kSelectorX = 10,
73  kSelectorY = 25
74  };
75 
76 public:
77 
78  ContainerNode &_node;
79 
80  Point16 _iconOrigin; // of the top left icon.
81  Point16 _iconSpacing; // The spacing between icons (in both X and Y)
82 
83  // The number of rows and columns of icons that can be seen
84  int16 _visibleRows,
85  _visibleCols;
86 
87  // The total number of rows, and the scroll position of the control
88  int16 _totalRows,
89  _scrollPosition;
90 
91  // Pointer to the object that this control is showing the
92  // contents of.
93  GameObject *_containerObject;
94 
95  // Mass and bulk indicators
96  int16 _totalMass,
97  _totalBulk;
98 
99  // Number of visible objects currently in the container
100  int16 _numObjects;
101 
102  // Constructor
104  gPanelList &,
105  const Rect16 &,
106  ContainerNode &nd,
107  const ContainerAppearanceDef &app,
108  AppFunc *cmd = NULL);
109 
110  // Destructor
111  ~ContainerView();
112 
113  // redraw the panel offscreen
114  virtual void drawClipped(gPort &port, const Point16 &offset, const Rect16 &clip);
115 
116  // draws the mereged object multi-item selector
117  void drawSelector(gPort &port, Point16 &pos);
118 
119  // Draw the quantity indicator below the object if quantity > 1
120  void drawQuantity(gPort &port, GameObject *item, ProtoObj *objProto, int16 x, int16 y);
121 
122  // returns true if the object is visible for this type of
123  // container.
124  virtual bool isVisible(GameObject *obj);
125 
126  // total the mass, bulk, and number of all objects in container.
127  void totalObjects();
128 
129  // Get the Nth visible object from this container.
130  ObjectID getObject(int16 slotNum);
131 
132  void setContainer(GameObject *container);
133 
134  // get the slot the point is over
135  TilePoint pickObjectSlot(const Point16 &pickPos);
136 
137  // Get the object in a slot (u/v)
138  GameObject *getObject(const TilePoint &slot);
139 
140  // Get the object that the point is over
141  GameObject *pickObject(const Point16 &pickPos);
142 
143  // Get the object ID that the point is over
144  ObjectID pickObjectID(const Point16 &pickPos);
145 
146 protected: // actions within a container
147 
148  // These are the actions when there is no Item in the mouse
149  virtual void clickOn(gPanelMessage &msg, GameObject *mObj, GameObject *cObj);
150  virtual void dblClickOn(gPanelMessage &msg, GameObject *mObj, GameObject *cObj);
151 
152  // this gets a merged item
153  void getMerged(GameObject *obj);
154 
155  // drop Physical Object into container
156  virtual void dropPhysical(gPanelMessage &msg, GameObject *mObj, GameObject *cObj, int16 num = 1);
157 
158  // Use Physical Object on other object in container
159  virtual void usePhysical(gPanelMessage &msg, GameObject *mObj, GameObject *cObj);
160 
161  // Use Concept or Psycological object in container
162  // note: only valid container use is to drop into
163  // center characters's ready container.
164  virtual void useConcept(gPanelMessage &msg, GameObject *mObj, GameObject *cObj);
165 
166  // Use Spell or Skill on other object in container or
167  // drop into center characters's ready container.
168  virtual void useSpell(gPanelMessage &msg, GameObject *mObj, GameObject *cObj);
169 
170  // Event-handling functions
171 
172  bool activate(gEventType why); // activate the control
173  void deactivate();
174 
175  virtual void pointerMove(gPanelMessage &msg);
176  virtual bool pointerHit(gPanelMessage &msg);
177  virtual void pointerRelease(gPanelMessage &msg);
178  virtual void timerTick(gPanelMessage &msg);
179 
180  void dblClick(GameObject *mouseObject, GameObject *slotObject, gPanelMessage &msg);
181 
182 private:
183  // Container manipulation functions
184  void add(ObjectID newObj);
185  void remove(ObjectID obj);
186  void swap(ObjectID newObj, ObjectID oldObj);
187 
188  // Determine if the mouse is pointing a new object, and if so,
189  // adjust the mouse text
190  void updateMouseText(Point16 &pickPos);
191  void setCursorText(GameObject *obj);
192  void setDelayedCursorText(GameObject *obj);
193 };
194 
195 // sub class for ready inventory items
196 
198 private:
199  void **_backImages; // pointers to background imagery
200  int16 _numIm;
201 
202 public:
203 
205  const Rect16 &,
206  ContainerNode &,
207  void **backgrounds,
208  int16 numRes,
209  int16 numRows,
210  int16 numCols,
211  int16 totRows,
212  AppFunc *cmd);
213 
214  // redraw the panel offscreen
215  virtual void drawClipped(gPort &port, const Point16 &offset, const Rect16 &clip);
216 
217  void setScrollOffset(int8 num);
218  void timerTick(gPanelMessage &msg);
219 };
220 
221 // sub class for enchantment container panels
222 
224 public:
226  ContainerNode &nd,
227  const ContainerAppearanceDef &app,
228  AppFunc *cmd = NULL);
229 
230  virtual void pointerMove(gPanelMessage &msg);
231  virtual bool pointerHit(gPanelMessage &msg);
232 };
233 
234 
235 // The container window is simply a floating window with an embedded
236 // container view panel and a close button control
237 
239 protected:
240  GfxCompButton *_closeCompButton; // the close button object
241  ContainerView *_view; // the container view object
242 
243 public:
245  const ContainerAppearanceDef &app,
246  const char saveas[]);
247 
248  virtual ~ContainerWindow();
249 
250  ContainerView &getView();
251  GameObject *containerObject() {
252  return getView()._containerObject;
253  }
254 
255  virtual void massBulkUpdate() {}
256 };
257 
258 // Base class for all container windows with scroll control
260 protected:
261  GfxCompButton *_scrollCompButton;
262 
263 public:
265  const ContainerAppearanceDef &app,
266  const char saveas[]);
267 
268  void scrollUp() {
269  if (_view->_scrollPosition > 0) _view->_scrollPosition--;
270  }
271 
272  void scrollDown() {
273  if (_view->_scrollPosition + _view->_visibleRows < _view->_totalRows)
274  _view->_scrollPosition++;
275  }
276 };
277 
278 // A container window for tangible containers
280 private:
281  GfxCompImage *_containerSpriteImg;
282  CMassWeightIndicator *_massWeightIndicator;
283 
284  Rect16 _objRect;
285  bool _deathFlag;
286 
287 private:
288  void setContainerSprite();
289 
290 public:
291 
293  const ContainerAppearanceDef &app);
295 
296  void drawClipped(gPort &port, const Point16 &offset, const Rect16 &clip);
297 
298  // this sets the mass and bulk gauges for physical containers
299  void massBulkUpdate();
300 };
301 
303 protected:
304  friend void setMindContainer(int index, IntangibleContainerWindow &cw);
305 private:
306  GfxMultCompButton *_mindSelectorCompButton;
307 
308 public:
309 
311 };
312 
314 protected:
315  GfxCompButton *_scrollCompButton;
316 
317 public:
319  const ContainerAppearanceDef &app);
320 };
321 
322 /* ===================================================================== *
323  ContainerAppearanceDef: A record listing container appearance info
324  * ===================================================================== */
325 
327  StaticRect defaultWindowPos; // default position of window
328  StaticRect viewRect; // position of view within window
329  StaticRect closeRect, // position of close button
330  scrollRect, // position of scrolling button
331  iconRect, // position of container icon
332  massRect; // position of mass & bulk indicator
333 
334  hResID closeResID[2], // resource ID's for close box
335  scrollResID[2]; // resource ID's for scroll indicator
336 
337  StaticPoint16 iconOrigin,
338  iconSpacing;
339  uint16 rows,
340  cols,
341  totRows;
342 };
343 
344 /* ===================================================================== *
345  ContainerNode: records the fact that a container was open for a
346  specific player
347  * ===================================================================== */
348 
349 // ContainerNode records the fact that a container was opened for a
350 // specific player
351 
352 // REM: What about the ordering of windows?
353 
355 
356  friend class ContainerManager;
357  friend class ContainerView;
358  friend class ContainerWindow;
359 
360 public:
361  enum ContainerNodeOwnerType {
362  kReadyType = 0, // This is a player ready container
363  kDeadType, // The "dead" container
364  kMentalType, // A player's mental container
365  kPhysicalType, // Physical container
366  kEnchantType // Enchantment container
367  };
368 
369  enum ContainerNodeOwners {
370  kNobody = 255 // owner = 255 means it's on the ground
371  };
372 
373  enum containerAction {
374  kActionUpdate = (1 << 0), // Refresh this window
375  kActionDelete = (1 << 1), // Delete this window
376  kActionHide = (1 << 2), // Refresh this window
377  kActionShow = (1 << 3) // Refresh this window
378  };
379 
380 private:
381  ObjectID _object; // Object being viewed
382  uint8 _type; // type of container
383  uint8 _owner; // which brother owns this container
384  Rect16 _position; // position of window
385  ContainerWindow *_window; // window, which may be NULL if hidden.
386  uint8 _action; // What action to take on container
387 public:
388  uint8 _mindType; // mindContainer type
389 
390 private:
391  // Nested structure used to archive ContainerNodes
392  struct Archive {
393  ObjectID object;
394  uint8 type;
395  uint8 owner;
396  Rect16 position;
397  uint8 mindType;
398  bool shown;
399  };
400 
401 public:
402  ContainerNode() {
403  _object = 0;
404  _type = 0;
405  _owner = 0;
406  _window = nullptr;
407  _action = 0;
408  _mindType = 0;
409  }
410  ContainerNode(ContainerManager &cl, ObjectID id, int type);
411  ~ContainerNode();
412 
413  static int32 archiveSize() {
414  return sizeof(Archive);
415  }
416 
417  void read(Common::InSaveFile *in);
418  void write(Common::MemoryWriteStreamDynamic *out);
419 
420  // Hide or show this container window.
421  void hide();
422  void show();
423  void update(); // Update container associated with this node
424 
425  // Set for lazy deletion
426  void markForDelete() {
427  _action |= kActionDelete;
428  }
429  void markForShow() {
430  _action |= kActionShow;
431  _action &= ~kActionHide;
432  }
433  void markForHide() {
434  _action |= kActionHide;
435  _action &= ~kActionShow;
436  }
437  void markForUpdate() {
438  _action |= kActionUpdate;
439  }
440 
441  // Find the address of the window and/or view
442  ContainerWindow *getWindow();
443  ContainerView *getView();
444 
445  // Access functions
446  uint8 getType() {
447  return _type;
448  }
449  uint8 getOwnerIndex() {
450  return _owner;
451  }
452  ObjectID getObject() {
453  return _object;
454  }
455  Rect16 &getPosition() {
456  return _position;
457  }
458  void setObject(ObjectID id) {
459  _object = id;
460  }
461 
462  // returns true if the object represented by the container can be
463  // accessed by the player.
464  bool isAccessable(ObjectID enactor);
465 
466  void changeOwner(int16 newOwner);
467 };
468 
469 // A list of container nodes
470 
472 public:
474 
475  enum {
476  kBufSize = 60,
477  };
478 
479  // used to ignore doubleClick when doubleClick == singleClick
480  bool _alreadyDone;
481 
482  // this will be used to determine if the cursor has been
483  // held over an object long enough to qualify for the hint to be displayed
484  bool _objTextAlarm;
485 
486  // determines if the cursor is in *A* container view
487  bool _mouseInView;
488 
489  ObjectID _lastPickedObjectID;
490 
491  // number of items to move for merged objects
492  uint16 _numPicked;
493 
494  int16 _amountIndY;
495 
496  // this will be used to hold a value of uint16 plus a -1 as a flag
497  int32 _lastPickedObjectQuantity;
498 
499  int32 _amountAccumulator;
500 
501  // merged object currently being gotten
502  GameObject *_objToGet;
503 
504  // selector image pointer
505  void *_selImage;
506 
507  // buffer for the mouse text
508  char _mouseText[kBufSize];
509 
510  ContainerManager() {
511  _alreadyDone = _objTextAlarm = _mouseInView = false;
512  _lastPickedObjectID = Nothing;
513  _numPicked = 1;
514  _amountIndY = -1;
515  _lastPickedObjectQuantity = - 1;
516  _amountAccumulator = 0;
517  _objToGet = nullptr;
518  _selImage = nullptr;
519  memset(_mouseText, 0, sizeof(_mouseText));
520  }
521 
522  void add(ContainerNode *cn) {
523  _list.push_front(cn);
524  }
525 
526  void remove(ContainerNode *cn) {
527  _list.remove(cn);
528  }
529 
530  void moveToFront(ContainerNode *cn) {
531  remove(cn);
532  add(cn);
533  }
534 
535  ContainerNode *find(ObjectID id);
536  ContainerNode *find(ObjectID id, int16 type);
537 
538  // Set which player is viewing the container windows.
539  void setPlayerNum(PlayerActorID playerNum);
540  void doDeferredActions();
541  void setUpdate(ObjectID id);
542 };
543 
544 ContainerNode *CreateContainerNode(ObjectID id, bool open = true, int16 mindType = 0);
545 ContainerNode *CreateReadyContainerNode(PlayerActorID player);
546 ContainerNode *OpenMindContainer(PlayerActorID player, int16 open, int16 type);
547 
548 /* ===================================================================== *
549  Exports
550  * ===================================================================== */
551 
552 void initContainers();
553 void cleanupContainers();
554 
555 void initContainerNodes();
556 void saveContainerNodes(Common::OutSaveFile *outS);
557 void loadContainerNodes(Common::InSaveFile *in);
558 void cleanupContainerNodes();
559 
560 extern void updateContainerWindows();
561 
562 extern APPFUNC(cmdCloseButtonFunc);
563 extern APPFUNC(cmdMindContainerFunc);
564 extern APPFUNC(cmdScrollFunc);
565 
566 } // end of namespace Saga2
567 
568 #endif
Definition: contain.h:63
Definition: objproto.h:371
Definition: contain.h:302
Definition: savefile.h:54
Definition: contain.h:279
Definition: actor.h:32
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Definition: intrface.h:293
Definition: contain.h:354
Definition: gdraw.h:178
Definition: list.h:44
Definition: button.h:198
Definition: button.h:298
Definition: memstream.h:194
Definition: tcoords.h:127
Definition: stream.h:745
Definition: rect.h:282
void push_front(const t_T &element)
Definition: list.h:135
Definition: contain.h:223
Definition: contain.h:326
Definition: contain.h:313
Definition: rect.h:42
Definition: contain.h:259
Definition: panel.h:255
Definition: objects.h:118
void remove(const t_T &val)
Definition: list.h:125
Definition: floating.h:272
Definition: panel.h:218
Definition: contain.h:197
Definition: button.h:96
Definition: rect.h:33
Definition: contain.h:471
Definition: rect.h:290
Definition: contain.h:238
Definition: panel.h:406