UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_messageoptions_callbacks.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, 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
35static int messageList_size = 0;
36static int messageList_scroll = 0;
37static int visibleMSOEntries = 0;
39
44static 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
76static 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
134
139static 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
153static 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
206static 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
220static void MSO_BackupSettings_f (void)
221{
223}
224
230static void MSO_RestoreSettings_f (void)
231{
234}
235
236void MSO_SetMenuState (const msoMenuState_t newState, const bool callInit, const bool preserveIndex)
237{
238 msoMenuState = newState;
239 if (newState == MSO_MSTATE_REINIT && !preserveIndex) {
242 }
243 if (callInit)
244 MSOCB_Init();
245}
246
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};
256{
258
259 cgi->Cmd_TableAddList(msgOptionsCallbacks);
260}
261
263{
264 cgi->Cmd_TableRemoveList(msgOptionsCallbacks);
265
266 cgi->UI_ResetData(TEXT_MESSAGEOPTIONS);
267}
Share stuff between the different cgame implementations.
ccs_t ccs
Header file for single player campaign control.
const cgame_import_t * cgi
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.
messageSettings_t messageSettings[NT_NUM_NOTIFYTYPE]
char const *const nt_strings[NT_NUM_NOTIFYTYPE]
valid notification types that may cause pause / notice
Header file for messageoptions related stuff.
notify_t
Notify types.
@ NT_NUM_NOTIFYTYPE
#define MSO_PAUSE
notification type: pause game
#define MSO_NOTIFY
notification type: add notification message
#define MSO_SOUND
notification type: play notification sound
static const cmdList_t msgOptionsCallbacks[]
static msoMenuState_t msoMenuState
static int visibleMSOEntries
void MSO_InitCallbacks(void)
void MSO_ShutdownCallbacks(void)
void MSO_SetMenuState(const msoMenuState_t newState, const bool callInit, const bool preserveIndex)
static void MSO_Init_f(void)
initializes message options menu by showing as much button lines as needed.
messageSettings_t backupMessageSettings[NT_NUM_NOTIFYTYPE]
static int messageList_scroll
static void MSO_Toggle_f(void)
Function for menu buttons to update message settings.
static void MSO_BackupSettings_f(void)
Saves actual settings into backup settings variable.
static void MSO_UpdateVisibleButtons(void)
Executes confuncs to update visible message options lines.
static void MSO_Scroll_f(void)
Function to update message options menu after scrolling. Updates all visible button lines based on co...
static void MSOCB_Init(void)
initializes message options menu by showing as much button lines as needed.
static void MSO_InitList(void)
Initializes menu texts for scrollable area.
static int messageList_size
static void MSO_RestoreSettings_f(void)
Restores actual settings from backup settings variable.
Header file for menu related console command callbacks.
void Sys_Error(const char *error,...)
Definition g_main.cpp:421
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
#define Q_streq(a, b)
Definition shared.h:136
#define OBJSET(obj, val)
Definition shared.h:177
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
structure holding pause and notify settings for a notify type.
const char * notifyType
bool isCategory
struct msgCategory_s * category
messageSettings_t * settings
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiNode_t * firstChild
Definition ui_nodes.h:89
uiNode_t * option
Definition ui_data.h:60
Data and interface to share data.
@ TEXT_MESSAGEOPTIONS
Definition ui_dataids.h:61
#define OPTIONEXTRADATA(node)
#define OPTIONEXTRADATACONST(node)