UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cl_tutorials.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, 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 
30 typedef struct tutorial_s {
31  char name[MAX_VAR];
33 } tutorial_t;
34 
35 #define MAX_TUTORIALS 16
37 static int numTutorials;
38 
39 static 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 
49 static 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 
61 static 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 
75 void 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 
85 static 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 
94 void TUT_ParseTutorials (const char* name, const char** text)
95 {
96  /* parse tutorials */
97  if (numTutorials >= MAX_TUTORIALS) {
98  Com_Printf("Too many tutorials, '%s' ignored.\n", name);
99  return;
100  }
101  tutorial_t* t = &tutorials[numTutorials++];
102  OBJZERO(*t);
103 
104  Com_ParseBlock(name, text, t, tutValues, nullptr);
105 }
bool Com_ParseBlock(const char *name, const char **text, void *base, const value_t *values, memPool_t *mempool)
Definition: scripts.cpp:1415
const char * Cmd_Argv(int arg)
Returns a given argument.
Definition: cmd.cpp:516
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 TUT_ParseTutorials(const char *name, const char **text)
#define _(String)
Definition: cl_shared.h:43
static tutorial_t tutorials[MAX_TUTORIALS]
static void TUT_List_f(void)
#define MAX_TUTORIALS
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
void TUT_InitStartup(void)
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition: cmd.cpp:1007
static void TUT_ListClick_f(void)
click function for text tutoriallist in menu_tutorials.ufo
#define OBJZERO(obj)
Definition: shared.h:178
#define MAX_VAR
Definition: shared.h:36
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
char name[MAX_VAR]
static const value_t tutValues[]
struct tutorial_s tutorial_t
Definition: scripts.h:49
QGL_EXTERN GLint i
Definition: r_gl.h:113
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
static void TUT_GetTutorials_f(void)
static int numTutorials
char sequence[MAX_VAR]
Primary header for client.
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.
Definition: ui_main.cpp:110