UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_actions.cpp File Reference
#include "ui_main.h"
#include "ui_internal.h"
#include "ui_parse.h"
#include "ui_input.h"
#include "ui_node.h"
#include "ui_actions.h"
#include "ui_lua.h"
#include "node/ui_node_abstractnode.h"
#include "../cl_language.h"

Go to the source code of this file.

Data Structures

struct  ui_typedActionToken_s
 

Typedefs

typedef struct
ui_typedActionToken_s 
ui_typedActionToken_t
 

Functions

static void UI_ExecuteActions (const uiAction_t *firstAction, uiCallContext_t *context)
 Execute a tree of actions from a source. More...
 
static void UI_CheckActionTokenTypeSanity (void)
 Check if the action token list is sorted by alphabet, else dichotomic search can't work. More...
 
int UI_GetActionTokenType (const char *token, int group)
 return an action type from a token, and a group More...
 
static const char * UI_GenCommandReadProperty (const char *input, char *output, int outputSize)
 read a property name from an input buffer to an output More...
 
int UI_GetParamNumber (const uiCallContext_t *context)
 
const char * UI_GetParam (const uiCallContext_t *context, int paramID)
 
const char * UI_GenInjectedString (const char *input, bool addNewLine, const uiCallContext_t *context)
 Replace injection identifiers (e.g. <eventParam>) by a value. More...
 
static void UI_NodeSetPropertyFromActionValue (uiNode_t *node, const value_t *property, const uiCallContext_t *context, uiAction_t *value)
 
static void UI_ExecuteSetAction (const uiAction_t *action, const uiCallContext_t *context)
 
static void UI_ExecuteCallAction (const uiAction_t *action, const uiCallContext_t *context)
 
uiValue_tUI_GetVariable (const uiCallContext_t *context, int relativeVarId)
 Return a variable from the context. More...
 
static void UI_ReleaseVariable (uiValue_t *variable)
 
static void UI_ExecuteAction (const uiAction_t *action, uiCallContext_t *context)
 Execute an action from a source. More...
 
void UI_ExecuteConFuncActions (uiNode_t *source, const uiAction_t *firstAction)
 allow to inject command param into cmd of confunc command More...
 
void UI_ExecuteEventActions (uiNode_t *source, const uiAction_t *firstAction)
 
void UI_ExecuteEventActionsEx (uiNode_t *source, const uiAction_t *firstAction, linkedList_t *params)
 
bool UI_IsInjectedString (const char *string)
 Test if a string use an injection syntax. More...
 
void UI_FreeStringProperty (void *pointer)
 Free a string property if it is allocated into ui_dynStringPool. More...
 
uiAction_tUI_AllocStaticCommandAction (const char *command)
 Allocate and initialize a command action. More...
 
void UI_PoolAllocAction (uiAction_t **action, int type, const void *data)
 Set a new action to a uiAction_t pointer. More...
 
void UI_AddListener (uiNode_t *node, const value_t *property, const uiNode_t *functionNode)
 Add a callback of a function into a node event. There can be more than on listener. More...
 
static void UI_AddListener_f (void)
 add a call of a function into a node event More...
 
void UI_RemoveListener (uiNode_t *node, const value_t *property, uiNode_t *functionNode)
 Remove a function callback from a node event. There can be more than on listener. More...
 
static void UI_RemoveListener_f (void)
 Remove a function callback from a node event. More...
 
static void UI_CvarChangeListener (const char *cvarName, const char *oldValue, const char *newValue, void *data)
 
static void UI_AddCvarListener_f (void)
 
static void UI_RemoveCvarListener_f (void)
 
void UI_InitActions (void)
 

Variables

static const ui_typedActionToken_t actionTokens []
 List of typed token. More...
 

Typedef Documentation

Function Documentation

void UI_AddListener ( uiNode_t node,
const value_t property,
const uiNode_t functionNode 
)

Add a callback of a function into a node event. There can be more than on listener.

Parameters
[in,out]nodeThe node to add the listener to.
[in]propertyThe property of the node to add the listener to.
[in]functionNodeThe node of the listener callback.
Todo:
It is a hack, we should remove that

Definition at line 835 of file ui_actions.cpp.

