Parse action handler condition for interface link in advance

This commit is contained in:
kaetemi 2013-07-28 03:02:07 +02:00
parent 2cc97d42e9
commit ae97a6bbde
2 changed files with 16 additions and 7 deletions

View file

@ -141,6 +141,7 @@ namespace NLGUI
std::string _ActionHandler; std::string _ActionHandler;
std::string _AHParams; std::string _AHParams;
std::string _AHCond; std::string _AHCond;
CInterfaceExprNode *_AHCondParsed;
CInterfaceGroup *_AHParent; CInterfaceGroup *_AHParent;
static TLinkList _LinkList; static TLinkList _LinkList;
TLinkList::iterator _ListEntry; TLinkList::iterator _ListEntry;

View file

@ -165,6 +165,7 @@ namespace NLGUI
_NextTriggeredLink[0] = _NextTriggeredLink[1] = NULL; _NextTriggeredLink[0] = _NextTriggeredLink[1] = NULL;
_Triggered[0] = _Triggered[1] = false; _Triggered[0] = _Triggered[1] = false;
_ParseTree = NULL; _ParseTree = NULL;
_AHCondParsed = NULL;
} }
//=========================================================== //===========================================================
@ -187,6 +188,9 @@ namespace NLGUI
_LinkList.erase(_ListEntry); _LinkList.erase(_ListEntry);
delete _ParseTree; delete _ParseTree;
_ParseTree = NULL;
delete _AHCondParsed;
_AHCondParsed = NULL;
} }
//=========================================================== //===========================================================
@ -243,7 +247,12 @@ namespace NLGUI
// //
_ActionHandler = actionHandler; _ActionHandler = actionHandler;
_AHParams = ahParams; _AHParams = ahParams;
nlassert(!_AHCondParsed);
_AHCond = ahCond; _AHCond = ahCond;
if (!ahCond.empty())
{
_AHCondParsed = CInterfaceExpr::buildExprTree(ahCond);
}
_AHParent = parentGroup; _AHParent = parentGroup;
return true; return true;
} }
@ -360,15 +369,14 @@ namespace NLGUI
if (!_ActionHandler.empty()) if (!_ActionHandler.empty())
{ {
// If there is a condition, test it. // If there is a condition, test it.
bool launch= true; bool launch = _AHCond.empty();
if(!_AHCond.empty()) if (_AHCondParsed)
{ {
launch= false; CInterfaceExprValue result;
CInterfaceExprValue result; _AHCondParsed->eval(result);
if(CInterfaceExpr::eval(_AHCond, result)) launch = result.getBool();
launch= result.getBool();
} }
if(launch) if (launch)
{ {
CAHManager::getInstance()->runActionHandler(_ActionHandler, _AHParent, _AHParams); CAHManager::getInstance()->runActionHandler(_ActionHandler, _AHParent, _AHParams);
// do not add any code after this line because this can be deleted !!!! // do not add any code after this line because this can be deleted !!!!