UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_parse.cpp File Reference
#include "../client.h"
#include "ui_parse.h"
#include "ui_main.h"
#include "ui_node.h"
#include "ui_data.h"
#include "ui_internal.h"
#include "ui_actions.h"
#include "ui_sprite.h"
#include "ui_components.h"
#include "node/ui_node_window.h"
#include "node/ui_node_selectbox.h"
#include "node/ui_node_abstractnode.h"
#include "node/ui_node_abstractoption.h"
#include "../../shared/parse.h"
#include "../cl_language.h"
Include dependency graph for ui_parse.cpp:

Go to the source code of this file.

Functions

static bool UI_ParseProperty (void *object, const value_t *property, const char *objectName, const char **text, const char **token)
 Parse a property value.
static uiAction_tUI_ParseActionList (uiNode_t *node, const char **text, const char **token)
 Parse actions and return action list.
static uiNode_tUI_ParseNode (uiNode_t *parent, const char **text, const char **token, const char *errhead)
 parse a node
bool UI_TokenIsReserved (const char *name)
static bool UI_TokenIsValue (const char *name, bool isQuoted)
bool UI_TokenIsName (const char *name, bool isQuoted)
const value_tUI_FindPropertyByName (const value_t *propertyList, const char *name)
 Find a value_t by name into a array of value_t.
float * UI_AllocStaticFloat (int count)
 Allocate a float into the UI static memory.
vec4_tUI_AllocStaticColor (int count)
 Allocate a color into the UI static memory.
char * UI_AllocStaticString (const char *string, int size)
 Allocate a string into the UI static memory.
uiAction_tUI_AllocStaticAction (void)
 Allocate an action.
bool UI_InitRawActionValue (uiAction_t *action, uiNode_t *node, const value_t *property, const char *string)
static bool UI_ParseSetAction (uiNode_t *node, uiAction_t *action, const char **text, const char **token, const char *errhead)
 Parser for setter command.
static bool UI_ParseCallAction (uiNode_t *node, uiAction_t *action, const char **text, const char **token, const char *errhead)
 Parser for call command.
static bool UI_ParseExcludeRect (uiNode_t *node, const char **text, const char **token, const char *errhead)
static bool UI_ParseEventProperty (uiNode_t *node, const value_t *event, const char **text, const char **token, const char *errhead)
static bool UI_ParseFunction (uiNode_t *node, const char **text, const char **token)
static bool UI_ParseNodeProperties (uiNode_t *node, const char **text, const char **token)
 parse all sequencial properties into a block
static bool UI_ParseNodeBody (uiNode_t *node, const char **text, const char **token, const char *errhead)
 Read a node body.
bool UI_ParseUIModel (const char *name, const char **text)
 parses the models.ufo and all files where UI models (menu_model) are defined
bool UI_ParseSprite (const char *name, const char **text)
bool UI_ParseComponent (const char *type, const char *name, const char **text)
 Parse a component.
bool UI_ParseWindow (const char *type, const char *name, const char **text)
 Parse a window.
const char * UI_GetReferenceString (const uiNode_t *const node, const char *ref)
float UI_GetReferenceFloat (const uiNode_t *const node, const void *ref)
 Returns the value of the reference variable.

Variables

static const value_t uiModelProperties []
 valid properties for a UI model definition
static char const *const reservedTokens []
 reserved token preventing calling a node with it

Detailed Description

Todo

remove all "token" param from function and use Com_UnParseLastToken

reduce use of uiGlobal (create global functions to add/get/... entities)

remove Com_EParseValue and use Com_ParseValue

Definition in file ui_parse.cpp.

Function Documentation

◆ UI_AllocStaticAction()

uiAction_t * UI_AllocStaticAction ( void )

Allocate an action.

Returns
An action

Definition at line 221 of file ui_parse.cpp.

References Com_Error(), ERR_FATAL, ui_global, and UI_MAX_ACTIONS.

Referenced by UI_AllocStaticCommandAction(), UI_ParseActionList(), UI_ParseExpression(), UI_ParseSetAction(), and UI_ParseValueExpression().

◆ UI_AllocStaticColor()

vec4_t * UI_AllocStaticColor ( int count)

Allocate a color into the UI static memory.

Note
Its not a dynamic memory allocation. Please only use it at the loading time
Parameters
[in]countnumber of element need to allocate
Todo
Assert out when we are not in parsing/loading stage

Definition at line 187 of file ui_parse.cpp.

References Com_Error(), count, ERR_FATAL, and UI_AllocHunkMemory().

◆ UI_AllocStaticFloat()

float * UI_AllocStaticFloat ( int count)

Allocate a float into the UI static memory.

