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