rnd-20030607-3-src
[rocksndiamonds.git] / src / editor.c
index 29b34116a901fb4e9ef2630384883061d3013e34..10a59ce5d1a6e27731fc89806a4e401eea0abd50 100644 (file)
 #define GADGET_ID_CUSTOM_MOVE_DIRECTION        (GADGET_ID_SELECTBOX_FIRST + 4)
 #define GADGET_ID_CUSTOM_WALKABLE_LAYER        (GADGET_ID_SELECTBOX_FIRST + 5)
 #define GADGET_ID_CHANGE_TIME_UNITS    (GADGET_ID_SELECTBOX_FIRST + 6)
-#define GADGET_ID_CHANGE_CAUSE         (GADGET_ID_SELECTBOX_FIRST + 7)
+#define GADGET_ID_CHANGE_PLAYER_ACTION (GADGET_ID_SELECTBOX_FIRST + 7)
+#define GADGET_ID_CHANGE_CAUSE         (GADGET_ID_SELECTBOX_FIRST + 8)
 
 /* textbutton identifiers */
-#define GADGET_ID_TEXTBUTTON_FIRST     (GADGET_ID_SELECTBOX_FIRST + 8)
+#define GADGET_ID_TEXTBUTTON_FIRST     (GADGET_ID_SELECTBOX_FIRST + 9)
 
 #define GADGET_ID_PROPERTIES_INFO      (GADGET_ID_TEXTBUTTON_FIRST + 0)
 #define GADGET_ID_PROPERTIES_CONFIG    (GADGET_ID_TEXTBUTTON_FIRST + 1)
 #define GADGET_ID_CUSTOM_USE_TEMPLATE  (GADGET_ID_CHECKBUTTON_FIRST + 16)
 #define GADGET_ID_CUSTOM_CHANGEABLE    (GADGET_ID_CHECKBUTTON_FIRST + 17)
 #define GADGET_ID_CHANGE_DELAY         (GADGET_ID_CHECKBUTTON_FIRST + 18)
+#define GADGET_ID_CHANGE_BY_PLAYER     (GADGET_ID_CHECKBUTTON_FIRST + 19)
 
 /* gadgets for buttons in element list */
-#define GADGET_ID_ELEMENTLIST_FIRST    (GADGET_ID_CHECKBUTTON_FIRST + 19)
+#define GADGET_ID_ELEMENTLIST_FIRST    (GADGET_ID_CHECKBUTTON_FIRST + 20)
 #define GADGET_ID_ELEMENTLIST_LAST     (GADGET_ID_ELEMENTLIST_FIRST +  \
                                        ED_NUM_ELEMENTLIST_BUTTONS - 1)
 
 #define ED_SELECTBOX_ID_CUSTOM_MOVE_DIRECTION  4
 #define ED_SELECTBOX_ID_CUSTOM_WALKABLE_LAYER  5
 #define ED_SELECTBOX_ID_CHANGE_TIME_UNITS      6
-#define ED_SELECTBOX_ID_CHANGE_CAUSE           7
+#define ED_SELECTBOX_ID_CHANGE_PLAYER_ACTION   7
+#define ED_SELECTBOX_ID_CHANGE_CAUSE           8
 
-#define ED_NUM_SELECTBOX                       8
+#define ED_NUM_SELECTBOX                       9
 
 #define ED_SELECTBOX_ID_CUSTOM_FIRST   ED_SELECTBOX_ID_CUSTOM_WALK_TO_ACTION
 #define ED_SELECTBOX_ID_CUSTOM_LAST    ED_SELECTBOX_ID_CUSTOM_WALKABLE_LAYER
 #define ED_CHECKBUTTON_ID_CUSTOM_USE_TEMPLATE  14
 #define ED_CHECKBUTTON_ID_CUSTOM_CHANGEABLE    15
 #define ED_CHECKBUTTON_ID_CHANGE_DELAY         16
+#define ED_CHECKBUTTON_ID_CHANGE_BY_PLAYER     17
 
-#define ED_NUM_CHECKBUTTONS                    17
+#define ED_NUM_CHECKBUTTONS                    18
 
 #define ED_CHECKBUTTON_ID_LEVEL_FIRST  ED_CHECKBUTTON_ID_DOUBLE_SPEED
 #define ED_CHECKBUTTON_ID_LEVEL_LAST   ED_CHECKBUTTON_ID_RANDOM_RESTRICTED
 #define ED_CHECKBUTTON_ID_CUSTOM_LAST  ED_CHECKBUTTON_ID_CUSTOM_WALKABLE
 
 #define ED_CHECKBUTTON_ID_CHANGE_FIRST ED_CHECKBUTTON_ID_CUSTOM_USE_GRAPHIC
