Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interface_v3 / parser_modules.cpp
blob37f93eda54725d245a5f8c273fca0a424e0ad27f
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2015 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "stdpch.h"
22 #include "parser_modules.h"
23 #include "nel/gui/view_text.h"
24 #include "nel/gui/interface_group.h"
25 #include "nel/gui/group_list.h"
26 #include "interface_ddx.h"
27 #include "macrocmd_manager.h"
28 #include "../commands.h"
29 #include "interface_3d_scene.h"
30 #include "nel/misc/i_xml.h"
31 #include "../continent_manager.h"
33 using namespace NLMISC;
35 #ifdef FINAL_VERSION
36 #include "../client_cfg.h"
37 #endif
39 extern CContinentManager ContinentMngr;
41 CIF3DSceneParser::CIF3DSceneParser()
43 parsingStage |= ( Resolved | GroupChildren );
46 CIF3DSceneParser::~CIF3DSceneParser()
50 bool CIF3DSceneParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup )
52 CInterface3DScene *pScene;
53 CXMLAutoPtr ptr;
55 pScene = new CInterface3DScene(CViewBase::TCtorParam());
57 // parse the group attributes
58 if (!pScene->parse(cur,parentGroup))
60 delete pScene;
61 // todo hulud interface syntax error
62 nlinfo ("cannot parse 3d scene attributes");
63 return false;
66 if (parentGroup)
68 CGroupList *pList = dynamic_cast<CGroupList*>(parentGroup);
69 if (pList != NULL)
70 pList->addChild (pScene);
71 else
72 parentGroup->addGroup (pScene);
74 else
76 std::string tmp = "no parent for "+pScene->getId();
77 // todo hulud interface syntax error
78 nlinfo (tmp.c_str());
79 delete pScene;
80 return false;
83 return true;
88 CIFDDXParser::CIFDDXParser()
90 parsingStage |= ( Resolved | GroupChildren );
93 CIFDDXParser::~CIFDDXParser()
97 bool CIFDDXParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup )
99 CInterfaceDDX *pDDX = NULL;
100 pDDX = new CInterfaceDDX;
101 if (pDDX)
103 if (!pDDX->parse(cur,parentGroup))
105 delete pDDX;
106 return false;
108 return true;
110 return false;
116 CActionCategoryParser::CActionCategoryParser()
118 parsingStage |= Unresolved;
121 CActionCategoryParser::~CActionCategoryParser()
125 bool CActionCategoryParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup )
127 // The category
128 CCategory category;
130 // Name
131 CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"name" ));
132 if (ptr)
133 category.Name = (const char*)ptr;
135 // Localized string
136 ptr = (char*) xmlGetProp( cur, (xmlChar*)"hardtext" );
137 if (ptr)
138 category.LocalizedName = (const char*)ptr;
140 // macroisable (per category)
141 ptr = (char*) xmlGetProp( cur, (xmlChar*)"macroisable" );
142 if (ptr)
143 category.Macroisable= CInterfaceElement::convertBool(ptr);
145 // Count number of action
146 uint ns = CIXml::countChildren(cur, "action");
147 category.BaseActions.resize( ns );
150 std::string actionCategoryContext = "game";
152 ptr = (char*) xmlGetProp( cur, (xmlChar*)"contexts" );
153 if (ptr)
154 actionCategoryContext = (const char *) ptr;
156 uint actionIndex = 0;
157 xmlNodePtr actionNode = CIXml::getFirstChildNode(cur, "action");
158 if (actionNode)
162 // The action
163 CBaseAction &action = category.BaseActions[actionIndex];
165 // list of contexts in which this action is valid
166 ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"contexts" );
167 if (ptr)
168 action.Contexts = (const char *) ptr;
169 else
170 action.Contexts = actionCategoryContext; // inherit from action category
172 // Repeat flag
173 ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"repeat" );
174 if (ptr)
175 fromString((const char*)ptr, action.Repeat);
177 // KeyDown flag
178 ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"keydown" );
179 if (ptr)
180 fromString((const char*)ptr, action.KeyDown);
182 // KeyUp flag
183 ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"keyup" );
184 if (ptr)
185 fromString((const char*)ptr, action.KeyUp);
187 // WaitForServer flag (wait an answer from server before continuing)
188 ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"waitforserver" );
189 if (ptr)
190 fromString((const char*)ptr, action.WaitForServer);
192 // Action name
193 ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"name" );
194 if (ptr)
195 action.Name = (const char*)ptr;
198 // Action localized name
199 ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"hardtext" );
200 if (ptr)
201 action.LocalizedName = (const char*)ptr;
203 // macroisable (per action)
204 action.Macroisable= true;
205 ptr = (char*) xmlGetProp( actionNode, (xmlChar*)"macroisable" );
206 if (ptr)
207 action.Macroisable = CInterfaceElement::convertBool(ptr);
210 // Read the parameters
211 action.Parameters.resize (CIXml::countChildren(actionNode, "parameter"));
213 uint parameterIndex = 0;
214 xmlNodePtr paramNode = CIXml::getFirstChildNode(actionNode, "parameter");
215 if (paramNode)
219 // The parameter
220 CBaseAction::CParameter &parameter = action.Parameters[parameterIndex];
222 // Parameter type
223 ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"type" );
224 if (ptr)
226 sint32 tType;
227 fromString((const char*)ptr, tType);
228 parameter.Type = (CBaseAction::CParameter::TType)tType;
231 // Parameter name
232 ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"name" );
233 if (ptr)
234 parameter.Name = (const char*)ptr;
236 // Parameter localized name
237 ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"hardtext" );
238 if (ptr)
239 parameter.LocalizedName = (const char*)ptr;
241 // Default value
242 ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"value" );
243 if (ptr)
244 parameter.DefaultValue = (const char*)ptr;
246 // Visible flag
247 //ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"visible" );
248 //if (ptr)
249 // fromString((const char*)ptr, parameter.Visible);
251 // Parse instance
252 xmlNodePtr instanceNode = CIXml::getFirstChildNode(paramNode, "instance");
253 if (instanceNode)
257 if (!parser->parseInstance(instanceNode))
259 // todo hulud interface syntax error
260 nlwarning("<CInterfaceParser::parseActionCategory> cannot create instance from template");
263 while((instanceNode = CIXml::getNextChildNode(instanceNode, "instance")));
266 parameter.Values.resize (CIXml::countChildren(paramNode, "value"));
268 uint valueIndex = 0;
269 xmlNodePtr valueNode = CIXml::getFirstChildNode(paramNode, "value");
270 if (valueNode)
274 // The value
275 CBaseAction::CParameter::CValue &value = parameter.Values[valueIndex];
277 // Value
278 ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"value" );
279 if (ptr)
280 value.Value = (const char*)ptr;
282 // list of contexts in which this value is valid
283 ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"contexts" );
284 if (ptr) value.Contexts = (const char*) ptr;
285 else value.Contexts = action.Contexts; // inherit context from action
287 // Localized value
288 ptr = (char*) xmlGetProp( valueNode, (xmlChar*)"hardtext" );
289 if (ptr)
290 value.LocalizedValue = (const char*)ptr;
292 valueIndex++;
294 while((valueNode = CIXml::getNextChildNode(valueNode, "value")));
297 parameterIndex++;
299 while((paramNode = CIXml::getNextChildNode(paramNode, "parameter")));
302 // Next action
303 actionIndex++;
305 while((actionNode = CIXml::getNextChildNode(actionNode, "action")));
308 // Add this category to the action manager
309 CActionsManager *actionManager = ActionsContext.getActionsManager (category.Name);
310 if (actionManager)
312 // They want to display debug shortcut in final version
313 #if FINAL_VERSION
314 if ((category.Name != "debug") || ClientCfg.AllowDebugCommands)
315 #else // FINAL_VERSION
316 if (1)
317 #endif // FINAL_VERSION
319 actionManager->removeCategory (category.Name);
320 actionManager->addCategory (category);
322 else
324 // Remove thoses actions from the manager
325 CAHManager *pAHFM = CAHManager::getInstance();
326 uint i;
327 for (i=0; i<category.BaseActions.size(); i++)
329 CAHManager::TFactoryMap::iterator ite = pAHFM->FactoryMap.find (category.BaseActions[i].Name);
330 if (ite != pAHFM->FactoryMap.end())
332 IActionHandler *ah = ite->second;
333 pAHFM->FactoryMap.erase (ite);
334 pAHFM->NameMap.erase (ah);
339 return true;
344 CCommandParser::CCommandParser()
346 parsingStage |= Unresolved;
349 CCommandParser::~CCommandParser()
353 bool CCommandParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup )
355 // Parse the key
356 bool ret = false;
358 // Localized string
359 CXMLAutoPtr ptrName((const char*) xmlGetProp( cur, (xmlChar*)"name" ));
360 if (ptrName)
362 // Does the action exist ?
363 std::string name = ptrName.str();
364 if (!ICommand::exists (name) || (CUserCommand::CommandMap.find(name) != CUserCommand::CommandMap.end()))
366 // Get the action
367 CXMLAutoPtr ptrAction((const char*) xmlGetProp( cur, (xmlChar*)"action" ));
368 if (ptrAction)
370 // Get the params
371 CXMLAutoPtr ptrParams((const char*) xmlGetProp( cur, (xmlChar*)"params" ));
372 if (ptrParams)
374 CUserCommand::createCommand (ptrName, ptrAction, ptrParams);
376 // if prop "ctrlchar" is declared with false, then disable ctrlchar for this command
377 CXMLAutoPtr prop((const char*) xmlGetProp( cur, (xmlChar*)"ctrlchar" ));
378 if( (const char*)prop && (CInterfaceElement::convertBool((const char*)prop)==false) )
379 ICommand::enableControlCharForCommand(ptrName.str(), false);
381 // Done
382 ret = true;
385 else
387 // todo hulud interface syntax error
388 nlwarning("<CInterfaceParser::parseCommand> No action for command : %s", (const char*)ptrName);
392 else
394 // todo hulud interface syntax error
395 nlwarning("<CInterfaceParser::parseCommand> No name for a key");
398 return ret;
403 CKeyParser::CKeyParser()
405 parsingStage |= Unresolved;
408 CKeyParser::~CKeyParser()
412 bool CKeyParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup )
414 // Parse the key
415 bool ret = false;
417 // Localized string
418 TKey key;
419 CXMLAutoPtr ptrKey((const char*) xmlGetProp( cur, (xmlChar*)"name" ));
420 if (ptrKey)
422 bool isNA = std::string((const char*)ptrKey) == std::string("N/A");
423 // Get the key from the string
424 key = CEventKey::getKeyFromString ((const char*)ptrKey);
425 if (key != KeyCount || isNA)
427 // Get the action
428 CXMLAutoPtr ptrAction((const char*) xmlGetProp( cur, (xmlChar*)"action" ));
429 if (ptrAction)
431 // Get the params
432 CXMLAutoPtr ptrParams((const char*) xmlGetProp( cur, (xmlChar*)"params" ));
434 // Get the modifiers
435 bool shift=false;
436 bool ctrl=false;
437 bool menu=false;
438 CXMLAutoPtr ptr((const char*) xmlGetProp( cur, (xmlChar*)"shift" ));
439 if (ptr)
440 fromString((const char*)ptr, shift);
441 ptr = (char*) xmlGetProp( cur, (xmlChar*)"ctrl" );
442 if (ptr)
443 fromString((const char*)ptr, ctrl);
444 ptr = (char*) xmlGetProp( cur, (xmlChar*)"menu" );
445 if (ptr)
446 fromString((const char*)ptr, menu);
448 // Repeat flag
449 bool repeat=false;
450 ptr = (char*) xmlGetProp( cur, (xmlChar*)"repeat" );
451 if (ptr)
452 fromString((const char*)ptr, repeat);
454 // Get the context
455 CXMLAutoPtr ptrContext((const char*) xmlGetProp( cur, (xmlChar*)"context" ));
456 std::string context = (const char*)ptrContext?(const char*)ptrContext:"";
458 // Add the action
459 CCombo combo;
460 combo.init(key, (TKeyButton)((shift?shiftKeyButton:noKeyButton)|(ctrl?ctrlKeyButton:noKeyButton)|(menu?altKeyButton:noKeyButton)));
461 ::CAction::CName actionName ((const char*)ptrAction, ptrParams?(const char*)ptrParams:"");
463 // Get the actions context manager
464 CActionsManager *actionManager = ActionsContext.getActionsManager(context);
465 if (actionManager)
467 bool canAdd= true;
469 // for keys.xml, don't replace already defined keys
470 if( parser->getDefine("key_def_no_replace")=="1" )
472 // if this combo key is already used for any action,
473 // or if this action is already bound to any key
474 if(isNA || actionManager->isComboAssociated(combo) || actionManager->isActionAssociated(actionName))
475 // don't replace
476 canAdd= false;
479 // add/replace the combo?
480 if(canAdd)
482 actionManager->addCombo(actionName, combo);
483 ::CAction *action = actionManager->getAction(actionName);
484 if (action && repeat) action->Repeat = true;
487 // if the action is to be shown in the Key interface
488 if( parser->getDefine("key_def_force_display")=="1" )
489 actionManager->forceDisplayForAction(actionName, true);
492 // Done
493 ret = true;
495 else
497 // todo hulud interface syntax error
498 nlwarning("<CInterfaceParser::parseKey> No action for key : %s", (const char*)ptrKey);
501 else
503 // todo hulud interface syntax error
504 nlwarning("<CInterfaceParser::parseKey> Unknown key : %s", (const char*)ptrKey);
507 else
509 // todo hulud interface syntax error
510 nlwarning("<CInterfaceParser::parseKey> No name for a key");
513 return ret;
518 CMacroParser::CMacroParser()
520 parsingStage |= Unresolved;
523 CMacroParser::~CMacroParser()
527 bool CMacroParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup )
529 H_AUTO(parseMacro)
531 CMacroCmd cmd;
532 if (cmd.readFrom(cur))
533 CMacroCmdManager::getInstance()->addMacro(cmd);
534 else
535 return false;
536 return true;
539 CLandmarkParser::CLandmarkParser()
541 parsingStage |= Unresolved;
544 CLandmarkParser::~CLandmarkParser()
548 bool CLandmarkParser::parse( xmlNodePtr cur, NLGUI::CInterfaceGroup *parentGroup )
550 H_AUTO(parseLandmark)
552 ContinentMngr.readFrom(cur);
554 return true;