Added: save_ui action handler to save keys and icfg files

--HG--
branch : develop
This commit is contained in:
Nimetu 2018-10-11 15:24:03 +03:00
parent 8ef8b2d62d
commit 1dc3d51ce2
3 changed files with 61 additions and 27 deletions

View file

@ -2665,18 +2665,8 @@ CCtrlButton *CGroupMap::addUserLandMark(const NLMISC::CVector2f &pos, const ucst
addLandMark(_UserLM, pos, title, getUserLandMarkOptions((uint32)_CurContinent->UserLandMarks.size() - 1)); addLandMark(_UserLM, pos, title, getUserLandMarkOptions((uint32)_CurContinent->UserLandMarks.size() - 1));
// Save the config file each time a user landmark is created // Save the config file each time a user landmark is created
CInterfaceManager *pIM = CInterfaceManager::getInstance(); CInterfaceManager::getInstance()->saveConfig();
uint8 currMode = pIM->getMode();
std::string filename = "save/interface_" + PlayerSelectedFileName + ".icfg";
if (!CFile::fileExists(filename) && CFile::fileExists("save/shared_interface.icfg"))
{
filename = "save/shared_interface.icfg";
}
pIM->saveConfig (filename);
if (currMode != pIM->getMode())
{
pIM->setMode(currMode);
}
return _UserLM.back(); return _UserLM.back();
} }

View file

@ -1270,32 +1270,19 @@ void CInterfaceManager::loadInterfaceConfig()
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CInterfaceManager::uninitInGame0 () void CInterfaceManager::uninitInGame0 ()
{ {
// Autosave of the keys // Autosave of the keys
if (_KeysLoaded) if (_KeysLoaded)
{ {
if (!ClientCfg.R2EDEnabled) saveKeys();
{
string filename = "save/keys_" + PlayerSelectedFileName + ".xml";
if (!CFile::fileExists(filename) && CFile::fileExists("save/shared_keys.xml"))
filename = "save/shared_keys.xml";
saveKeys(filename);
}
_KeysLoaded = false; _KeysLoaded = false;
} }
// Autosave of the interface in interface.cfg // Autosave of the interface in interface.cfg
if (_ConfigLoaded) if (_ConfigLoaded)
{ {
if (!ClientCfg.R2EDEnabled) saveConfig();
{
string filename = "save/interface_" + PlayerSelectedFileName + ".icfg";
if (!CFile::fileExists(filename) && CFile::fileExists("save/shared_interface.icfg"))
filename = "save/shared_interface.icfg";
saveConfig(filename);
}
_ConfigLoaded = false; _ConfigLoaded = false;
} }
} }
@ -1884,6 +1871,29 @@ public:
} }
}; };
// ------------------------------------------------------------------------------------------------
//
bool CInterfaceManager::saveConfig (bool verbose)
{
bool ret = true;
if (!ClientCfg.R2EDEnabled)
{
uint8 currMode = getMode();
string filename = "save/interface_" + PlayerSelectedFileName + ".icfg";
if (!CFile::fileExists(filename) && CFile::fileExists("save/shared_interface.icfg"))
filename = "save/shared_interface.icfg";
if (verbose) CInterfaceManager::getInstance()->displaySystemInfo("Saving " + filename);
ret = saveConfig(filename);
if (currMode != getMode())
setMode(currMode);
}
return ret;
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool CInterfaceManager::saveConfig (const string &filename) bool CInterfaceManager::saveConfig (const string &filename)
@ -2722,7 +2732,25 @@ void writeMacros (xmlNodePtr node)
} }
// *************************************************************************** // ***************************************************************************
bool CInterfaceManager::saveKeys(bool verbose)
{
bool ret = true;
if (!ClientCfg.R2EDEnabled)
{
string filename = "save/keys_" + PlayerSelectedFileName + ".xml";
if (!CFile::fileExists(filename) && CFile::fileExists("save/shared_keys.xml"))
filename = "save/shared_keys.xml";
if (verbose) CInterfaceManager::getInstance()->displaySystemInfo("Saving " + filename);
ret = saveKeys(filename);
}
return ret;
}
// ***************************************************************************
bool CInterfaceManager::saveKeys(const std::string &filename) bool CInterfaceManager::saveKeys(const std::string &filename)
{ {
bool ret = false; bool ret = false;
@ -2924,6 +2952,18 @@ void CInterfaceManager::displayWebWindow(const string & name, const string & url
CAHManager::getInstance()->runActionHandler("browse", NULL, "name="+name+":content:html|url="+url); CAHManager::getInstance()->runActionHandler("browse", NULL, "name="+name+":content:html|url="+url);
} }
// ***************************************************************************
class CAHSaveUI : public IActionHandler
{
virtual void execute (CCtrlBase *pCaller, const string &Params)
{
CInterfaceManager::getInstance()->saveKeys(true);
CInterfaceManager::getInstance()->saveConfig(true);
}
};
REGISTER_ACTION_HANDLER (CAHSaveUI, "save_ui");
/* /*
// *************************************************************************** // ***************************************************************************
class CHandlerDispWebOnQuit : public IActionHandler class CHandlerDispWebOnQuit : public IActionHandler

View file

@ -205,10 +205,14 @@ public:
// Load/Save position, size, etc.. of windows // Load/Save position, size, etc.. of windows
bool loadConfig (const std::string &filename); bool loadConfig (const std::string &filename);
// Save config to default location, if verbose is true, display message in game sysinfo
bool saveConfig (bool verbose = false);
bool saveConfig (const std::string &filename); bool saveConfig (const std::string &filename);
// delete the user config (give the player ident fileName) // delete the user config (give the player ident fileName)
bool deletePlayerConfig (const std::string &playerFileIdent); bool deletePlayerConfig (const std::string &playerFileIdent);
// Save keys to default location, if verbose is true, display message in game sysinfo
bool saveKeys (bool verbose = false);
// Save the keys config file // Save the keys config file
bool saveKeys (const std::string &filename); bool saveKeys (const std::string &filename);
// delete the user Keysconfig (give the player ident fileName) // delete the user Keysconfig (give the player ident fileName)