00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "../cl_shared.h"
00025 #include "../sound/s_sample.h"
00026 #include "../sound/s_main.h"
00027 #include "../ui/ui_main.h"
00028 #include "../ui/ui_popup.h"
00029 #include "cp_campaign.h"
00030 #include "cp_popup.h"
00031 #include "cp_messages.h"
00032 #include "cp_time.h"
00033 #include "save/save_messages.h"
00034
00035 char cp_messageBuffer[MAX_MESSAGE_TEXT];
00036 message_t *cp_messageStack;
00037
00044 static void MS_TimestampedText (char *text, message_t *message, size_t textsize)
00045 {
00046 dateLong_t date;
00047 CL_DateConvertLong(&message->date, &date);
00048 Com_sprintf(text, textsize, _("%i %s %02i, %02i:%02i: "), date.year,
00049 Date_GetMonthName(date.month - 1), date.day, date.hour, date.min);
00050 }
00051
00065 message_t *MS_AddNewMessage (const char *title, const char *text, qboolean popup, messageType_t type, technology_t *pedia)
00066 {
00067 return MS_AddNewMessageSound(title, text, popup, type, pedia, qtrue);
00068 }
00069
00083 message_t *MS_AddNewMessageSound (const char *title, const char *text, qboolean popup, messageType_t type, technology_t *pedia, qboolean playSound)
00084 {
00085 message_t *mess;
00086 const char *sound = NULL;
00087
00088 assert(type < MSG_MAX);
00089
00090
00091 mess = (message_t *) Mem_PoolAlloc(sizeof(*mess), cp_campaignPool, 0);
00092
00093
00094 mess->next = cp_messageStack;
00095 cp_messageStack = mess;
00096
00097 mess->type = type;
00098 mess->pedia = pedia;
00099
00100 mess->date = ccs.date;
00101
00103 Q_strncpyz(mess->title, title, sizeof(mess->title));
00104 mess->text = Mem_PoolStrDup(text, cp_campaignPool, 0);
00105
00106
00107 MS_TimestampedText(mess->timestamp, mess, sizeof(mess->timestamp));
00108
00109
00110 if (popup)
00111 CP_PopupList(mess->title, mess->text);
00112
00113 switch (type) {
00114 case MSG_DEBUG:
00115 break;
00116 case MSG_STANDARD:
00117 sound = "geoscape/standard";
00118 break;
00119 case MSG_INFO:
00120 case MSG_TRANSFERFINISHED:
00121 case MSG_DEATH:
00122 case MSG_CONSTRUCTION:
00123 case MSG_PRODUCTION:
00124 sound = "geoscape/info";
00125 break;
00126 case MSG_RESEARCH_PROPOSAL:
00127 case MSG_RESEARCH_FINISHED:
00128 assert(pedia);
00129 case MSG_RESEARCH_HALTED:
00130 case MSG_EVENT:
00131 case MSG_NEWS:
00132
00133 ccs.numUnreadMails = -1;
00134 sound = "geoscape/mail";
00135 break;
00136 case MSG_UFOSPOTTED:
00137 sound = "geoscape/ufospotted";
00138 break;
00139 case MSG_BASEATTACK:
00140 sound = "geoscape/basealert";
00141 break;
00142 case MSG_TERRORSITE:
00143 sound = "geoscape/alien-activity";
00144 break;
00145 case MSG_CRASHSITE:
00146 sound = "geoscape/newmission";
00147 break;
00148 case MSG_PROMOTION:
00149 sound = "geoscape/promotion";
00150 break;
00151 case MSG_MAX:
00152 break;
00153 }
00154
00155 if (playSound)
00156 S_StartLocalSample(sound, SND_VOLUME_DEFAULT);
00157
00158 return mess;
00159 }
00160
00167 static void MS_MessageSaveXML (mxml_node_t *p, message_t *message)
00168 {
00169 mxml_node_t *n;
00170
00171 if (!message)
00172 return;
00173
00174
00175 MS_MessageSaveXML(p, message->next);
00176
00177
00178 if (message->type == MSG_INFO)
00179 return;
00180
00181 Com_RegisterConstList(saveMessageConstants);
00182 n = mxml_AddNode(p, SAVE_MESSAGES_MESSAGE);
00183 mxml_AddString(n, SAVE_MESSAGES_TYPE, Com_GetConstVariable(SAVE_MESSAGETYPE_NAMESPACE, message->type));
00184 mxml_AddStringValue(n, SAVE_MESSAGES_TITLE, message->title);
00185 mxml_AddStringValue(n, SAVE_MESSAGES_TEXT, message->text);
00186
00187 if (message->type == MSG_EVENT) {
00188 mxml_AddString(n, SAVE_MESSAGES_EVENTMAILID, message->eventMail->id);
00189 mxml_AddBoolValue(n, SAVE_MESSAGES_EVENTMAILREAD, message->eventMail->read);
00190 }
00191 if (message->pedia)
00192 mxml_AddString(n, SAVE_MESSAGES_PEDIAID, message->pedia->id);
00193 mxml_AddDate(n, SAVE_MESSAGES_DATE, message->date.day, message->date.sec);
00194 Com_UnregisterConstList(saveMessageConstants);
00195 }
00196
00202 qboolean MS_SaveXML (mxml_node_t *p)
00203 {
00204 mxml_node_t *n = mxml_AddNode(p, SAVE_MESSAGES_MESSAGES);
00205
00206
00207 MS_MessageSaveXML(n, cp_messageStack);
00208 return qtrue;
00209 }
00210
00217 qboolean MS_LoadXML (mxml_node_t *p)
00218 {
00219 int i;
00220 mxml_node_t *n, *sn;
00221 n = mxml_GetNode(p, SAVE_MESSAGES_MESSAGES);
00222
00223 if (!n)
00224 return qfalse;
00225
00226
00227
00228
00229 S_SetSampleRepeatRate(500);
00230
00231 Com_RegisterConstList(saveMessageConstants);
00232 for (sn = mxml_GetNode(n, SAVE_MESSAGES_MESSAGE), i = 0; sn; sn = mxml_GetNextNode(sn, n, SAVE_MESSAGES_MESSAGE), i++) {
00233 eventMail_t *mail;
00234 const char *type = mxml_GetString(sn, SAVE_MESSAGES_TYPE);
00235 int mtype;
00236 char title[MAX_VAR];
00237 char text[MAX_MESSAGE_TEXT];
00238
00239 if (!Com_GetConstIntFromNamespace(SAVE_MESSAGETYPE_NAMESPACE, type, (int*) &mtype)) {
00240 Com_Printf("Invaild message type '%s'\n", type);
00241 continue;
00242 }
00243
00244
00245 Q_strncpyz(title, mxml_GetString(sn, SAVE_MESSAGES_TITLE), sizeof(title));
00246 Q_strncpyz(text, mxml_GetString(sn, SAVE_MESSAGES_TEXT), sizeof(text));
00247
00248 if (mtype == MSG_EVENT) {
00249 mail = CL_GetEventMail(mxml_GetString(sn, SAVE_MESSAGES_EVENTMAILID), qfalse);
00250 if (mail)
00251 mail->read = mxml_GetBool(sn, SAVE_MESSAGES_EVENTMAILREAD, qfalse);
00252 } else
00253 mail = NULL;
00254
00255
00257 if (!((mtype == MSG_EVENT && !mail) || (mtype == MSG_DEBUG && developer->integer != 1))) {
00258 char id[MAX_VAR];
00259 technology_t *tech = NULL;
00260 message_t *mess;
00261
00262 Q_strncpyz(id, mxml_GetString(sn, SAVE_MESSAGES_PEDIAID), sizeof(id));
00263 if (id[0] != '\0')
00264 tech = RS_GetTechByID(id);
00265 if (!tech && (mtype == MSG_RESEARCH_PROPOSAL || mtype == MSG_RESEARCH_FINISHED)) {
00267 continue;
00268 }
00269 mess = MS_AddNewMessageSound(title, text, qfalse, mtype, tech, qfalse);
00270 mess->eventMail = mail;
00271 mxml_GetDate(sn, SAVE_MESSAGES_DATE, &mess->date.day, &mess->date.sec);
00272
00273 MS_TimestampedText(mess->timestamp, mess, sizeof(mess->timestamp));
00274 }
00275 }
00276 Com_UnregisterConstList(saveMessageConstants);
00277
00278
00279 S_SetSampleRepeatRate(0);
00280
00281 return qtrue;
00282 }
00283
00284 void MS_MessageInit (void)
00285 {
00286 MSO_Init();
00287 }