rnd-20031129-1-src
authorHolger Schemel <info@artsoft.org>
Sat, 29 Nov 2003 00:50:16 +0000 (01:50 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:44:46 +0000 (10:44 +0200)
src/conftime.h
src/editor.c
src/files.c
src/libgame/setup.h
src/libgame/text.c
src/libgame/text.h
src/main.c
src/main.h
src/screens.c

index 21932cea47f71ec21b6f60760bef3eff14d81eb3..8fb097a7f0e15efcadf2a31cf5d193332ae204e8 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "[2003-11-28 03:02]"
+#define COMPILE_DATE_STRING "[2003-11-29 01:44]"
index cb202d16206bd999051e660581ca6019ba5c250c..0eea3c6da24218245c1a3c75980280f089e1b789 100644 (file)
@@ -5530,6 +5530,264 @@ char *getElementDescriptionFilename(int element)
   return NULL;
 }
 
   return NULL;
 }
 
+#if 1
+static boolean PrintInfoText(char *text, int font_nr, int start_line)
+{
+  int font_height = getFontHeight(font_nr);
+  int pad_x = ED_SETTINGS_XPOS(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;
+
+  if (start_line >= max_lines_per_screen)
+    return FALSE;
+
+  DrawText(sx, sy + start_line * font_height, text, font_nr);
+
+  return TRUE;
+}
+
+#if 1
+
+static int PrintElementDescriptionFromFile(char *filename, int start_line)
+{
+  int font_nr = FONT_TEXT_2;
+  int font_width = getFontWidth(font_nr);
+  int font_height = getFontHeight(font_nr);
+  int pad_x = ED_SETTINGS_XPOS(0);
+  int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
+  int sx = SX + pad_x;
+  int sy = SY + pad_y;
+  int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
+  int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
+  int current_line = start_line;
+  char line[MAX_LINE_LEN];
+  char buffer[max_chars_per_line + 1];
+  int buffer_len;
+  FILE *file;
+
+  if (current_line >= max_lines_per_screen)
+    return 0;
+
+  if (filename == NULL)
+    return 0;
+
+  if (!(file = fopen(filename, MODE_READ)))
+    return 0;
+
+  buffer[0] = '\0';
+  buffer_len = 0;
+
+  while(!feof(file) && current_line < max_lines_per_screen)
+  {
+    char *line_ptr;
+    boolean last_line_was_empty = TRUE;
+
+    /* read next line of input file */
+    if (!fgets(line, MAX_LINE_LEN, file))
+      break;
+
+    /* skip comments (lines directly beginning with '#') */
+    if (line[0] == '#')
+      continue;
+
+    /* cut trailing newline from input line */
+    for (line_ptr = line; *line_ptr; line_ptr++)
+    {
+      if (*line_ptr == '\n' || *line_ptr == '\r')
+      {
+       *line_ptr = '\0';
+       break;
+      }
+    }
+
+    if (strlen(line) == 0)             /* special case: force empty line */
+      strcpy(line, "\n");
+
+    line_ptr = line;
+
+    while (*line_ptr && current_line < max_lines_per_screen)
+    {
+      boolean buffer_filled = RenderLineToBuffer(&line_ptr,
+                                                buffer, &buffer_len,
+                                                last_line_was_empty,
+                                                max_chars_per_line);
+      if (buffer_filled)
+      {
+       DrawText(sx, sy + current_line * font_height, buffer, font_nr);
+       current_line++;
+
+       last_line_was_empty = (buffer_len == 0);
+
+       buffer[0] = '\0';
+       buffer_len = 0;
+      }
+    }
+  }
+
+  fclose(file);
+
+  if (buffer_len > 0 && current_line < max_lines_per_screen)
+  {
+    DrawText(sx, sy + current_line * font_height, buffer, font_nr);
+    current_line++;
+  }
+
+  return (current_line - start_line);
+}
+
+#else
+
+static int PrintElementDescriptionFromFile(char *filename, int start_line)
+{
+  int font_nr = FONT_TEXT_2;
+  int font_width = getFontWidth(font_nr);
+  int font_height = getFontHeight(font_nr);
+  int pad_x = ED_SETTINGS_XPOS(0);
+  int pad_y = ED_SETTINGS_YPOS(0) + ED_BORDER_SIZE;
+  int sx = SX + pad_x;
+  int sy = SY + pad_y;
+  int max_chars_per_line = (SXSIZE - 2 * pad_x) / font_width;
+  int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1;
+  int current_line = start_line;
+  char line[MAX_LINE_LEN];
+  char buffer[max_chars_per_line + 1];
+  int buffer_len;
+  FILE *file;
+
+  if (filename == NULL)
+    return 0;
+
+  if (!(file = fopen(filename, MODE_READ)))
+    return 0;
+
+  buffer[0] = '\0';
+  buffer_len = 0;
+
+  while(!feof(file))
+  {
+    char *line_ptr, *word_ptr;
+    boolean last_line_was_empty = TRUE;
+
+    /* read next line of input file */
+    if (!fgets(line, MAX_LINE_LEN, file))
+      break;
+
+    /* skip comments (lines directly beginning with '#') */
+    if (line[0] == '#')
+      continue;
+
+    /* cut trailing newline from input line */
+    for (line_ptr = line; *line_ptr; line_ptr++)
+    {
+      if (*line_ptr == '\n' || *line_ptr == '\r')
+      {
+       *line_ptr = '\0';
+       break;
+      }
+    }
+
+    if (strlen(line) == 0)             /* special case: force empty line */
+      strcpy(line, "\n");
+
+    word_ptr = line;
+
+    while (*word_ptr)
+    {
+      boolean print_buffer = FALSE;
+      int word_len;
+
+      /* skip leading whitespaces */
+      while (*word_ptr == ' ' || *word_ptr == '\t')
+       word_ptr++;
+
+      line_ptr = word_ptr;
+      word_len = 0;
+
+      /* look for end of next word */
+      while (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0')
+      {
+       line_ptr++;
+       word_len++;
+      }
+
+      if (word_len == 0)
+      {
+       continue;
+      }
+      else if (*word_ptr == '\n')      /* special case: force empty line */
+      {
+       if (buffer_len == 0)
+         word_ptr++;
+
+       /* prevent printing of multiple empty lines */
+       if (buffer_len > 0 || !last_line_was_empty)
+         print_buffer = TRUE;
+      }
+      else if (word_len < max_chars_per_line - buffer_len)
+      {
+       /* word fits into text buffer -- add word */
+
+       if (buffer_len > 0)
+         buffer[buffer_len++] = ' ';
+
+       strncpy(&buffer[buffer_len], word_ptr, word_len);
+       buffer_len += word_len;
+       buffer[buffer_len] = '\0';
+       word_ptr += word_len;
+      }
+      else if (buffer_len > 0)
+      {
+       /* not enough space left for word in text buffer -- print buffer */
+
+       print_buffer = TRUE;
+      }
+      else
+      {
+       /* word does not fit at all into empty text buffer -- cut word */
+
+       strncpy(buffer, word_ptr, max_chars_per_line);
+       buffer[max_chars_per_line] = '\0';
+       word_ptr += max_chars_per_line;
+       print_buffer = TRUE;
+      }
+
+      if (print_buffer)
+      {
+       if (current_line >= max_lines_per_screen)
+       {
+         fclose(file);
+
+         return (current_line - start_line);
+       }
+
+       DrawText(sx, sy + current_line * font_height, buffer, font_nr);
+       current_line++;
+
+       last_line_was_empty = (buffer_len == 0);
+
+       buffer[0] = '\0';
+       buffer_len = 0;
+       print_buffer = FALSE;
+      }
+    }
+  }
+
+  fclose(file);
+
+  if (buffer_len > 0 && current_line < max_lines_per_screen)
+  {
+    DrawText(sx, sy + current_line * font_height, buffer, font_nr);
+    current_line++;
+  }
+
+  return (current_line - start_line);
+}
+#endif
+
+#else
+
 static boolean PrintInfoText(char *text, int font_nr, int screen_line)
 {
   int font_height = getFontHeight(font_nr);
 static boolean PrintInfoText(char *text, int font_nr, int screen_line)
 {
   int font_height = getFontHeight(font_nr);
@@ -5596,6 +5854,10 @@ static int PrintElementDescriptionFromFile(char *filename, int screen_line)
 
     word_ptr = line;
 
 
     word_ptr = line;
 
+#if 0
+    printf("::: got line '%s'...\n", line);
+#endif
+
     while (*word_ptr)
     {
       boolean print_buffer = FALSE;
     while (*word_ptr)
     {
       boolean print_buffer = FALSE;
@@ -5658,8 +5920,16 @@ static int PrintElementDescriptionFromFile(char *filename, int screen_line)
 
       if (print_buffer)
       {
 
       if (print_buffer)
       {
+#if 0
+       printf("::: printing '%s'...\n", buffer);
+#endif
+
        if (!PrintInfoText(buffer, font_nr, screen_line + lines_printed))
        if (!PrintInfoText(buffer, font_nr, screen_line + lines_printed))
+       {
+         fclose(file);
+
          return lines_printed;
          return lines_printed;
+       }
 
        last_line_was_empty = (buffer_len == 0);
        lines_printed++;
 
        last_line_was_empty = (buffer_len == 0);
        lines_printed++;
@@ -5679,6 +5949,7 @@ static int PrintElementDescriptionFromFile(char *filename, int screen_line)
 
   return lines_printed;
 }
 
   return lines_printed;
 }
+#endif
 
 static void DrawPropertiesTabulatorGadgets()
 {
 
 static void DrawPropertiesTabulatorGadgets()
 {
index e65f387a3c461528dcd31064b5eaf06cf1d620bc..cb4c6a605a173139931c8203c7f39353b77275a6 100644 (file)
@@ -3236,30 +3236,25 @@ void LoadDemoAnimText()
   int i;
 
   if (demo_anim_text != NULL)
   int i;
 
   if (demo_anim_text != NULL)
-    freeSetupFileList(demo_anim_text);
+    freeSetupFileHash(demo_anim_text);
 
 
-  if ((demo_anim_text = loadSetupFileList(filename)) == NULL)
+  if ((demo_anim_text = loadSetupFileHash(filename)) == NULL)
   {
     /* use reliable default values from static configuration */
   {
     /* use reliable default values from static configuration */
-    SetupFileList *insert_ptr;
-
-    insert_ptr = demo_anim_text =
-      newSetupFileList(demo_anim_text_config[0].token,
-                      demo_anim_text_config[0].value);
+    demo_anim_text = newSetupFileHash();
 
 
-    for (i=1; demo_anim_text_config[i].token; i++)
-      insert_ptr = addListEntry(insert_ptr,
-                               demo_anim_text_config[i].token,
-                               demo_anim_text_config[i].value);
+    for (i=0; demo_anim_text_config[i].token; i++)
+      setHashEntry(demo_anim_text, demo_anim_text_config[i].token,
+                  demo_anim_text_config[i].value);
   }
 
 #if 0
   /* TEST ONLY */
   }
 
 #if 0
   /* TEST ONLY */
+  BEGIN_HASH_ITERATION(demo_anim_text, itr)
   {
   {
-    SetupFileList *list;
-
-    for (list = demo_anim_text; list != NULL; list = list->next)
-      printf("::: '%s' => '%s'\n", list->token, list->value);
+    printf("::: '%s' => '%s'\n",
+          HASH_ITERATION_TOKEN(itr), HASH_ITERATION_VALUE(itr));
   }
   }
+  END_HASH_ITERATION(hash, itr)
 #endif
 }
 #endif
 }
index dcbc5eeaa54d83e939d3a146d11bebbec277a2d1..006a713ad56055f26b2fb1e64a3852f0097c0478 100644 (file)
@@ -67,7 +67,7 @@ struct TokenInfo
 
 /* some definitions for list and hash handling */
 typedef struct SetupFileList SetupFileList;
 
 /* some definitions for list and hash handling */
 typedef struct SetupFileList SetupFileList;
-typedef struct hashtable SetupFileHash;
+typedef struct hashtable     SetupFileHash;
 
 #define BEGIN_HASH_ITERATION(hash, itr)                                \
   if (hash != NULL && hashtable_count(hash) > 0)               \
 
 #define BEGIN_HASH_ITERATION(hash, itr)                                \
   if (hash != NULL && hashtable_count(hash) > 0)               \
index 9e9556095fbd9dddd8b09534b2c007543044a732..2c5b77bf71edb7ce120f4a998a5dbe3faf88fec3 100644 (file)
@@ -364,3 +364,103 @@ void DrawTextToTextArea(int x, int y, char *text, int font_nr, int line_length,
 
   redraw_mask |= REDRAW_FIELD;
 }
 
   redraw_mask |= REDRAW_FIELD;
 }
+
+boolean RenderLineToBuffer(char **src_buffer_ptr, char *dst_buffer,
+                          int *dst_buffer_len, boolean last_line_was_empty,
+                          int max_chars_per_line)
+{
+  char *text_ptr = *src_buffer_ptr;
+  char *buffer = dst_buffer;
+  int buffer_len = *dst_buffer_len;
+  boolean buffer_filled = FALSE;
+
+  while (*text_ptr)
+  {
+    char *word_ptr;
+    int word_len;
+
+    /* skip leading whitespaces */
+    while (*text_ptr == ' ' || *text_ptr == '\t')
+      text_ptr++;
+
+    word_ptr = text_ptr;
+    word_len = 0;
+
+    /* look for end of next word */
+    while (*word_ptr != ' ' && *word_ptr != '\t' && *word_ptr != '\0')
+    {
+      word_ptr++;
+      word_len++;
+    }
+
+    if (word_len == 0)
+    {
+      continue;
+    }
+    else if (*text_ptr == '\n')                /* special case: force empty line */
+    {
+      if (buffer_len == 0)
+       text_ptr++;
+
+      /* prevent printing of multiple empty lines */
+      if (buffer_len > 0 || !last_line_was_empty)
+       buffer_filled = TRUE;
+    }
+    else if (word_len < max_chars_per_line - buffer_len)
+    {
+      /* word fits into text buffer -- add word */
+
+      if (buffer_len > 0)
+       buffer[buffer_len++] = ' ';
+
+      strncpy(&buffer[buffer_len], text_ptr, word_len);
+      buffer_len += word_len;
+      buffer[buffer_len] = '\0';
+      text_ptr += word_len;
+    }
+    else if (buffer_len > 0)
+    {
+      /* not enough space left for word in text buffer -- print buffer */
+
+      buffer_filled = TRUE;
+    }
+    else
+    {
+      /* word does not fit at all into empty text buffer -- cut word */
+
+      strncpy(buffer, text_ptr, max_chars_per_line);
+      buffer[max_chars_per_line] = '\0';
+      text_ptr += max_chars_per_line;
+      buffer_filled = TRUE;
+    }
+
+    if (buffer_filled)
+      break;
+  }
+
+  *src_buffer_ptr = text_ptr;
+  *dst_buffer_len = buffer_len;
+
+  return buffer_filled;
+}
+
+void DrawTextWrapped(int x, int y, char *text, int font_nr, int line_length,
+                    int max_lines)
+{
+  char *text_ptr = text;
+  char buffer[line_length + 1];
+  int buffer_len;
+  int current_line = 0;
+  int font_height = getFontHeight(font_nr);
+
+  while (*text_ptr && current_line < max_lines)
+  {
+    buffer[0] = '\0';
+    buffer_len = 0;
+
+    RenderLineToBuffer(&text_ptr, buffer, &buffer_len, TRUE, line_length);
+
+    DrawText(x, y + current_line * font_height, buffer, font_nr);
+    current_line++;
+  }
+}
index 611cf2be7a5fdfed184e7742a2fc1081d6128355..10c91d242c21837ee49487f50e520c0a2dc37d32 100644 (file)
@@ -69,5 +69,7 @@ void DrawTextSCentered(int, int, char *);
 void DrawText(int, int, char *, int);
 void DrawTextExt(DrawBuffer *, int, int, char *, int, int);
 void DrawTextToTextArea(int, int, char *, int, int, int, int, int);
 void DrawText(int, int, char *, int);
 void DrawTextExt(DrawBuffer *, int, int, char *, int, int);
 void DrawTextToTextArea(int, int, char *, int, int, int, int, int);
+boolean RenderLineToBuffer(char **, char *, int *, boolean, int);
+void DrawTextWrapped(int, int, char *, int, int, int);
 
 #endif /* TEXT_H */
 
 #endif /* TEXT_H */
index ef5d4b9910dbe967e238d5229ebb24d6b735ba8f..1754e225f0f26d2ce3d978c6f60cbc5e53c37b43 100644 (file)
@@ -106,7 +106,7 @@ struct SoundInfo       *sound_info = NULL;
 struct MusicInfo       *music_info = NULL;
 struct MusicFileInfo   *music_file_info = NULL;
 struct DemoAnimInfo    *demo_anim_info = NULL;
 struct MusicInfo       *music_info = NULL;
 struct MusicFileInfo   *music_file_info = NULL;
 struct DemoAnimInfo    *demo_anim_info = NULL;
-struct SetupFileList   *demo_anim_text = NULL;
+SetupFileHash          *demo_anim_text = NULL;
 
 
 /* ------------------------------------------------------------------------- */
 
 
 /* ------------------------------------------------------------------------- */
index 9f028d1d6855b814ce4f6ff143b852ec7a9f4292..ed85f13f2f6c4ba9c85849c1dd1a45d0773d9c32 100644 (file)
@@ -1668,7 +1668,7 @@ extern struct SoundInfo          *sound_info;
 extern struct MusicInfo               *music_info;
 extern struct MusicFileInfo    *music_file_info;
 extern struct DemoAnimInfo     *demo_anim_info;
 extern struct MusicInfo               *music_info;
 extern struct MusicFileInfo    *music_file_info;
 extern struct DemoAnimInfo     *demo_anim_info;
-extern struct SetupFileList    *demo_anim_text;
+extern SetupFileHash           *demo_anim_text;
 extern struct ConfigInfo       image_config[];
 extern struct ConfigInfo       sound_config[];
 extern struct ConfigInfo       music_config[];
 extern struct ConfigInfo       image_config[];
 extern struct ConfigInfo       sound_config[];
 extern struct ConfigInfo       music_config[];
index e47e922b58225dfecc853c235af9df667b40acbc..ec0a1231b4573c329886272d7e9127e7dbc629ea 100644 (file)
@@ -1007,7 +1007,8 @@ void DrawHelpScreenElText(int element, int action, int direction, int ypos)
   int ystep = TILEY + 4;
   char *text;
 
   int ystep = TILEY + 4;
   char *text;
 
-  text = getListEntry(demo_anim_text, element_info[element].token_name);
+  text = getHashEntry(demo_anim_text, element_info[element].token_name);
+
   if (text == NULL)
   {
     char token[MAX_LINE_LEN];
   if (text == NULL)
   {
     char token[MAX_LINE_LEN];
@@ -1020,15 +1021,31 @@ void DrawHelpScreenElText(int element, int action, int direction, int ypos)
     if (direction != -1)
       strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
 
     if (direction != -1)
       strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix);
 
-    text = getListEntry(demo_anim_text, token);
+    text = getHashEntry(demo_anim_text, token);
 
     if (text == NULL)
 
     if (text == NULL)
-      text = "[Oops! No Text found!]";
+      text = "No description available";
   }
 
 #if 1
   }
 
 #if 1
+
+#if 1
+
+  if (strlen(text) <= 34)
+    ystart += getFontHeight(FONT_TEXT_2) / 2;
+
+#if 0
+  DrawTextWrapped(xstart, ystart+1 + ypos * ystep, text, FONT_LEVEL_NUMBER,
+                 34, 2);
+#else
+  DrawTextWrapped(xstart, ystart+1 + ypos * ystep, text, FONT_TEXT_2, 34, 2);
+#endif
+
+#else
   DrawTextToTextArea(xstart, ystart + ypos * ystep, text, FONT_TEXT_2, 34,
                     34, 2, BLIT_ON_BACKGROUND);
   DrawTextToTextArea(xstart, ystart + ypos * ystep, text, FONT_TEXT_2, 34,
                     34, 2, BLIT_ON_BACKGROUND);
+#endif
+
 #else
   if (strlen(text) > 25)
     text[25] = '\0';
 #else
   if (strlen(text) > 25)
     text[25] = '\0';