Update of /cvsroot/super-tux/supertux/src/screen
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6618/src/screen
Modified Files:
font.cpp
Log Message:
Added support for data files internationalization by a simple 3 lines code in lispreader's read_string().
To translate a level's title to European Portuguese, I would look at:
(title "Hello World!")
and add:
(title-pt_PT "Olá Mundo!")
Also, made display_text_file() using lispreader (to make it i18n too). Unfortunately, there is a crash of lisp_reader in my system (not related), so I wasn't able to give it a try.
data/*.txt files also need updating to work. Else, it should just skip it, without crashing.
Index: font.cpp
===================================================================
RCS file: /cvsroot/super-tux/supertux/src/screen/font.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- font.cpp 29 Jun 2004 13:00:40 -0000 1.5
+++ font.cpp 7 Jul 2004 19:19:18 -0000 1.6
@@ -26,6 +26,7 @@
#include "screen.h"
#include "font.h"
#include "drawing_context.h"
+#include "../lispreader.h"
Font::Font(const std::string& file, FontType ntype, int nw, int nh,
int nshadowsize)
@@ -138,36 +139,40 @@
void display_text_file(const std::string& file, Surface* surface, float scroll_speed)
{
- int done;
- float scroll;
- float speed;
- FILE* fi;
- char temp[1024];
+ std::string text;
std::vector<std::string> names;
- char filename[1024];
- sprintf(filename,"%s/%s", datadir.c_str(), file.c_str());
- if((fi = fopen(filename,"r")) != NULL)
+ lisp_object_t* root_obj = lisp_read_from_file(datadir + file);
+ lisp_object_t* cur = lisp_car(root_obj);
+
+ if (lisp_symbol_p(cur) && strcmp(lisp_symbol(cur), "text") == 0)
{
- while(fgets(temp, sizeof(temp), fi) != NULL)
- {
- temp[strlen(temp)-1]='\0';
- names.push_back(temp);
- }
- fclose(fi);
+ LispReader reader(lisp_cdr(root_obj));
+ reader.read_string("text", text);
}
else
{
- names.push_back("File was not found!");
- names.push_back(filename);
- names.push_back("Shame on the guy, who");
- names.push_back("forgot to include it");
- names.push_back("in your SuperTux distribution.");
+ std::cerr << "Error: Could not open text. Ignoring...\n";
+ return;
}
- scroll = 0;
- speed = scroll_speed / 50;
- done = 0;
+ unsigned int l, i;
+ l = 0;
+ while(true)
+ {
+ i = l;
+ l = text.find("\n", i);
+ if(l != std::string::npos)
+ break;
+
+ char* temp = 0;
+ text.copy(temp, l, i);
+ names.push_back(temp);
+ }
+
+ int done = 0;
+ float scroll = 0;
+ float speed = scroll_speed / 50;
DrawingContext context;
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|