UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_option.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#include "../ui_main.h"
26#include "../ui_parse.h"
27#include "../ui_behaviour.h"
28#include "../ui_sprite.h"
30#include "ui_node_option.h"
31
32#include "../../client.h" /* gettext _() */
33
35
40
41#define EXTRADATA_TYPE optionExtraData_t
42#define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
43#define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
44
46
47
54{
55 int count = 0;
56 while (option) {
57 int localCount = 0;
58 assert(option->behaviour == ui_optionBehaviour);
59 if (option->invis) {
60 option = option->next;
61 continue;
62 }
63 if (OPTIONEXTRADATA(option).collapsed) {
64 OPTIONEXTRADATA(option).childCount = 0;
65 option = option->next;
66 count++;
67 continue;
68 }
69 if (option->firstChild)
70 localCount = UI_OptionUpdateCache(option->firstChild);
71 OPTIONEXTRADATA(option).childCount = localCount;
72 count += 1 + localCount;
73 option = option->next;
74 }
75 return count;
76}
77
79{
80 uiNode_t* child = node->firstChild;
81 int count = 0;
82
83 while (child && child->behaviour == ui_optionBehaviour) {
84 UI_Validate(child);
85 if (!child->invis) {
86 if (EXTRADATA(child).collapsed)
87 count += 1 + EXTRADATA(child).childCount;
88 else
89 count += 1;
90 }
91 child = child->next;
92 }
93 EXTRADATA(node).childCount = count;
94 node->invalidated = false;
95}
96
98{
99 if (property == propertyCollapsed) {
100 UI_Invalidate(node);
101 return;
102 }
103 uiLocatedNode::onPropertyChanged(node, property);
104}
105
112static void UI_InitOption (uiNode_t* option, const char* label, const char* value)
113{
114 assert(option);
115 assert(option->behaviour == ui_optionBehaviour);
116 Q_strncpyz(OPTIONEXTRADATA(option).label, label, sizeof(OPTIONEXTRADATA(option).label));
117 Q_strncpyz(OPTIONEXTRADATA(option).value, value, sizeof(OPTIONEXTRADATA(option).value));
118}
119
126uiNode_t* UI_AllocOptionNode (const char* name, const char* label, const char* value)
127{
128 uiNode_t* option;
129 option = UI_AllocNode(name, "option", true);
130 UI_InitOption(option, label, value);
131 return option;
132}
133
134void UI_Option_SetLabel (uiNode_t* node, const char* text) {
135 Q_strncpyz(OPTIONEXTRADATA(node).label, text, sizeof(OPTIONEXTRADATA(node).label));
136}
137
138void UI_Option_SetValue (uiNode_t* node, const char* text) {
139 Q_strncpyz(OPTIONEXTRADATA(node).value, text, sizeof(OPTIONEXTRADATA(node).value));
140}
141
142void UI_Option_SetIconByName (uiNode_t* node, const char* name) {
144 OPTIONEXTRADATA(node).icon = sprite;
145}
146
148{
149 behaviour->name = "option";
150 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
151 behaviour->manager = UINodePtr(new uiOptionNode());
152 behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiOptionNode_t *");
153
157 UI_RegisterExtradataNodeProperty(behaviour, "label", V_STRING, EXTRADATA_TYPE, label);
158
162 UI_RegisterExtradataNodeProperty(behaviour, "value", V_STRING, EXTRADATA_TYPE, value);
163
167 propertyCollapsed = UI_RegisterExtradataNodeProperty(behaviour, "collapsed", V_BOOL, EXTRADATA_TYPE, collapsed);
168
169 /* Icon used to display the node
170 */
172 UI_RegisterExtradataNodeProperty(behaviour, "flipicon", V_BOOL, EXTRADATA_TYPE, flipIcon);
173
174 ui_optionBehaviour = behaviour;
175}
virtual void onPropertyChanged(uiNode_t *node, const value_t *property)
void doLayout(uiNode_t *node) override
Call to update the node layout. This common code revalidates the node tree.
void onPropertyChanged(uiNode_t *node, const value_t *property) override
Primary header for client.
QGL_EXTERN GLuint count
Definition r_gl.h:99
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
@ V_BOOL
Definition scripts.h:50
@ V_STRING
Definition scripts.h:58
Header for lua script functions.
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition shared.cpp:457
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
bool invalidated
Definition ui_nodes.h:104
uiBehaviour_t * behaviour
Definition ui_nodes.h:83
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
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
void UI_Invalidate(uiNode_t *node)
Invalidate a node and all his parent to request a layout update.
Definition ui_node.cpp:1065
SharedPtr< uiNode > UINodePtr
#define EXTRADATA_TYPE
#define EXTRADATA(node)
const uiBehaviour_t * ui_optionBehaviour
uiNode_t * UI_AllocOptionNode(const char *name, const char *label, const char *value)
Initializes an option with a very little set of values.
int UI_OptionUpdateCache(uiNode_t *option)
update option cache about child, according to collapse and visible status
void UI_Option_SetIconByName(uiNode_t *node, const char *name)
static void UI_InitOption(uiNode_t *option, const char *label, const char *value)
Initializes an option with a very little set of values.
void UI_Option_SetLabel(uiNode_t *node, const char *text)
void UI_RegisterOptionNode(uiBehaviour_t *behaviour)
void UI_Option_SetValue(uiNode_t *node, const char *text)
static const value_t * propertyCollapsed
#define OPTIONEXTRADATA(node)
const uiBehaviour_t * ui_optionBehaviour
uiNode_t * UI_AllocNode(const char *name, const char *type, bool isDynamic)
Allocate a node into the UI memory.
Definition ui_nodes.cpp:381
#define V_UI_SPRITEREF
Definition ui_parse.h:56
uiSprite_t * UI_GetSpriteByName(const char *name)
Return an sprite by is name.