|
|
@ -458,6 +458,7 @@ CInterfaceManager::CInterfaceManager()
|
|
|
|
parser->addModule( "command", new CCommandParser() );
|
|
|
|
parser->addModule( "command", new CCommandParser() );
|
|
|
|
parser->addModule( "key", new CKeyParser() );
|
|
|
|
parser->addModule( "key", new CKeyParser() );
|
|
|
|
parser->addModule( "macro", new CMacroParser() );
|
|
|
|
parser->addModule( "macro", new CMacroParser() );
|
|
|
|
|
|
|
|
parser->addModule( "landmarks", new CLandmarkParser() );
|
|
|
|
parser->setCacheUIParsing( ClientCfg.CacheUIParsing );
|
|
|
|
parser->setCacheUIParsing( ClientCfg.CacheUIParsing );
|
|
|
|
|
|
|
|
|
|
|
|
CViewRenderer::setDriver( Driver );
|
|
|
|
CViewRenderer::setDriver( Driver );
|
|
|
@ -982,6 +983,9 @@ void CInterfaceManager::initInGame()
|
|
|
|
// Interface config
|
|
|
|
// Interface config
|
|
|
|
loadInterfaceConfig();
|
|
|
|
loadInterfaceConfig();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Load user landmarks
|
|
|
|
|
|
|
|
loadLandmarks();
|
|
|
|
|
|
|
|
|
|
|
|
// Must do extra init for people interaction after load
|
|
|
|
// Must do extra init for people interaction after load
|
|
|
|
PeopleInterraction.initAfterLoad();
|
|
|
|
PeopleInterraction.initAfterLoad();
|
|
|
|
|
|
|
|
|
|
|
@ -1217,6 +1221,22 @@ void CInterfaceManager::configureQuitDialogBox()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
std::string CInterfaceManager::getSaveFileName(const std::string &module, const std::string &ext, bool useShared) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string filename = "save/" + module + "_" + PlayerSelectedFileName + "." + ext;
|
|
|
|
|
|
|
|
if (useShared && !CFile::fileExists(filename))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string sharedFile = "save/shared_" + module + "." + ext;
|
|
|
|
|
|
|
|
if (CFile::fileExists(sharedFile))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return sharedFile;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void CInterfaceManager::loadKeys()
|
|
|
|
void CInterfaceManager::loadKeys()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1228,26 +1248,19 @@ void CInterfaceManager::loadKeys()
|
|
|
|
vector<string> xmlFilesToParse;
|
|
|
|
vector<string> xmlFilesToParse;
|
|
|
|
|
|
|
|
|
|
|
|
// Does the keys file exist ?
|
|
|
|
// Does the keys file exist ?
|
|
|
|
string userKeyFileName = "save/keys_"+PlayerSelectedFileName+".xml";
|
|
|
|
string userKeyFileName = getSaveFileName("keys", "xml");
|
|
|
|
if (CFile::fileExists(userKeyFileName) && CFile::getFileSize(userKeyFileName) > 0)
|
|
|
|
if (CFile::fileExists(userKeyFileName) && CFile::getFileSize(userKeyFileName) > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Load the user key file
|
|
|
|
// Load the user key file
|
|
|
|
xmlFilesToParse.push_back (userKeyFileName);
|
|
|
|
xmlFilesToParse.push_back (userKeyFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string filename = "save/shared_keys.xml";
|
|
|
|
|
|
|
|
if(CFile::fileExists(filename) && CFile::getFileSize(filename) > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
xmlFilesToParse.push_back(filename);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the default key (but don't replace existings bounds, see keys.xml "key_def_no_replace")
|
|
|
|
// Load the default key (but don't replace existings bounds, see keys.xml "key_def_no_replace")
|
|
|
|
xmlFilesToParse.push_back ("keys.xml");
|
|
|
|
xmlFilesToParse.push_back ("keys.xml");
|
|
|
|
|
|
|
|
|
|
|
|
if (!parseInterface (xmlFilesToParse, true))
|
|
|
|
if (!parseInterface (xmlFilesToParse, true))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
badXMLParseMessageBox();
|
|
|
|
createFileBackup("Error loading keys", userKeyFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_KeysLoaded = true;
|
|
|
|
_KeysLoaded = true;
|
|
|
@ -1260,10 +1273,7 @@ void CInterfaceManager::loadInterfaceConfig()
|
|
|
|
if (ClientCfg.R2EDEnabled) // in R2ED mode the CEditor class deals with it
|
|
|
|
if (ClientCfg.R2EDEnabled) // in R2ED mode the CEditor class deals with it
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
string filename = "save/interface_" + PlayerSelectedFileName + ".icfg";
|
|
|
|
string filename = getSaveFileName("interface", "icfg");
|
|
|
|
if (!CFile::fileExists(filename))
|
|
|
|
|
|
|
|
filename = "save/shared_interface.icfg";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadConfig(filename); // Invalidate coords of changed groups
|
|
|
|
loadConfig(filename); // Invalidate coords of changed groups
|
|
|
|
|
|
|
|
|
|
|
|
_ConfigLoaded = true;
|
|
|
|
_ConfigLoaded = true;
|
|
|
@ -1680,6 +1690,7 @@ bool CInterfaceManager::loadConfig (const string &filename)
|
|
|
|
uint32 nNbMode;
|
|
|
|
uint32 nNbMode;
|
|
|
|
CInterfaceConfig ic;
|
|
|
|
CInterfaceConfig ic;
|
|
|
|
bool lastInGameScreenResLoaded= false;
|
|
|
|
bool lastInGameScreenResLoaded= false;
|
|
|
|
|
|
|
|
uint32 nbLandmarks = 0;
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sint ver = f.serialVersion(ICFG_STREAM_VERSION);
|
|
|
|
sint ver = f.serialVersion(ICFG_STREAM_VERSION);
|
|
|
@ -1775,7 +1786,7 @@ bool CInterfaceManager::loadConfig (const string &filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Load user landmarks
|
|
|
|
// Load user landmarks
|
|
|
|
ContinentMngr.serialUserLandMarks(f);
|
|
|
|
nbLandmarks = ContinentMngr.serialUserLandMarks(f);
|
|
|
|
|
|
|
|
|
|
|
|
CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:INTERFACES:NB_BONUS_LANDMARKS" );
|
|
|
|
CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:INTERFACES:NB_BONUS_LANDMARKS" );
|
|
|
|
if ( pNL )
|
|
|
|
if ( pNL )
|
|
|
@ -1809,10 +1820,9 @@ bool CInterfaceManager::loadConfig (const string &filename)
|
|
|
|
catch(const NLMISC::EStream &)
|
|
|
|
catch(const NLMISC::EStream &)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
f.close();
|
|
|
|
f.close();
|
|
|
|
string sFileNameBackup = sFileName+"backup";
|
|
|
|
|
|
|
|
if (CFile::fileExists(sFileNameBackup))
|
|
|
|
createFileBackup("Config loading failed", sFileName);
|
|
|
|
CFile::deleteFile(sFileNameBackup);
|
|
|
|
|
|
|
|
CFile::moveFile(sFileNameBackup, sFileName);
|
|
|
|
|
|
|
|
nlwarning("Config loading failed : restore default");
|
|
|
|
nlwarning("Config loading failed : restore default");
|
|
|
|
vector<string> v;
|
|
|
|
vector<string> v;
|
|
|
|
if (!ClientCfg.R2EDEnabled)
|
|
|
|
if (!ClientCfg.R2EDEnabled)
|
|
|
@ -1823,6 +1833,35 @@ bool CInterfaceManager::loadConfig (const string &filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f.close();
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nbLandmarks > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// use copy for backup so on save proper shared/player icfg file is used
|
|
|
|
|
|
|
|
createFileBackup("Landmarks will be migrated to xml", sFileName, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if icfg is interface_player.icfg, then landmarks must also be loaded/saved to player file
|
|
|
|
|
|
|
|
if (nlstricmp(sFileName.substr(0, 12), "save/shared_") != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string lmfile = getSaveFileName("landmarks", "xml", false);
|
|
|
|
|
|
|
|
if (!CFile::fileExists(lmfile))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// create placeholder player landmarks file so saveLandmarks will use it
|
|
|
|
|
|
|
|
// even if shared landmarks file exists
|
|
|
|
|
|
|
|
COFile f;
|
|
|
|
|
|
|
|
if (f.open(lmfile, false, false, true))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string xml;
|
|
|
|
|
|
|
|
xml = "<?xml version=\"1.0\"?>\n<interface_config />";
|
|
|
|
|
|
|
|
f.serialBuffer((uint8 *)xml.c_str(), xml.size());
|
|
|
|
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// merge .icfg landmarks with landmarks.xml
|
|
|
|
|
|
|
|
loadLandmarks();
|
|
|
|
|
|
|
|
saveLandmarks();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// *** If saved resolution is different from the current one setuped, must fix positions in _Modes
|
|
|
|
// *** If saved resolution is different from the current one setuped, must fix positions in _Modes
|
|
|
|
if(lastInGameScreenResLoaded)
|
|
|
|
if(lastInGameScreenResLoaded)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1877,6 +1916,88 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CInterfaceManager::saveLandmarks(bool verbose) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ClientCfg.R2EDEnabled)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8 currMode = getMode();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string filename = getSaveFileName("landmarks", "xml");
|
|
|
|
|
|
|
|
if (verbose) CInterfaceManager::getInstance()->displaySystemInfo("Saving " + filename);
|
|
|
|
|
|
|
|
ret = saveLandmarks(filename);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CInterfaceManager::loadLandmarks()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Does the keys file exist ?
|
|
|
|
|
|
|
|
string filename = getSaveFileName("landmarks", "xml");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CIFile f;
|
|
|
|
|
|
|
|
string sFileName;
|
|
|
|
|
|
|
|
sFileName = NLMISC::CPath::lookup (filename, false);
|
|
|
|
|
|
|
|
if (sFileName.empty() || !f.open(sFileName))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
vector<string> xmlFilesToParse;
|
|
|
|
|
|
|
|
xmlFilesToParse.push_back (filename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//ContinentMngr.serialUserLandMarks(node);
|
|
|
|
|
|
|
|
if (!parseInterface (xmlFilesToParse, true))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createFileBackup("Error while loading landmarks", filename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CInterfaceManager::saveLandmarks(const std::string &filename) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nlinfo( "Saving landmarks : %s", filename.c_str() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
COFile f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// using temporary file, so no f.close() unless its a success
|
|
|
|
|
|
|
|
if (f.open(filename, false, false, true))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
COXml xmlStream;
|
|
|
|
|
|
|
|
xmlStream.init (&f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlDocPtr doc = xmlStream.getDocument ();
|
|
|
|
|
|
|
|
xmlNodePtr node = xmlNewDocNode(doc, NULL, (const xmlChar*)"interface_config", NULL);
|
|
|
|
|
|
|
|
xmlDocSetRootElement (doc, node);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContinentMngr.writeTo(node);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Flush the stream
|
|
|
|
|
|
|
|
xmlStream.flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Close the stream
|
|
|
|
|
|
|
|
f.close ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (const Exception &e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nlwarning ("Error while writing the file %s : %s.", filename.c_str(), e.what ());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
bool CInterfaceManager::saveConfig (bool verbose)
|
|
|
|
bool CInterfaceManager::saveConfig (bool verbose)
|
|
|
@ -1887,9 +2008,7 @@ bool CInterfaceManager::saveConfig (bool verbose)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint8 currMode = getMode();
|
|
|
|
uint8 currMode = getMode();
|
|
|
|
|
|
|
|
|
|
|
|
string filename = "save/interface_" + PlayerSelectedFileName + ".icfg";
|
|
|
|
string filename = getSaveFileName("interface", "icfg");
|
|
|
|
if (!CFile::fileExists(filename) && CFile::fileExists("save/shared_interface.icfg"))
|
|
|
|
|
|
|
|
filename = "save/shared_interface.icfg";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (verbose) CInterfaceManager::getInstance()->displaySystemInfo("Saving " + filename);
|
|
|
|
if (verbose) CInterfaceManager::getInstance()->displaySystemInfo("Saving " + filename);
|
|
|
|
ret = saveConfig(filename);
|
|
|
|
ret = saveConfig(filename);
|
|
|
@ -2004,8 +2123,13 @@ bool CInterfaceManager::saveConfig (const string &filename)
|
|
|
|
CTaskBarManager *pTBM= CTaskBarManager::getInstance();
|
|
|
|
CTaskBarManager *pTBM= CTaskBarManager::getInstance();
|
|
|
|
pTBM->serial(f);
|
|
|
|
pTBM->serial(f);
|
|
|
|
|
|
|
|
|
|
|
|
// Save user landmarks
|
|
|
|
//ContinentMngr.serialUserLandMarks(f);
|
|
|
|
ContinentMngr.serialUserLandMarks(f);
|
|
|
|
// empty landmarks block for compatibility
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
f.serialVersion(1);
|
|
|
|
|
|
|
|
uint32 numCont = 0;
|
|
|
|
|
|
|
|
f.serial(numCont);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Info Windows position.
|
|
|
|
// Info Windows position.
|
|
|
|
CInterfaceHelp::serialInfoWindows(f);
|
|
|
|
CInterfaceHelp::serialInfoWindows(f);
|
|
|
@ -2973,6 +3097,7 @@ class CAHSaveUI : public IActionHandler
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CInterfaceManager::getInstance()->saveKeys(true);
|
|
|
|
CInterfaceManager::getInstance()->saveKeys(true);
|
|
|
|
CInterfaceManager::getInstance()->saveConfig(true);
|
|
|
|
CInterfaceManager::getInstance()->saveConfig(true);
|
|
|
|
|
|
|
|
CInterfaceManager::getInstance()->saveLandmarks(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
REGISTER_ACTION_HANDLER (CAHSaveUI, "save_ui");
|
|
|
|
REGISTER_ACTION_HANDLER (CAHSaveUI, "save_ui");
|
|
|
@ -4136,3 +4261,40 @@ bool CInterfaceManager::parseTokens(ucstring& ucstr)
|
|
|
|
ucstr = str;
|
|
|
|
ucstr = str;
|
|
|
|
return true;;
|
|
|
|
return true;;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string CInterfaceManager::getNextBackupName(std::string filename)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string ts = getTimestampHuman("%Y-%m-%d");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ts.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string::size_type pos = filename.find_last_of('.');
|
|
|
|
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
|
|
|
|
filename = filename + "_" + ts + "_";
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
filename = filename.substr(0, pos) + "_" + ts + "_" + filename.substr(pos);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// filename_YYYY-MM-DD_000.ext
|
|
|
|
|
|
|
|
return CFile::findNewFile(filename);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CInterfaceManager::createFileBackup(const std::string &message, const std::string &filename, bool useCopy)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string backupName = getNextBackupName(filename);
|
|
|
|
|
|
|
|
nlwarning("%s: '%s'.", message.c_str(), filename.c_str());
|
|
|
|
|
|
|
|
if (!backupName.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (useCopy)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nlwarning("Backup copy saved as '%s'", backupName.c_str());
|
|
|
|
|
|
|
|
CFile::copyFile(backupName, filename);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nlwarning("File renamed to '%s'", backupName.c_str());
|
|
|
|
|
|
|
|
CFile::moveFile(backupName, filename);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|