pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src string_format.cxx,NONE,1.1 string_for


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src string_format.cxx,NONE,1.1 string_format.hxx,NONE,1.1 Makefile.am,1.150,1.151 pingus_main.cxx,1.85,1.86 start_screen.cxx,1.17,1.18story.cxx,1.22,1.23
Date: 16 Apr 2003 18:02:29 -0000

Update of /var/lib/cvs/Games/Pingus/src
In directory dark:/tmp/cvs-serv22047/src

Modified Files:
        Makefile.am pingus_main.cxx start_screen.cxx story.cxx 
Added Files:
        string_format.cxx string_format.hxx 
Log Message:
- added automatic formatting of story text
- ran update-po


--- NEW FILE: string_format.cxx ---
//  $Id: string_format.cxx,v 1.1 2003/04/16 18:02:27 torangan Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <ClanLib/Display/Font/font.h>
#include "string_format.hxx"

std::string
StringFormat::break_line (std::string text, int length, CL_Font* font)
{
  unsigned int pos = 0;
  while ((pos = text.find('\t', pos)) != std::string::npos)
    text.replace(pos, 1, 1, ' ');
  
  pos = 0;
  while ((pos = text.find("  ", pos)) != std::string::npos)
    text.replace(pos, 2, 1, ' ');

  pos = 0;  
  while ((pos = text.find('\n', pos)) != std::string::npos)
    {
      if (pos < text.length() && text[pos + 1] == '\n')   // double enter marks 
paragraph
        {
          text.replace(pos, 2, 1, '\n');                  // replace the two \n 
by one
        }
      else if (pos < text.length() - 1 && text[pos + 1] == ' ' && text[pos + 2] 
== '\n')
        {
            text.replace(pos, 3, 1, '\n');                // whitespace between 
the two \n doesn't matter
        }
      else
        {
          text.replace(pos, 1, 1, ' ');
          continue;                                       // no \n here 
anymore, so continue searching
        }

      if (pos && text[pos - 1] == ' ')
        text.replace(pos - 1, 2, 1, '\n');                // no whitespace in 
front
        
      if (pos < text.length() && text[pos + 1] == ' ')
         text.replace(pos, 2, 1, '\n');                   // no whitespace 
behind
        
      ++pos;                                              // we don't want to 
find it again
    }
        
  pos = 0;
  while ((pos = text.find("  ", pos)) != std::string::npos)
    text.replace(pos, 2, 1, ' ');


  int start_pos      = 0;
  int previous_space = 0;
  pos = 0;
  while ((pos = text.find(' ', pos + 1)) != std::string::npos)
    {
      if (font->get_text_width(text.substr(start_pos, pos - start_pos)) > 
length)
        {
          text[previous_space] = '\n';
          start_pos = previous_space + 1;
        }
      else if (font->get_text_width(text.substr(start_pos, text.length())) <= 
length)
        break;

      previous_space = pos;
    }

  return text;
}

/* EOF */

--- NEW FILE: string_format.hxx ---
//  $Id: string_format.hxx,v 1.1 2003/04/16 18:02:27 torangan Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_STRING_FORMAT_HXX
#define HEADER_PINGUS_STRING_FORMAT_HXX

#include <string>

class CL_Font;

class StringFormat {

public:
  static std::string break_line (std::string text, int length, CL_Font* font);
};

#endif

/* EOF */

Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/Makefile.am,v
retrieving revision 1.150
retrieving revision 1.151
diff -u -d -r1.150 -r1.151
--- Makefile.am 15 Apr 2003 23:12:29 -0000      1.150
+++ Makefile.am 16 Apr 2003 18:02:27 -0000      1.151
@@ -266,6 +266,8 @@
 story_screen.cxx \
 string_converter.cxx \
 string_converter.hxx \
+string_format.cxx \
+string_format.hxx \
 string_tokenizer.cxx \
 string_tokenizer.hxx \
 system.cxx \

Index: pingus_main.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/pingus_main.cxx,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- pingus_main.cxx     15 Apr 2003 23:56:40 -0000      1.85
+++ pingus_main.cxx     16 Apr 2003 18:02:27 -0000      1.86
@@ -122,7 +122,7 @@
       break;
     }
   puts ("exit(EXIT_FAILURE);");
-  exit (EXIT_FAILURE);
+  abort();
 }
 
 PingusMain::PingusMain()
@@ -971,11 +971,11 @@
   SavegameManager::instance();
   StatManager::init();
  
+  Fonts::init();
   Story::init();
   ScreenManager::init();
   PingusSound::init();
   PingusResource::init();
-  Fonts::init();
   XMLhelper::init();
   PinguActionFactory::init();
   Editor::init(); 

