TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
racemanmenu.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : racemanmenu.cpp
4 created : Fri Jan 3 22:24:41 CET 2003
5 copyright : (C) 2003-2026 by Eric EspiƩ, Bernhard Wymann
6 email : berniw@bluewin.ch
7
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
21
22#include <stdlib.h>
23#include <stdio.h>
24#include <tgfclient.h>
25#include <raceman.h>
26#include <racescreens.h>
27#include <driverconfig.h>
28#include <portability.h>
29
30#include "raceengine.h"
31#include "racemain.h"
32#include "raceinit.h"
33#include "racestate.h"
34
35#include "racemanmenu.h"
36
37static float red[4] = {1.0, 0.0, 0.0, 1.0};
38
39static void *racemanMenuHdle = NULL;
40static void *newTrackMenuHdle = NULL;
41static int newRaceButtonId = -1;
46static const char *NoDriversSelectedMessage = "No drivers selected. Configure Race and select at least one";
47
48static void reConfigRunState(void);
49
50static int
52{
53 return ReInfo && ReInfo->params && GfParmGetEltNb(ReInfo->params, RM_SECT_DRIVERS) > 0;
54}
55
56static void
58{
59 const int hasSelectedDrivers = reHasSelectedDrivers();
60
61 if (!racemanMenuHdle) {
62 return;
63 }
64
65 if (newRaceButtonId >= 0) {
67 }
68}
69
70static void
72{
73 if (!reHasSelectedDrivers()) {
75 return;
76 }
77
78 ReStartNewRace(NULL);
79}
80
81static void
83{
84 void *params = ReInfo->params;
85
86 /* Go back one step in the conf */
88 GfParmGetNum(params, RM_SECT_CONF, RM_ATTR_CUR_CONF, NULL, 1) - 2);
89
91}
92
93
94/***************************************************************/
95/* Callback hooks used only to run the automaton on activation */
96static void *configHookHandle = 0;
97
98static void
100{
102}
103
104static void *
114
115/***************************************************************/
116/* Config Back Hook */
117
118static void *ConfigBackHookHandle = 0;
119
120static void
125
126static void *
136
137static void
139{
140 int i;
141 const char* opt;
142 const char* conf;
143 int curConf;
144 int numOpt;
145 void *params = ReInfo->params;
146 const int BUFSIZE = 1024;
147 char path[BUFSIZE];
148
149 curConf = (int)GfParmGetNum(params, RM_SECT_CONF, RM_ATTR_CUR_CONF, NULL, 1);
150 if (curConf > GfParmGetEltNb(params, RM_SECT_CONF)) {
151 GfOut("End of configuration\n");
152 GfParmWriteFile(NULL, ReInfo->params, ReInfo->_reName);
153 goto menuback;
154 }
155
156 snprintf(path, BUFSIZE, "%s/%d", RM_SECT_CONF, curConf);
157 conf = GfParmGetStr(params, path, RM_ATTR_TYPE, 0);
158 if (!conf) {
159 GfOut("no %s here %s\n", RM_ATTR_TYPE, path);
160 goto menuback;
161 }
162
163 GfOut("Configuration step %s\n", conf);
164 if (!strcmp(conf, RM_VAL_TRACKSEL)) {
165 /* Track Select Menu */
166 ts.nextScreen = reConfigHookInit();
167 if (curConf == 1) {
168 ts.prevScreen = racemanMenuHdle;
169 } else {
170 ts.prevScreen = reConfigBackHookInit();
171 }
172 ts.param = ReInfo->params;
173 ts.trackItf = ReInfo->_reTrackItf;
174 RmTrackSelect(&ts);
175 } else if (!strcmp(conf, RM_VAL_DRVSEL)) {
176 /* Drivers select menu */
177 ds.nextScreen = reConfigHookInit();
178 if (curConf == 1) {
179 ds.prevScreen = racemanMenuHdle;
180 } else {
181 ds.prevScreen = reConfigBackHookInit();
182 }
183 ds.param = ReInfo->params;
185
186 } else if (!strcmp(conf, RM_VAL_RACECONF)) {
187 /* Race Options menu */
188 rp.nextScreen = reConfigHookInit();
189 if (curConf == 1) {
190 rp.prevScreen = racemanMenuHdle;
191 } else {
192 rp.prevScreen = reConfigBackHookInit();
193 }
194 rp.param = ReInfo->params;
195 rp.title = GfParmGetStr(params, path, RM_ATTR_RACE, "Race");
196 /* Select options to configure */
197 rp.confMask = 0;
198 snprintf(path, BUFSIZE, "%s/%d/%s", RM_SECT_CONF, curConf, RM_SECT_OPTIONS);
199 numOpt = GfParmGetEltNb(params, path);
200 for (i = 1; i < numOpt + 1; i++) {
201 snprintf(path, BUFSIZE, "%s/%d/%s/%d", RM_SECT_CONF, curConf, RM_SECT_OPTIONS, i);
202 opt = GfParmGetStr(params, path, RM_ATTR_TYPE, "");
203 if (!strcmp(opt, RM_VAL_CONFRACELEN)) {
204 /* Configure race length */
205 rp.confMask |= RM_CONF_RACE_LEN;
206 } else {
207 if (!strcmp(opt, RM_VAL_CONFDISPMODE)) {
208 /* Configure display mode */
209 rp.confMask |= RM_CONF_DISP_MODE;
210 }
211 }
212 }
214 }
215
216 curConf++;
217 GfParmSetNum(params, RM_SECT_CONF, RM_ATTR_CUR_CONF, NULL, curConf);
218
219 return;
220
221 /* Back to the race menu */
222 menuback:
225 return;
226}
227
228static void
230{
231 void *params = ReInfo->params;
232
233 /* Reset configuration automaton */
234 GfParmSetNum(params, RM_SECT_CONF, RM_ATTR_CUR_CONF, NULL, 1);
236}
237
238static void
239reSelectLoadFile(char *filename)
240{
241 const int BUFSIZE = 1024;
242 char buf[BUFSIZE];
243
244 snprintf(buf, BUFSIZE, "%sresults/%s/%s", GetLocalDir(), ReInfo->_reFilename, filename);
245 GfOut("Loading Saved File %s...\n", buf);
247 ReInfo->_reRaceName = ReInfo->_reName;
248 RmShowStandings(ReInfo->_reGameScreen, ReInfo);
249}
250
251// FIXME: remove this static shared buffer!
252const int VARBUFSIZE = 1024;
254
255static void
257{
258 void *params = ReInfo->params;
259
260 fs.prevScreen = prevHandle;
261 fs.select = reSelectLoadFile;
262
263 const char* str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_NAME, 0);
264 if (str) {
265 fs.title = str;
266 }
267
268 snprintf(varbuf, VARBUFSIZE, "%sresults/%s", GetLocalDir(), ReInfo->_reFilename);
269 fs.path = varbuf;
270
271 RmFileSelect((void*)&fs);
272}
273
274int
276{
277 void *params = ReInfo->params;
278
279 if (racemanMenuHdle) {
281 }
282 newRaceButtonId = -1;
283
285 tGfuiAction(),
286 tGfuiAction(),
287 1);
288
289 const char* str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_BGIMG, 0);
290 if (str) {
292 }
293
295
296 str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_NAME, 0);
297 if (str) {
298 GfuiTitleCreate(racemanMenuHdle, str, strlen(str));
299 }
300
301
303 "New Race", "Start a New Race", NoDriversSelectedMessage,
305
307 "Configure Race", "Configure The Race",
309
310/* GfuiMenuButtonCreate(racemanMenuHdle, */
311/* "Configure Players", "Players configuration menu", */
312/* TorcsDriverMenuInit(racemanMenuHdle), GfuiScreenActivate); */
313
314 if (GfParmGetEltNb(params, RM_SECT_TRACKS) > 1) {
316 "Load", "Load a Previously Saved Game",
317 [] { reLoadMenu(racemanMenuHdle); });
318 }
319
321 "Back to Main", "Return to previous Menu",
322 [] { GfuiScreenActivate(ReInfo->_reMenuScreen); });
323
326
327 return RM_ASYNC | RM_NEXT_STEP;
328}
329
330static void
332{
334}
335
336int
338{
339 void *params = ReInfo->params;
340 void *results = ReInfo->results;
341 const int BUFSIZE = 1024;
342 char buf[BUFSIZE];
343
344 if (newTrackMenuHdle) {
346 }
347
349 tGfuiAction(),
350 tGfuiAction(),
351 1);
352
353 const char* str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_BGIMG, 0);
354 if (str) {
356 }
357
358 str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_NAME, "");
359 GfuiTitleCreate(newTrackMenuHdle, str, strlen(str));
360
362
363 snprintf(buf, BUFSIZE, "Race Day #%d/%d on %s",
364 (int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_TRACK, NULL, 1),
366 ReInfo->track->name);
367
369 buf,
370 red,
372 320, 420,
373 GFUI_ALIGN_HC_VB, 50);
374
376 "Start Event", "Start The Current Race",
378
379
381 "Abandon", "Abandon The Race",
382 [] { GfuiScreenActivate(ReInfo->_reMenuScreen); });
383
384 GfuiAddKeyAction(newTrackMenuHdle, 27, "Abandon", [] { GfuiScreenActivate(ReInfo->_reMenuScreen); }, tGfuiAction());
385
387
388 return RM_ASYNC | RM_NEXT_STEP;
389}
static void * prevHandle
int GfuiMenuButtonCreateAction(void *scr, const char *text, const char *tip, const tGfuiAction &onpush)
Add a menu button with a focus tip.
Definition guimenu.cpp:165
void * GfuiScreenCreateExAction(float *bgColor, const tGfuiAction &onActivate, const tGfuiAction &onDeactivate, int mouseAllowed)
Create a screen.
Definition gui.cpp:619
void GfuiMenuDefaultKeysAdd(void *scr)
Add the default menu keyboard callback to a screen.
Definition guimenu.cpp:56
void GfuiScreenRelease(void *scr)
Release the given screen.
Definition gui.cpp:670
int GfuiTitleCreate(void *scr, const char *text, int maxlen)
Add a Title to the screen.
Definition guilabel.cpp:150
void GfuiAddKeyAction(void *scr, unsigned char key, const char *descr, const tGfuiAction &onKeyPressed, const tGfuiAction &onKeyReleased)
Add a Keyboard callback to a screen.
Definition gui.cpp:809
void GfuiScreenAddBgImg(void *scr, const char *filename)
Add an image background to a screen.
Definition gui.cpp:1058
int GfuiMenuButtonCreateActionWithDisabledTip(void *scr, const char *text, const char *tip, const char *disabledTip, const tGfuiAction &onpush)
Add a button to a menu screen.
Definition guimenu.cpp:124
int GfuiEnable(void *scr, int id, int flag)
Enable / Disable an object.
void * GfuiHookCreateAction(const tGfuiAction &onActivate)
Create a callback hook.
Definition gui.cpp:736
int GfuiLabelCreateEx(void *scr, const char *text, float *fgColor, int font, int x, int y, int align, int maxlen)
Create a new label (extended version).
Definition guilabel.cpp:51
int GfuiMenuBackQuitButtonCreateAction(void *scr, const char *text, const char *tip, const tGfuiAction &onpush)
Add the "Back" or "Quit" button at the bottom of the menu screen.
Definition guimenu.cpp:187
void GfuiScreenActivate(void *screen)
Activate a screen and make it current.
Definition gui.cpp:508
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
Definition params.cpp:2453
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
Definition params.cpp:2534
int GfParmSetNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle.
Definition params.cpp:2737
int GfParmWriteFile(const char *file, void *parmHandle, const char *name)
Write parameter set into file.
Definition params.cpp:1732
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
Definition params.cpp:1173
int GfParmGetEltNb(void *handle, const char *path)
Count the number of subsections in a section in the parameter set handle.
Definition params.cpp:2243
void RmShowStandings(void *prevHdle, tRmInfo *info)
Display standings.
Definition results.cpp:598
void RmDriversSelect(void *vs)
Drivers list selection, the race manager parameter set is handed over in vs, tRmDrvSelect....
void RmRaceParamMenu(void *vrp)
Race options menu.
Definition racemenu.cpp:134
void RmTrackSelect(void *)
Track selection, the race manager parameter set is handed over in vs, tRmTrackSelect....
void RmFileSelect(void *vs)
File selection.
tRmInfo * ReInfo
static float red[4]
Definition racegl.cpp:43
void ReStartNewRace(void *)
Definition raceinit.cpp:128
#define RM_ATTR_NAME
Definition raceman.h:258
#define RE_SECT_CURRENT
Definition raceman.h:333
#define RM_VAL_TRACKSEL
Definition raceman.h:301
#define RM_VAL_CONFDISPMODE
Definition raceman.h:305
#define RM_VAL_RACECONF
Definition raceman.h:303
#define RM_NEXT_STEP
Definition raceman.h:46
#define RM_SECT_OPTIONS
Definition raceman.h:242
#define RM_SECT_DRIVERS
Definition raceman.h:237
#define RE_ATTR_CUR_TRACK
Definition raceman.h:335
#define RM_SECT_CONF
Definition raceman.h:241
#define RM_ATTR_RACE
Definition raceman.h:274
#define RM_ASYNC
Definition raceman.h:41
#define RM_ATTR_CUR_CONF
Definition raceman.h:247
#define RM_VAL_CONFRACELEN
Definition raceman.h:304
#define RM_SECT_HEADER
Definition raceman.h:236
#define RM_ATTR_BGIMG
Definition raceman.h:262
#define RM_VAL_DRVSEL
Definition raceman.h:302
#define RM_SECT_TRACKS
Definition raceman.h:240
#define RM_ATTR_TYPE
Definition raceman.h:273
static void reConfigRunState(void)
static void reLoadMenu(void *prevHandle)
char varbuf[VARBUFSIZE]
static void reStateManage(void)
static int reHasSelectedDrivers(void)
int ReRacemanMenu(void)
static void * configHookHandle
static void reStartNewRace(void)
int ReNewTrackMenu(void)
static void reUpdateNewRaceState(void)
static tRmFileSelect fs
static void reConfigureMenu(void)
static tRmRaceParam rp
static void ConfigBackHookActivate(void)
static void * ConfigBackHookHandle
static void reConfigBack(void)
const int VARBUFSIZE
static void reSelectLoadFile(char *filename)
static const char * NoDriversSelectedMessage
static void * newTrackMenuHdle
static tRmDrvSelect ds
static void configHookActivate(void)
static void * racemanMenuHdle
static void * reConfigBackHookInit(void)
static int newRaceButtonId
static tRmTrackSelect ts
static void * reConfigHookInit(void)
#define RM_CONF_DISP_MODE
Definition racescreens.h:62
#define RM_CONF_RACE_LEN
Definition racescreens.h:61
void ReStateManage(void)
Definition racestate.cpp:52
Structure for driver selection.
Definition racescreens.h:44
Structure for file selection.
Definition racescreens.h:76
Structure for configuring parameters.
Definition racescreens.h:55
Structure for track selection.
Definition racescreens.h:32
char * GetLocalDir(void)
Definition tgf.cpp:230
#define GfOut
Definition tgf.h:372
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
Definition tgf.h:266
#define GFPARM_RMODE_STD
Return a new handle sharing cached data for this filename, if available.
Definition tgf.h:264
#define GFUI_ENABLE
Definition tgfclient.h:242
#define GFUI_FONT_MEDIUM_C
Definition tgfclient.h:253
std::function< void()> tGfuiAction
Definition tgfclient.h:107
#define GFUI_ALIGN_HC_VB
Definition tgfclient.h:74
#define GFUI_DISABLE
Definition tgfclient.h:241