UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_tutorials.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#include "cl_tutorials.h"
26#include "client.h"
27#include "ui/ui_main.h"
28#include "../shared/parse.h"
29
30typedef struct tutorial_s {
34
35#define MAX_TUTORIALS 16
37static int numTutorials;
38
39static void TUT_GetTutorials_f (void)
40{
41 UI_ExecuteConfunc("tutorialsListClear");
42
43 for (int i = 0; i < numTutorials; i++) {
44 const tutorial_t* t = &tutorials[i];
45 UI_ExecuteConfunc("tutorialsListAdd %i \"%s\"",i, _(t->name));
46 }
47}
48
49static void TUT_List_f (void)
50{
51 Com_Printf("Tutorials: %i\n", numTutorials);
52 for (int i = 0; i < numTutorials; i++) {
53 Com_Printf("tutorial: %s\n", tutorials[i].name);
54 Com_Printf("..sequence: %s\n", tutorials[i].sequence);
55 }
56}
57
61static void TUT_ListClick_f (void)
62{
63 if (Cmd_Argc() < 2) {
64 Com_Printf("Usage: %s <num>\n", Cmd_Argv(0));
65 return;
66 }
67
68 const int num = atoi(Cmd_Argv(1));
69 if (num < 0 || num >= numTutorials)
70 return;
71
72 Cmd_ExecuteString("seq_start %s", tutorials[num].sequence);
73}
74
75void TUT_InitStartup (void)
76{
77 /* tutorial stuff */
78 Cmd_AddCommand("listtutorials", TUT_List_f, "Show all tutorials");
79 Cmd_AddCommand("gettutorials", TUT_GetTutorials_f);
80 Cmd_AddCommand("tutoriallist_click", TUT_ListClick_f);
81
82 numTutorials = 0;
83}
84
85static const value_t tutValues[] = {
86 {"name", V_TRANSLATION_STRING, offsetof(tutorial_t, name), 0},
87 {"sequence", V_STRING, offsetof(tutorial_t, sequence), 0},
88 {nullptr, V_NULL, 0, 0}
89};
90
94void TUT_ParseTutorials (const char* name, const char** text)
95{
96 /* parse tutorials */
98 Com_Printf("Too many tutorials, '%s' ignored.\n", name);
99 return;
100 }
102 OBJZERO(*t);
103
104 Com_ParseBlock(name, text, t, tutValues, nullptr);
105}
#define _(String)
Definition cl_shared.h:44
static void TUT_GetTutorials_f(void)
static const value_t tutValues[]
static void TUT_ListClick_f(void)
click function for text tutoriallist in menu_tutorials.ufo
static void TUT_List_f(void)
static tutorial_t tutorials[MAX_TUTORIALS]
void TUT_InitStartup(void)
#define MAX_TUTORIALS
static int numTutorials
void TUT_ParseTutorials(const char *name, const char **text)
Primary header for client.
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition cmd.cpp:1007
const char * Cmd_Argv(int arg)
Returns a given argument.
Definition cmd.cpp:516
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
Shared parsing functions.
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
bool Com_ParseBlock(const char *name, const char **text, void *base, const value_t *values, memPool_t *mempool)
Definition scripts.cpp:1393
@ V_TRANSLATION_STRING
Definition scripts.h:59
@ V_NULL
Definition scripts.h:49
@ V_STRING
Definition scripts.h:58
#define OBJZERO(obj)
Definition shared.h:178
#define MAX_VAR
Definition shared.h:36
char sequence[MAX_VAR]
char name[MAX_VAR]
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.
Definition ui_main.cpp:110