00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "../cl_shared.h"
00026 #include "../ui/ui_main.h"
00027 #include "../../shared/parse.h"
00028 #include "cp_campaign.h"
00029 #include "cp_messageoptions.h"
00030 #include "cp_messageoptions_callbacks.h"
00031 #include "cp_time.h"
00032 #include "save/save_messageoptions.h"
00033
00035 const char *nt_strings[NT_NUM_NOTIFYTYPE] = {
00036 N_("installation_installed"),
00037 N_("installation_removed"),
00038 N_("installation_replaced"),
00039 N_("aircraft_refueled"),
00040 N_("aircraft_cannotrefuel"),
00041 N_("installation_build_started"),
00042 N_("installation_build_finished"),
00043 N_("installation_destroyed"),
00044 N_("research_new_proposed"),
00045 N_("research_halted"),
00046 N_("research_completed"),
00047 N_("production_started"),
00048 N_("production_finished"),
00049 N_("production_failed"),
00050 N_("production_queue_empty"),
00051 N_("nation_happiness_changed"),
00052 N_("nation_unhappy"),
00053 N_("nation_pleased"),
00054 N_("transfer_started"),
00055 N_("transfer_completed_success"),
00056 N_("transfer_lost"),
00057 N_("transfer_aliens_defered"),
00058 N_("transfer_uforecovery_finished"),
00059 N_("ufo_spotted"),
00060 N_("ufo_signal_lost"),
00061 N_("ufo_attacking"),
00062
00063 };
00064 CASSERT(lengthof(nt_strings) == NT_NUM_NOTIFYTYPE);
00065
00066 messageSettings_t messageSettings[NT_NUM_NOTIFYTYPE];
00079 void MSO_Set (const int listIndex, const notify_t type, const int optionType, const qboolean activate, const qboolean sendCommands)
00080 {
00081 messageSettings_t *settings = &messageSettings[type];
00082
00083 if (activate) {
00084 if ((optionType & NTMASK_PAUSE) == NTMASK_PAUSE)
00085 settings->doPause = activate;
00086 if ((optionType & NTMASK_SOUND)== NTMASK_SOUND)
00087 settings->doSound = activate;
00088
00089 settings->doNotify = activate;
00090 } else {
00091 if ((optionType & NTMASK_PAUSE) == NTMASK_PAUSE)
00092 settings->doPause = activate;
00093 if ((optionType & NTMASK_SOUND)== NTMASK_SOUND)
00094 settings->doSound = activate;
00095
00096 if (optionType == MSO_NOTIFY) {
00097 settings->doNotify = activate;
00098 settings->doPause = activate;
00099 settings->doSound = activate;
00100 }
00101 }
00102
00103 if (sendCommands)
00104 UI_ExecuteConfunc("ms_btnstate %i %i %i %i", listIndex, settings->doPause, settings->doNotify, settings->doSound);
00105 else
00106
00107 MSO_SetMenuState(MSO_MSTATE_PREPARED,qfalse, qfalse);
00108 }
00109
00114 static void MSO_Set_f (void)
00115 {
00116 if (Cmd_Argc() != 4)
00117 Com_Printf("Usage: %s <messagetypename> <pause|notify|sound> <0|1>\n", Cmd_Argv(0));
00118 else {
00119 notify_t type;
00120 int optionsType;
00121 const char *messagetype = Cmd_Argv(1);
00122
00123 for (type = 0; type < NT_NUM_NOTIFYTYPE; type++) {
00124 if (!strcmp(nt_strings[type], messagetype))
00125 break;
00126 }
00127 if (type == NT_NUM_NOTIFYTYPE) {
00128 Com_Printf("Unrecognized messagetype during set '%s' ignored\n", messagetype);
00129 return;
00130 }
00131
00132 if (!strcmp(Cmd_Argv(2), "pause"))
00133 optionsType = MSO_PAUSE;
00134 else if (!strcmp(Cmd_Argv(2), "notify"))
00135 optionsType = MSO_NOTIFY;
00136 else if (!strcmp(Cmd_Argv(2), "sound"))
00137 optionsType = MSO_SOUND;
00138 else {
00139 Com_Printf("Unrecognized optionstype during set '%s' ignored\n", Cmd_Argv(2));
00140 return;
00141 }
00142 MSO_Set(0, type, optionsType, atoi(Cmd_Argv(3)), qfalse);
00143 }
00144 }
00145
00151 static void MSO_SetAll_f(void)
00152 {
00153 if (Cmd_Argc() != 3)
00154 Com_Printf("Usage: %s <pause|notify|sound> <0|1>\n", Cmd_Argv(0));
00155 else {
00156 int optionsType;
00157 notify_t type;
00158 qboolean activate = atoi(Cmd_Argv(2));
00159 if (!strcmp(Cmd_Argv(1), "pause"))
00160 optionsType = MSO_PAUSE;
00161 else if (!strcmp(Cmd_Argv(1), "notify"))
00162 optionsType = MSO_NOTIFY;
00163 else if (!strcmp(Cmd_Argv(1), "sound"))
00164 optionsType = MSO_SOUND;
00165 else {
00166 Com_Printf("Unrecognized optionstype during set '%s' ignored\n", Cmd_Argv(2));
00167 return;
00168 }
00169
00170 for (type = 0; type < NT_NUM_NOTIFYTYPE; type ++) {
00171 MSO_Set(0, type, optionsType, activate, qfalse);
00172 }
00173
00174 MSO_SetMenuState(MSO_MSTATE_PREPARED,qtrue,qtrue);
00175 }
00176 }
00177
00190 message_t *MSO_CheckAddNewMessage (const notify_t messagecategory, const char *title, const char *text, qboolean popup, messageType_t type, void *pedia)
00191 {
00192 message_t *result = NULL;
00193
00194 if (messageSettings[messagecategory].doNotify)
00195 result = MS_AddNewMessageSound(title, text, popup, type, pedia, messageSettings[messagecategory].doSound);
00196 if (messageSettings[messagecategory].doPause)
00197 CL_GameTimeStop();
00198 return result;
00199 }
00200
00205 qboolean MSO_SaveXML (mxml_node_t *p)
00206 {
00207 notify_t type;
00208 mxml_node_t *n = mxml_AddNode(p, SAVE_MESSAGEOPTIONS_MESSAGEOPTIONS);
00209
00210
00211 for (type = 0; type < NT_NUM_NOTIFYTYPE; type++) {
00212 messageSettings_t actualSetting = messageSettings[type];
00213 mxml_node_t *s = mxml_AddNode(n, SAVE_MESSAGEOPTIONS_TYPE);
00214
00215 mxml_AddString(s, SAVE_MESSAGEOPTIONS_NAME, nt_strings[type]);
00216 mxml_AddBoolValue(s, SAVE_MESSAGEOPTIONS_NOTIFY, actualSetting.doNotify);
00217 mxml_AddBoolValue(s, SAVE_MESSAGEOPTIONS_PAUSE, actualSetting.doPause);
00218 mxml_AddBoolValue(s, SAVE_MESSAGEOPTIONS_SOUND, actualSetting.doSound);
00219 }
00220
00221 return qtrue;
00222 }
00223
00228 qboolean MSO_LoadXML (mxml_node_t *p)
00229 {
00230 mxml_node_t *n, *s;
00231
00232 memset(messageSettings, 1, sizeof(messageSettings));
00233
00234 n = mxml_GetNode(p, SAVE_MESSAGEOPTIONS_MESSAGEOPTIONS);
00235 if (!n)
00236 return qfalse;
00237
00238 for (s = mxml_GetNode(n, SAVE_MESSAGEOPTIONS_TYPE); s; s = mxml_GetNextNode(s,n, SAVE_MESSAGEOPTIONS_TYPE)) {
00239 const char *messagetype = mxml_GetString(s, SAVE_MESSAGEOPTIONS_NAME);
00240 notify_t type;
00241
00242 for (type = 0; type < NT_NUM_NOTIFYTYPE; type++) {
00243 if (strcmp(nt_strings[type], messagetype) == 0)
00244 break;
00245 }
00246
00248 if (type == NT_NUM_NOTIFYTYPE) {
00249 Com_Printf("Unrecognized messagetype '%s' ignored while loading\n", messagetype);
00250 continue;
00251 }
00252 MSO_Set(0, type, MSO_NOTIFY, mxml_GetBool(s, SAVE_MESSAGEOPTIONS_NOTIFY, qfalse), qfalse);
00253 MSO_Set(0, type, MSO_PAUSE, mxml_GetBool(s, SAVE_MESSAGEOPTIONS_PAUSE, qfalse), qfalse);
00254 MSO_Set(0, type, MSO_SOUND, mxml_GetBool(s, SAVE_MESSAGEOPTIONS_SOUND, qfalse), qfalse);
00255 }
00256
00257 MSO_SetMenuState(MSO_MSTATE_REINIT,qfalse, qfalse);
00258 return qtrue;
00259 }
00260
00266 void MSO_ParseSettings (const char *name, const char **text)
00267 {
00268 const char *errhead = "MSO_ParseSettings: unexpected end of file (names ";
00269 const char *token, *tmpCommand, *msgtype;
00270
00271
00272 token = Com_Parse(text);
00273
00274 if (!*text || *token !='{') {
00275 Com_Printf("MSO_ParseSettings: settingslist \"%s\" without body ignored\n", name);
00276 return;
00277 }
00278
00279 memset(messageSettings, 0, sizeof(messageSettings));
00280
00281 do {
00282
00283 msgtype = Com_EParse(text, errhead, name);
00284 if (text[0] == '\0')
00285 break;
00286 if (msgtype[0] == '}')
00287 break;
00288
00289 tmpCommand = va("%s", msgtype);
00290
00291 token = va("msgoptions_set %s %s 1", tmpCommand, Com_EParse(text, errhead, name));
00292 Cmd_ExecuteString(token);
00293 } while (*text);
00294
00295 MSO_SetMenuState(MSO_MSTATE_REINIT,qfalse,qfalse);
00296 }
00297
00304 void MSO_ParseCategories (const char *name, const char **text)
00305 {
00306 const char *errhead = "MSO_ParseCategories: unexpected end of file (names ";
00307 const char *token;
00308 int idx;
00309 msgCategory_t *category;
00310 msgCategoryEntry_t *entry;
00311
00312 name++;
00313
00314
00315 token = Com_Parse(text);
00316
00317 if (!*text || *token != '{') {
00318 Com_Printf("MSO_ParseCategories: category \"%s\" without body ignored\n", name);
00319 return;
00320 }
00321
00322
00323 if (ccs.numMsgCategories >= MAX_MESSAGECATEGORIES) {
00324 Com_Printf("MSO_ParseCategories: too many messagecategory defs\n");
00325 return;
00326 }
00327
00328 category = &ccs.messageCategories[ccs.numMsgCategories];
00329
00330 memset(category, 0, sizeof(*category));
00331 category->id = Mem_PoolStrDup(name, cp_campaignPool, 0);
00332 category->idx = ccs.numMsgCategories;
00333
00334 entry = &ccs.msgCategoryEntries[ccs.numMsgCategoryEntries];
00335
00336
00337 memset(entry, 0, sizeof(*entry));
00338 entry->category = &ccs.messageCategories[ccs.numMsgCategories];
00339 category->last = category->first = &ccs.msgCategoryEntries[ccs.numMsgCategoryEntries];
00340 entry->previous = NULL;
00341 entry->next = NULL;
00342 entry->isCategory = qtrue;
00343 entry->notifyType = category->id;
00344
00345 ccs.numMsgCategoryEntries++;
00346
00347 do {
00348
00349 token = Com_EParse(text, errhead, name);
00350 if (text[0] == '\0')
00351 break;
00352 if (token[0] == '}')
00353 break;
00354
00355 if (token[0] != '\0') {
00356 for (idx = 0; idx < NT_NUM_NOTIFYTYPE; idx ++) {
00357 if (!strncmp(token, nt_strings[idx],MAX_VAR)) {
00358
00359 msgCategoryEntry_t *old = ccs.messageCategories[ccs.numMsgCategories].last;
00360
00361 memset(&ccs.msgCategoryEntries[ccs.numMsgCategoryEntries], 0, sizeof(ccs.msgCategoryEntries[ccs.numMsgCategoryEntries]));
00362 ccs.msgCategoryEntries[ccs.numMsgCategoryEntries].category = &ccs.messageCategories[ccs.numMsgCategories];
00363
00364 ccs.messageCategories[ccs.numMsgCategories].last = &ccs.msgCategoryEntries[ccs.numMsgCategoryEntries];
00365 old->next = &ccs.msgCategoryEntries[ccs.numMsgCategoryEntries];
00366 ccs.msgCategoryEntries[ccs.numMsgCategoryEntries].previous = old;
00367 ccs.msgCategoryEntries[ccs.numMsgCategoryEntries].next = NULL;
00368 ccs.msgCategoryEntries[ccs.numMsgCategoryEntries].notifyType = nt_strings[idx];
00369 ccs.msgCategoryEntries[ccs.numMsgCategoryEntries].settings = &messageSettings[idx];
00370 ccs.numMsgCategoryEntries++;
00371 break;
00372 }
00373 }
00374 }
00375 } while (*text);
00376
00377 ccs.numMsgCategories++;
00378 MSO_SetMenuState(MSO_MSTATE_REINIT,qfalse,qfalse);
00379 }
00380
00381 void MSO_Init (void)
00382 {
00383 Cmd_AddCommand("msgoptions_setall", MSO_SetAll_f, "Sets pause, notification or sound setting for all message categories");
00384 Cmd_AddCommand("msgoptions_set", MSO_Set_f, "Sets pause, notification or sound setting for a message category");
00385 MSO_InitCallbacks();
00386 }
00387
00388 void MSO_Shutdown (void)
00389 {
00390 Cmd_RemoveCommand("msgoptions_setall");
00391 Cmd_RemoveCommand("msgoptions_set");
00392 MSO_ShutdownCallbacks();
00393 }