void PCreateSetLengthMenu(void* ts) { handle = GfuiScreenCreate(); fManager = PFileManager::Get(); // Create Title GfuiTitleCreate(handle, "Set Length", std::string("Set Length").length()); // Set up background image GfuiScreenAddBgImg(handle, "data/img/splash-filesel.png"); // Create Edit Box GfuiLabelCreate(handle, "Track Length (km):", GFUI_FONT_MEDIUM, 310, 260, GFUI_ALIGN_HC_VC, std::string("Track Length (km):").length()); editBoxID = GfuiEditboxCreate(handle, "1000", GFUI_FONT_MEDIUM, 265, 240, 100, 20, nullptr, nullptr, PUpdateEditBox); // Create error label errLabelID = GfuiLabelCreate(handle, " ", GFUI_FONT_MEDIUM, 30, 0, GFUI_ALIGN_HL_VB, 256); float col[4] = { 1.f, 0.f, 0.f, 1.f }; GfuiLabelSetColor(handle, errLabelID, col); // Create buttons GfuiButtonCreate(handle, "Accept", GFUI_FONT_MEDIUM, 365, 200, 50, GFUI_ALIGN_HC_VC, 0, ts, PAcceptCallback, nullptr, nullptr, nullptr); GfuiButtonCreate(handle, "Cancel", GFUI_FONT_MEDIUM, 245, 200, 50, GFUI_ALIGN_HC_VC, 0, ts, PAcceptCallback, nullptr, nullptr, nullptr); GfuiScreenActivate(handle); }
static int createBackgroundImage(void* hscr, void* hparm, const char* pszName) { const char* pszImage = GfParmGetStr(hparm, pszName, GFMNU_ATTR_IMAGE, ""); GfuiScreenAddBgImg(hscr, pszImage); return 1; }
void * MouseCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd) { //int x, y, dy; Cmd = cmd; maxCmd = maxcmd; if (scrHandle2) { return scrHandle2; } scrHandle2 = GfuiScreenCreateEx(NULL, NULL, onActivate2, NULL, NULL, 1); GfuiTitleCreate(scrHandle2, "Mouse Calibration", 0); GfuiMenuDefaultKeysAdd(scrHandle2); GfuiScreenAddBgImg(scrHandle2, "data/img/splash-mousecal.png"); //x = 128; //y = 300; //dy = 50; InstId = GfuiLabelCreate(scrHandle2, "", GFUI_FONT_MEDIUM, 320, 80, GFUI_ALIGN_HC_VB, 60); GfuiButtonCreate(scrHandle2, "Back", GFUI_FONT_LARGE, 160, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, prevMenu, GfuiScreenActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle2, "Reset", GFUI_FONT_LARGE, 480, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, onActivate2, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); return scrHandle2; }
/* Menu creation */ void * SimuMenuInit(void *prevMenu) { int x, y, x2, x3, x4, dy; /* screen already created */ if (scrHandle) { return scrHandle; } prevHandle = prevMenu; scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, onActivate, NULL, (tfuiCallback)NULL, 1); GfuiTitleCreate(scrHandle, "Simulation Configuration", 0); GfuiScreenAddBgImg(scrHandle, "data/img/splash-simucfg.png"); x = 20; x2 = 240; x3 = x2 + 100; x4 = x2 + 200; y = 370; dy = 30; y -= dy; GfuiLabelCreate(scrHandle, "Simulation version:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0); GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x2, y, GFUI_ALIGN_HL_VB, 1, (void*)-1, ChangeSimuVersion, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x4, y, GFUI_ALIGN_HR_VB, 1, (void*)1, ChangeSimuVersion, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); SimuVersionId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, x3, y, GFUI_ALIGN_HC_VB, 32); GfuiLabelSetColor(scrHandle, SimuVersionId, LabelColor); GfuiButtonCreate(scrHandle, "Accept", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, SaveSimuVersion, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Cancel", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, prevMenu, GfuiScreenActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddKey(scrHandle, 13, "Save", NULL, SaveSimuVersion, NULL); GfuiAddKey(scrHandle, 27, "Cancel Selection", prevMenu, GfuiScreenActivate, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_F12, "Screen-Shot", NULL, GfuiScreenShot, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_LEFT, "Previous Version in list", (void*)0, ChangeSimuVersion, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_RIGHT, "Next Version in list", (void*)1, ChangeSimuVersion, NULL); ReadSimuCfg(); return scrHandle; }
int ReRacemanMenu(void) { char *str; void *params = ReInfo->params; if (racemanMenuHdle) { GfuiScreenRelease(racemanMenuHdle); } racemanMenuHdle = GfuiScreenCreateEx(NULL, NULL, (tfuiCallback)NULL, NULL, (tfuiCallback)NULL, 1); str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_BGIMG, 0); if (str) { GfuiScreenAddBgImg(racemanMenuHdle, str); } GfuiMenuDefaultKeysAdd(racemanMenuHdle); str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_NAME, 0); if (str) { GfuiTitleCreate(racemanMenuHdle, str, strlen(str)); } GfuiMenuButtonCreate(racemanMenuHdle, "New Race", "Start a New Race", NULL, ReStartNewRace); GfuiMenuButtonCreate(racemanMenuHdle, "Configure Race", "Configure The Race", NULL, reConfigureMenu); /* GfuiMenuButtonCreate(racemanMenuHdle, */ /* "Configure Players", "Players configuration menu", */ /* TorcsDriverMenuInit(racemanMenuHdle), GfuiScreenActivate); */ if (GfParmGetEltNb(params, RM_SECT_TRACKS) > 1) { GfuiMenuButtonCreate(racemanMenuHdle, "Load", "Load a Previously Saved Game", racemanMenuHdle, reLoadMenu); } GfuiMenuBackQuitButtonCreate(racemanMenuHdle, "Back to Main", "Return to previous Menu", ReInfo->_reMenuScreen, GfuiScreenActivate); GfuiScreenActivate(racemanMenuHdle); return RM_ASYNC | RM_NEXT_STEP; }
int ReNewTrackMenu(void) { void *params = ReInfo->params; void *results = ReInfo->results; if (newTrackMenuHdle) { GfuiScreenRelease(newTrackMenuHdle); } newTrackMenuHdle = GfuiScreenCreateEx(NULL, NULL, (tfuiCallback)NULL, NULL, (tfuiCallback)NULL, 1); const char* str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_BGIMG, 0); if (str) { GfuiScreenAddBgImg(newTrackMenuHdle, str); } str = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_NAME, ""); GfuiTitleCreate(newTrackMenuHdle, str, strlen(str)); GfuiMenuDefaultKeysAdd(newTrackMenuHdle); sprintf(buf, "Race Day #%d/%d on %s", (int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_TRACK, NULL, 1), GfParmGetEltNb(params, RM_SECT_TRACKS), ReInfo->track->name); GfuiLabelCreateEx(newTrackMenuHdle, buf, red, GFUI_FONT_MEDIUM_C, 320, 420, GFUI_ALIGN_HC_VB, 50); GfuiMenuButtonCreate(newTrackMenuHdle, "Start Event", "Start The Current Race", NULL, reStateManage); GfuiMenuButtonCreate(newTrackMenuHdle, "Abandon", "Abandon The Race", ReInfo->_reMenuScreen, GfuiScreenActivate); GfuiAddKey(newTrackMenuHdle, 27, "Abandon", ReInfo->_reMenuScreen, GfuiScreenActivate, NULL); GfuiScreenActivate(newTrackMenuHdle); return RM_ASYNC | RM_NEXT_STEP; }
void * JoyCalMenuInit(void *prevMenu, tCmdInfo *cmd, int maxcmd) { int x, y, dy, i, index; Cmd = cmd; maxCmd = maxcmd; if (scrHandle2) { return scrHandle2; } scrHandle2 = GfuiScreenCreateEx(NULL, NULL, onActivate, NULL, NULL, 1); GfuiTitleCreate(scrHandle2, "Joystick Calibration", 0); GfuiMenuDefaultKeysAdd(scrHandle2); GfuiScreenAddBgImg(scrHandle2, "data/img/splash-joycal.png"); x = 128; y = 300; dy = 50; for (i = 0; i < 4; i++) { GfuiLabelCreate(scrHandle2, LabName[i], GFUI_FONT_LARGE, x, y, GFUI_ALIGN_HC_VC, 0); LabAxisId[i] = GfuiLabelCreate(scrHandle2, " ", GFUI_FONT_MEDIUM, 2 * x, y, GFUI_ALIGN_HC_VC, 0); LabMinId[i] = GfuiLabelCreate(scrHandle2, " ", GFUI_FONT_MEDIUM, 3 * x, y, GFUI_ALIGN_HC_VC, 0); LabMaxId[i] = GfuiLabelCreate(scrHandle2, " ", GFUI_FONT_MEDIUM, 4 * x, y, GFUI_ALIGN_HC_VC, 0); y -= dy; } for (index = 0; index < NUM_JOY; index++) { if (js[index] == NULL) { js[index] = new jsJoystick(index); } if (js[index]->notWorking()) { /* don't configure the joystick */ js[index] = NULL; } } InstId = GfuiLabelCreate(scrHandle2, Instructions[0], GFUI_FONT_MEDIUM, 320, 80, GFUI_ALIGN_HC_VB, 60); GfuiButtonCreate(scrHandle2, "Back", GFUI_FONT_LARGE, 160, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, prevMenu, onBack, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle2, "Reset", GFUI_FONT_LARGE, 480, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, onActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); return scrHandle2; }
void * ReResScreenInit(void) { int i; int y, dy; static const char *title[3] = {"Practice", "Qualifications", "Race"}; if (reResScreenHdle) { GfuiScreenRelease(reResScreenHdle); } reResScreenHdle = GfuiScreenCreateEx(bgcolor, 0, reResScreenActivate, 0, reResScreenShutdown, 0); GfuiTitleCreate(reResScreenHdle, title[ReInfo->s->_raceType], strlen(title[ReInfo->s->_raceType])); const char* img = GfParmGetStr(ReInfo->params, RM_SECT_HEADER, RM_ATTR_RUNIMG, 0); if (img) { GfuiScreenAddBgImg(reResScreenHdle, img); } reAddResKeys(); reResTitleId = GfuiLabelCreateEx(reResScreenHdle, "", red, GFUI_FONT_LARGE_C, 320, 420, GFUI_ALIGN_HC_VB, 50); y = 400; dy = 378 / LINES; for (i = 0; i < LINES; i++) { FREEZ(reResMsg[i]); reResMsgClr[i] = 0; reResMsgId[i] = GfuiLabelCreateEx(reResScreenHdle, "", white, GFUI_FONT_MEDIUM_C, 20, y, GFUI_ALIGN_HL_VB, 120); y -= dy; } reCurLine = 0; return reResScreenHdle; }
/* * Function * TorcsMainMenuInit * * Description * init the main menus * * Parameters * none * * Return * 0 ok -1 nok * * Remarks * */ int TorcsMainMenuInit(void) { if (getTextOnly()) ReSinglePlayerInit(NULL); else { menuHandle = GfuiScreenCreateEx((float*)NULL, NULL, TorcsMainMenuActivate, NULL, (tfuiCallback)NULL, 1); GfuiScreenAddBgImg(menuHandle, "data/img/splash-main.png"); GfuiTitleCreate(menuHandle, "TORCS", 0); GfuiLabelCreate(menuHandle, "The Open Racing Car Simulator", GFUI_FONT_LARGE, 320, 420, GFUI_ALIGN_HC_VB, 0); GfuiMenuButtonCreate(menuHandle, "Race", "Races Menu", ReSinglePlayerInit(menuHandle), GfuiScreenActivate); GfuiMenuButtonCreate(menuHandle, "Configure Players", "Players configuration menu", TorcsDriverMenuInit(menuHandle), GfuiScreenActivate); GfuiMenuButtonCreate(menuHandle, "Options", "Configure", TorcsOptionOptionInit(menuHandle), GfuiScreenActivate); GfuiMenuDefaultKeysAdd(menuHandle); GfuiMenuBackQuitButtonCreate(menuHandle, "Quit", "Quit TORCS", TorcsMainExitMenuInit(menuHandle), GfuiScreenActivate); } return 0; }
static void rmtsUpdateTrackInfo(void) { if (!PCurTrack) return; // Update GUI with track info. // 0) Track category and name. GfuiLabelSetText(ScrHandle, CategoryEditId, PCurTrack->getCategoryName().c_str()); GfuiLabelSetText(ScrHandle, NameEditId, PCurTrack->getName().c_str()); // 1) Track description, optionally wrapped in 2 lines std::string strDescLine1, strDescLine2; rmtsWordWrap(PCurTrack->getDescription(), strDescLine1, strDescLine2, DescLinesMaxLen); GfuiLabelSetText(ScrHandle, DescLine1LabelId, strDescLine1.c_str()); GfuiLabelSetText(ScrHandle, DescLine2LabelId, strDescLine2.c_str()); // 2) Authors GfuiLabelSetText(ScrHandle, AuthorsLabelId, PCurTrack->getAuthors().c_str()); // 3) Width. std::ostringstream ossData; ossData << std::fixed << std::setprecision(0) << PCurTrack->getWidth() << " m"; GfuiLabelSetText(ScrHandle, WidthLabelId, ossData.str().c_str()); // 4) Length. ossData.str(""); ossData << PCurTrack->getLength() << " m"; GfuiLabelSetText(ScrHandle, LengthLabelId, ossData.str().c_str()); // 5) Max number of pits slots. ossData.str(""); if (PCurTrack->getMaxNumOfPitSlots()) ossData << PCurTrack->getMaxNumOfPitSlots(); else ossData << "None"; GfuiLabelSetText(ScrHandle, MaxPitsLabelId, ossData.str().c_str()); // 6) Outline image. GfuiStaticImageSet(ScrHandle, OutlineImageId, PCurTrack->getOutlineFile().c_str()); // 7) Preview image (background). GfuiScreenAddBgImg(ScrHandle, PCurTrack->getPreviewFile().c_str()); }
/** File selection @param vs Pointer on tRmFileSelect structure (cast to void) @return none */ void RmFileSelect(void *vs) { tFList *FileCur; rmFs = (tRmFileSelect*)vs; if (scrHandle) { GfuiScreenRelease(scrHandle); } scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, rmActivate, NULL, (tfuiCallback)NULL, 1); GfuiScreenAddBgImg(scrHandle, "data/img/splash-filesel.png"); GfuiTitleCreate(scrHandle, rmFs->title, 0); /* Scroll List containing the File list */ fileScrollList = GfuiScrollListCreate(scrHandle, GFUI_FONT_MEDIUM_C, 120, 80, GFUI_ALIGN_HC_VB, 400, 310, GFUI_SB_RIGHT, NULL, rmClickOnFile); FileList = GfDirGetList(rmFs->path); if (FileList == NULL) { GfuiScreenActivate(rmFs->prevScreen); return; } FileSelected = FileList; FileCur = FileList; do { FileCur = FileCur->next; GfuiScrollListInsertElement(scrHandle, fileScrollList, FileCur->name, 1000, (void*)FileCur); } while (FileCur != FileList); /* Bottom buttons */ GfuiButtonCreate(scrHandle, "Select", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, rmSelect, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Cancel", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, rmDeactivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); /* Default menu keyboard actions */ GfuiMenuDefaultKeysAdd(scrHandle); GfuiScreenActivate(scrHandle); }
/* * Function * TorcsMainMenuInit * * Description * init the main menus * * Parameters * none * * Return * 0 ok -1 nok * * Remarks * */ int TorcsMainMenuInit(void) { menuHandle = GfuiScreenCreateEx((float*)NULL, NULL, TorcsMainMenuActivate, NULL, (tfuiCallback)NULL, 1); GfuiScreenAddBgImg(menuHandle, "data/img/splash-main.png"); GfuiTitleCreate(menuHandle, "TORCS Adaptive", 0); GfuiLabelCreate(menuHandle, "A TORCS Modification with procedural tracks", GFUI_FONT_LARGE, 320, 420, GFUI_ALIGN_HC_VB, 0); GfuiMenuButtonCreate(menuHandle, "Race", "Races Menu", ReSinglePlayerInit(menuHandle), GfuiScreenActivate); GfuiMenuButtonCreate(menuHandle, "Configure Players", "Players configuration menu", TorcsDriverMenuInit(menuHandle), GfuiScreenActivate); GfuiMenuButtonCreate(menuHandle, "Options", "Configure", TorcsOptionOptionInit(menuHandle), GfuiScreenActivate); GfuiMenuDefaultKeysAdd(menuHandle); GfuiMenuBackQuitButtonCreate(menuHandle, "Quit", "Quit TORCS", TorcsMainExitMenuInit(menuHandle), GfuiScreenActivate); return 0; }
/** @ingroup racemantools @param title Screen title. @param bgimg Optionnal backgrounf image (0 for no img). @return None. */ void RmLoadingScreenStart(char *title, char *bgimg) { int i; int y; if (GfuiScreenIsActive(menuHandle)) { /* Already active */ return; } if (menuHandle) { GfuiScreenRelease(menuHandle); } menuHandle = GfuiScreenCreateEx(black, NULL, NULL, NULL, rmDeativate, 0); GfuiTitleCreate(menuHandle, title, strlen(title)); /* create 20 lines of text */ for (i = 0, y = 400; i < TEXTLINES; i++, y -= 16) { white[i][0] = white[i][1] = white[i][2] = 1.0; white[i][3] = (float)i * 0.0421 + 0.2; rmTextId[i] = GfuiLabelCreateEx(menuHandle, "", white[i], GFUI_FONT_MEDIUM_C, 60, y, GFUI_ALIGN_HL_VB, 100); if (rmTextLines[i]) { /* free old text */ free(rmTextLines[i]); rmTextLines[i] = NULL; } } rmCurText = 0; if (bgimg) { GfuiScreenAddBgImg(menuHandle, bgimg); } GfuiScreenActivate(menuHandle); GfuiDisplay(); }
void * TorcsOptionOptionInit(void *precMenu) { if (optionHandle) return optionHandle; optionHandle = GfuiMenuScreenCreate("OPTIONS"); GfuiScreenAddBgImg(optionHandle, "data/img/splash-options.png"); GfuiMenuButtonCreate(optionHandle, "Graphic", "Configure graphic parameters", GraphMenuInit(optionHandle), GfuiScreenActivate); GfuiMenuButtonCreate(optionHandle, "Display", "Configure display parameters", GfScrMenuInit(optionHandle), GfuiScreenActivate); /* GfuiMenuButtonCreate(optionHandle, "Simulation", "Configure simulation parameters", SimuMenuInit(optionHandle), GfuiScreenActivate); */ GfuiMenuButtonCreate(optionHandle, "Sound", "Configure sound parameters", SoundMenuInit(optionHandle), GfuiScreenActivate); GfuiMenuButtonCreate(optionHandle, "OpenGL", "Configure OpenGL parameters", OpenGLMenuInit(optionHandle), GfuiScreenActivate); GfuiMenuBackQuitButtonCreate(optionHandle, "Back", "Back to Main", precMenu, GfuiScreenActivate); return optionHandle; }
void * exitMenuInit(void *menu, void *menuHandle) { if (menuHandle) { GfuiScreenRelease(menuHandle); } menuHandle = GfuiMenuScreenCreate("Quit ?"); GfuiScreenAddBgImg(menuHandle, "data/img/splash-quit.png"); GfuiMenuButtonCreate(menuHandle, "No, Back to Game", "Return to TORCS", menu, GfuiScreenActivate); GfuiMenuButtonCreate(menuHandle, "Yes, Let's Quit", "Exit of TORCS", NULL, endofprog); return menuHandle; }
/** Interactive track selection @param vs Pointer on a tRmTrackSelect structure (cast to void *) @warning The race manager's parameters are updated but not saved. @ingroup racemantools */ void RmTrackSelect(void *vs) { const char *defaultTrack; const char *defaultCategory; tFList *CatCur; tFList *TrList, *TrCur; int Xpos, Ypos, DX, DY; int curTrkIdx; const int BUFSIZE = 1024; char buf[BUFSIZE]; char path[BUFSIZE]; ts = (tRmTrackSelect*)vs; /* Get the list of categories directories */ CategoryList = GfDirGetList("tracks"); if (CategoryList == NULL) { GfTrace("RmTrackSelect: No track category available\n"); return; } CatCur = CategoryList; do { CatCur->dispName = RmGetCategoryName(CatCur->name); if (strlen(CatCur->dispName) == 0) { GfTrace("RmTrackSelect: No definition for track category %s\n", CatCur->name); return; } /* get the tracks in the category directory */ snprintf(buf, BUFSIZE, "tracks/%s", CatCur->name); TrList = GfDirGetList(buf); if (TrList == NULL) { GfTrace("RmTrackSelect: No track for category %s available\n", CatCur->name); return; } TrList = TrList->next; /* get the first one */ CatCur->userData = (void*)TrList; TrCur = TrList; do { TrCur->dispName = RmGetTrackName(CatCur->name, TrCur->name); if (strlen(TrCur->dispName) == 0) { GfTrace("RmTrackSelect: No definition for track %s\n", TrCur->name); return; } TrCur = TrCur->next; } while (TrCur != TrList); CatCur = CatCur->next; } while (CatCur != CategoryList); curTrkIdx = (int)GfParmGetNum(ts->param, RM_SECT_TRACKS, RE_ATTR_CUR_TRACK, NULL, 1); snprintf(path, BUFSIZE, "%s/%d", RM_SECT_TRACKS, curTrkIdx); defaultCategory = GfParmGetStr(ts->param, path, RM_ATTR_CATEGORY, CategoryList->name); /* XXX coherency check */ defaultTrack = GfParmGetStr(ts->param, path, RM_ATTR_NAME, ((tFList*)CategoryList->userData)->name); CatCur = CategoryList; do { if (strcmp(CatCur->name, defaultCategory) == 0) { CategoryList = CatCur; TrCur = (tFList*)(CatCur->userData); do { if (strcmp(TrCur->name, defaultTrack) == 0) { CatCur->userData = (void*)TrCur; break; } TrCur = TrCur->next; } while (TrCur != TrList); break; } CatCur = CatCur->next; } while (CatCur != CategoryList); scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, rmtsActivate, NULL, (tfuiCallback)NULL, 1); GfuiScreenAddBgImg(scrHandle, "data/img/splash-qrtrk.png"); rmtsAddKeys(); GfuiTitleCreate(scrHandle, "Select Track", 0); GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", 80, 400, GFUI_ALIGN_HC_VB, 0, (void*)0, rmCatPrevNext, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); CatLabelId = GfuiLabelCreate(scrHandle, CategoryList->dispName, GFUI_FONT_LARGE_C, 320, 400, GFUI_ALIGN_HC_VB, 30); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", 540, 400, GFUI_ALIGN_HC_VB, 0, (void*)1, rmCatPrevNext, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", 80, 370, GFUI_ALIGN_HC_VB, 0, (void*)0, rmtsPrevNext, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); TrackLabelId = GfuiLabelCreate(scrHandle, ((tFList*)CategoryList->userData)->dispName, GFUI_FONT_LARGE_C, 320, 370, GFUI_ALIGN_HC_VB, 30); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", 540, 370, GFUI_ALIGN_HC_VB, 0, (void*)1, rmtsPrevNext, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); MapId = GfuiStaticImageCreate(scrHandle, 320, 100, 260, 195, rmGetMapName(buf, BUFSIZE)); GfuiButtonCreate(scrHandle, "Accept", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, rmtsSelect, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Back", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, ts->prevScreen, rmtsDeactivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); Xpos = 20; Ypos = 320; DX = 110; DY = 30; GfuiLabelCreate(scrHandle, "Description:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); DescId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 50); Ypos -= DY; GfuiLabelCreate(scrHandle, "Author:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); AuthorId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 20); Ypos -= DY; GfuiLabelCreate(scrHandle, "Length:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); LengthId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 20); Ypos -= DY; GfuiLabelCreate(scrHandle, "Width:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); WidthId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 20); Ypos -= DY; GfuiLabelCreate(scrHandle, "Pits:", GFUI_FONT_MEDIUM, Xpos, Ypos, GFUI_ALIGN_HL_VB, 0); PitsId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, Xpos + DX, Ypos, GFUI_ALIGN_HL_VB, 20); rmUpdateTrackInfo(); GfuiScreenActivate(scrHandle); }
static void rmRaceResults(void *prevHdle, tRmInfo *info, int start) { void *results = info->results; const char *race = info->_reRaceName; int i; int x1, x2, x3, x4, x5, x6, x7, x8, x9; int dlap; int y; const int BUFSIZE = 1024; char buf[BUFSIZE]; char path[BUFSIZE]; const int TIMEFMTSIZE = 256; char timefmt[TIMEFMTSIZE]; float fgcolor[4] = {1.0, 0.0, 1.0, 1.0}; int laps, totLaps; tdble refTime; int nbCars; rmScrHdle = GfuiScreenCreate(); snprintf(buf, BUFSIZE, "Race Results"); GfuiTitleCreate(rmScrHdle, buf, strlen(buf)); snprintf(buf, BUFSIZE, "%s", info->track->name); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_LARGE_C, 320, 420, GFUI_ALIGN_HC_VB, 0); GfuiScreenAddBgImg(rmScrHdle, "data/img/splash-result.png"); x1 = 30; x2 = 60; x3 = 260; x4 = 330; x5 = 360; x6 = 420; x7 = 490; x8 = 545; x9 = 630; y = 400; GfuiLabelCreateEx(rmScrHdle, "Rank", fgcolor, GFUI_FONT_MEDIUM_C, x1, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Driver", fgcolor, GFUI_FONT_MEDIUM_C, x2+10, y, GFUI_ALIGN_HL_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Total", fgcolor, GFUI_FONT_MEDIUM_C, x3, y, GFUI_ALIGN_HR_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Best", fgcolor, GFUI_FONT_MEDIUM_C, x4, y, GFUI_ALIGN_HR_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Laps", fgcolor, GFUI_FONT_MEDIUM_C, x5, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Top Spd", fgcolor, GFUI_FONT_MEDIUM_C, x6, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Damage", fgcolor, GFUI_FONT_MEDIUM_C, x7, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Pit", fgcolor, GFUI_FONT_MEDIUM_C, x8, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Penalty", fgcolor, GFUI_FONT_MEDIUM_C, x9, y, GFUI_ALIGN_HR_VB, 0); y -= 20; snprintf(path, BUFSIZE, "%s/%s/%s", info->track->name, RE_SECT_RESULTS, race); totLaps = (int)GfParmGetNum(results, path, RE_ATTR_LAPS, NULL, 0); snprintf(path, BUFSIZE, "%s/%s/%s/%s/%d", info->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK, 1); refTime = GfParmGetNum(results, path, RE_ATTR_TIME, NULL, 0); snprintf(path, BUFSIZE, "%s/%s/%s/%s", info->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK); nbCars = (int)GfParmGetEltNb(results, path); for (i = start; i < MIN(start + MAX_LINES, nbCars); i++) { snprintf(path, BUFSIZE, "%s/%s/%s/%s/%d", info->track->name, RE_SECT_RESULTS, race, RE_SECT_RANK, i + 1); laps = (int)GfParmGetNum(results, path, RE_ATTR_LAPS, NULL, 0); snprintf(buf, BUFSIZE, "%d", i+1); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x1, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreate(rmScrHdle, GfParmGetStr(results, path, RE_ATTR_NAME, ""), GFUI_FONT_MEDIUM_C, x2, y, GFUI_ALIGN_HL_VB, 0); if (laps == totLaps) { if (i == 0) { GfTime2Str(timefmt, TIMEFMTSIZE, GfParmGetNum(results, path, RE_ATTR_TIME, NULL, 0), 0); } else { GfTime2Str(timefmt, TIMEFMTSIZE, GfParmGetNum(results, path, RE_ATTR_TIME, NULL, 0) - refTime, 1); } GfuiLabelCreate(rmScrHdle, timefmt, GFUI_FONT_MEDIUM_C, x3, y, GFUI_ALIGN_HR_VB, 0); } else { dlap = totLaps - laps; if (dlap == 1) { snprintf(buf, BUFSIZE, "+1 Lap"); } else { snprintf(buf, BUFSIZE, "+%d Laps", dlap); } GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x3, y, GFUI_ALIGN_HR_VB, 0); } GfTime2Str(timefmt, TIMEFMTSIZE, GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), 0); GfuiLabelCreate(rmScrHdle, timefmt, GFUI_FONT_MEDIUM_C, x4, y, GFUI_ALIGN_HR_VB, 0); snprintf(buf, BUFSIZE, "%d", laps); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x5, y, GFUI_ALIGN_HC_VB, 0); snprintf(buf, BUFSIZE, "%d", (int)(GfParmGetNum(results, path, RE_ATTR_TOP_SPEED, NULL, 0) * 3.6)); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x6, y, GFUI_ALIGN_HC_VB, 0); snprintf(buf, BUFSIZE, "%d", (int)(GfParmGetNum(results, path, RE_ATTR_DAMMAGES, NULL, 0))); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x7, y, GFUI_ALIGN_HC_VB, 0); snprintf(buf, BUFSIZE, "%d", (int)(GfParmGetNum(results, path, RE_ATTR_NB_PIT_STOPS, NULL, 0))); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x8, y, GFUI_ALIGN_HC_VB, 0); GfTime2Str(timefmt, TIMEFMTSIZE, GfParmGetNum(results, path, RE_ATTR_PENALTYTIME, NULL, 0), 0); GfuiLabelCreate(rmScrHdle, timefmt, GFUI_FONT_MEDIUM_C, x9, y, GFUI_ALIGN_HR_VB, 0); y -= 15; } if (start > 0) { RmPrevRace.prevHdle = prevHdle; RmPrevRace.info = info; RmPrevRace.start = start - MAX_LINES; GfuiGrButtonCreate(rmScrHdle, "data/img/arrow-up.png", "data/img/arrow-up.png", "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", 80, 40, GFUI_ALIGN_HL_VB, 1, (void*)&RmPrevRace, rmChgRaceScreen, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_PAGE_UP, "Previous Results", (void*)&RmPrevRace, rmChgRaceScreen, NULL); } GfuiButtonCreate(rmScrHdle, "Continue", GFUI_FONT_LARGE, /* 210, */ 320, 40, 150, GFUI_ALIGN_HC_VB, 0, prevHdle, GfuiScreenReplace, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); if (i < nbCars) { RmNextRace.prevHdle = prevHdle; RmNextRace.info = info; RmNextRace.start = start + MAX_LINES; GfuiGrButtonCreate(rmScrHdle, "data/img/arrow-down.png", "data/img/arrow-down.png", "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", 540, 40, GFUI_ALIGN_HL_VB, 1, (void*)&RmNextRace, rmChgRaceScreen, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_PAGE_DOWN, "Next Results", (void*)&RmNextRace, rmChgRaceScreen, NULL); } GfuiAddKey(rmScrHdle, (unsigned char)27, "", prevHdle, GfuiScreenReplace, NULL); GfuiAddKey(rmScrHdle, (unsigned char)13, "", prevHdle, GfuiScreenReplace, NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_F12, "Take a Screen Shot", NULL, GfuiScreenShot, NULL); GfuiScreenActivate(rmScrHdle); }
void* RmResScreenInit() { if (rmResScreenHdle) GfuiScreenRelease(rmResScreenHdle); tRmInfo* reInfo = LmRaceEngine().inData(); // Create screen, load menu XML descriptor and create static controls. rmResScreenHdle = GfuiScreenCreate(black, 0, rmResScreenActivate, 0, rmResScreenDeactivate, 0); void *hmenu = GfuiMenuLoad("raceblindscreen.xml"); GfuiMenuCreateStaticControls(rmResScreenHdle, hmenu); // Create variable main title (race session) label. rmResTitleId = GfuiMenuCreateLabelControl(rmResScreenHdle, hmenu, "Title"); // Create background image if any specified. const char* img = GfParmGetStr(reInfo->params, RM_SECT_HEADER, RM_ATTR_RUNIMG, 0); if (img) GfuiScreenAddBgImg(rmResScreenHdle, img); // Create variable subtitle (driver and race name, lap number) label. rmResSubTitleId = GfuiMenuCreateLabelControl(rmResScreenHdle, hmenu, "SubTitle"); // Create table header label. rmResHeaderId = GfuiMenuCreateLabelControl(rmResScreenHdle, hmenu, "Header"); // Get layout properties, except for nMaxResultRows (see below). const int yTopRow = (int)GfuiMenuGetNumProperty(hmenu, "yTopRow", 400); const int yRowShift = (int)GfuiMenuGetNumProperty(hmenu, "yRowShift", 20); // Allocate row info arrays, if not already done. if (!rmResRowLabelId) { // Load nMaxResultRows/colors only the first time (ignore any later change, // otherwize, we'd have to realloc the row info arrays). rmNMaxResRows = (int)GfuiMenuGetNumProperty(hmenu, "nMaxResultRows", 20); const GfuiColor cNormal = GfuiColor::build(GfuiMenuGetStrProperty(hmenu, "rowColorNormal", "0x0000FF")); const GfuiColor cHighlighted = GfuiColor::build(GfuiMenuGetStrProperty(hmenu, "rowColorHighlighted", "0x00FF00")); memcpy(rmColors[0], cNormal.toFloatRGBA(), sizeof(rmColors[0])); memcpy(rmColors[1], cHighlighted.toFloatRGBA(), sizeof(rmColors[1])); rmResRowLabelId = (int*)calloc(rmNMaxResRows, sizeof(int)); rmResRowText = (char**)calloc(rmNMaxResRows, sizeof(char*)); rmResRowColor = (float**)calloc(rmNMaxResRows, sizeof(float*)); } // Create result rows (1 label for each). int y = yTopRow; for (int i = 0; i < rmNMaxResRows; i++) { freez(rmResRowText[i]); rmResRowColor[i] = rmColors[0]; rmResRowLabelId[i] = GfuiMenuCreateLabelControl(rmResScreenHdle, hmenu, "Row", true, // from template "", GFUI_TPL_X, y, GFUI_TPL_FONTID, GFUI_TPL_WIDTH, GFUI_TPL_ALIGN, GFUI_TPL_MAXLEN, rmResRowColor[i]); y -= yRowShift; } // Close menu XML descriptor. GfParmReleaseHandle(hmenu); // Register keyboard shortcuts. GfuiAddKey(rmResScreenHdle, GFUIK_F1, "Help", rmResScreenHdle, GfuiHelpScreen, NULL); GfuiAddKey(rmResScreenHdle, GFUIK_F12, "Screen shot", NULL, GfuiScreenShot, NULL); GfuiAddKey(rmResScreenHdle, GFUIK_ESCAPE, "Stop current race", (void*)RE_STATE_RACE_STOP, rmApplyState, NULL); GfuiAddKey(rmResScreenHdle, 'q', GFUIM_ALT, "Quit game now, save nothing", (void*)RE_STATE_EXIT, rmApplyState, NULL); // Initialize current result row. rmCurRowIndex = 0; return rmResScreenHdle; }
/** Interactive Drivers list selection @param vs Pointer on tRmDrvSelect structure (cast to void) @warning The race manager params are modified but not saved. */ void RmDriversSelect(void *vs) { tModList *list; tModList *curmod; char dname[256]; char *sp; char *cardllname; int i, index; tDrvElt *curDrv; int nCars, robotIdx; void *robhdle; struct stat st; char *carName; void *carhdle; int human; #define B_BASE 380 #define B_HT 30 ds = (tRmDrvSelect*)vs; GF_TAILQ_INIT(&DrvList); scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, rmdsActivate, NULL, (tfuiCallback)NULL, 1); GfuiScreenAddBgImg(scrHandle, "data/img/splash-qrdrv.png"); GfuiTitleCreate(scrHandle, "Select Drivers", sizeof("Select Drivers")); GfuiLabelCreate(scrHandle, "Selected", GFUI_FONT_LARGE, 120, 400, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreate(scrHandle, "Not Selected", GFUI_FONT_LARGE, 496, 400, GFUI_ALIGN_HC_VB, 0); selectedScrollList = GfuiScrollListCreate(scrHandle, GFUI_FONT_MEDIUM_C, 20, 80, GFUI_ALIGN_HL_VB, 200, 310, GFUI_SB_RIGHT, NULL, rmdsClickOnDriver); unselectedScrollList = GfuiScrollListCreate(scrHandle, GFUI_FONT_MEDIUM_C, 396, 80, GFUI_ALIGN_HL_VB, 200, 310, GFUI_SB_RIGHT, NULL, rmdsClickOnDriver); GfuiButtonCreate(scrHandle, "Accept", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, rmdsSelect, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Cancel", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, ds->prevScreen, rmdsDeactivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Move Up", GFUI_FONT_MEDIUM, 320, B_BASE, 100, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, (void*)-1, rmMove, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Move Down", GFUI_FONT_MEDIUM, 320, B_BASE - B_HT, 100, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, (void*)1, rmMove, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "(De)Select", GFUI_FONT_MEDIUM, 320, B_BASE - 2 * B_HT, 100, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, (void*)0, rmSelectDeselect, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Set Focus", GFUI_FONT_MEDIUM, 320, B_BASE - 3 * B_HT, 100, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, rmdsSetFocus, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); list = (tModList *)NULL; sprintf(buf, "%sdrivers", GetLibDir ()); GfModInfoDir(CAR_IDENT, buf, 1, &list); curmod = list; if (curmod != NULL) { do { curmod = curmod->next; for (i = 0; i < MAX_MOD_ITF; i++) { if (curmod->modInfo[i].name) { sp = strrchr(curmod->sopath, '/'); if (sp == NULL) { sp = curmod->sopath; } else { sp++; } strcpy(dname, sp); dname[strlen(dname) - strlen(DLLEXT) - 1] = 0; /* cut .so or .dll */ sprintf(buf, "%sdrivers/%s/%s.xml", GetLocalDir(), dname, dname); robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD); if (!robhdle) { sprintf(buf, "drivers/%s/%s.xml", dname, dname); robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD); } sprintf(path, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, curmod->modInfo[i].index); carName = GfParmGetStr(robhdle, path, ROB_ATTR_CAR, ""); if (strcmp(GfParmGetStr(robhdle, path, ROB_ATTR_TYPE, ROB_VAL_ROBOT), ROB_VAL_ROBOT)) { human = 1; } else { human = 0; } sprintf(path, "cars/%s/%s.xml", carName, carName); if (!stat(path, &st)) { carhdle = GfParmReadFile(path, GFPARM_RMODE_STD); if (carhdle) { curDrv = (tDrvElt*)calloc(1, sizeof(tDrvElt)); curDrv->index = curmod->modInfo[i].index; curDrv->dname = strdup(dname); curDrv->name = strdup(curmod->modInfo[i].name); curDrv->car = carhdle; if (human) { curDrv->human = 1; GF_TAILQ_INSERT_HEAD(&DrvList, curDrv, link); } else { curDrv->human = 0; GF_TAILQ_INSERT_TAIL(&DrvList, curDrv, link); } } else { GfOut("Driver %s not selected because car %s is not readable\n", curmod->modInfo[i].name, carName); } } else { GfOut("Driver %s not selected because car %s is not present\n", curmod->modInfo[i].name, carName); } GfParmReleaseHandle(robhdle); } } } while (curmod != list); } nbSelectedDrivers = 0; nbMaxSelectedDrivers = (int)GfParmGetNum(ds->param, RM_SECT_DRIVERS, RM_ATTR_MAXNUM, NULL, 0); nCars = GfParmGetEltNb(ds->param, RM_SECT_DRIVERS); index = 1; for (i = 1; i < nCars+1; i++) { sprintf(dname, "%s/%d", RM_SECT_DRIVERS, i); cardllname = GfParmGetStr(ds->param, dname, RM_ATTR_MODULE, ""); robotIdx = (int)GfParmGetNum(ds->param, dname, RM_ATTR_IDX, (char*)NULL, 0); curDrv = GF_TAILQ_FIRST(&DrvList); if (curDrv != NULL) { do { if ((curDrv->index == robotIdx) && (strcmp(curDrv->dname, cardllname) == 0)) { if (nbSelectedDrivers < nbMaxSelectedDrivers) { GfuiScrollListInsertElement(scrHandle, selectedScrollList, curDrv->name, index, (void*)curDrv); curDrv->sel = index++; nbSelectedDrivers++; } break; } } while ((curDrv = GF_TAILQ_NEXT(curDrv, link)) != NULL); } } curDrv = GF_TAILQ_FIRST(&DrvList); if (curDrv != NULL) { do { if (curDrv->sel == 0) { GfuiScrollListInsertElement(scrHandle, unselectedScrollList, curDrv->name, 1000, (void*)curDrv); } } while ((curDrv = GF_TAILQ_NEXT(curDrv, link)) != NULL); } GfuiLabelCreate(scrHandle, "Focused:", GFUI_FONT_MEDIUM, 320, B_BASE - 5 * B_HT, GFUI_ALIGN_HC_VB, 0); cardllname = GfParmGetStr(ds->param, RM_SECT_DRIVERS, RM_ATTR_FOCUSED, ""); robotIdx = (int)GfParmGetNum(ds->param, RM_SECT_DRIVERS, RM_ATTR_FOCUSEDIDX, (char*)NULL, 0); curDrv = GF_TAILQ_FIRST(&DrvList); if (curDrv != NULL) { do { if ((curDrv->index == robotIdx) && (strcmp(curDrv->dname, cardllname) == 0)) { break; } } while ((curDrv = GF_TAILQ_NEXT(curDrv, link)) != NULL); } if (curDrv == NULL) { curDrv = GF_TAILQ_FIRST(&DrvList); } if (curDrv == NULL) { FocDrvLabelId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, 320, B_BASE - 5 * B_HT - GfuiFontHeight(GFUI_FONT_MEDIUM), GFUI_ALIGN_HC_VB, 256); } else { FocDrvLabelId = GfuiLabelCreate(scrHandle, curDrv->name, GFUI_FONT_MEDIUM_C, 320, B_BASE - 5 * B_HT - GfuiFontHeight(GFUI_FONT_MEDIUM), GFUI_ALIGN_HC_VB, 256); } /* Picked Driver Info */ GfuiLabelCreate(scrHandle, "Driver:", GFUI_FONT_MEDIUM, 320, B_BASE - 7 * B_HT, GFUI_ALIGN_HC_VB, 0); PickDrvNameLabelId = GfuiLabelCreateEx(scrHandle, "", aColor, GFUI_FONT_MEDIUM_C, 320, B_BASE - 7 * B_HT - GfuiFontHeight(GFUI_FONT_MEDIUM), GFUI_ALIGN_HC_VB, 256); GfuiLabelCreate(scrHandle, "Car:", GFUI_FONT_MEDIUM, 320, B_BASE - 8 * B_HT, GFUI_ALIGN_HC_VB, 0); PickDrvCarLabelId = GfuiLabelCreateEx(scrHandle, "", aColor, GFUI_FONT_MEDIUM_C, 320, B_BASE - 8 * B_HT - GfuiFontHeight(GFUI_FONT_MEDIUM), GFUI_ALIGN_HC_VB, 256); GfuiLabelCreate(scrHandle, "Category:", GFUI_FONT_MEDIUM, 320, B_BASE - 9 * B_HT, GFUI_ALIGN_HC_VB, 0); PickDrvCategoryLabelId = GfuiLabelCreateEx(scrHandle, "", aColor, GFUI_FONT_MEDIUM_C, 320, B_BASE - 9 * B_HT - GfuiFontHeight(GFUI_FONT_MEDIUM), GFUI_ALIGN_HC_VB, 256); GfuiMenuDefaultKeysAdd(scrHandle); rmdsAddKeys(); GfuiScreenActivate(scrHandle); }
void RmNextEventMenu(void) { char buf[128]; tRmInfo* reInfo = LmRaceEngine().inData(); void *params = reInfo->params; void *results = reInfo->results; int raceNumber; int xx; if (rmScrHandle) { GfuiScreenRelease(rmScrHandle); } GfLogTrace("Entering Next Event menu\n"); // Create screen, load menu XML descriptor and create static controls. rmScrHandle = GfuiScreenCreate(NULL, NULL, (tfuiCallback)NULL, NULL, (tfuiCallback)NULL, 1); void *menuXMLDescHdle = GfuiMenuLoad("racenexteventmenu.xml"); GfuiMenuCreateStaticControls(rmScrHandle, menuXMLDescHdle); // Create background image from race params. const char* pszBGImg = GfParmGetStr(params, RM_SECT_HEADER, RM_ATTR_BGIMG, 0); if (pszBGImg) { GfuiScreenAddBgImg(rmScrHandle, pszBGImg); } // Create variable title label from race params. int titleId = GfuiMenuCreateLabelControl(rmScrHandle, menuXMLDescHdle, "TitleLabel"); char pszTitle[128]; if (LmRaceEngine().race()->getManager()->hasSubFiles()) { const char* pszGroup = GfParmGetStr(reInfo->params, RM_SECT_HEADER, RM_ATTR_NAME, "<no group>"); snprintf(pszTitle, sizeof(pszTitle), "%s - %s", reInfo->_reName, pszGroup); } else snprintf(pszTitle, sizeof(pszTitle), "%s", reInfo->_reName); GfuiLabelSetText(rmScrHandle, titleId, pszTitle); // Calculate which race of the series this is raceNumber = 1; for (xx = 1; xx < (int)GfParmGetNum(results, RE_SECT_CURRENT, RE_ATTR_CUR_TRACK, NULL, 1); ++xx) { snprintf(buf, sizeof(buf), "%s/%d", RM_SECT_TRACKS, xx); if (!strcmp( GfParmGetStr(reInfo->params, buf, RM_ATTR_NAME, "free"), "free") == 0) ++raceNumber; } // Create variable subtitle label from race params. snprintf(buf, sizeof(buf), "Race Day #%d/%d at %s", raceNumber, (int)GfParmGetNum(params, RM_SECT_TRACKS, RM_ATTR_NUMBER, NULL, -1 ) >= 0 ? (int)GfParmGetNum(params, RM_SECT_TRACKS, RM_ATTR_NUMBER, NULL, -1 ) : GfParmGetEltNb(params, RM_SECT_TRACKS), reInfo->track->name); int subTitleId = GfuiMenuCreateLabelControl(rmScrHandle, menuXMLDescHdle, "SubTitleLabel"); GfuiLabelSetText(rmScrHandle, subTitleId, buf); // Create Start and Abandon buttons. GfuiMenuCreateButtonControl(rmScrHandle, menuXMLDescHdle, "StartButton", NULL, rmStateManage); GfuiMenuCreateButtonControl(rmScrHandle, menuXMLDescHdle, "AbandonButton", RmRaceSelectMenuHandle, GfuiScreenActivate); // Close menu XML descriptor. GfParmReleaseHandle(menuXMLDescHdle); // Register keyboard shortcuts. GfuiMenuDefaultKeysAdd(rmScrHandle); GfuiAddKey(rmScrHandle, GFUIK_RETURN, "Start Event", NULL, rmStateManage, NULL); GfuiAddKey(rmScrHandle, GFUIK_ESCAPE, "Abandon", RmRaceSelectMenuHandle, GfuiScreenActivate, NULL); // Activate screen. GfuiScreenActivate(rmScrHandle); }
void * GraphMenuInit(void *prevMenu) { int x, y, x2, dy; /* screen already created */ if (scrHandle) { return scrHandle; } scrHandle = GfuiMenuScreenCreate("Graphic Configuration"); GfuiScreenAddBgImg(scrHandle, "data/img/splash-graphconf.png"); sprintf(buf, "%s%s", GetLocalDir(), GR_PARAM_FILE); void * grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT); x = 50; x2 = 200; y = 370; dy = 30; GfuiLabelCreate(scrHandle, "Visibility (%):", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0); FovFactorValue = (int)GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_FOVFACT, "%", 100.0); sprintf(buf, "%d", FovFactorValue); FovEditId = GfuiEditboxCreate(scrHandle, buf, GFUI_FONT_MEDIUM_C, x2+10, y, 100, 16, NULL, (tfuiCallback)NULL, ChangeFov); y -= dy; GfuiLabelCreate(scrHandle, "Smoke:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0); SmokeValue = (int)GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_SMOKENB, NULL, 300.0); sprintf(buf, "%d", SmokeValue); SmokeEditId = GfuiEditboxCreate(scrHandle, buf, GFUI_FONT_MEDIUM_C, x2+10, y, 100, 16, NULL, (tfuiCallback)NULL, ChangeSmoke); y -= dy; GfuiLabelCreate(scrHandle, "Skid Marks:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0); SkidValue = (int)GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_MAXSTRIPBYWHEEL, NULL, 20.0); sprintf(buf, "%d", SkidValue); SkidEditId = GfuiEditboxCreate(scrHandle, buf, GFUI_FONT_MEDIUM_C, x2+10, y, 100, 16, NULL, (tfuiCallback)NULL, ChangeSkid); y -= dy; GfuiLabelCreate(scrHandle, "LOD factor:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0); LodFactorValue = GfParmGetNum(grHandle, GR_SCT_GRAPHIC, GR_ATT_LODFACTOR, NULL, 1.0); sprintf(buf, "%g", LodFactorValue); LodFactorEditId = GfuiEditboxCreate(scrHandle, buf, GFUI_FONT_MEDIUM_C, x2+10, y, 100, 16, NULL, (tfuiCallback)NULL, ChangeLodFactor); GfuiButtonCreate(scrHandle, "Accept", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, prevMenu, SaveGraphicOptions, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Cancel", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, prevMenu, GfuiScreenActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddKey(scrHandle, 27, "Cancel", prevMenu, GfuiScreenActivate, NULL); GfParmReleaseHandle(grHandle); return scrHandle; }
static void rmShowStandings(void *prevHdle, tRmInfo *info, int start) { int i; int x1, x2, x3; int y; const int BUFSIZE = 1024; char buf[BUFSIZE]; char path[BUFSIZE]; float fgcolor[4] = {1.0, 0.0, 1.0, 1.0}; int nbCars; int offset; void *results = info->results; const char *race = info->_reRaceName; rmScrHdle = GfuiScreenCreate(); snprintf(buf, BUFSIZE, "%s Results", race); GfuiTitleCreate(rmScrHdle, buf, strlen(buf)); GfuiScreenAddBgImg(rmScrHdle, "data/img/splash-result.png"); offset = 200; x1 = offset + 30; x2 = offset + 60; x3 = offset + 240; y = 400; GfuiLabelCreateEx(rmScrHdle, "Rank", fgcolor, GFUI_FONT_MEDIUM_C, x1, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Driver", fgcolor, GFUI_FONT_MEDIUM_C, x2+10, y, GFUI_ALIGN_HL_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Points", fgcolor, GFUI_FONT_MEDIUM_C, x3, y, GFUI_ALIGN_HR_VB, 0); y -= 20; nbCars = (int)GfParmGetEltNb(results, RE_SECT_STANDINGS); for (i = start; i < MIN(start + MAX_LINES, nbCars); i++) { snprintf(path, BUFSIZE, "%s/%d", RE_SECT_STANDINGS, i + 1); snprintf(buf, BUFSIZE, "%d", i+1); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x1, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreate(rmScrHdle, GfParmGetStr(results, path, RE_ATTR_NAME, ""), GFUI_FONT_MEDIUM_C, x2, y, GFUI_ALIGN_HL_VB, 0); snprintf(buf, BUFSIZE, "%d", (int)GfParmGetNum(results, path, RE_ATTR_POINTS, NULL, 0)); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x3, y, GFUI_ALIGN_HR_VB, 0); y -= 15; } if (start > 0) { RmPrevRace.prevHdle = prevHdle; RmPrevRace.info = info; RmPrevRace.start = start - MAX_LINES; GfuiGrButtonCreate(rmScrHdle, "data/img/arrow-up.png", "data/img/arrow-up.png", "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", 80, 40, GFUI_ALIGN_HL_VB, 1, (void*)&RmPrevRace, rmChgStandingScreen, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_PAGE_UP, "Previous Results", (void*)&RmPrevRace, rmChgStandingScreen, NULL); } GfuiButtonCreate(rmScrHdle, "Continue", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, 0, prevHdle, GfuiScreenReplace, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); rmSaveId = GfuiButtonCreate(rmScrHdle, "Save", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, 0, info, rmSaveRes, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); if (i < nbCars) { RmNextRace.prevHdle = prevHdle; RmNextRace.info = info; RmNextRace.start = start + MAX_LINES; GfuiGrButtonCreate(rmScrHdle, "data/img/arrow-down.png", "data/img/arrow-down.png", "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", 540, 40, GFUI_ALIGN_HL_VB, 1, (void*)&RmNextRace, rmChgStandingScreen, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_PAGE_DOWN, "Next Results", (void*)&RmNextRace, rmChgStandingScreen, NULL); } GfuiAddKey(rmScrHdle, (unsigned char)27, "", prevHdle, GfuiScreenReplace, NULL); GfuiAddKey(rmScrHdle, (unsigned char)13, "", prevHdle, GfuiScreenReplace, NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_F12, "Take a Screen Shot", NULL, GfuiScreenShot, NULL); GfuiScreenActivate(rmScrHdle); }
// Sound menu void * SoundMenuInit(void *prevMenu) { int x, y, x2, x3, x4, dy; // char buf[1024]; // Has screen already been created? if (scrHandle) { return scrHandle; } prevHandle = prevMenu; scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, onActivate, NULL, (tfuiCallback)NULL, 1); GfuiTitleCreate(scrHandle, "Sound Configuration", 0); GfuiScreenAddBgImg(scrHandle, "data/img/splash-qrdrv.png"); x = 20; x2 = 200; x3 = 340; x4 = (x2+x3)/2; y = 400; dy = 30; y -= dy; GfuiLabelCreate(scrHandle, "Sound System:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0); GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x2, y-5, GFUI_ALIGN_HL_VB, 1, (void*)-1, changeSoundState, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x3, y-5, GFUI_ALIGN_HR_VB, 1, (void*)1, changeSoundState, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); SoundOptionId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_MEDIUM_C, x4, y, GFUI_ALIGN_HC_VB, 32); GfuiLabelSetColor(scrHandle, SoundOptionId, LabelColor); /* y -= dy; GfuiLabelCreate(scrHandle, "Volume:", GFUI_FONT_MEDIUM, x, y, GFUI_ALIGN_HL_VB, 0); sprintf(buf, "%f", VolumeValue); VolumeValueId = GfuiEditboxCreate(scrHandle, buf, GFUI_FONT_MEDIUM_C, x2+10, y+2, x4-x2+20, 16, NULL, (tfuiCallback)NULL, changeVolume); */ GfuiButtonCreate(scrHandle, "Accept", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, saveSoundOption, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Cancel", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, prevMenu, GfuiScreenActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddKey(scrHandle, 13, "Save", NULL, saveSoundOption, NULL); GfuiAddKey(scrHandle, 27, "Cancel Selection", prevMenu, GfuiScreenActivate, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_F12, "Screen-Shot", NULL, GfuiScreenShot, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_LEFT, "Previous Option in list", (void*)0, changeSoundState, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_RIGHT, "Next Option in list", (void*)1, changeSoundState, NULL); readSoundCfg(); return scrHandle; }
static void rmPracticeResults(void *prevHdle, tRmInfo *info, int start) { void *results = info->results; const char *race = info->_reRaceName; int i; int x1, x2, x3, x4, x5, x6; int offset; int y; const int BUFSIZE = 1024; char buf[BUFSIZE]; char path[BUFSIZE]; const int TIMEFMTSIZE = 256; char timefmt[TIMEFMTSIZE]; float fgcolor[4] = {1.0, 0.0, 1.0, 1.0}; int totLaps; rmScrHdle = GfuiScreenCreate(); snprintf(buf, BUFSIZE, "Practice Results"); GfuiTitleCreate(rmScrHdle, buf, strlen(buf)); snprintf(path, BUFSIZE, "%s/%s/%s", info->track->name, RE_SECT_RESULTS, race); snprintf(buf, BUFSIZE, "%s on track %s", GfParmGetStr(results, path, RM_ATTR_DRVNAME, ""), info->track->name); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_LARGE_C, 320, 420, GFUI_ALIGN_HC_VB, 0); GfuiScreenAddBgImg(rmScrHdle, "data/img/splash-result.png"); offset = 90; x1 = offset + 30; x2 = offset + 50; x3 = offset + 130; x4 = offset + 240; x5 = offset + 310; x6 = offset + 400; y = 400; GfuiLabelCreateEx(rmScrHdle, "Lap", fgcolor, GFUI_FONT_MEDIUM_C, x1, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Time", fgcolor, GFUI_FONT_MEDIUM_C, x2+20, y, GFUI_ALIGN_HL_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Best", fgcolor, GFUI_FONT_MEDIUM_C, x3+20, y, GFUI_ALIGN_HL_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Top Spd", fgcolor, GFUI_FONT_MEDIUM_C, x4, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Min Spd", fgcolor, GFUI_FONT_MEDIUM_C, x5, y, GFUI_ALIGN_HC_VB, 0); GfuiLabelCreateEx(rmScrHdle, "Damages", fgcolor, GFUI_FONT_MEDIUM_C, x6, y, GFUI_ALIGN_HC_VB, 0); y -= 20; snprintf(path, BUFSIZE, "%s/%s/%s", info->track->name, RE_SECT_RESULTS, race); totLaps = (int)GfParmGetEltNb(results, path); for (i = 0 + start; i < MIN(start + MAX_LINES, totLaps); i++) { snprintf(path, BUFSIZE, "%s/%s/%s/%d", info->track->name, RE_SECT_RESULTS, race, i + 1); /* Lap */ snprintf(buf, BUFSIZE, "%d", i+1); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x1, y, GFUI_ALIGN_HC_VB, 0); /* Time */ GfTime2Str(timefmt, TIMEFMTSIZE, GfParmGetNum(results, path, RE_ATTR_TIME, NULL, 0), 0); GfuiLabelCreate(rmScrHdle, timefmt, GFUI_FONT_MEDIUM_C, x2, y, GFUI_ALIGN_HL_VB, 0); /* Best Lap Time */ GfTime2Str(timefmt, TIMEFMTSIZE, GfParmGetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, 0), 0); GfuiLabelCreate(rmScrHdle, timefmt, GFUI_FONT_MEDIUM_C, x3, y, GFUI_ALIGN_HL_VB, 0); /* Top Spd */ snprintf(buf, BUFSIZE, "%d", (int)(GfParmGetNum(results, path, RE_ATTR_TOP_SPEED, NULL, 0) * 3.6)); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x4, y, GFUI_ALIGN_HC_VB, 0); /* Min Spd */ snprintf(buf, BUFSIZE, "%d", (int)(GfParmGetNum(results, path, RE_ATTR_BOT_SPEED, NULL, 0) * 3.6)); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x5, y, GFUI_ALIGN_HC_VB, 0); /* Damages */ snprintf(buf, BUFSIZE, "%d", (int)(GfParmGetNum(results, path, RE_ATTR_DAMMAGES, NULL, 0))); GfuiLabelCreate(rmScrHdle, buf, GFUI_FONT_MEDIUM_C, x6, y, GFUI_ALIGN_HC_VB, 0); y -= 15; } if (start > 0) { RmPrevRace.prevHdle = prevHdle; RmPrevRace.info = info; RmPrevRace.start = start - MAX_LINES; GfuiGrButtonCreate(rmScrHdle, "data/img/arrow-up.png", "data/img/arrow-up.png", "data/img/arrow-up.png", "data/img/arrow-up-pushed.png", 80, 40, GFUI_ALIGN_HL_VB, 1, (void*)&RmPrevRace, rmChgPracticeScreen, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_PAGE_UP, "Previous Results", (void*)&RmPrevRace, rmChgPracticeScreen, NULL); } GfuiButtonCreate(rmScrHdle, "Continue", GFUI_FONT_LARGE, 320, 40, 150, GFUI_ALIGN_HC_VB, 0, prevHdle, GfuiScreenReplace, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); if (i < totLaps) { RmNextRace.prevHdle = prevHdle; RmNextRace.info = info; RmNextRace.start = start + MAX_LINES; GfuiGrButtonCreate(rmScrHdle, "data/img/arrow-down.png", "data/img/arrow-down.png", "data/img/arrow-down.png", "data/img/arrow-down-pushed.png", 540, 40, GFUI_ALIGN_HL_VB, 1, (void*)&RmNextRace, rmChgPracticeScreen, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_PAGE_DOWN, "Next Results", (void*)&RmNextRace, rmChgPracticeScreen, NULL); } GfuiAddKey(rmScrHdle, (unsigned char)27, "", prevHdle, GfuiScreenReplace, NULL); GfuiAddKey(rmScrHdle, (unsigned char)13, "", prevHdle, GfuiScreenReplace, NULL); GfuiAddSKey(rmScrHdle, GLUT_KEY_F12, "Take a Screen Shot", NULL, GfuiScreenShot, NULL); GfuiScreenActivate(rmScrHdle); }
// OpenGL menu void * OpenGLMenuInit(void *prevMenu) { int y, dy; // Has screen already been created? if (scrHandle) { return scrHandle; } prevHandle = prevMenu; scrHandle = GfuiScreenCreateEx((float*)NULL, NULL, onActivate, NULL, (tfuiCallback)NULL, 1); GfuiTitleCreate(scrHandle, "OpenGL Options", 0); GfuiScreenAddBgImg(scrHandle, "data/img/splash-simucfg.png"); y = 400; dy = 30; const int xleft = 160; // Center of left elements. const int xright = 480; // Center of right elements. const int width = 240; // Width of elements. y -= dy; // Texture compression. GfuiLabelCreate(scrHandle, "Texture Compression", GFUI_FONT_LARGE, xleft, 400, GFUI_ALIGN_HC_VB, 0); if (isCompressARBAvailable()) { GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", xleft-width/2, y, GFUI_ALIGN_HC_VB, 1, (void*)-1, changeTextureCompressState, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", xleft+width/2, y, GFUI_ALIGN_HC_VB, 1, (void*)1, changeTextureCompressState, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); TextureCompressOptionId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_LARGE_C, xleft, y, GFUI_ALIGN_HC_VB, 32); GfuiLabelSetColor(scrHandle, TextureCompressOptionId, LabelColor); } else { GfuiLabelCreate(scrHandle, "not available", GFUI_FONT_LARGE_C, xleft, y, GFUI_ALIGN_HC_VB, 0); } // Texture sizing. GfuiLabelCreate(scrHandle, "Texture Size Limit", GFUI_FONT_LARGE, xright, 400, GFUI_ALIGN_HC_VB, 0); GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", xright-width/2, y, GFUI_ALIGN_HC_VB, 0, (void*)-1, changeTextureSizeState, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", xright+width/2, y, GFUI_ALIGN_HC_VB, 0, (void*)1, changeTextureSizeState, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); TextureSizeOptionId = GfuiLabelCreate(scrHandle, "", GFUI_FONT_LARGE_C, xright, y, GFUI_ALIGN_HC_VB, 32); GfuiLabelSetColor(scrHandle, TextureSizeOptionId, LabelColor); GfuiButtonCreate(scrHandle, "Accept", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, saveOpenGLOption, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiButtonCreate(scrHandle, "Cancel", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, prevMenu, GfuiScreenActivate, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiAddKey(scrHandle, 13, "Save", NULL, saveOpenGLOption, NULL); GfuiAddKey(scrHandle, 27, "Cancel Selection", prevMenu, GfuiScreenActivate, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_F12, "Screen-Shot", NULL, GfuiScreenShot, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_LEFT, "Previous Option in list", (void*)0, changeTextureCompressState, NULL); GfuiAddSKey(scrHandle, GLUT_KEY_RIGHT, "Next Option in list", (void*)1, changeTextureCompressState, NULL); readOpenGLCfg(); return scrHandle; }
/** @ingroup racemantools @param title Screen title. @param bgimg Optional background image (0 for no img). @return None. */ void RmLoadingScreenStart(const char *title, const char *bgimg) { if (HScreen && GfuiScreenIsActive(HScreen)) return; if (HScreen) RmLoadingScreenShutdown(); // Create screen, load menu XML descriptor and create static controls. HScreen = GfuiScreenCreate(BGColor, NULL, NULL, NULL, NULL, 0); void *hmenu = GfuiMenuLoad("loadingscreen.xml"); GfuiMenuCreateStaticControls(HScreen, hmenu); // Create variable title label. int titleId = GfuiMenuCreateLabelControl(HScreen, hmenu, "titlelabel"); GfuiLabelSetText(HScreen, titleId, title); // Get layout / coloring properties. NTextLines = (int)GfuiMenuGetNumProperty(hmenu, "nLines", 20); const int yTopLine = (int)GfuiMenuGetNumProperty(hmenu, "yTopLine", 400); const int yLineShift = (int)GfuiMenuGetNumProperty(hmenu, "yLineShift", 16); const float alpha0 = GfuiMenuGetNumProperty(hmenu, "alpha0", 0.2); const float alphaSlope = GfuiMenuGetNumProperty(hmenu, "alphaSlope", 0.0421); // Allocate line info arrays. FGColors = (float**)calloc(NTextLines, sizeof(float*)); TextLines = (char**)calloc(NTextLines, sizeof(char*)); TextLineIds = (int*)calloc(NTextLines, sizeof(int)); // Create one label for each text line int y = yTopLine; for (int i = 0; i < NTextLines; i++) { // Create and set the color for this line. FGColors[i] = (float*)calloc(4, sizeof(float)); FGColors[i][0] = FGColors[i][1] = FGColors[i][2] = 1.0; FGColors[i][3] = (float)i * alphaSlope + alpha0; // Create the control from the template. TextLineIds[i] = GfuiMenuCreateLabelControl(HScreen, hmenu, "line", true, // from template "", GFUI_TPL_X, y, GFUI_TPL_FONTID, GFUI_TPL_WIDTH, GFUI_TPL_ALIGN, GFUI_TPL_MAXLEN, FGColors[i]); // Next line if not last. y -= yLineShift; } CurTextLineIdx = 0; // Add background image. if (bgimg) GfuiScreenAddBgImg(HScreen, bgimg); // Close menu XML descriptor. GfParmReleaseHandle(hmenu); // Display screen. GfuiScreenActivate(HScreen); GfuiDisplay(); }
void RmRaceParamMenu(void *vrp) { int y, x, x2, dy, dx; const int BUFSIZE = 1024; char buf[BUFSIZE]; rp = (tRmRaceParam*)vrp; snprintf(buf, BUFSIZE, "%s Options", rp->title); scrHandle = GfuiMenuScreenCreate(buf); GfuiScreenAddBgImg(scrHandle, "data/img/splash-raceopt.png"); x = 80; x2 = 240; y = 380; dx = 200; dy = GfuiFontHeight(GFUI_FONT_LARGE) + 5; if (rp->confMask & RM_CONF_RACE_LEN) { GfuiLabelCreate(scrHandle, "Race Distance (km):", GFUI_FONT_MEDIUM_C, x, y, GFUI_ALIGN_HL_VB, 0); rmrpDistance = (int)GfParmGetNum(rp->param, rp->title, RM_ATTR_DISTANCE, "km", 0); if (rmrpDistance == 0) { strcpy(buf, "---"); rmrpLaps = (int)GfParmGetNum(rp->param, rp->title, RM_ATTR_LAPS, NULL, 25); } else { snprintf(buf, BUFSIZE, "%d", rmrpDistance); rmrpLaps = 0; } rmrpDistId = GfuiEditboxCreate(scrHandle, buf, GFUI_FONT_MEDIUM_C, x + dx, y, 0, 8, NULL, (tfuiCallback)NULL, rmrpUpdDist); y -= dy; GfuiLabelCreate(scrHandle, "Laps:", GFUI_FONT_MEDIUM_C, x, y, GFUI_ALIGN_HL_VB, 0); if (rmrpLaps == 0) { strcpy(buf, "---"); } else { snprintf(buf, BUFSIZE, "%d", rmrpLaps); } rmrpLapsId = GfuiEditboxCreate(scrHandle, buf, GFUI_FONT_MEDIUM_C, x + dx, y, 0, 8, NULL, (tfuiCallback)NULL, rmrpUpdLaps); y -= dy; } if (rp->confMask & RM_CONF_DISP_MODE) { GfuiLabelCreate(scrHandle, "Display:", GFUI_FONT_MEDIUM_C, x, y, GFUI_ALIGN_HL_VB, 0); GfuiGrButtonCreate(scrHandle, "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left.png", "data/img/arrow-left-pushed.png", x2, y, GFUI_ALIGN_HL_VB, 1, (void*)0, rmChangeDisplayMode, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); GfuiGrButtonCreate(scrHandle, "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right.png", "data/img/arrow-right-pushed.png", x2 + 150, y, GFUI_ALIGN_HL_VB, 1, (void*)1, rmChangeDisplayMode, NULL, (tfuiCallback)NULL, (tfuiCallback)NULL); if (!strcmp(GfParmGetStr(rp->param, rp->title, RM_ATTR_DISPMODE, RM_VAL_VISIBLE), RM_VAL_INVISIBLE)) { rmCurDispMode = 1; } else { rmCurDispMode = 0; } rmDispModeEditId = GfuiLabelCreate(scrHandle, rmCurDispModeList[rmCurDispMode], GFUI_FONT_MEDIUM_C, x2 + 35, y, GFUI_ALIGN_HL_VB, 20); y -= dy; } GfuiButtonCreate(scrHandle, "Accept", GFUI_FONT_LARGE, 210, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, NULL, rmrpValidate, NULL, NULL, NULL); GfuiButtonCreate(scrHandle, "Cancel", GFUI_FONT_LARGE, 430, 40, 150, GFUI_ALIGN_HC_VB, GFUI_MOUSE_UP, rp->prevScreen, rmrpDeactivate, NULL, NULL, NULL); rmrpAddKeys(); GfuiScreenActivate(scrHandle); }
static void UpdateNetworkPlayers() { GfDriver* newDriver; NetNetwork *pNetwork = NetGetNetwork(); if (pNetwork->GetRefreshDisplay() == false) return; tRmInfo* reInfo = LmRaceEngine().inData(); //Set current driver that camera will look at pNetwork->SetCurrentDriver(); //reload xml file NetGetNetwork()->SetRaceXMLFile("config/raceman/networkrace.xml"); reInfo->params = GfParmReadFileLocal("config/raceman/networkrace.xml",GFPARM_RMODE_REREAD); assert(reInfo->params); reInfo->_reName = GfParmGetStr(reInfo->params, RM_SECT_HEADER, RM_ATTR_NAME, ""); assert(reInfo->_reName); // Scan each of the human drivers to see if they're active in this race if (NetIsServer()) { NetServerMutexData *pSData = NetGetServer()->LockServerData(); assert(pSData); // Ensure that garage menu knows about driver for (unsigned int i=0; i < pSData->m_vecNetworkPlayers.size(); i++) { newDriver = GfDrivers::self()->getDriver(NETWORKROBOT, pSData->m_vecNetworkPlayers[i].idx); if (!newDriver) { GfLogInfo("Driver %s not found, reloading drivers\n", pSData->m_vecNetworkPlayers[i].name); GfDrivers::self()->reload(); LmRaceEngine().race()->load(LmRaceEngine().race()->getManager(), true); break; } } for (unsigned int i=0; i < pSData->m_vecNetworkPlayers.size(); i++) { int k = 1; char path2[256]; pSData->m_vecNetworkPlayers[i].active = false; newDriver = GfDrivers::self()->getDriver(NETWORKROBOT, pSData->m_vecNetworkPlayers[i].idx); // Scan through drivers listed in 'networkrace.xml' while (pSData->m_vecNetworkPlayers[i].active == false) { sprintf(path2, "%s/%d", RM_SECT_DRIVERS, k++); if (GfParmExistsSection(reInfo->params, path2) == 0) { GfLogInfo("UpdateNetworkPlayers: Removing driver %s\n", pSData->m_vecNetworkPlayers[i].name); if (pSData->m_vecNetworkPlayers[i].client) { //need to tell/force client to disconnect } break; } if ((tdble)pSData->m_vecNetworkPlayers[i].idx == GfParmGetNum(reInfo->params, path2, RM_ATTR_IDX, NULL, 1.0) && strcmp(NETWORKROBOT, GfParmGetStr(reInfo->params, path2, RM_ATTR_MODULE, "")) == 0) { pSData->m_vecNetworkPlayers[i].active = true; } } // add or remove from competitor list (for garage menu) GfDriver* activeDriver = LmRaceEngine().race()->getCompetitor(NETWORKROBOT, pSData->m_vecNetworkPlayers[i].idx); if (pSData->m_vecNetworkPlayers[i].active) { if (!activeDriver) LmRaceEngine().race()->appendCompetitor(newDriver); } else { if (activeDriver) LmRaceEngine().race()->removeCompetitor(newDriver); } } NetGetServer()->UnlockServerData(); } else { #if 1 // Client XML files already written to disk - this works but is not the best solution.... GfDrivers::self()->reload(); LmRaceEngine().race()->load(LmRaceEngine().race()->getManager(), true); #endif } //Update track info std::string strTrackPath = GfParmGetStr(reInfo->params, "Tracks/1", RM_ATTR_NAME, ""); std::string strCategory = GfParmGetStr(reInfo->params, "Tracks/1", RM_ATTR_CATEGORY, ""); std::string strTrackName = GetTrackName(strCategory.c_str(),strTrackPath.c_str()); sprintf(buf, "%s", strTrackName.c_str()); GfuiLabelSetText(racemanMenuHdle,g_trackHd,buf); //Store current track - client needs this GfTrack* PCurTrack = GfTracks::self()->getTrackWithName(buf); LmRaceEngine().race()->getManager()->setEventTrack(0, PCurTrack); int laps = (int)GfParmGetNum(reInfo->params, reInfo->_reName,"laps", "", 1); sprintf(buf, "%i", laps); GfuiLabelSetText(racemanMenuHdle,g_lapsHd,buf); GfuiScreenAddBgImg(racemanMenuHdle, GetTrackPreviewFileName(strCategory.c_str(),strTrackPath.c_str()).c_str()); GfuiStaticImageSet(racemanMenuHdle, g_OutlineId, GetTrackOutlineFileName(strCategory.c_str(),strTrackPath.c_str()).c_str()); // Update category info std::string strCarCat; bool bCollisions; NetGetNetwork()->GetHostSettings(strCarCat,bCollisions); GfuiLabelSetText(racemanMenuHdle,g_catHd,strCarCat.c_str()); //fill in player data int nCars = GfParmGetEltNb(reInfo->params, RM_SECT_DRIVERS); char dname[256]; char robpath[256]; float *pColor = &green[0]; bool bEveryoneReadyToRace = true; for (int i = 1; i < nCars+1; i++) { sprintf(dname, "%s/%d", RM_SECT_DRIVERS, i); const char* robot = GfParmGetStr(reInfo->params, dname, RM_ATTR_MODULE, ""); //lookup playerName and car name sprintf(robpath,"drivers/%s/%s.xml",robot,robot); void *pMod = GfParmReadFileLocal(robpath,GFPARM_RMODE_REREAD); if (pMod == NULL) { //try again in other path sprintf(robpath,"drivers/%s/%s.xml",robot,robot); pMod = GfParmReadFile(robpath,GFPARM_RMODE_REREAD); if (pMod == NULL) continue; } assert(pMod); char ppname[256]; int idx = GfParmGetNum(reInfo->params, dname, RM_ATTR_IDX, "",0); sprintf(ppname,"Robots/index/%d",idx); const char* name = GfParmGetStr(pMod, ppname, RM_ATTR_NAME, ""); const char* car = GfParmGetStr(pMod, ppname, "car name", ""); std::string strRealCar = GfCars::self()->getCar(car)->getName(); // WAIT : pNData->m_vecReadyStatus[i-1] ?! // This can only work when _only_ networkhuman drivers in the race // (that is _no_robot_driver_) ; because m_vecReadyStatus is indexed // by the networkhuman drivers list. // TO fix this, 2 solutions: // 1) make the networking module take care of the robot drivers too // (in m_vecReadyStatus, m_vecNetworkPlayers, ...) // 2) make the networking _menu_ only take care of the networkhuman drivers. bool bReady = bRobotsReady; if(strcmp(NETWORKROBOT, GfParmGetStr(reInfo->params, dname, RM_ATTR_MODULE, "")) == 0) { // Write car model, as it may have changed via garage menu if (NetIsServer()) { NetServerMutexData *pSData = NetGetServer()->LockServerData(); strncpy(pSData->m_vecNetworkPlayers[idx-1].car, car, 64); GfLogInfo("idx %d car set to %s\n", idx, car); // also need to write back for garage menu const GfCar* newCar = GfCars::self()->getCar(car); newDriver = GfDrivers::self()->getDriver(NETWORKROBOT, pSData->m_vecNetworkPlayers[idx-1].idx); newDriver->setCar(newCar); NetGetServer()->UnlockServerData(); } //GfLogInfo("idx %d, m_vecReadyStatus.size() %d\n", idx, pNData->m_vecReadyStatus.size()); NetMutexData *pNData = NetGetNetwork()->LockNetworkData(); bReady = pNData->m_vecReadyStatus[idx-1]; NetGetNetwork()->UnlockNetworkData(); } int readyindex = 0; if (bReady) readyindex = 1; else bEveryoneReadyToRace = false; if (strcmp(NetGetNetwork()->GetDriverName(),name)==0) { pColor = &green[0]; g_strCar = strRealCar; //Make sure checkbox matches ready state GfuiCheckboxSetChecked(racemanMenuHdle, g_ReadyCheckboxId, bReady); if (NetGetClient()) EnableMenuClientButtons(bReady); else EnableMenuHostButtons(bReady); } else pColor = &white[0]; GfuiVisibilitySet(racemanMenuHdle,g_readystatus[i-1],true); GfuiStaticImageSetActive(racemanMenuHdle,g_readystatus[i-1],readyindex); GfuiLabelSetColor(racemanMenuHdle, g_playerNames[i-1], pColor); GfuiLabelSetText(racemanMenuHdle,g_playerNames[i-1],name); GfuiLabelSetColor(racemanMenuHdle, g_carNames[i-1], pColor); GfuiLabelSetText(racemanMenuHdle,g_carNames[i-1],strRealCar.c_str()); GfParmReleaseHandle(pMod); } //Clear out rest of table for (int i=nCars;i<MAXNETWORKPLAYERS;i++) { GfuiVisibilitySet(racemanMenuHdle,g_readystatus[i],false); GfuiLabelSetText(racemanMenuHdle,g_playerNames[i],""); GfuiLabelSetText(racemanMenuHdle,g_carNames[i],""); } pNetwork->SetRefreshDisplay(false); GfuiApp().eventLoop().postRedisplay(); if (NetIsClient()) { NetGetClient()->ConnectToClients(); if (!NetGetClient()->TimeSynced()) { NetGetClient()->SendServerTimeRequest(); } } if (NetIsServer()) { if (bEveryoneReadyToRace && nCars > 1) ServerPrepareStartNetworkRace(NULL); } }