34 #include "../cl_language.h"
97 for (
int i = 0;
i <
lengthof(actionTokens) - 1;
i++) {
98 const char* a = actionTokens[
i].
token;
99 const char* b = actionTokens[
i + 1].
token;
100 if (strcmp(a, b) >= 0) {
101 Sys_Error(
"UI_CheckActionTokenTypeSanity: '%s' is before '%s'. actionList must be sorted by alphabet", a, b);
115 unsigned char min = 0;
116 unsigned char max =
lengthof(actionTokens);
119 const int mid = (min + max) >> 1;
120 const int diff = strcmp(actionTokens[mid].token, token);
125 if (actionTokens[mid].group == group)
126 return actionTokens[mid].
type;
145 assert(input[0] ==
'<');
149 while (outputSize && *input !=
'\0' && *input !=
' ' && *input !=
'>') {
150 *output++ = *input++;
182 assert(paramID >= 1);
188 Com_Printf(
"UI_GetParam: %i out of range\n", paramID);
192 current = context->
params;
193 while (paramID > 1) {
194 current = current->
next;
198 return (
const char*) current->
data;
211 static char cmd[256];
212 int length =
sizeof(cmd) - (addNewLine ? 2 : 1);
213 static char propertyName[256];
214 const char* cin = input;
217 while (length && cin[0] !=
'\0') {
223 if (
char const*
const rest =
Q_strstart(propertyName,
"cvar:")) {
225 const int l = snprintf(cout, length,
"%s", cvar->
string);
230 }
else if (
char const*
const path =
Q_strstart(propertyName,
"node:")) {
237 Com_Printf(
"UI_GenInjectedString: Node '%s' wasn't found; '' returned\n", path);
242 }
else if (!property) {
243 Com_Printf(
"UI_GenInjectedString: Property '%s' wasn't found; '' returned\n", path);
247 if (
string ==
nullptr) {
248 Com_Printf(
"UI_GenInjectedString: String getter for '%s' property do not exists; '' injected\n", path);
253 l = snprintf(cout, length,
"%s",
string);
259 }
else if (
char const*
const command =
Q_strstart(propertyName,
"path:")) {
264 else if (
Q_streq(command,
"this"))
266 else if (
Q_streq(command,
"parent"))
269 Com_Printf(
"UI_GenCommand: Command '%s' for path injection unknown\n", command);
272 const int l = snprintf(cout, length,
"%s",
UI_GetPath(node));
291 if (value ==
nullptr)
293 l = snprintf(cout, length,
"%s", value);
304 const int checked = sscanf(propertyName,
"%d", &arg);
306 const int l = snprintf(cout, length,
"%s",
UI_GetParam(context, arg));
321 assert(cin[0] ==
'\0');
329 return va(
"%s", cmd);
347 const char*
string = value->
d.
terminal.d1.constString;
349 Com_GetValue<void*>(node, property) = value->
d.
terminal.d1.data;
358 const void* rawValue = value->
d.
terminal.d1.constData;
359 const int rawType = value->
d.
terminal.d2.integer;
379 if (left ==
nullptr) {
380 Com_Printf(
"UI_ExecuteSetAction: Action without left operand skipped.\n");
385 if (right ==
nullptr) {
386 Com_Printf(
"UI_ExecuteSetAction: Action without right operand skipped.\n");
391 const char* cvarName;
394 cvarName = left->
d.
terminal.d1.constString;
431 const value_t* callProperty =
nullptr;
433 const char* path = left->
d.
terminal.d1.constString;
436 memset(&luaMethod, 0,
sizeof(luaMethod));
444 if ((callNode ==
nullptr) && (!luaMethod.
type)) {
445 Com_Printf(
"UI_ExecuteCallAction: Node from path \"%s\" not found (relative to \"%s\").\n", path,
UI_GetPath(context->
source));
453 newContext.
source = callNode;
454 newContext.
params =
nullptr;
466 const char* value = (
char*) p->
data;
489 else if (callProperty ==
nullptr || callProperty->
type ==
V_UI_ACTION) {
490 uiAction_t const*
const actionsRef = callProperty ? Com_GetValue<uiAction_t*>(callNode, callProperty) : callNode->onClick;
493 if (callNode->lua_onClick != LUA_NOREF) {
502 func(callNode, &newContext);
519 const int varId = context->
varPosition + relativeVarId;
520 assert(relativeVarId >= 0);
521 assert(relativeVarId < context->varNumber);
528 switch (variable->
type) {
552 switch (action->
type) {
570 const int number = action->
d.
terminal.d1.integer;
571 assert(number <= context->varNumber);
572 for (
int i = 0;
i < number;
i++) {
587 Com_Error(
ERR_FATAL,
"UI_ExecuteAction: Variable stack full. UI_MAX_VARIABLESTACK hit.");
596 const char* cvarname = action->
d.
nonTerminal.left->d.terminal.d1.constString;
611 Com_Printf(
"UI_ExecuteAction: Infinite loop. Force breaking 'while'\n");
650 Com_Printf(
"UI_ExecuteAction: Infinite loop. Force breaking 'forchildin'\n");
670 action = action->
next;
676 action = action->
next;
703 static int callnumber = 0;
704 if (callnumber++ > 20) {
708 for (
const uiAction_t* action = firstAction; action && !context->
breakLoop; action = action->next) {
753 const char* c = string;
757 const char* d = c + 1;
762 if (*d ==
' ' || *d ==
'\t' || *d ==
'\n' || *d ==
'\r')
800 action->
d.
terminal.d1.constString = command;
819 (*action)->type =
type;
853 value->
next =
nullptr;
858 action->
next =
nullptr;
861 uiAction_t** anchor = &Com_GetValue<uiAction_t*>(node, property);
863 anchor = &(*anchor)->
next;
882 if (node ==
nullptr) {
887 Com_Printf(
"UI_AddListener_f: '%s' property not found, or is not an event.\n",
Cmd_Argv(1));
892 if (
function ==
nullptr) {
911 data = (
void*) &functionNode->
onClick;
914 uiAction_t*& action = Com_GetValue<uiAction_t*>(node, property);
917 if (lastAction->type ==
EA_LISTENER && lastAction->d.terminal.d2.constData == data) {
919 action = lastAction->
next;
921 while (lastAction->next) {
922 if (lastAction->next->type ==
EA_LISTENER && lastAction->next->d.terminal.d2.constData == data)
924 lastAction = lastAction->
next;
926 if (lastAction->next) {
927 tmp = lastAction->
next;
957 if (node ==
nullptr) {
962 Com_Printf(
"UI_RemoveListener_f: '%s' property not found, or is not an event.\n",
Cmd_Argv(1));
967 if (
function ==
nullptr) {
985 const char* cvarName;
986 const char* confuncName;
1003 const char* cvarName;
1004 const char* confuncName;
1023 if (entry !=
nullptr)
void UI_InitActions(void)
const char * Cmd_Argv(int arg)
Returns a given argument.
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
bool UI_IsInjectedString(const char *string)
Test if a string use an injection syntax.
static const char * UI_GenCommandReadProperty(const char *input, char *output, int outputSize)
read a property name from an input buffer to an output
uiAction_t * UI_AllocStaticAction(void)
Allocate an action.
struct uiAction_s::@14::@16 terminal
Stores a terminal action (a value, which must be a leaf in the tree)
void Sys_Error(const char *error,...)
bool UI_ExecuteLuaConFunc(uiNode_t *node, LUA_FUNCTION fcn)
Executes a lua based confunc node.
cvarChangeListener_t * Cvar_RegisterChangeListener(const char *varName, cvarChangeListenerFunc_t listenerFunc)
Registers a listener that is executed each time a cvar changed its value.
bool UI_NodeSetProperty(uiNode_t *node, const value_t *property, const char *value)
Set node property.
void UI_PoolAllocAction(uiAction_t **action, int type, const void *data)
Set a new action to a uiAction_t pointer.
void UI_ReadNodePath(const char *path, const uiNode_t *relativeNode, const uiNode_t *iterationNode, uiNode_t **resultNode, const value_t **resultProperty, value_t *luaMethod)
Read a path and return every we can use (node and property)
bool UI_GetBooleanFromExpression(uiAction_t *expression, const uiCallContext_t *context)
Check if an expression is true.
QGL_EXTERN GLint GLenum type
static void UI_CvarChangeListener(const char *cvarName, const char *oldValue, const char *newValue, void *data)
void Cvar_UnRegisterChangeListener(const char *varName, cvarChangeListenerFunc_t listenerFunc)
Unregisters a cvar change listener.
Basic lua initialization for the ui.
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
uiNode_t * UI_GetNodeByPath(const char *path)
Return a node by a path name (names with dot separation) It is a simplification facade over UI_ReadNo...
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
struct ui_typedActionToken_s ui_typedActionToken_t
QGL_EXTERN GLint GLenum GLboolean GLsizei const GLvoid * pointer
static void UI_ExecuteAction(const uiAction_t *action, uiCallContext_t *context)
Execute an action from a source.
uiBehaviour_t * behaviour
void Cbuf_AddText(const char *format,...)
Adds command text at the end of the buffer.
uiValue_t * UI_GetVariable(const uiCallContext_t *context, int relativeVarId)
Return a variable from the context.
uiAction_t * UI_AllocStaticCommandAction(const char *command)
Allocate and initialize a command action.
#define UI_MAX_VARIABLESTACK
void Com_Printf(const char *const fmt,...)
static void UI_AddListener_f(void)
add a call of a function into a node event
void LIST_Delete(linkedList_t **list)
union uiAction_s::@14 d
Stores data about the action.
struct uiAction_s * onClick
void UI_FreeStringProperty(void *pointer)
Free a string property if it is allocated into ui_dynStringPool.
const value_t * UI_GetPropertyFromBehaviour(const uiBehaviour_t *behaviour, const char *name)
Get a property from a behaviour or his inheritance It use a dichotomic search.
int LIST_Count(const linkedList_t *list)
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,...)
static void UI_CheckActionTokenTypeSanity(void)
Check if the action token list is sorted by alphabet, else dichotomic search can't work...
cvarChangeListenerFunc_t exec
struct uiAction_s::@14::@15 nonTerminal
Stores a none terminal action (a command or an operator)
bool _Mem_AllocatedInPool(memPool_t *pool, const void *pointer)
int UI_GetActionTokenType(const char *token, int group)
return an action type from a token, and a group
static void UI_RemoveListener_f(void)
Remove a function callback from a node event.
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
void LIST_AddString(linkedList_t **listDest, const char *data)
Adds an string to a new or to an already existing linked list. The string is copied here...
const char * UI_GetStringFromExpression(uiAction_t *expression, const uiCallContext_t *context)
QGL_EXTERN GLuint GLsizei GLsizei * length
memPool_t * ui_dynStringPool
static const ui_typedActionToken_t actionTokens[]
List of typed token.
static void UI_ExecuteCallAction(const uiAction_t *action, const uiCallContext_t *context)
static void UI_NodeSetPropertyFromActionValue(uiNode_t *node, const value_t *property, const uiCallContext_t *context, uiAction_t *value)
void UI_ExecuteEventActionsEx(uiNode_t *source, const uiAction_t *firstAction, linkedList_t *params)
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
uiNode_t * UI_GetNodeFromExpression(uiAction_t *expression, const uiCallContext_t *context, const value_t **property)
Get a node and a property from an expression.
const char * UI_GetPath(const uiNode_t *node)
Return a path from a window to a node.
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
static void UI_AddCvarListener_f(void)
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
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.
const linkedList_t * LIST_ContainsString(const linkedList_t *list, const char *string)
Searches for the first occurrence of a given string.
Atomic structure used to define most of the UI.
bool LIST_RemoveEntry(linkedList_t **list, linkedList_t *entry)
Removes one entry from the linked list.
static void UI_ExecuteSetAction(const uiAction_t *action, const uiCallContext_t *context)
bool Cvar_Delete(const char *varName)
Function to remove the cvar and free the space.
Contain the context of the calling of a function.
void UI_NodeSetPropertyFromRAW(uiNode_t *node, const value_t *property, const void *rawValue, int rawType)
int UI_GetParamNumber(const uiCallContext_t *context)
void UI_ExecuteConFuncActions(uiNode_t *source, const uiAction_t *firstAction)
allow to inject command param into cmd of confunc command
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. ) by a value.
#define V_UI_NODEMETHOD_LUA
cvarChangeListener_t * changeListener
const char * CL_Translate(const char *t)
union uiValue_s::@17 value
uiValue_t variableStack[UI_MAX_VARIABLESTACK]
Local var for script function.
bool UI_InitRawActionValue(uiAction_t *action, uiNode_t *node, const value_t *property, const char *string)
#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 ...
struct uiAction_s * next
Next element in the action list.
Type for uiAction_t It also contain type about type (for example EA_BINARYOPERATOR) ...
cvar_t * Cvar_ForceSet(const char *varName, const char *value)
Will set the variable even if NOSET or LATCH.
GLsizei const GLvoid * data
struct cvarChangeListener_s * next
#define Mem_PoolStrDup(in, pool, tagNum)
static void UI_ReleaseVariable(uiValue_t *variable)
void(* uiNodeMethod_t)(uiNode_t *node, const struct uiCallContext_s *context)
Signature of a function to bind a node method.
const char * UI_GetStringFromNodeProperty(const uiNode_t *node, const value_t *property)
Return a string from a node property.
bool LIST_IsEmpty(const linkedList_t *list)
Checks whether the given list is empty.
#define Mem_PoolAllocType(type, pool)
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 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. ...
cvar_t * Cvar_FindVar(const char *varName)
Searches for a cvar given by parameter.
short type
Define the type of the element, it can be a command, an operator, or a value.
Atomic element to store UI scripts The parser use this atom to translate script action into many tree...
static void UI_RemoveCvarListener_f(void)
static void UI_ExecuteActions(const uiAction_t *firstAction, uiCallContext_t *context)
Execute a tree of actions from a source.
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.