UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
ui_popup.cpp
Go to the documentation of this file.
1
4
5
/*
6
Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8
This program is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License
10
as published by the Free Software Foundation; either version 2
11
of the License, or (at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17
See the GNU General Public License for more details.
18
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23
*/
24
25
#include "
ui_main.h
"
26
#include "
ui_nodes.h
"
27
#include "
ui_node.h
"
28
#include "
ui_popup.h
"
29
#include "
ui_actions.h
"
30
#include "
node/ui_node_abstractnode.h
"
31
32
#define POPUPBUTTON_WINDOW_NAME "popup_button"
33
#define POPUPBUTTON_NODE_NAME "popup_button_"
34
#define POPUP_WINDOW_NAME "popup"
35
37
char
popupText
[
UI_MAX_SMALLTEXTLEN
];
38
static
char
popupAction1
[
UI_MAX_SMALLTEXTLEN
];
39
static
char
popupAction2
[
UI_MAX_SMALLTEXTLEN
];
40
static
char
popupAction3
[
UI_MAX_SMALLTEXTLEN
];
41
47
void
UI_Popup
(
const
char
* title,
const
char
* text)
48
{
49
Cvar_Set
(
"ui_sys_popup_title"
,
"%s"
, title);
50
UI_RegisterText
(
TEXT_POPUP_INFO
, text);
51
if
(!
UI_IsWindowOnStack
(
POPUP_WINDOW_NAME
))
52
UI_PushWindow
(
POPUP_WINDOW_NAME
);
53
}
54
62
uiNode_t
*
UI_PopupList
(
const
char
* title,
const
char
* headline,
linkedList_t
* entries,
const
char
* clickAction)
63
{
64
uiNode_t
* window;
65
uiNode_t
* listNode;
66
67
Cvar_Set
(
"ui_sys_popup_title"
,
"%s"
, title);
68
UI_RegisterText
(
TEXT_POPUP_INFO
, headline);
69
70
/* make sure, that we are using the linked list */
71
UI_ResetData
(
TEXT_LIST
);
72
UI_RegisterLinkedListText
(
TEXT_LIST
, entries);
73
74
window =
UI_GetWindow
(
POPUPLIST_WINDOW_NAME
);
75
if
(!window)
76
Com_Error
(
ERR_FATAL
,
"Could not get "
POPUPLIST_WINDOW_NAME
" window"
);
77
listNode =
UI_GetNode
(window,
POPUPLIST_NODE_NAME
);
78
if
(!listNode)
79
Com_Error
(
ERR_FATAL
,
"Could not get "
POPUPLIST_NODE_NAME
" node in "
POPUPLIST_WINDOW_NAME
" window"
);
80
81
/* free previous actions */
82
if
(listNode->
onClick
) {
83
assert(listNode->
onClick
->d.terminal.d1.data);
84
Mem_Free
(listNode->
onClick
->d.terminal.d1.data);
85
Mem_Free
(listNode->
onClick
);
86
listNode->
onClick
=
nullptr
;
87
}
88
89
if
(clickAction) {
90
UI_PoolAllocAction
(&listNode->
onClick
,
EA_CMD
, clickAction);
91
}
else
{
92
listNode->
onClick
=
nullptr
;
93
}
94
95
if
(!
UI_IsWindowOnStack
(window->
name
))
96
UI_PushWindow
(window->
name
);
97
return
listNode;
98
}
99
107
static
void
UI_SetOneButton
(
uiNode_t
* window,
const
char
* button,
const
char
* clickAction)
108
{
109
uiNode_t
* buttonNode;
110
111
buttonNode =
UI_GetNode
(window, button);
112
if
(!buttonNode)
113
Com_Error
(
ERR_FATAL
,
"Could not get %s node in %s window"
, button, window->
name
);
114
115
/* free previous actions */
116
if
(buttonNode->
onClick
) {
117
assert(buttonNode->
onClick
->d.terminal.d1.data);
118
Mem_Free
(buttonNode->
onClick
->d.terminal.d1.data);
119
Mem_Free
(buttonNode->
onClick
);
120
buttonNode->
onClick
=
nullptr
;
121
}
122
123
if
(clickAction) {
124
UI_PoolAllocAction
(&buttonNode->
onClick
,
EA_CMD
, clickAction);
125
buttonNode->
invis
=
false
;
126
}
else
{
127
buttonNode->
onClick
=
nullptr
;
128
buttonNode->
invis
=
true
;
129
}
130
}
131
147
void
UI_PopupButton
(
const
char
* title,
const
char
* text,
148
const
char
* clickAction1,
const
char
* clickText1,
const
char
* tooltip1,
149
const
char
* clickAction2,
const
char
* clickText2,
const
char
* tooltip2,
150
const
char
* clickAction3,
const
char
* clickText3,
const
char
* tooltip3)
151
{
152
uiNode_t
* window;
153
154
Cvar_Set
(
"ui_sys_popup_title"
,
"%s"
, title);
155
if
(text)
156
UI_RegisterText
(
TEXT_POPUP_INFO
, text);
157
else
158
UI_RegisterText
(
TEXT_POPUP_INFO
,
popupText
);
159
160
window =
UI_GetWindow
(
POPUPBUTTON_WINDOW_NAME
);
161
if
(!window)
162
Com_Error
(
ERR_FATAL
,
"Could not get \""
POPUPBUTTON_WINDOW_NAME
"\" window"
);
163
164
Cvar_Set
(
"ui_sys_popup_button_text1"
,
"%s"
, clickText1);
165
Cvar_Set
(
"ui_sys_popup_button_tooltip1"
,
"%s"
, tooltip1);
166
if
(!clickAction1 && !clickText1) {
167
UI_SetOneButton
(window,
va
(
"%s1"
,
POPUPBUTTON_NODE_NAME
),
168
nullptr
);
169
}
else
{
170
UI_SetOneButton
(window,
va
(
"%s1"
,
POPUPBUTTON_NODE_NAME
),
171
clickAction1 ? clickAction1 :
popupAction1
);
172
}
173
174
Cvar_Set
(
"ui_sys_popup_button_text2"
,
"%s"
, clickText2);
175
Cvar_Set
(
"ui_sys_popup_button_tooltip2"
,
"%s"
, tooltip2);
176
if
(!clickAction2 && !clickText2) {
177
UI_SetOneButton
(window,
va
(
"%s2"
,
POPUPBUTTON_NODE_NAME
),
nullptr
);
178
}
else
{
179
UI_SetOneButton
(window,
va
(
"%s2"
,
POPUPBUTTON_NODE_NAME
),
180
clickAction2 ? clickAction2 :
popupAction2
);
181
}
182
183
Cvar_Set
(
"ui_sys_popup_button_text3"
,
"%s"
, clickText3);
184
Cvar_Set
(
"ui_sys_popup_button_tooltip3"
,
"%s"
, tooltip3);
185
if
(!clickAction3 && !clickText3) {
186
UI_SetOneButton
(window,
va
(
"%s3"
,
POPUPBUTTON_NODE_NAME
),
nullptr
);
187
}
else
{
188
UI_SetOneButton
(window,
va
(
"%s3"
,
POPUPBUTTON_NODE_NAME
),
189
clickAction3 ? clickAction3 :
popupAction3
);
190
}
191
192
if
(!
UI_IsWindowOnStack
(window->
name
))
193
UI_PushWindow
(window->
name
);
194
}
Com_Error
void Com_Error(int code, const char *fmt,...)
Definition
common.cpp:459
ERR_FATAL
#define ERR_FATAL
Definition
common.h:210
Cvar_Set
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition
cvar.cpp:615
Mem_Free
#define Mem_Free(ptr)
Definition
mem.h:35
va
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...
Definition
shared.cpp:410
linkedList_t
Definition
list.h:30
uiNode_t
Atomic structure used to define most of the UI.
Definition
ui_nodes.h:80
uiNode_t::invis
bool invis
Definition
ui_nodes.h:101
uiNode_t::name
char name[MAX_VAR]
Definition
ui_nodes.h:82
uiNode_t::onClick
struct uiAction_s * onClick
Definition
ui_nodes.h:135
UI_PoolAllocAction
void UI_PoolAllocAction(uiAction_t **action, int type, const void *data)
Set a new action to a uiAction_t pointer.
Definition
ui_actions.cpp:814
ui_actions.h
EA_CMD
@ EA_CMD
Definition
ui_actions.h:44
UI_ResetData
void UI_ResetData(int dataId)
Reset a shared data. Type became NONE and value became nullptr.
Definition
ui_data.cpp:212
UI_RegisterText
void UI_RegisterText(int dataId, const char *text)
share a text with a data id
Definition
ui_data.cpp:115
UI_RegisterLinkedListText
void UI_RegisterLinkedListText(int dataId, linkedList_t *text)
share a linked list of text with a data id
Definition
ui_data.cpp:131
TEXT_LIST
@ TEXT_LIST
Definition
ui_dataids.h:31
TEXT_POPUP_INFO
@ TEXT_POPUP_INFO
Definition
ui_dataids.h:39
ui_main.h
UI_GetNode
uiNode_t * UI_GetNode(const uiNode_t *node, const char *name)
Search a child node by given name.
Definition
ui_node.cpp:714
ui_node.h
C interface to allow to access to cpp node code.
ui_node_abstractnode.h
ui_nodes.h
UI_SetOneButton
static void UI_SetOneButton(uiNode_t *window, const char *button, const char *clickAction)
Set string and action button.
Definition
ui_popup.cpp:107
UI_Popup
void UI_Popup(const char *title, const char *text)
Popup on geoscape.
Definition
ui_popup.cpp:47
UI_PopupList
uiNode_t * UI_PopupList(const char *title, const char *headline, linkedList_t *entries, const char *clickAction)
Generates a popup that contains a list of selectable choices.
Definition
ui_popup.cpp:62
POPUPBUTTON_WINDOW_NAME
#define POPUPBUTTON_WINDOW_NAME
Definition
ui_popup.cpp:32
POPUPBUTTON_NODE_NAME
#define POPUPBUTTON_NODE_NAME
Definition
ui_popup.cpp:33
popupAction3
static char popupAction3[UI_MAX_SMALLTEXTLEN]
Definition
ui_popup.cpp:40
UI_PopupButton
void UI_PopupButton(const char *title, const char *text, const char *clickAction1, const char *clickText1, const char *tooltip1, const char *clickAction2, const char *clickText2, const char *tooltip2, const char *clickAction3, const char *clickText3, const char *tooltip3)
Generates a popup that contains up to 3 buttons.
Definition
ui_popup.cpp:147
popupText
char popupText[UI_MAX_SMALLTEXTLEN]
strings to be used for popup when text is not static
Definition
ui_popup.cpp:37
popupAction2
static char popupAction2[UI_MAX_SMALLTEXTLEN]
Definition
ui_popup.cpp:39
popupAction1
static char popupAction1[UI_MAX_SMALLTEXTLEN]
Definition
ui_popup.cpp:38
POPUP_WINDOW_NAME
#define POPUP_WINDOW_NAME
Definition
ui_popup.cpp:34
ui_popup.h
POPUPLIST_WINDOW_NAME
#define POPUPLIST_WINDOW_NAME
Definition
ui_popup.h:29
UI_MAX_SMALLTEXTLEN
#define UI_MAX_SMALLTEXTLEN
Definition
ui_popup.h:34
POPUPLIST_NODE_NAME
#define POPUPLIST_NODE_NAME
Definition
ui_popup.h:30
UI_GetWindow
uiNode_t * UI_GetWindow(const char *name)
Searches all windows for the specified one.
Definition
ui_windows.cpp:567
UI_IsWindowOnStack
bool UI_IsWindowOnStack(const char *name)
Check if a named window is on the stack if active windows.
Definition
ui_windows.cpp:373
UI_PushWindow
uiNode_t * UI_PushWindow(const char *name, const char *parentName, linkedList_t *params)
Push a window onto the window stack.
Definition
ui_windows.cpp:170
src
client
ui
ui_popup.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0