Index: start_screen.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/start_screen.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- start_screen.cxx    12 Apr 2003 15:52:17 -0000      1.17
+++ start_screen.cxx    16 Apr 2003 18:02:27 -0000      1.18
@@ -34,6 +34,7 @@
 #include "start_screen.hxx"
 #include "game_time.hxx"
 #include "sound/sound.hxx"
+#include "string_format.hxx"
 
 class StartScreenComponent : public GUI::Component
 {
@@ -188,61 +189,8 @@
   if (description == "")
     return description;
 
-  unsigned int pos = 0;
-  while ((pos = description.find('\t', pos)) != std::string::npos)
-    description.replace(pos, 1, 1, ' ');
+  description = StringFormat::break_line(description, length, 
Fonts::chalk_normal);
   
-  pos = 0;
-  while ((pos = description.find("  ", pos)) != std::string::npos)
-    description.replace(pos, 2, 1, ' ');
-
-  pos = 0;  
-  while ((pos = description.find('\n', pos)) != std::string::npos)
-    {
-      if (pos < description.length() && description[pos + 1] == '\n')   // 
double enter marks paragraph
-       {
-          description.replace(pos, 2, 1, '\n');                        // 
replace the two \n by one
-       }
-      else if (pos < description.length() - 1 && description[pos + 1] == ' ' 
&& description[pos + 2] == '\n')
-        {
-            description.replace(pos, 3, 1, '\n');                      // 
whitespace between the two \n doesn't matter
-       }
-      else
-        {
-          description.replace(pos, 1, 1, ' ');
-         continue;                                                     // no 
\n here anymore, so continue searching
-        }
-
-      if (pos && description[pos - 1] == ' ')
-        description.replace(pos - 1, 2, 1, '\n');                      // no 
whitespace in front
-       
-      if (pos < description.length() && description[pos + 1] == ' ')
-         description.replace(pos, 2, 1, '\n');                         // no 
whitespace behind
-       
-      ++pos;                                                           // we 
don't want to find it again
-    }
-        
-  pos = 0;
-  while ((pos = description.find("  ", pos)) != std::string::npos)
-    description.replace(pos, 2, 1, ' ');
-
-
-  int start_pos      = 0;
-  int previous_space = 0;
-  pos = 0;
-  while ((pos = description.find(' ', pos + 1)) != std::string::npos)
-    {
-      if (Fonts::chalk_normal->get_text_width(description.substr(start_pos, 
pos - start_pos)) > length)
-        {
-         description[previous_space] = '\n';
-         start_pos = previous_space + 1;
-       }
-      else if 
(Fonts::chalk_normal->get_text_width(description.substr(start_pos, 
description.length())) <= length)
-        break;
-
-      previous_space = pos;
-    }
-    
   return description;
 }
 

Index: story.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/story.cxx,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- story.cxx   11 Apr 2003 23:52:37 -0000      1.22
+++ story.cxx   16 Apr 2003 18:02:27 -0000      1.23
@@ -20,6 +20,8 @@
 #include <algorithm>
 #include "my_gettext.hxx"
 #include "story.hxx"
+#include "string_format.hxx"
+#include "fonts.hxx"
 
 Story Story::credits;
 Story Story::intro;
@@ -37,38 +39,46 @@
   credits.title = _("The Journey Continues");
   credits.pages.push_back
     (StoryPage
-     (ResDescriptor("Story/credits1", "story"), 
+     (ResDescriptor("Story/credits1", "story"),
+      StringFormat::break_line(
       _("Now after you and the Pingus have learned the basics and\n"
         "practiced a bit it is time to move on and begin the journey into\n"
         "the world. Since the floe with which the Pingus traveled to the\n"
         "Tutorial Island isn't going to hold the whole way into the warmer\n"
         "climated regions the Pingus have to find something else to guide\n"
-        "them on their journey.\n")));
+        "them on their journey.\n"), 570, Fonts::chalk_normal)
+        ));
 
   credits.pages.push_back
     (StoryPage
      (ResDescriptor("Story/credits2", "story"), 
+      StringFormat::break_line(
       _("But as the eldest have said, the Tutorial Island provides not\n"
         "only a way to practive, but it is also the starting point into\n"
         "the world. After some search the Pingus discovered the meaning\n"
         "of this, the large tree at the end of the island provides good\n"
-        "wood to construct a float.\n")));
+        "wood to construct a float.\n"), 570, Fonts::chalk_normal)
+       ));
      
   credits.pages.push_back
     (StoryPage
      (ResDescriptor("Story/credits3", "story"), 
+      StringFormat::break_line(
       _("So the Pingus set out and constructed some large floats, enough\n"
         "to carry them all. After also packaging up a bunch of provisions\n"
         "they where prepared to finally start of their journey and leave\n"
-        "their familiar ground and enter the unknown parts of the world.\n")));
+        "their familiar ground and enter the unknown parts of the world.\n"), 
570, Fonts::chalk_normal)
+        ));
      
   credits.pages.push_back
     (StoryPage
      (ResDescriptor("Story/credits4", "story"), 
+      StringFormat::break_line(
       _("So the Pingus sat on their float, worrying whats to come and\n"
         "where to go, while floating into the sunset.\n"
         "\n"
-        "To be continued...")));
+        "To be continued..."), 570, Fonts::chalk_normal)
+       ));
 
   std::reverse(credits.pages.begin(), credits.pages.end());
 }
