Changed: update button selection handler keyset_select

--HG--
branch : menu_navi
hg/feature/menu-navi
Inky 6 years ago
parent 5d1233e805
commit c8927c9c4b

@ -2454,7 +2454,7 @@ public:
virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance(); //CInterfaceManager *pIM = CInterfaceManager::getInstance();
CInterfaceGroup *pList = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_KEYSET)); CInterfaceGroup *pList = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_KEYSET));
pList->clearGroups(); pList->clearGroups();
} }
@ -2465,59 +2465,66 @@ REGISTER_ACTION_HANDLER (CAHResetKeysetList, "reset_keyset_list");
// *************************************************************************** // ***************************************************************************
class CAHResetKeysetSelect : public IActionHandler class CAHResetKeysetSelect : public IActionHandler
{ {
public:
std::string getIdPostFix(const std::string fullId) std::string getIdPostFix(const std::string fullId)
{ {
std::string::size_type pos = fullId.find_last_of(":"); std::string::size_type pos = fullId.find_last_of(":");
if (pos != std::string::npos) if (pos != std::string::npos)
{
return fullId.substr(pos + 1); return fullId.substr(pos + 1);
}
return ""; return "";
} }
virtual void execute (CCtrlBase *pCaller, const string &/* Params */)
virtual void execute(CCtrlBase *pCaller, const std::string &Params)
{ {
if (!pCaller) return;
// 'unpush' all groups but the caller // 'unpush' all groups but the caller
//
struct CUnpush : public CInterfaceElementVisitor struct CUnpush : public CInterfaceElementVisitor
{ {
CCtrlBase *Ref; CCtrlBase *Ref;
virtual void visitCtrl(CCtrlBase *ctrl) virtual void visitCtrl(CCtrlBase *ctrl)
{ {
if (ctrl == Ref) return; if (ctrl == Ref) return;
CCtrlBaseButton *but = dynamic_cast<CCtrlBaseButton *>(ctrl); CCtrlBaseButton *but = dynamic_cast<CCtrlBaseButton*>(ctrl);
if (but) if (but)
{ {
but->setPushed(false); but->setPushed(false);
} }
} }
}; };
CInterfaceManager *pIM = CInterfaceManager::getInstance(); CInterfaceGroup *list = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_KEYSET));
CInterfaceGroup * list = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_KEYSET)); if (!list)
if (list) return;
{
CUnpush unpusher; // unselect
unpusher.Ref = pCaller; CUnpush unpusher;
list->visit(&unpusher); unpusher.Ref = pCaller;
} list->visit(&unpusher);
CCtrlBaseButton *but = dynamic_cast<CCtrlBaseButton *>(pCaller);
// now select
CCtrlBaseButton *but = dynamic_cast<CCtrlBaseButton*>(pCaller);
if (but) if (but)
{
but->setPushed(true); but->setPushed(true);
std::string id;
if (Params.empty())
{
if (!pCaller) return;
if (!pCaller->getParent()) return;
id = getIdPostFix(pCaller->getParent()->getId());
} }
// else
id = getIdPostFix(Params);
GameKeySet = "keys.xml"; GameKeySet = "keys.xml";
RingEditorKeySet = "keys_r2ed.xml"; RingEditorKeySet = "keys_r2ed.xml";
if (!pCaller->getParent()) return;
// compute the 2 filenames from the id // compute the two filenames from the id
// if id is in the built-in keysets : // if id is in the built-in keysets
CConfigFile::CVar *keySetVar = ClientCfg.ConfigFile.getVarPtr(KeySetVarName); CConfigFile::CVar *keySetVar = ClientCfg.ConfigFile.getVarPtr(KeySetVarName);
if (keySetVar && keySetVar->size() != 0) if (keySetVar && keySetVar->size() > 0)
{ {
for (uint k = 0; k < keySetVar->size(); ++k) for (uint k = 0; k < keySetVar->size(); ++k)
{ {
std::string id = getIdPostFix(pCaller->getParent()->getId());
if (keySetVar->asString(k) == id) if (keySetVar->asString(k) == id)
{ {
GameKeySet = "keys" + string(id.empty() ? "" : "_") + id + ".xml"; GameKeySet = "keys" + string(id.empty() ? "" : "_") + id + ".xml";
@ -2526,17 +2533,15 @@ public:
} }
} }
} }
// ... else maybe from a previous character ?
if (CFile::isExists("save/keys_" + getIdPostFix(pCaller->getParent()->getId()) + ".xml") )
{
GameKeySet = "keys_" + getIdPostFix(pCaller->getParent()->getId()) + ".xml";
}
if (CFile::isExists("save/keys_r2ed_" + getIdPostFix(pCaller->getParent()->getId()) + ".xml") )
{
RingEditorKeySet = "keys_r2ed_" + getIdPostFix(pCaller->getParent()->getId()) + ".xml";
}
// NB : key file will be copied for real when the new 'character summary' is
// else maybe from a previous character?
if (CFile::isExists("save/keys_" + id + ".xml"))
GameKeySet = "keys_" + id + ".xml";
if (CFile::isExists("save/keys_r2ed_" + id + ".xml"))
RingEditorKeySet = "keys_r2ed_" + id + ".xml";
// NB: key file will be copied for real when the new character summary is
} }
}; };
REGISTER_ACTION_HANDLER (CAHResetKeysetSelect, "keyset_select"); REGISTER_ACTION_HANDLER (CAHResetKeysetSelect, "keyset_select");

Loading…
Cancel
Save