summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2016-09-04 12:47:07 +0000
committeralberth <alberth@openttd.org>2016-09-04 12:47:07 +0000
commit2fa0fdb1768f45ffaf4fe14fbdbdb73d501d6c36 (patch)
treeffe7234137f524ab7c0ebf484c9d383e56311333
parent3b8ede5ebe74bafba528f0bf40942c1367cbcaee (diff)
downloadopenttd-2fa0fdb1768f45ffaf4fe14fbdbdb73d501d6c36.tar.xz
(svn r27638) -Codechange: Move FiosType enum, move and rename SetFiosType function.
-rw-r--r--src/console_cmds.cpp2
-rw-r--r--src/fileio_type.h15
-rw-r--r--src/fios.h15
-rw-r--r--src/fios_gui.cpp33
-rw-r--r--src/openttd.cpp2
-rw-r--r--src/saveload/saveload.cpp33
-rw-r--r--src/saveload/saveload.h2
7 files changed, 54 insertions, 48 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 8df5b15cd..67f3f6098 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -366,7 +366,7 @@ DEF_CONSOLE_CMD(ConLoad)
switch (item->type) {
case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE: {
_switch_mode = SM_LOAD_GAME;
- SetFiosType(item->type);
+ _file_to_saveload.SetMode(item->type);
strecpy(_file_to_saveload.name, FiosBrowseTo(item), lastof(_file_to_saveload.name));
strecpy(_file_to_saveload.title, item->title, lastof(_file_to_saveload.title));
diff --git a/src/fileio_type.h b/src/fileio_type.h
index fc50484f2..390b28f24 100644
--- a/src/fileio_type.h
+++ b/src/fileio_type.h
@@ -22,6 +22,21 @@ enum AbstractFileType {
FT_HEIGHTMAP, ///< heightmap file
};
+/** Elements of a file system that are recognized. */
+enum FiosType {
+ FIOS_TYPE_DRIVE,
+ FIOS_TYPE_PARENT,
+ FIOS_TYPE_DIR,
+ FIOS_TYPE_FILE,
+ FIOS_TYPE_OLDFILE,
+ FIOS_TYPE_SCENARIO,
+ FIOS_TYPE_OLD_SCENARIO,
+ FIOS_TYPE_DIRECT,
+ FIOS_TYPE_PNG,
+ FIOS_TYPE_BMP,
+ FIOS_TYPE_INVALID = 255,
+};
+
/**
* The different kinds of subdirectories OpenTTD uses
*/
diff --git a/src/fios.h b/src/fios.h
index 6ef7783b6..4ccd1f192 100644
--- a/src/fios.h
+++ b/src/fios.h
@@ -107,20 +107,6 @@ enum SaveLoadDialogMode {
SLD_SAVE_HEIGHTMAP, ///< Save a heightmap.
};
-enum FiosType {
- FIOS_TYPE_DRIVE,
- FIOS_TYPE_PARENT,
- FIOS_TYPE_DIR,
- FIOS_TYPE_FILE,
- FIOS_TYPE_OLDFILE,
- FIOS_TYPE_SCENARIO,
- FIOS_TYPE_OLD_SCENARIO,
- FIOS_TYPE_DIRECT,
- FIOS_TYPE_PNG,
- FIOS_TYPE_BMP,
- FIOS_TYPE_INVALID = 255,
-};
-
/** Deals with finding savegames */
struct FiosItem {
FiosType type;
@@ -163,6 +149,5 @@ int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
extern const TextColour _fios_colours[];
void BuildFileList(SaveLoadDialogMode mode);
-void SetFiosType(const byte fiostype);
#endif /* FIOS_H */
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
index 31f0b3d51..50a6711c6 100644
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -527,7 +527,7 @@ public:
case WID_SL_LOAD_BUTTON:
if (this->selected != NULL && !_load_check_data.HasErrors()) {
const char *name = FiosBrowseTo(this->selected);
- SetFiosType(this->selected->type);
+ _file_to_saveload.SetMode(this->selected->type);
strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
strecpy(_file_to_saveload.title, this->selected->title, lastof(_file_to_saveload.title));
@@ -588,7 +588,7 @@ public:
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) {
- SetFiosType(file->type);
+ _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));
@@ -772,32 +772,3 @@ void ShowSaveLoadDialog(SaveLoadDialogMode mode)
new SaveLoadWindow(sld, mode);
}
-
-void SetFiosType(const byte fiostype)
-{
- switch (fiostype) {
- case FIOS_TYPE_FILE:
- case FIOS_TYPE_SCENARIO:
- _file_to_saveload.mode = SL_LOAD;
- break;
-
- case FIOS_TYPE_OLDFILE:
- case FIOS_TYPE_OLD_SCENARIO:
- _file_to_saveload.mode = SL_OLD_LOAD;
- break;
-
-#ifdef WITH_PNG
- case FIOS_TYPE_PNG:
- _file_to_saveload.mode = SL_PNG;
- break;
-#endif /* WITH_PNG */
-
- case FIOS_TYPE_BMP:
- _file_to_saveload.mode = SL_BMP;
- break;
-
- default:
- _file_to_saveload.mode = SL_INVALID;
- break;
- }
-}
diff --git a/src/openttd.cpp b/src/openttd.cpp
index c149ebbd4..b5f654df6 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -626,7 +626,7 @@ int openttd_main(int argc, char *argv[])
const char *t = strrchr(_file_to_saveload.name, '.');
if (t != NULL) {
FiosType ft = FiosGetSavegameListCallback(SLD_LOAD_GAME, _file_to_saveload.name, t, NULL, NULL);
- if (ft != FIOS_TYPE_INVALID) SetFiosType(ft);
+ if (ft != FIOS_TYPE_INVALID) _file_to_saveload.SetMode(ft);
}
break;
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 03c0cb8c8..007b22f01 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -2892,6 +2892,39 @@ void GenerateDefaultSaveName(char *buf, const char *last)
SanitizeFilename(buf);
}
+/**
+ * Set the mode of the file to save or load based on the type of file entry at the file system.
+ * @param ft Type of file entry of the file system.
+ */
+void FileToSaveLoad::SetMode(FiosType ft)
+{
+ switch (ft) {
+ case FIOS_TYPE_FILE:
+ case FIOS_TYPE_SCENARIO:
+ this->mode = SL_LOAD;
+ break;
+
+ case FIOS_TYPE_OLDFILE:
+ case FIOS_TYPE_OLD_SCENARIO:
+ this->mode = SL_OLD_LOAD;
+ break;
+
+#ifdef WITH_PNG
+ case FIOS_TYPE_PNG:
+ this->mode = SL_PNG;
+ break;
+#endif /* WITH_PNG */
+
+ case FIOS_TYPE_BMP:
+ this->mode = SL_BMP;
+ break;
+
+ default:
+ this->mode = SL_INVALID;
+ break;
+ }
+}
+
#if 0
/**
* Function to get the type of the savegame by looking at the file header.
diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h
index 450fe58fe..43b9d5d3c 100644
--- a/src/saveload/saveload.h
+++ b/src/saveload/saveload.h
@@ -39,6 +39,8 @@ struct FileToSaveLoad {
AbstractFileType filetype; ///< what type of file are we dealing with
char name[MAX_PATH]; ///< name
char title[255]; ///< internal name of the game
+
+ void SetMode(FiosType ft);
};
/** Types of save games. */