diff --git a/code/ryzom/client/src/item_group_manager.cpp b/code/ryzom/client/src/item_group_manager.cpp index 2cefc0c76..e1060a5e7 100644 --- a/code/ryzom/client/src/item_group_manager.cpp +++ b/code/ryzom/client/src/item_group_manager.cpp @@ -38,9 +38,9 @@ CItemGroup::CItemGroup() bool CItemGroup::contains(CDBCtrlSheet *other) { - for(int i=0;i<_Items.size();i++) + for(int i=0;igetSheetId()); if (sheet.toString() == item.sheetName && other->getQuality() == item.quality && other->getItemWeight() == item.weight && other->getItemColor() == item.color && @@ -56,16 +56,16 @@ bool CItemGroup::contains(CDBCtrlSheet *other) void CItemGroup::addItem(std::string sheetName, uint16 quality, uint32 weight, uint8 color) { - _Items.push_back(CItem(sheetName, quality, weight, color)); + Items.push_back(CItem(sheetName, quality, weight, color)); } void CItemGroup::writeTo(xmlNodePtr node) { xmlNodePtr groupNode = xmlNewChild (node, NULL, (const xmlChar*)"group", NULL ); xmlSetProp(groupNode, (const xmlChar*)"name", (const xmlChar*)name.c_str()); - for(int i=0;i<_Items.size();i++) + for(int i=0;i::max()); - _Items.push_back(item); + //Old version of groups.xml could save unknown sheets, remove them for clarity + if(item.sheetName != "unknown.unknown") + Items.push_back(item); } curNode = curNode->next; } @@ -165,6 +167,11 @@ CItemGroupManager::CItemGroupManager() void CItemGroupManager::init() { loadGroups(); + linkInterface(); +} + +void CItemGroupManager::linkInterface() +{ //attach item group subgroup to right-click in bag group CWidgetManager* pWM = CWidgetManager::getInstance(); CGroupMenu *pRootMenu = dynamic_cast(pWM->getElementFromId("ui:interface:item_menu_in_bag")); @@ -175,19 +182,23 @@ void CItemGroupManager::init() if(pMenu && pGroupSubMenu) pMenu->setSubMenu(pMenu->getNumLine() - 1, pGroupSubMenu); else - nlinfo("Couldn't update yet, maybe wait a little bit ?"); + nlwarning("Couldn't link group action to group menu, interface isn't initialize yet ?"); } void CItemGroupManager::uninit() { saveGroups(); - } // Inspired from macro parsing void CItemGroupManager::saveGroups() { std::string userGroupFileName = "save/groups_" + PlayerSelectedFileName + ".xml"; + if(PlayerSelectedFileName.empty()) + { + nlwarning("Trying to save group with an empty PlayerSelectedFileName, aborting"); + return; + } try { NLMISC::COFile f; if(f.open(userGroupFileName, false, false, true)) @@ -222,6 +233,11 @@ bool CItemGroupManager::loadGroups() { std::string userGroupFileName = "save/groups_" + PlayerSelectedFileName + ".xml"; + if(PlayerSelectedFileName.empty()) + { + nlwarning("Trying to load group with an empty PlayerSelectedFileName, aborting"); + return false; + } if (!NLMISC::CFile::fileExists(userGroupFileName) || NLMISC::CFile::getFileSize(userGroupFileName) == 0) { nlinfo("No item groups file found !"); @@ -380,6 +396,7 @@ bool CItemGroupManager::createGroup(std::string name) { pCS = CInventoryManager::getInstance()->getHandSheet(i); if(!pCS) continue; + if(!pCS->isSheetValid()) continue; NLMISC::CSheetId sheet(pCS->getSheetId()); group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor()); } @@ -389,6 +406,7 @@ bool CItemGroupManager::createGroup(std::string name) { pCS = CInventoryManager::getInstance()->getEquipSheet(i); if(!pCS) continue; + if(!pCS->isSheetValid()) continue; NLMISC::CSheetId sheet(pCS->getSheetId()); group.addItem(sheet.toString(), pCS->getQuality(), pCS->getItemWeight(), pCS->getItemColor()); } @@ -416,10 +434,12 @@ bool CItemGroupManager::deleteGroup(std::string name) void CItemGroupManager::listGroup() { CInterfaceManager *pIM = CInterfaceManager::getInstance(); + pIM->displaySystemInfo(ucstring("Available item groups :")); for(int i=0;i<_Groups.size();i++) { CItemGroup group = _Groups[i]; - pIM->displaySystemInfo(ucstring(group.name)); + ucstring msg = "* " + ucstring(group.name) + ucstring(NLMISC::toString(" with %d items inside.", group.Items.size())); + pIM->displaySystemInfo(msg); } } @@ -447,7 +467,6 @@ CItemGroup* CItemGroupManager::findGroup(std::string name) } return NULL; } -// Note : Guild & room aren't supported because missing price might cause issue std::string CItemGroupManager::toDbPath(INVENTORIES::TInventory inventory) { switch(inventory) diff --git a/code/ryzom/client/src/item_group_manager.h b/code/ryzom/client/src/item_group_manager.h index 1655eb477..38f53f4a9 100644 --- a/code/ryzom/client/src/item_group_manager.h +++ b/code/ryzom/client/src/item_group_manager.h @@ -60,9 +60,7 @@ public: void readFrom(xmlNodePtr node); std::string name; - -private: - std::vector _Items; + std::vector Items; }; class CItemGroupManager { @@ -77,6 +75,7 @@ public: void uninit(); void saveGroups(); bool loadGroups(); + void linkInterface(); //Return NULL if no group was found //Return false if no group was found bool moveGroup(std::string name, INVENTORIES::TInventory dst);