UFO: Alien Invasion
ui_data.cpp File Reference
#include "../cl_shared.h"
#include "../cl_language.h"
#include "ui_main.h"
#include "ui_internal.h"
#include "ui_nodes.h"
#include "node/ui_node_option.h"
Include dependency graph for ui_data.cpp:

Go to the source code of this file.

Functions

 CASSERT (lengthof(ui_sharedDataIDNames)==UI_MAX_DATAID)
 
int UI_GetDataIDByName (const char *name)
 Return a dataId by name. More...
 
void UI_RegisterText (int dataId, const char *text)
 share a text with a data id More...
 
void UI_RegisterLinkedListText (int dataId, linkedList_t *text)
 share a linked list of text with a data id More...
 
const char * UI_GetText (int textId)
 
const char * UI_GetTextFromList (int textId, int line)
 
int UI_GetDataVersion (int textId)
 
uiNode_tUI_AddOption (uiNode_t **tree, const char *name, const char *label, const char *value)
 Append an option to an option list. More...
 
static void UI_DeleteOption (uiNode_t *tree)
 
void UI_ResetData (int dataId)
 Reset a shared data. Type became NONE and value became nullptr. More...
 
static uiNode_tUI_OptionNodeRemoveHigherOption (uiNode_t **option)
 Remove the higher element (in alphabet) from a list. More...
 
void UI_SortOptions (uiNode_t **first)
 Sort options by alphabet. More...
 
void UI_UpdateInvisOptions (uiNode_t *option, const linkedList_t *stringList)
 Unhide those options that are stored in the linked list and hide the others. More...
 
void UI_RegisterOption (int dataId, uiNode_t *option)
 
uiNode_tUI_GetOption (int dataId)
 
static uiNode_tUI_FindOptionAtIndex (int index, uiNode_t *option, uiOptionIterator_t *iterator)
 find an option why index (0 is the first option) More...
 
uiNode_tUI_InitOptionIteratorAtIndex (int index, uiNode_t *option, uiOptionIterator_t *iterator)
 Init an option iterator at an index. More...
 
uiNode_tUI_InitOptionIteratorAtIndex (int index, uiNode_t *option, uiOptionIterator_t *iterator, bool skipCollapsed, bool skipInvisible)
 Init an option iterator at an index. More...
 
uiNode_tUI_OptionIteratorNextOption (uiOptionIterator_t *iterator)
 Find the next element from the iterator Iterator skipCollapsed and skipInvisible attribute can control the option flow. More...
 
uiNode_tUI_FindOptionByValue (uiOptionIterator_t *iterator, const char *value)
 Find an option (and all his parents) by is value. More...
 
int UI_FindOptionPosition (uiOptionIterator_t *iterator, const uiNode_t *option)
 Find an option position from an option iterator. More...
 
static void UI_ResetData_f (void)
 Resets the ui_global.sharedData pointers from a func node. More...
 
void UI_InitData (void)
 Initialize console command about UI shared data. More...
 

Variables

static const char *const ui_sharedDataIDNames []
 

Function Documentation

◆ CASSERT()

◆ UI_AddOption()

uiNode_t * UI_AddOption ( uiNode_t **  tree,
const char *  name,
const char *  label,
const char *  value 
)

Append an option to an option list.

Parameters
[in,out]treefirst option of the list/tree of options
[in]namename of the option (should be unique in the option list)
[in]labellabel displayed
[in]valuevalue used when this option is selected
Returns
The new option

Definition at line 172 of file ui_data.cpp.

References name, uiNode_t::next, and UI_AllocOptionNode().

Referenced by CL_InitSkin_f(), CL_LanguageInitMenu(), CL_TeamDefInitMenu(), CL_VideoInitMenu(), GAME_GetImportData(), and IN_JoystickInitMenu().

◆ UI_DeleteOption()

static void UI_DeleteOption ( uiNode_t tree)
static
Warning
If we use it with real option node, i will crash the code cause relation with parent node are not updated
Parameters
treeRoot of nodes we want to delete

Definition at line 200 of file ui_data.cpp.

References uiNode_t::next, and UI_DeleteNode().

Referenced by UI_ResetData().

◆ UI_FindOptionAtIndex()

static uiNode_t * UI_FindOptionAtIndex ( int  index,
uiNode_t option,
uiOptionIterator_t iterator 
)
static

find an option why index (0 is the first option)

