fixed bug with restarting same menu music on different screens
[rocksndiamonds.git] / src / files.c
index ed5274695887f47821a88e08af6ab9366d579cdf..c0f256c73c27016f42c2af688f47f97cc0769111 100644 (file)
@@ -1786,10 +1786,41 @@ static void setFileInfoToDefaults(struct LevelFileInfo *level_file_info)
   level_file_info->filename = NULL;
 }
 
+int getMappedElement_SB(int, boolean);
+
 static void ActivateLevelTemplate()
 {
   int x, y;
 
+  if (check_special_flags("load_xsb_to_ces"))
+  {
+    /* fill smaller playfields with padding "beyond border wall" elements */
+    if (level.fieldx < level_template.fieldx ||
+       level.fieldy < level_template.fieldy)
+    {
+      short field[level.fieldx][level.fieldy];
+      int new_fieldx = MAX(level.fieldx, level_template.fieldx);
+      int new_fieldy = MAX(level.fieldy, level_template.fieldy);
+      int pos_fieldx = (new_fieldx - level.fieldx) / 2;
+      int pos_fieldy = (new_fieldy - level.fieldy) / 2;
+
+      /* copy old playfield (which is smaller than the visible area) */
+      for (y = 0; y < level.fieldy; y++) for (x = 0; x < level.fieldx; x++)
+       field[x][y] = level.field[x][y];
+
+      /* fill new, larger playfield with "beyond border wall" elements */
+      for (y = 0; y < new_fieldy; y++) for (x = 0; x < new_fieldx; x++)
+       level.field[x][y] = getMappedElement_SB('_', TRUE);
+
+      /* copy the old playfield to the middle of the new playfield */
+      for (y = 0; y < level.fieldy; y++) for (x = 0; x < level.fieldx; x++)
+       level.field[pos_fieldx + x][pos_fieldy + y] = field[x][y];
+
+      level.fieldx = new_fieldx;
+      level.fieldy = new_fieldy;
+    }
+  }
+
   /* Currently there is no special action needed to activate the template
      data, because 'element_info' property settings overwrite the original
      level data, while all other variables do not change. */
@@ -5756,32 +5787,6 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level,
   {
     /* special global settings can now be set in level template */
 
-    /* fill smaller playfields with padding "beyond border wall" elements */
-    if (level->fieldx < SCR_FIELDX ||
-       level->fieldy < SCR_FIELDY)
-    {
-      short field[level->fieldx][level->fieldy];
-      int new_fieldx = MAX(level->fieldx, SCR_FIELDX);
-      int new_fieldy = MAX(level->fieldy, SCR_FIELDY);
-      int pos_fieldx = (new_fieldx - level->fieldx) / 2;
-      int pos_fieldy = (new_fieldy - level->fieldy) / 2;
-
-      /* copy old playfield (which is smaller than the visible area) */
-      for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++)
-       field[x][y] = level->field[x][y];
-
-      /* fill new, larger playfield with "beyond border wall" elements */
-      for (y = 0; y < new_fieldy; y++) for (x = 0; x < new_fieldx; x++)
-       level->field[x][y] = getMappedElement_SB('_', load_xsb_to_ces);
-
-      /* copy the old playfield to the middle of the new playfield */
-      for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++)
-       level->field[pos_fieldx + x][pos_fieldy + y] = field[x][y];
-
-      level->fieldx = new_fieldx;
-      level->fieldy = new_fieldy;
-    }
-
     level->use_custom_template = TRUE;
   }
 }
@@ -8966,12 +8971,48 @@ static void InitMenuDesignSettings_SpecialPostProcessing()
 
   /* set default position for snapshot buttons to stop/pause/play buttons */
   for (i = 0; game_buttons_xy[i].dst != NULL; i++)
-  {
     if ((*game_buttons_xy[i].dst).x == -1 &&
        (*game_buttons_xy[i].dst).y == -1)
+      *game_buttons_xy[i].dst = *game_buttons_xy[i].src;
+}
+
+static void InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics()
+{
+  static struct
+  {
+    struct XYTileSize *dst, *src;
+    int graphic;
+  }
+  editor_buttons_xy[] =
+  {
+    {
+      &editor.button.element_left,     &editor.palette.element_left,
+      IMG_GFX_EDITOR_BUTTON_ELEMENT_LEFT
+    },
     {
-      (*game_buttons_xy[i].dst).x = (*game_buttons_xy[i].src).x;
-      (*game_buttons_xy[i].dst).y = (*game_buttons_xy[i].src).y;
+      &editor.button.element_middle,   &editor.palette.element_middle,
+      IMG_GFX_EDITOR_BUTTON_ELEMENT_MIDDLE
+    },
+    {
+      &editor.button.element_right,    &editor.palette.element_right,
+      IMG_GFX_EDITOR_BUTTON_ELEMENT_RIGHT
+    },
+
+    { NULL,                    NULL                    }
+  };
+  int i;
+
+  /* set default position for element buttons to element graphics */
+  for (i = 0; editor_buttons_xy[i].dst != NULL; i++)
+  {
+    if ((*editor_buttons_xy[i].dst).x == -1 &&
+       (*editor_buttons_xy[i].dst).y == -1)
+    {
+      struct GraphicInfo *gd = &graphic_info[editor_buttons_xy[i].graphic];
+
+      gd->width = gd->height = editor_buttons_xy[i].src->tile_size;
+
+      *editor_buttons_xy[i].dst = *editor_buttons_xy[i].src;
     }
   }
 }
