From 00aba83ad99eeecbd5aeedd49ec4f086a1f42fef Mon Sep 17 00:00:00 2001 From: cirdan Date: Fri, 13 Oct 2017 20:41:12 +0200 Subject: [PATCH] Use a simple formula for the subdirectory in SaveLoadWindow Use a simple arithmetic formula to compute the subdirectory to use for a given file type in the constructor of struct SaveLoadWindow. There are static assertions in place to ensure that we catch changes to the enum values that make the formula fail. --- src/fios_gui.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 722407a32..e0d1b19ab 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -298,24 +298,12 @@ public: o_dir.type = FIOS_TYPE_DIRECT; o_dir.mtime = 0; o_dir.title[0] = '\0'; - Subdirectory subdir; - switch (this->abstract_filetype) { - case FT_SAVEGAME: - subdir = SAVE_DIR; - break; - - case FT_SCENARIO: - subdir = SCENARIO_DIR; - break; - case FT_HEIGHTMAP: - subdir = HEIGHTMAP_DIR; - break; - - default: - NOT_REACHED(); - } - FioGetDirectory (o_dir.name, lengthof(o_dir.name), subdir); + assert_compile ((FT_SAVEGAME * 3) / 2 == SAVE_DIR); + assert_compile ((FT_SCENARIO * 3) / 2 == SCENARIO_DIR); + assert_compile ((FT_HEIGHTMAP * 3) / 2 == HEIGHTMAP_DIR); + FioGetDirectory (o_dir.name, lengthof(o_dir.name), + (Subdirectory) ((this->abstract_filetype * 3) / 2)); /* Focus the edit box by default in the save windows */ if (save) this->SetFocusedWidget (WID_SL_SAVE_OSK_TITLE); -- 2.11.4.GIT