summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2011-05-28 13:55:59 +0000
committeralberth <alberth@openttd.org>2011-05-28 13:55:59 +0000
commitc6f3ded6d54d79320c5cdf4daa5d09c713084ab5 (patch)
tree91301e5e0754af135babd1d5029f1746cf96cd2e
parentf1cae9960f37b853e1abc0c02b6c31590cc86cb1 (diff)
downloadopenttd-c6f3ded6d54d79320c5cdf4daa5d09c713084ab5.tar.xz
(svn r22513) -Add: Allow for saving a heightmap from the file dialogue window.
-rw-r--r--src/fios.h1
-rw-r--r--src/fios_gui.cpp40
-rw-r--r--src/lang/english.txt1
3 files changed, 28 insertions, 14 deletions
diff --git a/src/fios.h b/src/fios.h
index e9a20a9fb..c34de10e9 100644
--- a/src/fios.h
+++ b/src/fios.h
@@ -99,6 +99,7 @@ enum SaveLoadDialogMode {
SLD_SAVE_GAME, ///< Save a game.
SLD_SAVE_SCENARIO, ///< Save a scenario.
SLD_LOAD_HEIGHTMAP, ///< Load a heightmap.
+ SLD_SAVE_HEIGHTMAP, ///< Save a heightmap.
};
/** The different types of files that the system knows about. */
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
index c3b3be621..27c0f5625 100644
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -206,6 +206,7 @@ void BuildFileList()
case SLD_LOAD_SCENARIO:
case SLD_SAVE_SCENARIO:
FiosGetScenarioList(_saveload_mode); break;
+ case SLD_SAVE_HEIGHTMAP:
case SLD_LOAD_HEIGHTMAP:
FiosGetHeightmapList(_saveload_mode); break;
@@ -245,6 +246,7 @@ private:
Scrollbar *vscroll;
public:
+ /** Generate a default save filename. */
void GenerateFileName()
{
GenerateDefaultSaveName(this->edit_str_buf, &this->edit_str_buf[this->edit_str_size - 1]);
@@ -258,6 +260,7 @@ public:
STR_SAVELOAD_SAVE_CAPTION,
STR_SAVELOAD_SAVE_SCENARIO,
STR_SAVELOAD_LOAD_HEIGHTMAP,
+ STR_SAVELOAD_SAVE_HEIGHTMAP,
};
assert((uint)mode < lengthof(saveload_captions));
@@ -265,6 +268,7 @@ public:
* by current file mode */
switch (mode) {
case SLD_SAVE_GAME: this->GenerateFileName(); break;
+ case SLD_SAVE_HEIGHTMAP:
case SLD_SAVE_SCENARIO: strecpy(this->edit_str_buf, "UNNAMED", &this->edit_str_buf[edit_str_size - 1]); break;
default: break;
}
@@ -304,6 +308,7 @@ public:
FioGetDirectory(o_dir.name, lengthof(o_dir.name), SCENARIO_DIR);
break;
+ case SLD_SAVE_HEIGHTMAP:
case SLD_LOAD_HEIGHTMAP:
FioGetDirectory(o_dir.name, lengthof(o_dir.name), HEIGHTMAP_DIR);
break;
@@ -313,7 +318,7 @@ public:
}
/* Focus the edit box by default in the save windows */
- if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
+ if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) {
this->SetFocusedWidget(SLWW_SAVE_OSK_TITLE);
}
}
@@ -498,7 +503,7 @@ public:
this->vscroll->SetCount(_fios_items.Length());
this->DrawWidgets();
- if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
+ if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) {
this->DrawEditBox(SLWW_SAVE_OSK_TITLE);
}
}
@@ -564,7 +569,7 @@ public:
this->InvalidateData(1);
}
- if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
+ if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) {
/* Copy clicked name to editbox */
ttd_strlcpy(this->text.buf, file->title, this->text.max_bytes);
UpdateTextBufferSize(&this->text);
@@ -611,7 +616,7 @@ public:
virtual void OnMouseLoop()
{
- if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
+ if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) {
this->HandleEditBox(SLWW_SAVE_OSK_TITLE);
}
}
@@ -624,7 +629,7 @@ public:
}
EventState state = ES_NOT_HANDLED;
- if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) &&
+ if ((_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) &&
this->HandleEditBoxKey(SLWW_SAVE_OSK_TITLE, key, keycode, state) == HEBR_CONFIRM) {
this->HandleButtonClick(SLWW_SAVE_GAME);
}
@@ -635,8 +640,8 @@ public:
virtual void OnTimeout()
{
/* This test protects against using widgets 11 and 12 which are only available
- * in those two saveload mode */
- if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) return;
+ * in those saveload modes. */
+ if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP)) return;
if (this->IsWidgetLowered(SLWW_DELETE_SELECTION)) { // Delete button clicked
if (!FiosDelete(this->text.buf)) {
@@ -649,8 +654,13 @@ public:
UpdateTextBufferSize(&this->text);
} else if (this->IsWidgetLowered(SLWW_SAVE_GAME)) { // Save button clicked
- _switch_mode = SM_SAVE_GAME;
- FiosMakeSavegameName(_file_to_saveload.name, this->text.buf, sizeof(_file_to_saveload.name));
+ if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
+ _switch_mode = SM_SAVE_GAME;
+ FiosMakeSavegameName(_file_to_saveload.name, this->text.buf, sizeof(_file_to_saveload.name));
+ } else {
+ _switch_mode = SM_SAVE_HEIGHTMAP;
+ FiosMakeHeightmapName(_file_to_saveload.name, this->text.buf, sizeof(_file_to_saveload.name));
+ }
/* In the editor set up the vehicle engines correctly (date might have changed) */
if (_game_mode == GM_EDITOR) StartupEngines();
@@ -726,11 +736,12 @@ static const WindowDesc _save_dialog_desc(
* So each entry, as expressed by the related comment, is based on the enum
*/
static const FileType _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_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
};
/**
@@ -745,6 +756,7 @@ void ShowSaveLoadDialog(SaveLoadDialogMode mode)
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;
diff --git a/src/lang/english.txt b/src/lang/english.txt
index c8aeba440..68a8b5e3d 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2278,6 +2278,7 @@ STR_SAVELOAD_LOAD_CAPTION :{WHITE}Load Gam
STR_SAVELOAD_SAVE_SCENARIO :{WHITE}Save Scenario
STR_SAVELOAD_LOAD_SCENARIO :{WHITE}Load Scenario
STR_SAVELOAD_LOAD_HEIGHTMAP :{WHITE}Load Heightmap
+STR_SAVELOAD_SAVE_HEIGHTMAP :{WHITE}Save Heightmap
STR_SAVELOAD_HOME_BUTTON :{BLACK}Click here to jump to the current default save/load directory
STR_SAVELOAD_BYTES_FREE :{BLACK}{BYTES} free
STR_SAVELOAD_LIST_TOOLTIP :{BLACK}List of drives, directories and saved-game files