From: Holger Schemel Date: Tue, 17 Oct 2017 19:27:18 +0000 (+0200) Subject: added loading newly created user level set after it was created in editor X-Git-Tag: 4.1.0.0~92 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=3a3108d045227e21342a915ffc7e022e8eecbedc;p=rocksndiamonds.git added loading newly created user level set after it was created in editor --- diff --git a/src/editor.c b/src/editor.c index 78864c6d..8da3feb9 100644 --- a/src/editor.c +++ b/src/editor.c @@ -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 && diff --git a/src/libgame/setup.c b/src/libgame/setup.c index d683b67c..62a8322a 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -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) diff --git a/src/libgame/setup.h b/src/libgame/setup.h index 5679506d..7e45cb5a 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -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);