added loading newly created user level set after it was created in editor
authorHolger Schemel <info@artsoft.org>
Tue, 17 Oct 2017 19:27:18 +0000 (21:27 +0200)
committerHolger Schemel <info@artsoft.org>
Fri, 23 Mar 2018 22:21:14 +0000 (23:21 +0100)
src/editor.c
src/libgame/setup.c
src/libgame/setup.h

index 78864c6d34806f4aabb1649b010c71e28707c7f7..8da3feb9c03aa11ddf7e3055e2f686b64406bf00 100644 (file)
@@ -8236,6 +8236,26 @@ static void InitLevelSetInfo()
   levelset_save_mode = LEVELSET_SAVE_MODE_UPDATE;
 }
 
+static void ChangeEditorToLevelSet(char *levelset_subdir)
+{
+  leveldir_current = getTreeInfoFromIdentifier(leveldir_first, levelset_subdir);
+
+  // the previous level set might have used custom artwork
+  ReloadCustomArtwork(0);
+
+  LoadLevelSetup_SeriesInfo();
+
+  SaveLevelSetup_LastSeries();
+  SaveLevelSetup_SeriesInfo();
+
+  TapeErase();
+
+  LoadLevel(level_nr);
+  LoadScore(level_nr);
+
+  DrawLevelEd();
+}
+
 void DrawLevelEd()
 {
   int fade_mask = REDRAW_FIELD;
@@ -12639,13 +12659,14 @@ static void HandleTextbuttonGadgets(struct GadgetInfo *gi)
                             levelset_first_level_nr))
       {
        Request("New level set created!", REQ_CONFIRM);
+
+       AddUserLevelSetToLevelInfo(levelset_subdir);
+       ChangeEditorToLevelSet(levelset_subdir);
       }
       else
       {
        Request("Creating new level set failed!", REQ_CONFIRM);
       }
-
-      DrawLevelInfoWindow();   // update (increment) level set directory name
     }
   }
   else if (type_id == ED_TEXTBUTTON_ID_ADD_CHANGE_PAGE &&
index d683b67c6b13b736166c362496cf3b1a1ef4645e..62a8322a78ade618840ef4cd0d3a13ee30945376 100644 (file)
@@ -3516,6 +3516,49 @@ void LoadLevelArtworkInfo()
   print_timestamp_done("LoadLevelArtworkInfo");
 }
 
+static boolean AddUserLevelSetToLevelInfoExt(char *level_subdir_new)
+{
+  // get level info tree node of first (original) user level set
+  char *level_subdir_old = getLoginName();
+  LevelDirTree *leveldir_old = getTreeInfoFromIdentifier(leveldir_first,
+                                                        level_subdir_old);
+  if (leveldir_old == NULL)            // should not happen
+    return FALSE;
+
+  int draw_deactivation_mask = GetDrawDeactivationMask();
+
+  // override draw deactivation mask (temporarily disable drawing)
+  SetDrawDeactivationMask(REDRAW_ALL);
+
+  // load new level set config and add it next to first user level set
+  LoadLevelInfoFromLevelConf(&leveldir_old->next, NULL,
+                            leveldir_old->basepath, level_subdir_new);
+
+  // set draw deactivation mask to previous value
+  SetDrawDeactivationMask(draw_deactivation_mask);
+
+  // get level info tree node of newly added user level set
+  LevelDirTree *leveldir_new = getTreeInfoFromIdentifier(leveldir_first,
+                                                        level_subdir_new);
+  if (leveldir_new == NULL)            // should not happen
+    return FALSE;
+
+  // correct top link and parent node link of newly created tree node
+  leveldir_new->node_top    = leveldir_old->node_top;
+  leveldir_new->node_parent = leveldir_old->node_parent;
+
+  // sort level info tree to adjust position of newly added level set
+  sortTreeInfo(&leveldir_first);
+
+  return TRUE;
+}
+
+void AddUserLevelSetToLevelInfo(char *level_subdir_new)
+{
+  if (!AddUserLevelSetToLevelInfoExt(level_subdir_new))
+    Error(ERR_EXIT, "internal level set structure corrupted -- aborting");
+}
+
 boolean UpdateUserLevelSet(char *level_subdir,
                           char *level_name, char *level_author,
                           int num_levels, int first_level_nr)
index 5679506daccf361bf41d10c78f48750484e91a6d..7e45cb5ae9e8a279156f32102167966caccfe75d 100644 (file)
@@ -311,6 +311,7 @@ void LoadLevelInfo(void);
 void LoadArtworkInfo(void);
 void LoadLevelArtworkInfo(void);
 
+void AddUserLevelSetToLevelInfo(char *);
 boolean UpdateUserLevelSet(char *, char *, char *, int, int);
 boolean CreateUserLevelSet(char *, char *, char *, int, int);