static void ReBoardInfo(void * /* vboard */) { if (ReInfo->s->_raceState & RM_RACE_PAUSED) { ReInfo->s->_raceState &= ~RM_RACE_PAUSED; ReStart(); GfuiVisibilitySet(reScreenHandle, rePauseId, 0); } else { ReInfo->s->_raceState |= RM_RACE_PAUSED; ReStop(); GfuiVisibilitySet(reScreenHandle, rePauseId, 1); } }
static void rmSaveRes(void *vInfo) { tRmInfo *info = (tRmInfo *)vInfo; GfParmWriteFile(0, info->results, "Results"); GfuiVisibilitySet(rmScrHdle, rmSaveId, GFUI_INVISIBLE); }
/** Add the "Back" or "Quit" button at the bottom of the menu screen. @ingroup gui @param scr Screen or Menu handle @param text Text of the button @param tip Text to display when the button is focused @param userdata Parameter of the Push function @param onpush Callback when the button is pushed @return Button Id */ int GfuiMenuBackQuitButtonCreate(void *scr, char *text, char *tip, void *userdata, tfuiCallback onpush) { tMnuCallbackInfo *cbinfo; int xpos, ypos; int bId; xpos = 320; ypos = 40; cbinfo = (tMnuCallbackInfo*)calloc(1, sizeof(tMnuCallbackInfo)); cbinfo->screen = scr; cbinfo->labelId = GfuiTipCreate(scr, tip, strlen(tip)); GfuiVisibilitySet(scr, cbinfo->labelId, 0); bId = GfuiButtonCreate(scr, text, GFUI_FONT_LARGE, xpos, ypos, GFUI_BTNSZ, GFUI_ALIGN_HC_VB, 0, userdata, onpush, (void*)cbinfo, dispInfo, remInfo); GfuiAddKey(scr, (unsigned char)27, tip, userdata, onpush, NULL); return bId; }
static int createImageButton(void* hscr, void* hparm, const char* pszPath, void* userDataOnPush, tfuiCallback onPush, void* userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost, bool bFromTemplate = false, const char* tip = GFUI_TPL_TIP, int x = GFUI_TPL_X, int y = GFUI_TPL_Y, int width = GFUI_TPL_WIDTH, int height = GFUI_TPL_HEIGHT) { if (strcmp(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TYPE, ""), GFMNU_TYPE_IMAGE_BUTTON)) { GfLogError("Failed to create image button control '%s' : section not found or not an '%s'\n", pszPath, GFMNU_TYPE_IMAGE_BUTTON); return -1; } const char* pszTip = bFromTemplate && tip != GFUI_TPL_TIP ? tip : GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TIP, ""); const int nX = bFromTemplate && x != GFUI_TPL_X ? x : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_X, NULL, 0); const int nY = bFromTemplate && y != GFUI_TPL_Y ? y : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_Y, NULL, 0); int nWidth = bFromTemplate && width != GFUI_TPL_WIDTH ? width : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_WIDTH, NULL, 0); int nHeight = bFromTemplate && height != GFUI_TPL_HEIGHT ? height : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_HEIGHT, NULL, 0); if (strlen(pszTip) > 0) { tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo)); cbinfo->screen = hscr; cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip)); GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE); // TODO: In this case, we crudely overwrite onFocus/onFocusLost ! userDataOnFocus = (void*)cbinfo; onFocus = onFocusShowTip; onFocusLost = onFocusLostHideTip; } const char* pszDisabledImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_DISABLED, ""); const char* pszEnabledImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_ENABLED, ""); const char* pszFocusedImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_FOCUSED, ""); const char* pszPushedImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_PUSHED, ""); int butId = GfuiGrButtonCreate(hscr, pszDisabledImage, pszEnabledImage, pszFocusedImage, pszPushedImage, nX, nY, nWidth, nHeight, GFUI_MIRROR_NONE, true, GFUI_MOUSE_UP, userDataOnPush, onPush, userDataOnFocus, onFocus, onFocusLost); return butId; }
int GfuiMenuCreateProgressbarControl(void* hscr, void* hparm, const char* pszName) { std::string strControlPath(GFMNU_SECT_DYNAMIC_CONTROLS"/"); strControlPath += pszName; const std::string strType = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TYPE, ""); if (strType != GFMNU_TYPE_PROGRESS_BAR) { GfLogError("Failed to create control '%s' : section not found or not an '%s' \n", pszName, GFMNU_TYPE_PROGRESS_BAR); return -1; } const char* pszImage = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_IMAGE, "data/img/progressbar.png"); const char* pszBgImage = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_BG_IMAGE, "data/img/progressbar-bg.png"); const float* aOutlineColor = 0; const GfuiColor color = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR); if (color.alpha) aOutlineColor = color.toFloatRGBA(); const int x = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_X, NULL, 0.0); const int y = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_Y, NULL, 0.0); const int w = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_WIDTH, NULL, 100.0); const int h = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_HEIGHT, NULL, 20.0); const float min = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MIN, NULL, 0.0); const float max = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MAX, NULL, 100.0); const float value = GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_VALUE, NULL, 50.0); const char* pszTip = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TIP, ""); void* userDataOnFocus = 0; tfuiCallback onFocus = 0; tfuiCallback onFocusLost = 0; if (strlen(pszTip) > 0) { tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo)); cbinfo->screen = hscr; cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip)); GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE); userDataOnFocus = (void*)cbinfo; onFocus = onFocusShowTip; onFocusLost = onFocusLostHideTip; } int id = GfuiProgressbarCreate(hscr, x, y, w, h, pszBgImage, pszImage, aOutlineColor, min, max, value, userDataOnFocus, onFocus, onFocusLost); return id; }
void * ReScreenInit(void) { ReScreenShutdown(); reScreenHandle = GfuiScreenCreateEx(bgcolor, 0, reScreenActivate, 0, 0, 0); reAddKeys(); reMsgId = GfuiLabelCreateEx(reScreenHandle, "", red, GFUI_FONT_LARGE_C, 320, 400, GFUI_ALIGN_HC_VB, 32); rePauseId = GfuiLabelCreateEx(reScreenHandle, "P A U S E", red, GFUI_FONT_BIG_C, 320, 420, GFUI_ALIGN_HC_VB, 0); reBigMsgId = GfuiLabelCreateEx(reScreenHandle, "", red, GFUI_FONT_BIG_C, 320, 360, GFUI_ALIGN_HC_VB, 32); GfuiVisibilitySet(reScreenHandle, rePauseId, 0); return reScreenHandle; }
void * RmScreenInit() { // Release screen if was initialized. RmScreenShutdown(); // Create screen, load menu XML descriptor and create static controls. rmScreenHandle = GfuiScreenCreate(black, 0, rmScreenActivate, 0, 0, 0); void *menuXMLDescHdle = GfuiMenuLoad("raceglscreen.xml"); GfuiMenuCreateStaticControls(rmScreenHandle, menuXMLDescHdle); // Create Message, BigMessage and Pause labels. rmMsgId = GfuiMenuCreateLabelControl(rmScreenHandle, menuXMLDescHdle, "message"); rmBigMsgId = GfuiMenuCreateLabelControl(rmScreenHandle, menuXMLDescHdle, "bigmessage"); rmPauseId = GfuiMenuCreateLabelControl(rmScreenHandle, menuXMLDescHdle, "pause"); // Close menu XML descriptor. GfParmReleaseHandle(menuXMLDescHdle); // Register keyboard shortcuts. rmAddKeys(); // We are starting "unpaused". GfuiVisibilitySet(rmScreenHandle, rmPauseId, GFUI_INVISIBLE); rmRacePaused = false; #ifdef STARTPAUSED rmPreRacePause = false; #endif // Re-initialize the progressive time modifier, // in case the race was exited while it was running. rmProgressiveTimeModifier.reset(); // Initialize the movie capture system. rmInitMovieCapture(); return rmScreenHandle; }
/** Add a button to a menu screen. @ingroup gui @param scr Screen (menu) handle @param text Text of the button @param tip Text of the tip displayed when the button is focused @param userdata Parameter of the Push function @param onpush Callback when the button is pushed @return Button Id */ int GfuiMenuButtonCreate(void *scr, char *text, char *tip, void *userdata, tfuiCallback onpush) { tMnuCallbackInfo *cbinfo; int xpos, ypos; int nbItems = ((tGfuiScreen*)scr)->nbItems++; int bId; if (nbItems < 11) { xpos = 320; ypos = 380 - 30 * nbItems; } else { if (nbItems > 22) { GfTrace("Too many items in that menu !!!\n"); return -1; } xpos = 380; ypos = 380 - 30 * (nbItems - 11); } cbinfo = (tMnuCallbackInfo*)calloc(1, sizeof(tMnuCallbackInfo)); cbinfo->screen = scr; cbinfo->labelId = GfuiTipCreate(scr, tip, strlen(tip)); GfuiVisibilitySet(scr, cbinfo->labelId, 0); bId = GfuiButtonCreate(scr, text, GFUI_FONT_LARGE, xpos, ypos, GFUI_BTNSZ, GFUI_ALIGN_HC_VB, 0, userdata, onpush, (void*)cbinfo, dispInfo, remInfo); return bId; }
static void rmRacePause(void * /* vboard */) { #ifdef STARTPAUSED // Pause is disabled during Pre Race Pause // as the simulation is already Paused if (!rmPreRacePause) { if (rmRacePaused) { if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(false); #else if (rmRacePaused) { if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(false); #endif LmRaceEngine().start(); // Hide the "Pause" label. GfuiVisibilitySet(rmScreenHandle, rmPauseId, GFUI_INVISIBLE); // Show again the hidden message label. GfuiVisibilitySet(rmScreenHandle, rmMsgId, GFUI_VISIBLE); // Launch the "slow resume race" manager if non-blind mode. if (LmRaceEngine().outData()->_displayMode == RM_DISP_MODE_NORMAL) rmProgressiveTimeModifier.start(); } else { if (LegacyMenu::self().soundEngine()) LegacyMenu::self().soundEngine()->mute(true); LmRaceEngine().stop(); // Show the "Pause" label. GfuiVisibilitySet(rmScreenHandle, rmPauseId, GFUI_VISIBLE); // Hide the message label (no need to bother the user with the time mult. factor // when it is changing, whihc occurs when the user hits P when a slow start // is in-process). GfuiVisibilitySet(rmScreenHandle, rmMsgId, GFUI_INVISIBLE); } // Toggle the race-paused flag. rmRacePaused = !rmRacePaused; // The menu changed. rmbMenuChanged = true; #ifdef STARTPAUSED } #endif } static void rmSkipPreStart(void * /* dummy */) { // TODO: move this to a new LmRaceEngine().skipRacePreStart() ... tRmInfo* reInfo = LmRaceEngine().inData(); if (reInfo->s->currentTime < -1.0) { reInfo->s->currentTime = -1.0; reInfo->_reLastRobTime = -1.0; } }
/* Load screen editable fields with relevant values : - all empty if no player selected, - from selected player current settings otherwise */ static void refreshEditVal(void) { int autoRevVisible = GFUI_INVISIBLE; if (CurrPlayer == PlayersInfo.end()) { GfuiEditboxSetString(ScrHandle, NameEditId, ""); GfuiEnable(ScrHandle, NameEditId, GFUI_DISABLE); GfuiEditboxSetString(ScrHandle, RaceNumEditId, ""); GfuiEnable(ScrHandle, RaceNumEditId, GFUI_DISABLE); GfuiLabelSetText(ScrHandle, GearChangeEditId, ""); GfuiEnable(ScrHandle, GearChangeEditId, GFUI_DISABLE); GfuiEditboxSetString(ScrHandle, PitsEditId, ""); GfuiEnable(ScrHandle, PitsEditId, GFUI_DISABLE); GfuiLabelSetText(ScrHandle, SkillEditId, ""); GfuiEnable(ScrHandle, SkillEditId, GFUI_DISABLE); GfuiLabelSetText(ScrHandle, AutoReverseEditId, ""); GfuiEnable(ScrHandle, AutoReverseEditId, GFUI_DISABLE); } else { if (strcmp((*CurrPlayer)->dispName(), NoPlayer)) { GfuiEditboxSetString(ScrHandle, NameEditId, (*CurrPlayer)->dispName()); } else { GfuiEditboxSetString(ScrHandle, NameEditId, PlayerNamePrompt); } GfuiEnable(ScrHandle, NameEditId, GFUI_ENABLE); snprintf(buf, sizeof(buf), "%d", (*CurrPlayer)->raceNumber()); GfuiEditboxSetString(ScrHandle, RaceNumEditId, buf); GfuiEnable(ScrHandle, RaceNumEditId, GFUI_ENABLE); GfuiLabelSetText(ScrHandle, GearChangeEditId, (*CurrPlayer)->gearChangeModeString()); GfuiEnable(ScrHandle, GearChangeEditId, GFUI_ENABLE); snprintf(buf, sizeof(buf), "%d", (*CurrPlayer)->nbPitStops()); GfuiEditboxSetString(ScrHandle, PitsEditId, buf); GfuiEnable(ScrHandle, PitsEditId, GFUI_ENABLE); GfuiLabelSetText(ScrHandle, SkillEditId, SkillLevelString[(*CurrPlayer)->skillLevel()]); GfuiEnable(ScrHandle, SkillEditId, GFUI_ENABLE); GfuiLabelSetText(ScrHandle, AutoReverseEditId, Yn[(*CurrPlayer)->autoReverse()]); GfuiEnable(ScrHandle, AutoReverseEditId, GFUI_ENABLE); if ((*CurrPlayer)->gearChangeMode() == GEAR_MODE_AUTO) autoRevVisible = GFUI_VISIBLE; } GfuiVisibilitySet(ScrHandle, AutoReverseLabelId, autoRevVisible); GfuiVisibilitySet(ScrHandle, AutoReverseLeftId, autoRevVisible); GfuiVisibilitySet(ScrHandle, AutoReverseEditId, autoRevVisible); GfuiVisibilitySet(ScrHandle, AutoReverseRightId, autoRevVisible); }
// Host on-line race menu. void RmNetworkHostMenu(void * /* dummy */) { GfLogTrace("Entering Network Host menu.\n"); if (!NetGetNetwork()) { NetSetServer(true); NetSetClient(false); if (!NetGetServer()->Start(SPEEDDREAMSPORT)) { NetSetServer(false); return; } } if (racemanMenuHdle) GfuiScreenRelease(racemanMenuHdle); racemanMenuHdle = GfuiScreenCreate(NULL, NULL, (tfuiCallback)OnActivateNetworkHost, NULL, (tfuiCallback)NULL, 1); void *mparam = GfuiMenuLoad("networkhostmenu.xml"); GfuiMenuCreateStaticControls(racemanMenuHdle, mparam); RmSetRacemanMenuHandle(racemanMenuHdle); NetworkRaceInfo(); g_trackHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"trackname"); g_lapsHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"lapcountname"); g_catHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"carcatname"); g_OutlineId = GfuiMenuCreateStaticImageControl(racemanMenuHdle,mparam,"outlineimage"); //Show players for (int i = 0; i < MAXNETWORKPLAYERS; i++) { char buf[1024]; sprintf(buf,"ready%i",i); g_readystatus[i] = GfuiMenuCreateStaticImageControl(racemanMenuHdle,mparam,buf); GfuiVisibilitySet(racemanMenuHdle,g_readystatus[i],false); sprintf(buf,"driver%i",i); g_playerNames[i] = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,buf); GfuiLabelSetText(racemanMenuHdle,g_playerNames[i],""); sprintf(buf,"car%i",i); g_carNames[i] = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,buf); GfuiLabelSetText(racemanMenuHdle,g_carNames[i],""); } g_ReadyCheckboxId = GfuiMenuCreateCheckboxControl(racemanMenuHdle, mparam, "playerreadycheckbox", NULL, onHostPlayerReady); g_HostSettingsButtonId = GfuiMenuCreateButtonControl(racemanMenuHdle, mparam, "networkhostsettings", racemanMenuHdle, rmNetworkHostSettingsMenu); GfuiEnable(racemanMenuHdle, g_HostSettingsButtonId, GFUI_DISABLE); g_RaceSetupId = GfuiMenuCreateButtonControl(racemanMenuHdle, mparam, "racesetup", racemanMenuHdle, RmConfigureRace); GfuiMenuCreateButtonControl(racemanMenuHdle, mparam, "start race", NULL, ServerPrepareStartNetworkRace); g_CancelButtonId = GfuiMenuCreateButtonControl(racemanMenuHdle, mparam, "cancel", NULL, rmNetworkServerDisconnect); GfParmReleaseHandle(mparam); GfuiMenuDefaultKeysAdd(racemanMenuHdle); GfuiAddKey(racemanMenuHdle, GFUIK_ESCAPE, "Back to previous menu", 0, 0, rmNetworkServerDisconnect); UpdateNetworkPlayers(); GfuiScreenActivate(racemanMenuHdle); }
static void onFocusLostHideTip(void* cbinfo) { GfuiVisibilitySet(((tMenuCallbackInfo*)cbinfo)->screen, ((tMenuCallbackInfo*)cbinfo)->labelId, GFUI_INVISIBLE); }
static int createTextButton(void* hscr, void* hparm, const char* pszPath, void* userDataOnPush, tfuiCallback onPush, void* userDataOnFocus, tfuiCallback onFocus, tfuiCallback onFocusLost, bool bFromTemplate = false, const char* text = GFUI_TPL_TEXT, const char* tip = GFUI_TPL_TIP, int x = GFUI_TPL_X, int y = GFUI_TPL_Y, int width = GFUI_TPL_WIDTH, int font = GFUI_TPL_FONTID, int textHAlign = GFUI_TPL_ALIGN, const float* aFgColor = GFUI_TPL_COLOR, const float* aFgFocusColor = GFUI_TPL_FOCUSCOLOR, const float* aFgPushedColor = GFUI_TPL_PUSHEDCOLOR) { if (strcmp(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TYPE, ""), GFMNU_TYPE_TEXT_BUTTON)) { GfLogError("Failed to create text button control '%s' : section not found or not a '%s'\n", pszPath, GFMNU_TYPE_TEXT_BUTTON); return -1; } const char* pszText = bFromTemplate && text != GFUI_TPL_TEXT ? text : GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TEXT, ""); const char* pszTip = bFromTemplate && tip != GFUI_TPL_TIP ? tip : GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TIP, ""); const int nX = bFromTemplate && x != GFUI_TPL_X ? x : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_X, NULL, 0); const int nY = bFromTemplate && y != GFUI_TPL_Y ? y : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_Y, NULL, 0); int nWidth = bFromTemplate && width != GFUI_TPL_WIDTH ? width : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_WIDTH, NULL, 0); if (nWidth <= 0) nWidth = GFUI_BTNSZ; // TODO: Get default from screen.xml const int nFontId = bFromTemplate && font != GFUI_TPL_FONTID ? font : gfuiMenuGetFontId(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_FONT, "")); const char* pszAlignH = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_H_ALIGN, ""); //const char* pszAlignV = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_V_ALIGN, ""); const int nAlign = bFromTemplate && textHAlign != GFUI_TPL_ALIGN ? textHAlign : gfuiMenuGetAlignment(pszAlignH); //, pszAlignV); GfuiColor color; const float* aColor = 0; if (bFromTemplate && aFgColor != GFUI_TPL_COLOR) aColor = aFgColor; else { color = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR); if (color.alpha) aColor = color.toFloatRGBA(); } GfuiColor focusColor; const float* aFocusColor = 0; if (bFromTemplate && aFgFocusColor != GFUI_TPL_FOCUSCOLOR) aFocusColor = aFgFocusColor; else { focusColor = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR_FOCUSED); if (focusColor.alpha) aFocusColor = focusColor.toFloatRGBA(); } GfuiColor pushedColor; const float* aPushedColor = 0; if (bFromTemplate && aFgPushedColor != GFUI_TPL_PUSHEDCOLOR) aPushedColor = aFgPushedColor; else { pushedColor = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR_PUSHED); if (pushedColor.alpha) aPushedColor = pushedColor.toFloatRGBA(); } if (pszTip && strlen(pszTip) > 0) { tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo)); cbinfo->screen = hscr; cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip)); GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE); // TODO: In this case, we crudely overwrite onFocus/onFocusLost ! userDataOnFocus = (void*)cbinfo; onFocus = onFocusShowTip; onFocusLost = onFocusLostHideTip; } const bool bShowbox = getControlBoolean(hparm, pszPath, GFMNU_ATTR_BOX_SHOW, true); const char* pszDisabledImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_DISABLED, 0); const char* pszEnabledImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_ENABLED, 0); const char* pszFocusedImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_FOCUSED, 0); const char* pszPushedImage = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_IMAGE_PUSHED, 0); const int imgX = (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_IMAGE_X, NULL, 0.0); const int imgY = (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_IMAGE_Y, NULL, 0.0); const int imgWidth = (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_IMAGE_WIDTH, NULL, 20.0); const int imgHeight = (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_IMAGE_HEIGHT, NULL, 20.0); int butId = GfuiButtonCreate(hscr, pszText, nFontId, nX, nY, nWidth, nAlign, GFUI_MOUSE_UP, userDataOnPush, onPush, userDataOnFocus, onFocus, onFocusLost); GfuiButtonShowBox(hscr, butId, bShowbox); if (pszDisabledImage || pszEnabledImage || pszFocusedImage || pszPushedImage) GfuiButtonSetImage(hscr, butId, imgX, imgY, imgWidth, imgHeight, pszDisabledImage, pszEnabledImage, pszFocusedImage, pszPushedImage); GfuiButtonSetColors(hscr, butId, GfuiColor::build(aColor), GfuiColor::build(aFocusColor), GfuiColor::build(aPushedColor)); return butId; }
static int createLabel(void* hscr, void* hparm, const char* pszPath, bool bFromTemplate = false, const char* text = GFUI_TPL_TEXT, int x = GFUI_TPL_X, int y = GFUI_TPL_Y, int font = GFUI_TPL_FONTID, int width = GFUI_TPL_WIDTH, int hAlign = GFUI_TPL_ALIGN, int maxlen = GFUI_TPL_MAXLEN, const float* aFgColor = GFUI_TPL_COLOR, const float* aFgFocusColor = GFUI_TPL_FOCUSCOLOR) { if (strcmp(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TYPE, ""), GFMNU_TYPE_LABEL)) { GfLogError("Failed to create label control '%s' : section not found or not a '%s'\n", pszPath, GFMNU_TYPE_LABEL); return -1; } const char* pszText = bFromTemplate && text != GFUI_TPL_TEXT ? text : GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TEXT, ""); const int nX = bFromTemplate && x != GFUI_TPL_X ? x : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_X, NULL, 0); const int nY = bFromTemplate && y != GFUI_TPL_Y ? y : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_Y, NULL, 0); const int nWidth = bFromTemplate && width != GFUI_TPL_WIDTH ? width : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_WIDTH, NULL, 0); const int nFontId = bFromTemplate && font != GFUI_TPL_FONTID ? font : gfuiMenuGetFontId(GfParmGetStr(hparm, pszPath, GFMNU_ATTR_FONT, "")); const char* pszAlignH = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_H_ALIGN, ""); //const char* pszAlignV = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_V_ALIGN, ""); const int nAlign = bFromTemplate && hAlign != GFUI_TPL_ALIGN ? hAlign : gfuiMenuGetAlignment(pszAlignH); //, pszAlignV); int nMaxLen = bFromTemplate && maxlen != GFUI_TPL_MAXLEN ? maxlen : (int)GfParmGetNum(hparm, pszPath, GFMNU_ATTR_MAX_LEN, NULL, 0); GfuiColor color; const float* aColor = 0; if (bFromTemplate && aFgColor != GFUI_TPL_COLOR) aColor = aFgColor; else { color = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR); if (color.alpha) aColor = color.toFloatRGBA(); } GfuiColor focusColor; const float* aFocusColor = 0; if (bFromTemplate && aFgFocusColor != GFUI_TPL_FOCUSCOLOR) aFocusColor = aFgFocusColor; else { focusColor = getControlColor(hparm, pszPath, GFMNU_ATTR_COLOR_FOCUSED); if (focusColor.alpha) aFocusColor = focusColor.toFloatRGBA(); } void* userDataOnFocus = 0; tfuiCallback onFocus = 0; tfuiCallback onFocusLost = 0; const char* pszTip = GfParmGetStr(hparm, pszPath, GFMNU_ATTR_TIP, 0); if (pszTip && strlen(pszTip) > 0) { tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo)); cbinfo->screen = hscr; cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip)); GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE); userDataOnFocus = (void*)cbinfo; onFocus = onFocusShowTip; onFocusLost = onFocusLostHideTip; } int labelId = GfuiLabelCreate(hscr, pszText, nFontId, nX, nY, nWidth, nAlign, nMaxLen, aColor, aFocusColor, userDataOnFocus, onFocus, onFocusLost); return labelId; }
void RmNetworkClientMenu(void * /* dummy */) { GfLogTrace("Entering Network Client menu.\n"); ShowWaitingToConnectScreen(); if (!NetGetClient()) { NetSetServer(false); NetSetClient(true); NetDriver driver; GetHumanDriver(driver,1); driver.client = true; driver.active = true; strcpy(driver.name,g_strDriver.c_str()); if (!NetGetClient()->ConnectToServer((char*)g_strHostIP.c_str(),SPEEDDREAMSPORT,&driver)) { //failed so back to connect menu NetworkClientConnectMenu(NULL); return; } //NetGetClient()->SendDriverInfoPacket(&driver); } if (racemanMenuHdle) GfuiScreenRelease(racemanMenuHdle); racemanMenuHdle = GfuiScreenCreate(NULL, NULL, (tfuiCallback)OnActivateNetworkClient, NULL, (tfuiCallback)NULL, 1); void *mparam = GfuiMenuLoad("networkclientmenu.xml"); GfuiMenuCreateStaticControls(racemanMenuHdle, mparam); GfuiMenuDefaultKeysAdd(racemanMenuHdle); RmSetRacemanMenuHandle(racemanMenuHdle); g_trackHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"trackname"); g_lapsHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"lapcountname"); g_catHd = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,"carcatname"); g_OutlineId = GfuiMenuCreateStaticImageControl(racemanMenuHdle,mparam,"outlineimage"); //Show players for (int i = 0; i < MAXNETWORKPLAYERS; i++) { char buf[1024]; sprintf(buf,"ready%i",i); g_readystatus[i] = GfuiMenuCreateStaticImageControl(racemanMenuHdle,mparam,buf); GfuiVisibilitySet(racemanMenuHdle,g_readystatus[i],false); sprintf(buf,"driver%i",i); g_playerNames[i] = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,buf); GfuiLabelSetText(racemanMenuHdle,g_playerNames[i],""); sprintf(buf,"car%i",i); g_carNames[i] = GfuiMenuCreateLabelControl(racemanMenuHdle,mparam,buf); GfuiLabelSetText(racemanMenuHdle,g_carNames[i],""); } g_ReadyCheckboxId = GfuiMenuCreateCheckboxControl(racemanMenuHdle, mparam, "playerreadycheckbox", NULL, onClientPlayerReady); g_CarSetupButtonId = GfuiMenuCreateButtonControl(racemanMenuHdle, mparam, "garage", racemanMenuHdle, rmCarSettingsMenu); g_DisconnectButtonId = GfuiMenuCreateButtonControl(racemanMenuHdle, mparam, "disconnect", NULL,rmNetworkClientDisconnect); GfParmReleaseHandle(mparam); UpdateNetworkPlayers(); GfuiScreenActivate(racemanMenuHdle); GfuiApp().eventLoop().setRecomputeCB(ClientIdle); }
int GfuiMenuCreateComboboxControl(void* hscr, void* hparm, const char* pszName, void* userData, tfuiComboboxCallback onChange) { std::string strControlPath(GFMNU_SECT_DYNAMIC_CONTROLS"/"); strControlPath += pszName; const std::string strType = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TYPE, ""); if (strType != GFMNU_TYPE_COMBO_BOX) { GfLogError("Failed to create control '%s' : section not found or not an '%s' \n", pszName, GFMNU_TYPE_COMBO_BOX); return -1; } int id = -1; const int x = (int)GfParmGetNum(hparm,strControlPath.c_str(), GFMNU_ATTR_X, NULL, 0.0); const int y = (int)GfParmGetNum(hparm,strControlPath.c_str(), GFMNU_ATTR_Y, NULL, 0.0); std::string strFontName = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_FONT, ""); const int font = gfuiMenuGetFontId(strFontName.c_str()); int width = (int)GfParmGetNum(hparm,strControlPath.c_str(), GFMNU_ATTR_WIDTH, NULL, 0.0); if (width == 0) width = 200; const int nArrowsWidth = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_ARROWS_WIDTH, NULL, 0); const int nArrowsHeight = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_ARROWS_HEIGHT, NULL, 0); const char* pszText = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TEXT, ""); const int maxlen = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_MAX_LEN, 0, 0); const char* pszTip = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TIP, 0); void* userDataOnFocus = 0; tfuiCallback onFocus = 0; tfuiCallback onFocusLost = 0; if (pszTip && strlen(pszTip) > 0) { tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo)); cbinfo->screen = hscr; cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip)); GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE); userDataOnFocus = (void*)cbinfo; onFocus = onFocusShowTip; onFocusLost = onFocusLostHideTip; } const float* aColor = 0; const GfuiColor color = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR); if (color.alpha) aColor = color.toFloatRGBA(); const float* aFocusColor = 0; const GfuiColor focusColor = getControlColor(hparm, strControlPath.c_str(), GFMNU_ATTR_COLOR_FOCUSED); if (focusColor.alpha) aFocusColor = focusColor.toFloatRGBA(); id = GfuiComboboxCreate(hscr, font, x, y, width, nArrowsWidth, nArrowsHeight, pszText, maxlen, aColor, aFocusColor, userData, onChange, userDataOnFocus, onFocus, onFocusLost); return id; }
int GfuiMenuCreateCheckboxControl(void* hscr, void* hparm, const char* pszName,void* userData,tfuiCheckboxCallback onChange) { std::string strControlPath(GFMNU_SECT_DYNAMIC_CONTROLS"/"); strControlPath += pszName; const std::string strType = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TYPE, ""); if (strType != GFMNU_TYPE_CHECK_BOX) { GfLogError("Failed to create control '%s' : section not found or not an '%s' \n", pszName, GFMNU_TYPE_CHECK_BOX); return -1; } int id = -1; const int x = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_X, NULL, 0.0); const int y = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_Y, NULL, 0.0); std::string strFontName = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_FONT, ""); const int font = gfuiMenuGetFontId(strFontName.c_str()); const char* pszText = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TEXT, ""); int imagewidth = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_IMAGE_WIDTH, NULL, 0.0); if (imagewidth <= 0) imagewidth = 30; // TODO: Get default from screen.xml int imageheight = (int)GfParmGetNum(hparm, strControlPath.c_str(), GFMNU_ATTR_IMAGE_HEIGHT, NULL, 0.0); if (imageheight <= 0) imageheight = 30; // TODO: Get default from screen.xml const bool bChecked = getControlBoolean(hparm, strControlPath.c_str(), GFMNU_ATTR_CHECKED, false); const char* pszTip = GfParmGetStr(hparm, strControlPath.c_str(), GFMNU_ATTR_TIP, ""); void* userDataOnFocus = 0; tfuiCallback onFocus = 0; tfuiCallback onFocusLost = 0; if (strlen(pszTip) > 0) { tMenuCallbackInfo * cbinfo = (tMenuCallbackInfo*)calloc(1, sizeof(tMenuCallbackInfo)); cbinfo->screen = hscr; cbinfo->labelId = GfuiTipCreate(hscr, pszTip, strlen(pszTip)); GfuiVisibilitySet(hscr, cbinfo->labelId, GFUI_INVISIBLE); userDataOnFocus = (void*)cbinfo; onFocus = onFocusShowTip; onFocusLost = onFocusLostHideTip; } id = GfuiCheckboxCreate(hscr, font, x, y, imagewidth, imageheight, pszText, bChecked, userData, onChange, userDataOnFocus, onFocus, onFocusLost); GfuiColor c = getControlColor(hparm, pszName, GFMNU_ATTR_COLOR); if (c.alpha) GfuiCheckboxSetTextColor(hscr, id, c); return id; }
static void remInfo(void *cbinfo) { GfuiVisibilitySet(((tMnuCallbackInfo*)cbinfo)->screen, ((tMnuCallbackInfo*)cbinfo)->labelId, 0); }
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); } }