UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_lua.h File Reference

Basic lua initialization for the ui. More...

Go to the source code of this file.

Functions

void UI_InitLua (void)
 Performs UI specific initialization. Call this after CL_InitLua. More...
 
void UI_ShutdownLua (void)
 Performs UI specific lua shutdown. Call this before CL_ShutdownLua. More...
 
void UI_RegisterHandler_OnLoad (LUA_FUNCTION fcn)
 Register global lua callback function called after loading the module. More...
 
void UI_CallHandler_OnLoad (lua_State *L, const char *key)
 Call the registered callback handler. This stub primarily exists should the signature of the call change in the future. CL_ExecuteCallback only supports a callback with no arguments. More...
 
bool UI_ParseAndLoadLuaScript (const char *name, const char **text)
 Parses and loads a .ufo file holding a lua script. More...
 
bool UI_ExecuteLuaEventScript (uiNode_t *node, LUA_EVENT event)
 Executes a lua event handler. More...
 
bool UI_ExecuteLuaEventScript_ParamList (uiNode_t *node, LUA_EVENT event, linkedList_t *params)
 Executes a lua event handler with string parameter list. More...
 
bool UI_ExecuteLuaEventScript_ReturnBool (uiNode_t *node, LUA_EVENT event, bool &result)
 Executes a lua event handler and returns the result as a boolean. More...
 
bool UI_ExecuteLuaEventScript_XY (uiNode_t *node, LUA_EVENT event, int x, int y)
 Executes a lua event handler with (x,y) argument. More...
 
bool UI_ExecuteLuaEventScript_DxDy (uiNode_t *node, LUA_EVENT event, int dx, int dy)
 Executes a lua event handler with (dx,dy) argument. More...
 
bool UI_ExecuteLuaEventScript_Key (uiNode_t *node, LUA_EVENT event, unsigned int key, unsigned short unicode)
 Executes a lua event handler with (keycode,unicode) argument. More...
 
bool UI_ExecuteLuaEventScript_DragDrop (uiNode_t *node, LUA_EVENT event, bool &result)
 Executes a lua event handler for dragdrop interaction. More...
 
bool UI_ExecuteLuaEventScript_DragDrop_XY (uiNode_t *node, LUA_EVENT event, int x, int y, bool &result)
 Executes a lua event handler for dragdrop interaction. More...
 
bool UI_ExecuteLuaEventScript_DragDrop_IsDropped (uiNode_t *node, LUA_EVENT event, bool isDropped, bool &result)
 Executes a lua event handler for dragdrop interaction. More...
 
bool UI_ExecuteLuaMethod (uiNode_t *node, LUA_FUNCTION fcn, linkedList_t *params, int nparams)
 Executes a lua based method defined on the behaviour class of a node. More...
 
bool UI_ExecuteLuaConFunc (uiNode_t *node, LUA_FUNCTION fcn)
 Executes a lua based confunc node. More...
 
bool UI_ExecuteLuaMethod_ByName (uiNode_t *node, const char *name, linkedList_t *params, int nparams)
 Executes a lua based method defined on the behaviour class of a node. More...
 
uiNode_tUI_CreateControl (uiNode_t *parent, const char *type, const char *name, const char *super)
 Create a new control inherited from a given node class or other node. More...
 
uiNode_tUI_CreateComponent (const char *type, const char *name, const char *super)
 Create a new component inherited from a given node class or other node. More...
 
uiNode_tUI_CreateWindow (const char *type, const char *name, const char *super)
 Create a window node with specified type and inheritance. More...
 
void UI_PrintNodeTree (uiNode_t *node, int level=0)
 
const char * UI_Node_TypeOf (uiNode_t *node)
 

Detailed Description

Basic lua initialization for the ui.

Definition in file ui_lua.h.

Function Documentation

void UI_CallHandler_OnLoad ( lua_State *  L,
const char *  key 
)

Call the registered callback handler. This stub primarily exists should the signature of the call change in the future. CL_ExecuteCallback only supports a callback with no arguments.

Definition at line 372 of file ui_lua.cpp.

References CL_ExecuteCallback().

Referenced by UI_ParseAndLoadLuaScript().

uiNode_t* UI_CreateComponent ( const char *  type,
const char *  name,
const char *  super 
)

