1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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
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"
37 // designates a given slot in the local inventory
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
):
46 branch(INVENTORIES::UNDEFINED
),
50 bool operator==(const CSlot
&other
) const {return (branch
== other
.branch
) && (index
== other
.index
);}
51 void writeTo(xmlNodePtr node
);
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
);
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
),
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
);
87 bool contains(CDBCtrlSheet
*pCS
);
88 void addSheet(CDBCtrlSheet
*pCS
, CSlot slot
, bool removeEmpty
);
89 void addItem(CItem item
);
90 void addRemoveSlot(CSlot slot
);
92 void writeTo(xmlNodePtr node
);
93 void deserialize(xmlNodePtr node
, std::string version
);
94 bool empty() const { return items
.size() == 0;}
97 std::vector
<CItemGroup::CItem
> items
;
98 std::vector
<CItemGroup::CSlot
> removeSlots
;
101 class CItemGroupManager
104 // Singleton management
105 static CItemGroupManager
*getInstance();
106 static void releaseInstance();
112 std::string
getFilePath(std::string playerName
);
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
);
127 std::vector
<std::string
> getGroupNames(CDBCtrlSheet
*pCS
);
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