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/*
23 * Copyright (C) 2006-2010 - Frictional Games
24 *
25 * This file is part of Penumbra Overture.
26 */
27
28#ifndef GAME_INVENTORY_H
29#define GAME_INVENTORY_H
30
31#include "hpl1/engine/engine.h"
32
33using namespace hpl;
34
35#include "hpl1/penumbra-overture/GameTypes.h"
36
37class cInit;
39
40class cGameItemType;
43
44//--------------------------------------------
45
47public:
48 iInventoryWidget(cInit *apInit, const cRect2f &aRect, cGfxObject *apGfxObject, float afZ);
49 virtual ~iInventoryWidget() {
50 if (mpGfxObject)
51 mpDrawer->DestroyGfxObject(mpGfxObject);
52 }
53
54 virtual void Draw();
55
56 virtual void OnDraw() {}
57 virtual void OnMouseOver() {}
58 virtual void OnMouseDown(eMButton aButton) {}
59 virtual void OnMouseUp(eMButton aButton) {}
60 virtual void OnDoubleClick(eMButton aButton) {}
61 virtual void OnUpdate(float afTimeStep) {}
62 virtual void OnShortcutDown(int alNum) {}
63
64 cRect2f &GetRect() { return mRect; }
65 cGfxObject *GetGfxObject() { return mpGfxObject; }
66
67protected:
68 cInit *mpInit;
69 cGraphicsDrawer *mpDrawer;
70 cGfxObject *mpGfxObject;
71 cRect2f mRect;
72 float mfZ;
73};
74
77
78//-----------------------------------------
79
80class cInventoryItem;
81
83 friend class cInventory;
84
85public:
86 cInventorySlot(cInit *apInit, const cVector2f &avPos, bool abEquip, int alIndex);
87
88 void OnDraw();
89 void OnMouseOver();
90 void OnMouseDown(eMButton aButton);
91 void OnMouseUp(eMButton aButton);
92 void OnDoubleClick(eMButton aButton);
93 void OnUpdate(float afTimeStep);
94 void OnShortcutDown(int alNum);
95
96 cInventoryItem *GetItem() { return mpItem; }
97 void SetItem(cInventoryItem *apItem) { mpItem = apItem; }
98
99 void SetIndex(int alX) { mlIndex = alX; }
100 void SetEquip(bool abX) { mbEquip = abX; }
101
102 void SetEquipIndex(int alX) { mlEquipIndex = alX; }
103 int GetEquipIndex() { return mlEquipIndex; }
104
105private:
106 cInventoryItem *mpItem;
107 int mlIndex;
108 bool mbEquip;
109
110 int mlEquipIndex;
111
112 cGfxObject *mpGfxBack;
113
114 FontData *mpFont;
115};
116
119
120//-----------------------------------------
121
122class cGameItem;
124 friend class cInventory;
125
126public:
127 cInventoryItem(cInit *apInit);
129
130 bool Init(cGameItem *apGameItem);
131 bool InitFromFile(const tString &asFile);
132
133 void Drop();
134
135 void SetName(const tString &asName) { msName = asName; }
136 const tString &GetName() { return msName; }
137
138 void SetSubType(const tString &asSubType) { msSubType = asSubType; }
139 const tString &GetSubType() { return msSubType; }
140
141 const tWString &GetGameName() { return msGameName; }
142 const tWString &GetDescription() { return msDescription; }
143
144 const tString &GetHudModelFile() { return msHudModelFile; }
145 const tString &GetHudModelName() { return msHudModelName; }
146
147 const tString &GetEntityFile() { return msEntityFile; }
148
149 cGfxObject *GetGfxObject() { return mpGfxObject; }
150 cGfxObject *GetGfxObjectAdditive() { return mpGfxObjectAdditive; }
151
152 eGameItemType GetItemType() { return mItemType; }
153
154 bool CanBeDropped() { return mbCanBeDropped; }
155
156 bool HasCount() { return mbHasCount; }
157 int GetCount() { return mlCount; }
158 void AddCount(int alX) { mlCount += alX; }
159 void SetCount(int alX) { mlCount = alX; }
160
161private:
162 cInit *mpInit;
163 tString msName;
164 tString msSubType;
165
166 tWString msGameName;
167 tWString msDescription;
168
169 eGameItemType mItemType;
170
171 tString msEntityFile;
172
173 tString msHudModelFile;
174 tString msHudModelName;
175
176 cGfxObject *mpGfxObject;
177 cGfxObject *mpGfxObjectAdditive;
178 cGraphicsDrawer *mpDrawer;
179
180 // cInventoryItem *mpItem;
181
182 bool mbCanBeDropped;
183 bool mbHasCount;
184 int mlCount;
185};
186
188typedef tInventoryItemMap::iterator tInventoryItemMapIt;
189
190//-----------------------------------------
191
193public:
194 cInventoryBattery(cInit *apInit, const cRect2f &aRect, cGfxObject *apGfxObject, float afZ);
196
197 void OnDraw();
198 void OnMouseOver();
199 void OnUpdate(float afTimeStep);
200
201private:
202 cGfxObject *mpGfxBatteryMeter;
203 cGfxObject *mpGfxBatteryMeterBar;
204};
205
206//-----------------------------------------
207
209public:
210 cInventoryHealth(cInit *apInit, const cRect2f &aRect, cGfxObject *apGfxObject, float afZ);
212
213 void OnDraw();
214 void OnMouseOver();
215 void OnUpdate(float afTimeStep);
216
217private:
218 cGfxObject *mpGfxFine;
219 cGfxObject *mpGfxCaution;
220 cGfxObject *mpGfxDanger;
221};
222
223//-----------------------------------------
224
226public:
227 cInventoryContext(cInit *apInit);
229
230 void SetActive(bool abX);
231 bool IsActive() { return mbActive; }
232
233 void Draw();
234
235 void Update(float afTimeStep);
236
237 void OnMouseDown(eMButton aButton);
238 void OnMouseUp(eMButton aButton);
239
240 void Setup(cInventoryItem *apItem, const cVector2f &avPos);
241
242private:
243 cInit *mpInit;
244 cGraphicsDrawer *mpDrawer;
245 FontData *mpFont;
246
247 cGfxObject *mpGfxBack;
248 cGfxObject *mpGfxCorner11;
249 cGfxObject *mpGfxCorner12;
250 cGfxObject *mpGfxCorner21;
251 cGfxObject *mpGfxCorner22;
252 cGfxObject *mpGfxRight;
253 cGfxObject *mpGfxLeft;
254 cGfxObject *mpGfxTop;
255 cGfxObject *mpGfxBottom;
256
257 bool mbActive;
258
259 float mfAlpha;
260
261 tWStringVec *mpActionVec;
262
263 float mfRowStart;
264 float mfRowSize;
265 float mfColLength;
266
267 int mlSelectedRow;
268
269 cInventoryItem *mpItem;
270 cVector3f mvPos;
271 cVector2f mvSize;
272 cRect2f mRect;
273};
274
275//-----------------------------------------
276
277kSaveData_BaseClass(cInventory) {
278 kSaveData_ClassInit(cInventory) public : cContainerList<cStartPosEntity> mlstStartpos;
279
283
284 virtual iSaveObject *CreateSaveObject(cSaveObjectHandler * apSaveObjectHandler, cGame * apGame);
285 virtual int GetSaveCreatePrio();
286};
287
288//--------------------------------------------
289
290class cInventory : public iUpdateable {
291 friend class cSaveHandler;
292
293public:
294 cInventory(cInit *apInit);
295 ~cInventory();
296
297 void OnStart();
298 void Update(float afTimeStep);
299 void Reset();
300 void OnDraw();
301
302 void SetActive(bool abX);
303 bool IsActive();
304
305 float GetAlpha() { return mfAlpha; }
306
307 void AddWidget(iInventoryWidget *apWidget);
308
309 void AddItem(cGameItem *apGameItem);
310 void AddItemFromFile(const tString &asName, const tString &asFile, int alSlotIndex);
311
312 void RemoveItem(cInventoryItem *apItem);
313 cInventoryItem *GetItem(const tString &asName);
314
315 void SetMousePos(const cVector2f &avPos);
316 void AddMousePos(const cVector2f &avRel);
317
318 void SetNoteBookActive(bool abX) { mbNoteBookIsActive = abX; }
319 bool GetNoteBookActive() { return mbNoteBookIsActive; }
320
321 void OnMouseDown(eMButton aButton);
322 void OnMouseUp(eMButton aButton);
323 void OnDoubleClick(eMButton aButton);
324
325 void OnInventoryDown();
326
327 void OnShortcutDown(int alNum);
328
329 cVector2f GetMousePos() { return mvMousePos; }
330 // void SetMousePos(const cVector2f& avPos){ mvMousePos = avPos;}
331
332 void SetItemName(const tWString &asName) {
333 msItemName = asName;
334 mbDrawText = true;
335 }
336 void SetItemDesc(const tWString &asDesc) {
337 msItemDesc = asDesc;
338 mbDrawText = true;
339 }
340
341 cInventoryItem *GetCurrentItem() { return mpCurrentItem; }
342 void SetCurrentItem(cInventoryItem *apItem) { mpCurrentItem = apItem; }
343
344 cInventorySlot *GetCurrentSlot() { return mpCurrentSlot; }
345 void SetCurrentSlot(cInventorySlot *apSlot) { mpCurrentSlot = apSlot; }
346
347 void SetCurrentItemOffset(const cVector2f &avOffset) { mvCurrentItemOffset = avOffset; }
348
349 cInventorySlot *GetEquipSlot(int alIdx) { return mvEquipSlots[alIdx]; }
350
351 cInventoryContext *GetContext() { return mpContext; }
352
353 cGameItemType *GetItemType(int alIndex) { return mvItemTypes[alIndex]; }
354
355 void SetDroppedInSlot(bool abX) { mbDroppedInSlot = abX; }
356
357 void SetMessage(const tWString &asMessage);
358
359 void AddPickupCallback(const tString &asItem, const tString &asFunction);
360 void AddUseCallback(const tString &asItem, const tString &asObject, const tString &asFunction);
361 void AddCombineCallback(const tString &asItem1, const tString &asItem2, const tString &asFunction);
362
363 void RemovePickupCallback(const tString &asFunction);
364 void RemoveUseCallback(const tString &asFunction);
365 void RemoveCombineCallback(const tString &asFunction);
366
367 void ClearCallbacks();
368
369 void CheckPickupCallback(const tString &asItem);
370 bool CheckUseCallback(const tString &asItem, const tString &asObject);
371 bool CheckCombineCallback(const tString &asItem1, const tString &asItem2, int alSlotIndex);
372
373 // Global save
374 void SaveToGlobal(cInventory_GlobalSave *apSave);
375 void LoadFromGlobal(cInventory_GlobalSave *apSave);
376
377 // Save
378 iSaveData *CreateSaveData();
379
380private:
381 cInit *mpInit;
382 cGraphicsDrawer *mpDrawer;
383 cInventoryContext *mpContext;
384
385 cGfxObject *mpGfxBackground;
386
387 cGfxObject *mpBatteryMeter;
388 cGfxObject *mpBatteryMeterBar;
389
390 cGfxObject *mpHealthMan_Fine;
391 cGfxObject *mpHealthMan_Caution;
392 cGfxObject *mpHealthMan_Danger;
393 cGfxObject *mpHealthTextFrame;
394
395 cGfxObject *mpBagpack;
396
397 tGameItemTypeVec mvItemTypes;
398
399 bool mbActive;
400 float mfAlpha;
401 float mfTextAlpha;
402 eCrossHairState mLastCrossHairState;
403
404 tWString msItemName;
405 tWString msItemDesc;
406 bool mbDrawText;
407
408 bool mbDroppedInSlot;
409
410 bool mbCheckingCombineItems;
411
412 bool mbNoteBookIsActive;
413
414 FontData *mpFont;
415
416 cVector2f mvMousePos;
417
418 bool mbMessageActive;
419 tWString msMessage;
420 float mfMessageAlpha;
421 cGfxObject *mpMessageBackground;
422
423 cInventoryItem *mpCurrentItem;
424 cVector2f mvCurrentItemOffset;
425 cInventorySlot *mpCurrentSlot;
426
427 tInventoryWidgetList mlstWidgets;
428 tInventoryItemMap m_mapItems;
429 tInventorySlotList mlstSlots;
431
432 tInventoryPickupCallbackMap m_mapPickupCallbacks;
433 tInventoryUseCallbackMap m_mapUseCallbacks;
434 tInventoryCombineCallbackList mlstCombineCallbacks;
435};
436
437#endif // GAME_INVENTORY_H
Definition: str.h:59
Definition: ustr.h:57
Definition: GameItem.h:62
Definition: GameItemType.h:45
Definition: Init.h:70
Definition: SaveHandler.h:113
Definition: Inventory.h:192
Definition: Inventory.h:225
Definition: Inventory.h:208
Definition: Inventory.h:290
Definition: Inventory.h:123
Definition: Inventory.h:82
Definition: SaveHandler.h:323
Definition: font_data.h:67
Definition: Container.h:219
Definition: Game.h:91
Definition: GfxObject.h:38
Definition: GraphicsDrawer.h:77
void DestroyGfxObject(cGfxObject *apObject)
Definition: SaveGame.h:183
Definition: SaveGame.h:111
Definition: SaveGame.h:130
Definition: Updateable.h:35
Definition: Inventory.h:46
Definition: list_intern.h:54