Create a new component inherited from a given node class or other node.

Parameters
[in]typeThe behaviour type of the component to create.
[in]nameThe name of the component to create.
[in]superThe name this component inherits from. If NULL the component has no super defined.
Note
A component is a reusable window or panel.

Definition at line 544 of file ui_lua.cpp.

References uiNode_t::behaviour, Com_Printf(), uiBehaviour_t::name, UI_AllocNode(), UI_CloneNode(), UI_GetComponent(), UI_GetNodeBehaviour(), UI_InsertComponent(), UI_Node_Loaded(), UI_TokenIsName(), and UI_TokenIsReserved().

Referenced by _wrap_create_component().

uiNode_t* UI_CreateControl ( uiNode_t parent,
const char *  type,
const char *  name,
const char *  super 
)

Create a new control inherited from a given node class or other node.

Parameters
[in]parentThe parent control or window/component owning this control.
[in]typeThe behaviour type of the control to create. This can be a previously defined control instance.
[in]nameThe name of the control to create.
[in]superThe name this control inherits from. If specified overrides the behaviour type of super must match type.
Note
A control is a node inside a component or window. Unlike a component or window, a control is always attached to a parent.
Code needs to be refactored.

Definition at line 428 of file ui_lua.cpp.

References uiNode_t::behaviour, Com_DPrintf(), Com_Printf(), DEBUG_CLIENT, uiBehaviour_t::name, uiNode_t::root, uiNode_t::super, UI_AllocNode(), UI_AppendNode(), UI_CloneNode(), UI_GetComponent(), UI_GetNode(), UI_GetNodeBehaviour(), UI_GetPath(), UI_Node_Loaded(), UI_TokenIsName(), UI_TokenIsReserved(), and UI_UpdateRoot().

Referenced by _wrap_create_control(), UI_CreateBar(), UI_CreateBaseInventory(), UI_CreateBaseLayout(), UI_CreateButton(), UI_CreateCheckBox(), UI_CreateConFunc(), UI_CreateContainer(), UI_CreateData(), UI_CreateGeoscape(), UI_CreateImage(), UI_CreateItem(), UI_CreateLineChart(), UI_CreateMessageList(), UI_CreateModel(), UI_CreateOption(), UI_CreateOptionList(), UI_CreateOptionTree(), UI_CreatePanel(), UI_CreateRadar(), UI_CreateRadioButton(), UI_CreateRows(), UI_CreateSelectBox(), UI_CreateSequence(), UI_CreateSpinner(), UI_CreateString(), UI_CreateTab(), UI_CreateTBar(), UI_CreateText(), UI_CreateText2(), UI_CreateTextEntry(), UI_CreateTextList(), UI_CreateTexture(), UI_CreateTimer(), UI_CreateVideo(), UI_CreateVScrollbar(), UI_CreateWidget(), and UI_CreateZone().

uiNode_t* UI_CreateWindow ( const char *  type,
const char *  name,
const char *  super 
)

Create a window node with specified type and inheritance.

Parameters
[in]typeThe behaviour type of the window to create.
[in]nameThe name of the window to create.
[in]superThe name this window inherits from. If NULL the window has no super defined.
Note
A window is a top level component in the ui.
Todo:
If the old style ui scripts are no longer used, the check UI_TokenIsReserved should be removed.

Definition at line 618 of file ui_lua.cpp.

References Com_Error(), Com_Printf(), ERR_FATAL, i, uiNode_t::name, uiGlobal_s::numWindows, Q_streq, uiNode_t::root, Sys_Error(), UI_AllocNode(), UI_CloneNode(), UI_GetWindow(), ui_global, UI_InsertWindow(), UI_MAX_WINDOWS, UI_Node_Loaded(), UI_TokenIsName(), UI_TokenIsReserved(), and uiGlobal_s::windows.

bool UI_ExecuteLuaConFunc ( uiNode_t node,
LUA_FUNCTION  fcn 
)

Executes a lua based confunc node.

Parameters
[in]nodeThe node the method is defined on.
[in]fcnThe The method to execute.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the method in lua is: function(sender, p1..pn), so the actual number of parameters for the function is actually nparams + 1.
Parameters are read from cmd.
All parameters are send to lua as strings.

