From b689c570525d41a459b6b52fd28e0c3c1d81f949 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 7 Jul 2012 19:49:13 +0200 Subject: [PATCH 01/16] CHANGED: #1471 Little cleanup in CInterfaceParser. --HG-- branch : gui-refactoring --- code/ryzom/client/src/commands.h | 6 +- .../src/interface_v3/ctrl_sheet_selection.h | 4 - .../src/interface_v3/interface_parser.cpp | 294 +----------------- .../src/interface_v3/interface_parser.h | 39 +-- 4 files changed, 16 insertions(+), 327 deletions(-) diff --git a/code/ryzom/client/src/commands.h b/code/ryzom/client/src/commands.h index 19e2bc02f..7b16f442c 100644 --- a/code/ryzom/client/src/commands.h +++ b/code/ryzom/client/src/commands.h @@ -37,12 +37,12 @@ public: public: uint KeywordsCount; std::string Action; - std::vector Keywords; + std::vector Keywords; }; - CUserCommand (const string &commandName, const ucstring &help, const ucstring &argsHelp); + CUserCommand (const std::string &commandName, const ucstring &help, const ucstring &argsHelp); - void addMode (const string &action, uint numArg, bool infiniteAgr, const std::vector &keywords); + void addMode (const std::string &action, uint numArg, bool infiniteAgr, const std::vector &keywords); // From ICommand virtual bool execute(const std::string &rawCommandString, const std::vector &args, NLMISC::CLog &log, bool quiet, bool human); diff --git a/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h b/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h index 3d1ea5ca7..febff220b 100644 --- a/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h +++ b/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h @@ -19,10 +19,6 @@ #ifndef CL_SHEET_CTRL_SELECTION_H #define CL_SHEET_CTRL_SELECTION_H - - -class CDBCtrlSheet; - namespace NLGUI { class IActionHandler; diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 5d8462e94..53798f910 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -14,129 +14,40 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . - - -// ---------------------------------------------------------------------------- - -#include "stdpch.h" - +#include "interface_parser.h" #include "nel/misc/i_xml.h" #include "nel/misc/file.h" #include "nel/misc/algo.h" #include "nel/misc/mem_stream.h" #include "nel/misc/factory.h" #include "nel/misc/big_file.h" - #include "nel/misc/xml_auto_ptr.h" - -#include "interface_parser.h" -#include "interface_observer.h" #include "nel/gui/interface_options.h" -#include "interface_options_ryzom.h" #include "nel/gui/interface_anim.h" -#include "interface_3d_scene.h" -// View -#include "nel/gui/view_bitmap.h" -#include "view_bitmap_faber_mp.h" -#include "nel/gui/view_bitmap_combo.h" -#include "nel/gui/view_text.h" -#include "nel/gui/view_text_formated.h" -#include "nel/gui/view_text_id.h" -#include "nel/gui/view_text_id_formated.h" -#include "view_radar.h" +#include "nel/gui/interface_expr.h" #include "nel/gui/view_pointer.h" -// DBView (View linked to the database) -#include "nel/gui/dbview_bar.h" -#include "nel/gui/dbview_bar3.h" -#include "nel/gui/dbview_number.h" -#include "nel/gui/dbview_quantity.h" -#include "nel/gui/dbview_digit.h" -// Ctrl -#include "nel/gui/ctrl_scroll.h" -#include "nel/gui/ctrl_button.h" -#include "nel/gui/ctrl_col_pick.h" -#include "nel/gui/ctrl_tooltip.h" -#include "nel/gui/ctrl_text_button.h" -#include "nel/gui/group_paragraph.h" // For CCtrlLink -// DBCtrl -#include "dbctrl_sheet.h" -// Group -#include "nel/gui/group_frame.h" -#include "group_career.h" #include "nel/gui/group_modal.h" -#include "group_modal_get_key.h" #include "nel/gui/group_list.h" -#include "nel/gui/group_tree.h" -#include "nel/gui/group_menu.h" #include "nel/gui/group_container.h" -#include "nel/gui/group_scrolltext.h" -#include "nel/gui/group_editbox.h" -#include "group_skills.h" -#include "group_html_forum.h" -#include "group_html_mail.h" -#include "group_html_qcm.h" -#include "group_html_cs.h" -#include "group_quick_help.h" -#include "group_compas.h" -#include "group_map.h" -#include "group_in_scene_user_info.h" -#include "group_in_scene_bubble.h" -#include "group_phrase_skill_filter.h" -#include "nel/gui/group_tab.h" -#include "nel/gui/group_table.h" -// DBGroup -#include "nel/gui/dbgroup_select_number.h" -#include "dbgroup_list_sheet.h" -#include "nel/gui/dbgroup_combo_box.h" -#include "dbgroup_list_sheet_trade.h" -#include "dbgroup_list_sheet_mission.h" -#include "guild_manager.h" // for CDBGroupListAscensor -#include "dbgroup_build_phrase.h" -#include "dbgroup_list_sheet_text_phrase.h" -#include "dbgroup_list_sheet_text_phrase_id.h" -#include "dbgroup_list_sheet_text_brick_composition.h" -#include "dbgroup_list_sheet_text_share.h" -#include "dbgroup_list_sheet_bonus_malus.h" -#include "dbgroup_list_sheet_icon_phrase.h" -// Misc. #include "nel/gui/interface_link.h" -#include "interface_ddx.h" -#include "../actions.h" -#include "macrocmd_manager.h" -#include "inventory_manager.h" -#include "task_bar_manager.h" -#include "../commands.h" #include "nel/gui/lua_helper.h" -using namespace NLGUI; #include "nel/gui/lua_ihm.h" -#include "lua_ihm_ryzom.h" -#include "../r2/editor.h" #include "nel/gui/lua_manager.h" +#include "interface_options_ryzom.h" +#include "interface_3d_scene.h" +#include "lua_ihm_ryzom.h" +#include "interface_ddx.h" +#include "macrocmd_manager.h" +#include "../commands.h" + #ifdef LUA_NEVRAX_VERSION #include "lua_ide_dll_nevrax/include/lua_ide_dll/ide_interface.h" // external debugger #endif const uint32 UI_CACHE_SERIAL_CHECK = (uint32) 'IUG_'; using namespace NLMISC; - -void badLuaParseMessageBox() -{ - NL3D::UDriver::TMessageBoxId ret = - CViewRenderer::getInstance()->getDriver()->systemMessageBox( "LUA files reading failed!\n" - "Some LUA files are corrupted, moved or may have been removed.\n" - "Ryzom may need to be restarted to run properly.\n" - "Would you like to quit now?", - "LUA reading failed!", - NL3D::UDriver::yesNoType, - NL3D::UDriver::exclamationIcon); - if (ret == NL3D::UDriver::yesId) - { - extern void quitCrashReport (); - quitCrashReport (); - exit (EXIT_FAILURE); - } -} +using namespace NLGUI; void saveXMLTree(COFile &f, xmlNodePtr node) { @@ -418,7 +329,7 @@ bool CInterfaceParser::parseInterface (const std::vector & strings, xmlNodePtr cur = NULL; bool saveParseResult = false; bool readFromUncompressedXML = true; - if (isFilename && ClientCfg.CacheUIParsing) + if( false /* isFilename && ClientCfg.CacheUIParsing */ ) { saveParseResult = true; std::string archive = CPath::lookup(nextFileName + "_compressed", false, false); @@ -699,12 +610,6 @@ bool CInterfaceParser::parseXMLDocument(xmlNodePtr root, bool reload) // todo hulud interface syntax error nlwarning ("could not parse vector"); } - else if ( !strcmp((char*)root->name,"observer") ) - { - if (!parseObserver(root,rootGroup)) - // todo hulud interface syntax error - nlwarning ("could not parse observer"); - } else if ( !strcmp((char*)root->name,"link") ) { if (!parseLink(root,rootGroup)) @@ -779,8 +684,8 @@ bool CInterfaceParser::parseXMLDocument(xmlNodePtr root, bool reload) { if(!parseLUAScript(root)) { - badLuaParseMessageBox(); nlwarning ("could not parse 'lua'"); + exit( EXIT_FAILURE ); } } @@ -1185,14 +1090,6 @@ bool CInterfaceParser::parseVector(xmlNodePtr cur) return step > 0 ? (i == index + size) : (i == index - size); } -// ---------------------------------------------------------------------------- -bool CInterfaceParser::parseObserver (xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - H_AUTO(parseObserver ) - - return IInterfaceObserverFactory::create(cur,parentGroup)!= NULL; -} - // ---------------------------------------------------------------------------- bool CInterfaceParser::parseLink(xmlNodePtr cur, CInterfaceGroup * parentGroup) { @@ -1481,8 +1378,6 @@ bool CInterfaceParser::parseGroupChildren(xmlNodePtr cur, CInterfaceGroup * pare ok = ok && parseInstance(cur); else if ( !strcmp((char*)cur->name,"vector") ) ok = ok && parseVector(cur); - else if ( !strcmp((char*)cur->name,"observer") ) - ok = ok && parseObserver(cur,parentGroup); else if ( !strcmp((char*)cur->name,"link") ) ok = ok && parseLink(cur,parentGroup); else if ( !strcmp((char*)cur->name,"scene3d") ) @@ -2129,7 +2024,6 @@ bool CInterfaceParser::initCoordsAndLuaScript() for (map::const_iterator itLua = _LuaClassAssociation.begin(); itLua != _LuaClassAssociation.end(); itLua++) { // execute the script on this group - CInterfaceManager *pIM= CInterfaceManager::getInstance(); CAHManager::getInstance()->runActionHandler("lua", itLua->first, itLua->second); } @@ -2573,147 +2467,6 @@ xmlNodePtr CInterfaceParser::searchTreeNodeInHierarchy(xmlNodePtr root, const ch return NULL; } - -// *************************************************************************** -bool CInterfaceParser::parseCareerGenerator(xmlNodePtr /* cur */) -{ - H_AUTO(parseCareerGenerator) - - // No more CAREER / Bricks!!! - // TODO_BRICK: remove this code. - return false; - - /* - CBrickManager *pBM= CBrickManager::getInstance(); - - CXMLAutoPtr prop; - - string templateCareer; - string templateJob; - string careerWindow; - string jobWindow; - string knownWindow; - xmlNodePtr rootTreeNode; - bool brickTypeFilter; - BRICK_TYPE::EBrickType brickType; - - if(! parseCareerGeneratorParams(cur, templateCareer, templateJob, careerWindow, jobWindow, rootTreeNode, - brickTypeFilter, brickType) ) - return false; - - - // knownWindow (optional) - prop = xmlGetProp (cur, (xmlChar*)"known_window"); - if(prop) knownWindow= (const char*)prop; - - - // **** Create all existing careers - xmlNodePtr nextSibling=cur; - for(uint careerId=0;careerIdgetCareer(brickType, (ROLES::ERole)careerId ); - - // if no filter, then dispplay all careers - if(career || !brickTypeFilter) - { - // Ok, create the xml node to instanciate the career - xmlNodePtr node= xmlNewNode(cur->ns, (xmlChar*)"instance" ); - xmlSetProp(node, (xmlChar*)"template", (xmlChar*)templateCareer.c_str()); - xmlSetProp(node, (xmlChar*)"careerid", (xmlChar*)toString(careerId).c_str()); - - // add it before rootContainer => next to nextSibling - xmlAddNextSibling (nextSibling, node); - nextSibling = nextSibling->next; - - // Create the associated tree node - xmlNodePtr careerTreeNode= xmlNewNode(cur->ns, (xmlChar*)"tree" ); - string windowId= careerWindow + toString(careerId); - xmlSetProp(careerTreeNode, (xmlChar*)"node", (xmlChar*)windowId.c_str()); - // link it to the root - xmlAddChild(rootTreeNode, careerTreeNode); - - - // Create the associated tree node for the known sentence if needed - if(!knownWindow.empty()) - { - xmlNodePtr knownTreeNode= xmlNewNode(cur->ns, (xmlChar*)"tree" ); - windowId= knownWindow + toString(careerId); - xmlSetProp(knownTreeNode, (xmlChar*)"node", (xmlChar*)windowId.c_str()); - // link it to the career - xmlAddChild(careerTreeNode, knownTreeNode); - } - - - // **** create all existing jobs. - sint numJobs; - - // parse all jobs if not brick type filter - if(!brickTypeFilter) - numJobs= BRICKS_MAX_JOB_PER_CAREER; - else - numJobs= career->Jobs.size(); - - // for all jobs to parse - for(sint jobIndex=0;jobIndexJobs[jobIndex].Job ); - - // if the job exist - if(jobId>=0) - { - // create the xml node to instanciate the job - xmlNodePtr node= xmlNewNode(cur->ns, (xmlChar*)"instance" ); - xmlSetProp(node, (xmlChar*)"template", (xmlChar*)templateJob.c_str()); - xmlSetProp(node, (xmlChar*)"careerid", (xmlChar*)toString(careerId).c_str()); - xmlSetProp(node, (xmlChar*)"jobid", (xmlChar*)toString(jobId).c_str()); - - // add it before rootContainer => next to nextSibling - xmlAddNextSibling (nextSibling, node); - nextSibling = nextSibling->next; - - // Create the associated tree node - xmlNodePtr jobTreeNode= xmlNewNode(cur->ns, (xmlChar*)"tree" ); - windowId= jobWindow + toString(careerId) + "_" + toString(jobId); - xmlSetProp(jobTreeNode, (xmlChar*)"node", (xmlChar*)windowId.c_str()); - // link it - xmlAddChild(careerTreeNode, jobTreeNode); - - - // Create the associated tree node for the known sentence if needed - if(!knownWindow.empty()) - { - xmlNodePtr knownTreeNode= xmlNewNode(cur->ns, (xmlChar*)"tree" ); - windowId= knownWindow + toString(careerId) + "_" + toString(jobId); - xmlSetProp(knownTreeNode, (xmlChar*)"node", (xmlChar*)windowId.c_str()); - // link it to the job - xmlAddChild(jobTreeNode, knownTreeNode); - } - } - } - } - } - - return true;*/ -} - - //================================================================== bool CInterfaceParser::parseAnim(xmlNodePtr cur, CInterfaceGroup * parentGroup) { @@ -3302,7 +3055,6 @@ CInterfaceElement *CInterfaceParser::createUIElement(const std::string &template return NULL; } - CInterfaceManager *pIM= CInterfaceManager::getInstance(); CInterfaceElement *pIE= CWidgetManager::getInstance()->getElementFromId(parentID); CInterfaceGroup * parentGroup = dynamic_cast(pIE); @@ -3405,28 +3157,13 @@ void CInterfaceParser::removeAllAnims() // *************************************************************************** void CInterfaceParser::removeAll() { - NLMISC::TTime initStart; - initStart = ryzomGetLocalTime (); removeAllLinks(); - //nlinfo ("%d seconds for removeAllLinks", (uint32)(ryzomGetLocalTime ()-initStart)/1000); - initStart = ryzomGetLocalTime (); CWidgetManager::getInstance()->removeAllOptions(); - //nlinfo ("%d seconds for removeAllOptions", (uint32)(ryzomGetLocalTime ()-initStart)/1000); - initStart = ryzomGetLocalTime (); removeAllProcedures(); - //nlinfo ("%d seconds for removeAllProcedures", (uint32)(ryzomGetLocalTime ()-initStart)/1000); - initStart = ryzomGetLocalTime (); removeAllDefines(); - //nlinfo ("%d seconds for removeAllDefines", (uint32)(ryzomGetLocalTime ()-initStart)/1000); - initStart = ryzomGetLocalTime (); removeAllTemplates(); - //nlinfo ("%d seconds for removeAllTemplates", (uint32)(ryzomGetLocalTime ()-initStart)/1000); - initStart = ryzomGetLocalTime (); removeAllAnims(); - //nlinfo ("%d seconds for removeAllAnims", (uint32)(ryzomGetLocalTime ()-initStart)/1000); - initStart = ryzomGetLocalTime (); CWidgetManager::getInstance()->removeAllMasterGroups(); - //nlinfo ("%d seconds for removeAllMasterGroups", (uint32)(ryzomGetLocalTime ()-initStart)/1000); _StyleMap.clear(); _CtrlSheetSelection.deleteGroups(); } @@ -3634,13 +3371,6 @@ bool CInterfaceParser::parseBrickCareerGenerator(xmlNodePtr /* cur */) } -// *************************************************************************** -void CInterfaceParser::createJobBricks(BRICK_TYPE::EBrickType brickType, xmlNodePtr &nextSibling, xmlNodePtr parentTreeNode, - const CBrickJob &/* job */, const string &/* templateBrick */, const string &/* baseWindowId */, sint32 /* xstart */) -{ -} - - // *************************************************************************** bool CInterfaceParser::parseBrickSuffixGenerator(xmlNodePtr /* cur */) { diff --git a/code/ryzom/client/src/interface_v3/interface_parser.h b/code/ryzom/client/src/interface_v3/interface_parser.h index 076fe56ff..693b2e6da 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.h +++ b/code/ryzom/client/src/interface_v3/interface_parser.h @@ -27,7 +27,6 @@ #include "game_share/brick_types.h" #include "nel/gui/lua_helper.h" #include "nel/gui/widget_manager.h" -using namespace NLGUI; namespace NLGUI { @@ -42,7 +41,7 @@ namespace NLGUI class CViewPointer; } -class CBrickJob; +using namespace NLGUI; // *************************************************************************** /** @@ -73,65 +72,32 @@ public: bool parseInterface (const std::vector &xmlFileNames, bool reload, bool isFilename = true, bool checkInData = false); bool parseXMLDocument (xmlNodePtr root, bool reload); - bool parseTemplateNode (xmlNodePtr node,xmlNodePtr instance,xmlNodePtr templ); - bool parseInstance(xmlNodePtr cur); - - // bool parseDynamicList (xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseVector (xmlNodePtr cur); - - bool parseObserver (xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseVariable (xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseOptions (xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseGroup (xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload); - bool parseGroupChildren(xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload); - bool parseControl (xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload); - bool parseLink (xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseView (xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload); - bool parseTreeNode (xmlNodePtr cur, CGroupContainer *parentGroup); - bool parseTree (xmlNodePtr cur, CWidgetManager::SMasterGroup *parentGroup); - bool parseDefine(xmlNodePtr cur); - bool parseProcedure(xmlNodePtr cur, bool reload); - bool parseSheetSelection(xmlNodePtr cur); - - bool parseCareerGenerator(xmlNodePtr cur); - bool parseAnim(xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseScene3D (xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseActionCategory (xmlNodePtr cur); - bool parseKey(xmlNodePtr cur); - bool parseMacro(xmlNodePtr cur); - bool parseCommand(xmlNodePtr cur); - bool parseBrickCareerGenerator(xmlNodePtr cur); - bool parseBrickSuffixGenerator(xmlNodePtr cur); - bool parseStyle(xmlNodePtr cur); - bool parseDDX (xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseLUAScript (xmlNodePtr cur); - bool setupTree (xmlNodePtr cur, CWidgetManager::SMasterGroup *parentGroup); bool setupTreeNode (xmlNodePtr cur, CGroupContainer *parentGroup); @@ -353,9 +319,6 @@ protected: BRICK_TYPE::EBrickType &brickType ); - void createJobBricks(BRICK_TYPE::EBrickType brickType, xmlNodePtr &nextSibling, xmlNodePtr parentTreeNode, - const CBrickJob &job, const std::string &templateBrick, const std::string &baseWindowId, sint32 xstart); - bool parseGeneratorRootContainer(xmlNodePtr cur, xmlNodePtr &rootTreeNode); From 750b069ff7cb083a793d67aabaf0a0e55bd49ea8 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 7 Jul 2012 20:38:45 +0200 Subject: [PATCH 02/16] CHANGED: #1471 Moved CSheetSelectionGroup and CSheetSelection to the GUI library. --HG-- branch : gui-refactoring --- .../include/nel/gui/ctrl_sheet_selection.h | 83 ++++++++++++++++ code/nel/src/gui/ctrl_sheet_selection.cpp | 98 +++++++++++++++++++ .../src/interface_v3/action_handler_game.cpp | 2 +- .../src/interface_v3/ctrl_sheet_selection.cpp | 95 ------------------ .../src/interface_v3/ctrl_sheet_selection.h | 83 ---------------- .../interface_expr_user_fct_items.cpp | 2 +- .../src/interface_v3/interface_manager.h | 2 +- .../src/interface_v3/interface_parser.cpp | 7 -- .../src/interface_v3/interface_parser.h | 2 +- 9 files changed, 185 insertions(+), 189 deletions(-) create mode 100644 code/nel/include/nel/gui/ctrl_sheet_selection.h create mode 100644 code/nel/src/gui/ctrl_sheet_selection.cpp delete mode 100644 code/ryzom/client/src/interface_v3/ctrl_sheet_selection.cpp delete mode 100644 code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h diff --git a/code/nel/include/nel/gui/ctrl_sheet_selection.h b/code/nel/include/nel/gui/ctrl_sheet_selection.h new file mode 100644 index 000000000..4ca52427e --- /dev/null +++ b/code/nel/include/nel/gui/ctrl_sheet_selection.h @@ -0,0 +1,83 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef CL_SHEET_CTRL_SELECTION_H +#define CL_SHEET_CTRL_SELECTION_H + +namespace NLGUI +{ + class IActionHandler; + + /** Infos about a selection group + */ + class CSheetSelectionGroup + { + public: + CSheetSelectionGroup(std::string name) : _Name(name), _Active(false), _TextureIndex(-1), _Color(NLMISC::CRGBA::White), _GlobalColorEnabled(true) {} + void setTexture(const std::string &texName); + sint32 getTextureIndex() const { return _TextureIndex; } + sint32 getTextureWidth() const { return _TextureWidth; } + sint32 getTextureHeight() const { return _TextureHeight; } + void setColor(NLMISC::CRGBA color) { _Color = color; } + NLMISC::CRGBA getColor() const { return _Color; } + void setActive(bool active) { _Active = active; } + bool isActive() const { return _Active; } + const std::string &getName() const { return _Name; } + void enableGlobalColor(bool enabled) { _GlobalColorEnabled = enabled; } + bool isGlobalColorEnabled() const { return _GlobalColorEnabled; } + private: + std::string _Name; + bool _Active; + sint32 _TextureIndex; // index for the selection texture + sint32 _TextureWidth; + sint32 _TextureHeight; + NLMISC::CRGBA _Color; // color that modulate the texture of selection + bool _GlobalColorEnabled; + }; + + /** Class to manage selection of sheet. + * Sheet are managed by groups, identified by their ID. + */ + class CCtrlSheetSelection + { + public: + // Add a group, and returns its index, or -1 if already created. + sint addGroup(const std::string &name); + // Get a group by its name (must exist) + CSheetSelectionGroup *getGroup(const std::string &name); + const CSheetSelectionGroup *getGroup(const std::string &name) const; + // Get a group by its index + CSheetSelectionGroup *getGroup(uint index); + const CSheetSelectionGroup *getGroup(uint index) const; + // Get the index of a group from its name, return -1 if not a group + sint getGroupIndex(const std::string &name) const; + // Deactivate all groups + void deactivateAll(); + // delete all groups + void deleteGroups(); + private: + // + typedef std::vector TGroupVect; + typedef std::map TGroupNameToIndex; + private: + TGroupVect _Groups; + TGroupNameToIndex _GroupNameToIndex; + }; + +} + +#endif diff --git a/code/nel/src/gui/ctrl_sheet_selection.cpp b/code/nel/src/gui/ctrl_sheet_selection.cpp new file mode 100644 index 000000000..ef63fc06a --- /dev/null +++ b/code/nel/src/gui/ctrl_sheet_selection.cpp @@ -0,0 +1,98 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include +#include +#include "nel/misc/types_nl.h" +#include "nel/misc/rgba.h" +#include "nel/gui/ctrl_sheet_selection.h" +#include "nel/gui/view_renderer.h" + +namespace NLGUI +{ + + //============================================================= + void CSheetSelectionGroup::setTexture(const std::string &texName) + { + CViewRenderer &rVR = *CViewRenderer::getInstance(); + _TextureIndex = rVR.getTextureIdFromName(texName); + rVR.getTextureSizeFromId(_TextureIndex, _TextureWidth, _TextureHeight); + } + + //============================================================= + void CCtrlSheetSelection::deleteGroups() + { + _Groups.clear(); + _GroupNameToIndex.clear(); + } + + //============================================================= + sint CCtrlSheetSelection::addGroup(const std::string &name) + { + if (getGroupIndex(name) != -1) + { + nlwarning(" Group inserted twice : %s", name.c_str()); + return - 1; + } + _Groups.push_back(CSheetSelectionGroup(name)); + _GroupNameToIndex[name] = (uint)_Groups.size() - 1; + return (sint)_Groups.size() - 1; + } + + //============================================================= + sint CCtrlSheetSelection::getGroupIndex(const std::string &name) const + { + TGroupNameToIndex::const_iterator it = _GroupNameToIndex.find(name); + return it == _GroupNameToIndex.end() ? - 1 : (sint) it->second; + } + + //============================================================= + CSheetSelectionGroup *CCtrlSheetSelection::getGroup(const std::string &name) + { + return getGroup(getGroupIndex(name)); + } + + //============================================================= + const CSheetSelectionGroup *CCtrlSheetSelection::getGroup(const std::string &name) const + { + return getGroup(getGroupIndex(name)); + } + + //============================================================= + CSheetSelectionGroup *CCtrlSheetSelection::getGroup(uint index) + { + if (index > _Groups.size()) + { + // nlwarning(" invalid group index"); + return NULL; + } + return &_Groups[index]; + } + + //============================================================= + const CSheetSelectionGroup *CCtrlSheetSelection::getGroup(uint index) const + { + if (index > _Groups.size()) + { + nlwarning(" invalid group index"); + return NULL; + } + return &_Groups[index]; + } + +} + + 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 4eb3a6cd7..6e6c3d2b8 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_game.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_game.cpp @@ -35,7 +35,7 @@ #include "bot_chat_page_dynamic_mission.h" #include "bot_chat_page_ring_sessions.h" #include "dbctrl_sheet.h" -#include "ctrl_sheet_selection.h" +#include "nel/gui/ctrl_sheet_selection.h" #include "nel/gui/interface_expr.h" #include "nel/gui/group_menu.h" #include "nel/gui/group_container.h" diff --git a/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.cpp b/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.cpp deleted file mode 100644 index f4c9b5f9f..000000000 --- a/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#include "stdpch.h" -#include "ctrl_sheet_selection.h" -#include "interface_manager.h" - -//============================================================= -void CSheetSelectionGroup::setTexture(const std::string &texName) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CViewRenderer &rVR = *CViewRenderer::getInstance(); - _TextureIndex = rVR.getTextureIdFromName(texName); - rVR.getTextureSizeFromId(_TextureIndex, _TextureWidth, _TextureHeight); -} - -//============================================================= -void CCtrlSheetSelection::deleteGroups() -{ - _Groups.clear(); - _GroupNameToIndex.clear(); -} - -//============================================================= -sint CCtrlSheetSelection::addGroup(const std::string &name) -{ - if (getGroupIndex(name) != -1) - { - nlwarning(" Group inserted twice : %s", name.c_str()); - return - 1; - } - _Groups.push_back(CSheetSelectionGroup(name)); - _GroupNameToIndex[name] = (uint)_Groups.size() - 1; - return (sint)_Groups.size() - 1; -} - -//============================================================= -sint CCtrlSheetSelection::getGroupIndex(const std::string &name) const -{ - TGroupNameToIndex::const_iterator it = _GroupNameToIndex.find(name); - return it == _GroupNameToIndex.end() ? - 1 : (sint) it->second; -} - -//============================================================= -CSheetSelectionGroup *CCtrlSheetSelection::getGroup(const std::string &name) -{ - return getGroup(getGroupIndex(name)); -} - -//============================================================= -const CSheetSelectionGroup *CCtrlSheetSelection::getGroup(const std::string &name) const -{ - return getGroup(getGroupIndex(name)); -} - -//============================================================= -CSheetSelectionGroup *CCtrlSheetSelection::getGroup(uint index) -{ - if (index > _Groups.size()) - { - // nlwarning(" invalid group index"); - return NULL; - } - return &_Groups[index]; -} - -//============================================================= -const CSheetSelectionGroup *CCtrlSheetSelection::getGroup(uint index) const -{ - if (index > _Groups.size()) - { - nlwarning(" invalid group index"); - return NULL; - } - return &_Groups[index]; -} - - - - diff --git a/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h b/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h deleted file mode 100644 index febff220b..000000000 --- a/code/ryzom/client/src/interface_v3/ctrl_sheet_selection.h +++ /dev/null @@ -1,83 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#ifndef CL_SHEET_CTRL_SELECTION_H -#define CL_SHEET_CTRL_SELECTION_H - -namespace NLGUI -{ - class IActionHandler; -} - -/** Infos about a selection group - */ -class CSheetSelectionGroup -{ -public: - CSheetSelectionGroup(std::string name) : _Name(name), _Active(false), _TextureIndex(-1), _Color(NLMISC::CRGBA::White), _GlobalColorEnabled(true) {} - void setTexture(const std::string &texName); - sint32 getTextureIndex() const { return _TextureIndex; } - sint32 getTextureWidth() const { return _TextureWidth; } - sint32 getTextureHeight() const { return _TextureHeight; } - void setColor(NLMISC::CRGBA color) { _Color = color; } - NLMISC::CRGBA getColor() const { return _Color; } - void setActive(bool active) { _Active = active; } - bool isActive() const { return _Active; } - const std::string &getName() const { return _Name; } - void enableGlobalColor(bool enabled) { _GlobalColorEnabled = enabled; } - bool isGlobalColorEnabled() const { return _GlobalColorEnabled; } -private: - std::string _Name; - bool _Active; - sint32 _TextureIndex; // index for the selection texture - sint32 _TextureWidth; - sint32 _TextureHeight; - NLMISC::CRGBA _Color; // color that modulate the texture of selection - bool _GlobalColorEnabled; -}; - -/** Class to manage selection of sheet. - * Sheet are managed by groups, identified by their ID. - */ -class CCtrlSheetSelection -{ -public: - // Add a group, and returns its index, or -1 if already created. - sint addGroup(const std::string &name); - // Get a group by its name (must exist) - CSheetSelectionGroup *getGroup(const std::string &name); - const CSheetSelectionGroup *getGroup(const std::string &name) const; - // Get a group by its index - CSheetSelectionGroup *getGroup(uint index); - const CSheetSelectionGroup *getGroup(uint index) const; - // Get the index of a group from its name, return -1 if not a group - sint getGroupIndex(const std::string &name) const; - // Deactivate all groups - void deactivateAll(); - // delete all groups - void deleteGroups(); -private: - // - typedef std::vector TGroupVect; - typedef std::map TGroupNameToIndex; -private: - TGroupVect _Groups; - TGroupNameToIndex _GroupNameToIndex; -}; - -#endif diff --git a/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp b/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp index 23807a361..64c2b5648 100644 --- a/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp +++ b/code/ryzom/client/src/interface_v3/interface_expr_user_fct_items.cpp @@ -22,7 +22,7 @@ #include "../sheet_manager.h" #include "nel/gui/interface_expr.h" #include "dbctrl_sheet.h" -#include "ctrl_sheet_selection.h" +#include "nel/gui/ctrl_sheet_selection.h" #include "dbgroup_list_sheet.h" #include "interface_manager.h" #include "sbrick_manager.h" diff --git a/code/ryzom/client/src/interface_v3/interface_manager.h b/code/ryzom/client/src/interface_v3/interface_manager.h index a142f4d17..121504846 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.h +++ b/code/ryzom/client/src/interface_v3/interface_manager.h @@ -36,7 +36,7 @@ // InterfaceV3 #include "interface_parser.h" -#include "ctrl_sheet_selection.h" +#include "nel/gui/ctrl_sheet_selection.h" #include "nel/gui/interface_options.h" #include "interface_config.h" #include "interface_pointer.h" diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 53798f910..7fb1bf405 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -642,13 +642,6 @@ bool CInterfaceParser::parseXMLDocument(xmlNodePtr root, bool reload) // todo hulud interface syntax error nlwarning ("could not parse sheet selection"); } - // Special Magic/Combat auto-generation - else if ( !strcmp((char*)root->name,"career_generator") ) - { - if (!parseCareerGenerator(root)) - // todo hulud interface syntax error - nlwarning ("could not parse 'career_generator'"); - } else if ( !strcmp((char*)root->name,"anim") ) { if (!parseAnim(root,rootGroup)) diff --git a/code/ryzom/client/src/interface_v3/interface_parser.h b/code/ryzom/client/src/interface_v3/interface_parser.h index 693b2e6da..e601b4058 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.h +++ b/code/ryzom/client/src/interface_v3/interface_parser.h @@ -21,7 +21,7 @@ #include "nel/misc/types_nl.h" #include "nel/3d/u_texture.h" -#include "ctrl_sheet_selection.h" +#include "nel/gui/ctrl_sheet_selection.h" #include "nel/gui/interface_link.h" #include "nel/misc/smart_ptr.h" #include "game_share/brick_types.h" From 18b83ad1fc0b20d6df4eaa7fc61e820f4e23cedc Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 7 Jul 2012 21:17:15 +0200 Subject: [PATCH 03/16] CHANGED: #1471 Some more cleanup in CInterfaceParser, removed some unused code, which also means less coupling and less refactoring to do :P --HG-- branch : gui-refactoring --- .../src/interface_v3/interface_parser.cpp | 186 ------------------ .../src/interface_v3/interface_parser.h | 18 -- 2 files changed, 204 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 7fb1bf405..3f0ba583b 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -654,19 +654,6 @@ bool CInterfaceParser::parseXMLDocument(xmlNodePtr root, bool reload) // todo hulud interface syntax error nlwarning ("could not parse 'scene3d'"); } - // Special BrickViewer - else if ( !strcmp((char*)root->name,"brick_career_generator") ) - { - if (!parseBrickCareerGenerator(root)) - // todo hulud interface syntax error - nlwarning ("could not parse 'brick_career_generator'"); - } - else if ( !strcmp((char*)root->name,"brick_suffix_generator") ) - { - if (!parseBrickSuffixGenerator(root)) - // todo hulud interface syntax error - nlwarning ("could not parse 'brick_suffix_generator'"); - } else if ( !strcmp((char*)root->name,"ddx") ) { if (!parseDDX(root,rootGroup)) @@ -3198,179 +3185,6 @@ bool CInterfaceParser::getProcedureAction(const std::string &procName, uint acti return false; } - -// *************************************************************************** -bool CInterfaceParser::parseGeneratorRootContainer(xmlNodePtr cur, xmlNodePtr &rootTreeNode) -{ - CXMLAutoPtr prop; - - // root_container - string rootContainer; - prop = xmlGetProp (cur, (xmlChar*)"root_container"); - if(prop) rootContainer= (const char*)prop; - else - { - // todo hulud interface syntax error - nlwarning("prop 'root_container' not found"); - return false; - } - - // search root container option - bool rootContainerSearch= false; - prop = xmlGetProp (cur, (xmlChar*)"root_container_search"); - if(prop) rootContainerSearch= CInterfaceElement::convertBool((const char*)prop); - - - // **** In all case, create or find the root_container - // if don't search but create the root container... - if(!rootContainerSearch) - { - rootTreeNode= xmlNewNode(cur->ns, (xmlChar*)"tree" ); - xmlSetProp(rootTreeNode, (xmlChar*)"node", (xmlChar*)rootContainer.c_str()); - // add it next to us now. - xmlAddNextSibling (cur, rootTreeNode); - } - else - { - rootTreeNode= NULL; - - // search from the cur place ALL the tree node that match rootContainer. - xmlNodePtr curSearch= cur; - curSearch= curSearch->next; - while(curSearch) - { - // if the node is a tree node. - if ( !strcmp((char*)curSearch->name,"tree") ) - { - // Test if him or one of his son match the name. - xmlNodePtr candidate= searchTreeNodeInHierarchy(curSearch, rootContainer.c_str()); - // found? stop! - if(candidate) - { - rootTreeNode= candidate; - break; - } - } - - curSearch= curSearch->next; - } - - // not found? abort - if(!rootTreeNode) - { - // todo hulud interface syntax error - nlwarning("career*_generator: thee root container '%s' was not found", rootContainer.c_str()); - return false; - } - } - - return true; -} - - -// *************************************************************************** -bool CInterfaceParser::parseCareerGeneratorParams(xmlNodePtr cur, - string &templateCareer, - string &templateJob, - string &careerWindow, - string &jobWindow, - xmlNodePtr &rootTreeNode, - bool &brickTypeFilter, - BRICK_TYPE::EBrickType &brickType - ) -{ - CXMLAutoPtr prop; - - // **** Parse the generator properties - // template_career - prop = xmlGetProp (cur, (xmlChar*)"template_career"); - if(prop) templateCareer= (const char*)prop; - else - { - // todo hulud interface syntax error - nlwarning("prop 'template_career' not found"); - return false; - } - - // template_job - prop = xmlGetProp (cur, (xmlChar*)"template_job"); - if(prop) templateJob= (const char*)prop; - else - { - // todo hulud interface syntax error - nlwarning("prop 'template_job' not found"); - return false; - } - - // career_window - prop = xmlGetProp (cur, (xmlChar*)"career_window"); - if(prop) careerWindow= (const char*)prop; - else - { - // todo hulud interface syntax error - nlwarning("prop 'career_window' not found"); - return false; - } - - // job_window - prop = xmlGetProp (cur, (xmlChar*)"job_window"); - if(prop) jobWindow= (const char*)prop; - else - { - // todo hulud interface syntax error - nlwarning("prop 'job_window' not found"); - return false; - } - - // get brick type - prop = xmlGetProp (cur, (xmlChar*)"brick_type"); - if(prop) - { - if( !strcmp(prop, "none") ) - { - brickTypeFilter= false; - } - else - { - brickTypeFilter= true; - brickType= BRICK_TYPE::toBrickType((const char*)prop); - if(brickType == BRICK_TYPE::UNKNOWN) - { - // todo hulud interface syntax error - nlwarning("'brick_type' UKNOWN"); - return false; - } - } - } - else - { - // todo hulud interface syntax error - nlwarning("prop 'brick_type' not found"); - return false; - } - - // create or search the root container. - if(!parseGeneratorRootContainer(cur, rootTreeNode)) - return false; - - return true; -} - - -// *************************************************************************** -bool CInterfaceParser::parseBrickCareerGenerator(xmlNodePtr /* cur */) -{ - return false; -} - - -// *************************************************************************** -bool CInterfaceParser::parseBrickSuffixGenerator(xmlNodePtr /* cur */) -{ - return false; -} - - // *************************************************************************** bool CInterfaceParser::parseStyle(xmlNodePtr cur) { diff --git a/code/ryzom/client/src/interface_v3/interface_parser.h b/code/ryzom/client/src/interface_v3/interface_parser.h index e601b4058..3b1bd4e4b 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.h +++ b/code/ryzom/client/src/interface_v3/interface_parser.h @@ -24,7 +24,6 @@ #include "nel/gui/ctrl_sheet_selection.h" #include "nel/gui/interface_link.h" #include "nel/misc/smart_ptr.h" -#include "game_share/brick_types.h" #include "nel/gui/lua_helper.h" #include "nel/gui/widget_manager.h" @@ -93,8 +92,6 @@ public: bool parseKey(xmlNodePtr cur); bool parseMacro(xmlNodePtr cur); bool parseCommand(xmlNodePtr cur); - bool parseBrickCareerGenerator(xmlNodePtr cur); - bool parseBrickSuffixGenerator(xmlNodePtr cur); bool parseStyle(xmlNodePtr cur); bool parseDDX (xmlNodePtr cur, CInterfaceGroup * parentGroup); bool parseLUAScript (xmlNodePtr cur); @@ -307,21 +304,6 @@ protected: typedef std::map TStyleMap; TStyleMap _StyleMap; -protected: - - bool parseCareerGeneratorParams(xmlNodePtr cur, - std::string &templateCareer, - std::string &templateJob, - std::string &careerWindow, - std::string &jobWindow, - xmlNodePtr &rootTreeNode, - bool &brickTypeFilter, - BRICK_TYPE::EBrickType &brickType - ); - - bool parseGeneratorRootContainer(xmlNodePtr cur, xmlNodePtr &rootTreeNode); - - protected: // LUA // ---------------------------------------------------------------------------------- From 5e68fa3e754ae965f3f915bc48081cb6991d94b5 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 8 Jul 2012 01:56:49 +0200 Subject: [PATCH 04/16] CHANGED: #1471 Classes derived from CInterfaceOptions are now instantiated using a factory. --HG-- branch : gui-refactoring --- code/nel/include/nel/gui/interface_options.h | 15 +++++++---- code/nel/src/gui/interface_options.cpp | 20 +++++++++++---- .../interface_v3/interface_options_ryzom.cpp | 5 +++- .../interface_v3/interface_options_ryzom.h | 4 ++- .../src/interface_v3/interface_parser.cpp | 25 ++++++------------- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/code/nel/include/nel/gui/interface_options.h b/code/nel/include/nel/gui/interface_options.h index 0ef9b0d6d..e46be901b 100644 --- a/code/nel/include/nel/gui/interface_options.h +++ b/code/nel/include/nel/gui/interface_options.h @@ -72,7 +72,12 @@ namespace NLGUI public: - CInterfaceOptions(); + // for factory construction + struct TCtorParam + { + }; + + CInterfaceOptions( const TCtorParam &/* param */ ); virtual ~CInterfaceOptions(); virtual bool parse (xmlNodePtr cur); @@ -103,7 +108,7 @@ namespace NLGUI { public: - COptionsLayer(); + COptionsLayer( const TCtorParam &/* param */ ); ~COptionsLayer(); virtual bool parse (xmlNodePtr cur); @@ -159,7 +164,7 @@ namespace NLGUI class COptionsContainerInsertion : public CInterfaceOptions { public: - COptionsContainerInsertion(); + COptionsContainerInsertion( const TCtorParam &/* param */ ); virtual bool parse (xmlNodePtr cur); sint32 TxId_R_Arrow; @@ -173,7 +178,7 @@ namespace NLGUI class COptionsContainerMove : public CInterfaceOptions { public: - COptionsContainerMove(); + COptionsContainerMove( const TCtorParam &/* param */ ); virtual bool parse (xmlNodePtr cur); sint32 TrackW; @@ -193,7 +198,7 @@ namespace NLGUI class COptionsList : public CInterfaceOptions { public: - COptionsList(); + COptionsList( const TCtorParam &/* param */ ); virtual bool parse (xmlNodePtr cur); uint getNumParams() const {return _NumParams;} diff --git a/code/nel/src/gui/interface_options.cpp b/code/nel/src/gui/interface_options.cpp index 28c1edafb..3423eb69b 100644 --- a/code/nel/src/gui/interface_options.cpp +++ b/code/nel/src/gui/interface_options.cpp @@ -19,6 +19,8 @@ #include "nel/gui/interface_element.h" #include "nel/gui/interface_options.h" #include "nel/gui/view_renderer.h" +#include "nel/misc/factory.h" +#include using namespace std; using namespace NLMISC; @@ -44,7 +46,7 @@ namespace NLGUI // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- - CInterfaceOptions::CInterfaceOptions() + CInterfaceOptions::CInterfaceOptions( const TCtorParam &/* param */ ) { } @@ -132,7 +134,9 @@ namespace NLGUI // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- - COptionsLayer::COptionsLayer() + NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsLayer, std::string, "layer"); + COptionsLayer::COptionsLayer( const TCtorParam ¶m ) : + CInterfaceOptions( param ) { TxId_TL = TxId_T = TxId_TR = TxId_L = TxId_R = TxId_Blank = TxId_BL = TxId_B = -2; TxId_BR = TxId_BL_Open = TxId_B_Open = TxId_BR_Open = TxId_EL_Open = TxId_EM_Open = TxId_ER_Open =-2; @@ -237,7 +241,9 @@ namespace NLGUI } // ---------------------------------------------------------------------------- - COptionsContainerInsertion::COptionsContainerInsertion() + NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsContainerInsertion, std::string, "container_insertion_opt"); + COptionsContainerInsertion::COptionsContainerInsertion( const TCtorParam ¶m ) : + CInterfaceOptions( param ) { TxId_R_Arrow = -2; TxId_L_Arrow = -2; @@ -264,7 +270,9 @@ namespace NLGUI // *************************************************************************** - COptionsContainerMove::COptionsContainerMove() + NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsContainerMove, std::string, "container_move_opt"); + COptionsContainerMove::COptionsContainerMove( const TCtorParam ¶m ) : + CInterfaceOptions( param ) { TrackW = -8; TrackH = 22; @@ -289,7 +297,9 @@ namespace NLGUI } // *************************************************************************** - COptionsList::COptionsList() + NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsList, std::string, "list"); + COptionsList::COptionsList( const TCtorParam ¶m ) : + CInterfaceOptions( param ) { _NumParams= 0; } diff --git a/code/ryzom/client/src/interface_v3/interface_options_ryzom.cpp b/code/ryzom/client/src/interface_v3/interface_options_ryzom.cpp index f4e0fe5cd..a2365fd1d 100644 --- a/code/ryzom/client/src/interface_v3/interface_options_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/interface_options_ryzom.cpp @@ -38,6 +38,7 @@ using namespace NLMISC; extern CEntityAnimationManager *EAM; +NLMISC_REGISTER_OBJECT(CInterfaceOptions, CMissionIconList, std::string, "mission_icons"); // *************************************************************************** bool CMissionIconList::parse(xmlNodePtr cur) @@ -90,7 +91,9 @@ bool CMissionIconList::parse(xmlNodePtr cur) // *************************************************************************** -COptionsAnimationSet::COptionsAnimationSet() +NLMISC_REGISTER_OBJECT(CInterfaceOptions, COptionsAnimationSet, std::string, "animation_set"); +COptionsAnimationSet::COptionsAnimationSet( const TCtorParam ¶m ) : +CInterfaceOptions( param ) { AnimationSet= NULL; } diff --git a/code/ryzom/client/src/interface_v3/interface_options_ryzom.h b/code/ryzom/client/src/interface_v3/interface_options_ryzom.h index 24d3b7524..a8bbd2767 100644 --- a/code/ryzom/client/src/interface_v3/interface_options_ryzom.h +++ b/code/ryzom/client/src/interface_v3/interface_options_ryzom.h @@ -26,6 +26,8 @@ using namespace NLGUI; class CMissionIconList : public CInterfaceOptions { public: + CMissionIconList( const TCtorParam ¶m ) : CInterfaceOptions( param ){} + ~CMissionIconList(){} virtual bool parse (xmlNodePtr cur); sint32 getBackTexID(uint index) const { return index >= IconBackTexID.size() ? -1 : IconBackTexID[index]; } sint32 getTexID(uint index) const { return index >= IconTexID.size() ? -1 : IconTexID[index]; } @@ -40,7 +42,7 @@ private: class COptionsAnimationSet : public CInterfaceOptions { public: - COptionsAnimationSet(); + COptionsAnimationSet( const TCtorParam &/* param */ ); // see code for important release note virtual ~COptionsAnimationSet(); virtual bool parse (xmlNodePtr cur); diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 3f0ba583b..195a70118 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -34,7 +34,6 @@ #include "nel/gui/lua_ihm.h" #include "nel/gui/lua_manager.h" -#include "interface_options_ryzom.h" #include "interface_3d_scene.h" #include "lua_ihm_ryzom.h" #include "interface_ddx.h" @@ -1207,28 +1206,18 @@ bool CInterfaceParser::parseOptions (xmlNodePtr cur, CInterfaceGroup * /* parent H_AUTO(parseOptions ) // build the options from type - CInterfaceOptions *options; + CInterfaceOptions *options = NULL; CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"type" )); if (ptr) { - if (nlstricmp(ptr.getDatas(), "layer") == 0) - options = new COptionsLayer; - else if (nlstricmp(ptr.getDatas(), "container_insertion_opt") == 0) - options = new COptionsContainerInsertion; - else if (nlstricmp(ptr.getDatas(), "container_move_opt") == 0) - options = new COptionsContainerMove; - else if (nlstricmp(ptr.getDatas(), "list") == 0) - options = new COptionsList; - else if (nlstricmp(ptr.getDatas(), "mission_icons") == 0) - options = new CMissionIconList; - else if (nlstricmp(ptr.getDatas(), "animation_set") == 0) - options = new COptionsAnimationSet; - else - options = new CInterfaceOptions; + options = NLMISC_GET_FACTORY( CInterfaceOptions, std::string ).createObject( std::string( (const char*)ptr ), CInterfaceOptions::TCtorParam() ); + + if( options == NULL ) + options = new CInterfaceOptions( CInterfaceOptions::TCtorParam() ); } else { - options = new CInterfaceOptions; + options = new CInterfaceOptions( CInterfaceOptions::TCtorParam() ); } CWidgetManager *wm = CWidgetManager::getInstance(); @@ -1277,7 +1266,7 @@ bool CInterfaceParser::parseGroup (xmlNodePtr cur, CInterfaceGroup * parentGroup CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"type" )); if (ptr) { - group = dynamic_cast(NLMISC_GET_FACTORY(CViewBase, std::string).createObject(string((const char*)ptr), CViewBase::TCtorParam())); + group = dynamic_cast( NLMISC_GET_FACTORY(CViewBase, std::string).createObject(string((const char*)ptr), CViewBase::TCtorParam()) ); if (group == NULL) { group = dynamic_cast(NLMISC_GET_FACTORY(CViewBase, std::string).createObject("interface_group", CViewBase::TCtorParam())); From d78ed9eac3ad9287e465533836e9dd9aa1239b89 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 9 Jul 2012 02:36:17 +0200 Subject: [PATCH 05/16] CHANGED: #1471 Modularized CInterfaceParser. It is now extendable with parser modules, so it can parse Ryzom game related stuff without the parser code having to be in the class itself. --HG-- branch : gui-refactoring --- code/ryzom/client/src/actions.cpp | 13 +- .../src/interface_v3/interface_manager.cpp | 11 + .../src/interface_v3/interface_parser.cpp | 642 ++---------------- .../src/interface_v3/interface_parser.h | 48 +- .../src/interface_v3/parser_modules.cpp | 526 ++++++++++++++ .../client/src/interface_v3/parser_modules.h | 77 +++ 6 files changed, 734 insertions(+), 583 deletions(-) create mode 100644 code/ryzom/client/src/interface_v3/parser_modules.cpp create mode 100644 code/ryzom/client/src/interface_v3/parser_modules.h diff --git a/code/ryzom/client/src/actions.cpp b/code/ryzom/client/src/actions.cpp index 599f7a637..9052455d8 100644 --- a/code/ryzom/client/src/actions.cpp +++ b/code/ryzom/client/src/actions.cpp @@ -747,11 +747,20 @@ const CActionsManager::CCategoryLocator *CActionsManager::getActionLocator (cons while ((ite != _ActionCategory.end ()) && (ite->first == name.Name)) { // Ref on the base action - const CBaseAction &baseAction = _Categories[ite->second.CategoryId].BaseActions[ite->second.BaseActionId]; + const CCategory &cat = _Categories[ite->second.CategoryId]; + uint baseActionId = ite->second.BaseActionId; + uint baseActionSize = cat.BaseActions.size(); + + if( ite->second.BaseActionId >= cat.BaseActions.size() ) + return NULL; + + const CBaseAction &baseAction = cat.BaseActions[ite->second.BaseActionId]; // Check parameters uint i; - for (i=0; idriver = driver; this->textcontext = textcontext; diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 195a70118..76d378963 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -34,11 +34,8 @@ #include "nel/gui/lua_ihm.h" #include "nel/gui/lua_manager.h" -#include "interface_3d_scene.h" #include "lua_ihm_ryzom.h" -#include "interface_ddx.h" -#include "macrocmd_manager.h" -#include "../commands.h" + #ifdef LUA_NEVRAX_VERSION #include "lua_ide_dll_nevrax/include/lua_ide_dll/ide_interface.h" // external debugger @@ -47,6 +44,7 @@ const uint32 UI_CACHE_SERIAL_CHECK = (uint32) 'IUG_'; using namespace NLMISC; using namespace NLGUI; +using namespace std; void saveXMLTree(COFile &f, xmlNodePtr node) { @@ -114,17 +112,6 @@ xmlNodePtr buildTree(CIFile &f) -// ---------------------------------------------------------------------------- - -extern CActionsManager Actions; // Actions Manager. -extern CActionsManager EditActions; // Actions Manager. -extern CActionsContext ActionsContext; // Actions context. - -// ---------------------------------------------------------------------------- - -using namespace NLMISC; -using namespace std; - // ---------------------------------------------------------------------------- // CRootGroup // ---------------------------------------------------------------------------- @@ -212,11 +199,13 @@ CInterfaceParser::CInterfaceParser() { // LUA _LuaState= NULL; + cacheUIParsing = false; } CInterfaceParser::~CInterfaceParser() { _LuaState = NULL; + removeAllModules(); } /** Convert a string into a memstream */ @@ -328,7 +317,7 @@ bool CInterfaceParser::parseInterface (const std::vector & strings, xmlNodePtr cur = NULL; bool saveParseResult = false; bool readFromUncompressedXML = true; - if( false /* isFilename && ClientCfg.CacheUIParsing */ ) + if( isFilename && cacheUIParsing ) { saveParseResult = true; std::string archive = CPath::lookup(nextFileName + "_compressed", false, false); @@ -457,11 +446,6 @@ bool CInterfaceParser::parseXMLDocument(xmlNodePtr root, bool reload) //parse templates xmlNodePtr curNode = root->children; - // Resize action category array - uint actionCategoryCount = CIXml::countChildren(curNode, "action_category"); - Actions.reserveCategories((uint)Actions.getCategories ().size()+actionCategoryCount); - EditActions.reserveCategories(1); - std::vector< CWidgetManager::SMasterGroup > &_MasterGroups = CWidgetManager::getInstance()->getAllMasterGroup(); while (curNode) @@ -515,30 +499,20 @@ bool CInterfaceParser::parseXMLDocument(xmlNodePtr root, bool reload) // todo hulud interface syntax error nlwarning ("could not parse define"); } - else if ( !strcmp((char*)curNode->name,"action_category") ) - { - if (!parseActionCategory(curNode)) - // todo hulud interface syntax error - nlwarning ("could not parse action_category"); - } - else if ( !strcmp((char*)curNode->name,"key") ) - { - parseKey(curNode); - } - else if ( !strcmp((char*)curNode->name,"macro") ) - { - parseMacro(curNode); - } - else if ( !strcmp((char*)curNode->name,"command") ) - { - parseCommand(curNode); - } else if ( !strcmp((char*)curNode->name,"style") ) { if (!parseStyle(curNode)) // todo hulud interface syntax error nlwarning ("could not parse 'style'"); } + else + { + IParserModule *module = getModuleFor( (char*)( curNode->name ) ); + if( module != NULL ){ + if( module->canParseInStage( IParserModule::Unresolved ) ) + module->parse( curNode, rootGroup ); + } + } curNode = curNode->next; } @@ -647,18 +621,6 @@ bool CInterfaceParser::parseXMLDocument(xmlNodePtr root, bool reload) // todo hulud interface syntax error nlwarning ("could not parse 'anim'"); } - else if ( !strcmp((char*)root->name,"scene3d") ) - { - if (!parseScene3D(root,rootGroup)) - // todo hulud interface syntax error - nlwarning ("could not parse 'scene3d'"); - } - else if ( !strcmp((char*)root->name,"ddx") ) - { - if (!parseDDX(root,rootGroup)) - // todo hulud interface syntax error - nlwarning ("could not parse 'ddx'"); - } else if ( !strcmp((char*)root->name,"lua") ) { if(!parseLUAScript(root)) @@ -667,6 +629,15 @@ bool CInterfaceParser::parseXMLDocument(xmlNodePtr root, bool reload) exit( EXIT_FAILURE ); } } + else + { + IParserModule *module = getModuleFor( (char*)( root->name ) ); + if( module != NULL ) + { + if( module->canParseInStage( IParserModule::Resolved ) ) + module->parse( root, rootGroup ); + } + } root = root->next; } @@ -860,78 +831,6 @@ bool CInterfaceParser::parseInstance(xmlNodePtr cur) return true; } -// ---------------------------------------------------------------------------- -/*bool CInterfaceParser::parseDynamicList(xmlNodePtr cur, CInterfaceGroup * parentGroup) -{ - CGroupListDynamic* li = new CGroupListDynamic; - if (!li->parse(cur,parentGroup)) - { - nlinfo("failed to parse a dynamic list"); - delete li; - return false; - } - - //copy the templates used by the instance of the list, otherwise it will be scratched after init - xmlNodePtr listChild = cur->children; - //listChild should exist here otherwise li->parse would have returned false - nlassert(listChild); - CXMLAutoPtr buf = (char*) xmlGetProp( listChild, (xmlChar*)"template" ); - if (!buf) - { - nlinfo(" dynamic list : the child instance has no template attribute"); - return false; - } - - for (vector::const_iterator it = _Templates.begin(); it != _Templates.end();it++) - { - CXMLAutoPtr ptr = (char*) xmlGetProp( *it, (xmlChar*)"name" ); - if (!ptr) - { - nlinfo("no name in a template node"); - return false; - } - if ( !strcmp(buf,ptr) ) - { - break; - } - } - xmlNodePtr node = xmlCopyNode(*it,1); - _KeptTemplates.push_back(node); - - CXMLAutoPtr dependencies = (char*) xmlGetProp( cur, (xmlChar*)"dependencies" ); - if (dependencies) - { - char *seekPtr = dependencies.getDatas(); - seekPtr = strtok(seekPtr," ,\t"); - while (seekPtr) - { - for (vector::const_iterator it = _Templates.begin(); it != _Templates.end();it++) - { - CXMLAutoPtr ptr = (char*) xmlGetProp( *it, (xmlChar*)"name" ); - if (!ptr) - { - nlinfo("no name in a template node"); - return false; - } - if ( !strcmp(seekPtr, ptr) ) - { - break; - } - } - xmlNodePtr node = xmlCopyNode(*it,1); - _KeptTemplates.push_back(node); - seekPtr = strtok(NULL," ,\t"); - } - } - - //add the list in the tree - if (parentGroup) - { - parentGroup->addGroup(li); - } - return true; -}*/ - // ---------------------------------------------------------------------------- bool CInterfaceParser::parseVector(xmlNodePtr cur) { @@ -1349,10 +1248,15 @@ bool CInterfaceParser::parseGroupChildren(xmlNodePtr cur, CInterfaceGroup * pare ok = ok && parseVector(cur); else if ( !strcmp((char*)cur->name,"link") ) ok = ok && parseLink(cur,parentGroup); - else if ( !strcmp((char*)cur->name,"scene3d") ) - ok = ok && parseScene3D(cur,parentGroup); - else if ( !strcmp((char*)cur->name,"ddx") ) - ok = ok && parseDDX(cur,parentGroup); + else + { + IParserModule *module = getModuleFor( (char*)( cur->name ) ); + if( module != NULL ) + { + if( module->canParseInStage( IParserModule::GroupChildren ) ) + ok = ok && module->parse( cur, parentGroup ); + } + } cur = cur->next; @@ -1610,6 +1514,42 @@ bool CInterfaceParser::setupTreeNode (xmlNodePtr cur, CGroupContainer * /* paren return true; } +void CInterfaceParser::addModule( std::string name, IParserModule *module ) +{ + std::map< std::string, IParserModule* >::iterator itr = + moduleMap.find( name ); + + if( itr != moduleMap.end() ) + { + nlwarning( "Tried to add parser module %s, which already exists.",name.c_str() ); + delete module; + return; + } + + module->setParser( this ); + moduleMap[ name ] = module; +} + +CInterfaceParser::IParserModule* CInterfaceParser::getModuleFor( std::string name ) const +{ + std::map< std::string, IParserModule* >::const_iterator itr = + moduleMap.find( name ); + if( itr == moduleMap.end() ) + return NULL; + else + return itr->second; +} + +void CInterfaceParser::removeAllModules() +{ + std::map< std::string, IParserModule* >::iterator itr; + for( itr = moduleMap.begin(); itr != moduleMap.end(); ++itr ) + { + delete itr->second; + } + moduleMap.clear(); +} + // ---------------------------------------------------------------------------- bool CInterfaceParser::setupTree (xmlNodePtr cur, CWidgetManager::SMasterGroup * /* parentGroup */) { @@ -2471,435 +2411,6 @@ bool CInterfaceParser::parseAnim(xmlNodePtr cur, CInterfaceGroup * parentGroup) return true; } -//================================================================== -bool CInterfaceParser::parseScene3D(xmlNodePtr cur, CInterfaceGroup * parentGroup) -{ - H_AUTO(parseScene3D) - - CInterface3DScene *pScene; - CXMLAutoPtr ptr; - - pScene = new CInterface3DScene(CViewBase::TCtorParam()); - - // parse the group attributes - if (!pScene->parse(cur,parentGroup)) - { - delete pScene; - // todo hulud interface syntax error - nlinfo ("cannot parse 3d scene attributes"); - return false; - } - - if (parentGroup) - { - CGroupList *pList = dynamic_cast(parentGroup); - if (pList != NULL) - pList->addChild (pScene); - else - parentGroup->addGroup (pScene); - } - else - { - string tmp = "no parent for "+pScene->getId(); - // todo hulud interface syntax error - nlinfo (tmp.c_str()); - delete pScene; - return false; - } - - return true; -} - -// ---------------------------------------------------------------------------- -bool CInterfaceParser::parseActionCategory(xmlNodePtr cur) -{ - H_AUTO(parseActionCategory) - - // The category - CCategory category; - - // Name - CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"name" )); - if (ptr) - category.Name = (const char*)ptr; - - // Localized string - ptr = (char*) xmlGetProp( cur, (xmlChar*)"hardtext" ); - if (ptr) - category.LocalizedName = (const char*)ptr; - - // macroisable (per category) - ptr = (char*) xmlGetProp( cur, (xmlChar*)"macroisable" ); - if (ptr) - category.Macroisable= CInterfaceElement::convertBool(ptr); - - // Count number of action - category.BaseActions.resize (CIXml::countChildren(cur, "action")); - - - std::string actionCategoryContext = "game"; - - ptr = (char*) xmlGetProp( cur, (xmlChar*)"contexts" ); - if (ptr) - actionCategoryContext = (const char *) ptr; - - uint actionIndex = 0; - xmlNodePtr actionNode = CIXml::getFirstChildNode(cur, "action"); - if (actionNode) - { - do - { - // The action - CBaseAction &action = category.BaseActions[actionIndex]; - - // list of contexts in which this action is valid - ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"contexts" ); - if (ptr) - action.Contexts = (const char *) ptr; - else - action.Contexts = actionCategoryContext; // inherit from action category - - // Repeat flag - ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"repeat" ); - if (ptr) - fromString((const char*)ptr, action.Repeat); - - // KeyDown flag - ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"keydown" ); - if (ptr) - fromString((const char*)ptr, action.KeyDown); - - // KeyUp flag - ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"keyup" ); - if (ptr) - fromString((const char*)ptr, action.KeyUp); - - // WaitForServer flag (wait an answer from server before continuing) - ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"waitforserver" ); - if (ptr) - fromString((const char*)ptr, action.WaitForServer); - - // Action name - ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"name" ); - if (ptr) - action.Name = (const char*)ptr; - - - // Action localized name - ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"hardtext" ); - if (ptr) - action.LocalizedName = (const char*)ptr; - - // macroisable (per action) - action.Macroisable= true; - ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"macroisable" ); - if (ptr) - action.Macroisable = CInterfaceElement::convertBool(ptr); - - - // Read the parameters - action.Parameters.resize (CIXml::countChildren(actionNode, "parameter")); - - uint parameterIndex = 0; - xmlNodePtr paramNode = CIXml::getFirstChildNode(actionNode, "parameter"); - if (paramNode) - { - do - { - // The parameter - CBaseAction::CParameter ¶meter = action.Parameters[parameterIndex]; - - // Parameter type - ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"type" ); - if (ptr) - { - sint32 tType; - fromString((const char*)ptr, tType); - parameter.Type = (CBaseAction::CParameter::TType)tType; - } - - // Parameter name - ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"name" ); - if (ptr) - parameter.Name = (const char*)ptr; - - // Parameter localized name - ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"hardtext" ); - if (ptr) - parameter.LocalizedName = (const char*)ptr; - - // Default value - ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"value" ); - if (ptr) - parameter.DefaultValue = (const char*)ptr; - - // Visible flag - //ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"visible" ); - //if (ptr) - // fromString((const char*)ptr, parameter.Visible); - - // Parse instance - xmlNodePtr instanceNode = CIXml::getFirstChildNode(paramNode, "instance"); - if (instanceNode) - { - do - { - if (!parseInstance(instanceNode)) - { - // todo hulud interface syntax error - nlwarning(" cannot create instance from template"); - } - } - while((instanceNode = CIXml::getNextChildNode(instanceNode, "instance"))); - } - - parameter.Values.resize (CIXml::countChildren(paramNode, "value")); - - uint valueIndex = 0; - xmlNodePtr valueNode = CIXml::getFirstChildNode(paramNode, "value"); - if (valueNode) - { - do - { - // The value - CBaseAction::CParameter::CValue &value = parameter.Values[valueIndex]; - - // Value - ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"value" ); - if (ptr) - value.Value = (const char*)ptr; - - // list of contexts in which this value is valid - ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"contexts" ); - if (ptr) value.Contexts = (const char*) ptr; - else value.Contexts = action.Contexts; // inherit context from action - - // Localized value - ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"hardtext" ); - if (ptr) - value.LocalizedValue = (const char*)ptr; - - valueIndex++; - } - while((valueNode = CIXml::getNextChildNode(valueNode, "value"))); - } - - parameterIndex++; - } - while((paramNode = CIXml::getNextChildNode(paramNode, "parameter"))); - } - - // Next action - actionIndex++; - } - while((actionNode = CIXml::getNextChildNode(actionNode, "action"))); - } - - // Add this category to the action manager - CActionsManager *actionManager = ActionsContext.getActionsManager (category.Name); - if (actionManager) - { -// They want to display debug shortcut in final version -#if FINAL_VERSION - if ((category.Name != "debug") || ClientCfg.AllowDebugCommands) -#else // FINAL_VERSION - if (1) -#endif // FINAL_VERSION - { - actionManager->removeCategory (category.Name); - actionManager->addCategory (category); - } - else - { - // Remove thoses actions from the manager - CAHManager *pAHFM = CAHManager::getInstance(); - uint i; - for (i=0; iFactoryMap.find (category.BaseActions[i].Name); - if (ite != pAHFM->FactoryMap.end()) - { - IActionHandler *ah = ite->second; - pAHFM->FactoryMap.erase (ite); - pAHFM->NameMap.erase (ah); - } - } - } - } - return true; -} - -//================================================================== -bool CInterfaceParser::parseKey(xmlNodePtr cur) -{ - H_AUTO(parseKey) - - // Parse the key - bool ret = false; - - // Localized string - TKey key; - CXMLAutoPtr ptrKey((const char*) xmlGetProp( cur, (xmlChar*)"name" )); - if (ptrKey) - { - bool isNA = string((const char*)ptrKey) == string("N/A"); - // Get the key from the string - key = CEventKey::getKeyFromString ((const char*)ptrKey); - if (key != KeyCount || isNA) - { - // Get the action - CXMLAutoPtr ptrAction((const char*) xmlGetProp( cur, (xmlChar*)"action" )); - if (ptrAction) - { - // Get the params - CXMLAutoPtr ptrParams((const char*) xmlGetProp( cur, (xmlChar*)"params" )); - - // Get the modifiers - bool shift=false; - bool ctrl=false; - bool menu=false; - CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"shift" )); - if (ptr) - fromString((const char*)ptr, shift); - ptr = (char*) xmlGetProp( cur, (xmlChar*)"ctrl" ); - if (ptr) - fromString((const char*)ptr, ctrl); - ptr = (char*) xmlGetProp( cur, (xmlChar*)"menu" ); - if (ptr) - fromString((const char*)ptr, menu); - - // Repeat flag - bool repeat=false; - ptr = (char*) xmlGetProp( cur, (xmlChar*)"repeat" ); - if (ptr) - fromString((const char*)ptr, repeat); - - // Get the context - CXMLAutoPtr ptrContext((const char*) xmlGetProp( cur, (xmlChar*)"context" )); - string context = (const char*)ptrContext?(const char*)ptrContext:""; - - // Add the action - CCombo combo; - combo.init(key, (TKeyButton)((shift?shiftKeyButton:noKeyButton)|(ctrl?ctrlKeyButton:noKeyButton)|(menu?altKeyButton:noKeyButton))); - ::CAction::CName actionName ((const char*)ptrAction, ptrParams?(const char*)ptrParams:""); - - // Get the actions context manager - CActionsManager *actionManager = ActionsContext.getActionsManager(context); - if (actionManager) - { - bool canAdd= true; - - // for keys.xml, don't replace already defined keys - if(getDefine("key_def_no_replace")=="1") - { - // if this combo key is already used for any action, - // or if this action is already bound to any key - if(isNA || actionManager->isComboAssociated(combo) || actionManager->isActionAssociated(actionName)) - // don't replace - canAdd= false; - } - - // add/replace the combo? - if(canAdd) - { - actionManager->addCombo(actionName, combo); - ::CAction *action = actionManager->getAction(actionName); - if (action && repeat) action->Repeat = true; - } - - // if the action is to be shown in the Key interface - if(getDefine("key_def_force_display")=="1") - actionManager->forceDisplayForAction(actionName, true); - } - - // Done - ret = true; - } - else - { - // todo hulud interface syntax error - nlwarning(" No action for key : %s", (const char*)ptrKey); - } - } - else - { - // todo hulud interface syntax error - nlwarning(" Unknown key : %s", (const char*)ptrKey); - } - } - else - { - // todo hulud interface syntax error - nlwarning(" No name for a key"); - } - - return ret; -} - -//================================================================== -bool CInterfaceParser::parseCommand(xmlNodePtr cur) -{ - H_AUTO(parseCommand) - - // Parse the key - bool ret = false; - - // Localized string - CXMLAutoPtr ptrName((const char*) xmlGetProp( cur, (xmlChar*)"name" )); - if (ptrName) - { - // Does the action exist ? - string name = ptrName; - if (!ICommand::exists (name) || (CUserCommand::CommandMap.find(name) != CUserCommand::CommandMap.end())) - { - // Get the action - CXMLAutoPtr ptrAction((const char*) xmlGetProp( cur, (xmlChar*)"action" )); - if (ptrAction) - { - // Get the params - CXMLAutoPtr ptrParams((const char*) xmlGetProp( cur, (xmlChar*)"params" )); - if (ptrParams) - { - CUserCommand::createCommand (ptrName, ptrAction, ptrParams); - - // if prop "ctrlchar" is declared with false, then disable ctrlchar for this command - CXMLAutoPtr prop((const char*) xmlGetProp( cur, (xmlChar*)"ctrlchar" )); - if( (const char*)prop && (CInterfaceElement::convertBool((const char*)prop)==false) ) - ICommand::enableControlCharForCommand(ptrName, false); - - // Done - ret = true; - } - } - else - { - // todo hulud interface syntax error - nlwarning(" No action for command : %s", (const char*)ptrName); - } - } - } - else - { - // todo hulud interface syntax error - nlwarning(" No name for a key"); - } - - return ret; -} - -//================================================================== -bool CInterfaceParser::parseMacro(xmlNodePtr cur) -{ - H_AUTO(parseMacro) - - CMacroCmd cmd; - if (cmd.readFrom(cur)) - CMacroCmdManager::getInstance()->addMacro(cmd); - else - return false; - return true; -} - //================================================================== void CInterfaceParser::freeXMLNodeAndSibblings(xmlNodePtr node) { @@ -3219,25 +2730,6 @@ bool CInterfaceParser::parseStyle(xmlNodePtr cur) return true; } -// *************************************************************************** -bool CInterfaceParser::parseDDX (xmlNodePtr cur, CInterfaceGroup * parentGroup) -{ - H_AUTO(parseDDX ) - - CInterfaceDDX *pDDX = NULL; - pDDX = new CInterfaceDDX; - if (pDDX) - { - if (!pDDX->parse(cur,parentGroup)) - { - delete pDDX; - return false; - } - return true; - } - return false; -} - // *************************************************************************** bool CInterfaceParser::parseLUAScript (xmlNodePtr cur) { diff --git a/code/ryzom/client/src/interface_v3/interface_parser.h b/code/ryzom/client/src/interface_v3/interface_parser.h index 3b1bd4e4b..c78d87577 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.h +++ b/code/ryzom/client/src/interface_v3/interface_parser.h @@ -55,6 +55,40 @@ class CInterfaceParser : public IParser { public: + + class IParserModule + { + public: + enum ParsingStage + { + None = 0, + Unresolved = 1, + Resolved = 2, + GroupChildren = 4 + }; + + IParserModule(){ + parser = NULL; + parsingStage = None; + } + virtual ~IParserModule(){} + + bool canParseInStage( ParsingStage stage ) + { + if( ( parsingStage & static_cast< uint >( stage ) ) != 0 ) + return true; + else + return false; + } + + virtual bool parse( xmlNodePtr cur, CInterfaceGroup *parentGroup ) = 0; + void setParser( CInterfaceParser *p ){ parser = p; } + + protected: + CInterfaceParser *parser; + uint parsingStage; + }; + CInterfaceParser(); virtual ~CInterfaceParser(); @@ -87,16 +121,14 @@ public: bool parseProcedure(xmlNodePtr cur, bool reload); bool parseSheetSelection(xmlNodePtr cur); bool parseAnim(xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseScene3D (xmlNodePtr cur, CInterfaceGroup * parentGroup); - bool parseActionCategory (xmlNodePtr cur); - bool parseKey(xmlNodePtr cur); - bool parseMacro(xmlNodePtr cur); - bool parseCommand(xmlNodePtr cur); bool parseStyle(xmlNodePtr cur); - bool parseDDX (xmlNodePtr cur, CInterfaceGroup * parentGroup); bool parseLUAScript (xmlNodePtr cur); bool setupTree (xmlNodePtr cur, CWidgetManager::SMasterGroup *parentGroup); bool setupTreeNode (xmlNodePtr cur, CGroupContainer *parentGroup); + + void addModule( std::string name, IParserModule *module ); + IParserModule* getModuleFor( std::string name ) const; + void removeAllModules(); // Called by each parse in parseXMLDocument bool solveDefine(xmlNodePtr cur); @@ -197,6 +229,8 @@ public: // return false if procedure not found, or if bad action index. return false if has some param variable (@0...) bool getProcedureAction( const std::string &procName, uint actionIndex, std::string &ah, std::string ¶ms ) const; + void setCacheUIParsing( bool b ){ cacheUIParsing = b; } + protected: /** @@ -305,6 +339,7 @@ protected: TStyleMap _StyleMap; protected: + std::map< std::string, IParserModule* > moduleMap; // LUA // ---------------------------------------------------------------------------------- // LUA Interface State. NB: The LUA environnement is not shared between Login/OutGame/InGame @@ -315,6 +350,7 @@ protected: std::set _LuaFileScripts; // Load A .lua. false if parse error. string 'error' contains the eventual error desc (but warning still displayed) bool loadLUA(const std::string &luaFile, std::string &error); + bool cacheUIParsing; }; #endif // RZ_INTERFACE_PARSER_H diff --git a/code/ryzom/client/src/interface_v3/parser_modules.cpp b/code/ryzom/client/src/interface_v3/parser_modules.cpp new file mode 100644 index 000000000..9d912bd77 --- /dev/null +++ b/code/ryzom/client/src/interface_v3/parser_modules.cpp @@ -0,0 +1,526 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "parser_modules.h" +#include "nel/gui/view_text.h" +#include "nel/gui/interface_group.h" +#include "nel/gui/group_list.h" +#include "interface_ddx.h" +#include "macrocmd_manager.h" +#include "../commands.h" +#include "interface_3d_scene.h" +#include "nel/misc/i_xml.h" + +using namespace NLMISC; + +CIF3DSceneParser::CIF3DSceneParser() +{ + parsingStage |= ( Resolved | GroupChildren ); +} + +CIF3DSceneParser::~CIF3DSceneParser() +{ +} + +bool CIF3DSceneParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup ) +{ + CInterface3DScene *pScene; + CXMLAutoPtr ptr; + + pScene = new CInterface3DScene(CViewBase::TCtorParam()); + + // parse the group attributes + if (!pScene->parse(cur,parentGroup)) + { + delete pScene; + // todo hulud interface syntax error + nlinfo ("cannot parse 3d scene attributes"); + return false; + } + + if (parentGroup) + { + CGroupList *pList = dynamic_cast(parentGroup); + if (pList != NULL) + pList->addChild (pScene); + else + parentGroup->addGroup (pScene); + } + else + { + std::string tmp = "no parent for "+pScene->getId(); + // todo hulud interface syntax error + nlinfo (tmp.c_str()); + delete pScene; + return false; + } + + return true; +} + + + +CIFDDXParser::CIFDDXParser() +{ + parsingStage |= ( Resolved | GroupChildren ); +} + +CIFDDXParser::~CIFDDXParser() +{ +} + +bool CIFDDXParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup ) +{ + CInterfaceDDX *pDDX = NULL; + pDDX = new CInterfaceDDX; + if (pDDX) + { + if (!pDDX->parse(cur,parentGroup)) + { + delete pDDX; + return false; + } + return true; + } + return false; +} + + + + +CActionCategoryParser::CActionCategoryParser() +{ + parsingStage |= Unresolved; +} + +CActionCategoryParser::~CActionCategoryParser() +{ +} + +bool CActionCategoryParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup ) +{ + // The category + CCategory category; + + // Name + CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"name" )); + if (ptr) + category.Name = (const char*)ptr; + + // Localized string + ptr = (char*) xmlGetProp( cur, (xmlChar*)"hardtext" ); + if (ptr) + category.LocalizedName = (const char*)ptr; + + // macroisable (per category) + ptr = (char*) xmlGetProp( cur, (xmlChar*)"macroisable" ); + if (ptr) + category.Macroisable= CInterfaceElement::convertBool(ptr); + + // Count number of action + uint ns = CIXml::countChildren(cur, "action"); + category.BaseActions.resize( ns ); + + + std::string actionCategoryContext = "game"; + + ptr = (char*) xmlGetProp( cur, (xmlChar*)"contexts" ); + if (ptr) + actionCategoryContext = (const char *) ptr; + + uint actionIndex = 0; + xmlNodePtr actionNode = CIXml::getFirstChildNode(cur, "action"); + if (actionNode) + { + do + { + // The action + CBaseAction &action = category.BaseActions[actionIndex]; + + // list of contexts in which this action is valid + ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"contexts" ); + if (ptr) + action.Contexts = (const char *) ptr; + else + action.Contexts = actionCategoryContext; // inherit from action category + + // Repeat flag + ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"repeat" ); + if (ptr) + fromString((const char*)ptr, action.Repeat); + + // KeyDown flag + ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"keydown" ); + if (ptr) + fromString((const char*)ptr, action.KeyDown); + + // KeyUp flag + ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"keyup" ); + if (ptr) + fromString((const char*)ptr, action.KeyUp); + + // WaitForServer flag (wait an answer from server before continuing) + ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"waitforserver" ); + if (ptr) + fromString((const char*)ptr, action.WaitForServer); + + // Action name + ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"name" ); + if (ptr) + action.Name = (const char*)ptr; + + + // Action localized name + ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"hardtext" ); + if (ptr) + action.LocalizedName = (const char*)ptr; + + // macroisable (per action) + action.Macroisable= true; + ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"macroisable" ); + if (ptr) + action.Macroisable = CInterfaceElement::convertBool(ptr); + + + // Read the parameters + action.Parameters.resize (CIXml::countChildren(actionNode, "parameter")); + + uint parameterIndex = 0; + xmlNodePtr paramNode = CIXml::getFirstChildNode(actionNode, "parameter"); + if (paramNode) + { + do + { + // The parameter + CBaseAction::CParameter ¶meter = action.Parameters[parameterIndex]; + + // Parameter type + ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"type" ); + if (ptr) + { + sint32 tType; + fromString((const char*)ptr, tType); + parameter.Type = (CBaseAction::CParameter::TType)tType; + } + + // Parameter name + ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"name" ); + if (ptr) + parameter.Name = (const char*)ptr; + + // Parameter localized name + ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"hardtext" ); + if (ptr) + parameter.LocalizedName = (const char*)ptr; + + // Default value + ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"value" ); + if (ptr) + parameter.DefaultValue = (const char*)ptr; + + // Visible flag + //ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"visible" ); + //if (ptr) + // fromString((const char*)ptr, parameter.Visible); + + // Parse instance + xmlNodePtr instanceNode = CIXml::getFirstChildNode(paramNode, "instance"); + if (instanceNode) + { + do + { + if (!parser->parseInstance(instanceNode)) + { + // todo hulud interface syntax error + nlwarning(" cannot create instance from template"); + } + } + while((instanceNode = CIXml::getNextChildNode(instanceNode, "instance"))); + } + + parameter.Values.resize (CIXml::countChildren(paramNode, "value")); + + uint valueIndex = 0; + xmlNodePtr valueNode = CIXml::getFirstChildNode(paramNode, "value"); + if (valueNode) + { + do + { + // The value + CBaseAction::CParameter::CValue &value = parameter.Values[valueIndex]; + + // Value + ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"value" ); + if (ptr) + value.Value = (const char*)ptr; + + // list of contexts in which this value is valid + ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"contexts" ); + if (ptr) value.Contexts = (const char*) ptr; + else value.Contexts = action.Contexts; // inherit context from action + + // Localized value + ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"hardtext" ); + if (ptr) + value.LocalizedValue = (const char*)ptr; + + valueIndex++; + } + while((valueNode = CIXml::getNextChildNode(valueNode, "value"))); + } + + parameterIndex++; + } + while((paramNode = CIXml::getNextChildNode(paramNode, "parameter"))); + } + + // Next action + actionIndex++; + } + while((actionNode = CIXml::getNextChildNode(actionNode, "action"))); + } + + // Add this category to the action manager + CActionsManager *actionManager = ActionsContext.getActionsManager (category.Name); + if (actionManager) + { +// They want to display debug shortcut in final version +#if FINAL_VERSION + if ((category.Name != "debug") || ClientCfg.AllowDebugCommands) +#else // FINAL_VERSION + if (1) +#endif // FINAL_VERSION + { + actionManager->removeCategory (category.Name); + actionManager->addCategory (category); + } + else + { + // Remove thoses actions from the manager + CAHManager *pAHFM = CAHManager::getInstance(); + uint i; + for (i=0; iFactoryMap.find (category.BaseActions[i].Name); + if (ite != pAHFM->FactoryMap.end()) + { + IActionHandler *ah = ite->second; + pAHFM->FactoryMap.erase (ite); + pAHFM->NameMap.erase (ah); + } + } + } + } + return true; +} + + + +CCommandParser::CCommandParser() +{ + parsingStage |= Unresolved; +} + +CCommandParser::~CCommandParser() +{ +} + +bool CCommandParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup ) +{ + // Parse the key + bool ret = false; + + // Localized string + CXMLAutoPtr ptrName((const char*) xmlGetProp( cur, (xmlChar*)"name" )); + if (ptrName) + { + // Does the action exist ? + std::string name = ptrName; + if (!ICommand::exists (name) || (CUserCommand::CommandMap.find(name) != CUserCommand::CommandMap.end())) + { + // Get the action + CXMLAutoPtr ptrAction((const char*) xmlGetProp( cur, (xmlChar*)"action" )); + if (ptrAction) + { + // Get the params + CXMLAutoPtr ptrParams((const char*) xmlGetProp( cur, (xmlChar*)"params" )); + if (ptrParams) + { + CUserCommand::createCommand (ptrName, ptrAction, ptrParams); + + // if prop "ctrlchar" is declared with false, then disable ctrlchar for this command + CXMLAutoPtr prop((const char*) xmlGetProp( cur, (xmlChar*)"ctrlchar" )); + if( (const char*)prop && (CInterfaceElement::convertBool((const char*)prop)==false) ) + ICommand::enableControlCharForCommand(ptrName, false); + + // Done + ret = true; + } + } + else + { + // todo hulud interface syntax error + nlwarning(" No action for command : %s", (const char*)ptrName); + } + } + } + else + { + // todo hulud interface syntax error + nlwarning(" No name for a key"); + } + + return ret; +} + + + +CKeyParser::CKeyParser() +{ + parsingStage |= Unresolved; +} + +CKeyParser::~CKeyParser() +{ +} + +bool CKeyParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup ) +{ + // Parse the key + bool ret = false; + + // Localized string + TKey key; + CXMLAutoPtr ptrKey((const char*) xmlGetProp( cur, (xmlChar*)"name" )); + if (ptrKey) + { + bool isNA = std::string((const char*)ptrKey) == std::string("N/A"); + // Get the key from the string + key = CEventKey::getKeyFromString ((const char*)ptrKey); + if (key != KeyCount || isNA) + { + // Get the action + CXMLAutoPtr ptrAction((const char*) xmlGetProp( cur, (xmlChar*)"action" )); + if (ptrAction) + { + // Get the params + CXMLAutoPtr ptrParams((const char*) xmlGetProp( cur, (xmlChar*)"params" )); + + // Get the modifiers + bool shift=false; + bool ctrl=false; + bool menu=false; + CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"shift" )); + if (ptr) + fromString((const char*)ptr, shift); + ptr = (char*) xmlGetProp( cur, (xmlChar*)"ctrl" ); + if (ptr) + fromString((const char*)ptr, ctrl); + ptr = (char*) xmlGetProp( cur, (xmlChar*)"menu" ); + if (ptr) + fromString((const char*)ptr, menu); + + // Repeat flag + bool repeat=false; + ptr = (char*) xmlGetProp( cur, (xmlChar*)"repeat" ); + if (ptr) + fromString((const char*)ptr, repeat); + + // Get the context + CXMLAutoPtr ptrContext((const char*) xmlGetProp( cur, (xmlChar*)"context" )); + std::string context = (const char*)ptrContext?(const char*)ptrContext:""; + + // Add the action + CCombo combo; + combo.init(key, (TKeyButton)((shift?shiftKeyButton:noKeyButton)|(ctrl?ctrlKeyButton:noKeyButton)|(menu?altKeyButton:noKeyButton))); + ::CAction::CName actionName ((const char*)ptrAction, ptrParams?(const char*)ptrParams:""); + + // Get the actions context manager + CActionsManager *actionManager = ActionsContext.getActionsManager(context); + if (actionManager) + { + bool canAdd= true; + + // for keys.xml, don't replace already defined keys + if( parser->getDefine("key_def_no_replace")=="1" ) + { + // if this combo key is already used for any action, + // or if this action is already bound to any key + if(isNA || actionManager->isComboAssociated(combo) || actionManager->isActionAssociated(actionName)) + // don't replace + canAdd= false; + } + + // add/replace the combo? + if(canAdd) + { + actionManager->addCombo(actionName, combo); + ::CAction *action = actionManager->getAction(actionName); + if (action && repeat) action->Repeat = true; + } + + // if the action is to be shown in the Key interface + if( parser->getDefine("key_def_force_display")=="1" ) + actionManager->forceDisplayForAction(actionName, true); + } + + // Done + ret = true; + } + else + { + // todo hulud interface syntax error + nlwarning(" No action for key : %s", (const char*)ptrKey); + } + } + else + { + // todo hulud interface syntax error + nlwarning(" Unknown key : %s", (const char*)ptrKey); + } + } + else + { + // todo hulud interface syntax error + nlwarning(" No name for a key"); + } + + return ret; +} + + + +CMacroParser::CMacroParser() +{ + parsingStage |= Unresolved; +} + +CMacroParser::~CMacroParser() +{ +} + +bool CMacroParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup ) +{ + H_AUTO(parseMacro) + + CMacroCmd cmd; + if (cmd.readFrom(cur)) + CMacroCmdManager::getInstance()->addMacro(cmd); + else + return false; + return true; +} + diff --git a/code/ryzom/client/src/interface_v3/parser_modules.h b/code/ryzom/client/src/interface_v3/parser_modules.h new file mode 100644 index 000000000..375fccb9d --- /dev/null +++ b/code/ryzom/client/src/interface_v3/parser_modules.h @@ -0,0 +1,77 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef PARSER_MODULES_H +#define PARSER_MODULES_H + +#include "interface_parser.h" + +class CIF3DSceneParser : public CInterfaceParser::IParserModule +{ +public: + CIF3DSceneParser(); + ~CIF3DSceneParser(); + + bool parse( xmlNodePtr cur, CInterfaceGroup *parentGroup ); +}; + +class CIFDDXParser : public CInterfaceParser::IParserModule +{ +public: + CIFDDXParser(); + ~CIFDDXParser(); + + bool parse( xmlNodePtr cur, CInterfaceGroup *parentGroup ); +}; + +class CActionCategoryParser : public CInterfaceParser::IParserModule +{ +public: + CActionCategoryParser(); + ~CActionCategoryParser(); + + bool parse( xmlNodePtr cur, CInterfaceGroup *parentGroup ); +}; + +class CCommandParser : public CInterfaceParser::IParserModule +{ +public: + CCommandParser(); + ~CCommandParser(); + + bool parse( xmlNodePtr cur, CInterfaceGroup *parentGroup ); +}; + +class CKeyParser : public CInterfaceParser::IParserModule +{ +public: + CKeyParser(); + ~CKeyParser(); + + bool parse( xmlNodePtr cur, CInterfaceGroup *parentGroup ); +}; + +class CMacroParser : public CInterfaceParser::IParserModule +{ +public: + CMacroParser(); + ~CMacroParser(); + + bool parse( xmlNodePtr cur, CInterfaceGroup *parentGroup ); +}; + +#endif From e11d65bedc07b32576701e133dfd2f88a5cb9633 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 9 Jul 2012 03:07:19 +0200 Subject: [PATCH 06/16] CHANGED: #1471 CInterfaceParser no longer depends on CLuaIHMRyzom. --HG-- branch : gui-refactoring --- .../client/src/interface_v3/interface_manager.cpp | 13 +++++++++++++ .../client/src/interface_v3/interface_manager.h | 2 ++ .../client/src/interface_v3/interface_parser.cpp | 4 ---- .../client/src/interface_v3/interface_parser.h | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index 39e942ede..87b1505dd 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -585,6 +585,19 @@ void CInterfaceManager::destroy () _Instance = NULL; } +void CInterfaceManager::initLUA() +{ + if( _LuaState != NULL ) + return; + + CInterfaceParser::initLUA(); + + if( _LuaState == NULL ) + return; + + CLuaIHMRyzom::RegisterRyzomFunctions( *_LuaState ); +} + // ------------------------------------------------------------------------------------------------ void CInterfaceManager::initLogin() { diff --git a/code/ryzom/client/src/interface_v3/interface_manager.h b/code/ryzom/client/src/interface_v3/interface_manager.h index 121504846..55c8d3f4a 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.h +++ b/code/ryzom/client/src/interface_v3/interface_manager.h @@ -146,6 +146,8 @@ public: void setInGame( bool i ); bool isInGame() const { return _InGame; } + void initLUA(); + /// initialize the whole login interface void initLogin(); diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 76d378963..8d66ae077 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -34,9 +34,6 @@ #include "nel/gui/lua_ihm.h" #include "nel/gui/lua_manager.h" -#include "lua_ihm_ryzom.h" - - #ifdef LUA_NEVRAX_VERSION #include "lua_ide_dll_nevrax/include/lua_ide_dll/ide_interface.h" // external debugger #endif @@ -2856,7 +2853,6 @@ void CInterfaceParser::initLUA() // register LUA methods CLuaIHM::registerAll(*_LuaState); - CLuaIHMRyzom::RegisterRyzomFunctions( *_LuaState ); } // *************************************************************************** diff --git a/code/ryzom/client/src/interface_v3/interface_parser.h b/code/ryzom/client/src/interface_v3/interface_parser.h index c78d87577..b28a2ab9e 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.h +++ b/code/ryzom/client/src/interface_v3/interface_parser.h @@ -344,8 +344,8 @@ protected: // ---------------------------------------------------------------------------------- // LUA Interface State. NB: The LUA environnement is not shared between Login/OutGame/InGame NLMISC::CSmartPtr _LuaState; - void initLUA(); - void uninitLUA(); + virtual void initLUA(); + void uninitLUA(); // List of script loaded (for reloadLua command) std::set _LuaFileScripts; // Load A .lua. false if parse error. string 'error' contains the eventual error desc (but warning still displayed) From dcadeb9095384da3cc4ddb45f3b1c3b3c7907772 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 9 Jul 2012 03:45:00 +0200 Subject: [PATCH 07/16] CHANGED: #1471 CInterfaceParser is now part of the Nel GUI library and is under the NLGUI namespace. --HG-- branch : gui-refactoring --- code/nel/include/nel/gui/interface_parser.h | 355 ++ code/nel/src/gui/interface_parser.cpp | 2885 ++++++++++++++++ code/ryzom/client/src/actions.h | 2 - .../src/interface_v3/interface_manager.h | 4 +- .../src/interface_v3/interface_parser.cpp | 2919 ----------------- .../src/interface_v3/interface_parser.h | 356 -- .../client/src/interface_v3/parser_modules.h | 4 +- 7 files changed, 3245 insertions(+), 3280 deletions(-) create mode 100644 code/nel/include/nel/gui/interface_parser.h create mode 100644 code/nel/src/gui/interface_parser.cpp delete mode 100644 code/ryzom/client/src/interface_v3/interface_parser.cpp delete mode 100644 code/ryzom/client/src/interface_v3/interface_parser.h diff --git a/code/nel/include/nel/gui/interface_parser.h b/code/nel/include/nel/gui/interface_parser.h new file mode 100644 index 000000000..2ddc359cd --- /dev/null +++ b/code/nel/include/nel/gui/interface_parser.h @@ -0,0 +1,355 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#ifndef RZ_INTERFACE_PARSER_H +#define RZ_INTERFACE_PARSER_H + +#include "nel/misc/types_nl.h" +#include "nel/3d/u_texture.h" +#include "nel/gui/ctrl_sheet_selection.h" +#include "nel/gui/interface_link.h" +#include "nel/misc/smart_ptr.h" +#include "nel/gui/lua_helper.h" +#include "nel/gui/widget_manager.h" + +namespace NLGUI +{ + class CInterfaceElement; + class CInterfaceGroup; + class CInterfaceOptions; + class CInterfaceLink; + class CCtrlBase; + class CGroupList; + class CGroupContainer; + class CInterfaceAnim; + class CViewPointer; + + // *************************************************************************** + /** + * class managing the interface parsing + * \author Matthieu 'TrapII' Besson + * \author Nevrax France + * \date 2002 + */ + + // this is the base class for CInterfaceManager + class CInterfaceParser : public IParser + { + + public: + + class IParserModule + { + public: + enum ParsingStage + { + None = 0, + Unresolved = 1, + Resolved = 2, + GroupChildren = 4 + }; + + IParserModule(){ + parser = NULL; + parsingStage = None; + } + virtual ~IParserModule(){} + + bool canParseInStage( ParsingStage stage ) + { + if( ( parsingStage & static_cast< uint >( stage ) ) != 0 ) + return true; + else + return false; + } + + virtual bool parse( xmlNodePtr cur, CInterfaceGroup *parentGroup ) = 0; + void setParser( CInterfaceParser *p ){ parser = p; } + + protected: + CInterfaceParser *parser; + uint parsingStage; + }; + + CInterfaceParser(); + virtual ~CInterfaceParser(); + + public: + + /** + * Parsing methods + */ + + /** Load a set of xml files + * \param isFilename true if xmlFileNames array contains the names of the xml file, false, if each + * array is a script itself + */ + bool parseInterface (const std::vector &xmlFileNames, bool reload, bool isFilename = true, bool checkInData = false); + + bool parseXMLDocument (xmlNodePtr root, bool reload); + bool parseTemplateNode (xmlNodePtr node,xmlNodePtr instance,xmlNodePtr templ); + bool parseInstance(xmlNodePtr cur); + bool parseVector (xmlNodePtr cur); + bool parseVariable (xmlNodePtr cur, CInterfaceGroup * parentGroup); + bool parseOptions (xmlNodePtr cur, CInterfaceGroup * parentGroup); + bool parseGroup (xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload); + bool parseGroupChildren(xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload); + bool parseControl (xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload); + bool parseLink (xmlNodePtr cur, CInterfaceGroup * parentGroup); + bool parseView (xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload); + bool parseTreeNode (xmlNodePtr cur, CGroupContainer *parentGroup); + bool parseTree (xmlNodePtr cur, CWidgetManager::SMasterGroup *parentGroup); + bool parseDefine(xmlNodePtr cur); + bool parseProcedure(xmlNodePtr cur, bool reload); + bool parseSheetSelection(xmlNodePtr cur); + bool parseAnim(xmlNodePtr cur, CInterfaceGroup * parentGroup); + bool parseStyle(xmlNodePtr cur); + bool parseLUAScript (xmlNodePtr cur); + bool setupTree (xmlNodePtr cur, CWidgetManager::SMasterGroup *parentGroup); + bool setupTreeNode (xmlNodePtr cur, CGroupContainer *parentGroup); + + void addModule( std::string name, IParserModule *module ); + IParserModule* getModuleFor( std::string name ) const; + void removeAllModules(); + + // Called by each parse in parseXMLDocument + bool solveDefine(xmlNodePtr cur); + bool solveStyle(xmlNodePtr cur); + + // Solve All define in a string. return false if some define not founs (defError contains this define) + bool solveDefine(const std::string &propVal, std::string &newPropVal, std::string &defError); + + // Called after template & options parsing + virtual void setupOptions() { } + + /** + * Initializer + */ + + bool initCoordsAndLuaScript (); + + /// Association builders : associate an element of the interface with the string ID of + /// another element used as reference for position values + void addParentPositionAssociation (CInterfaceElement *element, const std::string &parentID); + void addParentSizeAssociation (CInterfaceElement *element, const std::string &parentID); + void addParentSizeMaxAssociation (CInterfaceElement *element, const std::string &parentID); + + /// LUA Class Association builder : associate a lua script to a group (called for each group after every document parsed) + void addLuaClassAssociation(CInterfaceGroup *group, const std::string &luaScript); + + /** + * Accessors + */ + // access to control sheet selection + CCtrlSheetSelection &getCtrlSheetSelection() { return _CtrlSheetSelection; } + + /// \name Parameter variable + // @{ + const std::string &getDefine(const std::string &id) const; + bool isDefineExist(const std::string &id) const; + void setDefine(const std::string &id, const std::string &value); + // @} + + /// \name Dynamic links mgt + // @{ + /** Associate the given dynamic link with an ID + * \return true if succesful + */ + bool addLink(CInterfaceLink *link, const std::string &id); + /** remove the given link from its ID + * \return true if succesful + */ + bool removeLink(const std::string &id); + // @} + + /** create a template from an instance consisting of a single group + * \param templateName name of the template in the xml + * \param templateParams array containing each template parameter and its name + * \param number of template parameters in the array + */ + CInterfaceGroup *createGroupInstance(const std::string &templateName, const std::string &parentID, const std::pair *templateParams, uint numParams, bool updateLinks = true); + CInterfaceGroup *createGroupInstance(const std::string &templateName, const std::string &parentID, std::vector > &templateParams, bool updateLinks = true) + { + if (templateParams.size() > 0) + return createGroupInstance(templateName, parentID, &templateParams[0], (uint)templateParams.size(), updateLinks); + else + return createGroupInstance(templateName, parentID, NULL, 0, updateLinks); + } + + /** create a template from an instance consisting of a single control or group + * \param templateName name of the template in the xml + * \param templateParams array containing each template parameter and its name + * \param number of template parameters in the array + */ + CInterfaceElement *createUIElement(const std::string &templateName, const std::string &parentID, const std::pair *templateParams, uint numParams, bool updateLinks /* = true */); + CInterfaceElement *createUIElement(const std::string &templateName, const std::string &parentID, std::vector > &templateParams, bool updateLinks = true) + { + if (templateParams.size() > 0) + return createUIElement(templateName, parentID, &templateParams[0], (uint)templateParams.size(), updateLinks); + else + return createUIElement(templateName, parentID, NULL, 0, updateLinks); + } + + static void freeXMLNodeAndSibblings(xmlNodePtr node); + + // search a "tree" node in the hierarchy that match node. may return root! NULL if not found + static xmlNodePtr searchTreeNodeInHierarchy(xmlNodePtr root, const char *node); + + /// \name Clearing mgt + // @{ + void removeAllLinks(); + void removeAllProcedures(); + void removeAllDefines(); + void removeAllTemplates(); + void removeAllAnims(); + void removeAll(); + // @} + + // get info on procedure. return 0 if procedure not found + uint getProcedureNumActions( const std::string &procName ) const; + + // return false if procedure not found, or if bad action index. return false if has some param variable (@0...) + bool getProcedureAction( const std::string &procName, uint actionIndex, std::string &ah, std::string ¶ms ) const; + + void setCacheUIParsing( bool b ){ cacheUIParsing = b; } + + protected: + + /** + * Temporary data for init + */ + + /// vector storing parsed templates during init. At the end of init, only used template are kept + std::vector _Templates; + + + // map linking an element to its parent position used during init only + std::map _ParentPositionsMap; + std::map _ParentSizesMap; + std::map _ParentSizesMaxMap; + + // map linking a group to its lua script. used during init only + std::map _LuaClassAssociation; + + /** + * Data of initialized interface + */ + + /// Define Variable list + typedef std::map TVarMap; + typedef TVarMap::iterator ItVarMap; + typedef TVarMap::const_iterator CstItVarMap; + TVarMap _DefineMap; + + bool validDefineChar(char c) const; + + /// Procedure def + class CParamBlock + { + public: + // -1 if not a param id, but a string + sint32 NumParam; + std::string String; + + CParamBlock() + { + NumParam= -1; + } + }; + class CAction + { + public: + // a condition to launch this action handler (is an expression) + std::vector CondBlocks; + + // the action handler (may be proc!!) + std::string Action; + // A list of string/or param number => to build the final params at execution + std::vector ParamBlocks; + + // build a paramBlock from a string + void buildParamBlock (const std::string ¶ms); + // from ParamBlock, and a paramList (skip the 0th), build params. + void buildParams (const std::vector ¶mList, std::string ¶ms) const; + + void buildCondBlock (const std::string ¶ms); + + void buildCond (const std::vector ¶mList, std::string &cond) const; + + static void buildBlocks (const std::string &in, std::vector &out); + static void eval (const std::vector &inArgs, const std::vector &inBlocks, std::string &out); + + }; + class CProcedure + { + public: + // List of the actions + std::vector Actions; + }; + class CStyleProperty + { + public: + std::string Name; + std::string Value; + }; + class CStyle + { + public: + std::vector Properties; + }; + + + /// Procedure list + typedef std::map TProcedureMap; + typedef TProcedureMap::iterator ItProcedureMap; + typedef TProcedureMap::const_iterator CstItProcedureMap; + TProcedureMap _ProcedureMap; + + // mgt of sheet selections (inventory, buy, sell..) + CCtrlSheetSelection _CtrlSheetSelection; + + // Map of dynamic links + typedef std::map > TLinkMap; + TLinkMap _LinkMap; + + // Map of anims + typedef std::map TAnimMap; + TAnimMap _AnimMap; + + // Map of styles. + typedef std::map TStyleMap; + TStyleMap _StyleMap; + + protected: + std::map< std::string, IParserModule* > moduleMap; + // LUA + // ---------------------------------------------------------------------------------- + // LUA Interface State. NB: The LUA environnement is not shared between Login/OutGame/InGame + NLMISC::CSmartPtr _LuaState; + virtual void initLUA(); + void uninitLUA(); + // List of script loaded (for reloadLua command) + std::set _LuaFileScripts; + // Load A .lua. false if parse error. string 'error' contains the eventual error desc (but warning still displayed) + bool loadLUA(const std::string &luaFile, std::string &error); + bool cacheUIParsing; + }; + +} + +#endif // RZ_INTERFACE_PARSER_H diff --git a/code/nel/src/gui/interface_parser.cpp b/code/nel/src/gui/interface_parser.cpp new file mode 100644 index 000000000..22705fd64 --- /dev/null +++ b/code/nel/src/gui/interface_parser.cpp @@ -0,0 +1,2885 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include +#include "nel/misc/rgba.h" +#include "nel/gui/interface_parser.h" +#include "nel/misc/i_xml.h" +#include "nel/misc/file.h" +#include "nel/misc/algo.h" +#include "nel/misc/mem_stream.h" +#include "nel/misc/factory.h" +#include "nel/misc/big_file.h" +#include "nel/misc/xml_auto_ptr.h" +#include "nel/gui/interface_options.h" +#include "nel/gui/interface_anim.h" +#include "nel/gui/interface_expr.h" +#include "nel/gui/view_pointer.h" +#include "nel/gui/group_modal.h" +#include "nel/gui/group_list.h" +#include "nel/gui/group_container.h" +#include "nel/gui/interface_link.h" +#include "nel/gui/lua_helper.h" +#include "nel/gui/lua_ihm.h" +#include "nel/gui/lua_manager.h" + +#ifdef LUA_NEVRAX_VERSION + #include "lua_ide_dll_nevrax/include/lua_ide_dll/ide_interface.h" // external debugger +#endif +const uint32 UI_CACHE_SERIAL_CHECK = (uint32) 'IUG_'; + +using namespace NLMISC; +using namespace std; + +namespace NLGUI +{ + + void saveXMLTree(COFile &f, xmlNodePtr node) + { + // save node name + std::string name = (const char *) node->name; + f.serial(name); + // save properties + uint32 numProp = 0; + xmlAttrPtr currProp = node->properties; + while (currProp) + { + ++ numProp; + currProp = currProp->next; + } + f.serial(numProp); + currProp = node->properties; + while (currProp) + { + std::string name = (const char *) currProp->name; + f.serial(name); + CXMLAutoPtr ptr(xmlGetProp(node, currProp->name)); + std::string value = (const char *) ptr; + f.serial(value); + currProp = currProp->next; + } + uint32 numChildren = 0; + xmlNodePtr currChild = node->children; + while (currChild) + { + ++ numChildren; + currChild = currChild->next; + } + f.serial(numChildren); + currChild = node->children; + while (currChild) + { + saveXMLTree(f, currChild); + currChild = currChild->next; + } + } + + xmlNodePtr buildTree(CIFile &f) + { + // load node name + std::string name; + f.serial(name); + xmlNodePtr node = xmlNewNode(NULL, (const xmlChar *) name.c_str()); + // slod properties + uint32 numProp; + f.serial(numProp); + for(uint k = 0; k < numProp; ++k) + { + std::string name, value; + f.serial(name, value); + xmlSetProp(node, (const xmlChar *) name.c_str(), (const xmlChar *) value.c_str()); + } + uint32 numChildren; + f.serial(numChildren); + for(uint k = 0; k < numChildren; ++k) + { + xmlAddChild(node, buildTree(f)); + } + return node; + } + + + + // ---------------------------------------------------------------------------- + // CRootGroup + // ---------------------------------------------------------------------------- + + class CRootGroup : public CInterfaceGroup + { + public: + CRootGroup(const TCtorParam ¶m) + : CInterfaceGroup(param) + { } + + /// Destructor + virtual ~CRootGroup() { } + + virtual CInterfaceElement* getElement (const std::string &id) + { + if (_Id == id) + return this; + + if (id.substr(0, _Id.size()) != _Id) + return NULL; + + vector::const_iterator itv; + for (itv = _Views.begin(); itv != _Views.end(); itv++) + { + CViewBase *pVB = *itv; + if (pVB->getId() == id) + return pVB; + } + + vector::const_iterator itc; + for (itc = _Controls.begin(); itc != _Controls.end(); itc++) + { + CCtrlBase* ctrl = *itc; + if (ctrl->getId() == id) + return ctrl; + } + + // Accelerate + string sTmp = id; + sTmp = sTmp.substr(_Id.size()+1,sTmp.size()); + string::size_type pos = sTmp.find(':'); + if (pos != string::npos) + sTmp = sTmp.substr(0,pos); + + map::iterator it = _Accel.find(sTmp); + if (it != _Accel.end()) + { + CInterfaceGroup *pIG = it->second; + return pIG->getElement(id); + } + return NULL; + } + + virtual void addGroup (CInterfaceGroup *child, sint eltOrder = -1) + { + string sTmp = child->getId(); + sTmp = sTmp.substr(_Id.size()+1,sTmp.size()); + _Accel.insert(pair(sTmp, child)); + CInterfaceGroup::addGroup(child,eltOrder); + } + + virtual bool delGroup (CInterfaceGroup *child, bool dontDelete = false) + { + string sTmp = child->getId(); + sTmp = sTmp.substr(_Id.size()+1,sTmp.size()); + map::iterator it = _Accel.find(sTmp); + if (it != _Accel.end()) + { + _Accel.erase(it); + } + return CInterfaceGroup::delGroup(child,dontDelete); + } + + private: + map _Accel; + }; + + // ---------------------------------------------------------------------------- + // CInterfaceParser + // ---------------------------------------------------------------------------- + + // ---------------------------------------------------------------------------- + CInterfaceParser::CInterfaceParser() + { + // LUA + _LuaState= NULL; + cacheUIParsing = false; + } + + CInterfaceParser::~CInterfaceParser() + { + _LuaState = NULL; + removeAllModules(); + } + /** Convert a string into a memstream + */ + static void interfaceScriptAsMemStream(const std::string &script, CMemStream &destStream) + { + NLMISC::contReset(destStream); + if (destStream.isReading()) // we must be sure that we are reading the stream + { + destStream.invert(); + } + destStream.seek(0, NLMISC::IStream::begin); + if (script.empty()) return; + destStream.serialBuffer(const_cast((const uint8 *) &script[0]), (uint)script.size()); + destStream.invert(); + destStream.seek(0, NLMISC::IStream::begin); + } + + // ---------------------------------------------------------------------------- + bool CInterfaceParser::parseInterface (const std::vector & strings, bool reload, bool isFilename, bool checkInData) + { + bool ok; + + bool needCheck = false; + + #if !FINAL_VERSION + needCheck = false; + #endif + + // TestYoyo. UnHide For Parsing Profile + /* + NLMISC::CHTimer::startBench(); + { + + H_AUTO(parseInterface); + */ + + //ignore the content of tags containing only white space + xmlKeepBlanksDefault(0); + //parse all interface files and build a single xml document + xmlNodePtr globalEnclosing; + nlassert (strings.size()); + CIXml read; + string nextFileName; + static const char *SCRIPT_AS_STRING = "