Merge with menu_navi

--HG--
branch : yubo
hg/yubo
Inky 6 years ago
commit 1910f7bc86

@ -154,7 +154,7 @@ sint LoginCharsel = -1;
static const char *KeySetVarName = "BuiltInKeySets"; static const char *KeySetVarName = "BuiltInKeySets";
#define GROUP_LIST_CHARACTER "ui:outgame:charsel_import:import_list"
#define GROUP_LIST_MAINLAND "ui:outgame:appear_mainland:mainland_list" #define GROUP_LIST_MAINLAND "ui:outgame:appear_mainland:mainland_list"
#define GROUP_LIST_KEYSET "ui:outgame:appear_keyset:keyset_list" #define GROUP_LIST_KEYSET "ui:outgame:appear_keyset:keyset_list"
vector<CMainlandSummary> Mainlands; vector<CMainlandSummary> Mainlands;
@ -3444,3 +3444,234 @@ class CAHOpenRingSessions : public IActionHandler
} }
}; };
REGISTER_ACTION_HANDLER (CAHOpenRingSessions, "open_ring_sessions"); REGISTER_ACTION_HANDLER (CAHOpenRingSessions, "open_ring_sessions");
// ***************************************************************************
class CAHInitImportCharacter : public IActionHandler
{
virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
{
CInterfaceGroup *list = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CHARACTER));
if (!list)
{
nlwarning("element " GROUP_LIST_CHARACTER " not found probably bad outgame.xml");
return;
}
// retrieve saved files
std::vector<string> savedCharacters;
CPath::getPathContent("save/", false, false, true, savedCharacters);
CInterfaceGroup *newLine;
CInterfaceGroup *prevLine;
for (uint i = 0; i < savedCharacters.size(); ++i)
{
// search saved characters only
if (testWildCard(CFile::getFilename(savedCharacters[i]), "character_*.save"))
{
const std::string id = CFile::getFilenameWithoutExtension(savedCharacters[i]).substr(strlen("character_"));
if (id.empty())
continue;
std::vector<pair<string, string>> params;
params.clear();
params.push_back(std::pair<string, string>("id", id));
// adjust ref
if (list->getNumGroup() > 0)
params.push_back(std::pair<string, string>("posref", "BL TL"));
newLine = CWidgetManager::getInstance()->getParser()->createGroupInstance("t_import", GROUP_LIST_CHARACTER, params);
if (newLine)
{
CViewText *text = dynamic_cast<CViewText*>(newLine->getView("name"));
if (text)
text->setText(ucstring(savedCharacters[i]));
// add to the list now
newLine->setParent(list);
newLine->setParentSize(list);
newLine->setParentPos(prevLine);
list->addGroup(newLine);
prevLine = newLine;
}
}
}
// none case
if (list->getNumGroup() == 0)
CLuaManager::getInstance().executeLuaScript("outgame:procCharselNotifaction(3)");
list->invalidateCoords();
}
};
REGISTER_ACTION_HANDLER( CAHInitImportCharacter, "import_char_init" );
// ***************************************************************************
class CAHResetImportCharacter : public IActionHandler
{
virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
{
CInterfaceGroup *list = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CHARACTER));
if (list)
list->clearGroups();
if (!ImportCharacter.empty())
ImportCharacter = "";
}
};
REGISTER_ACTION_HANDLER( CAHResetImportCharacter, "import_char_reset" );
// ***************************************************************************
class CAHSelectImportCharacter : public IActionHandler
{
virtual void execute (CCtrlBase *pCaller, const std::string &Params)
{
struct CUnpush : public CInterfaceElementVisitor
{
CCtrlBase *Ref;
virtual void visitCtrl(CCtrlBase *ctrl)
{
if (ctrl == Ref) return;
CCtrlBaseButton *but = dynamic_cast<CCtrlBaseButton*>(ctrl);
if (but)
{
but->setPushed(false);
}
}
};
CInterfaceGroup *list = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CHARACTER));
if (!list)
return;
// unselect
if (Params.empty())
{
CUnpush unpusher;
unpusher.Ref = pCaller;
list->visit(&unpusher);
}
// now select
std::string name;
if (Params.empty())
{
CCtrlButton *pCB = dynamic_cast<CCtrlButton*>(pCaller);
if (!pCB)
return;
std::string id = pCB->getId();
id = id.substr(0, id.rfind(':'));
if (!fromString(id.substr(id.rfind(':')+1, id.size()), name))
return;
pCB->setPushed(true);
}
else
if (!fromString(Params, name))
return;
ImportCharacter = "";
// check filename and store
if (CFile::fileExists(toString("save/character_%s.save", name.c_str())))
ImportCharacter = name;
}
};
REGISTER_ACTION_HANDLER( CAHSelectImportCharacter, "import_char_select" );
// ***************************************************************************
class CAHImportCharacter : public IActionHandler
{
virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
{
if (ImportCharacter.empty())
return;
if (!CFile::fileExists(toString("save/character_%s.save", ImportCharacter.c_str())))
return;
bool success = false;
CIFile fd;
CCharacterSummary CS;
// use temporary file until close()
if (fd.open(toString("save/character_%s.save", ImportCharacter.c_str())))
{
try
{
CS.serial(fd);
SCharacter3DSetup::setupDBFromCharacterSummary("UI:TEMP:CHAR3D", CS);
// validate import
CDBManager::getInstance()->getDbProp("UI:TEMP:IMPORT")->setValue32(1);
success = true;
}
catch (const EStream &e)
{
nlwarning(e.what());
}
fd.close();
}
else
nlwarning("Failed to open file: save/character_%s.save", ImportCharacter.c_str());
// user notification
if (!success)
CLuaManager::getInstance().executeLuaScript("outgame:procCharselNotifaction(2)");
else
CAHManager::getInstance()->runActionHandler("proc", NULL, "proc_charsel_create_new");
}
};
REGISTER_ACTION_HANDLER( CAHImportCharacter, "import_char" );
// ***************************************************************************
class CAHExportCharacter : public IActionHandler
{
virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params)
{
if (Params.empty())
return;
sint32 slot = -1;
if (!fromString(getParam(Params, "slot"), slot))
return;
if (slot >= CharacterSummaries.size() || slot < 0)
return;
// retrieve infos
CCharacterSummary &CS = CharacterSummaries[slot];
if (CS.Name.empty())
return;
// extract name
const std::string name = buildPlayerNameForSaveFile(CS.Name.toString());
COFile fd;
bool success = false;
// use temporary file until close()
if (fd.open(toString("save/character_%s.save", name.c_str()), false, false, true))
{
try
{
fd.serial(CS);
fd.flush();
// validate
success = true;
}
catch (const EStream &e)
{
nlwarning(e.what());
}
fd.close();
}
else
nlwarning("Failed to open file: save/character_%s.save", name.c_str());
const uint8 val = (success == true) ? 0 : 1;
// user notification
CLuaManager::getInstance().executeLuaScript(toString("outgame:procCharselNotifaction(%i)", val));
}
};
REGISTER_ACTION_HANDLER( CAHExportCharacter, "export_char" );

Loading…
Cancel
Save