cl_tip.c
Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "client.h"
00029 #include "cl_tip.h"
00030 #include "ui/ui_main.h"
00031 #include "../shared/parse.h"
00032
00033 typedef struct tipOfTheDay_s {
00034 const char *tipString;
00035 struct tipOfTheDay_s* next;
00036 } tipOfTheDay_t;
00037
00038 static tipOfTheDay_t *tipList;
00039 static int tipCount;
00041 static cvar_t* cl_showTipOfTheDay;
00048 static void CL_GetTipOfTheDay_f (void)
00049 {
00050 static int lastOne = 0;
00051 int rnd;
00052 tipOfTheDay_t* tip;
00053
00055 if (!tipCount) {
00056 UI_CloseWindow("popup_tipoftheday");
00057 Com_Printf("No tips parsed\n");
00058 return;
00059 }
00060
00061 if (Cmd_Argc() == 2) {
00062 rnd = rand() % tipCount;
00063 lastOne = rnd;
00064 } else {
00065 lastOne = (lastOne + 1) % tipCount;
00066 rnd = lastOne;
00067 }
00068
00069 tip = tipList;
00070 while (rnd) {
00071 tip = tip->next;
00072 rnd--;
00073 }
00074
00075 UI_RegisterText(TEXT_TIPOFTHEDAY, tip->tipString);
00076 }
00077
00081 void CL_ParseTipsOfTheDay (const char *name, const char **text)
00082 {
00083 const char *errhead = "CL_ParseTipsOfTheDay: unexpected end of file (tips ";
00084 const char *token;
00085 tipOfTheDay_t *tip;
00086
00087
00088 token = Com_Parse(text);
00089
00090 if (!*text || *token != '{') {
00091 Com_Printf("CL_ParseTipsOfTheDay: tips without body ignored\n");
00092 return;
00093 }
00094
00095 do {
00096
00097 token = Com_EParse(text, errhead, name);
00098 if (!*text)
00099 break;
00100 if (*token == '}')
00101 break;
00102 if (*token != '_') {
00103 Com_Printf("Ignore tip: '%s' - not marked translatable\n", token);
00104 continue;
00105 }
00106 tip = Mem_PoolAlloc(sizeof(*tip), cl_genericPool, 0);
00107 tip->tipString = Mem_PoolStrDup(token, cl_genericPool, 0);
00108 tip->next = tipList;
00109 tipList = tip;
00110 tipCount++;
00111 } while (*text);
00112 }
00113
00117 void TOTD_InitStartup (void)
00118 {
00119 cl_showTipOfTheDay = Cvar_Get("cl_showTipOfTheDay", "1", CVAR_ARCHIVE, "Show the tip of the day for singleplayer campaigns");
00120
00121
00122 Cmd_AddCommand("tipoftheday", CL_GetTipOfTheDay_f, "Get the next tip of the day from the script files - called from tip of the day menu");
00123 }