-#define ED_CHECKBUTTON_ID_CHANGE_LAST  ED_CHECKBUTTON_ID_CHANGE_DELAY
+#define ED_CHECKBUTTON_ID_CHANGE_LAST  ED_CHECKBUTTON_ID_CHANGE_BY_PLAYER
 
 /* values for radiobutton gadgets */
 #define ED_RADIOBUTTON_ID_PERCENTAGE   0
@@ -878,6 +882,14 @@ static struct ValueTextInfo options_time_units[] =
 };
 static int index_time_units = 0;
 
+static struct ValueTextInfo options_change_player_action[] =
+{
+  { CE_PRESSED_BY_PLAYER,      "pressed"                       },
+  { CE_TOUCHED_BY_PLAYER,      "touched"                       },
+  { -1,                                NULL                            }
+};
+static int index_change_player_action = 0, value_change_player_action = 0;
+
 static struct ValueTextInfo options_change_cause[] =
 {
   { 1,                         "specified delay"               },
@@ -956,7 +968,15 @@ static struct
     "delay time given in", NULL, "delay time units for change"
   },
   {
-    ED_SETTINGS_XPOS(0),               ED_COUNTER_YPOS(8),
+    ED_SETTINGS_XPOS(2),               ED_SETTINGS_YPOS(5),
+    GADGET_ID_CHANGE_PLAYER_ACTION,
+    -1,
+    options_change_player_action, &index_change_player_action,
+    &value_change_player_action,
+    NULL, "by player", "type of player contact"
+  },
+  {
+    ED_SETTINGS_XPOS(0),               ED_SETTINGS_YPOS(10),
     GADGET_ID_CHANGE_CAUSE,
     -1,
     options_change_cause, &index_change_cause,
@@ -989,7 +1009,7 @@ static struct
     11, "Advanced",                    "Advanced element configuration"
   },
   {
-    ED_SETTINGS_XPOS(0) + 262,         ED_SETTINGS_YPOS(5),
+    ED_SETTINGS_XPOS(0) + 262,         ED_SETTINGS_YPOS(12),
     GADGET_ID_SAVE_AS_TEMPLATE,
     -1, "Save as template",            "Save current settings as new template"
   },
@@ -1196,7 +1216,7 @@ static struct
     "use graphic of element:",         "use graphic for custom element"
   },
   {
-    ED_SETTINGS_XPOS(0),               ED_SETTINGS_YPOS(5),
+    ED_SETTINGS_XPOS(0),               ED_SETTINGS_YPOS(12),
     GADGET_ID_CUSTOM_USE_TEMPLATE,
     &custom_element.use_template,
     "use template",                    "use template for custom properties"
@@ -1205,7 +1225,7 @@ static struct
     ED_SETTINGS_XPOS(0),               ED_SETTINGS_YPOS(2),
     GADGET_ID_CUSTOM_CHANGEABLE,
     &custom_element_properties[EP_CHANGEABLE],
-    "element changes to    after:",    "element can change to other element"
+    "element changes to    after/when:","element can change to other element"
   },
   {
     ED_SETTINGS_XPOS(1),               ED_SETTINGS_YPOS(3),
@@ -1213,6 +1233,12 @@ static struct
     &custom_element_change_events[CE_DELAY],
     NULL,                              "element changes after delay"
   },
+  {
+    ED_SETTINGS_XPOS(1),               ED_SETTINGS_YPOS(5),
+    GADGET_ID_CHANGE_BY_PLAYER,
+    &custom_element_change_events[CE_BY_PLAYER],
+    NULL,                              "element changes by player contact"
+  },
 };
 
 
@@ -3371,6 +3397,12 @@ static void CopyCustomElementPropertiesToEditor(int element)
     (IS_WALKABLE_OVER(element) ||
      IS_WALKABLE_INSIDE(element) ||
      IS_WALKABLE_UNDER(element));
+
+  /* set change by player selectbox help value */
+  value_change_player_action =
+    (HAS_CHANGE_EVENT(element, CE_TOUCHED_BY_PLAYER) ? CE_TOUCHED_BY_PLAYER :
+     HAS_CHANGE_EVENT(element, CE_PRESSED_BY_PLAYER) ? CE_PRESSED_BY_PLAYER :
+     CE_PRESSED_BY_PLAYER);
 }
 
 static void CopyCustomElementPropertiesToGame(int element)
@@ -3406,6 +3438,11 @@ static void CopyCustomElementPropertiesToGame(int element)
   custom_element_properties[custom_element.walkable_layer] =
     custom_element_properties[EP_WALKABLE];
 
+  /* set player change event from checkbox and selectbox */
+  custom_element.change.events &= ~CE_PRESSED_BY_PLAYER;
+  custom_element.change.events &= ~CE_TOUCHED_BY_PLAYER;
+  custom_element.change.events |= value_change_player_action;
+
   for (i=0; i < NUM_ELEMENT_PROPERTIES; i++)
     SET_PROPERTY(element, i, custom_element_properties[i]);
 
