ScummVM API documentation
inventory.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 #ifndef LASTEXPRESS_INVENTORY_H
23 #define LASTEXPRESS_INVENTORY_H
24 
25 /*
26  Inventory entry (32 entries)
27  ----------------------------
28 
29  byte {1} - Item ID (set to 0 for "undefined" items)
30  byte {1} - Scene ID
31  byte {1} - ??
32  byte {1} - Selectable (1 if item is selectable, 0 otherwise)
33  byte {1} - Is item in inventory (set to 1 for telegram and article)
34  byte {1} - Auto selection (1 for no auto selection, 0 otherwise)
35  byte {1} - Location
36 
37 */
38 
39 #include "lastexpress/shared.h"
40 
41 #include "lastexpress/eventhandler.h"
42 
43 #include "common/events.h"
44 #include "common/serializer.h"
45 
46 namespace LastExpress {
47 
48 class LastExpressEngine;
49 class Scene;
50 
52 public:
53 
54  // Entry
56  CursorStyle cursor;
57  SceneIndex scene;
58  byte usable;
59  bool isSelectable;
60  bool inPocket;
61  bool floating;
62  ObjectLocation location;
63 
64  InventoryEntry() {
65  cursor = kCursorNormal;
66  scene = kSceneNone;
67  usable = 0;
68  isSelectable = false;
69  inPocket = false;
70  floating = true;
71  location = kObjectLocationNone;
72  }
73 
74  Common::String toString() {
75  return Common::String::format("{ %d - %d - %d - %d - %d - %d - %d }", cursor, scene, usable, isSelectable, inPocket, floating, location);
76  }
77 
78  void saveLoadWithSerializer(Common::Serializer &s) override {
79  s.syncAsByte(cursor);
80  s.syncAsByte(scene);
81  s.syncAsByte(usable);
82  s.syncAsByte(isSelectable);
83  s.syncAsByte(inPocket);
84  s.syncAsByte(floating);
85  s.syncAsByte(location);
86  }
87  };
88 
90  ~Inventory() override;
91 
92  // Inventory contents
93  void addItem(InventoryItem item);
94  void removeItem(InventoryItem item, ObjectLocation newLocation = kObjectLocationNone);
95  bool hasItem(InventoryItem item);
96  void selectItem(InventoryItem item);
97  void unselectItem();
98  InventoryItem getSelectedItem() { return _selectedItem; }
99 
100  InventoryEntry *get(InventoryItem item);
101  InventoryEntry *getSelectedEntry() { return get(_selectedItem); }
102 
103  InventoryItem getFirstExaminableItem() const;
104  void setLocationAndProcess(InventoryItem item, ObjectLocation location);
105 
106  // UI Control
107  void show();
108  void showHourGlass() const;
109  void setPortrait(InventoryItem item) const;
110  void drawEgg() const;
111  void drawBlinkingEgg(uint ticks = 1);
112 
113  // Handle inventory UI events.
114  void handleMouseEvent(const Common::Event &ev);
115 
116  // State
117  bool isMagnifierInUse() { return _useMagnifier; }
118  bool isPortraitHighlighted() { return _portraitHighlighted; }
119  bool isOpened() { return _isOpened; }
120  bool isEggHighlighted() { return _eggHightlighted; }
121 
122  // Serializable
123  void saveLoadWithSerializer(Common::Serializer &s) override;
124  void saveSelectedItem(Common::Serializer &s);
125 
131  Common::String toString();
132 
133 private:
134  LastExpressEngine *_engine;
135 
136  InventoryEntry _entries[32];
137  InventoryItem _selectedItem;
138  uint32 _highlightedItemIndex;
139 
140  uint32 _itemsShown;
141 
142  bool _showingHourGlass;
143  int16 _blinkingDirection;
144  uint16 _blinkingBrightness;
145 
146  // Flags
147  bool _useMagnifier;
148  bool _portraitHighlighted;
149  bool _isOpened;
150  bool _eggHightlighted;
151 
152  Scene *_itemScene;
153 
154  Common::Rect _menuEggRect;
155  Common::Rect _selectedItemRect;
156 
157  void init();
158 
159  void open();
160  void close();
161  void examine(InventoryItem item);
162  void drawHighlight(uint32 currentIndex, bool reset);
163  uint32 getItemIndex(uint32 currentIndex) const;
164 
165  bool isItemSceneParameter(InventoryItem item) const;
166 
167  void drawItem(CursorStyle id, uint16 x, uint16 y, int16 brighnessIndex = -1) const;
168  void blinkEgg();
169 
170  void drawSelectedItem();
171  void clearSelectedItem() const;
172 };
173 
174 } // End of namespace LastExpress
175 
176 #endif // LASTEXPRESS_INVENTORY_H
Definition: str.h:59
Definition: scene.h:195
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: lastexpress.h:69
Definition: eventhandler.h:36
Definition: rect.h:144
Definition: animation.h:45
Definition: inventory.h:51
Definition: serializer.h:79
Definition: events.h:199
Definition: inventory.h:55
Definition: serializer.h:308