UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_tip.cpp
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Copyright (C) 1997-2001 Id Software, Inc.
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20See the GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program; if not, write to the Free Software
24Foundation, 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
33typedef struct tipOfTheDay_s {
34 const char* tipString;
35 struct tipOfTheDay_s* next;
37
39static int tipCount;
40
42
48static 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
69 while (rnd) {
70 tip = tip->next;
71 rnd--;
72 }
73
75}
76
80void 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 }
88 tip->next = tipList;
89 tipList = tip;
90 tipCount++;
91}
92
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
104void TOTD_Shutdown (void)
105{
106 tipList = nullptr;
107 tipCount = 0;
108}
memPool_t * cl_genericPool
Definition cl_main.cpp:86
static void CL_GetTipOfTheDay_f(void)
Popup with tip of the day messages.
Definition cl_tip.cpp:48
void TOTD_InitStartup(void)
Init function for cvars and console command bindings.
Definition cl_tip.cpp:96
static cvar_t * cl_showTipOfTheDay
Definition cl_tip.cpp:41
static int tipCount
Definition cl_tip.cpp:39
void TOTD_Shutdown(void)
Definition cl_tip.cpp:104
void CL_ParseTipOfTheDay(const char *name, const char **text)
Parse all tip definitions from the script files.
Definition cl_tip.cpp:80
static tipOfTheDay_t * tipList
Definition cl_tip.cpp:38
Primary header for client.
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 Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition cmd.cpp:744
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
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
#define CVAR_ARCHIVE
Definition cvar.h:40
#define Mem_PoolStrDup(in, pool, tagNum)
Definition mem.h:50
#define Mem_PoolAllocType(type, pool)
Definition mem.h:43
Shared parsing functions.
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition cvar.h:71
const char * tipString
Definition cl_tip.cpp:34
struct tipOfTheDay_s * next
Definition cl_tip.cpp:35
void UI_RegisterText(int dataId, const char *text)
share a text with a data id
Definition ui_data.cpp:115
@ TEXT_TIPOFTHEDAY
Definition ui_dataids.h:55
void UI_CloseWindow(const char *name)