UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
cl_tip.cpp
Go to the documentation of this file.
1
5
6
/*
7
All original material Copyright (C) 2002-2025 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
;
35
struct
tipOfTheDay_s*
next
;
36
}
tipOfTheDay_t
;
37
38
static
tipOfTheDay_t
*
tipList
;
39
static
int
tipCount
;
40
41
static
cvar_t
*
cl_showTipOfTheDay
;
42
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
74
UI_RegisterText
(
TEXT_TIPOFTHEDAY
, tip->
tipString
);
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
}
86
tipOfTheDay_t
*
const
tip =
Mem_PoolAllocType
(
tipOfTheDay_t
,
cl_genericPool
);
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
}
cl_genericPool
memPool_t * cl_genericPool
Definition
cl_main.cpp:86
CL_GetTipOfTheDay_f
static void CL_GetTipOfTheDay_f(void)
Popup with tip of the day messages.
Definition
cl_tip.cpp:48
TOTD_InitStartup
void TOTD_InitStartup(void)
Init function for cvars and console command bindings.
Definition
cl_tip.cpp:96
cl_showTipOfTheDay
static cvar_t * cl_showTipOfTheDay
Definition
cl_tip.cpp:41
tipCount
static int tipCount
Definition
cl_tip.cpp:39
TOTD_Shutdown
void TOTD_Shutdown(void)
Definition
cl_tip.cpp:104
CL_ParseTipOfTheDay
void CL_ParseTipOfTheDay(const char *name, const char **text)
Parse all tip definitions from the script files.
Definition
cl_tip.cpp:80
tipList
static tipOfTheDay_t * tipList
Definition
cl_tip.cpp:38
cl_tip.h
client.h
Primary header for client.
Cmd_Argc
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
Cmd_AddCommand
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition
cmd.cpp:744
Com_Printf
void Com_Printf(const char *const fmt,...)
Definition
common.cpp:428
Cvar_Get
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
CVAR_ARCHIVE
#define CVAR_ARCHIVE
Definition
cvar.h:40
Mem_PoolStrDup
#define Mem_PoolStrDup(in, pool, tagNum)
Definition
mem.h:50
Mem_PoolAllocType
#define Mem_PoolAllocType(type, pool)
Definition
mem.h:43
parse.h
Shared parsing functions.
name
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition
r_gl.h:110
cvar_t
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition
cvar.h:71
tipOfTheDay_t
Definition
cl_tip.cpp:33
tipOfTheDay_t::tipString
const char * tipString
Definition
cl_tip.cpp:34
tipOfTheDay_t::next
struct tipOfTheDay_s * next
Definition
cl_tip.cpp:35
UI_RegisterText
void UI_RegisterText(int dataId, const char *text)
share a text with a data id
Definition
ui_data.cpp:115
TEXT_TIPOFTHEDAY
@ TEXT_TIPOFTHEDAY
Definition
ui_dataids.h:55
ui_main.h
UI_CloseWindow
void UI_CloseWindow(const char *name)
Definition
ui_windows.cpp:435
src
client
cl_tip.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0