UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_popup.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 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"
31 
32 #define POPUPBUTTON_WINDOW_NAME "popup_button"
33 #define POPUPBUTTON_NODE_NAME "popup_button_"
34 #define POPUP_WINDOW_NAME "popup"
35 
41 
47 void UI_Popup (const char* title, const char* text)
48 {
49  Cvar_Set("ui_sys_popup_title", "%s", title);
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);
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 
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)
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) {
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 }
#define POPUPBUTTON_NODE_NAME
Definition: ui_popup.cpp:33
struct uiAction_s::@14::@16 terminal
Stores a terminal action (a value, which must be a leaf in the tree)
static char popupAction1[UI_MAX_SMALLTEXTLEN]
Definition: ui_popup.cpp:38
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
char popupText[UI_MAX_SMALLTEXTLEN]
strings to be used for popup when text is not static
Definition: ui_popup.cpp:37
void UI_RegisterLinkedListText(int dataId, linkedList_t *text)
share a linked list of text with a data id
Definition: ui_data.cpp:131
void UI_RegisterText(int dataId, const char *text)
share a text with a data id
Definition: ui_data.cpp:115
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
#define POPUP_WINDOW_NAME
Definition: ui_popup.cpp:34
#define POPUPLIST_NODE_NAME
Definition: ui_popup.h:30
char name[MAX_VAR]
Definition: ui_nodes.h:82
#define POPUPBUTTON_WINDOW_NAME
Definition: ui_popup.cpp:32
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
union uiAction_s::@14 d
Stores data about the action.
struct uiAction_s * onClick
Definition: ui_nodes.h:135
#define ERR_FATAL
Definition: common.h:210
#define UI_MAX_SMALLTEXTLEN
Definition: ui_popup.h:34
C interface to allow to access to cpp node code.
void Com_Error(int code, const char *fmt,...)
Definition: common.cpp:417
bool invis
Definition: ui_nodes.h:101
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
void UI_ResetData(int dataId)
Reset a shared data. Type became NONE and value became nullptr.
Definition: ui_data.cpp:212
bool UI_IsWindowOnStack(const char *name)
Check if a named window is on the stack if active windows.
Definition: ui_windows.cpp:373
#define POPUPLIST_WINDOW_NAME
Definition: ui_popup.h:29
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
static char popupAction3[UI_MAX_SMALLTEXTLEN]
Definition: ui_popup.cpp:40
uiNode_t * UI_GetWindow(const char *name)
Searches all windows for the specified one.
Definition: ui_windows.cpp:567
static void UI_SetOneButton(uiNode_t *window, const char *button, const char *clickAction)
Set string and action button.
Definition: ui_popup.cpp:107
uiNode_t * UI_GetNode(const uiNode_t *node, const char *name)
Search a child node by given name.
Definition: ui_node.cpp:702
#define Mem_Free(ptr)
Definition: mem.h:35
static char popupAction2[UI_MAX_SMALLTEXTLEN]
Definition: ui_popup.cpp:39
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition: cvar.cpp:615
void UI_Popup(const char *title, const char *text)
Popup on geoscape.
Definition: ui_popup.cpp:47
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