Note
Its not a dynamic memory allocation. Please only use it at the loading time
Parameters
[in]countnumber of element need to allocate
Todo
Assert out when we are not in parsing/loading stage

Definition at line 171 of file ui_parse.cpp.

References Com_Error(), count, ERR_FATAL, and UI_AllocHunkMemory().

Referenced by UI_CloneCvarOrFloat(), and UI_InitCvarOrFloat().

◆ UI_AllocStaticString()

char * UI_AllocStaticString ( const char * string,
int size )

Allocate a string into the UI static memory.

Note
Its not a dynamic memory allocation. Please only use it at the loading time
Parameters
[in]stringUse to initialize the string
[in]sizerequest a fixed memory size, if 0 the string size is used
Todo
Assert out when we are not in parsing/loading stage

Definition at line 204 of file ui_parse.cpp.

References Com_Error(), ERR_FATAL, Q_strncpyz(), and UI_AllocHunkMemory().

Referenced by uiModelNode::clone(), uiModelNode::doLayout(), UI_AutoGenerateSprite(), UI_InitRawActionValue(), UI_ParseActionList(), UI_ParseSetAction(), and UI_ParseValueExpression().

◆ UI_FindPropertyByName()

const value_t * UI_FindPropertyByName ( const value_t * propertyList,
const char * name )

Find a value_t by name into a array of value_t.

Parameters
[in]propertyListArray of value_t, with null termination
[in]nameProperty name we search
Returns
A value_t with the requested name, else nullptr

Definition at line 154 of file ui_parse.cpp.

References name, Q_strcasecmp, and value_t::string.

Referenced by UI_MaterialEditorChangeValue_f(), UI_ParseSprite(), and UI_ParseUIModel().

◆ UI_GetReferenceFloat()

float UI_GetReferenceFloat ( const uiNode_t *const node,
const void * ref )

Returns the value of the reference variable.

Note
A reference variable is either a pointer to a float or a pointer to a string. In case of a pointer to a string, a Cvar name is expected, starting with "*cvar".
See also
uiAbstractValueNode

Definition at line 1434 of file ui_parse.cpp.

References Cvar_GetValue(), and Q_strstart().

Referenced by uiAbstractValueNode::decValue(), uiAbstractValueNode::getDelta(), uiAbstractValueNode::getMax(), uiAbstractValueNode::getMin(), uiAbstractValueNode::getValue(), uiAbstractValueNode::incValue(), uiRadioButtonNode::onActivate(), uiAbstractValueNode::setDelta(), uiAbstractValueNode::setMax(), uiAbstractValueNode::setMin(), uiAbstractValueNode::setValue(), UI_GetStringFromNodeProperty(), and UI_RadioButtonNodeIsSelected().

◆ UI_GetReferenceString()

◆ UI_InitRawActionValue()

bool UI_InitRawActionValue ( uiAction_t * action,
uiNode_t * node,
const value_t * property,
const char * string )

Parse a string according to a property type, and allocate a raw value to the static memory

Parameters
actionAction to initialize
nodeCurrent node we are parsing, only used for error message
propertyType of the value to parse, if nullptr the string is not stored as string
stringString value to parse
Returns
True if the action is initialized
Todo
remove node param and catch error where we call that function
Todo
we should hide use of ui_global.curadata

Definition at line 238 of file ui_parse.cpp.

References Com_AlignPtr(), Com_EParseValue(), Com_Printf(), uiAction_t::d, uiAction_t::d1, uiAction_t::d2, uiTerminalActionData_t::data, EA_VALUE_RAW, EA_VALUE_STRING, uiTerminalActionData_t::integer, value_t::size, value_t::string, uiAction_t::terminal, uiAction_t::type, value_t::type, UI_AllocStaticString(), UI_GetPath(), UI_GetSpriteByName(), ui_global, V_BASETYPEMASK, V_UI_CVAR, V_UI_MASK, and V_UI_SPRITEREF.

Referenced by UI_NodeSetPropertyFromActionValue(), and UI_ParseSetAction().

◆ UI_ParseActionList()

uiAction_t * UI_ParseActionList ( uiNode_t * node,
const char ** text,
const char ** token )
static

◆ UI_ParseCallAction()

bool UI_ParseCallAction ( uiNode_t * node,
uiAction_t * action,
const char ** text,
const char ** token,
const char * errhead )
static

◆ UI_ParseComponent()

bool UI_ParseComponent ( const char * type,
const char * name,
const char ** text )

◆ UI_ParseEventProperty()

bool UI_ParseEventProperty ( uiNode_t * node,
const value_t * event,
const char ** text,
const char ** token,
const char * errhead )
static

◆ UI_ParseExcludeRect()

bool UI_ParseExcludeRect ( uiNode_t * node,
const char ** text,
const char ** token,
const char * errhead )
static