Definition at line 323 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Cmd_Argc(), Cmd_Argv(), Com_Printf(), i, uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by UI_ConfuncCommand_f(), and UI_ExecuteCallAction().

bool UI_ExecuteLuaEventScript ( uiNode_t node,
LUA_EVENT  event 
)

Executes a lua event handler.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender)

Definition at line 71 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by uiSequenceNode::draw(), uiTimerNode::draw(), uiVideoNode::drawOverWindow(), uiRadioButtonNode::onActivate(), uiNode::onActivate(), uiOptionTreeNode::onCapturedMouseMove(), uiOptionListNode::onCapturedMouseMove(), uiContainerNode::onDndFinished(), uiLocatedNode::onFocusGained(), uiLocatedNode::onFocusLost(), uiTextListNode::onLeftClick(), uiNode::onLoaded(), uiMaterialEditorNode::onMouseDown(), uiBaseInventoryNode::onMouseDown(), uiContainerNode::onMouseDown(), uiLocatedNode::onMouseEnter(), uiLocatedNode::onMouseLeave(), uiTextListNode::onRightClick(), uiOptionTreeNode::onScroll(), uiOptionListNode::onScroll(), uiPanelNode::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_OptionListNodeUpdateScroll(), UI_OptionTree_SelectValue(), UI_OptionTreeNodeUpdateScroll(), UI_TextEntryNodeValidateEdition(), UI_TextNodeSelectLine(), UI_TextScrollEnd(), and UI_TopDownFlowLayout().

bool UI_ExecuteLuaEventScript_DragDrop ( uiNode_t node,
LUA_EVENT  event,
bool &  result 
)

Executes a lua event handler for dragdrop interaction.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
[out]resultA reference to a bool set to the function result.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender) and should return a boolean

Definition at line 211 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by uiLocatedNode::onDndEnter(), and uiLocatedNode::onDndLeave().

bool UI_ExecuteLuaEventScript_DragDrop_IsDropped ( uiNode_t node,
LUA_EVENT  event,
bool  isDropped,
bool &  result 
)

Executes a lua event handler for dragdrop interaction.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
[in]isDroppedThe boolean of the call signature (isDropped).
[out]resultA reference to a bool set to the function result.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender, isDropped) and should return a boolean

Definition at line 266 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by uiLocatedNode::onDndFinished().

bool UI_ExecuteLuaEventScript_DragDrop_XY ( uiNode_t node,
LUA_EVENT  event,
int  x,
int  y,
bool &  result 
)

Executes a lua event handler for dragdrop interaction.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
[in]xThe x value of the call signature (x, y)
[in]yThe y value of the call signature (x, y)
[out]resultA reference to a bool set to the function result.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender, x, y) and should return a boolean

Definition at line 238 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by uiLocatedNode::onDndDrop(), and uiLocatedNode::onDndMove().

bool UI_ExecuteLuaEventScript_DxDy ( uiNode_t node,
LUA_EVENT  event,
int  dx,
int  dy 
)

Executes a lua event handler with (dx,dy) argument.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
[in]dxThe dx-coordinate of the (dx,dy) argument.
[in]dyThe dy-coordinate of the (dx,dy) argument.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender, dx, dy)

Definition at line 166 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by uiLocatedNode::onScroll().

bool UI_ExecuteLuaEventScript_Key ( uiNode_t node,
LUA_EVENT  event,
unsigned int  key,
unsigned short  unicode 
)

Executes a lua event handler with (keycode,unicode) argument.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
[in]keyThe key value of the (keycode,unicode) argument.
[in]unicodeThe unicode value of the (keycode,unicode) argument.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender, key, unicode)

Definition at line 189 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by uiLocatedNode::onKeyPressed(), and uiLocatedNode::onKeyReleased().

bool UI_ExecuteLuaEventScript_ParamList ( uiNode_t node,
LUA_EVENT  event,
linkedList_t params 
)

Executes a lua event handler with string parameter list.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
[in]paramsLinkedLst of strings
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender, ...)

Definition at line 91 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), LIST_Foreach, uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by uiWindowNode::onWindowOpened().

bool UI_ExecuteLuaEventScript_ReturnBool ( uiNode_t node,
LUA_EVENT  event,
bool &  result 
)

