1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
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>
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/>.
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
;
36 #include "../client_cfg.h"
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
;
55 pScene
= new CInterface3DScene(CViewBase::TCtorParam());
57 // parse the group attributes
58 if (!pScene
->parse(cur
,parentGroup
))
61 // todo hulud interface syntax error
62 nlinfo ("cannot parse 3d scene attributes");
68 CGroupList
*pList
= dynamic_cast<CGroupList
*>(parentGroup
);
70 pList
->addChild (pScene
);
72 parentGroup
->addGroup (pScene
);
76 std::string tmp
= "no parent for "+pScene
->getId();
77 // todo hulud interface syntax error
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
;
103 if (!pDDX
->parse(cur
,parentGroup
))
116 CActionCategoryParser::CActionCategoryParser()
118 parsingStage
|= Unresolved
;
121 CActionCategoryParser::~CActionCategoryParser()
125 bool CActionCategoryParser::parse( xmlNodePtr cur
, NLGUI::CInterfaceGroup
*parentGroup
)
131 CXMLAutoPtr
ptr((const char*) xmlGetProp( cur
, (xmlChar
*)"name" ));
133 category
.Name
= (const char*)ptr
;
136 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"hardtext" );
138 category
.LocalizedName
= (const char*)ptr
;
140 // macroisable (per category)
141 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"macroisable" );
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" );
154 actionCategoryContext
= (const char *) ptr
;
156 uint actionIndex
= 0;
157 xmlNodePtr actionNode
= CIXml::getFirstChildNode(cur
, "action");
163 CBaseAction
&action
= category
.BaseActions
[actionIndex
];
165 // list of contexts in which this action is valid
166 ptr
= (char*) xmlGetProp( actionNode
, (xmlChar
*)"contexts" );
168 action
.Contexts
= (const char *) ptr
;
170 action
.Contexts
= actionCategoryContext
; // inherit from action category
173 ptr
= (char*) xmlGetProp( actionNode
, (xmlChar
*)"repeat" );
175 fromString((const char*)ptr
, action
.Repeat
);
178 ptr
= (char*) xmlGetProp( actionNode
, (xmlChar
*)"keydown" );
180 fromString((const char*)ptr
, action
.KeyDown
);
183 ptr
= (char*) xmlGetProp( actionNode
, (xmlChar
*)"keyup" );
185 fromString((const char*)ptr
, action
.KeyUp
);
187 // WaitForServer flag (wait an answer from server before continuing)
188 ptr
= (char*) xmlGetProp( actionNode
, (xmlChar
*)"waitforserver" );
190 fromString((const char*)ptr
, action
.WaitForServer
);
193 ptr
= (char*) xmlGetProp( actionNode
, (xmlChar
*)"name" );
195 action
.Name
= (const char*)ptr
;
198 // Action localized name
199 ptr
= (char*) xmlGetProp( actionNode
, (xmlChar
*)"hardtext" );
201 action
.LocalizedName
= (const char*)ptr
;
203 // macroisable (per action)
204 action
.Macroisable
= true;
205 ptr
= (char*) xmlGetProp( actionNode
, (xmlChar
*)"macroisable" );
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");
220 CBaseAction::CParameter
¶meter
= action
.Parameters
[parameterIndex
];
223 ptr
= (char*) xmlGetProp( paramNode
, (xmlChar
*)"type" );
227 fromString((const char*)ptr
, tType
);
228 parameter
.Type
= (CBaseAction::CParameter::TType
)tType
;
232 ptr
= (char*) xmlGetProp( paramNode
, (xmlChar
*)"name" );
234 parameter
.Name
= (const char*)ptr
;
236 // Parameter localized name
237 ptr
= (char*) xmlGetProp( paramNode
, (xmlChar
*)"hardtext" );
239 parameter
.LocalizedName
= (const char*)ptr
;
242 ptr
= (char*) xmlGetProp( paramNode
, (xmlChar
*)"value" );
244 parameter
.DefaultValue
= (const char*)ptr
;
247 //ptr = (char*) xmlGetProp( paramNode, (xmlChar*)"visible" );
249 // fromString((const char*)ptr, parameter.Visible);
252 xmlNodePtr instanceNode
= CIXml::getFirstChildNode(paramNode
, "instance");
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"));
269 xmlNodePtr valueNode
= CIXml::getFirstChildNode(paramNode
, "value");
275 CBaseAction::CParameter::CValue
&value
= parameter
.Values
[valueIndex
];
278 ptr
= (char*) xmlGetProp( valueNode
, (xmlChar
*)"value" );
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
288 ptr
= (char*) xmlGetProp( valueNode
, (xmlChar
*)"hardtext" );
290 value
.LocalizedValue
= (const char*)ptr
;
294 while((valueNode
= CIXml::getNextChildNode(valueNode
, "value")));
299 while((paramNode
= CIXml::getNextChildNode(paramNode
, "parameter")));
305 while((actionNode
= CIXml::getNextChildNode(actionNode
, "action")));
308 // Add this category to the action manager
309 CActionsManager
*actionManager
= ActionsContext
.getActionsManager (category
.Name
);
312 // They want to display debug shortcut in final version
314 if ((category
.Name
!= "debug") || ClientCfg
.AllowDebugCommands
)
315 #else // FINAL_VERSION
317 #endif // FINAL_VERSION
319 actionManager
->removeCategory (category
.Name
);
320 actionManager
->addCategory (category
);
324 // Remove thoses actions from the manager
325 CAHManager
*pAHFM
= CAHManager::getInstance();
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
);
344 CCommandParser::CCommandParser()
346 parsingStage
|= Unresolved
;
349 CCommandParser::~CCommandParser()
353 bool CCommandParser::parse( xmlNodePtr cur
, NLGUI::CInterfaceGroup
*parentGroup
)
359 CXMLAutoPtr
ptrName((const char*) xmlGetProp( cur
, (xmlChar
*)"name" ));
362 // Does the action exist ?
363 std::string name
= ptrName
.str();
364 if (!ICommand::exists (name
) || (CUserCommand::CommandMap
.find(name
) != CUserCommand::CommandMap
.end()))
367 CXMLAutoPtr
ptrAction((const char*) xmlGetProp( cur
, (xmlChar
*)"action" ));
371 CXMLAutoPtr
ptrParams((const char*) xmlGetProp( cur
, (xmlChar
*)"params" ));
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);
387 // todo hulud interface syntax error
388 nlwarning("<CInterfaceParser::parseCommand> No action for command : %s", (const char*)ptrName
);
394 // todo hulud interface syntax error
395 nlwarning("<CInterfaceParser::parseCommand> No name for a key");
403 CKeyParser::CKeyParser()
405 parsingStage
|= Unresolved
;
408 CKeyParser::~CKeyParser()
412 bool CKeyParser::parse( xmlNodePtr cur
, NLGUI::CInterfaceGroup
*parentGroup
)
419 CXMLAutoPtr
ptrKey((const char*) xmlGetProp( cur
, (xmlChar
*)"name" ));
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
)
428 CXMLAutoPtr
ptrAction((const char*) xmlGetProp( cur
, (xmlChar
*)"action" ));
432 CXMLAutoPtr
ptrParams((const char*) xmlGetProp( cur
, (xmlChar
*)"params" ));
438 CXMLAutoPtr
ptr((const char*) xmlGetProp( cur
, (xmlChar
*)"shift" ));
440 fromString((const char*)ptr
, shift
);
441 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"ctrl" );
443 fromString((const char*)ptr
, ctrl
);
444 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"menu" );
446 fromString((const char*)ptr
, menu
);
450 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"repeat" );
452 fromString((const char*)ptr
, repeat
);
455 CXMLAutoPtr
ptrContext((const char*) xmlGetProp( cur
, (xmlChar
*)"context" ));
456 std::string context
= (const char*)ptrContext
?(const char*)ptrContext
:"";
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
);
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
))
479 // add/replace the combo?
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);
497 // todo hulud interface syntax error
498 nlwarning("<CInterfaceParser::parseKey> No action for key : %s", (const char*)ptrKey
);
503 // todo hulud interface syntax error
504 nlwarning("<CInterfaceParser::parseKey> Unknown key : %s", (const char*)ptrKey
);
509 // todo hulud interface syntax error
510 nlwarning("<CInterfaceParser::parseKey> No name for a key");
518 CMacroParser::CMacroParser()
520 parsingStage
|= Unresolved
;
523 CMacroParser::~CMacroParser()
527 bool CMacroParser::parse( xmlNodePtr cur
, NLGUI::CInterfaceGroup
*parentGroup
)
532 if (cmd
.readFrom(cur
))
533 CMacroCmdManager::getInstance()->addMacro(cmd
);
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
);