added function to get existing or new user level set
authorHolger Schemel <info@artsoft.org>
Tue, 17 Oct 2017 16:39:20 +0000 (18:39 +0200)
committerHolger Schemel <info@artsoft.org>
Fri, 23 Mar 2018 22:21:14 +0000 (23:21 +0100)
src/editor.c

index ce772508756c57a322a451fec2dc922d1601fc4a..78864c6d34806f4aabb1649b010c71e28707c7f7 100644 (file)
@@ -8766,10 +8766,18 @@ static void DrawLevelInfoLevel()
     MapTextInputGadget(i);
 }
 
+static char *getLevelSubdirFromSaveMode(int save_mode)
+{
+  if (save_mode == LEVELSET_SAVE_MODE_CREATE)
+    return getNewUserLevelSubdir();
+
+  return leveldir_current->subdir;
+}
+
 static void DrawLevelInfoLevelSet_DirectoryInfo()
 {
   char *directory_text = "Level set directory:";
-  char *directory_name = leveldir_current->subdir;
+  char *directory_name = getLevelSubdirFromSaveMode(levelset_save_mode);
   int font1_nr = FONT_TEXT_1;
   int font2_nr = FONT_TEXT_2;
   int font1_height = getFontHeight(font1_nr);
@@ -8777,9 +8785,6 @@ static void DrawLevelInfoLevelSet_DirectoryInfo()
   int x = ED_LEVEL_SETTINGS_X(0);
   int y = ED_LEVEL_SETTINGS_Y(6);
 
-  if (levelset_save_mode == LEVELSET_SAVE_MODE_CREATE)
-    directory_name = getNewUserLevelSubdir();
-
   PrintInfoText(directory_text, font1_nr, x, y - yoffset_above);
   PrintInfoText(directory_name, font2_nr, x, y);
 }
@@ -12586,6 +12591,8 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
   }
   else if (type_id == ED_TEXTBUTTON_ID_SAVE_LEVELSET)
   {
+    char *levelset_subdir = getLevelSubdirFromSaveMode(levelset_save_mode);
+
     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE &&
        leveldir_current->readonly)
     {
@@ -12610,7 +12617,7 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
 
     if (levelset_save_mode == LEVELSET_SAVE_MODE_UPDATE)
     {
-      if (UpdateUserLevelSet(leveldir_current->subdir,
+      if (UpdateUserLevelSet(levelset_subdir,
                             levelset_name,
                             levelset_author,
                             levelset_num_levels,
@@ -12625,7 +12632,7 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
     }
     else
     {
-      if (CreateUserLevelSet(getNewUserLevelSubdir(),
+      if (CreateUserLevelSet(levelset_subdir,
                             levelset_name,
                             levelset_author,
                             levelset_num_levels,