Added action handlers to change contact group and read/write to file

ryzom/ui/improvements
Sit Melai 4 years ago
parent 49fcec5759
commit 5dc85db8b1

@ -311,6 +311,8 @@ void CPeopleInterraction::release()
ChatInput.Tell.removeListeningPeopleList(&TeamList);
ChatInput.Team.removeListeningPeopleList(&TeamList);
FriendList.saveContactGroups();
CChatWindowManager &cwm = getChatWndMgr();
AroundMe.release();
@ -1266,6 +1268,9 @@ void CPeopleInterraction::initContactLists( const std::vector<uint32> &vFriendLi
addContactInList(contactIdPool++, vFriendListName[i], vFriendListOnline[i], 0);
for (uint i = 0; i < vIgnoreListName.size(); ++i)
addContactInList(contactIdPool++, vIgnoreListName[i], ccs_offline, 1);
FriendList.readContactGroups();
CPeopleList::TSortOrder order = (CPeopleList::TSortOrder)(NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CONTACT_LIST:SORT_ORDER")->getValue32());
FriendList.sortEx(order);
updateAllFreeTellerHeaders();
}
@ -1278,6 +1283,8 @@ void CPeopleInterraction::addContactInList(uint32 contactId, const ucstring &nam
// remove the shard name if possible
ucstring name= CEntityCL::removeShardFromName(nameIn);
// add the contact to this list
sint index = pl.getIndexFromName(name);
// try to create if not found
@ -2312,7 +2319,7 @@ uint lastPeopleIndexChangeGroup;
class CHandlerChangeContactGroupBegin : public IActionHandler
{
public:
void execute (CCtrlBase * /* pCaller */, const std::string &sParams)
void execute (CCtrlBase * pCaller, const std::string &sParams)
{
// retrieve the index of the people
CPeopleList *srcList;
@ -2329,10 +2336,10 @@ public:
}
}
};
REGISTER_ACTION_HANDLER( CHandlerMoveContact, "change_contact_group_begin");
REGISTER_ACTION_HANDLER( CHandlerChangeContactGroupBegin, "change_contact_group_begin");
//=================================================================================================================
// Add a contact to the list
// Change the group of a contact in the list
class CHandlerChangeContactGroup : public IActionHandler
{
public:
@ -2343,26 +2350,20 @@ public:
if (pCaller)
{
// Get the modal edit box
CGroupEditBox *geb = dynamic_cast<CGroupEditBox *>(CWidgetManager::getInstance()->getElementFromId("ui:interface:change_contact_group_eb:eb"));
if (geb && !geb->getInputString().empty())
CGroupEditBox *geb = dynamic_cast<CGroupEditBox *>(CWidgetManager::getInstance()->getElementFromId("ui:interface:change_contact_group:change_contact_group_eb:eb"));
if (geb)
{
// don't add if it is the player name
if (!ClientCfg.Local && (UserEntity->getEntityName() == geb->getInputString()))
{
displayVisibleSystemMsg(CI18N::get("uiCantAddYourSelfInContactList"));
}
else
{
PeopleInterraction.askAddContact(geb->getInputString(), peopleList);
geb->setInputString(ucstring(""));
}
PeopleInterraction.FriendList.changeGroup(lastPeopleIndexChangeGroup, geb->getInputString());
geb->setInputString(ucstring(""));
CPeopleList::TSortOrder order = (CPeopleList::TSortOrder)(NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CONTACT_LIST:SORT_ORDER")->getValue32());
PeopleInterraction.FriendList.sortEx(order);
}
}
CAHManager::getInstance()->runActionHandler("leave_modal", pCaller, "");
}
};
REGISTER_ACTION_HANDLER( CHandlerAddContact, "change_contact_group");
REGISTER_ACTION_HANDLER( CHandlerChangeContactGroup, "change_contact_group");
//=================================================================================================================
class CHandlerSortContacts : public IActionHandler

@ -31,6 +31,7 @@
#include "chat_text_manager.h"
#include "people_interraction.h"
#include "../user_entity.h"
#include "nel/misc/o_xml.h"
using namespace std;
using namespace NLMISC;
@ -191,21 +192,28 @@ sint CPeopleList::getIndexFromContainerID(const std::string &id) const
//==================================================================
bool CPeopleList::sortExByContactId(const CPeople& a, const CPeople& b)
{
if (a.Group == b.Group)
return (a.ContactId < b.ContactId);
else
return (a.Group < b.Group);
}
//==================================================================
bool CPeopleList::sortExByName(const CPeople& a, const CPeople& b)
{
if (a.Group == b.Group) {
ucstring name_a = toUpper(a.getName());
ucstring name_b = toUpper(b.getName());
return (name_a < name_b);
}
else
return (a.Group < b.Group);
}
//==================================================================
bool CPeopleList::sortExByOnline(const CPeople& a, const CPeople& b)
{
if (a.Group == b.Group) {
ucstring name_a = toUpper(a.getName());
ucstring name_b = toUpper(b.getName());
@ -234,9 +242,9 @@ bool CPeopleList::sortExByOnline(const CPeople& a, const CPeople& b)
break;
}
}
// Should not get here so just return something
return true;
}
else
return (a.Group < b.Group);
}
//==================================================================
@ -245,9 +253,16 @@ void CPeopleList::sortEx(TSortOrder order)
// remove all people from the father container
if (!_BaseContainer) return;
uint k;
for(k = 0; k < _Peoples.size(); ++k)
{
_BaseContainer->detachContainer(_Peoples[k].Container);
CGroupContainer *parentContainer = _Peoples[k].Container->getProprietaryContainer();
parentContainer->detachContainer(_Peoples[k].Container);
}
for (k = 0; k < _GroupContainers.size(); ++k)
{
if (_GroupContainers[k].second->getProprietaryContainer() != NULL)
_BaseContainer->detachContainer(_GroupContainers[k].second);
}
switch (order)
@ -265,9 +280,29 @@ void CPeopleList::sortEx(TSortOrder order)
break;
}
CGroupContainer *group = _BaseContainer;
ucstring groupName = "";
uint groupIndex = 0;
for(k = 0; k < _Peoples.size(); ++k)
{
_BaseContainer->attachContainer(_Peoples[k].Container);
bool newGroup = false;
if (k == 0)
{
newGroup = true;
}
while (groupIndex < _GroupContainers.size() && _GroupContainers[groupIndex].first != _Peoples[k].Group.toString())
{
newGroup = true;
++groupIndex;
}
if (newGroup && groupIndex < _GroupContainers.size())
{
group = _GroupContainers[groupIndex].second;
groupName = _GroupContainers[groupIndex].first;
_BaseContainer->attachContainer(group);
}
group->attachContainer(_Peoples[k].Container);
}
}
@ -415,8 +450,9 @@ void CPeopleList::removePeople(uint index)
}
else
{
if (_BaseContainer)
_BaseContainer->detachContainer(_Peoples[index].Container);
CGroupContainer *parentContainer = _Peoples[index].Container->getProprietaryContainer();
if (parentContainer)
parentContainer->detachContainer(_Peoples[index].Container);
}
CInterfaceManager *im = CInterfaceManager::getInstance();
CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
@ -447,6 +483,150 @@ void CPeopleList::setContactId(uint index, uint32 contactId)
_Peoples[index].ContactId = contactId;
}
//==================================================================
void CPeopleList::changeGroup(uint index, const ucstring &groupName)
{
if (index >= _Peoples.size())
{
nlwarning("<CPeopleList::changeGroup> bad index.");
return;
}
ucstring group = groupName;
if (group.toString() == "General")
group = ucstring("");
_Peoples[index].Group = group;
for (uint k = 0; k < _GroupContainers.size(); ++k)
{
if (_GroupContainers[k].first == group.toString())
return;
}
vector<pair<string, string> > properties;
properties.push_back(make_pair(string("posparent"), string("parent")));
properties.push_back(make_pair(string("id"), _ContainerID + "_group_" + toString(_GroupContainers.size())));
if (group.toString() == "")
properties.push_back(make_pair(string("title"), "General"));
else
properties.push_back(make_pair(string("title"), group.toString()));
CGroupContainer *gc = dynamic_cast<CGroupContainer *>(CWidgetManager::getInstance()->getParser()->createGroupInstance("people_list_group_header", "ui:interface", properties, false));
if (group.toString() == "")
gc->setUCTitle(ucstring("General"));
else
gc->setUCTitle(group.toString());
gc->setSavable(false);
CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
pRoot->addGroup (gc);
_BaseContainer->attachContainer(gc);
_GroupContainers.push_back(make_pair(group.toString(), gc));
std::sort(_GroupContainers.begin(), _GroupContainers.end());
}
//==================================================================
void CPeopleList::readContactGroups()
{
_GroupContainers.clear();
const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("contactgroups", "xml");
try
{
CIFile fd;
if (fd.open(CPath::lookup(filename)))
{
CIXml stream;
stream.init(fd);
xmlKeepBlanksDefault(0);
xmlNodePtr root = stream.getRootNode();
if (!root) return;
xmlNodePtr node = root->children;
uint nb = 0;
while (node)
{
CXMLAutoPtr propName = xmlGetProp(node, (xmlChar*)"name");
CXMLAutoPtr propGroup = xmlGetProp(node, (xmlChar*)"group");
if (propName && propGroup)
{
sint index = getIndexFromName(propName.str());
if (index < _Peoples.size())
{
_Peoples[index].Group = propGroup.str();
if (_GroupContainers.empty() || _GroupContainers.back().first != propName.str()) {
vector<pair<string, string> > properties;
properties.push_back(make_pair(string("posparent"), string("parent")));
properties.push_back(make_pair(string("id"), _ContainerID + "_group_" + toString(_GroupContainers.size())));
if (propGroup.str() == "")
properties.push_back(make_pair(string("title"), "General"));
else
properties.push_back(make_pair(string("title"), propGroup.str()));
CInterfaceGroup *group = CWidgetManager::getInstance()->getParser()->createGroupInstance("people_list_group_header", "ui:interface", properties, false);
CGroupContainer *gc = dynamic_cast<CGroupContainer *>(group);
if (propGroup.str() == "")
gc->setUCTitle(ucstring("General"));
else
gc->setUCTitle(propGroup.str());
gc->setSavable(false);
CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
pRoot->addGroup (gc);
_BaseContainer->attachContainer(gc);
_GroupContainers.push_back(make_pair(propGroup.str(), gc));
}
}
}
node = node->next;
nb++;
}
fd.close();
}
std::sort(_GroupContainers.begin(), _GroupContainers.end());
}
catch (const Exception &e)
{
nlwarning("Error while parsing xml file %s : %s", filename.c_str(), e.what());
}
}
//==================================================================
void CPeopleList::saveContactGroups()
{
const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("contactgroups", "xml");
try
{
COFile fd;
if (fd.open(filename, false, false, true))
{
COXml stream;
stream.init(&fd);
xmlDocPtr doc = stream.getDocument();
xmlNodePtr node = xmlNewDocNode(doc, NULL, (const xmlChar*)"contact_groups", NULL);
xmlDocSetRootElement(doc, node);
for (uint k = 0; k < _Peoples.size(); ++k)
{
xmlNodePtr newNode = xmlNewChild(node, NULL, (const xmlChar*)"contact", NULL);
xmlSetProp(newNode, (const xmlChar*)"name", (const xmlChar*)_Peoples[k].getName().toString().c_str());
xmlSetProp(newNode, (const xmlChar*)"group", (const xmlChar*)_Peoples[k].Group.toString().c_str());
}
stream.flush();
fd.close();
}
nlinfo("save %s", filename.c_str());
}
catch (const Exception &e)
{
nlwarning("Error while writing the file %s : %s", filename.c_str(), e.what());
}
}
//==================================================================
void CPeopleList::displayLocalPlayerTell(const ucstring &receiver, uint index, const ucstring &msg,uint numBlinks /*=0*/)
{

@ -110,6 +110,11 @@ public:
void setContactId(uint index, uint32 contactId);
sint getIndexFromContactId(uint32 contactId);
// For Friend Groups management
void changeGroup(uint index, const ucstring &groupName);
void readContactGroups();
void saveContactGroups();
/** Display a message for the given people
* If the window is closed, it causes it to blink (and also the parent window)
*/
@ -165,6 +170,7 @@ private:
typedef std::vector<CPeople> TPeopleVect;
private:
CGroupContainerPtr _BaseContainer;
std::vector<std::pair<std::string, NLMISC::CRefPtr<CGroupContainer> > > _GroupContainers;
NLMISC::CRefPtr<CChatWindow> _ChatWindow;
TPeopleVect _Peoples;
CPeopleListDesc::TContactType _ContactType;

Loading…
Cancel
Save