Added spawnCrystalItem
[ryzomcore.git] / ryzom / client / src / item_group_manager.h
blob705e570a260c825fe6fc5b3af1ae8506a3be3770
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef RY_ITEM_GROUP_MANAGER_H
18 #define RY_ITEM_GROUP_MANAGER_H
19 #include <limits>
20 #include "interface_v3/inventory_manager.h"
21 #include "interface_v3/dbctrl_sheet.h"
22 #include "game_share/inventories.h"
23 #include "game_share/slot_equipment.h"
25 #define ITEMGROUPS_CURRENT_VERSION "2" // versioning for migrations
26 #define MENU_IN_BAG "ui:interface:item_menu_in_bag"
27 #define ITEMGROUP_MENU "ui:interface:item_menu_in_bag:item_group_menu"
28 #define LIST_ITEMGROUPS "ui:interface:inventory:content:equip:midsection:content:itemgroups:list_container:itemgroups_list"
29 #define LIST_ITEMGROUPS_2 "ui:interface:inv_equip:content:equip:midsection:content:itemgroups:list_container:itemgroups_list"
30 #define LIST_EMPTY_TEXT "empty_text"
31 #define TEMPLATE_ITEMGROUP_ITEM "itemgroups_item"
32 #define TEMPLATE_ITEMGROUP_ITEM_NAME "name"
34 class CItemGroup
36 public:
37 // designates a given slot in the local inventory
38 struct CSlot {
39 INVENTORIES::TInventory branch; // the local inventory branch (e.g. INVENTORIES::handling or INVENTORIES::equipment)
40 uint16 index; // the index in the branch
41 CSlot(INVENTORIES::TInventory branch, uint16 index):
42 branch(branch),
43 index(index)
45 CSlot():
46 branch(INVENTORIES::UNDEFINED),
47 index(0)
50 bool operator==(const CSlot &other) const {return (branch == other.branch) && (index == other.index);}
51 void writeTo(xmlNodePtr node);
52 bool isValid();
53 const std::string toDbPath();
54 const std::string toString();
55 CDBCtrlSheet* getSheet();
56 static CSlot readFromV1(xmlNodePtr node);
57 static CSlot readFromV2(xmlNodePtr node);
58 static CSlot handSlot(uint16 index) { return CSlot(INVENTORIES::handling, index); }
59 static CSlot equipSlot(uint16 index) { return CSlot(INVENTORIES::equipment, index); }
60 static CSlot hotbarSlot(uint16 index) { return CSlot(INVENTORIES::hotbar, index); }
61 static CSlot fromSlotEquipment(SLOT_EQUIPMENT::TSlotEquipment slotEquipment);
64 // an item group item
65 struct CItem {
66 sint32 createTime; // create time of the item in the inventory (used to find the item in the inventory)
67 sint32 serial; // serial of the item in the inventory (used to find the item in the inventory)
68 CItemGroup::CSlot dstSlot; // the slot where we want to put the item
69 CDBCtrlSheet *pCS; // references an item in the current inventory
70 CItem(sint32 createTime, sint32 serial, CSlot dstSlot):
71 createTime(createTime),
72 serial(serial),
73 dstSlot(dstSlot),
74 pCS(NULL)
77 bool operator<(const CItem &item) const { return (dstSlot.branch != item.dstSlot.branch) ? (dstSlot.branch < item.dstSlot.branch) : (dstSlot.index < item.dstSlot.index); }
78 void equip(uint32 &equipTime);
79 bool isInDestinationSlot();
80 void writeTo(xmlNodePtr node);
81 static CItem readFrom(xmlNodePtr node);
84 public:
85 CItemGroup();
87 bool contains(CDBCtrlSheet *pCS);
88 void addSheet(CDBCtrlSheet *pCS, CSlot slot, bool removeEmpty);
89 void addItem(CItem item);
90 void addRemoveSlot(CSlot slot);
91 void updateSheets();
92 void writeTo(xmlNodePtr node);
93 void deserialize(xmlNodePtr node, std::string version);
94 bool empty() const { return items.size() == 0;}
96 std::string name;
97 std::vector<CItemGroup::CItem> items;
98 std::vector<CItemGroup::CSlot> removeSlots;
101 class CItemGroupManager
103 public:
104 // Singleton management
105 static CItemGroupManager *getInstance();
106 static void releaseInstance();
107 // Ctor
108 CItemGroupManager();
109 // Regular function
110 void init();
111 void uninit();
112 std::string getFilePath(std::string playerName);
113 void saveGroups();
114 bool loadGroups();
115 void linkInterface();
116 void unlinkInterface();
117 void undrawGroupsList();
118 void drawGroupsList();
119 CInterfaceGroup* generateGroupsListLine(std::string parent, uint i);
120 //Return NULL if no group was found
121 //Return false if no group was found
122 bool moveGroup(std::string name, INVENTORIES::TInventory dst);
123 bool equipGroup(std::string name, bool pullBefore = true);
124 bool createGroup(std::string name, bool removeUnequiped = false);
125 bool deleteGroup(std::string name);
126 void listGroup();
127 std::vector<std::string> getGroupNames(CDBCtrlSheet *pCS);
129 private:
130 CItemGroup *findGroup(std::string name);
131 std::vector<CItemGroup> _Groups;
132 // Singleton's instance
133 static CItemGroupManager *_Instance;
134 // Workaround: sometimes item are marked as equipped by pIM->isBagItemWeared() even tho they aren't really
135 // Because of a synchronisation error between client and server
136 bool isItemEquipped(CDBCtrlSheet *item, CItemGroup::CSlot &equipSlot);
137 std::string generateDocumentation();
140 #endif // RY_ITEM_GROUP_MANAGER_H