Executes a lua event handler and returns the result as a boolean.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
[in,out]resultThe boolean value returned by the lua script.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender) and must return a boolean value

Definition at line 116 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by UI_CheckVisibility().

bool UI_ExecuteLuaEventScript_XY ( uiNode_t node,
LUA_EVENT  event,
int  x,
int  y 
)

Executes a lua event handler with (x,y) argument.

Parameters
[in]nodeThe node the event handler is associated with.
[in]eventThe event to execute.
[in]xThe x-coordinate of the (x,y) argument.
[in]yThe y-coordinate of the (x,y) argument.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the event handler in lua is: onevent(sender, x, y)

Definition at line 143 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by uiTextListNode::onLeftClick(), uiRadioButtonNode::onLeftClick(), uiTextEntryNode::onLeftClick(), uiText2Node::onLeftClick(), uiTextNode::onLeftClick(), uiCheckBoxNode::onLeftClick(), uiLocatedNode::onLeftClick(), uiLocatedNode::onMiddleClick(), and uiLocatedNode::onRightClick().

bool UI_ExecuteLuaMethod ( uiNode_t node,
LUA_FUNCTION  fcn,
linkedList_t params,
int  nparams 
)

Executes a lua based method defined on the behaviour class of a node.

Parameters
[in]nodeThe node the method is defined on.
[in]fcnThe The method to execute.
[in]paramsA linked list of parameters for the lua based function call.
[in]nparamsThe number of parameters for the lua based function call.
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the method in lua is: function(sender, p1..pn), so the actual number of parameters for the function is actually nparams + 1.
All parameters are send to lua as strings.

Definition at line 295 of file ui_lua.cpp.

References uiNode_t::behaviour, CL_GetLuaState(), Com_Printf(), i, LIST_GetByIdx(), uiBehaviour_t::lua_SWIG_typeinfo, uiBehaviour_t::name, SWIG_NewPointerObj, and UI_GetPath().

Referenced by UI_ExecuteCallAction(), and UI_ExecuteLuaMethod_ByName().

bool UI_ExecuteLuaMethod_ByName ( uiNode_t node,
const char *  name,
linkedList_t params,
int  nparams 
)

Executes a lua based method defined on the behaviour class of a node.

Parameters
[in]nodeThe node the method is defined on
[in]nameThe name of the node
[in]paramsList of Lua method parameters
[in]nparamsNumber of parameters on the list
Returns
True if the operation succeeds, false otherwise.
Note
The signature of the method in lua is: function(sender)

Definition at line 350 of file ui_lua.cpp.

References Com_Printf(), uiNode_t::name, UI_ExecuteLuaMethod(), and UI_GetNodeMethod().

void UI_InitLua ( void  )

Performs UI specific initialization. Call this after CL_InitLua.

Definition at line 55 of file ui_lua.cpp.

Referenced by UI_Init().

const char* UI_Node_TypeOf ( uiNode_t node)

Definition at line 529 of file ui_lua.cpp.

References uiNode_t::behaviour, and uiBehaviour_t::name.

bool UI_ParseAndLoadLuaScript ( const char *  name,
const char **  text 
)

Parses and loads a .ufo file holding a lua script.

Parameters
[in]nameThe name of the .ufo file (holding the lua script).
[in]textThe contents of the .ufo file, only provided to be in line with code handling other .ufo content types.
See also
CL_ParseClientData
Returns
True if parsing was succesful, false otherwise.
Note
All parsed lua files will be added to the lua state.

Definition at line 386 of file ui_lua.cpp.

References CL_GetLuaState(), Com_Error(), Com_Printf(), Q_strncpyz(), UI_CallHandler_OnLoad(), and ui_scriptname.

Referenced by CL_ParseClientData(), and UI_Restart_f().

void UI_PrintNodeTree ( uiNode_t node,
int  level = 0 
)
void UI_RegisterHandler_OnLoad ( LUA_FUNCTION  fcn)

Register global lua callback function called after loading the module.

Definition at line 363 of file ui_lua.cpp.

References CL_RegisterCallback(), and ui_scriptname.

Referenced by _wrap_register_onload().

void UI_ShutdownLua ( void  )

Performs UI specific lua shutdown. Call this before CL_ShutdownLua.

Definition at line 61 of file ui_lua.cpp.

Referenced by UI_Shutdown().