summaryrefslogtreecommitdiff
path: root/src/fios_gui.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2016-09-04 12:56:56 +0000
committeralberth <alberth@openttd.org>2016-09-04 12:56:56 +0000
commit88bdf482c0dc96661e3c8e89df44dcacea0199d7 (patch)
tree208483daee32fa031e628cbe44f42578576d3546 /src/fios_gui.cpp
parent75ad6d01003ec807918b6dbad85f17ecf35f8bc5 (diff)
downloadopenttd-88bdf482c0dc96661e3c8e89df44dcacea0199d7.tar.xz
(svn r27648) -Codechange: Remove remaining _saveload_mode usage.
Diffstat (limited to 'src/fios_gui.cpp')
-rw-r--r--src/fios_gui.cpp216
1 files changed, 111 insertions, 105 deletions
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);
}