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