References uiAction_s::d, EA_LISTENER, Mem_PoolAllocType, Mem_PoolStrDup, uiAction_s::next, uiAction_s::nonTerminal, uiNode_t::onClick, uiAction_s::terminal, uiAction_s::type, UI_GetPath(), and ui_sysPool.

Referenced by uiConFuncNode::onWindowOpened(), and UI_AddListener_f().

static void UI_AddListener_f ( void  )
static

add a call of a function into a node event

Definition at line 870 of file ui_actions.cpp.

References Cmd_Argc(), Cmd_Argv(), Com_Printf(), value_s::type, UI_AddListener(), UI_GetNodeByPath(), UI_ReadNodePath(), and V_UI_ACTION.

Referenced by UI_InitActions().

uiAction_t* UI_AllocStaticCommandAction ( const char *  command)

Allocate and initialize a command action.

Parameters
[in]commandA command for the action
Returns
An initialised action

Definition at line 796 of file ui_actions.cpp.

References uiAction_s::d, EA_CMD, uiAction_s::terminal, uiAction_s::type, and UI_AllocStaticAction().

Referenced by UI_Window_SetCloseButton().

static void UI_CheckActionTokenTypeSanity ( void  )
static

Check if the action token list is sorted by alphabet, else dichotomic search can't work.

Definition at line 95 of file ui_actions.cpp.

References i, lengthof, Sys_Error(), and ui_typedActionToken_s::token.

Referenced by UI_InitActions().

static void UI_CvarChangeListener ( const char *  cvarName,
const char *  oldValue,
const char *  newValue,
void data 
)
static

Definition at line 975 of file ui_actions.cpp.

References LIST_Foreach, and UI_ExecuteConfunc().

Referenced by UI_AddCvarListener_f(), and UI_RemoveCvarListener_f().

static void UI_ExecuteAction ( const uiAction_t action,
uiCallContext_t context 
)
static
static void UI_ExecuteActions ( const uiAction_t firstAction,
uiCallContext_t context 
)
static

Execute a tree of actions from a source.

Parameters
[in]contextContext node
[in]firstActionAction to execute

Definition at line 701 of file ui_actions.cpp.

References uiCallContext_s::breakLoop, Com_Printf(), uiCallContext_s::source, UI_ExecuteAction(), and UI_GetPath().

Referenced by UI_ExecuteAction(), UI_ExecuteCallAction(), UI_ExecuteConFuncActions(), UI_ExecuteEventActions(), and UI_ExecuteEventActionsEx().

void UI_ExecuteConFuncActions ( uiNode_t source,
const uiAction_t firstAction 
)

allow to inject command param into cmd of confunc command

Definition at line 717 of file ui_actions.cpp.

References OBJZERO, uiCallContext_s::source, UI_ExecuteActions(), and uiCallContext_s::useCmdParam.

Referenced by UI_ConfuncCommand_f().

void UI_ExecuteEventActions ( uiNode_t source,
const uiAction_t firstAction 
)

Definition at line 726 of file ui_actions.cpp.

References OBJZERO, uiCallContext_s::source, UI_ExecuteActions(), and uiCallContext_s::useCmdParam.

Referenced by uiSequenceNode::draw(), uiTimerNode::draw(), uiVideoNode::drawOverWindow(), uiRadioButtonNode::onActivate(), uiNode::onActivate(), uiOptionTreeNode::onCapturedMouseMove(), uiOptionListNode::onCapturedMouseMove(), uiContainerNode::onDndFinished(), uiTextListNode::onLeftClick(), uiRadioButtonNode::onLeftClick(), uiTextNode::onLeftClick(), uiText2Node::onLeftClick(), uiTextEntryNode::onLeftClick(), uiCheckBoxNode::onLeftClick(), uiLocatedNode::onLeftClick(), uiLocatedNode::onMiddleClick(), uiMaterialEditorNode::onMouseDown(), uiBaseInventoryNode::onMouseDown(), uiContainerNode::onMouseDown(), uiLocatedNode::onMouseEnter(), uiLocatedNode::onMouseLeave(), uiTextListNode::onRightClick(), uiTextNode::onRightClick(), uiText2Node::onRightClick(), uiLocatedNode::onRightClick(), uiMessageListNode::onScroll(), uiOptionTreeNode::onScroll(), uiOptionListNode::onScroll(), uiTextNode::onScroll(), uiPanelNode::onScroll(), uiLocatedNode::onScroll(), uiWindowNode::onWindowActivate(), uiWindowNode::onWindowClosed(), uiAbstractScrollableNode::setScrollY(), uiAbstractValueNode::setValue(), UI_AbstractOption_SetCurrentValue(), UI_AbstractScrollbarNodeSet(), UI_AbstractValue_SetValueCvar(), UI_BaseInventoryNodeUpdateScroll(), UI_ClientLayout(), UI_ColumnLayout(), UI_ContainerNodeAutoPlaceItem(), UI_FinishWindowsInit(), UI_FocusExecuteActionNode(), UI_OptionListNodeUpdateScroll(), UI_OptionTree_SelectValue(), UI_OptionTreeNodeUpdateScroll(), UI_TextEntryNodeAbortEdition(), UI_TextEntryNodeValidateEdition(), UI_TextNodeSelectLine(), UI_TextScrollEnd(), UI_TopDownFlowLayout(), and UI_ZoneNodeRepeat().

