diff options
-rw-r--r-- | src/fios.h | 13 | ||||
-rw-r--r-- | src/fios_gui.cpp | 216 | ||||
-rw-r--r-- | src/intro_gui.cpp | 6 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 6 | ||||
-rw-r--r-- | src/toolbar_gui.cpp | 14 |
5 files changed, 125 insertions, 130 deletions
diff --git a/src/fios.h b/src/fios.h index 1c61492af..86bcf3e3a 100644 --- a/src/fios.h +++ b/src/fios.h @@ -97,16 +97,6 @@ enum FileSlots { MAX_FILE_SLOTS = 64 }; -/** Mode of the file dialogue window. */ -enum SaveLoadDialogMode { - SLD_LOAD_GAME, ///< Load a game. - SLD_LOAD_SCENARIO, ///< Load a scenario. - SLD_SAVE_GAME, ///< Save a game. - SLD_SAVE_SCENARIO, ///< Save a scenario. - SLD_LOAD_HEIGHTMAP, ///< Load a heightmap. - SLD_SAVE_HEIGHTMAP, ///< Save a heightmap. -}; - /** Deals with finding savegames */ struct FiosItem { FiosType type; @@ -215,10 +205,9 @@ enum SortingBits { DECLARE_ENUM_AS_BIT_SET(SortingBits) /* Variables to display file lists */ -extern SaveLoadDialogMode _saveload_mode; extern SortingBits _savegame_sort_order; -void ShowSaveLoadDialog(SaveLoadDialogMode mode); +void ShowSaveLoadDialog(AbstractFileType abstract_filetype, FileOperation fop); void FiosGetSavegameList(FileOperation fop, FileList &file_list); void FiosGetScenarioList(FileOperation fop, FileList &file_list); diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index e217ab6e1..e902941d6 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -36,7 +36,6 @@ #include "safeguards.h" -SaveLoadDialogMode _saveload_mode; LoadCheckData _load_check_data; ///< Data loaded from save during SL_LOAD_CHECK. static bool _fios_path_changed; @@ -222,6 +221,8 @@ static void SortSaveGameList(FileList &file_list) struct SaveLoadWindow : public Window { private: QueryString filename_editbox; ///< Filename editbox. + AbstractFileType abstract_filetype; /// Type of file to select. + FileOperation fop; ///< File operation to perform. FileList fios_items; ///< Save game list. FiosItem o_dir; const FiosItem *selected; ///< Selected game in #fios_items, or \c NULL. @@ -235,35 +236,56 @@ public: this->filename_editbox.text.UpdateSize(); } - SaveLoadWindow(WindowDesc *desc, SaveLoadDialogMode mode) : Window(desc), filename_editbox(64) + SaveLoadWindow(WindowDesc *desc, AbstractFileType abstract_filetype, FileOperation fop) + : Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop) { - 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, - STR_SAVELOAD_SAVE_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_HEIGHTMAP: - case SLD_SAVE_SCENARIO: this->filename_editbox.text.Assign("UNNAMED"); break; - default: break; + assert(this->fop == FOP_SAVE || this->fop == FOP_LOAD); + + /* For saving, construct an initial file name. */ + if (this->fop == FOP_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 (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL); - this->GetWidget<NWidgetCore>(WID_SL_CAPTION)->widget_data = saveload_captions[mode]; - this->vscroll = this->GetScrollbar(WID_SL_SCROLLBAR); + if (this->fop == FOP_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 == FOP_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION; + break; + + case FT_SCENARIO: + caption_string = (this->fop == FOP_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO; + break; + case FT_HEIGHTMAP: + caption_string = (this->fop == FOP_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); @@ -279,20 +301,18 @@ public: ResetObjectToPlace(); + /* Select the initial directory. */ o_dir.type = FIOS_TYPE_DIRECT; - switch (_saveload_mode) { - case SLD_SAVE_GAME: - case SLD_LOAD_GAME: + switch (this->abstract_filetype) { + case FT_SAVEGAME: FioGetDirectory(o_dir.name, lastof(o_dir.name), SAVE_DIR); break; - case SLD_SAVE_SCENARIO: - case SLD_LOAD_SCENARIO: + case FT_SCENARIO: FioGetDirectory(o_dir.name, lastof(o_dir.name), SCENARIO_DIR); break; - case SLD_SAVE_HEIGHTMAP: - case SLD_LOAD_HEIGHTMAP: + case FT_HEIGHTMAP: FioGetDirectory(o_dir.name, lastof(o_dir.name), HEIGHTMAP_DIR); break; @@ -301,9 +321,7 @@ public: } /* Focus the edit box by default in the save windows */ - if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) { - this->SetFocusedWidget(WID_SL_SAVE_OSK_TITLE); - } + if (this->fop == FOP_SAVE) this->SetFocusedWidget(WID_SL_SAVE_OSK_TITLE); } virtual ~SaveLoadWindow() @@ -405,7 +423,7 @@ public: if (y > y_max) break; /* Hide current date for scenarios */ - if (_saveload_mode != SLD_LOAD_SCENARIO && _saveload_mode != SLD_SAVE_SCENARIO) { + if (this->abstract_filetype != FT_SCENARIO) { /* Current date */ SetDParam(0, _load_check_data.current_date); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CURRENT_DATE); @@ -413,7 +431,7 @@ public: } /* Hide the NewGRF stuff when saving. We also hide the button. */ - if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) { + if (this->fop == FOP_LOAD && (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO)) { y += WD_PAR_VSEP_NORMAL; if (y > y_max) break; @@ -426,7 +444,7 @@ public: if (y > y_max) break; /* Hide the company stuff for scenarios */ - if (_saveload_mode != SLD_LOAD_SCENARIO && _saveload_mode != SLD_SAVE_SCENARIO) { + if (this->abstract_filetype != FT_SCENARIO) { y += FONT_HEIGHT_NORMAL; if (y > y_max) break; @@ -516,9 +534,10 @@ public: strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name)); strecpy(_file_to_saveload.title, this->selected->title, lastof(_file_to_saveload.title)); - if (_saveload_mode == SLD_LOAD_HEIGHTMAP) { + if (this->abstract_filetype == FT_HEIGHTMAP) { delete this; ShowHeightmapLoad(); + } else if (!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()) { _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD_GAME; ClearErrorMessages(); @@ -562,22 +581,25 @@ public: this->InvalidateData(1); } - if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) { + if (this->fop == FOP_SAVE) { /* Copy clicked name to editbox */ this->filename_editbox.text.Assign(file->title); this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE); } } else if (!_load_check_data.HasErrors()) { this->selected = file; - if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) { - this->OnClick(pt, WID_SL_LOAD_BUTTON, 1); - } else if (_saveload_mode == SLD_LOAD_HEIGHTMAP) { - _file_to_saveload.SetMode(file->type); - strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name)); - strecpy(_file_to_saveload.title, file->title, lastof(_file_to_saveload.title)); - - delete this; - ShowHeightmapLoad(); + if (this->fop == FOP_LOAD) { + if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) { + this->OnClick(pt, WID_SL_LOAD_BUTTON, 1); + } else { + assert(this->abstract_filetype == FT_HEIGHTMAP); + _file_to_saveload.SetMode(file->type); + strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name)); + strecpy(_file_to_saveload.title, file->title, lastof(_file_to_saveload.title)); + + delete this; + ShowHeightmapLoad(); + } } } } else { @@ -592,10 +614,11 @@ public: ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR); } else { #if defined(ENABLE_NETWORK) - switch (_saveload_mode) { + assert(this->fop == FOP_LOAD); + switch (this->abstract_filetype) { default: NOT_REACHED(); - case SLD_LOAD_SCENARIO: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_SCENARIO); break; - case SLD_LOAD_HEIGHTMAP: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP); break; + case FT_SCENARIO: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_SCENARIO); break; + case FT_HEIGHTMAP: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP); break; } #endif } @@ -623,9 +646,8 @@ public: virtual void OnTimeout() { - /* This test protects against using widgets 11 and 12 which are only available - * in those saveload modes. */ - if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP)) return; + /* Widgets WID_SL_DELETE_SELECTION and WID_SL_SAVE_GAME only exist when saving to a file. */ + if (this->fop != FOP_SAVE) return; if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked if (!FiosDelete(this->filename_editbox.text.buf)) { @@ -633,10 +655,10 @@ public: } else { this->InvalidateData(); /* Reset file name to current date on successful delete */ - if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName(); + if (this->abstract_filetype == FT_SAVEGAME) GenerateFileName(); } } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked - if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { + if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) { _switch_mode = SM_SAVE_GAME; FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); } else { @@ -669,19 +691,7 @@ public: if (!gui_scope) break; _fios_path_changed = true; - - AbstractFileType abstract_filetype; - FileOperation fop; - switch (_saveload_mode) { - case SLD_LOAD_GAME: abstract_filetype = FT_SAVEGAME; fop = FOP_LOAD; break; - case SLD_LOAD_SCENARIO: abstract_filetype = FT_SCENARIO; fop = FOP_LOAD; break; - case SLD_SAVE_GAME: abstract_filetype = FT_SAVEGAME; fop = FOP_SAVE; break; - case SLD_SAVE_SCENARIO: abstract_filetype = FT_SCENARIO; fop = FOP_SAVE; break; - case SLD_LOAD_HEIGHTMAP: abstract_filetype = FT_HEIGHTMAP; fop = FOP_LOAD; break; - case SLD_SAVE_HEIGHTMAP: abstract_filetype = FT_HEIGHTMAP; fop = FOP_SAVE; break; - default: NOT_REACHED(); - } - this->fios_items.BuildFileList(abstract_filetype, fop); + this->fios_items.BuildFileList(this->abstract_filetype, this->fop); this->vscroll->SetCount(this->fios_items.Length()); this->selected = NULL; _load_check_data.Clear(); @@ -689,16 +699,29 @@ public: case 1: /* Selection changes */ if (!gui_scope) break; - if (_saveload_mode == SLD_LOAD_HEIGHTMAP) { - this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == NULL || _load_check_data.HasErrors()); - } - if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) { - this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, - this->selected == NULL || _load_check_data.HasErrors() || !(!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs())); - this->SetWidgetDisabledState(WID_SL_NEWGRF_INFO, - !_load_check_data.HasNewGrfs()); - this->SetWidgetDisabledState(WID_SL_MISSING_NEWGRFS, - !_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility == GLC_ALL_GOOD); + + if (this->fop != FOP_LOAD) break; + + switch (this->abstract_filetype) { + case FT_HEIGHTMAP: + this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == NULL || _load_check_data.HasErrors()); + break; + + case FT_SAVEGAME: + case FT_SCENARIO: { + bool disabled = this->selected == NULL || _load_check_data.HasErrors(); + if (!_settings_client.gui.UserIsAllowedToChangeNewGRFs()) { + disabled |= _load_check_data.HasNewGrfs() && _load_check_data.grf_compatibility == GLC_NOT_FOUND; + } + this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, disabled); + this->SetWidgetDisabledState(WID_SL_NEWGRF_INFO, !_load_check_data.HasNewGrfs()); + this->SetWidgetDisabledState(WID_SL_MISSING_NEWGRFS, + !_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility == GLC_ALL_GOOD); + break; + } + + default: + NOT_REACHED(); } break; } @@ -730,40 +753,23 @@ static WindowDesc _save_dialog_desc( ); /** - * These values are used to convert the file/operations mode into a corresponding file type. - * So each entry, as expressed by the related comment, is based on the enum - */ -static const AbstractFileType _file_modetotype[] = { - FT_SAVEGAME, // used for SLD_LOAD_GAME - FT_SCENARIO, // used for SLD_LOAD_SCENARIO - FT_SAVEGAME, // used for SLD_SAVE_GAME - FT_SCENARIO, // used for SLD_SAVE_SCENARIO - FT_HEIGHTMAP, // used for SLD_LOAD_HEIGHTMAP - FT_HEIGHTMAP, // used for SLD_SAVE_HEIGHTMAP -}; - -/** * Launch save/load dialog in the given mode. - * @param mode Save/load mode. + * @param abstract_filetype Kind of file to handle. + * @param fop File operation to perform (load or save). */ -void ShowSaveLoadDialog(SaveLoadDialogMode mode) +void ShowSaveLoadDialog(AbstractFileType abstract_filetype, FileOperation fop) { DeleteWindowById(WC_SAVELOAD, 0); WindowDesc *sld; - switch (mode) { - case SLD_SAVE_GAME: - case SLD_SAVE_SCENARIO: - case SLD_SAVE_HEIGHTMAP: - sld = &_save_dialog_desc; break; - case SLD_LOAD_HEIGHTMAP: - sld = &_load_heightmap_dialog_desc; break; - default: - sld = &_load_dialog_desc; break; + if (fop == FOP_SAVE) { + sld = &_save_dialog_desc; + } else { + /* Dialogue for loading a file. */ + sld = (abstract_filetype == FT_HEIGHTMAP) ? &_load_heightmap_dialog_desc : &_load_dialog_desc; } - _saveload_mode = mode; - _file_to_saveload.filetype = _file_modetotype[mode]; + _file_to_saveload.filetype = abstract_filetype; - new SaveLoadWindow(sld, mode); + new SaveLoadWindow(sld, abstract_filetype, fop); } diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index de8b37939..b6ac73cb7 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -111,9 +111,9 @@ struct SelectGameWindow : public Window { } break; - case WID_SGI_LOAD_GAME: ShowSaveLoadDialog(SLD_LOAD_GAME); break; - case WID_SGI_PLAY_SCENARIO: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break; - case WID_SGI_PLAY_HEIGHTMAP: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break; + case WID_SGI_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, FOP_LOAD); break; + case WID_SGI_PLAY_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, FOP_LOAD); break; + case WID_SGI_PLAY_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,FOP_LOAD); break; case WID_SGI_EDIT_SCENARIO: StartScenarioEditor(); break; case WID_SGI_PLAY_NETWORK: diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 7c04ad4e0..c3aef5b0f 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1187,17 +1187,17 @@ struct NetworkStartServerWindow : public Window { case WID_NSS_LOAD_GAME: _is_network_server = true; - ShowSaveLoadDialog(SLD_LOAD_GAME); + ShowSaveLoadDialog(FT_SAVEGAME, FOP_LOAD); break; case WID_NSS_PLAY_SCENARIO: _is_network_server = true; - ShowSaveLoadDialog(SLD_LOAD_SCENARIO); + ShowSaveLoadDialog(FT_SCENARIO, FOP_LOAD); break; case WID_NSS_PLAY_HEIGHTMAP: _is_network_server = true; - ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); + ShowSaveLoadDialog(FT_HEIGHTMAP,FOP_LOAD); break; } } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 40c75ad71..55b49fd74 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -427,17 +427,17 @@ static CallBackFunction MenuClickSaveLoad(int index = 0) { if (_game_mode == GM_EDITOR) { switch (index) { - case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(SLD_SAVE_SCENARIO); break; - case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break; - case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(SLD_SAVE_HEIGHTMAP); break; - case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break; + case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, FOP_SAVE); break; + case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, FOP_LOAD); break; + case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,FOP_SAVE); break; + case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,FOP_LOAD); break; case SLEME_EXIT_TOINTRO: AskExitToGameMenu(); break; case SLEME_EXIT_GAME: HandleExitGameRequest(); break; } } else { switch (index) { - case SLNME_SAVE_GAME: ShowSaveLoadDialog(SLD_SAVE_GAME); break; - case SLNME_LOAD_GAME: ShowSaveLoadDialog(SLD_LOAD_GAME); break; + case SLNME_SAVE_GAME: ShowSaveLoadDialog(FT_SAVEGAME, FOP_SAVE); break; + case SLNME_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, FOP_LOAD); break; case SLNME_EXIT_TOINTRO: AskExitToGameMenu(); break; case SLNME_EXIT_GAME: HandleExitGameRequest(); break; } @@ -1712,7 +1712,7 @@ struct MainToolbarWindow : Window { case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break; case MTHK_SETTINGS: ShowGameOptions(); break; case MTHK_SAVEGAME: MenuClickSaveLoad(); break; - case MTHK_LOADGAME: ShowSaveLoadDialog(SLD_LOAD_GAME); break; + case MTHK_LOADGAME: ShowSaveLoadDialog(FT_SAVEGAME, FOP_LOAD); break; case MTHK_SMALLMAP: ShowSmallMap(); break; case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break; case MTHK_SUBSIDIES: ShowSubsidiesList(); break; |