UFO: Alien Invasion
Doxygen documentation generating
cp_messageoptions_callbacks.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2023 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 */
25 
26 #include "../../cl_shared.h"
27 /* UI_InitOptionIteratorAtIndex */
28 #include "../../ui/ui_main.h"
29 #include "../../ui/ui_data.h"
30 #include "cp_campaign.h"
31 #include "cp_messageoptions.h"
33 
35 static int messageList_size = 0;
36 static int messageList_scroll = 0;
37 static int visibleMSOEntries = 0;
44 static void MSO_InitList (void)
45 {
46  uiNode_t* messageSetting = nullptr;
47  uiNode_t* lastCategory = nullptr;
48  int idx;
49 
50  /* option already allocated, nothing to do */
51  if (cgi->UI_GetOption(TEXT_MESSAGEOPTIONS) != nullptr)
52  return;
53 
54  cgi->UI_ResetData(TEXT_MESSAGEOPTIONS);
55  for (idx = 0; idx < ccs.numMsgCategoryEntries; idx++) {
56  const msgCategoryEntry_t* entry = &ccs.msgCategoryEntries[idx];
57  const char* id = va("%d", idx);
58 
59  if (entry->isCategory) {
60  lastCategory = cgi->UI_AddOption(&messageSetting, id, va("_%s", entry->notifyType), id);
61  } else {
62  if (!lastCategory)
63  Sys_Error("MSO_InitList: The first entry must be a category");
64  cgi->UI_AddOption(&lastCategory->firstChild, id, va("_%s", entry->notifyType), id);
65  }
66  }
67  cgi->UI_RegisterOption(TEXT_MESSAGEOPTIONS, messageSetting);
69 }
70 
76 static void MSO_UpdateVisibleButtons (void)
77 {
78  int visible;/* current line */
79  uiOptionIterator_t iterator;
80  uiNode_t* messageSetting = cgi->UI_GetOption(TEXT_MESSAGEOPTIONS);
81 
82  cgi->UI_InitOptionIteratorAtIndex(messageList_scroll, messageSetting, &iterator);
83 
84  /* update visible button lines based on current displayed values */
85  for (visible = 0; visible < messageList_size; visible++) {
86  const uiNode_t* option = iterator.option;
87  int idx;
88  msgCategoryEntry_t* entry;
89 
90  if (!option)
91  break;
92  idx = atoi(OPTIONEXTRADATACONST(option).value);
93 
94  entry = &ccs.msgCategoryEntries[idx];
95  if (!entry)
96  break;
97  if (entry->isCategory) {
98  /* category is visible anyway*/
99  cgi->UI_ExecuteConfunc("ms_disable %i", visible);
100 
101  } else {
102  assert(entry->category);
103  cgi->UI_ExecuteConfunc("ms_enable %i", visible);
104  cgi->UI_ExecuteConfunc("ms_btnstate %i %i %i %i", visible, entry->settings->doPause,
105  entry->settings->doNotify, entry->settings->doSound);
106  }
107 
108  cgi->UI_OptionIteratorNextOption(&iterator);
109  }
110 
111  for (; visible < messageList_size; visible++)
112  cgi->UI_ExecuteConfunc("ms_disable %i", visible);
113 }
114 
122 static void MSOCB_Init (void)
123 {
125  MSO_InitList();
127  }
128 
132  }
133 }
134 
139 static void MSO_Init_f (void)
140 {
141  if (cgi->Cmd_Argc() == 2) {
142  messageList_size = atoi(cgi->Cmd_Argv(1));
143  }
144 
145  MSOCB_Init();
146 }
147 
153 static void MSO_Toggle_f (void)
154 {
155  if (cgi->Cmd_Argc() != 3)
156  cgi->Com_Printf("Usage: %s <listId> <pause|notify|sound>\n", cgi->Cmd_Argv(0));
157  else {
158  uiOptionIterator_t iterator;
159  const int listIndex = atoi(cgi->Cmd_Argv(1));
160  int idx;
161  const msgCategoryEntry_t* selectedEntry;
162  int optionType;
163  bool activate;
164  int type;
165  uiNode_t* messageSetting = cgi->UI_GetOption(TEXT_MESSAGEOPTIONS);
166 
167  cgi->UI_InitOptionIteratorAtIndex(messageList_scroll + listIndex, messageSetting, &iterator);
168  if (!iterator.option)
169  return;
170 
171  idx = atoi(OPTIONEXTRADATA(iterator.option).value);
172  selectedEntry = &ccs.msgCategoryEntries[idx];
173  if (!selectedEntry)
174  return;
175  if (selectedEntry->isCategory) {
176  cgi->Com_Printf("Toggle command with selected category entry ignored.\n");
177  return;
178  }
179  for (type = 0; type < NT_NUM_NOTIFYTYPE; type++) {
180  if (Q_streq(nt_strings[type], selectedEntry->notifyType))
181  break;
182  }
183  if (type == NT_NUM_NOTIFYTYPE) {
184  cgi->Com_Printf("Unrecognized messagetype during toggle '%s' ignored\n", selectedEntry->notifyType);
185  return;
186  }
187 
188  if (Q_streq(cgi->Cmd_Argv(2), "pause")) {
189  optionType = MSO_PAUSE;
190  activate = !selectedEntry->settings->doPause;
191  } else if (Q_streq(cgi->Cmd_Argv(2), "notify")) {
192  optionType = MSO_NOTIFY;
193  activate = !selectedEntry->settings->doNotify;
194  } else {
195  optionType = MSO_SOUND;
196  activate = !selectedEntry->settings->doSound;
197  }
198  MSO_Set(listIndex, (notify_t)type, optionType, activate, true);
199  }
200 }
201 
206 static void MSO_Scroll_f (void)
207 {
208  if (cgi->Cmd_Argc() < 2)
209  return;
210 
211  /* no scrolling if visible entry count is less than max on page (due to folding) */
212  messageList_scroll = atoi(cgi->Cmd_Argv(1));
213 
215 }
216 
220 static void MSO_BackupSettings_f (void)
221 {
223 }
224 
230 static void MSO_RestoreSettings_f (void)
231 {
233  MSO_SetMenuState(MSO_MSTATE_REINIT, false, true);
234 }
235 
236 void MSO_SetMenuState (const msoMenuState_t newState, const bool callInit, const bool preserveIndex)
237 {
238  msoMenuState = newState;
239  if (newState == MSO_MSTATE_REINIT && !preserveIndex) {
240  visibleMSOEntries = 0;
241  messageList_scroll = 0;
242  }
243  if (callInit)
244  MSOCB_Init();
245 }
246 
247 static const cmdList_t msgOptionsCallbacks[] = {
248  {"msgoptions_toggle", MSO_Toggle_f, "Toggles pause, notification or sound setting for a message category"},
249  {"msgoptions_scroll", MSO_Scroll_f, "Scroll callback function for message options menu text"},
250  {"msgoptions_init", MSO_Init_f, "Initializes message options menu"},
251  {"msgoptions_backup", MSO_BackupSettings_f, "Backup message settings"},
252  {"msgoptions_restore",MSO_RestoreSettings_f, "Restore message settings from backup"},
253  {nullptr, nullptr, nullptr}
254 };
255 void MSO_InitCallbacks (void)
256 {
258 
259  cgi->Cmd_TableAddList(msgOptionsCallbacks);
260 }
261 
263 {
264  cgi->Cmd_TableRemoveList(msgOptionsCallbacks);
265 
266  cgi->UI_ResetData(TEXT_MESSAGEOPTIONS);
267 }
struct msgCategory_s * category
uiNode_t *IMPORT * UI_OptionIteratorNextOption(uiOptionIterator_t *iterator)
void Sys_Error(const char *error,...)
Definition: g_main.cpp:421
static int messageList_scroll
static void MSOCB_Init(void)
initializes message options menu by showing as much button lines as needed.
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don&#39;t need to have varargs versions of all text functi...
Definition: shared.cpp:410
static void MSO_UpdateVisibleButtons(void)
Executes confuncs to update visible message options lines.
static msoMenuState_t msoMenuState
#define OBJSET(obj, val)
Definition: shared.h:177
#define MSO_SOUND
notification type: play notification sound
char const *const nt_strings[NT_NUM_NOTIFYTYPE]
valid notification types that may cause pause / notice
void MSO_InitCallbacks(void)
const char *IMPORT * Cmd_Argv(int n)
void MSO_SetMenuState(const msoMenuState_t newState, const bool callInit, const bool preserveIndex)
Header file for messageoptions related stuff.
#define MSO_PAUSE
notification type: pause game
static void MSO_Scroll_f(void)
Function to update message options menu after scrolling. Updates all visible button lines based on co...
#define OPTIONEXTRADATACONST(node)
static const cmdList_t msgOptionsCallbacks[]
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
#define OPTIONEXTRADATA(node)
messageSettings_t messageSettings[NT_NUM_NOTIFYTYPE]
int numMsgCategoryEntries
Definition: cp_campaign.h:364
const cgame_import_t * cgi
const char uiNode_t *IMPORT * UI_AddOption(uiNode_t **tree, const char *name, const char *label, const char *value)
uiNode_t *IMPORT * UI_InitOptionIteratorAtIndex(int index, uiNode_t *option, uiOptionIterator_t *iterator)
ccs_t ccs
Definition: cp_campaign.cpp:63
messageSettings_t * settings
msgCategoryEntry_t msgCategoryEntries[NT_NUM_NOTIFYTYPE+MAX_MESSAGECATEGORIES]
Definition: cp_campaign.h:363
static void MSO_Init_f(void)
initializes message options menu by showing as much button lines as needed.
static void MSO_Toggle_f(void)
Function for menu buttons to update message settings.
static int visibleMSOEntries
uiNode_t * firstChild
Definition: ui_nodes.h:89
uiNode_t *IMPORT * UI_GetOption(int dataId)
static void MSO_InitList(void)
Initializes menu texts for scrollable area.
static int messageList_size
void MSO_Set(const int listIndex, const notify_t type, const int optionType, const bool activate, const bool sendCommands)
Function updates pause or notification settings.
Header file for single player campaign control.
structure holding pause and notify settings for a notify type.
const char * notifyType
#define Q_streq(a, b)
Definition: shared.h:136
static void MSO_RestoreSettings_f(void)
Restores actual settings from backup settings variable.
uiNode_t * option
Definition: ui_data.h:60
void MSO_ShutdownCallbacks(void)
messageSettings_t backupMessageSettings[NT_NUM_NOTIFYTYPE]
#define MSO_NOTIFY
notification type: add notification message
Header file for menu related console command callbacks.
notify_t
Notify types.
Definition: cmd.h:86
static void MSO_BackupSettings_f(void)
Saves actual settings into backup settings variable.