Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / interface_v3 / inventory_manager.h
blob10ef38a9c1d1bbebbee790abf898cf903b6aea08
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef RY_INVENTORY_MANAGER_H
24 #define RY_INVENTORY_MANAGER_H
26 #include "nel/misc/cdb_leaf.h"
27 #include "dbgroup_list_sheet_text.h"
28 #include "dbgroup_list_sheet.h"
29 #include "game_share/item_infos.h"
30 #include "game_share/temp_inventory_mode.h"
31 #include "game_share/inventories.h"
32 #include "game_share/bot_chat_types.h"
34 namespace NLMISC{
35 class CCDBNodeBranch;
37 class CDBCtrlSheet;
38 class IItermInfoWaiter;
40 const uint MAX_TEMPINV_ENTRIES = INVENTORIES::NbTempInvSlots;
41 const uint MAX_BAGINV_ENTRIES = INVENTORIES::NbBagSlots;
42 const uint MAX_HANDINV_ENTRIES = 2;
43 const uint MAX_EQUIPINV_ENTRIES = 19;
44 const uint MAX_HOTBARINV_ENTRIES = INVENTORIES::NbHotbarSlots;
45 const uint MAX_ANIMALINV_ENTRIES = INVENTORIES::NbPackerSlots;
46 const uint MAX_GUILDINV_ENTRIES = INVENTORIES::NbGuildSlots;
47 const uint MAX_ROOMINV_ENTRIES = INVENTORIES::NbRoomSlots;
48 // This is the personal player inventory max (bag and animal)
49 const uint MAX_PLAYER_INV_ENTRIES = std::max(MAX_BAGINV_ENTRIES, MAX_ANIMALINV_ENTRIES);
50 // db path for the local inventory
51 #define LOCAL_INVENTORY "LOCAL:INVENTORY"
52 #define SERVER_INVENTORY "SERVER:INVENTORY"
55 // ***************************************************************************
56 /** Image of an item in the database
57 * Unavailable fields are set to NULL
58 * \author Nicolas Vizerie
59 * \author Nevrax France
60 * \date September 2003
62 class CItemImage
64 public:
65 NLMISC::CCDBNodeLeaf *Sheet;
66 NLMISC::CCDBNodeLeaf *Quality;
67 NLMISC::CCDBNodeLeaf *Quantity;
68 NLMISC::CCDBNodeLeaf *CreateTime;
69 NLMISC::CCDBNodeLeaf *Serial;
70 NLMISC::CCDBNodeLeaf *UserColor;
71 NLMISC::CCDBNodeLeaf *Price;
72 NLMISC::CCDBNodeLeaf *Weight;
73 NLMISC::CCDBNodeLeaf *NameId;
74 NLMISC::CCDBNodeLeaf *InfoVersion;
75 NLMISC::CCDBNodeLeaf *ResaleFlag;
77 public:
78 // ctor
79 CItemImage();
80 // build from a branch
81 void build(NLMISC::CCDBNodeBranch *branch);
82 uint64 getItemId() const;
83 // shortcuts to avoid NULL pointer tests
84 uint32 getSheetID() const { return (uint32) (Sheet ? Sheet->getValue32() : 0); }
85 uint16 getQuality() const { return (uint16) (Quality ? Quality->getValue16() : 0); }
86 uint16 getQuantity() const { return (uint16) (Quantity ? Quantity->getValue16() : 0); }
87 uint32 getCreateTime() const { return (uint32) (CreateTime ? CreateTime->getValue32() : 0); }
88 uint32 getSerial() const { return (uint32) (Serial ? Serial->getValue32() : 0); }
89 uint8 getUserColor() const { return (uint8) (UserColor ? UserColor->getValue16() : 0); }
90 uint32 getPrice() const { return (uint32) (Price ? Price->getValue32() : 0); }
91 uint32 getWeight() const { return (uint32) (Weight ? Weight->getValue32() : 0); }
92 uint32 getNameId() const { return (uint32) (NameId ? NameId->getValue32() : 0); }
93 uint8 getInfoVersion() const { return (uint8) (InfoVersion ? (uint8) InfoVersion->getValue8() : 0); }
94 uint8 getResaleFlag() const { return (uint8) (ResaleFlag ? (uint8) ResaleFlag->getValue8() : 0); }
95 bool getLockedByOwner() const { return (bool) (ResaleFlag ? (ResaleFlag->getValue8() == BOTCHATTYPE::ResaleKOLockedByOwner) : false); }
97 void setSheetID(uint32 si) { if (Sheet) Sheet->setValue32((sint32) si); }
98 void setQuality(uint16 quality) { if (Quality) Quality->setValue16((sint16) quality); }
99 void setQuantity(uint16 quantity) { if (Quantity) Quantity->setValue16((sint16) quantity); }
100 void setCreateTime(uint32 create_time) { if (CreateTime) CreateTime->setValue32((sint32) create_time); }
101 void setSerial(uint32 serial) { if (Serial) Serial->setValue32((sint32) serial); }
102 void setUserColor(uint8 uc) { if (UserColor) UserColor->setValue8((sint8) uc); }
103 void setPrice(uint32 price) { if (Price) Price->setValue32((sint32) price); }
104 void setWeight(uint32 wgt) { if (Weight) Weight->setValue32((sint32) wgt); }
105 void setNameId(uint32 nid) { if (NameId) NameId->setValue32((sint32) nid); }
106 void setInfoVersion(uint8 iv) { if (InfoVersion) InfoVersion->setValue8((sint8) iv); }
107 void setResaleFlag(uint8 resale) { if (ResaleFlag) ResaleFlag->setValue8(resale); }
111 // ***************************************************************************
112 /** Extra Item Info retrieved via ItemInfo system
114 class CClientItemInfo : public CItemInfos
116 public:
117 // System
118 uint16 InfoVersionFromMsg;
119 uint16 InfoVersionFromSlot;
120 // This is the InfoVersionFromSlot when last request was sent to server
121 uint16 InfoVersionSlotServerWaiting;
123 // Used to track cache age (reset on use, +1 on every save)
124 uint32 CacheCycle;
126 CClientItemInfo()
128 InfoVersionFromMsg= 0;
129 InfoVersionFromSlot= 0;
130 InfoVersionSlotServerWaiting= 0;
131 CacheCycle= 0;
134 /// Set InfoVersion from Info message (info requested by the player)
135 void readFromImpulse(const CItemInfos &itemInfo);
137 /// Set InfoVersion from a refresh message (to prevent missing a change when InfoVersion in the database has reached a complete cycle)
138 void refreshInfoVersion(uint8 infoVersion) { InfoVersionFromMsg= infoVersion; }
141 class CItemInfoCache
143 public:
144 void load(const std::string &filename);
145 void save(const std::string &filename);
146 void serial(NLMISC::IStream &s);
148 // retrieve pointer to item info or null if error
149 const CClientItemInfo *getItemInfo(uint32 serial, uint32 createTime) const;
150 const CClientItemInfo *getItemInfo(uint64 itemId) const;
152 // set/update item info in cache
153 void readFromImpulse(uint64 itemId, CItemInfos itemInfo);
154 void debugItemInfoCache() const;
156 private:
157 typedef std::map<uint64, CClientItemInfo> TItemInfoCacheMap;
158 TItemInfoCacheMap _ItemInfoCacheMap;
161 // ***************************************************************************
162 /** This manager gives direct access to inventory slots (bag, temporary inventory, hands, and equip inventory)
163 * This also give access to player money
164 * \author Nicolas Vizerie
165 * \author Nevrax France
166 * \date September 2003
168 class CInventoryManager
170 public:
171 // db path for all the inventories (without the SERVER: prefix)
172 static const std::string InventoryDBs[];
173 static const uint InventoryIndexes[];
174 static const uint NumInventories;
176 public:
177 // get the unique instance of that manager
178 static CInventoryManager *getInstance();
180 // release singleton
181 static void releaseInstance();
183 /** Init the manager. This should be done after the local database has been created,
184 * because shortcuts pointers are made to the db leaf that represents the inventory.
185 * Interface manager should also have been created
187 void init();
188 // LOCAL INVENTORY
189 // get item of bag (local inventory)
190 CItemImage &getBagItem(uint index);
191 // get temporary item (local inventory)
192 CItemImage &getTempItem(uint index);
193 // get hand item (local inventory) can be NULL (nothing in the hand)
194 CItemImage *getHandItem(uint index);
195 // get equip item (local inventory)
196 CItemImage *getEquipItem(uint index);
197 // get hotbar item (local inventory)
198 CItemImage *getHotbarItem(uint index);
199 // get hand item (local inventory)
200 CDBCtrlSheet *getHandSheet(uint index);
201 // get equip item (local inventory)
202 CDBCtrlSheet *getEquipSheet(uint index);
203 // get hotbar item (local inventory)
204 CDBCtrlSheet *getHotbarSheet(uint index);
205 // get/set money
206 uint64 getMoney() const;
207 void setMoney(uint64 value);
208 // get item of pack animal (local inventory). beastIndex ranges from 0 to MAX_INVENTORY_ANIMAL-1
209 CItemImage &getPAItem(uint beastIndex, uint index);
210 // get the item Image for the given inventory. assert if bad inventory
211 CItemImage &getLocalItem(uint inv, uint index);
213 // SERVER INVENTORY
214 // get item of bag (local inventory)
215 CItemImage &getServerBagItem(uint index);
216 const CItemImage &getServerBagItem(uint index) const;
217 // get temporary item (local inventory)
218 CItemImage &getServerTempItem(uint index);
219 const CItemImage &getServerTempItem(uint index) const;
220 // get hand item (local inventory)
221 CItemImage *getServerHandItem(uint index);
222 // get equip item (local inventory)
223 CItemImage *getServerEquipItem(uint index);
224 // get/set server money
225 uint64 getServerMoney() const;
226 void setServerMoney(uint64 value);
227 // get item of pack animal (server inventory). beastIndex ranges from 0 to MAX_INVENTORY_ANIMAL-1
228 CItemImage &getServerPAItem(uint beastIndex, uint index);
229 const CItemImage &getServerPAItem(uint beastIndex, uint index) const;
230 // get the item Image for the given inventory. assert if bad inventory
231 CItemImage &getServerItem(uint inv, uint index);
232 // get the item Image for the given slotId or NULL if bad
233 const CItemImage *getServerItem(uint slotId) const;
235 // Drag'n'Drop Management
236 enum TFrom { Slot, TextList, IconList, Nowhere };
237 void beginDrag(CDBCtrlSheet *pCS, TFrom eFromWhere);
238 void endDrag();
239 bool isDragging() { return DNDCurrentItem != NULL; }
240 // Is the dragged sheet comes from inventory list
241 bool isDraggingFromTextList() { return DNDFrom == TextList; }
242 bool isDraggingFromIconList() { return DNDFrom == IconList; }
243 bool isDraggingFromSlot() { return DNDFrom == Slot; }
244 CDBCtrlSheet *getDraggedItem() { return DNDCurrentItem; }
246 // Get from an interface object the corresponding database entry (ie: LOCAL:INVENTORY:EQUIP:4)
247 std::string getDBIndexPath(CDBCtrlSheet *);
248 // Check if an item is a 2 hand item
249 bool is2HandItem(uint32 sheetID);
250 // Check if an item is a melee weapon item
251 bool isMeleeWeaponItem(uint32 sheetID);
252 // Check if an item is a range weapon item
253 bool isRangeWeaponItem(uint32 sheetID);
254 bool isDagger(uint32 sheetID);
255 bool isSword(uint32 sheetID);
256 // Check if an item is a forage tool
257 bool isForageToolItem(uint32 sheetID);
258 // Check if an item is usable
259 bool isUsableItem(uint32 sheetID);
260 // Get the Hand item sheet
261 uint32 getRightHandItemSheet() const { return getHandItemSheet(true); }
262 uint32 getLeftHandItemSheet() const { return getHandItemSheet(false); }
263 bool isLeftHandItemCompatible(uint32 leftHandSheet, uint32 rightHandSheet, uint32 lastRightHandSheet);
266 // Bag wearing
267 // lock an item in the bag because it is weared (done on interface elements of the 2 lists (text and icons))
268 void wearBagItem(sint32 bagEntryIndex);
269 // unlock an item in the bag because it is unweared
270 void unwearBagItem(sint32 bagEntryIndex);
271 // check if an item in the bag is weared or not
272 bool isBagItemWeared(sint32 bagEntryIndex);
273 // Equip a part of the player with a bag entry (the params are path in the database)
274 // ie : bagPath = LOCAL:INVENTORY:BAG:0 and invPath = LOCAL:INVENTORY:HAND:0
275 void equip(const std::string &bagPath, const std::string &invPath);
276 // UnEquip a part of the player (same format as equip method)
277 void unequip(const std::string &invPath);
278 // auto equip an item (given by index) from the bag (return true if equipped)
279 bool autoEquip(sint bagEntryIndex, bool allowReplace);
281 void dropOrDestroyItem(CDBCtrlSheet *item, NLMISC::CBitMemStream &out, uint16 quantity);
282 // check all equipement slot and reset if they point to an invalid bag index
283 void checkIndexInBagIntegrity();
285 // Get the current bag bulk
286 static double getBranchBulk(const std::string &basePath, uint16 startItemIndex, uint16 numItems);
287 // Get the number of used and max slots
288 static void getBranchSlotCounts(const std::string &basePath, uint& nbUsedSlots, uint& nbMaxSlots );
289 // 0 bag, 1 - 6 pack animal 1 to 5, 7 temp inv
290 double getBagBulk(uint32 inventoryIndex);
291 double getMaxBagBulk(uint32 inventoryIndex);
292 double getItemBulk(uint32 sheetID);
293 // item should have :SHEET and :QUANTITY
294 bool isSpaceInAllBagsForItem(CDBCtrlSheet *item);
295 bool isSpaceInBagForItem(CDBCtrlSheet *item, uint32 quantity, uint32 bagId);
297 // ItemExtraInfo management. From each slot is a unique uint16
298 uint16 getItemSlotId(CDBCtrlSheet *ctrl);
299 uint16 getItemSlotId(const std::string &itemDb, uint slotIndex);
300 const CClientItemInfo &getItemInfo(uint slotId) const;
301 // get item info from cache
302 const CClientItemInfo *getItemInfoCache(uint32 serial, uint32 createTime) const;
303 uint getItemSheetForSlotId(uint slotId) const;
304 // get item in bag from cache
305 uint32 getBagItemSheet(sint32 bagId) const;
306 // Returns true if the item info is already in slot cache
307 bool isItemInfoAvailable(uint slotId) const;
308 // Returns true if the item info version already matches
309 bool isItemInfoUpToDate(uint slotId) const;
310 // Add a Waiter on ItemInfo (ItemHelp opening). no-op if here, but reorder (returns true if the version already matches or if waiter is NULL)
311 void addItemInfoWaiter(IItemInfoWaiter *waiter);
312 // remove a Waiter on ItemInfo (ItemHelp closing). no-op if not here. NB: no delete
313 void removeItemInfoWaiter(IItemInfoWaiter *waiter);
314 // Called on impulse
315 void onReceiveItemInfo(const CItemInfos &itemInfo);
316 void onRefreshItemInfoVersion(uint16 slotId, uint8 infoVersion);
317 void onUpdateEquipHands();
318 // Log for debug
319 void debugItemInfoWaiters();
320 void debugItemInfoCache() const;
322 void sortBag();
324 // Animal Inventories
325 // Is the inventory present? if true, it may still not be available for modification (eg: animal too far)
326 bool isInventoryPresent(INVENTORIES::TInventory invId);
327 // Is the inventory present and available for modification?
328 bool isInventoryAvailable(INVENTORIES::TInventory invId);
329 // Is the inventory empty or not present?
330 bool isInventoryEmpty (INVENTORIES::TInventory invId);
333 enum TInvType { InvBag, InvPA0, InvPA1, InvPA2, InvPA3, InvPA4, InvPA5, InvPA6, InvGuild, InvRoom, InvUnknown };
334 static TInvType invTypeFromString(const std::string &str);
336 static std::string invToDbPath(INVENTORIES::TInventory inventory);
338 // inventory and slot from slotId
339 void getSlotInvIndex(uint slotId, uint &inv, uint &index) const;
342 private:
343 // LOCAL INVENTORY
344 CItemImage Bag[MAX_BAGINV_ENTRIES];
345 CItemImage TempInv[MAX_TEMPINV_ENTRIES];
346 sint32 Hands[MAX_HANDINV_ENTRIES];
347 CDBCtrlSheet *UIHands[MAX_HANDINV_ENTRIES];
348 CDBCtrlSheet *UIHands2[MAX_HANDINV_ENTRIES];
349 CDBCtrlSheet *UIHands3[MAX_HANDINV_ENTRIES];
350 sint32 Equip[MAX_EQUIPINV_ENTRIES];
351 CDBCtrlSheet *UIEquip[MAX_EQUIPINV_ENTRIES];
352 CDBCtrlSheet *UIEquip2[MAX_EQUIPINV_ENTRIES];
353 sint32 Hotbar[MAX_HOTBARINV_ENTRIES];
354 CDBCtrlSheet *UIHotbar[MAX_HOTBARINV_ENTRIES];
355 CDBCtrlSheet *UIHotbar2[MAX_HOTBARINV_ENTRIES];
356 CDBCtrlSheet *UIHotbar3[MAX_HOTBARINV_ENTRIES];
357 NLMISC::CCDBNodeLeaf *Money;
358 CItemImage PAInv[MAX_INVENTORY_ANIMAL][MAX_ANIMALINV_ENTRIES];
359 // SERVER INVENTORY
360 CItemImage ServerBag[MAX_BAGINV_ENTRIES];
361 CItemImage ServerTempInv[MAX_TEMPINV_ENTRIES];
362 sint32 ServerHands[MAX_HANDINV_ENTRIES];
363 sint32 ServerEquip[MAX_EQUIPINV_ENTRIES];
364 sint32 ServerHotbar[MAX_EQUIPINV_ENTRIES];
365 NLMISC::CCDBNodeLeaf *ServerMoney;
366 CItemImage ServerPAInv[MAX_INVENTORY_ANIMAL][MAX_ANIMALINV_ENTRIES];
367 // Drag'n'Drop
368 TFrom DNDFrom;
369 CDBCtrlSheet *DNDCurrentItem;
371 // ItemExtraInfo management.
372 std::string _ItemInfoCacheFilename;
373 CItemInfoCache _ItemInfoCache;
374 typedef std::map<uint, CClientItemInfo> TItemInfoMap;
375 TItemInfoMap _ItemInfoMap;
376 typedef std::list<IItemInfoWaiter*> TItemInfoWaiters;
377 TItemInfoWaiters _ItemInfoWaiters;
379 // Cache to know if bag is locked or not, because of item worn
380 bool BagItemEquipped[MAX_BAGINV_ENTRIES];
382 private:
383 /// Singleton's instance
384 static CInventoryManager *_Instance;
386 // ctor
387 CInventoryManager();
388 // dtor
389 ~CInventoryManager();
391 // init an array of items from a db branch
392 void initItemArray(const std::string &dbBranchName, CItemImage *dest, uint numItems);
393 // init array of int that represents indirection to the bag
394 void initIndirection(const std::string &dbbranch, sint32 *indices, sint32 nbIndex, bool putObs = false);
396 // Get the Hand item sheet
397 uint32 getHandItemSheet( bool rightHand ) const;
399 // ItemExtraInfo management.
400 void onTradeChangeSession();
401 void onReceiveItemSheet(NLMISC::ICDBNode* node);
402 void onReceiveItemInfoSlotVersion(NLMISC::ICDBNode* node);
403 void updateItemInfoQueue();
404 void updateItemInfoWaiters(uint slotId);
405 class CItemInfoSlotVersionObs : public NLMISC::ICDBNode::IPropertyObserver
407 public:
408 virtual void update(NLMISC::ICDBNode* node);
410 class CItemSheetObs : public NLMISC::ICDBNode::IPropertyObserver
412 public:
413 virtual void update(NLMISC::ICDBNode* node);
415 class CItemInfoTradeObs : public NLMISC::ICDBNode::IPropertyObserver
417 public:
418 virtual void update(NLMISC::ICDBNode* node);
420 CItemInfoTradeObs _DBTradeInfoObs;
421 CItemInfoSlotVersionObs _DBInfoSlotVersionObs;
422 CItemSheetObs _DBItemSheetObs;
423 friend class CItemInfoTradeObs;
424 friend class CItemInfoSlotVersionObs;
425 friend class CItemSheetObs;
427 // Equipment observer
428 class CDBEquipObs : public NLMISC::ICDBNode::IPropertyObserver
430 public:
431 virtual void update(NLMISC::ICDBNode* node);
433 CDBEquipObs _DBEquipObs;
434 friend class CDBEquipObs;
436 // Bag observer for auto equipment (put only on the sheet leaf)
437 class CDBBagObs : public NLMISC::ICDBNode::IPropertyObserver
439 public:
440 virtual void update(NLMISC::ICDBNode* node);
442 CDBBagObs _DBBagObs;
444 // shortcut to access the inventory
445 inline CInventoryManager &getInventory() { return *CInventoryManager::getInstance(); }
448 // ***************************************************************************
450 * class used to manage the temporary inventory
451 * \author Matthieu 'TrapII' Besson
452 * \author Nevrax France
453 * \date August 2003
455 class CTempInvManager
458 public:
460 /// The singleton 's instance
461 static CTempInvManager* getInstance()
463 if (!_Instance)
464 _Instance = new CTempInvManager;
465 return _Instance;
468 /// Destructor
469 virtual ~CTempInvManager();
471 // release singleton
472 static void releaseInstance();
474 // Called internally by the observer on the DB
475 void update();
477 // Called internally by the type observer on the DB
478 void updateType();
480 // Called internally by the forage observer on the DB
481 void updateForageQQ( uint whichOne );
483 // Launch temp_inv waiting for some incoming sheet (reset local DB)
484 void open(TEMP_INV_MODE::TInventoryMode m);
486 // Close temporary inventory (reset local DB)
487 void close();
489 bool isOpened();
491 TEMP_INV_MODE::TInventoryMode getMode() { return _Mode; }
493 private:
495 /// Constructor
496 CTempInvManager();
498 // Database management stuff
499 class CDBObs : public NLMISC::ICDBNode::IPropertyObserver
501 public:
502 virtual void update(NLMISC::ICDBNode* node);
505 class CDBObsType : public NLMISC::ICDBNode::IPropertyObserver
507 public:
508 virtual void update(NLMISC::ICDBNode* node);
511 // Database management stuff, specialized for forage progress
512 class CDBForageQQObs : public NLMISC::ICDBNode::IPropertyObserver
514 public:
515 CDBForageQQObs() : NLMISC::ICDBNode::IPropertyObserver(), WhichOne(~0), FullValue(0.0f) {}
516 virtual void update(NLMISC::ICDBNode *node);
517 uint WhichOne;
518 float FullValue;
521 CDBObs _DBObs;
522 CDBObsType _DBObsType;
523 CDBForageQQObs _DBForageQQObs [2];
525 private:
526 /// Singleton's instance
527 static CTempInvManager* _Instance;
529 TEMP_INV_MODE::TInventoryMode _Mode;
532 // ***************************************************************************
534 * For Bag Management
535 * \author Matthieu 'TrapII' Besson
536 * \author Nevrax France
537 * \date October 2003
539 struct SSortStruct
541 CDBGroupListSheetText::CSheetChild *SheetText;
542 CDBGroupListSheet::CSheetChild *SheetIcon;
543 std::string Pos;
544 bool operator < (const SSortStruct &o) const { return Pos < o.Pos; }
547 // Helper to sort with only one way for bag and trade
548 void initStructForItemSort(std::vector<SSortStruct>&vTemp, sint32 sheetId, sint32 quality, sint32 indexInList, sint32 indexInDB);
551 // ***************************************************************************
553 * For Bag Management (shared structure between 2 lists (text and icon))
554 * \author Matthieu 'TrapII' Besson
555 * \author Nevrax France
556 * \date May 2004
558 struct SBagOptions
560 CInventoryManager::TInvType InvType;
562 NLMISC::CCDBNodeLeaf *DbFilterArmor;
563 NLMISC::CCDBNodeLeaf *DbFilterWeapon;
564 NLMISC::CCDBNodeLeaf *DbFilterTool;
565 NLMISC::CCDBNodeLeaf *DbFilterPet;
566 NLMISC::CCDBNodeLeaf *DbFilterMP;
567 NLMISC::CCDBNodeLeaf *DbFilterMissMP;
568 NLMISC::CCDBNodeLeaf *DbFilterTP;
570 bool LastDbFilterArmor;
571 bool LastDbFilterWeapon;
572 bool LastDbFilterTool;
573 bool LastDbFilterPet;
574 bool LastDbFilterMP;
575 bool LastDbFilterMissMP;
576 bool LastDbFilterTP;
578 bool SearchFilterChanged;
579 uint16 SearchQualityMin;
580 uint16 SearchQualityMax;
581 std::vector<std::string> SearchFilter;
583 // -----------------------
584 SBagOptions()
586 InvType = CInventoryManager::InvUnknown;
587 DbFilterArmor = DbFilterWeapon = DbFilterTool = DbFilterPet = DbFilterMP = DbFilterMissMP = DbFilterTP = NULL;
588 LastDbFilterArmor = LastDbFilterWeapon = LastDbFilterTool = LastDbFilterPet = LastDbFilterMP = LastDbFilterMissMP = LastDbFilterTP = false;
589 SearchFilterChanged = false;
590 SearchQualityMin = 0;
591 SearchQualityMax = 999;
594 bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
596 bool isSomethingChanged(); // From last call ?
598 bool isSearchFilterChanged() const { return SearchFilterChanged; }
599 void setSearchFilter(const std::string &s);
601 bool getFilterArmor() const
603 if (DbFilterArmor == NULL) return true;
604 return (DbFilterArmor->getValue8()!=0);
607 bool getFilterWeapon() const
609 if (DbFilterWeapon == NULL) return true;
610 return (DbFilterWeapon->getValue8()!=0);
613 bool getFilterTool() const
615 if (DbFilterTool == NULL) return true;
616 return (DbFilterTool->getValue8()!=0);
619 bool getFilterPet() const
621 if (DbFilterPet == NULL) return true;
622 return (DbFilterPet->getValue8()!=0);
625 bool getFilterMP() const
627 if (DbFilterMP == NULL) return true;
628 return (DbFilterMP->getValue8()!=0);
631 bool getFilterMissMP() const
633 if (DbFilterMissMP == NULL) return true;
634 return (DbFilterMissMP->getValue8()!=0);
637 bool getFilterTP() const
639 if (DbFilterTP == NULL) return true;
640 return (DbFilterTP->getValue8() != 0);
643 // Return true if the sheet can be displayed due to filters
644 bool canDisplay(CDBCtrlSheet *pCS) const;
648 // ***************************************************************************
650 * Special list for bag (Text list)
651 * \author Matthieu 'TrapII' Besson
652 * \author Nevrax France
653 * \date September 2003
655 class CDBGroupListSheetBag : public CDBGroupListSheetText
657 public:
658 CDBGroupListSheetBag(const TCtorParam &param)
659 : CDBGroupListSheetText(param)
663 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
664 virtual void checkCoords ();
666 //////////////////////////////////////////////////////////////////////////
668 // A child node
669 struct CSheetChildBag : public CDBGroupListSheetText::CSheetChild
671 // quality is important for ItemRequirement color
672 sint32 LastQuality;
673 CInterfaceProperty CurrentQuality;
675 virtual void updateViewText(CDBGroupListSheetText *pFather);
676 virtual bool isSheetValid(CDBGroupListSheetText *pFather); // To filter
677 virtual void init(CDBGroupListSheetText *pFather, uint index);
678 virtual bool isInvalidated(CDBGroupListSheetText *pFather);
679 virtual void update(CDBGroupListSheetText *pFather);
681 CSheetChildBag() : CSheetChild()
683 LastQuality = -1;
687 virtual CSheetChild *createSheetChild() { return new CSheetChildBag; }
688 virtual bool swapable () const {return true;}
689 virtual void onSwap (sint nDraggedSheet, sint nDroppedSheet);
690 virtual void sort();
692 CInventoryManager::TInvType getInvType() const { return _BO.InvType; }
694 // Return true if the sheet can be displayed due to filters
695 bool canDisplay(CDBCtrlSheet *pCS) { return _BO.canDisplay(pCS); }
697 void setSearchFilter(const std::string &s) { _BO.setSearchFilter(s); }
699 private:
701 SBagOptions _BO;
704 // ***************************************************************************
706 * Special list for bag (The icon list)
707 * \author Matthieu 'TrapII' Besson
708 * \author Nevrax France
709 * \date September 2003
711 class CDBGroupIconListBag : public CDBGroupListSheet
713 public:
714 CDBGroupIconListBag(const TCtorParam &param)
715 : CDBGroupListSheet(param)
719 virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
720 virtual void checkCoords ();
722 virtual CSheetChild *createSheetChild() { return new CSheetChildBag; }
723 virtual void sort();
725 CInventoryManager::TInvType getInvType() const { return _BO.InvType; }
727 // Return true if the sheet can be displayed due to filters
728 bool canDisplay(CDBCtrlSheet *pCS) const { return _BO.canDisplay(pCS); }
730 void setSearchFilter(const std::string &s) { _BO.setSearchFilter(s); }
732 //////////////////////////////////////////////////////////////////////////
734 // A child node
735 struct CSheetChildBag : public CDBGroupListSheet::CSheetChild
737 virtual bool isSheetValid(CDBGroupListSheet *pFather);
740 private:
742 SBagOptions _BO;
746 // ***************************************************************************
748 * Special list for filtering items according to the CLM (control launching modal)
749 * \author Lionel Berenguier
751 class CDBGroupListSheetFilterCLMSlot : public CDBGroupListSheet
753 public:
754 CDBGroupListSheetFilterCLMSlot (const TCtorParam &param)
755 : CDBGroupListSheet(param)
758 virtual CSheetChild *createSheetChild() { return new CSheetChildFilter; }
760 // A child node
761 struct CSheetChildFilter : public CDBGroupListSheet::CSheetChild
763 virtual bool isSheetValid(CDBGroupListSheet *pFather);
767 // ***************************************************************************
769 * Special list for filtering items which are usable
771 class CDBGroupListSheetFilterHotbarSlot : public CDBGroupListSheet
773 public:
774 CDBGroupListSheetFilterHotbarSlot (const TCtorParam &param)
775 : CDBGroupListSheet(param)
778 virtual CSheetChild *createSheetChild() { return new CSheetChildFilter; }
780 // A child node
781 struct CSheetChildFilter : public CDBGroupListSheet::CSheetChild
783 virtual bool isSheetValid(CDBGroupListSheet *pFather);
787 // ***************************************************************************
789 * Special list for filtering items which are exchangeable only
790 * \author Lionel Berenguier
792 class CDBGroupListSheetFilterExchangeable : public CDBGroupListSheet
794 public:
795 CDBGroupListSheetFilterExchangeable (const TCtorParam &param)
796 : CDBGroupListSheet(param)
799 virtual CSheetChild *createSheetChild() { return new CSheetChildFilter; }
801 // A child node
802 struct CSheetChildFilter : public CDBGroupListSheet::CSheetChild
804 virtual bool isSheetValid(CDBGroupListSheet *pFather);
807 void sort();
808 bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
810 private:
811 SBagOptions _BO;
815 // ***************************************************************************
816 // Interface Part
817 // ***************************************************************************
819 #define WIN_TEMPINV "ui:interface:temp_inventory"
820 #define VIEW_TEMPINV_TITLE "ui:interface:temp_inventory:title"
822 #define WIN_TEMPINV_TITLE_LOOT "uiTILoot"
823 #define WIN_TEMPINV_TITLE_QUARTERING "uiTIQuartering"
824 #define WIN_TEMPINV_TITLE_FORAGING "uiTIForaging"
825 #define WIN_TEMPINV_TITLE_FORAGE_RESULT "uiTIForageResult"
826 #define WIN_TEMPINV_TITLE_BAGFULL "uiTIBagFull"
827 #define WIN_TEMPINV_TITLE_CRAFT "uiTICraft"
828 #define WIN_TEMPINV_TITLE_MISSIONREWARD "uiTIMissionItem" // in fact not only for rewards
829 #define WIN_TEMPINV_TITLE_CRYSTALLIZE "uiTICrystallize"
831 #define WIN_TEMPINV_TITLE_ERROR "uiTIError"
833 #define WIN_TEMPINV_TITLE_WAIT_LOOT "uiTIWaitLoot"
834 #define WIN_TEMPINV_TITLE_WAIT_QUARTERING "uiTIWaitQuartering"
835 #define WIN_TEMPINV_TITLE_WAIT_FORAGING "uiTIWaitForaging"
836 #define WIN_TEMPINV_TITLE_WAIT_BAGFULL "uiTIWaitBagFull"
837 #define WIN_TEMPINV_TITLE_WAIT_CRAFT "uiTIWaitCraft"
838 #define WIN_TEMPINV_TITLE_WAIT_MISSIONREWARD "uiTIWaitMissionItem"
839 #define WIN_TEMPINV_TITLE_WAIT_CRYSTALLIZE "uiTIWaitCrystallize"
841 #define WIN_TEMPINV_TITLE_WAIT_ERROR "uiTIError"
843 #define LIST_BAG_TEXT "ui:interface:inventory:content:bag:iil:bag_list"
844 #define LIST_BAG_ICONS "ui:interface:inventory:content:bag:iil:bag_icons"
846 #define LIST_ROOM_TEXT "ui:interface:inv_room:content:iil:bag_list"
847 #define LIST_ROOM_ICONS "ui:interface:inv_room:content:iil:bag_icons"
849 #define LIST_GUILD_TEXT "ui:interface:inv_guild:content:iil:bag_list"
850 #define LIST_GUILD_ICONS "ui:interface:inv_guild:content:iil:bag_icons"
852 #define LIST_PA0_TEXT "ui:interface:inv_pa0:content:iil:bag_list"
853 #define LIST_PA0_ICONS "ui:interface:inv_pa0:content:iil:bag_icons"
855 #define LIST_PA1_TEXT "ui:interface:inv_pa1:content:iil:bag_list"
856 #define LIST_PA1_ICONS "ui:interface:inv_pa1:content:iil:bag_icons"
858 #define LIST_PA2_TEXT "ui:interface:inv_pa2:content:iil:bag_list"
859 #define LIST_PA2_ICONS "ui:interface:inv_pa2:content:iil:bag_icons"
861 #define LIST_PA3_TEXT "ui:interface:inv_pa3:content:iil:bag_list"
862 #define LIST_PA3_ICONS "ui:interface:inv_pa3:content:iil:bag_icons"
864 #define LIST_PA4_TEXT "ui:interface:inv_pa4:content:iil:bag_list"
865 #define LIST_PA4_ICONS "ui:interface:inv_pa4:content:iil:bag_icons"
867 #define LIST_PA5_TEXT "ui:interface:inv_pa5:content:iil:bag_list"
868 #define LIST_PA5_ICONS "ui:interface:inv_pa5:content:iil:bag_icons"
870 #define LIST_PA6_TEXT "ui:interface:inv_pa6:content:iil:bag_list"
871 #define LIST_PA6_ICONS "ui:interface:inv_pa6:content:iil:bag_icons"
873 // Theorically never used
874 #define LIST_BAG2_TEXT "ui:interface:inv_bag:content:iil:bag_list"
875 #define LIST_BAG2_ICONS "ui:interface:inv_bag:content:iil:bag_icons"
877 #define MENU_BAG_ITEM "ui:interface:item_menu_in_bag"
879 #define CTRL_HAND_RIGHT "ui:interface:gestionsets:hands:handr"
880 #define CTRL_HAND_LEFT "ui:interface:gestionsets:hands:handl"
882 #define CTRL_JEWEL_EARING_LEFT "ui:interface:inv_equip:content:equip:jewelry:earing_l"
883 #define CTRL_JEWEL_BRACELET_LEFT "ui:interface:inv_equip:content:equip:jewelry:bracelet_l"
884 #define CTRL_JEWEL_RING_LEFT "ui:interface:inv_equip:content:equip:jewelry:ring_l"
885 #define CTRL_JEWEL_ANKLET_LEFT "ui:interface:inv_equip:content:equip:jewelry:anklet_l"
886 #define CTRL_JEWEL_EARING_RIGHT "ui:interface:inv_equip:content:equip:jewelry:earing_r"
887 #define CTRL_JEWEL_BRACELET_RIGHT "ui:interface:inv_equip:content:equip:jewelry:bracelet_r"
888 #define CTRL_JEWEL_RING_RIGHT "ui:interface:inv_equip:content:equip:jewelry:ring_r"
889 #define CTRL_JEWEL_ANKLET_RIGHT "ui:interface:inv_equip:content:equip:jewelry:anklet_r"
890 #define CTRL_JEWEL_HEADDRESS "ui:interface:inv_equip:content:equip:jewelry:headdress"
891 #define CTRL_JEWEL_NECK "ui:interface:inv_equip:content:equip:jewelry:neck"
893 #define CTRL_ARMOR_HEAD "ui:interface:inv_equip:content:equip:armors:head"
894 #define CTRL_ARMOR_CHEST "ui:interface:inv_equip:content:equip:armors:chest"
895 #define CTRL_ARMOR_LEGS "ui:interface:inv_equip:content:equip:armors:legs"
896 #define CTRL_ARMOR_FEET "ui:interface:inv_equip:content:equip:armors:feet"
897 #define CTRL_ARMOR_ARMS "ui:interface:inv_equip:content:equip:armors:arms"
898 #define CTRL_ARMOR_HANDS "ui:interface:inv_equip:content:equip:armors:hands"
900 #define CTRL_HOTBAR_1 "ui:interface:inv_equip:content:equip:hotbar_c:hotbar:hotbar1"
901 #define CTRL_HOTBAR_2 "ui:interface:inv_equip:content:equip:hotbar_c:hotbar:hotbar2"
902 #define CTRL_HOTBAR_3 "ui:interface:inv_equip:content:equip:hotbar_c:hotbar:hotbar3"
903 #define CTRL_HOTBAR_4 "ui:interface:inv_equip:content:equip:hotbar_c:hotbar:hotbar4"
904 #define CTRL_HOTBAR_5 "ui:interface:inv_equip:content:equip:hotbar_c:hotbar:hotbar5"
906 #define CTRL_HAND2_RIGHT "ui:interface:inv_equip:content:equip:handr"
907 #define CTRL_HAND2_LEFT "ui:interface:inv_equip:content:equip:handl"
909 #define CTRL_JEWL2_EARING_LEFT "ui:interface:inventory:content:equip:jewelry:earing_l"
910 #define CTRL_JEWL2_BRACELET_LEFT "ui:interface:inventory:content:equip:jewelry:bracelet_l"
911 #define CTRL_JEWL2_RING_LEFT "ui:interface:inventory:content:equip:jewelry:ring_l"
912 #define CTRL_JEWL2_ANKLET_LEFT "ui:interface:inventory:content:equip:jewelry:anklet_l"
913 #define CTRL_JEWL2_EARING_RIGHT "ui:interface:inventory:content:equip:jewelry:earing_r"
914 #define CTRL_JEWL2_BRACELET_RIGHT "ui:interface:inventory:content:equip:jewelry:bracelet_r"
915 #define CTRL_JEWL2_RING_RIGHT "ui:interface:inventory:content:equip:jewelry:ring_r"
916 #define CTRL_JEWL2_ANKLET_RIGHT "ui:interface:inventory:content:equip:jewelry:anklet_r"
917 #define CTRL_JEWL2_HEADDRESS "ui:interface:inventory:content:equip:jewelry:headdress"
918 #define CTRL_JEWL2_NECK "ui:interface:inventory:content:equip:jewelry:neck"
920 #define CTRL_ARMR2_HEAD "ui:interface:inventory:content:equip:armors:head"
921 #define CTRL_ARMR2_CHEST "ui:interface:inventory:content:equip:armors:chest"
922 #define CTRL_ARMR2_LEGS "ui:interface:inventory:content:equip:armors:legs"
923 #define CTRL_ARMR2_FEET "ui:interface:inventory:content:equip:armors:feet"
924 #define CTRL_ARMR2_ARMS "ui:interface:inventory:content:equip:armors:arms"
925 #define CTRL_ARMR2_HANDS "ui:interface:inventory:content:equip:armors:hands"
927 #define CTRL_HOTBAR2_1 "ui:interface:inventory:content:equip:hotbar_c:hotbar:hotbar1"
928 #define CTRL_HOTBAR2_2 "ui:interface:inventory:content:equip:hotbar_c:hotbar:hotbar2"
929 #define CTRL_HOTBAR2_3 "ui:interface:inventory:content:equip:hotbar_c:hotbar:hotbar3"
930 #define CTRL_HOTBAR2_4 "ui:interface:inventory:content:equip:hotbar_c:hotbar:hotbar4"
931 #define CTRL_HOTBAR2_5 "ui:interface:inventory:content:equip:hotbar_c:hotbar:hotbar5"
933 #define CTRL_HAND3_RIGHT "ui:interface:inventory:content:equip:handr"
934 #define CTRL_HAND3_LEFT "ui:interface:inventory:content:equip:handl"
936 #define CTRL_HOTBAR3_1 "ui:interface:inv_hotbar:content:hotbar:hotbar1"
937 #define CTRL_HOTBAR3_2 "ui:interface:inv_hotbar:content:hotbar:hotbar2"
938 #define CTRL_HOTBAR3_3 "ui:interface:inv_hotbar:content:hotbar:hotbar3"
939 #define CTRL_HOTBAR3_4 "ui:interface:inv_hotbar:content:hotbar:hotbar4"
940 #define CTRL_HOTBAR3_5 "ui:interface:inv_hotbar:content:hotbar:hotbar5"
942 #endif // RY_INVENTORY_MANAGER_H
944 /* End of inventory_manager.h */