@@ -9359,6 +9400,11 @@ void LoadMenuDesignSettings()
   InitMenuDesignSettings_SpecialPostProcessing();
 }
 
+void LoadMenuDesignSettings_AfterGraphics()
+{
+  InitMenuDesignSettings_SpecialPostProcessing_AfterGraphics();
+}
+
 void LoadUserDefinedEditorElementList(int **elements, int *num_elements)
 {
   char *filename = getEditorSetupFilename();
@@ -9996,15 +10042,15 @@ void ConvertLevels()
 
   convert_level_nr = convert_leveldir->first_level;
 
-  printf_line("=", 79);
-  printf("Converting levels\n");
-  printf_line("-", 79);
-  printf("Level series identifier: '%s'\n", convert_leveldir->identifier);
-  printf("Level series name:       '%s'\n", convert_leveldir->name);
-  printf("Level series author:     '%s'\n", convert_leveldir->author);
-  printf("Number of levels:        %d\n",   convert_leveldir->levels);
-  printf_line("=", 79);
-  printf("\n");
+  PrintLine("=", 79);
+  Print("Converting levels\n");
+  PrintLine("-", 79);
+  Print("Level series identifier: '%s'\n", convert_leveldir->identifier);
+  Print("Level series name:       '%s'\n", convert_leveldir->name);
+  Print("Level series author:     '%s'\n", convert_leveldir->author);
+  Print("Number of levels:        %d\n",   convert_leveldir->levels);
+  PrintLine("=", 79);
+  Print("\n");
 
   for (i = 0; i < MAX_NUM_CONVERT_LEVELS; i++)
     levels_failed[i] = FALSE;
@@ -10016,16 +10062,16 @@ void ConvertLevels()
 
     level_nr = convert_level_nr++;
 
-    printf("Level %03d: ", level_nr);
+    Print("Level %03d: ", level_nr);
 
     LoadLevel(level_nr);
     if (level.no_valid_file)
     {
-      printf("(no level)\n");
+      Print("(no level)\n");
       continue;
     }
 
-    printf("converting level ... ");
+    Print("converting level ... ");
 
     level_filename = getDefaultLevelFilename(level_nr);
     new_level = !fileExists(level_filename);
@@ -10036,28 +10082,28 @@ void ConvertLevels()
 
       num_levels_converted++;
 
-      printf("converted.\n");
+      Print("converted.\n");
     }
     else
     {
       if (level_nr >= 0 && level_nr < MAX_NUM_CONVERT_LEVELS)
        levels_failed[level_nr] = TRUE;
 
-      printf("NOT CONVERTED -- LEVEL ALREADY EXISTS.\n");
+      Print("NOT CONVERTED -- LEVEL ALREADY EXISTS.\n");
     }
 
     num_levels_handled++;
   }
 
-  printf("\n");
-  printf_line("=", 79);
-  printf("Number of levels handled: %d\n", num_levels_handled);
-  printf("Number of levels converted: %d (%d%%)\n", num_levels_converted,
+  Print("\n");
+  PrintLine("=", 79);
+  Print("Number of levels handled: %d\n", num_levels_handled);
+  Print("Number of levels converted: %d (%d%%)\n", num_levels_converted,
         (num_levels_handled ?
          num_levels_converted * 100 / num_levels_handled : 0));
-  printf_line("-", 79);
-  printf("Summary (for automatic parsing by scripts):\n");
-  printf("LEVELDIR '%s', CONVERTED %d/%d (%d%%)",
+  PrintLine("-", 79);
+  Print("Summary (for automatic parsing by scripts):\n");
+  Print("LEVELDIR '%s', CONVERTED %d/%d (%d%%)",
         convert_leveldir->identifier, num_levels_converted,
         num_levels_handled,
         (num_levels_handled ?
@@ -10065,14 +10111,14 @@ void ConvertLevels()
 
   if (num_levels_handled != num_levels_converted)
   {
-    printf(", FAILED:");
+    Print(", FAILED:");
     for (i = 0; i < MAX_NUM_CONVERT_LEVELS; i++)
       if (levels_failed[i])
-       printf(" %03d", i);
+       Print(" %03d", i);
   }
 
-  printf("\n");
-  printf_line("=", 79);
+  Print("\n");
+  PrintLine("=", 79);
 
   CloseAllAndExit(0);
 }