From: Holger Schemel Date: Tue, 14 Mar 2017 19:16:05 +0000 (+0100) Subject: added new automatically saved config file for level editor zoom tile size X-Git-Tag: 4.1.0.0~155 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=092cfc403b3bcf3a390e961f594f28056b5f6aec;p=rocksndiamonds.git added new automatically saved config file for level editor zoom tile size --- diff --git a/src/editor.c b/src/editor.c index e714de15..504feba9 100644 --- a/src/editor.c +++ b/src/editor.c @@ -8148,8 +8148,16 @@ static int getMaxEdFieldY(boolean has_scrollbar) return max_ed_fieldy; } -void InitZoomLevelSettings() +void InitZoomLevelSettings(int zoom_tilesize) { + if (zoom_tilesize == -1) + zoom_tilesize = setup.auto_setup.editor_zoom_tilesize; + + // limit zoom tilesize by upper and lower bound + zoom_tilesize = MIN(MAX(MICRO_TILESIZE, zoom_tilesize), TILESIZE); + + ed_tilesize = setup.auto_setup.editor_zoom_tilesize = zoom_tilesize; + MAX_ED_FIELDX = getMaxEdFieldX(FALSE); MAX_ED_FIELDY = getMaxEdFieldY(FALSE); } @@ -8170,7 +8178,7 @@ void DrawLevelEd() ClearField(); - InitZoomLevelSettings(); + InitZoomLevelSettings(-1); OpenDoor(DOOR_OPEN_1 | DOOR_OPEN_2 | DOOR_NO_DELAY); @@ -12881,7 +12889,7 @@ static void HandleControlButtons(struct GadgetInfo *gi) // limit zoom level by upper and lower bound ed_tilesize = MIN(MAX(MICRO_TILESIZE, ed_tilesize), TILESIZE); - InitZoomLevelSettings(); + InitZoomLevelSettings(ed_tilesize); if (edit_mode == ED_MODE_DRAWING) { @@ -12891,6 +12899,9 @@ static void HandleControlButtons(struct GadgetInfo *gi) PrintEditorGadgetInfoText(level_editor_gadget[id]); } + /* save current editor zoom tilesize */ + SaveSetup_AutoSetup(); + break; case GADGET_ID_CUSTOM_COPY_FROM: diff --git a/src/files.c b/src/files.c index 2ba8e9e6..30e10f5a 100644 --- a/src/files.c +++ b/src/files.c @@ -8251,6 +8251,11 @@ void SaveScore(int nr) #define NUM_GLOBAL_SETUP_TOKENS 44 +/* auto setup */ +#define SETUP_TOKEN_AUTO_EDITOR_ZOOM_TILESIZE 0 + +#define NUM_AUTO_SETUP_TOKENS 1 + /* editor setup */ #define SETUP_TOKEN_EDITOR_EL_CLASSIC 0 #define SETUP_TOKEN_EDITOR_EL_CUSTOM 1 @@ -8389,6 +8394,7 @@ void SaveScore(int nr) static struct SetupInfo si; +static struct SetupAutoSetupInfo sasi; static struct SetupEditorInfo sei; static struct SetupEditorCascadeInfo seci; static struct SetupShortcutInfo ssi; @@ -8446,6 +8452,11 @@ static struct TokenInfo global_setup_tokens[] = { TYPE_INTEGER,&si.touch.drop_distance, "touch.drop_distance" }, }; +static struct TokenInfo auto_setup_tokens[] = +{ + { TYPE_INTEGER,&sasi.editor_zoom_tilesize, "editor.zoom_tilesize" }, +}; + static struct TokenInfo editor_setup_tokens[] = { { TYPE_SWITCH, &sei.el_classic, "editor.el_classic" }, @@ -8789,6 +8800,11 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) #endif } +static void setSetupInfoToDefaults_AutoSetup(struct SetupInfo *si) +{ + si->auto_setup.editor_zoom_tilesize = MINI_TILESIZE; +} + static void setSetupInfoToDefaults_EditorCascade(struct SetupInfo *si) { si->editor_cascade.el_bd = TRUE; @@ -8938,6 +8954,22 @@ static void decodeSetupFileHash(SetupFileHash *setup_file_hash) setup.options = soi; } +static void decodeSetupFileHash_AutoSetup(SetupFileHash *setup_file_hash) +{ + int i; + + if (!setup_file_hash) + return; + + /* auto setup */ + sasi = setup.auto_setup; + for (i = 0; i < NUM_AUTO_SETUP_TOKENS; i++) + setSetupInfo(auto_setup_tokens, i, + getHashEntry(setup_file_hash, + auto_setup_tokens[i].text)); + setup.auto_setup = sasi; +} + static void decodeSetupFileHash_EditorCascade(SetupFileHash *setup_file_hash) { int i; @@ -9012,6 +9044,26 @@ void LoadSetup() LoadSetup_SpecialPostProcessing(); } +void LoadSetup_AutoSetup() +{ + char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME); + SetupFileHash *setup_file_hash = NULL; + + /* always start with reliable default values */ + setSetupInfoToDefaults_AutoSetup(&setup); + + setup_file_hash = loadSetupFileHash(filename); + + if (setup_file_hash) + { + decodeSetupFileHash_AutoSetup(setup_file_hash); + + freeSetupFileHash(setup_file_hash); + } + + free(filename); +} + void LoadSetup_EditorCascade() { char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME); @@ -9162,6 +9214,34 @@ void SaveSetup() SetFilePermissions(filename, PERMS_PRIVATE); } +void SaveSetup_AutoSetup() +{ + char *filename = getPath2(getSetupDir(), AUTOSETUP_FILENAME); + FILE *file; + int i; + + InitUserDataDirectory(); + + if (!(file = fopen(filename, MODE_WRITE))) + { + Error(ERR_WARN, "cannot write auto setup file '%s'", filename); + free(filename); + return; + } + + fprintFileHeader(file, AUTOSETUP_FILENAME); + + sasi = setup.auto_setup; + for (i = 0; i < NUM_AUTO_SETUP_TOKENS; i++) + fprintf(file, "%s\n", getSetupLine(auto_setup_tokens, "", i)); + + fclose(file); + + SetFilePermissions(filename, PERMS_PRIVATE); + + free(filename); +} + void SaveSetup_EditorCascade() { char *filename = getPath2(getSetupDir(), EDITORCASCADE_FILENAME); diff --git a/src/files.h b/src/files.h index f12faca9..bfad4958 100644 --- a/src/files.h +++ b/src/files.h @@ -60,6 +60,9 @@ void LoadSetupFromFilename(char *); void LoadSetup(); void SaveSetup(); +void LoadSetup_AutoSetup(); +void SaveSetup_AutoSetup(); + void LoadSetup_EditorCascade(); void SaveSetup_EditorCascade(); diff --git a/src/init.c b/src/init.c index 4bde60f9..8817d963 100644 --- a/src/init.c +++ b/src/init.c @@ -5039,6 +5039,7 @@ void Execute_Command(char *command) static void InitSetup() { LoadSetup(); /* global setup info */ + LoadSetup_AutoSetup(); /* global auto setup info */ /* set some options from setup file */ diff --git a/src/libgame/system.h b/src/libgame/system.h index 730c8a7f..2fd5e97b 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -517,6 +517,7 @@ /* file names and filename extensions */ #define LEVELSETUP_DIRECTORY "levelsetup" #define SETUP_FILENAME "setup.conf" +#define AUTOSETUP_FILENAME "autosetup.conf" #define LEVELSETUP_FILENAME "levelsetup.conf" #define EDITORSETUP_FILENAME "editorsetup.conf" #define EDITORCASCADE_FILENAME "editorcascade.conf" @@ -1016,6 +1017,11 @@ struct SetupEditorInfo boolean use_template_for_new_levels; }; +struct SetupAutoSetupInfo +{ + int editor_zoom_tilesize; +}; + struct SetupEditorCascadeInfo { boolean el_bd; @@ -1155,6 +1161,7 @@ struct SetupInfo int volume_loops; int volume_music; + struct SetupAutoSetupInfo auto_setup; struct SetupEditorInfo editor; struct SetupEditorCascadeInfo editor_cascade; struct SetupShortcutInfo shortcut;