UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_popup.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_nodes.h"
27#include "ui_node.h"
28#include "ui_popup.h"
29#include "ui_actions.h"
31
32#define POPUPBUTTON_WINDOW_NAME "popup_button"
33#define POPUPBUTTON_NODE_NAME "popup_button_"
34#define POPUP_WINDOW_NAME "popup"
35
41
47void UI_Popup (const char* title, const char* text)
48{
49 Cvar_Set("ui_sys_popup_title", "%s", title);
53}
54
62uiNode_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);
69
70 /* make sure, that we are using the linked list */
73
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
107static 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
147void 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)
157 else
159
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) {
168 nullptr);
169 } else {
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 {
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 {
189 clickAction3 ? clickAction3 : popupAction3);
190 }
191
192 if (!UI_IsWindowOnStack(window->name))
193 UI_PushWindow(window->name);
194}
void Com_Error(int code, const char *fmt,...)
Definition common.cpp:459
#define ERR_FATAL
Definition common.h:210
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition cvar.cpp:615
#define Mem_Free(ptr)
Definition mem.h:35
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
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
bool invis
Definition ui_nodes.h:101
char name[MAX_VAR]
Definition ui_nodes.h:82
struct uiAction_s * onClick
Definition ui_nodes.h:135
void UI_PoolAllocAction(uiAction_t **action, int type, const void *data)
Set a new action to a uiAction_t pointer.
@ EA_CMD
Definition ui_actions.h:44
void UI_ResetData(int dataId)
Reset a shared data. Type became NONE and value became nullptr.
Definition ui_data.cpp:212
void UI_RegisterText(int dataId, const char *text)
share a text with a data id
Definition ui_data.cpp:115
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
Definition ui_dataids.h:31
@ TEXT_POPUP_INFO
Definition ui_dataids.h:39
uiNode_t * UI_GetNode(const uiNode_t *node, const char *name)
Search a child node by given name.
Definition ui_node.cpp:714
C interface to allow to access to cpp node code.
static void UI_SetOneButton(uiNode_t *window, const char *button, const char *clickAction)
Set string and action button.
Definition ui_popup.cpp:107
void UI_Popup(const char *title, const char *text)
Popup on geoscape.
Definition ui_popup.cpp:47
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
#define POPUPBUTTON_WINDOW_NAME
Definition ui_popup.cpp:32
#define POPUPBUTTON_NODE_NAME
Definition ui_popup.cpp:33
static char popupAction3[UI_MAX_SMALLTEXTLEN]
Definition ui_popup.cpp:40
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
char popupText[UI_MAX_SMALLTEXTLEN]
strings to be used for popup when text is not static
Definition ui_popup.cpp:37
static char popupAction2[UI_MAX_SMALLTEXTLEN]
Definition ui_popup.cpp:39
static char popupAction1[UI_MAX_SMALLTEXTLEN]
Definition ui_popup.cpp:38
#define POPUP_WINDOW_NAME
Definition ui_popup.cpp:34
#define POPUPLIST_WINDOW_NAME
Definition ui_popup.h:29
#define UI_MAX_SMALLTEXTLEN
Definition ui_popup.h:34
#define POPUPLIST_NODE_NAME
Definition ui_popup.h:30
uiNode_t * UI_GetWindow(const char *name)
Searches all windows for the specified one.
bool UI_IsWindowOnStack(const char *name)
Check if a named window is on the stack if active windows.
uiNode_t * UI_PushWindow(const char *name, const char *parentName, linkedList_t *params)
Push a window onto the window stack.