/** * @sa CL_EventAddMail_f */ void UP_OpenEventMail (const char* eventMailID) { eventMail_t* mail; mail = CL_GetEventMail(eventMailID); if (!mail) return; cgi->UI_PushWindow("mail"); UP_Article(nullptr, mail); }
/** * @brief Adds the event mail to the message stack. This message is going to be added to the savegame. */ void CL_EventAddMail (const char *eventMailId) { eventMail_t* eventMail = CL_GetEventMail(eventMailId); if (!eventMail) { Com_Printf("CL_EventAddMail: Could not find eventmail with id '%s'\n", eventMailId); return; } if (eventMail->sent) { return; } if (!eventMail->from || !eventMail->to || !eventMail->subject || !eventMail->body) { Com_Printf("CL_EventAddMail: mail with id '%s' has incomplete data\n", eventMailId); return; } if (!eventMail->date) { dateLong_t date; char dateBuf[MAX_VAR] = ""; CP_DateConvertLong(&ccs.date, &date); Com_sprintf(dateBuf, sizeof(dateBuf), _("%i %s %02i"), date.year, Date_GetMonthName(date.month - 1), date.day); eventMail->date = Mem_PoolStrDup(dateBuf, cp_campaignPool, 0); } eventMail->sent = true; if (!eventMail->skipMessage) { uiMessageListNodeMessage_t *m = MS_AddNewMessage("", va(_("You've got a new mail: %s"), _(eventMail->subject)), MSG_EVENT); if (m) m->eventMail = eventMail; else Com_Printf("CL_EventAddMail: Could not add message with id: %s\n", eventMailId); } UP_OpenEventMail(eventMailId); }
/** * @brief Load callback for messages * @param[in] p XML Node structure, where we get the information from * @sa MS_SaveXML * @sa UI_AddNewMessageSound */ bool MS_LoadXML (xmlNode_t* p) { int i; xmlNode_t* n, *sn; n = cgi->XML_GetNode(p, SAVE_MESSAGES_MESSAGES); if (!n) return false; /* we have to set this a little bit higher here, otherwise the samples that are played when adding * a message to the stack would all played a few milliseconds after each other - that doesn't sound * nice */ cgi->S_SetSampleRepeatRate(500); cgi->Com_RegisterConstList(saveMessageConstants); for (sn = cgi->XML_GetNode(n, SAVE_MESSAGES_MESSAGE), i = 0; sn; sn = cgi->XML_GetNextNode(sn, n, SAVE_MESSAGES_MESSAGE), i++) { eventMail_t* mail; const char* type = cgi->XML_GetString(sn, SAVE_MESSAGES_TYPE); int mtype; char title[MAX_VAR]; char text[MAX_MESSAGE_TEXT]; char id[MAX_VAR]; technology_t* tech = nullptr; uiMessageListNodeMessage_t* mess; if (!cgi->Com_GetConstIntFromNamespace(SAVE_MESSAGETYPE_NAMESPACE, type, (int*) &mtype)) { cgi->Com_Printf("Invalid message type '%s'\n", type); continue; } /* can contain high bits due to utf8 */ Q_strncpyz(title, cgi->XML_GetString(sn, SAVE_MESSAGES_TITLE), sizeof(title)); Q_strncpyz(text, cgi->XML_GetString(sn, SAVE_MESSAGES_TEXT), sizeof(text)); if (mtype == MSG_EVENT) { mail = CL_GetEventMail(cgi->XML_GetString(sn, SAVE_MESSAGES_EVENTMAILID)); if (mail) mail->read = cgi->XML_GetBool(sn, SAVE_MESSAGES_EVENTMAILREAD, false); } else mail = nullptr; /* event and not mail means, dynamic mail - we don't save or load them */ if (mtype == MSG_EVENT && !mail) continue; if (mtype == MSG_DEBUG && cgi->Cvar_GetInteger("developer") == 0) continue; Q_strncpyz(id, cgi->XML_GetString(sn, SAVE_MESSAGES_PEDIAID), sizeof(id)); if (id[0] != '\0') tech = RS_GetTechByID(id); if (!tech && (mtype == MSG_RESEARCH_PROPOSAL || mtype == MSG_RESEARCH_FINISHED)) { /** No tech found drop message. */ continue; } mess = MS_AddNewMessage(title, text, (messageType_t)mtype, tech, false, false); mess->eventMail = mail; cgi->XML_GetDate(sn, SAVE_MESSAGES_DATE, &mess->date.day, &mess->date.sec); /* redo timestamp text after setting date */ MS_TimestampedText(mess->timestamp, mess, sizeof(mess->timestamp)); if (mail) { dateLong_t date; char dateBuf[MAX_VAR] = ""; CP_DateConvertLong(&mess->date, &date); Com_sprintf(dateBuf, sizeof(dateBuf), _("%i %s %02i"), date.year, Date_GetMonthName(date.month - 1), date.day); mail->date = cgi->PoolStrDup(dateBuf, cp_campaignPool, 0); } } cgi->Com_UnregisterConstList(saveMessageConstants); /* reset the sample repeat rate */ cgi->S_SetSampleRepeatRate(0); return true; }