UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cl_tip.cpp
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 Copyright (C) 1997-2001 Id Software, Inc.
10 
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 
20 See the GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 
26 */
27 
28 #include "cl_tip.h"
29 #include "client.h"
30 #include "ui/ui_main.h"
31 #include "../shared/parse.h"
32 
33 typedef struct tipOfTheDay_s {
34  const char* tipString;
37 
39 static int tipCount;
48 static void CL_GetTipOfTheDay_f (void)
49 {
50  static int lastOne = 0;
51 
53  if (!tipCount) {
54  UI_CloseWindow("popup_tipoftheday");
55  Com_Printf("No tips parsed\n");
56  return;
57  }
58 
59  int rnd;
60  if (Cmd_Argc() == 2) {
61  rnd = rand() % tipCount;
62  lastOne = rnd;
63  } else {
64  lastOne = (lastOne + 1) % tipCount;
65  rnd = lastOne;
66  }
67 
68  tipOfTheDay_t* tip = tipList;
69  while (rnd) {
70  tip = tip->next;
71  rnd--;
72  }
73 
75 }
76 
80 void CL_ParseTipOfTheDay (const char* name, const char** text)
81 {
82  if (name[0] != '_') {
83  Com_Printf("Ignore tip: '%s' - not marked translatable\n", name);
84  return;
85  }
87  tip->tipString = Mem_PoolStrDup(name, cl_genericPool, 0);
88  tip->next = tipList;
89  tipList = tip;
90  tipCount++;
91 }
92 
96 void TOTD_InitStartup (void)
97 {
98  cl_showTipOfTheDay = Cvar_Get("cl_showTipOfTheDay", "1", CVAR_ARCHIVE, "Show the tip of the day for singleplayer campaigns");
99 
100  /* commands */
101  Cmd_AddCommand("tipoftheday", CL_GetTipOfTheDay_f, "Get the next tip of the day from the script files - called from tip of the day menu");
102 }
103 
104 void TOTD_Shutdown (void)
105 {
106  tipList = nullptr;
107  tipCount = 0;
108 }
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition: cmd.cpp:744
struct tipOfTheDay_s * next
Definition: cl_tip.cpp:35
void TOTD_InitStartup(void)
Init function for cvars and console command bindings.
Definition: cl_tip.cpp:96
void UI_RegisterText(int dataId, const char *text)
share a text with a data id
Definition: ui_data.cpp:115
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition: cvar.h:71
static void CL_GetTipOfTheDay_f(void)
Popup with tip of the day messages.
Definition: cl_tip.cpp:48
const char * tipString
Definition: cl_tip.cpp:34
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
#define CVAR_ARCHIVE
Definition: cvar.h:40
memPool_t * cl_genericPool
Definition: cl_main.cpp:86
void CL_ParseTipOfTheDay(const char *name, const char **text)
Parse all tip definitions from the script files.
Definition: cl_tip.cpp:80
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition: cvar.cpp:342
static int tipCount
Definition: cl_tip.cpp:39
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
Definition: cmd.cpp:505
void TOTD_Shutdown(void)
Definition: cl_tip.cpp:104
void UI_CloseWindow(const char *name)
Definition: ui_windows.cpp:435
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
static cvar_t * cl_showTipOfTheDay
Definition: cl_tip.cpp:41
struct tipOfTheDay_s tipOfTheDay_t
Primary header for client.
#define Mem_PoolStrDup(in, pool, tagNum)
Definition: mem.h:50
#define Mem_PoolAllocType(type, pool)
Definition: mem.h:43
static tipOfTheDay_t * tipList
Definition: cl_tip.cpp:38