/** * Get a list of scenarios. * @param mode Save/load mode. * @see FiosGetFileList */ void FiosGetScenarioList(SaveLoadDialogMode mode) { static char *fios_scn_path = NULL; /* Copy the default path on first run or on 'New Game' */ if (fios_scn_path == NULL) { fios_scn_path = MallocT<char>(MAX_PATH); FioGetDirectory(fios_scn_path, MAX_PATH, SCENARIO_DIR); } _fios_path = fios_scn_path; char base_path[MAX_PATH]; FioGetDirectory(base_path, sizeof(base_path), SCENARIO_DIR); FiosGetFileList(mode, &FiosGetScenarioListCallback, (mode == SLD_LOAD_SCENARIO && strcmp(base_path, _fios_path) == 0) ? SCENARIO_DIR : NO_DIRECTORY); }
/** * Get a list of savegames. * @param mode Save/load mode. * @see FiosGetFileList */ void FiosGetSavegameList(SaveLoadDialogMode mode) { static char *fios_save_path = NULL; if (fios_save_path == NULL) { fios_save_path = MallocT<char>(MAX_PATH); FioGetDirectory(fios_save_path, MAX_PATH, SAVE_DIR); } _fios_path = fios_save_path; FiosGetFileList(mode, &FiosGetSavegameListCallback, NO_DIRECTORY); }
SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(64) { static const StringID saveload_captions[] = { STR_SAVELOAD_LOAD_CAPTION, STR_SAVELOAD_LOAD_SCENARIO, STR_SAVELOAD_SAVE_CAPTION, STR_SAVELOAD_SAVE_SCENARIO, STR_SAVELOAD_LOAD_HEIGHTMAP, }; assert((uint)mode < lengthof(saveload_captions)); /* Use an array to define what will be the current file type being handled * by current file mode */ switch (mode) { case SLD_SAVE_GAME: this->GenerateFileName(); break; case SLD_SAVE_SCENARIO: strecpy(this->edit_str_buf, "UNNAMED", &this->edit_str_buf[edit_str_size - 1]); break; default: break; } this->afilter = CS_ALPHANUMERAL; InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 240); this->CreateNestedTree(desc); if (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(SLWW_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL); this->GetWidget<NWidgetCore>(SLWW_WINDOWTITLE)->widget_data = saveload_captions[mode]; this->FinishInitNested(desc, 0); this->LowerWidget(SLWW_DRIVES_DIRECTORIES_LIST); /* pause is only used in single-player, non-editor mode, non-menu mode. It * will be unpaused in the WE_DESTROY event handler. */ if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) { DoCommandP(0, PM_PAUSED_SAVELOAD, 1, CMD_PAUSE); } SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0); this->OnInvalidateData(0); ResetObjectToPlace(); o_dir.type = FIOS_TYPE_DIRECT; switch (_saveload_mode) { case SLD_SAVE_GAME: case SLD_LOAD_GAME: FioGetDirectory(o_dir.name, lengthof(o_dir.name), SAVE_DIR); break; case SLD_SAVE_SCENARIO: case SLD_LOAD_SCENARIO: FioGetDirectory(o_dir.name, lengthof(o_dir.name), SCENARIO_DIR); break; case SLD_LOAD_HEIGHTMAP: FioGetDirectory(o_dir.name, lengthof(o_dir.name), HEIGHTMAP_DIR); break; default: strecpy(o_dir.name, _personal_dir, lastof(o_dir.name)); } /* Focus the edit box by default in the save windows */ if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { this->SetFocusedWidget(SLWW_SAVE_OSK_TITLE); } }
SaveLoadWindow(WindowDesc *desc, AbstractFileType abstract_filetype, SaveLoadOperation fop) : Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop), filter_editbox(EDITBOX_MAX_SIZE) { assert(this->fop == SLO_SAVE || this->fop == SLO_LOAD); /* For saving, construct an initial file name. */ if (this->fop == SLO_SAVE) { switch (this->abstract_filetype) { case FT_SAVEGAME: this->GenerateFileName(); break; case FT_SCENARIO: case FT_HEIGHTMAP: this->filename_editbox.text.Assign("UNNAMED"); break; default: NOT_REACHED(); } } this->querystrings[WID_SL_SAVE_OSK_TITLE] = &this->filename_editbox; this->filename_editbox.ok_button = WID_SL_SAVE_GAME; this->CreateNestedTree(true); if (this->fop == SLO_LOAD && this->abstract_filetype == FT_SAVEGAME) { this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL); } /* Select caption string of the window. */ StringID caption_string; switch (this->abstract_filetype) { case FT_SAVEGAME: caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION; break; case FT_SCENARIO: caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO; break; case FT_HEIGHTMAP: caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP; break; default: NOT_REACHED(); } this->GetWidget<NWidgetCore>(WID_SL_CAPTION)->widget_data = caption_string; this->vscroll = this->GetScrollbar(WID_SL_SCROLLBAR); this->FinishInitNested(0); this->LowerWidget(WID_SL_DRIVES_DIRECTORIES_LIST); this->querystrings[WID_SL_FILTER] = &this->filter_editbox; this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR; /* pause is only used in single-player, non-editor mode, non-menu mode. It * will be unpaused in the WE_DESTROY event handler. */ if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) { DoCommandP(0, PM_PAUSED_SAVELOAD, 1, CMD_PAUSE); } SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0); this->OnInvalidateData(SLIWD_RESCAN_FILES); ResetObjectToPlace(); /* Select the initial directory. */ o_dir.type = FIOS_TYPE_DIRECT; switch (this->abstract_filetype) { case FT_SAVEGAME: FioGetDirectory(o_dir.name, lastof(o_dir.name), SAVE_DIR); break; case FT_SCENARIO: FioGetDirectory(o_dir.name, lastof(o_dir.name), SCENARIO_DIR); break; case FT_HEIGHTMAP: FioGetDirectory(o_dir.name, lastof(o_dir.name), HEIGHTMAP_DIR); break; default: strecpy(o_dir.name, _personal_dir, lastof(o_dir.name)); } switch (this->fop) { case SLO_SAVE: /* Focus the edit box by default in the save window */ this->SetFocusedWidget(WID_SL_SAVE_OSK_TITLE); break; default: this->SetFocusedWidget(WID_SL_FILTER); } }