//**************************************************************************************** // Challenge menu //***************************************************************************************** bool addChallenges() { char sPath[PATH_MAX]; const char *sSearchPath = "challenges"; UDWORD slotCount; static char sSlotCaps[totalslots][totalslotspace]; static char sSlotTips[totalslots][totalslotspace]; static char sSlotFile[totalslots][totalslotspace]; char **i, **files; (void) PHYSFS_mkdir(sSearchPath); // just in case psRequestScreen = widgCreateScreen(); // init the screen widgSetTipFont(psRequestScreen, font_regular); /* add a form to place the tabbed form on */ W_FORMINIT sFormInit; sFormInit.formID = 0; //this adds the blue background, and the "box" behind the buttons -Q sFormInit.id = CHALLENGE_FORM; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD) CHALLENGE_X; sFormInit.y = (SWORD) CHALLENGE_Y; sFormInit.width = CHALLENGE_W; // we need the form to be long enough for all resolutions, so we take the total number of items * height // and * the gaps, add the banner, and finally, the fudge factor ;) sFormInit.height = (slotsInColumn * CHALLENGE_ENTRY_H + CHALLENGE_HGAP * slotsInColumn) + CHALLENGE_BANNER_DEPTH + 20; sFormInit.disableChildren = true; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRequestScreen, &sFormInit); // Add Banner sFormInit.formID = CHALLENGE_FORM; sFormInit.id = CHALLENGE_BANNER; sFormInit.x = CHALLENGE_HGAP; sFormInit.y = CHALLENGE_VGAP; sFormInit.width = CHALLENGE_W - (2 * CHALLENGE_HGAP); sFormInit.height = CHALLENGE_BANNER_DEPTH; sFormInit.disableChildren = false; sFormInit.pDisplay = displayLoadBanner; sFormInit.UserData = 0; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label W_LABINIT sLabInit; sLabInit.formID = CHALLENGE_BANNER; sLabInit.id = CHALLENGE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 3; sLabInit.width = CHALLENGE_W - (2 * CHALLENGE_HGAP); //CHALLENGE_W; sLabInit.height = CHALLENGE_BANNER_DEPTH; //This looks right -Q sLabInit.pText = "Challenge"; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. W_BUTINIT sButInit; sButInit.formID = CHALLENGE_BANNER; sButInit.x = 8; sButInit.y = 8; sButInit.width = iV_GetImageWidth(IntImages, IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages, IMAGE_NRUTER); sButInit.UserData = PACKDWORD_TRI(0, IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = CHALLENGE_CANCEL; sButInit.pTip = _("Close"); sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots sButInit = W_BUTINIT(); sButInit.formID = CHALLENGE_FORM; sButInit.width = CHALLENGE_ENTRY_W; sButInit.height = CHALLENGE_ENTRY_H; sButInit.pDisplay = displayLoadSlot; for (slotCount = 0; slotCount < totalslots; slotCount++) { sButInit.id = slotCount + CHALLENGE_ENTRY_START; if (slotCount < slotsInColumn) { sButInit.x = 22 + CHALLENGE_HGAP; sButInit.y = (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + ( slotCount * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H))); } else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2))) { sButInit.x = 22 + (2 * CHALLENGE_HGAP + CHALLENGE_ENTRY_W); sButInit.y = (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + ( (slotCount % slotsInColumn) * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H))); } else { sButInit.x = 22 + (3 * CHALLENGE_HGAP + (2 * CHALLENGE_ENTRY_W)); sButInit.y = (SWORD)((CHALLENGE_BANNER_DEPTH + (2 * CHALLENGE_VGAP)) + ( (slotCount % slotsInColumn) * (CHALLENGE_VGAP + CHALLENGE_ENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; sstrcpy(sPath, sSearchPath); sstrcat(sPath, "/*.ini"); debug(LOG_SAVE, "Searching \"%s\" for challenges", sPath); // add challenges to buttons files = PHYSFS_enumerateFiles(sSearchPath); for (i = files; *i != NULL; ++i) { W_BUTTON *button; char description[totalslotspace]; char highscore[totalslotspace]; const char *name, *difficulty, *map, *givendescription; inifile *inif; // See if this filename contains the extension we're looking for if (!strstr(*i, ".ini")) { // If it doesn't, move on to the next filename continue; } /* First grab any high score associated with this challenge */ inif = inifile_load(CHALLENGE_SCORES); sstrcpy(sPath, *i); sPath[strlen(sPath) - 4] = '\0'; // remove .ini sstrcpy(highscore, "no score"); if (inif) { char key[64]; bool victory; int seconds; ssprintf(key, "%s:Player", sPath); name = inifile_get(inif, key, "NO NAME"); ssprintf(key, "%s:Victory", sPath); victory = inifile_get_as_bool(inif, key, false); ssprintf(key, "%s:Seconds", sPath); seconds = inifile_get_as_int(inif, key, -1); if (seconds > 0) { getAsciiTime(key, seconds * GAME_TICKS_PER_SEC); ssprintf(highscore, "%s by %s (%s)", key, name, victory ? "Victory" : "Survived"); } inifile_delete(inif); } ssprintf(sPath, "%s/%s", sSearchPath, *i); inif = inifile_load(sPath); inifile_set_current_section(inif, "challenge"); if (!inif) { debug(LOG_ERROR, "Could not open \"%s\"", sPath); continue; } name = inifile_get(inif, "Name", "BAD NAME"); map = inifile_get(inif, "Map", "BAD MAP"); difficulty = inifile_get(inif, "difficulty", "BAD DIFFICULTY"); givendescription = inifile_get(inif, "description", ""); ssprintf(description, "%s, %s, %s. %s", map, difficulty, highscore, givendescription); button = (W_BUTTON*)widgGetFromID(psRequestScreen, CHALLENGE_ENTRY_START + slotCount); debug(LOG_SAVE, "We found [%s]", *i); /* Set the button-text */ sstrcpy(sSlotCaps[slotCount], name); // store it! sstrcpy(sSlotTips[slotCount], description); // store it, too! sstrcpy(sSlotFile[slotCount], sPath); // store filename inifile_delete(inif); /* Add button */ button->pTip = sSlotTips[slotCount]; button->pText = sSlotCaps[slotCount]; button->pUserData = (void *)sSlotFile[slotCount]; slotCount++; // go to next button... if (slotCount == totalslots) { break; } } PHYSFS_freeList(files); challengesUp = true; return true; }
// //////////////////////////////////////////////////// static BOOL _addLoadSave(BOOL bLoad,CHAR *sSearchPath,CHAR *sExtension, CHAR *title) { W_FORMINIT sFormInit; W_BUTINIT sButInit; W_LABINIT sLabInit; UDWORD slotCount; static STRING sSlots[10][64]; STRING sTemp[255]; WIN32_FIND_DATA found; HANDLE dir; mode = bLoad; if(GetCurrentDirectory(255,(char*)&sTemp) == 0) { return FALSE; // failed, directory probably didn't exist. } if ((bLoadSaveMode == LOAD_INGAME) || (bLoadSaveMode == SAVE_INGAME)) { if (!bMultiPlayer || (NetPlay.bComms ==0)) { gameTimeStop(); if(GetGameMode() == GS_NORMAL) { BOOL radOnScreen = radarOnScreen; // Only do this in main game. bRender3DOnly = TRUE; radarOnScreen = FALSE; displayWorld(); // Just display the 3d, no interface pie_UploadDisplayBuffer(DisplayBuffer); // Upload the current display back buffer into system memory. iV_ScaleBitmapRGB(DisplayBuffer,iV_GetDisplayWidth(), iV_GetDisplayHeight(),2,2,2); // Make it darker. radarOnScreen = radOnScreen; bRender3DOnly = FALSE; } setGamePauseStatus( TRUE ); setGameUpdatePause(TRUE); setScriptPause(TRUE); setScrollPause(TRUE); setConsolePause(TRUE); } forceHidePowerBar(); intRemoveReticule(); } CreateDirectory(sSearchPath,NULL); // create the directory required... fails if already there, so no problem. widgCreateScreen(&psRequestScreen); // init the screen. widgSetTipFont(psRequestScreen,WFont); /* add a form to place the tabbed form on */ memset(&sFormInit, 0, sizeof(W_FORMINIT)); sFormInit.formID = 0; sFormInit.id = LOADSAVE_FORM; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD)(LOADSAVE_X); sFormInit.y = (SWORD)(LOADSAVE_Y); sFormInit.width = LOADSAVE_W; sFormInit.height = LOADSAVE_H; sFormInit.disableChildren = TRUE; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRequestScreen, &sFormInit); // Add Banner sFormInit.formID = LOADSAVE_FORM; sFormInit.id = LOADSAVE_BANNER; sFormInit.x = LOADSAVE_HGAP; sFormInit.y = LOADSAVE_VGAP; sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); sFormInit.height = LOADSAVE_BANNER_DEPTH; sFormInit.disableChildren = FALSE; sFormInit.pDisplay = displayLoadBanner; sFormInit.pUserData = (VOID *)bLoad; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label memset(&sLabInit, 0, sizeof(W_LABINIT)); sLabInit.formID = LOADSAVE_BANNER; sLabInit.id = LOADSAVE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 4; sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W; sLabInit.height = 20; sLabInit.pText = title; sLabInit.FontID = WFont; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_BANNER; sButInit.x = 4; sButInit.y = 3; sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER); sButInit.pUserData = (void*)PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = LOADSAVE_CANCEL; sButInit.style = WBUT_PLAIN; sButInit.pTip = strresGetString(psStringRes, STR_MISC_CLOSE); sButInit.FontID = WFont; sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_FORM; sButInit.style = WBUT_PLAIN; sButInit.width = LOADENTRY_W; sButInit.height = LOADENTRY_H; sButInit.pDisplay = displayLoadSlot; sButInit.FontID = WFont; for(slotCount = 0; slotCount< 10 ; slotCount++) { sButInit.id = slotCount+LOADENTRY_START; if(slotCount<5) { sButInit.x = LOADSAVE_HGAP; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + ( slotCount*(LOADSAVE_VGAP+LOADENTRY_H))); } else { sButInit.x = (2*LOADSAVE_HGAP)+LOADENTRY_W; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount-5) *(LOADSAVE_VGAP+LOADENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; sprintf(sTemp,"%s*.%s",sSearchPath,sExtension); // form search string. strcpy(sPath,sSearchPath); // setup locals. strcpy(sExt,sExtension); dir =FindFirstFile(sTemp,&found); if(dir != INVALID_HANDLE_VALUE) { while( TRUE ) { /* Set the tip and add the button */ found.cFileName[strlen(found.cFileName) -4 ] = '\0'; // chop extension strcpy(sSlots[slotCount],found.cFileName); //store it! ((W_BUTTON *)widgGetFromID(psRequestScreen,LOADENTRY_START+slotCount))->pTip = sSlots[slotCount]; ((W_BUTTON *)widgGetFromID(psRequestScreen,LOADENTRY_START+slotCount))->pText = sSlots[slotCount]; slotCount++; // goto next but. if(!FindNextFile(dir,&found ) || slotCount == 10 )// only show upto 10 entrys. { break; } } } FindClose(dir); bLoadSaveUp = TRUE; return TRUE; }
/** Searches in the given search directory for files ending with the * given extension. Then will create a window with buttons for each * found file. * \param searchDir the directory to search in * \param fileExtension the extension files should end with, if the * extension has a dot (.) then this dot _must_ be present as * the first char in this parameter * \param mode (purpose unknown) * \param numPlayers (purpose unknown) */ void addMultiRequest(const char* searchDir, const char* fileExtension, UDWORD mode, UBYTE mapCam, UBYTE numPlayers) { W_FORMINIT sFormInit; W_BUTINIT sButInit; UDWORD players; char** fileList; char** currFile; const unsigned int extensionLength = strlen(fileExtension); const unsigned int buttonsX = (mode == MULTIOP_MAP) ? 22 : 17; unsigned int numButtons, count, butPerForm, i; static char tips[NBTIPS][MAX_STR_LENGTH]; context = mode; if(mode == MULTIOP_MAP) { // only save these when they select MAP button current_tech = mapCam; current_numplayers = numPlayers; } fileList = PHYSFS_enumerateFiles(searchDir); if (!fileList) { debug(LOG_FATAL, "addMultiRequest: Out of memory"); abort(); return; } // Count number of required buttons numButtons = 0; for (currFile = fileList; *currFile != NULL; ++currFile) { const unsigned int fileNameLength = strlen(*currFile); // Check to see if this file matches the given extension if (fileNameLength > extensionLength && strcmp(&(*currFile)[fileNameLength - extensionLength], fileExtension) == 0) ++numButtons; } if(mode == MULTIOP_MAP) // if its a map, also look in the predone stuff. { char* map; if ((map = enumerateMultiMaps(&players, true, mapCam, numPlayers))) { free(map); numButtons++; while ((map = enumerateMultiMaps(&players, false, mapCam, numPlayers))) { free(map); numButtons++; } } } psRScreen = widgCreateScreen(); ///< move this to intinit or somewhere like that.. (close too.) widgSetTipFont(psRScreen,font_regular); /* Calculate how many buttons will go on a single form */ butPerForm = ((M_REQUEST_W - 0 - 4) / (R_BUT_W +4)) * ((M_REQUEST_H - 0- 4) / (R_BUT_H+ 4)); /* add a form to place the tabbed form on */ memset(&sFormInit, 0, sizeof(W_FORMINIT)); sFormInit.formID = 0; sFormInit.id = M_REQUEST; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD)(M_REQUEST_X+D_W); sFormInit.y = (SWORD)(M_REQUEST_Y+D_H); sFormInit.width = M_REQUEST_W; sFormInit.height = M_REQUEST_H; sFormInit.disableChildren = true; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRScreen, &sFormInit); /* Add the tabs */ memset(&sFormInit, 0, sizeof(W_FORMINIT)); sFormInit.formID = M_REQUEST; sFormInit.id = M_REQUEST_TAB; sFormInit.style = WFORM_TABBED; sFormInit.x = 2; sFormInit.y = 2; sFormInit.width = M_REQUEST_W; sFormInit.height = M_REQUEST_H-4; sFormInit.numMajor = numForms(numButtons, butPerForm); sFormInit.majorPos = WFORM_TABTOP; sFormInit.minorPos = WFORM_TABNONE; sFormInit.majorSize = OBJ_TABWIDTH+2; sFormInit.majorOffset = OBJ_TABOFFSET; sFormInit.tabVertOffset = (OBJ_TABHEIGHT/2); sFormInit.tabMajorThickness = OBJ_TABHEIGHT; sFormInit.pUserData = &StandardTab; sFormInit.pTabDisplay = intDisplayTab; // TABFIXME: // This appears to be the map pick screen, when we have lots of maps // this will need to change. if (sFormInit.numMajor > MAX_TAB_STD_SHOWN) { ASSERT(sFormInit.numMajor < MAX_TAB_SMALL_SHOWN,"Too many maps! Need scroll tabs here."); sFormInit.pUserData = &SmallTab; sFormInit.majorSize /= 2; } for (i = 0; i < sFormInit.numMajor; ++i) { sFormInit.aNumMinors[i] = 2; } widgAddForm(psRScreen, &sFormInit); // Add the close button. memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = M_REQUEST; sButInit.id = M_REQUEST_CLOSE; sButInit.style = WBUT_PLAIN; sButInit.x = M_REQUEST_W - CLOSE_WIDTH - 3; sButInit.y = 0; sButInit.width = CLOSE_WIDTH; sButInit.height = CLOSE_HEIGHT; sButInit.pTip = _("Close"); sButInit.FontID = font_regular; sButInit.pDisplay = intDisplayImageHilight; sButInit.UserData = PACKDWORD_TRI(0,IMAGE_CLOSEHILIGHT , IMAGE_CLOSE); widgAddButton(psRScreen, &sButInit); /* Put the buttons on it *//* Set up the button struct */ memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = M_REQUEST_TAB; sButInit.id = M_REQUEST_BUT; sButInit.style = WBUT_PLAIN; sButInit.x = buttonsX; sButInit.y = 4; sButInit.width = R_BUT_W; sButInit.height = R_BUT_H; sButInit.pUserData = NULL; sButInit.pDisplay = displayRequestOption; sButInit.FontID = font_regular; for (currFile = fileList, count = 0; *currFile != NULL && count < (butPerForm * 4); ++currFile) { const unsigned int tip_index = check_tip_index(sButInit.id - M_REQUEST_BUT); const unsigned int fileNameLength = strlen(*currFile); const unsigned int tipStringLength = fileNameLength - extensionLength; // Check to see if this file matches the given extension if (!(fileNameLength > extensionLength) || strcmp(&(*currFile)[fileNameLength - extensionLength], fileExtension) != 0) continue; // Set the tip and add the button // Copy all of the filename except for the extension into the tiptext string strlcpy(tips[tip_index], *currFile, MIN(tipStringLength + 1, sizeof(tips[tip_index]))); sButInit.pTip = tips[tip_index]; sButInit.pText = tips[tip_index]; if(mode == MULTIOP_MAP) // if its a map, set player flag. { const char* mapText; unsigned int mapTextLength; sButInit.UserData = (*currFile)[0] - '0'; if( (*currFile)[1] != 'c') { continue; } // Chop off description mapText = strrchr(*currFile, '-') + 1; if (mapText - 1 == NULL) continue; mapTextLength = tipStringLength - (mapText - *currFile); strlcpy(tips[tip_index], mapText, MIN(mapTextLength + 1, sizeof(tips[tip_index]))); } ++count; widgAddButton(psRScreen, &sButInit); /* Update the init struct for the next button */ sButInit.id += 1; sButInit.x = (SWORD)(sButInit.x + (R_BUT_W+ 4)); if (sButInit.x + R_BUT_W+ 2 > M_REQUEST_W) { sButInit.x = buttonsX; sButInit.y = (SWORD)(sButInit.y +R_BUT_H + 4); } if (sButInit.y +R_BUT_H + 4 > M_REQUEST_H) { sButInit.y = 4; sButInit.majorID += 1; } } // Make sure to return memory back to PhyscisFS PHYSFS_freeList(fileList); if(mode == MULTIOP_MAP) { char* mapName; if ((mapName = enumerateMultiMaps(&players, true, mapCam, numPlayers))) { do { unsigned int tip_index = check_tip_index(sButInit.id-M_REQUEST_BUT); // add number of players to string. sstrcpy(tips[tip_index], mapName); free(mapName); sButInit.pTip = tips[tip_index]; sButInit.pText = tips[tip_index]; sButInit.UserData = players; widgAddButton(psRScreen, &sButInit); sButInit.id += 1; sButInit.x = (SWORD)(sButInit.x + (R_BUT_W+ 4)); if (sButInit.x + R_BUT_W+ 2 > M_REQUEST_W) { sButInit.x = buttonsX; sButInit.y = (SWORD)(sButInit.y +R_BUT_H + 4); } if (sButInit.y +R_BUT_H + 4 > M_REQUEST_H) { sButInit.y = 4; sButInit.majorID += 1; } } while ((mapName = enumerateMultiMaps(&players, false, mapCam, numPlayers))); } } multiRequestUp = true; // if it's map select then add the cam style buttons. if(mode == MULTIOP_MAP) { memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = M_REQUEST; sButInit.id = M_REQUEST_C1; sButInit.style = WBUT_PLAIN; sButInit.x = 4; sButInit.y = 258; sButInit.width = 17; sButInit.height = 17; sButInit.UserData = 1; sButInit.FontID = font_regular; sButInit.pTip = _("Technology level 1"); sButInit.pDisplay = displayCamTypeBut; widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_C2; sButInit.y += 22; sButInit.UserData = 2; sButInit.pTip = _("Technology level 2"); widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_C3; sButInit.y += 22; sButInit.UserData = 3; sButInit.pTip = _("Technology level 3"); widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_AP; sButInit.y = 17; sButInit.UserData = 0; sButInit.pTip = _("Any number of players"); sButInit.pDisplay = displayNumPlayersBut; widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_2P; sButInit.y += 22; sButInit.UserData = 2; sButInit.pTip = _("2 players"); widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_3P; sButInit.y += 22; sButInit.UserData = 3; sButInit.pTip = _("3 players"); widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_4P; sButInit.y += 22; sButInit.UserData = 4; sButInit.pTip = _("4 players"); widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_5P; sButInit.y += 22; sButInit.UserData = 5; sButInit.pTip = _("5 players"); widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_6P; sButInit.y += 22; sButInit.UserData = 6; sButInit.pTip = _("6 players"); widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_7P; sButInit.y += 22; sButInit.UserData = 7; sButInit.pTip = _("7 players"); widgAddButton(psRScreen, &sButInit); sButInit.id = M_REQUEST_8P; sButInit.y += 22; sButInit.UserData = 8; sButInit.pTip = _("8 players"); widgAddButton(psRScreen, &sButInit); } }
//**************************************************************************************** // Load menu/save menu? //***************************************************************************************** static BOOL _addLoadSave(BOOL bLoad, const char *sSearchPath, const char *sExtension, const char *title) { W_FORMINIT sFormInit; W_BUTINIT sButInit; W_LABINIT sLabInit; UDWORD slotCount; // removed hardcoded values! change with the defines above! -Q static char sSlotCaps[totalslots][totalslotspace]; static char sSlotTips[totalslots][totalslotspace]; char **i, **files; const char* checkExtension; mode = bLoad; debug(LOG_SAVE, "called (%d, %s, %s, %s)", bLoad, sSearchPath, sExtension, title); if ((bLoadSaveMode == LOAD_INGAME) || (bLoadSaveMode == SAVE_INGAME)) { if (!bMultiPlayer || (NetPlay.bComms ==0)) { gameTimeStop(); if(GetGameMode() == GS_NORMAL) { BOOL radOnScreen = radarOnScreen; // Only do this in main game. bRender3DOnly = true; radarOnScreen = false; displayWorld(); // Just display the 3d, no interface pie_UploadDisplayBuffer(); // Upload the current display back buffer into system memory. radarOnScreen = radOnScreen; bRender3DOnly = false; } setGamePauseStatus( true ); setGameUpdatePause(true); setScriptPause(true); setScrollPause(true); setConsolePause(true); } forceHidePowerBar(); intRemoveReticule(); } (void) PHYSFS_mkdir(sSearchPath); // just in case psRequestScreen = widgCreateScreen(); // init the screen widgSetTipFont(psRequestScreen,font_regular); /* add a form to place the tabbed form on */ memset(&sFormInit, 0, sizeof(W_FORMINIT)); sFormInit.formID = 0; //this adds the blue background, and the "box" behind the buttons -Q sFormInit.id = LOADSAVE_FORM; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD) LOADSAVE_X; sFormInit.y = (SWORD) LOADSAVE_Y; sFormInit.width = LOADSAVE_W; // we need the form to be long enough for all resolutions, so we take the total number of items * height // and * the gaps, add the banner, and finally, the fudge factor ;) sFormInit.height = (slotsInColumn * LOADENTRY_H + LOADSAVE_HGAP* slotsInColumn)+ LOADSAVE_BANNER_DEPTH+20; sFormInit.disableChildren = true; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRequestScreen, &sFormInit); // Add Banner sFormInit.formID = LOADSAVE_FORM; sFormInit.id = LOADSAVE_BANNER; sFormInit.x = LOADSAVE_HGAP; sFormInit.y = LOADSAVE_VGAP; sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); sFormInit.height = LOADSAVE_BANNER_DEPTH; sFormInit.disableChildren = false; sFormInit.pDisplay = displayLoadBanner; sFormInit.UserData = bLoad; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label memset(&sLabInit, 0, sizeof(W_LABINIT)); sLabInit.formID = LOADSAVE_BANNER; sLabInit.id = LOADSAVE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 3; sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W; sLabInit.height = LOADSAVE_BANNER_DEPTH; //This looks right -Q sLabInit.pText = title; sLabInit.FontID = font_regular; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_BANNER; sButInit.x = 8; sButInit.y = 8; sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER); sButInit.UserData = PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = LOADSAVE_CANCEL; sButInit.style = WBUT_PLAIN; sButInit.pTip = _("Close"); sButInit.FontID = font_regular; sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots memset(&sButInit, 0, sizeof(W_BUTINIT)); sButInit.formID = LOADSAVE_FORM; sButInit.style = WBUT_PLAIN; sButInit.width = LOADENTRY_W; sButInit.height = LOADENTRY_H; sButInit.pDisplay = displayLoadSlot; sButInit.FontID = font_regular; for(slotCount = 0; slotCount< totalslots; slotCount++) { sButInit.id = slotCount+LOADENTRY_START; if(slotCount < slotsInColumn) { sButInit.x = 22 + LOADSAVE_HGAP; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + ( slotCount*(LOADSAVE_VGAP+LOADENTRY_H))); } else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2))) { sButInit.x = 22 + (2*LOADSAVE_HGAP + LOADENTRY_W); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } else { sButInit.x = 22 + (3*LOADSAVE_HGAP + (2*LOADENTRY_W)); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; sstrcpy(sPath, sSearchPath); // setup locals. sstrcpy(sExt, sExtension); debug(LOG_SAVE, "Searching \"%s\" for savegames", sSearchPath); // Check for an extension like ".ext", not "ext" sasprintf((char**)&checkExtension, ".%s", sExtension); // add savegame filenames minus extensions to buttons files = PHYSFS_enumerateFiles(sSearchPath); for (i = files; *i != NULL; ++i) { W_BUTTON *button; char savefile[256]; time_t savetime; // See if this filename contains the extension we're looking for if (!strstr(*i, checkExtension)) { // If it doesn't, move on to the next filename continue; } button = (W_BUTTON*)widgGetFromID(psRequestScreen, LOADENTRY_START + slotCount); debug(LOG_SAVE, "We found [%s]", *i); /* Figure save-time */ snprintf(savefile, sizeof(savefile), "%s/%s", sSearchPath, *i); savetime = PHYSFS_getLastModTime(savefile); sstrcpy(sSlotTips[slotCount], ctime(&savetime)); /* Set the button-text */ (*i)[strlen(*i) - 4] = '\0'; // remove .gam extension sstrcpy(sSlotCaps[slotCount], *i); //store it! /* Add button */ button->pTip = sSlotTips[slotCount]; button->pText = sSlotCaps[slotCount]; slotCount++; // goto next but... if (slotCount == totalslots) { break; } } PHYSFS_freeList(files); bLoadSaveUp = true; return true; }
// //////////////////////////////////////////////////////////////////////////// bool addLoadSave(LOADSAVE_MODE savemode, const char *title) { bool bLoad = true; char NewSaveGamePath[PATH_MAX] = {'\0'}; bLoadSaveMode = savemode; UDWORD slotCount; static char sSlotCaps[totalslots][totalslotspace]; static char sSlotTips[totalslots][totalslotspace]; char **i, **files; switch(savemode) { case LOAD_FRONTEND_MISSION: case LOAD_INGAME_MISSION: case LOAD_MISSIONEND: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); break; case LOAD_FRONTEND_SKIRMISH: case LOAD_INGAME_SKIRMISH: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "skirmish"); break; case SAVE_MISSIONEND: case SAVE_INGAME_MISSION: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); bLoad = false; break; case SAVE_INGAME_SKIRMISH: ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "skirmish"); bLoad = false; break; default: ASSERT("Invalid load/save mode!", "Invalid load/save mode!"); ssprintf(NewSaveGamePath, "%s%s/", SaveGamePath, "campaign"); break; } mode = bLoad; debug(LOG_SAVE, "called (%d, %s)", bLoad, title); if ((bLoadSaveMode == LOAD_INGAME_MISSION) || (bLoadSaveMode == SAVE_INGAME_MISSION) || (bLoadSaveMode == LOAD_INGAME_SKIRMISH) || (bLoadSaveMode == SAVE_INGAME_SKIRMISH)) { if (!bMultiPlayer || (NetPlay.bComms ==0)) { gameTimeStop(); if(GetGameMode() == GS_NORMAL) { bool radOnScreen = radarOnScreen; // Only do this in main game. bRender3DOnly = true; radarOnScreen = false; displayWorld(); // Just display the 3d, no interface radarOnScreen = radOnScreen; bRender3DOnly = false; } setGamePauseStatus( true ); setGameUpdatePause(true); setScriptPause(true); setScrollPause(true); setConsolePause(true); } forceHidePowerBar(); intRemoveReticule(); } psRequestScreen = widgCreateScreen(); // init the screen widgSetTipFont(psRequestScreen,font_regular); /* add a form to place the tabbed form on */ W_FORMINIT sFormInit; sFormInit.formID = 0; //this adds the blue background, and the "box" behind the buttons -Q sFormInit.id = LOADSAVE_FORM; sFormInit.style = WFORM_PLAIN; sFormInit.x = (SWORD) LOADSAVE_X; sFormInit.y = (SWORD) LOADSAVE_Y; sFormInit.width = LOADSAVE_W; // we need the form to be long enough for all resolutions, so we take the total number of items * height // and * the gaps, add the banner, and finally, the fudge factor ;) sFormInit.height = (slotsInColumn * LOADENTRY_H + LOADSAVE_HGAP* slotsInColumn)+ LOADSAVE_BANNER_DEPTH+20; sFormInit.disableChildren = true; sFormInit.pDisplay = intOpenPlainForm; widgAddForm(psRequestScreen, &sFormInit); // Add Banner sFormInit.formID = LOADSAVE_FORM; sFormInit.id = LOADSAVE_BANNER; sFormInit.x = LOADSAVE_HGAP; sFormInit.y = LOADSAVE_VGAP; sFormInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); sFormInit.height = LOADSAVE_BANNER_DEPTH; sFormInit.disableChildren = false; sFormInit.pDisplay = displayLoadBanner; sFormInit.UserData = bLoad; widgAddForm(psRequestScreen, &sFormInit); // Add Banner Label W_LABINIT sLabInit; sLabInit.formID = LOADSAVE_BANNER; sLabInit.FontID = font_large; sLabInit.id = LOADSAVE_LABEL; sLabInit.style = WLAB_ALIGNCENTRE; sLabInit.x = 0; sLabInit.y = 0; sLabInit.width = LOADSAVE_W-(2*LOADSAVE_HGAP); //LOADSAVE_W; sLabInit.height = LOADSAVE_BANNER_DEPTH; //This looks right -Q sLabInit.pText = title; widgAddLabel(psRequestScreen, &sLabInit); // add cancel. W_BUTINIT sButInit; sButInit.formID = LOADSAVE_BANNER; sButInit.x = 8; sButInit.y = 10; sButInit.width = iV_GetImageWidth(IntImages,IMAGE_NRUTER); sButInit.height = iV_GetImageHeight(IntImages,IMAGE_NRUTER); sButInit.UserData = PACKDWORD_TRI(0,IMAGE_NRUTER , IMAGE_NRUTER); sButInit.id = LOADSAVE_CANCEL; sButInit.style = WBUT_PLAIN; sButInit.pTip = _("Close"); sButInit.pDisplay = intDisplayImageHilight; widgAddButton(psRequestScreen, &sButInit); // add slots sButInit = W_BUTINIT(); sButInit.formID = LOADSAVE_FORM; sButInit.style = WBUT_PLAIN; sButInit.width = LOADENTRY_W; sButInit.height = LOADENTRY_H; sButInit.pDisplay = displayLoadSlot; for(slotCount = 0; slotCount< totalslots; slotCount++) { sButInit.id = slotCount+LOADENTRY_START; if(slotCount < slotsInColumn) { sButInit.x = 22 + LOADSAVE_HGAP; sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2*LOADSAVE_VGAP)) + ( slotCount*(LOADSAVE_VGAP+LOADENTRY_H))); } else if (slotCount >= slotsInColumn && (slotCount < (slotsInColumn *2))) { sButInit.x = 22 + (2*LOADSAVE_HGAP + LOADENTRY_W); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } else { sButInit.x = 22 + (3*LOADSAVE_HGAP + (2*LOADENTRY_W)); sButInit.y = (SWORD)((LOADSAVE_BANNER_DEPTH +(2* LOADSAVE_VGAP)) + ( (slotCount % slotsInColumn)*(LOADSAVE_VGAP+LOADENTRY_H))); } widgAddButton(psRequestScreen, &sButInit); } // fill slots. slotCount = 0; debug(LOG_SAVE, "Searching \"%s\" for savegames", NewSaveGamePath); // add savegame filenames minus extensions to buttons files = PHYSFS_enumerateFiles(NewSaveGamePath); for (i = files; *i != NULL; ++i) { W_BUTTON *button; char savefile[256]; time_t savetime; struct tm *timeinfo; // See if this filename contains the extension we're looking for if (!strstr(*i, sExt)) { // If it doesn't, move on to the next filename continue; } button = (W_BUTTON*)widgGetFromID(psRequestScreen, LOADENTRY_START + slotCount); debug(LOG_SAVE, "We found [%s]", *i); /* Figure save-time */ snprintf(savefile, sizeof(savefile), "%s/%s", NewSaveGamePath, *i); savetime = PHYSFS_getLastModTime(savefile); timeinfo = localtime(&savetime); strftime(sSlotTips[slotCount], sizeof(sSlotTips[slotCount]), "%x %X", timeinfo); /* Set the button-text */ (*i)[strlen(*i) - 4] = '\0'; // remove .gam extension sstrcpy(sSlotCaps[slotCount], *i); //store it! /* Add button */ button->pTip = sSlotTips[slotCount]; button->pText = sSlotCaps[slotCount]; slotCount++; // goto next but... if (slotCount == totalslots) { break; } } PHYSFS_freeList(files); bLoadSaveUp = true; return true; }