cl_tutorials.c

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2002-2010 UFO: Alien Invasion.
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 
00017 See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023 */
00024 
00025 #include "client.h"
00026 #include "cl_tutorials.h"
00027 #include "ui/ui_main.h"
00028 #include "../shared/parse.h"
00029 
00030 typedef struct tutorial_s {
00031     char name[MAX_VAR];
00032     char sequence[MAX_VAR];
00033 } tutorial_t;
00034 
00035 #define MAX_TUTORIALS 16
00036 static tutorial_t tutorials[MAX_TUTORIALS];
00037 static int numTutorials;
00038 
00039 static void TUT_GetTutorials_f (void)
00040 {
00041     int i;
00042     linkedList_t *tutorialList = NULL;
00043 
00044     for (i = 0; i < numTutorials; i++) {
00045         const tutorial_t *t = &tutorials[i];
00046         LIST_AddString(&tutorialList, va("%s", _(t->name)));
00047     }
00048     UI_RegisterLinkedListText(TEXT_LIST, tutorialList);
00049 }
00050 
00051 static void TUT_List_f (void)
00052 {
00053     int i;
00054 
00055     Com_Printf("Tutorials: %i\n", numTutorials);
00056     for (i = 0; i < numTutorials; i++) {
00057         Com_Printf("tutorial: %s\n", tutorials[i].name);
00058         Com_Printf("..sequence: %s\n", tutorials[i].sequence);
00059     }
00060 }
00061 
00065 static void TUT_ListClick_f (void)
00066 {
00067     int num;
00068 
00069     if (Cmd_Argc() < 2) {
00070         Com_Printf("Usage: %s <num>\n", Cmd_Argv(0));
00071         return;
00072     }
00073 
00074     num = atoi(Cmd_Argv(1));
00075     if (num < 0 || num >= numTutorials)
00076         return;
00077 
00078     Cmd_ExecuteString(va("seq_start %s", tutorials[num].sequence));
00079 }
00080 
00081 void TUT_InitStartup (void)
00082 {
00083     /* tutorial stuff */
00084     Cmd_AddCommand("listtutorials", TUT_List_f, "Show all tutorials");
00085     Cmd_AddCommand("gettutorials", TUT_GetTutorials_f, NULL);
00086     Cmd_AddCommand("tutoriallist_click", TUT_ListClick_f, NULL);
00087 }
00088 
00089 
00090 static const value_t tutValues[] = {
00091     {"name", V_TRANSLATION_STRING, offsetof(tutorial_t, name), 0},
00092     {"sequence", V_STRING, offsetof(tutorial_t, sequence), 0},
00093     {NULL, 0, 0, 0}
00094 };
00095 
00099 void TUT_ParseTutorials (const char *name, const char **text)
00100 {
00101     tutorial_t *t;
00102     const char *errhead = "TUT_ParseTutorials: unexpected end of file (tutorial ";
00103     const char *token;
00104     const value_t *v;
00105 
00106     /* get name list body body */
00107     token = Com_Parse(text);
00108 
00109     if (!*text || *token != '{') {
00110         Com_Printf("TUT_ParseTutorials: tutorial \"%s\" without body ignored\n", name);
00111         return;
00112     }
00113 
00114     /* parse tutorials */
00115     if (numTutorials >= MAX_TUTORIALS) {
00116         Com_Printf("Too many tutorials, '%s' ignored.\n", name);
00117         numTutorials = MAX_TUTORIALS;
00118         return;
00119     }
00120 
00121     t = &tutorials[numTutorials++];
00122     memset(t, 0, sizeof(*t));
00123     do {
00124         /* get the name type */
00125         token = Com_EParse(text, errhead, name);
00126         if (!*text)
00127             break;
00128         if (*token == '}')
00129             break;
00130         for (v = tutValues; v->string; v++)
00131             if (!strncmp(token, v->string, sizeof(v->string))) {
00132                 /* found a definition */
00133                 token = Com_EParse(text, errhead, name);
00134                 if (!*text)
00135                     return;
00136 
00137                 Com_EParseValue(t, token, v->type, v->ofs, v->size);
00138                 break;
00139             }
00140         if (!v->string)
00141             Com_Printf("TUT_ParseTutorials: unknown token \"%s\" ignored (tutorial %s)\n", token, name);
00142     } while (*text);
00143 }

Generated by  doxygen 1.6.2