static const char* UI_GenCommandReadProperty ( const char *  input,
char *  output,
int  outputSize 
)
inlinestatic

read a property name from an input buffer to an output

Returns
last position in the input buffer if we find the property, nullptr otherwise

Definition at line 143 of file ui_actions.cpp.

Referenced by UI_GenInjectedString().

const char* UI_GenInjectedString ( const char *  input,
bool  addNewLine,
const uiCallContext_t context 
)

Replace injection identifiers (e.g. <eventParam>) by a value.

Note
The injection identifier can be every node value - e.g. <image> or <width>. It's also possible to do something like
1 cmd "set someCvar &lt;min&gt;/&lt;max&gt;"

Definition at line 209 of file ui_actions.cpp.

References uiNode_t::behaviour, Com_Printf(), Cvar_Get(), length, uiNode_t::parent, Q_streq, Q_strstart(), uiNode_t::root, uiCallContext_s::source, cvar_s::string, UI_GenCommandReadProperty(), UI_GetParam(), UI_GetParamNumber(), UI_GetPath(), UI_GetPropertyFromBehaviour(), UI_GetStringFromNodeProperty(), UI_ReadNodePath(), and va().

Referenced by UI_ExecuteAction(), UI_ExecuteCallAction(), UI_ExecuteSetAction(), UI_GetBooleanFromExpression(), UI_GetFloatFromExpression(), UI_GetNodeFromExpression(), and UI_GetStringFromExpression().

int UI_GetActionTokenType ( const char *  token,
int  group 
)

return an action type from a token, and a group

Parameters
[in]tokenRequested token
[in]groupRequested group, EA_ACTION, EA_BINARYOPERATOR, or EA_UNARYOPERATOR
See also
actionTokens
Returns
a action type from the requested group, else EA_NULL

Definition at line 113 of file ui_actions.cpp.

References EA_NULL, lengthof, and ui_typedActionToken_s::type.

Referenced by UI_ParseActionList(), and UI_ParseExpression().

const char* UI_GetParam ( const uiCallContext_t context,
int  paramID 
)

Get a param from an execution context

Parameters
[in]contextThe execution context
[in]paramIDThe ID of the requested param (first param is integer 1)
Returns
The requested param

Definition at line 179 of file ui_actions.cpp.

References Cmd_Argv(), Com_Printf(), linkedList_t::data, linkedList_t::next, uiCallContext_s::paramNumber, uiCallContext_s::params, and uiCallContext_s::useCmdParam.

Referenced by UI_AbstractNodeCallCreateChild(), UI_AbstractNodeCallDeleteTimed(), UI_GenInjectedString(), UI_GetFloatFromExpression(), UI_GetStringFromExpression(), and UI_OptionTreeSetSelectedValue().

int UI_GetParamNumber ( const uiCallContext_t context)
uiValue_t* UI_GetVariable ( const uiCallContext_t context,
int  relativeVarId 
)

Return a variable from the context.

Parameters
contextCall context
relativeVarIdid of the variable relative to the context

Definition at line 517 of file ui_actions.cpp.

References ui_global, uiGlobal_s::variableStack, and uiCallContext_s::varPosition.

Referenced by UI_GetFloatFromExpression(), UI_GetNodeFromExpression(), and UI_GetStringFromExpression().

void UI_InitActions ( void  )
Todo:
rework these commands to use a script language way

Definition at line 1034 of file ui_actions.cpp.