@@ -79,70 +89,85 @@
   intro.title = _("The Journey Begins");
   intro.pages.push_back
     (StoryPage
-     (ResDescriptor("Story/story0", "story"), 
+     (ResDescriptor("Story/story0", "story"),
+      StringFormat::break_line(
       _("For a long time now the Pingus have lived happily in peace on the\n"
         "south pole along with all the other animals, everything was in\n"
         "balance and it seemed like nothing could disrupt their peace.  The\n"
-        "Pingus where happy and it seemed like this could never end.\n")));
+        "Pingus where happy and it seemed like this could never end.\n"), 570, 
Fonts::chalk_normal)
+       ));
 
   intro.pages.push_back
     (StoryPage
      (ResDescriptor("Story/story1", "story"), 
+      StringFormat::break_line(
       _("But then one day, things began to change slowly, the sky got darker\n"
         "and the earth got warmer, first of they thought this was just a\n"
         "normal fluctuation in the worlds climate, but things seemed to get\n"
-        "worse and worse with every year.")));
+        "worse and worse with every year."), 570, Fonts::chalk_normal)
+       ));
 
 
   intro.pages.push_back
     (StoryPage
      (ResDescriptor("Story/story2", "story"), 
+      StringFormat::break_line(
       _("The snow began to melt away in a few regions and food became an\n"
         "issue. Other animals already tend to leave the region to search\n"
         "for colder areas, but the Pingus knew that this wouldn't help,\n"
-        "they knew that they had to do something about this problem.")));
+        "they knew that they had to do something about this problem."), 570, 
Fonts::chalk_normal)
+       ));
 
   intro.pages.push_back
     (StoryPage
      (ResDescriptor("Story/story3", "story"), 
+      StringFormat::break_line(
       _("So the circle of the eldest came together to decide what to do\n"
         "about it. They decided to send out an expedition around the world\n"
         "to find the cause for this warming. The expedition consisted of\n"
-        "hundreds of the bravest Pingus around on the south pole.")));
+        "hundreds of the bravest Pingus around on the south pole."), 570, 
Fonts::chalk_normal)
+       ));
     
   intro.pages.push_back
     (StoryPage
      (ResDescriptor("Story/story4", "story"), 
+      StringFormat::break_line(
       _("And they picked you to lead them on their journey around the\n"
         "world. Since the journey will be dangerous and difficult, your\n"
         "first goal is the Island of Mogorok, also know has Tutorial\n"
         "Island. According to the eldest, this island has always been the\n"
-        "first stop of Pingus which where send out into the world.")));
+        "first stop of Pingus which where send out into the world."), 570, 
Fonts::chalk_normal)
+       ));
 
   intro.pages.push_back
     (StoryPage
      (ResDescriptor("Story/story5", "story"), 
+      StringFormat::break_line(
       _("The island consists of many regions which are ideally to train the\n"
         "abilities of the Pingus. The Pingus can train there their ability\n"
         "to build bridges, climb, bash and all the rest of their talents\n"
-        "which they will surly need on their long and dangerous journey.")));
+        "which they will surly need on their long and dangerous journey."), 
570, Fonts::chalk_normal)
+       ));
 
   intro.pages.push_back
     (StoryPage
      (ResDescriptor("Story/story6", "story"), 
+      StringFormat::break_line(
       _("While you on the other side can practice there your ability to\n"
         "command and guide the Pingus. You can also get familiar there with\n"
         "all the abilities the Pingus provide and learn to master them,\n"
         "since you will need them all for sure an your journey around the\n"
-        "world.")));
+        "world."), 570, Fonts::chalk_normal)
+       ));
 
   intro.pages.push_back
     (StoryPage
      (ResDescriptor("Story/story6", "story"), 
+      StringFormat::break_line(
       _("Now that you and the Pingus have arrived at tutorial island it\n"
         "is time to take over the command and begin your mission.\n"
-        "\n"
-        "                                                  Good Luck!")));
+        "\nGood Luck!"), 570, Fonts::chalk_normal)
+       ));
 
   std::reverse(intro.pages.begin(), intro.pages.end());
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]