Parameters
[in]indexRequested index (0 is the first option)
[in]optionFirst element of options (it can be a tree)
[in,out]iteratorneed an initialised iterator, and update it into the write index

Definition at line 338 of file ui_data.cpp.

References uiNode_t::behaviour, uiOptionIterator_t::depthCache, uiOptionIterator_t::depthPos, uiNode_t::firstChild, index, uiNode_t::invis, MAX_DEPTH_OPTIONITERATORCACHE, uiNode_t::next, uiOptionIterator_t::option, OPTIONEXTRADATA, UI_FindOptionAtIndex(), and ui_optionBehaviour.

Referenced by UI_FindOptionAtIndex(), and UI_InitOptionIteratorAtIndex().

◆ UI_FindOptionByValue()

uiNode_t * UI_FindOptionByValue ( uiOptionIterator_t iterator,
const char *  value 
)

Find an option (and all his parents) by is value.

Parameters
[in,out]iteratorIf it found an option, the iterator contain all option parent
[in]valueThe value we search
Returns
The right option, else nullptr

Definition at line 468 of file ui_data.cpp.

References uiNode_t::behaviour, uiOptionIterator_t::option, OPTIONEXTRADATA, Q_streq, ui_optionBehaviour, and UI_OptionIteratorNextOption().

Referenced by UI_OptionTree_SelectValue().

◆ UI_FindOptionPosition()

int UI_FindOptionPosition ( uiOptionIterator_t iterator,
const uiNode_t option 
)

Find an option position from an option iterator.

Parameters
[in,out]iteratorContext of the iteration. If it found an option, the iterator contain all option parent
[in]optionThe value we search
Returns
The option index, else -1

Definition at line 485 of file ui_data.cpp.

References i, uiOptionIterator_t::option, and UI_OptionIteratorNextOption().

Referenced by UI_OptionTree_SelectValue().

◆ UI_GetDataIDByName()

int UI_GetDataIDByName ( const char *  name)

Return a dataId by name.

Returns
A dataId if data found, else -1

Definition at line 102 of file ui_data.cpp.

References name, Q_streq, UI_MAX_DATAID, and ui_sharedDataIDNames.

Referenced by UI_AbstractOption_SetDataIdByName(), UI_ParseProperty(), and UI_ResetData_f().

◆ UI_GetDataVersion()

◆ UI_GetOption()

◆ UI_GetText()

◆ UI_GetTextFromList()

const char * UI_GetTextFromList ( int  textId,
int  line 
)

◆ UI_InitData()

void UI_InitData ( void  )

Initialize console command about UI shared data.

Note
called by UI_Init

Definition at line 521 of file ui_data.cpp.

References Cmd_AddCommand(), and UI_ResetData_f().

Referenced by UI_Init().

◆ UI_InitOptionIteratorAtIndex() [1/2]

uiNode_t * UI_InitOptionIteratorAtIndex ( int  index,
uiNode_t option,
uiOptionIterator_t iterator 
)

Init an option iterator at an index.

Note
invis option are skipped, and child are counted
Parameters
[in]indexRequested index (0 is the first option)
[in]optionFirst element of options (it can be a tree)
[out]iteratorInitialised iterator
Returns
the first option element found (current position of the iterator)
UI_InitOptionIteratorAtIndex(index, firstOption, &iterator); // also return the option
while (iterator.option) {
...
UI_OptionIteratorNextOption(&iterator); // also return the option
}
QGL_EXTERN GLuint index
Definition: r_gl.h:110
uiNode_t * option
Definition: ui_data.h:60
uiNode_t * UI_InitOptionIteratorAtIndex(int index, uiNode_t *option, uiOptionIterator_t *iterator)
Init an option iterator at an index.
Definition: ui_data.cpp:394
uiNode_t * UI_OptionIteratorNextOption(uiOptionIterator_t *iterator)
Find the next element from the iterator Iterator skipCollapsed and skipInvisible attribute can contro...
Definition: ui_data.cpp:430
Todo:
Rework that code, we should split "Init" and "AtIndex"

Definition at line 394 of file ui_data.cpp.

References index, and UI_InitOptionIteratorAtIndex().

Referenced by uiOptionTreeNode::draw(), GAME_GetImportData(), UI_InitOptionIteratorAtIndex(), UI_OptionTree_SelectValue(), and UI_OptionTreeNodeGetOptionAtPosition().

