fixed handling key event actions by global animations in level editor
[rocksndiamonds.git] / src / editor.c
index dc1b528f90daf8ebaa38ee3d5c06c7420e7a2009..8f453e2c3f7d85605a5c3261f8fdca207adf0d15 100644 (file)
@@ -11996,27 +11996,28 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
     char text[MAX_CB_TEXT_SIZE + 1] = "";
     int width  = (draw_with_brush ? brush_width  : lev_fieldx);
     int height = (draw_with_brush ? brush_height : lev_fieldy);
+    char *format = "%s%03d";
+
+    for (y = 0; y < height; y++)
+      for (x = 0; x < width; x++)
+       if ((draw_with_brush ? brush_buffer[x][y] : Feld[x][y]) > 999)
+         format = "%s%04d";
 
     for (y = 0; y < height; y++)
     {
       for (x = 0; x < width; x++)
       {
        int element = (draw_with_brush ? brush_buffer[x][y] : Feld[x][y]);
-       int element_mapped = element;
        char *prefix = (mode == CB_DUMP_BRUSH ||
                        mode == CB_BRUSH_TO_CLIPBOARD ? "`" : "¸");
 
-       if (IS_CUSTOM_ELEMENT(element))
-         element_mapped = EL_CUSTOM_START;
-       else if (IS_GROUP_ELEMENT(element))
-         element_mapped = EL_GROUP_START;
-       else if (element >= NUM_FILE_ELEMENTS)
-         element_mapped = EL_UNKNOWN;
+       if (element >= NUM_FILE_ELEMENTS)
+         element = EL_UNKNOWN;
 
        // copy brush to level sketch text buffer for the R'n'D forum:
-       // - large tiles: `xxx (0x60 ASCII)
-       // - small tiles: ¸xxx (0xb8 ISO-8859-1, 0xc2b8 UTF-8)
-       snprintf(part, MAX_CB_PART_SIZE + 1, "%s%03d", prefix, element_mapped);
+       // - large tiles: `xxx or `xxxx (0x60 ASCII)
+       // - small tiles: ¸xxx or ¸xxxx (0xb8 ISO-8859-1, 0xc2b8 UTF-8)
+       snprintf(part, MAX_CB_PART_SIZE + 1, format, prefix, element);
        strcat(text, part);
       }
 
@@ -12063,11 +12064,13 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
 
     char *clipboard_text = SDL_GetClipboardText();
     char *ptr = clipboard_text;
+    boolean allow_new_row = FALSE;
     boolean stop = FALSE;
 
     while (*ptr && !stop)
     {
       boolean prefix_found = FALSE;
+      boolean start_new_row = FALSE;
 
       // level sketch element number prefixes (may be multi-byte characters)
       char *prefix_list[] = { "`", "¸" };
@@ -12096,19 +12099,10 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
        }
       }
 
-      // continue with next character if prefix not found
-      if (!prefix_found)
-      {
-       ptr++;          // !!! FIX THIS for real UTF-8 handling !!!
-
-       continue;
-      }
-
-      // continue with next character if prefix not found
-      if (strlen(ptr) < 3)
-       break;
-
-      if (ptr[0] >= '0' && ptr[0] <= '9' &&
+      // check if prefix found and followed by (at least) three digits
+      if (prefix_found &&
+         strlen(ptr) >= 3 &&
+         ptr[0] >= '0' && ptr[0] <= '9' &&
          ptr[1] >= '0' && ptr[1] <= '9' &&
          ptr[2] >= '0' && ptr[2] <= '9')
       {
@@ -12118,6 +12112,13 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
 
        ptr += 3;
 
+       // level sketch element number might consist of four digits
+       if (ptr[0] >= '0' && ptr[0] <= '9')
+       {
+         element = element * 10 + (ptr[0] - '0');
+         ptr++;
+       }
+
        if (element >= NUM_FILE_ELEMENTS)
          element = EL_UNKNOWN;
 
@@ -12128,14 +12129,28 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y,
 
        x++;
 
-       if (x >= MAX_LEV_FIELDX || *ptr == '\n')
-       {
-         x = 0;
-         y++;
+       if (x >= MAX_LEV_FIELDX)
+         start_new_row = TRUE;
 
-         if (y >= MAX_LEV_FIELDY)
-           stop = TRUE;
-       }
+       allow_new_row = TRUE;
+      }
+      else
+      {
+       if ((*ptr == '\n' || *ptr == '\r') && allow_new_row)
+         start_new_row = TRUE;
+
+       ptr++;          // !!! FIX THIS for real UTF-8 handling !!!
+      }
+
+      if (start_new_row)
+      {
+       x = 0;
+       y++;
+
+       if (y >= MAX_LEV_FIELDY)
+         stop = TRUE;
+
+       allow_new_row = FALSE;
       }
     }
 
@@ -13767,6 +13782,10 @@ static void HandleControlButtons(struct GadgetInfo *gi)
                     button == 2 ? ed_tilesize_default :
                     button == 3 ? ed_tilesize / 2 : ed_tilesize);
 
+      // when using touch device, cycle through all zoom tilesizes
+      if (runtime.uses_touch_device && ed_tilesize > TILESIZE)
+       ed_tilesize = MICRO_TILESIZE;
+
       // limit zoom level by upper and lower bound
       ed_tilesize = MIN(MAX(MICRO_TILESIZE, ed_tilesize), TILESIZE);
 
@@ -14066,7 +14085,7 @@ void HandleLevelEditorKeyInput(Key key)
     else if (key == KSYM_Escape)
       DrawLevelText(0, 0, 0, TEXT_END);
   }
-  else if (button_status == MB_RELEASED)
+  else
   {
     int id = GADGET_ID_NONE;
     int new_element_shift = element_shift;