@@ -3922,7 +3959,7 @@ static boolean PrintInfoText(char *text, int font_nr, int screen_line)
 {
   int font_height = getFontHeight(font_nr);
   int pad_x = ED_SETTINGS_XPOS(0);
-  int pad_y = ED_SETTINGS_YPOS(0);
+  int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
   int sx = SX + pad_x;
   int sy = SY + pad_y;
   int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
@@ -4076,12 +4113,18 @@ static void DrawPropertiesTabulatorGadgets()
   int gd_y = gd->y + gd_gi->height - 1;
   Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y);
   int id_first = ED_TEXTBUTTON_ID_PROPERTIES_INFO;
+#if 1
+  int id_last  = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG;
+#else
   int id_last  = ED_TEXTBUTTON_ID_PROPERTIES_INFO;
+#endif
   int i;
 
+#if 0
   /* draw additional "configure" tabulator for configurable elements */
   if (checkPropertiesConfig())
     id_last = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG;
+#endif
 
   /* draw additional "advanced" tabulator for custom elements */
   if (IS_CUSTOM_ELEMENT(properties_element))
@@ -4162,7 +4205,7 @@ static void DrawPropertiesInfo()
   int font1_width = getFontWidth(font1_nr);
   int font2_height = getFontHeight(font2_nr);
   int pad_x = ED_SETTINGS_XPOS(0);
-  int pad_y = ED_SETTINGS_YPOS(0);
+  int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
   int screen_line = 0;
   int i, x, y;
 
@@ -4303,6 +4346,13 @@ static void DrawPropertiesConfig()
 {
   int i;
 
+  if (!checkPropertiesConfig())
+  {
+    PrintInfoText("No configuration options available.", FONT_TEXT_1, 0);
+
+    return;
+  }
+
   /* check if there are elements where a score can be chosen for */
   for (i=0; elements_with_counter[i].element != -1; i++)
   {
@@ -4389,6 +4439,51 @@ static void DrawPropertiesAdvanced()
   DrawCustomChangedArea();
 }
 
+static void DrawElementName(int x, int y, int element)
+{
+  char *element_name = getElementInfoText(element);
+  int font_nr = FONT_TEXT_1;
+  int font_width = getFontWidth(font_nr);
+  int font_height = getFontHeight(font_nr);
+  int max_text_width = SXSIZE - x - ED_SETTINGS_XPOS(0);
+  int max_chars_per_line = max_text_width / font_width;
+  char buffer[max_chars_per_line + 1];
+
+  if (strlen(element_name) <= max_chars_per_line)
+    DrawTextF(x, y, font_nr, element_name);
+  else
+  {
+    int next_pos = max_chars_per_line;
+
+    strncpy(buffer, element_name, max_chars_per_line);
+    buffer[max_chars_per_line] = '\0';
+
+    if (element_name[max_chars_per_line] == ' ')
+      next_pos++;
+    else
+    {
+      int i;
+
+      for (i = max_chars_per_line - 1; i >= 0; i--)
+       if (buffer[i] == ' ')
+         break;
+
+      if (strlen(&element_name[i + 1]) <= max_chars_per_line)
+      {
+       buffer[i] = '\0';
+       next_pos = i + 1;
+      }
+    }
+
+    DrawTextF(x, y - font_height / 2, font_nr, buffer);
+
+    strncpy(buffer, &element_name[next_pos], max_chars_per_line);
+    buffer[max_chars_per_line] = '\0';
+
+    DrawTextF(x, y + font_height / 2, font_nr, buffer);
+  }
+}
+
 static void DrawPropertiesWindow()
 {
   int xstart = 2;
@@ -4401,9 +4496,11 @@ static void DrawPropertiesWindow()
       !IS_CUSTOM_ELEMENT(properties_element))
     edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
 
+#if 0
   if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG &&
       !checkPropertiesConfig())
     edit_mode_properties = ED_MODE_PROPERTIES_INFO;
+#endif
 
   if (IS_CUSTOM_ELEMENT(properties_element))
     CopyCustomElementPropertiesToEditor(properties_element);
@@ -4426,8 +4523,8 @@ static void DrawPropertiesWindow()
 
   FrameCounter = 0;    /* restart animation frame counter */
 
-  DrawTextF((xstart + 3) * MINI_TILEX, (ystart + 1) * MINI_TILEY,
-           FONT_TEXT_1, getElementInfoText(properties_element));
+  DrawElementName((xstart + 3) * MINI_TILEX, (ystart + 1) * MINI_TILEY,
+                 properties_element);
 
   DrawPropertiesTabulatorGadgets();