UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_abstractoption.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "../ui_main.h"
27#include "../ui_internal.h"
28#include "../ui_parse.h"
29#include "../ui_draw.h"
30#include "../ui_data.h"
31#include "../ui_lua.h"
32
35
37
38#define EXTRADATA_TYPE abstractOptionExtraData_t
39#define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
40
45{
46 uiNode_t* option;
47 assert(UI_Node_IsOptionContainer(node));
49
52 option = node->firstChild;
53 while (option->next)
54 option = option->next;
55 node->lastChild = option;
56}
57
59{
60 /* no cvar given? */
61 if (!EXTRADATA(node).cvar || !*EXTRADATA(node).cvar) {
62 Com_Printf("UI_AbstractOptionGetCurrentValue: node [%s] doesn't have a valid cvar assigned\n", UI_GetPath(node));
63 return nullptr;
64 }
65
66 /* not a cvar? */
67 if (!Q_strstart(EXTRADATA(node).cvar, "*cvar:")) {
68 Com_Printf("UI_AbstractOptionGetCurrentValue: in node [%s], the name [%s] is not a value cvar\n", UI_GetPath(node), EXTRADATA(node).cvar);
69 return nullptr;
70 }
71
72 return UI_GetReferenceString(node, EXTRADATA(node).cvar);
73}
74
75void UI_AbstractOption_SetCurrentValue(uiNode_t* node, const char* value)
76{
77 const char* cvarName = &EXTRADATA(node).cvar[6];
78 Cvar_Set(cvarName, "%s", value);
79 if (node->onChange) {
81 }
82 if (node->lua_onChange != LUA_NOREF) {
84 }
85}
86
89 EXTRADATA(node).lua_onViewChange = LUA_NOREF;
90}
91
93{
94 uiNode_t* option = node->firstChild;
95
96 if (EXTRADATA(node).dataId == 0) {
97 int count = 0;
98 while (option && option->behaviour == ui_optionBehaviour) {
99 UI_Validate(option);
100 if (!option->invis)
101 count++;
102 option = option->next;
103 }
104
105 EXTRADATA(node).count = count;
106 }
107
108 node->invalidated = false;
109}
110
116{
117 if (node->firstChild && node->firstChild->behaviour == ui_optionBehaviour) {
118 return node->firstChild;
119 } else {
120 const int v = UI_GetDataVersion(EXTRADATA(node).dataId);
121 if (v != EXTRADATA(node).versionId) {
122 int count = 0;
123 uiNode_t* option = UI_GetOption(EXTRADATA(node).dataId);
124 while (option) {
125 if (!option->invis)
126 count++;
127 option = option->next;
128 }
129 EXTRADATA(node).count = count;
130 EXTRADATA(node).versionId = v;
131 }
132 return UI_GetOption(EXTRADATA(node).dataId);
133 }
134}
135
142{
143 return 1;
144}
145
152{
153 return 1;
154}
155
157 return EXTRADATA(node).dataId;
158}
159
161 return EXTRADATA(node).count;
162}
163
165 return EXTRADATA(node).cvar;
166}
167
169 EXTRADATA(node).dataId = id;
170}
171
173 EXTRADATA(node).dataId = UI_GetDataIDByName(name);
174}
175
176void UI_AbstractOption_SetCvar (uiNode_t* node, const char* name) {
177 cvar_t* var = Cvar_Get(name);
178 EXTRADATA(node).cvar = var->name;
179}
180
183 UI_EXTRADATA(node, abstractOptionExtraData_t).background = sprite;
184}
185
187 return EXTRADATA(node).scrollY.viewPos;
188}
189
191 EXTRADATA(node).scrollY.move(pos);
192}
193
195 EXTRADATA(node).scrollY.set(-1, size, -1);
196}
197
199 EXTRADATA(node).scrollY.set(-1, -1, size);
200}
201
203 return EXTRADATA(node).scrollY.viewSize;
204}
205
207 return EXTRADATA(node).scrollY.fullSize;
208}
209
210
212{
213 behaviour->name = "abstractoption";
214 behaviour->isAbstract = true;
215 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
216 behaviour->drawItselfChild = true;
217 behaviour->manager = UINodePtr(new uiAbstractOptionNode());
218 behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiAbstractOptionNode_t *");
219
221 UI_RegisterExtradataNodeProperty(behaviour, "dataid", V_UI_DATAID, EXTRADATA_TYPE, dataId);
223 UI_RegisterExtradataNodeProperty(behaviour, "lineheight", V_INT, EXTRADATA_TYPE, lineHeight);
224
225 /* position of the vertical view (into the full number of elements the node contain) */
226 UI_RegisterExtradataNodeProperty(behaviour, "viewpos", V_INT, EXTRADATA_TYPE, scrollY.viewPos);
227 /* size of the vertical view (proportional to the number of elements the node can display without moving) */
228 UI_RegisterExtradataNodeProperty(behaviour, "viewsize", V_INT, EXTRADATA_TYPE, scrollY.viewSize);
229 /* full vertical size (proportional to the number of elements the node contain) */
230 UI_RegisterExtradataNodeProperty(behaviour, "fullsize", V_INT, EXTRADATA_TYPE, scrollY.fullSize);
231
232 /* number of elements contain the node */
234
235 /* Define the cvar containing the value of the current selected option */
237
238 /* Called when one of the properties viewpos/viewsize/fullsize change */
239 UI_RegisterExtradataNodeProperty(behaviour, "onviewchange", V_UI_ACTION, EXTRADATA_TYPE, onViewChange);
240}
int getCellHeight(uiNode_t *node) override
Return size of the cell, which is the size (in virtual "pixel") which represents 1 in the scroll valu...
void doLayout(uiNode_t *node) override
Call to update the node layout. This common code revalidates the node tree.
void initNode(uiNode_t *node) override
int getCellWidth(uiNode_t *node) override
Return size of the cell, which is the size (in virtual "pixel") which represents 1 in the scroll valu...
virtual void initNode(uiNode_t *node)
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition cvar.cpp:615
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition cvar.cpp:342
voidpf void uLong size
Definition ioapi.h:42
QGL_EXTERN GLuint count
Definition r_gl.h:99
QGL_EXTERN int GLboolean GLfloat * v
Definition r_gl.h:120
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
QGL_EXTERN GLuint * id
Definition r_gl.h:86
@ V_INT
Definition scripts.h:52
Header for lua script functions.
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
Definition shared.cpp:587
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition cvar.h:71
char * name
Definition cvar.h:72
node behaviour, how a node work
const char * name
void * lua_SWIG_typeinfo
UINodePtr manager
intptr_t extraDataSize
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiNode_t * firstChild
Definition ui_nodes.h:89
bool invis
Definition ui_nodes.h:101
uiNode_t * next
Definition ui_nodes.h:91
uiNode_t * lastChild
Definition ui_nodes.h:90
bool invalidated
Definition ui_nodes.h:104
uiBehaviour_t * behaviour
Definition ui_nodes.h:83
LUA_EVENT lua_onChange
Definition ui_nodes.h:162
struct uiAction_s * onChange
Definition ui_nodes.h:143
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
int UI_GetDataIDByName(const char *name)
Return a dataId by name.
Definition ui_data.cpp:102
uiNode_t * UI_GetOption(int dataId)
Definition ui_data.cpp:324
void UI_SortOptions(uiNode_t **first)
Sort options by alphabet.
Definition ui_data.cpp:273
int UI_GetDataVersion(int textId)
Definition ui_data.cpp:159
Data and interface to share data.
Internal data use by the UI package.
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
Definition ui_lua.cpp:71
Basic lua initialization for the ui.
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
void UI_Validate(uiNode_t *node)
Validate a node tree.
Definition ui_node.cpp:1078
bool UI_Node_IsOptionContainer(uiNode_t const *node)
Definition ui_node.cpp:54
SharedPtr< uiNode > UINodePtr
void UI_AbstractOption_Scroll_SetCurrent(uiNode_t *node, int pos)
int UI_AbstractOption_GetCount(uiNode_t *node)
int UI_AbstractOption_Scroll_ViewSize(uiNode_t *node)
#define EXTRADATA_TYPE
uiNode_t * UI_AbstractOption_GetFirstOption(uiNode_t *node)
Return the first option of the node.
const char * UI_AbstractOption_GetCurrentValue(uiNode_t *node)
int UI_AbstractOption_GetDataId(uiNode_t *node)
void UI_AbstractOption_Scroll_SetViewSize(uiNode_t *node, int size)
void UI_AbstractOption_SetCvar(uiNode_t *node, const char *name)
#define EXTRADATA(node)
int UI_AbstractOption_Scroll_Current(uiNode_t *node)
void UI_AbstractOption_SetDataId(uiNode_t *node, int id)
void UI_AbstractOption_SetDataIdByName(uiNode_t *node, const char *name)
void UI_AbstractOption_Scroll_SetFullSize(uiNode_t *node, int size)
void UI_AbstractOption_SetBackgroundByName(uiNode_t *node, const char *name)
const char * UI_AbstractOption_GetCvar(uiNode_t *node)
void UI_RegisterAbstractOptionNode(uiBehaviour_t *behaviour)
void UI_AbstractOption_SetCurrentValue(uiNode_t *node, const char *value)
void UI_AbstractOption_SortOptions(uiNode_t *node)
Sort options by alphabet.
int UI_AbstractOption_Scroll_FullSize(uiNode_t *node)
const uiBehaviour_t * ui_optionBehaviour
const char * UI_GetPath(const uiNode_t *node)
Return a path from a window to a node.
Definition ui_nodes.cpp:174
#define UI_EXTRADATA(NODE, TYPE)
Definition ui_nodes.h:185
const char * UI_GetReferenceString(const uiNode_t *const node, const char *ref)
#define V_UI_DATAID
Definition ui_parse.h:58
#define V_UI_ACTION
Definition ui_parse.h:54
#define V_UI_CVAR
Definition ui_parse.h:59
uiSprite_t * UI_GetSpriteByName(const char *name)
Return an sprite by is name.