◆ UI_InitOptionIteratorAtIndex() [2/2]

uiNode_t * UI_InitOptionIteratorAtIndex ( int  index,
uiNode_t option,
uiOptionIterator_t iterator,
bool  skipCollapsed,
bool  skipInvisible 
)

Init an option iterator at an index.

Note
invis option are skipped, and child are counted
Parameters
[in]indexRequested index (0 is the first option)
[in]optionFirst element of options (it can be a tree)
[in]skipCollapsedSet to true to skip collapsed nodes in the iteration.
[in]skipInvisibleSet to true to skip invisible nodes in the iteration.
[out]iteratorInitialised iterator
Returns
the first option element found (current position of the iterator)
UI_InitOptionIteratorAtIndex(index, firstOption, &iterator); // also return the option
while (iterator.option) {
...
UI_OptionIteratorNextOption(&iterator); // also return the option
}
Todo:
Rework that code, we should split "Init" and "AtIndex"

Definition at line 417 of file ui_data.cpp.

References uiNode_t::behaviour, index, OBJZERO, uiOptionIterator_t::skipCollapsed, uiOptionIterator_t::skipInvisible, UI_FindOptionAtIndex(), and ui_optionBehaviour.

◆ UI_OptionIteratorNextOption()

uiNode_t * UI_OptionIteratorNextOption ( uiOptionIterator_t iterator)

◆ UI_OptionNodeRemoveHigherOption()

static uiNode_t * UI_OptionNodeRemoveHigherOption ( uiNode_t **  option)
static

Remove the higher element (in alphabet) from a list.

Todo:
option should start with '_' if we need to translate it
Warning
update parent

Definition at line 240 of file ui_data.cpp.

References CL_Translate(), uiNode_t::next, and OPTIONEXTRADATA.

Referenced by UI_SortOptions().

◆ UI_RegisterLinkedListText()

void UI_RegisterLinkedListText ( int  dataId,
linkedList_t text 
)

share a linked list of text with a data id

Note
The UI code manage the linked list memory (linked list is freed by the UI code)
Todo:
FIXME It is a hack to disable release memory, if we only want to update the same list

Definition at line 131 of file ui_data.cpp.

References uiSharedData_t::data, uiSharedData_t::linkedListText, uiGlobal_t::sharedData, uiSharedData_t::type, ui_global, UI_ResetData(), UI_SHARED_LINKEDLISTTEXT, and uiSharedData_t::versionId.

Referenced by GAME_GetImportData(), GAME_InitMissionBriefing(), Irc_Client_Names_f(), UI_MaterialEditorUpdate(), and UI_PopupList().

◆ UI_RegisterOption()

void UI_RegisterOption ( int  dataId,
uiNode_t option 
)

◆ UI_RegisterText()

◆ UI_ResetData()

◆ UI_ResetData_f()

static void UI_ResetData_f ( void  )
static

Resets the ui_global.sharedData pointers from a func node.

Note
You can give this function a parameter to only delete a specific data
See also
ui_sharedDataIDNames

Definition at line 502 of file ui_data.cpp.

References Cmd_Argc(), Cmd_Argv(), Com_Printf(), i, UI_GetDataIDByName(), UI_MAX_DATAID, and UI_ResetData().

Referenced by UI_InitData().

◆ UI_SortOptions()

void UI_SortOptions ( uiNode_t **  first)

Sort options by alphabet.

Definition at line 273 of file ui_data.cpp.

References uiNode_t::next, and UI_OptionNodeRemoveHigherOption().

Referenced by CL_LanguageInitMenu(), GAME_GetImportData(), and UI_AbstractOption_SortOptions().

◆ UI_UpdateInvisOptions()

void UI_UpdateInvisOptions ( uiNode_t option,
const linkedList_t stringList 
)

Unhide those options that are stored in the linked list and hide the others.

Parameters
[in,out]optionOption list we want to update
[in]stringListList of option name (ID) we want to display

Definition at line 297 of file ui_data.cpp.

References uiNode_t::invis, LIST_ContainsString(), uiNode_t::name, and uiNode_t::next.

Referenced by GAME_GetImportData().

Variable Documentation

◆ ui_sharedDataIDNames

const char* const ui_sharedDataIDNames[]
static

Definition at line 37 of file ui_data.cpp.

Referenced by UI_GetDataIDByName().