added new automatically saved config file for level editor zoom tile size
authorHolger Schemel <info@artsoft.org>
Tue, 14 Mar 2017 19:16:05 +0000 (20:16 +0100)
committerHolger Schemel <info@artsoft.org>
Fri, 23 Mar 2018 22:21:11 +0000 (23:21 +0100)
src/editor.c
src/files.c
src/files.h
src/init.c
src/libgame/system.h

index e714de15eb1a634968cec358c17b4bfc6b24817b..504feba9855f18f5957ea3e2f92975ff3b5f902c 100644 (file)
@@ -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:
index 2ba8e9e6126e867d8f5c7edc6b92479707e1711f..30e10f5a5f60c7e50acd1af37109a68d62d12808 100644 (file)
@@ -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);
index f12faca99c9e2206074f4977e5d8d08847210782..bfad49584446ca850f3b644567aad72254168c95 100644 (file)
@@ -60,6 +60,9 @@ void LoadSetupFromFilename(char *);
 void LoadSetup();
 void SaveSetup();
 
+void LoadSetup_AutoSetup();
+void SaveSetup_AutoSetup();
+
 void LoadSetup_EditorCascade();
 void SaveSetup_EditorCascade();
 
index 4bde60f91115bb361ca862c91a67bab34e164d78..8817d9634e95a0e039ff029df600da25d916eb20 100644 (file)
@@ -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 */
 
index 730c8a7fd1e3c245bc8283aac4886b271358ac6d..2fd5e97b7fde94f66eaaf79d4da28450a4c0aeb0 100644 (file)
 /* 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;