From 9390f9cca5336b8304aca24b7fe324ea5bba4a67 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 15 Aug 2017 11:54:24 +0300 Subject: [PATCH] Changed: Sort tribe fame list --HG-- branch : develop --- .../gamedev/interfaces_v3/info_player.lua | 2 + .../src/interface_v3/action_handler_game.cpp | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/code/ryzom/client/data/gamedev/interfaces_v3/info_player.lua b/code/ryzom/client/data/gamedev/interfaces_v3/info_player.lua index 12210fadf..64858c69c 100644 --- a/code/ryzom/client/data/gamedev/interfaces_v3/info_player.lua +++ b/code/ryzom/client/data/gamedev/interfaces_v3/info_player.lua @@ -1431,6 +1431,8 @@ function game:onInGameDbInitialized() end game:setInfoPlayerCharacterRace() + + runAH(nil, "sort_tribefame", "") end function game:onWebIgReady() diff --git a/code/ryzom/client/src/interface_v3/action_handler_game.cpp b/code/ryzom/client/src/interface_v3/action_handler_game.cpp index 2f14ce8a0..196b0a45e 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_game.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_game.cpp @@ -20,6 +20,7 @@ #include "stdpch.h" #include +#include // Interface includes #include "interface_manager.h" @@ -4511,3 +4512,63 @@ public: } }; REGISTER_ACTION_HANDLER( CHandlerEmote, "emote"); + +//================================================================================================================= +class CHandlerSortTribeFame : public IActionHandler +{ +public: + void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */) + { + CGroupList * list = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:fame:content:tribes:list")); + if (list && list->getNumChildren() > 1) + { + uint nbChilds = list->getNumChildren(); + + // std::collate does not work with ucchar + std::vector names; + + for (uint i = 0; i < nbChilds; ++i) + { + CInterfaceGroup *pIG = dynamic_cast(list->getChild(i)); + if (!pIG) break; + + CViewText *pVT = dynamic_cast(pIG->getView("t")); + if (!pVT) break; + + names.push_back(toUpper(pVT->getText().toUtf8())); + } + + if (names.size() != nbChilds) + { + nlwarning("Failed to sort tribe fame list"); + return; + } + + std::locale loc(""); + const std::collate& coll = std::use_facet >(loc); + + for(uint i = 0; i < nbChilds - 1; ++i) + { + uint imin = i; + for(uint j = i; j < nbChilds; j++) + { + // simple comparison fails with accented letters + if (coll.compare(names[j].c_str(), names[j].c_str() + names[j].size(), + names[imin].c_str(), names[imin].c_str() + names[imin].size()) < 0) + { + imin = j; + } + } + if (imin != i) + { + list->swapChildren(i, imin); + std::swap(names[i], names[imin]); + } + } + + list->invalidateCoords(); + } + } +}; +REGISTER_ACTION_HANDLER( CHandlerSortTribeFame, "sort_tribefame"); +