References Cmd_AddCommand(), UI_AddCvarListener_f(), UI_AddListener_f(), UI_CheckActionTokenTypeSanity(), UI_RemoveCvarListener_f(), and UI_RemoveListener_f().

Referenced by UI_Init().

bool UI_IsInjectedString ( const char *  string)

Test if a string use an injection syntax.

Parameters
[in]stringThe string to check for injection
Returns
True if we find the following syntax in the string "<" {thing without space} ">"

Definition at line 751 of file ui_actions.cpp.

Referenced by UI_ParseSetAction(), and UI_ParseValueExpression().

static void UI_NodeSetPropertyFromActionValue ( uiNode_t node,
const value_t property,
const uiCallContext_t context,
uiAction_t value 
)
static

Apply an action value to a node property. If the tuple property/value allow it, the function pre compute the value and update the action value to speed up the next call.

Parameters
nodeNode to edit
propertyProperty of the node to edit
valueAction value containing the value to set to the node property
contextCall context of the script
Todo:
refactoring it to remove "context", we should only call that function when the action value is a leaf (then a value, and not an expression)
Todo:
here we must catch error in a better way, and using cvar for error code to create unittest automations
Todo:
we should improve if when the prop is a boolean/int/float

Definition at line 342 of file ui_actions.cpp.

References uiAction_s::d, EA_VALUE_RAW, EA_VALUE_STRING, Q_strstart(), uiAction_s::terminal, uiAction_s::type, value_s::type, UI_GetStringFromExpression(), UI_InitRawActionValue(), UI_NodeSetProperty(), UI_NodeSetPropertyFromRAW(), V_UI_CVAR, and V_UI_MASK.

Referenced by UI_ExecuteSetAction().

void UI_PoolAllocAction ( uiAction_t **  action,
int  type,
const void data 
)

Set a new action to a uiAction_t pointer.

Parameters
[in,out]actionAllocated action
[in]typeOnly EA_CMD is supported
[in]dataThe data for this action - in case of EA_CMD this is the commandline
Note
You first have to free existing node actions - only free those that are not static in ui_global.actions array
Todo:
we should create a function to free the memory. We can use a tag in the Mem_PoolAlloc calls and use use Mem_FreeTag.

Definition at line 814 of file ui_actions.cpp.

References Com_Error(), EA_CMD, ERR_FATAL, Mem_PoolAllocType, Mem_PoolStrDup, type, and ui_sysPool.

Referenced by UI_PopupList(), and UI_SetOneButton().

static void UI_ReleaseVariable ( uiValue_t variable)
static
Todo:
most of cases here are useless, it only should be EA_VALUE_STRING

Definition at line 525 of file ui_actions.cpp.

References Com_Error(), EA_VALUE_CVAR, EA_VALUE_FLOAT, EA_VALUE_NODE, EA_VALUE_STRING, ERR_FATAL, OBJZERO, uiValue_s::string, uiValue_s::type, UI_FreeStringProperty(), and uiValue_s::value.

Referenced by UI_ExecuteAction().

void UI_RemoveListener ( uiNode_t node,
const value_t property,
uiNode_t functionNode 
)

Remove a function callback from a node event. There can be more than on listener.

Parameters
[in,out]nodeThe node to remove the listener from.
[in]propertyThe property of the node to remove the listener from.
[in]functionNodeThe node of the listener callback.

Definition at line 906 of file ui_actions.cpp.

References Cmd_Argv(), Com_Printf(), uiAction_s::d, EA_LISTENER, Mem_Free, uiAction_s::next, uiAction_s::nonTerminal, uiNode_t::onClick, and uiAction_s::terminal.

Referenced by uiConFuncNode::onWindowClosed(), and UI_RemoveListener_f().

static void UI_RemoveListener_f ( void  )
static

Remove a function callback from a node event.

Definition at line 945 of file ui_actions.cpp.

References Cmd_Argc(), Cmd_Argv(), Com_Printf(), value_s::type, UI_GetNodeByPath(), UI_ReadNodePath(), UI_RemoveListener(), and V_UI_ACTION.

Referenced by UI_InitActions().

Variable Documentation

const ui_typedActionToken_t actionTokens[]
static

List of typed token.

Note
token ordered by alphabet, because it use a dichotomic search

Definition at line 46 of file ui_actions.cpp.