29 #include "../../shared/cxx.h"
30 #include "../../shared/defines.h"
31 #include "../../shared/shared.h"
32 #include "../../common/cvar.h"
33 #include "../../common/hashtable.h"
34 #include "../../common/filesys.h"
35 #include "../../common/scripts_lua.h"
36 #include "../cl_lua.h"
46 #include "../../common/swig_lua_runtime.h"
121 Com_Printf(
"UI_ExecuteLuaEventScript_ReturnBool\n");
126 Com_Printf(
"UI_ExecuteLuaEventScript_ReturnBool\n");
173 Com_Printf(
"UI_ExecuteLuaEventScript_DxDy\n");
216 Com_Printf(
"UI_ExecuteLuaEventScript_DragDrop\n");
245 Com_Printf(
"UI_ExecuteLuaEventScript_DragDrop_XY\n");
272 Com_Printf(
"UI_ExecuteLuaEventScript_DragDrop_IsDropped\n");
301 for (
int i = 0;
i < nparams;
i++) {
302 const char* value =
const_cast<const char*
>((
char*)
LIST_GetByIdx(params,
i));
356 Com_Printf(
"UI_ExecuteNodeMethod_ByName: calling undefined method %s on node %s\n", name, node->
name);
389 int ntext = strlen(*text);
391 Com_Printf(
"UI_ParseAndLoadLuaScript: %s\n", name);
432 uiNode_t* inherited_control =
nullptr;
440 if (!inherited_control) {
441 Com_Printf(
"UI_CreateControl: node behaviour/control '%s' doesn't exist (%s)\n", type,
UI_GetPath(parent));
444 behaviour = inherited_control->
behaviour;
451 if (node_super->
behaviour != behaviour) {
452 Com_Printf(
"UI_CreateControl: behaviour [%s] of super does not match requested type [%s]\n", behaviour->
name, node_super->
behaviour->
name);
460 Com_Printf(
"UI_CreateControl: \"%s\" is not a well formed node name ([a-zA-Z_][a-zA-Z0-9_]*)\n", name);
464 Com_Printf(
"UI_CreateControl: \"%s\" is a reserved token, we can't call a node with it\n", name);
479 const uiBehaviour_t* test = (behaviour !=
nullptr) ? behaviour : (inherited_control !=
nullptr) ? inherited_control->
behaviour :
nullptr;
488 node =
UI_CloneNode(node_super,
nullptr,
true, name,
true);
491 else if (inherited_control) {
493 node =
UI_CloneNode(inherited_control,
nullptr,
true, name,
true);
502 if (node_super || inherited_control)
516 char* indent =
new char[level + 1];
517 for (i = 0; i <
level; i++) {
553 Com_Printf(
"UI_CreateComponent: \"%s\" is not a well formed node name ([a-zA-Z_][a-zA-Z0-9_]*)\n", name);
557 Com_Printf(
"UI_CreateComponent: \"%s\" is a reserved token, we can't call a node with it\n", name);
567 Com_Printf(
"UI_CreateComponent: node behaviour/control '%s' doesn't exist\n", type);
576 if (node_super->
behaviour != behaviour) {
577 Com_Printf(
"UI_CreateComponent: behaviour [%s] of super does not match requested type [%s]\n", behaviour->
name, node_super->
behaviour->
name);
585 component =
UI_CloneNode(node_super,
nullptr,
true, name,
true);
591 component =
UI_CloneNode(inherited,
nullptr,
true, name,
true);
621 if (!
Q_streq(type,
"window")) {
628 Com_Printf(
"UI_CreateWindow: \"%s\" is not a well formed node name ([a-zA-Z_][a-zA-Z0-9_]*)\n", name);
633 Com_Printf(
"UI_CreateWindow: \"%s\" is a reserved token, we can't call a node with it (node \"%s\")\n", name, name);
644 Com_Printf(
"UI_CreateWindow: %s \"%s\" with same name found, second ignored\n", type, name);
656 if (super !=
nullptr) {
659 if (superWindow ==
nullptr) {
660 Sys_Error(
"Could not get the super window \"%s\"", super);
662 window =
UI_CloneNode(superWindow,
nullptr,
true, name,
true);
665 window->
root = window;
const char * Cmd_Argv(int arg)
Returns a given argument.
void Sys_Error(const char *error,...)
bool UI_ExecuteLuaConFunc(uiNode_t *node, LUA_FUNCTION fcn)
Executes a lua based confunc node.
QGL_EXTERN GLint GLenum type
void UI_InsertWindow(uiNode_t *window)
Add a new window to the list of all windows.
bool UI_ParseAndLoadLuaScript(const char *name, const char **text)
Parses and loads a .ufo file holding a lua script.
Basic lua initialization for the ui.
void UI_UpdateRoot(uiNode_t *node, uiNode_t *newRoot)
void * LIST_GetByIdx(linkedList_t *list, int index)
Get an entry of a linked list by its index in the list.
uiNode_t * UI_GetComponent(const char *name)
Searches all components for the specified one.
const char * UI_Node_TypeOf(uiNode_t *node)
int LUA_EVENT
holds a reference to a lua event handler
bool UI_TokenIsReserved(const char *name)
uiBehaviour_t * behaviour
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
lua_State * CL_GetLuaState(void)
Returns the lua state for the client side.
bool UI_ExecuteLuaEventScript_DragDrop_IsDropped(uiNode_t *node, LUA_EVENT event, bool isDropped, bool &result)
Executes a lua event handler for dragdrop interaction.
void Com_Printf(const char *const fmt,...)
void UI_AppendNode(uiNode_t *const parent, uiNode_t *newNode)
add a node at the end of the node child
bool UI_ExecuteLuaEventScript_DragDrop(uiNode_t *node, LUA_EVENT event, bool &result)
Executes a lua event handler for dragdrop interaction.
void UI_InitLua(void)
Performs UI specific initialization. Call this after CL_InitLua.
Internal data use by the UI package.
C interface to allow to access to cpp node code.
void Com_Error(int code, const char *fmt,...)
uiNode_t * UI_AllocNode(const char *name, const char *type, bool isDynamic)
Allocate a node into the UI memory.
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
bool UI_ExecuteLuaEventScript_DxDy(uiNode_t *node, LUA_EVENT event, int dx, int dy)
Executes a lua event handler with (dx,dy) argument.
bool UI_TokenIsName(const char *name, bool isQuoted)
#define SWIG_NewPointerObj(L, ptr, type, owner)
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.
void UI_Node_Loaded(uiNode_t *node)
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
const char * UI_GetPath(const uiNode_t *node)
Return a path from a window to a node.
uiNode_t * UI_CreateWindow(const char *type, const char *name, const char *super)
Create a window node with specified type and inheritance.
bool UI_ExecuteLuaEventScript_XY(uiNode_t *node, LUA_EVENT event, int x, int y)
Executes a lua event handler with (x,y) argument.
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
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 cha...
Atomic structure used to define most of the UI.
uiNode_t * windows[UI_MAX_WINDOWS]
uiNode_t * UI_CloneNode(const uiNode_t *node, uiNode_t *newWindow, bool recursive, const char *newName, bool isDynamic)
Clone a node.
void UI_PrintNodeTree(uiNode_t *node, int level)
uiNode_t * UI_GetWindow(const char *name)
Searches all windows for the specified one.
bool UI_ExecuteLuaEventScript_ParamList(uiNode_t *node, LUA_EVENT event, linkedList_t *params)
Executes a lua event handler with string parameter list.
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.
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.
uiNode_t * UI_GetNode(const uiNode_t *node, const char *name)
Search a child node by given name.
node behaviour, how a node work
void UI_RegisterHandler_OnLoad(LUA_FUNCTION fcn)
Register global lua callback function called after loading the module.
uiBehaviour_t * UI_GetNodeBehaviour(const char *name)
Return a node behaviour by name.
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
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.
bool UI_GetNodeMethod(const uiNode_t *node, const char *name, LUA_METHOD &fcn)
Finds the lua based method on this node or its super.
#define LIST_Foreach(list, type, var)
Iterates over a linked list, it's safe to delete the returned entry from the list while looping over ...
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.
int LUA_FUNCTION
callback signatures for functions defined in Lua
void CL_ExecuteCallback(lua_State *L, const char *key)
Calls the registered lua onload callback function.
void UI_ShutdownLua(void)
Performs UI specific lua shutdown. Call this before CL_ShutdownLua.
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.
void CL_RegisterCallback(const char *key, LUA_FUNCTION fnc)
Registers a lua callback function with a key.
void UI_InsertComponent(uiNode_t *component)
Add a new component to the list of all components.
bool UI_ExecuteLuaEventScript_ReturnBool(uiNode_t *node, LUA_EVENT event, bool &result)
Executes a lua event handler and returns the result as a boolean.