◆ UI_ParseFunction()

bool UI_ParseFunction ( uiNode_t * node,
const char ** text,
const char ** token )
static

Definition at line 890 of file ui_parse.cpp.

References uiNode_t::onClick, UI_Node_IsFunction(), and UI_ParseActionList().

Referenced by UI_ParseNodeBody().

◆ UI_ParseNode()

uiNode_t * UI_ParseNode ( uiNode_t * parent,
const char ** text,
const char ** token,
const char * errhead )
static

parse a node

See also
UI_ParseNodeProperties
Todo
we can think about merging UI_ParseNodeProperties here
Note
first token already read
dont read more than the need token (last right token is '}' of end of node)

Definition at line 1059 of file ui_parse.cpp.

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

Referenced by UI_ParseNodeBody().

◆ UI_ParseNodeBody()

bool UI_ParseNodeBody ( uiNode_t * node,
const char ** text,
const char ** token,
const char * errhead )
static

Read a node body.

Note
Node header already read, we are over the node name, or '{'
Allowed syntax
{ properties }
OR
{ nodes }
OR
{ { properties } nodes }

Definition at line 978 of file ui_parse.cpp.

References uiNode_t::behaviour, Com_EParse(), Com_Printf(), uiNode_t::name, UI_GetPath(), UI_GetPropertyFromBehaviour(), ui_global, UI_Node_IsFunction(), UI_ParseFunction(), UI_ParseNode(), and UI_ParseNodeProperties().

Referenced by UI_ParseComponent(), UI_ParseNode(), and UI_ParseWindow().

◆ UI_ParseNodeProperties()

bool UI_ParseNodeProperties ( uiNode_t * node,
const char ** text,
const char ** token )
static

parse all sequencial properties into a block

See also
UI_ParseNodeProperties
Note
allow to use an extra block
foobehaviour foonode {
{ properties }
// the function stop reading here
nodes
}
foobehaviour foonode {
properties
// the function stop reading here
nodes
}

Definition at line 920 of file ui_parse.cpp.

References uiNode_t::behaviour, Com_EParse(), Com_Printf(), uiNode_t::name, value_t::string, UI_GetPath(), UI_GetPropertyFromBehaviour(), and UI_ParseProperty().

Referenced by UI_ParseNodeBody().

◆ UI_ParseProperty()

bool UI_ParseProperty ( void * object,
const value_t * property,
const char * objectName,
const char ** text,
const char ** token )
static

◆ UI_ParseSetAction()

◆ UI_ParseSprite()

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

◆ UI_ParseUIModel()

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

◆ UI_ParseWindow()

bool UI_ParseWindow ( const char * type,
const char * name,
const char ** text )

◆ UI_TokenIsName()

bool UI_TokenIsName ( const char * name,
bool isQuoted )

◆ UI_TokenIsReserved()

bool UI_TokenIsReserved ( const char * name)

◆ UI_TokenIsValue()

bool UI_TokenIsValue ( const char * name,
bool isQuoted )
static

Definition at line 93 of file ui_parse.cpp.

References name, and Q_streq.

Referenced by UI_ParseProperty().

Variable Documentation

◆ reservedTokens

char const* const reservedTokens[]
static
Initial value:
= {
"this",
"parent",
"root",
"null",
"super",
"node",
"cvar",
"int",
"float",
"string",
"var",
"child",
nullptr
}

reserved token preventing calling a node with it

Todo
Use dichotomic search

Definition at line 66 of file ui_parse.cpp.

Referenced by UI_TokenIsReserved().

◆ uiModelProperties

const value_t uiModelProperties[]
static
Initial value:
= {
{"model", V_HUNK_STRING, offsetof(uiModel_t, model), 0},
{"need", V_NULL, 0, 0},
{"anim", V_HUNK_STRING, offsetof(uiModel_t, anim), 0},
{"skin", V_INT, offsetof(uiModel_t, skin), sizeof(int)},
{"color", V_COLOR, offsetof(uiModel_t, color), sizeof(vec4_t)},
{"tag", V_HUNK_STRING, offsetof(uiModel_t, tag), 0},
{"parent", V_HUNK_STRING, offsetof(uiModel_t, parent), 0},
{nullptr, V_NULL, 0, 0},
}
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
@ V_HUNK_STRING
Definition scripts.h:69
@ V_NULL
Definition scripts.h:49
@ V_INT
Definition scripts.h:52
@ V_COLOR
Definition scripts.h:57
Model that have more than one part (top and down part of an aircraft).
vec_t vec4_t[4]
Definition ufotypes.h:40

valid properties for a UI model definition

Definition at line 51 of file ui_parse.cpp.

Referenced by UI_ParseUIModel().