[Tux4kids-commits] r830 - in tuxtype/trunk: . src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Thu Jan 8 19:31:57 UTC 2009
Author: dbruce-guest
Date: 2009-01-08 19:31:57 +0000 (Thu, 08 Jan 2009)
New Revision: 830
Modified:
tuxtype/trunk/ChangeLog
tuxtype/trunk/ChangeLog~
tuxtype/trunk/src/scripting.c
tuxtype/trunk/src/titlescreen.c
Log:
adaptation of menu code for lessons activity so as to be consistent with
rest of menus.
Modified: tuxtype/trunk/ChangeLog
===================================================================
--- tuxtype/trunk/ChangeLog 2009-01-08 18:06:48 UTC (rev 829)
+++ tuxtype/trunk/ChangeLog 2009-01-08 19:31:57 UTC (rev 830)
@@ -1,5 +1,8 @@
+08 Jan 2009 - svn revision 830
+[ David Bruce <davidstuartbruce at gmail.com> ]
+ - adaptation of menu code for lessons activity so as to be consistent with
+ rest of menus.
-=======
06 Jan 2009 - svn revision 822
[ David Bruce <davidstuartbruce at gmail.com> ]
- Bugfix to prevent BlackOutline() from segfault if passed empty string
Modified: tuxtype/trunk/ChangeLog~
===================================================================
--- tuxtype/trunk/ChangeLog~ 2009-01-08 18:06:48 UTC (rev 829)
+++ tuxtype/trunk/ChangeLog~ 2009-01-08 19:31:57 UTC (rev 830)
@@ -1,15 +1,3 @@
-<<<<<<< .mine
-10 Dec 2008 - svn revision 795
-Version 1.7.0
-[ David Bruce <davidstuartbruce at gmail.com> ]
- - First release following 2008 Google Summer of Code.
- - Several major enhancements:
- - GNU gettext used for internationalization (M. Mohan)
- - Themes and translations for multiple additional
- Indic languages (M. Mohan)
- - Graphical keyboard hint system (Sreyas K.)
- - Rewritten phrase practice activity (D. Bruce)
- - Fullscreen mode at native resolution (D. Bruce)
=======
06 Jan 2009 - svn revision 822
@@ -22,7 +10,18 @@
- Bugfix for path for bundled fonts - caused error when run on non-Debian
systems.
->>>>>>> .r825
+10 Dec 2008 - svn revision 795
+Version 1.7.0
+[ David Bruce <davidstuartbruce at gmail.com> ]
+ - First release following 2008 Google Summer of Code.
+ - Several major enhancements:
+ - GNU gettext used for internationalization (M. Mohan)
+ - Themes and translations for multiple additional
+ Indic languages (M. Mohan)
+ - Graphical keyboard hint system (Sreyas K.)
+ - Rewritten phrase practice activity (D. Bruce)
+ - Fullscreen mode at native resolution (D. Bruce)
+
2008-11-22 gettextize <bug-gnu-gettext at gnu.org>
* m4/gettext.m4: Upgrade to gettext-0.17.
Modified: tuxtype/trunk/src/scripting.c
===================================================================
--- tuxtype/trunk/src/scripting.c 2009-01-08 18:06:48 UTC (rev 829)
+++ tuxtype/trunk/src/scripting.c 2009-01-08 19:31:57 UTC (rev 830)
@@ -115,10 +115,9 @@
run_script();
}
-/* FIXME work in progress - adapt code to actually pick lessons! */
+
int TestLesson(void)
{
-{
SDL_Surface* titles[MAX_LESSONS] = {NULL};
SDL_Surface* select[MAX_LESSONS] = {NULL};
SDL_Surface* left = NULL, *right = NULL;
@@ -129,113 +128,102 @@
int stop = 0;
int loc = 0;
int old_loc = 1;
- int lists = 0;
+ int num_scripts = 0;
+ int found = 0;
int i;
- unsigned char wordPath[FNLEN];
- unsigned char wordlistFile[MAX_LESSONS][200];
- unsigned char wordlistName[MAX_LESSONS][200];
+ unsigned char script_path[FNLEN];
+ unsigned char script_filenames[MAX_LESSONS][200];
+ char fn[FNLEN];
- DIR* wordsDir = NULL;
- struct dirent* wordsFile = NULL;
- FILE* tempFile = NULL;
+ DIR* script_dir = NULL;
+ struct dirent* script_file = NULL;
- LOG("Entering chooseWordlist():\n");
+ LOG("Entering TestLesson():\n");
- /* find the directory to load wordlists from */
+ font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
- /* Check under theme directory first, if theme selected: */
- if (!settings.use_english) /* Using theme: */
+ /* First look in theme path, if desired: */
+ if (!settings.use_english)
{
- sprintf(wordPath,"%s/words", settings.theme_data_path);
- if (!CheckFile(wordPath))
+ sprintf(script_path, "%s/scripts", settings.theme_data_path);
+ if (CheckFile(script_path))
{
- fprintf(stderr, "chooseWordList() - theme contains no wordlist dir \n");
- return 0;
+ DEBUGCODE {fprintf(stderr, "Using theme script dir: %s\n", script_path);}
+ found = 1;
}
}
- else /* No theme selected - using English: */
+
+ /* Now look in default path if desired or needed: */
+ if (!found)
{
- sprintf(wordPath,"%s/words", settings.default_data_path);
- if (!CheckFile(wordPath))
+ sprintf( script_path, "%s/scripts", settings.default_data_path);
+ if (CheckFile(script_path))
{
- fprintf(stderr, "chooseWordList() - data path contains no wordlist dir \n");
- return 0;
+ DEBUGCODE { fprintf(stderr, "Using theme script dir: %s\n", script_path); }
+ found = 1;
}
}
- /* If we get to here, we know there is at least a wordlist directory */
+ if (!found)
+ {
+ fprintf(stderr, "TestLesson(): Error finding script directory!\n");
+ return 0;
+ }
+
+
+ /* If we get to here, we know there is at least a lesson script directory */
/* but not necessarily any valid files. */
- DEBUGCODE { fprintf(stderr, "wordPath is: %s\n", wordPath); }
+ DEBUGCODE { fprintf(stderr, "script_path is: %s\n", script_path); }
/* FIXME looks like a place for scandir() - or our own w32_scandir() */
- /* create a list of all the .txt files */
+ /* create a list of all the .xml files */
- wordsDir = opendir( wordPath );
+ script_dir = opendir(script_path);
do
{
- wordsFile = readdir(wordsDir);
- if (!wordsFile)
- break; /* Loop continues until break occurs */
+ script_file = readdir(script_dir);
+ if (!script_file)
+ break;
- /* must have at least .txt at the end */
- if (strlen(wordsFile->d_name) < 5)
+ /* must have at least '.xml' at the end */
+ if (strlen(script_file->d_name) < 5)
continue;
- if (strcmp(&wordsFile->d_name[strlen(wordsFile->d_name) -4 ],".txt"))
+ if (strcmp(&script_file->d_name[strlen(script_file->d_name) - 4],".xml"))
continue;
- sprintf(wordlistFile[lists], "%s/%s", wordPath, wordsFile->d_name);
+ sprintf(script_filenames[num_scripts], "%s", script_file->d_name);
+ num_scripts++;
+ DEBUGCODE { fprintf(stderr, "Adding XML file no. %d: %s\n",
+ num_scripts, script_filenames[num_scripts]); }
- /* load the name for the wordlist from the file ... (1st line) */
- tempFile = fopen( wordlistFile[lists], "r" );
- if (!tempFile)
- continue;
+ } while (1); /* Leave loop when readdir() returns NULL */
- fscanf(tempFile, "%[^\n]\n", wordlistName[lists]);
+ closedir(script_dir);
- /* check to see if it has a \r at the end of it (dos format!) */
- if (wordlistName[lists][strlen(wordlistName[lists]) - 1] == '\r')
- wordlistName[lists][strlen(wordlistName[lists]) - 1] = '\0';
+ DEBUGCODE { fprintf(stderr, "Found %d . xml file(s) in script dir\n", num_scripts); }
- lists++;
- fclose(tempFile);
- } while (1); /* Loop continues until break occurs */
-
- closedir(wordsDir);
-
- DEBUGCODE { fprintf(stderr, "Found %d .txt file(s) in words dir\n", lists); }
-
-
-
- /* let the user pick the list */
-
- /* Render SDL_Surfaces for list entries: */
-// titles[0] = BlackOutline( _("Alphabet"), font, &white );
-// select[0] = BlackOutline( _("Alphabet"), font, &yellow);
-
- /* NOTE - no longer hard-coding titles[0] to be alphabet - themes */
- /* should include a regular word list file called "alphabet.txt" */
- /* Should sort the list and always put the alphabet file first, if */
- /* present. */
- for (i = 0; i < lists; i++)
+ /* let the user pick the lesson script */
+ for (i = 0; i < num_scripts; i++)
{
- titles[i] = BlackOutline( wordlistName[i], font, &white );
- select[i] = BlackOutline( wordlistName[i], font, &yellow);
+ titles[i] = BlackOutline( script_filenames[i], font, &white );
+ select[i] = BlackOutline( script_filenames[i], font, &yellow);
}
left = LoadImage("left.png", IMG_ALPHA);
right = LoadImage("right.png", IMG_ALPHA);
+ LoadBothBkgds("main_bkg.png");
/* Get out if needed surface not loaded successfully: */
if (!CurrentBkgd() || !left || !right)
{
- fprintf(stderr, "chooseWordList(): needed image not available\n");
+ fprintf(stderr, "TestLesson(): needed image not available\n");
- for (i = 0; i < lists; i++)
+ for (i = 0; i < num_scripts; i++)
{
SDL_FreeSurface(titles[i]);
SDL_FreeSurface(select[i]);
@@ -280,10 +268,10 @@
break;
case SDL_MOUSEMOTION:
- for (i=0; (i<8) && (loc-(loc%8)+i<lists); i++)
- if (inRect( titleRects[i], event.motion.x, event.motion.y ))
+ for (i = 0; (i < 8) && (loc - (loc % 8) + i < num_scripts); i++)
+ if (inRect(titleRects[i], event.motion.x, event.motion.y ))
{
- loc = loc-(loc%8)+i;
+ loc = loc - (loc % 8) + i;
break;
}
break;
@@ -300,22 +288,21 @@
if (inRect(rightRect, event.button.x, event.button.y))
{
- if (loc - (loc % 8) + 8 < lists)
+ if (loc - (loc % 8) + 8 < num_scripts)
{
loc = loc - (loc % 8) + 8;
break;
}
}
- for (i = 0; (i < 8) && (loc - (loc % 8) + i < lists); i++)
+ for (i = 0; (i < 8) && (loc - (loc % 8) + i < num_scripts); i++)
{
if (inRect(titleRects[i], event.button.x, event.button.y))
{
loc = loc - (loc % 8) + i;
- ClearWordList(); /* clear old selection */
- GenerateWordList(wordlistFile[loc]);
+ sprintf(fn, "%s/scripts/%s", settings.default_data_path, script_filenames[loc]);
stop = 1;
- break;
+ break;
}
}
@@ -330,8 +317,7 @@
if (event.key.keysym.sym == SDLK_RETURN)
{
- ClearWordList(); /* clear old selection */
- GenerateWordList(wordlistFile[loc]);
+ sprintf(fn, "%s/scripts/%s", settings.default_data_path, script_filenames[loc]);
stop = 1;
break;
}
@@ -346,7 +332,7 @@
if ((event.key.keysym.sym == SDLK_RIGHT)
|| (event.key.keysym.sym == SDLK_PAGEDOWN))
{
- if (loc - (loc % 8) + 8 < lists)
+ if (loc - (loc % 8) + 8 < num_scripts)
loc = (loc - (loc % 8) + 8);
}
@@ -358,7 +344,7 @@
if (event.key.keysym.sym == SDLK_DOWN)
{
- if (loc+1<lists)
+ if (loc + 1 < num_scripts)
loc++;
}
}
@@ -373,7 +359,7 @@
start = loc - (loc % 8);
- for (i = start; i< MIN(start + 8,lists); i++)
+ for (i = start; i < MIN(start + 8, num_scripts); i++)
{
titleRects[i % 8].x = screen->w/2 - (titles[i]->w/2);
if (i == loc) /* Draw selected text in yellow: */
@@ -386,7 +372,7 @@
if (start > 0)
SDL_BlitSurface(left, NULL, screen, &leftRect);
- if (start + 8 < lists)
+ if (start + 8 < num_scripts)
SDL_BlitSurface(right, NULL, screen, &rightRect);
SDL_UpdateRect(screen, 0, 0, 0 ,0);
@@ -397,10 +383,12 @@
}
/* --- clear graphics before leaving function --- */
- for (i = 0; i < lists; i++)
+ for (i = 0; i < num_scripts; i++)
{
- SDL_FreeSurface(titles[i]);
- SDL_FreeSurface(select[i]);
+ if (titles[i])
+ SDL_FreeSurface(titles[i]);
+ if (select[i])
+ SDL_FreeSurface(select[i]);
titles[i] = select[i] = NULL;
}
@@ -408,291 +396,35 @@
SDL_FreeSurface(right);
left = right = NULL; /* Maybe overkill - about to be destroyed anyway */
- DEBUGCODE { fprintf( stderr, "Leaving chooseWordlist();\n" ); }
+ FreeBothBkgds();
+ TTF_CloseFont(font);
+ font = NULL;
+
+
if (stop == 2)
+ {
+ SDL_ShowCursor(1);
return 0;
+ }
+ /* Getting to here means "stop == 1", try to run chosen script: */
+ if (load_script(fn) != 0)
+ {
+ fprintf(stderr, "load_script() failed to load '%s'\n",fn);
+ SDL_ShowCursor(1);
+ return 0; // bail if any errors occur
+ }
+
+ DEBUGCODE { fprintf(stderr, "Attempting to run script: %s\n", fn); }
+
+ run_script();
+ SDL_ShowCursor(1);
+
+ LOG("Leave TestLesson()\n");
+
return 1;
}
-// SDL_Surface* left = NULL, *right = NULL, *pointer = NULL, *bkg = NULL;
-// SDL_Surface* filenames[200] = {NULL};
-//
-// SDL_Rect spot, arrow_area;
-// SDL_Rect leftRect, rightRect;
-// SDL_Rect titleRects[8];
-//
-// TTF_Font* font = NULL;
-//
-// int stop = 0;
-// int loc = 0;
-// int old_loc = 1;
-// int i;
-// int c = 0;
-// int found = 0;
-//
-// char fn[FNLEN];
-// unsigned char wordlistFile[200][200];
-// unsigned char script_path[FNLEN];
-//
-// DIR* wordsDir = NULL;
-// struct dirent* wordsFile = NULL;
-//
-// LOG("\nEnter TestLesson()\n");
-//
-// pointer = LoadImage( "right.png", IMG_ALPHA );
-// bkg = LoadImage( "main_bkg.png", IMG_REGULAR );
-// left = LoadImage("left.png", IMG_ALPHA);
-// right = LoadImage("right.png", IMG_ALPHA);
-//
-// if (!pointer || !bkg || !left ||!right)
-// {
-// fprintf(stderr, "TestLesson() - needed image not found\n");
-// /* Free anything that got loaded: */
-// SDL_FreeSurface(pointer);
-// SDL_FreeSurface(left);
-// SDL_FreeSurface(right);
-// SDL_FreeSurface(bkg);
-// pointer = left = right = bkg = NULL;
-// return 0;
-// }
-//
-// SDL_ShowCursor(0);
-//
-// /* find the directory to load wordlists from */
-// /* First look in theme path, if desired: */
-// if (!settings.use_english)
-// {
-// sprintf( script_path, "%s/scripts", settings.theme_data_path);
-// if (CheckFile(script_path))
-// {
-// DEBUGCODE { fprintf(stderr, "Using theme script dir: %s\n", script_path); }
-// found = 1;
-// }
-// }
-//
-// /* Now look in default path if desired or needed: */
-// if (!found)
-// {
-// sprintf( script_path, "%s/scripts", settings.default_data_path);
-// if (CheckFile(script_path))
-// {
-// DEBUGCODE { fprintf(stderr, "Using theme script dir: %s\n", script_path); }
-// found = 1;
-// }
-// }
-//
-// if (!found)
-// {
-// fprintf(stderr, "TestLesson(): Error finding script directory!\n");
-// return 0;
-// }
-//
-// /* What is this location? */
-// spot.x = 60;
-// spot.y = 20;
-//
-//
-// /* create a list of all the .xml files */
-//
-// wordsDir = opendir( script_path );
-// font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
-// do
-// {
-// wordsFile = readdir(wordsDir);
-// if (!wordsFile)
-// break;
-//
-// /* must have at least '.xml' at the end */
-// if (strlen(wordsFile->d_name) < 5)
-// continue;
-//
-// if (strcmp(&wordsFile->d_name[strlen(wordsFile->d_name)-4],".xml"))
-// continue;
-//
-// sprintf( wordlistFile[c], "%s", wordsFile->d_name );
-//
-// DEBUGCODE { fprintf(stderr, "Adding XML file no. %d: %s\n", c, wordlistFile[c]); }
-//
-//
-// filenames[c] = TTF_RenderUTF8_Blended(font, wordsFile->d_name, white);
-// SDL_BlitSurface( filenames[c], NULL, screen, &spot );
-// SDL_FreeSurface(filenames[c]);
-// c++;
-// spot.y += MENU_FONT_SIZE;
-// } while (1); /* Leave loop when readdir() returns NULL */
-//
-// TTF_CloseFont(font);
-// font = NULL;
-// closedir(wordsDir);
-// wordsDir = NULL;
-// SDL_Flip(screen);
-//
-// /* Should be safe - tested 'left' and 'right' above: */
-// leftRect.w = left->w; leftRect.h = left->h;
-// leftRect.x = 320 - 80 - (leftRect.w/2); leftRect.y = 430;
-//
-// rightRect.w = right->w; rightRect.h = right->h;
-// rightRect.x = 320 + 80 - (rightRect.w/2); rightRect.y = 430;
-//
-// /* set initial rect sizes */
-// titleRects[0].y = 30;
-// titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
-//
-// for (i = 1; i < 8; i++)
-// {
-// titleRects[i].y = titleRects[i-1].y + 50;
-// titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
-// }
-//
-// arrow_area.x = 0;
-// arrow_area.y = 0;
-// arrow_area.w = 59;
-// arrow_area.h = 479;
-//
-// while (!stop)
-// {
-// while (SDL_PollEvent(&event))
-// {
-// switch (event.type)
-// {
-// case SDL_QUIT:
-// exit(0);
-// break;
-// /* FIXME some of mouse code is wrong */
-// case SDL_MOUSEMOTION:
-// for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
-// if (inRect( titleRects[i], event.motion.x, event.motion.y ))
-// {
-// loc = loc-(loc%8)+i;
-// break;
-// }
-// break;
-//
-// case SDL_MOUSEBUTTONDOWN:
-// if (inRect( leftRect, event.button.x, event.button.y ))
-// if (loc-(loc%8)-8 >= 0)
-// {
-// loc=loc-(loc%8)-8;
-// break;
-// }
-//
-// if (inRect( rightRect, event.button.x, event.button.y ))
-// if (loc-(loc%8)+8 < c)
-// {
-// loc=loc-(loc%8)+8;
-// break;
-// }
-//
-// for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
-// if (inRect(titleRects[i], event.button.x, event.button.y))
-// {
-// // loc = loc-(loc%8)+i;
-// // ClearWordList(); /* clear old selection */
-// // if (loc==0)
-// // UseAlphabet();
-// // else
-// // GenerateWordList(wordlistFile[loc]);
-// //
-// // stop = 1;
-// // break;
-// }
-// break;
-//
-// case SDL_KEYDOWN:
-// if (event.key.keysym.sym == SDLK_ESCAPE)
-// {
-// stop = 2;
-// break;
-// }
-//
-// if (event.key.keysym.sym == SDLK_RETURN)
-// {
-// sprintf(fn, "%s/scripts/%s", settings.default_data_path, wordlistFile[loc]);
-// stop = 1;
-// break;
-// }
-//
-// if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP))
-// {
-// if (loc-(loc%8)-8 >= 0)
-// loc=loc-(loc%8)-8;
-// SDL_ShowCursor(1);
-// }
-//
-// if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN))
-// {
-// if (loc-(loc%8)+8 < c)
-// loc=(loc-(loc%8)+8);
-// }
-//
-// if (event.key.keysym.sym == SDLK_UP)
-// {
-// if (loc > 0)
-// loc--;
-// }
-//
-// if (event.key.keysym.sym == SDLK_DOWN)
-// {
-// if (loc+1< c)
-// loc++;
-// }
-// } /* End of 'switch(event.type)' loop */
-// } /* End of 'while(SDL_PollEvent(&event))' loop */
-//
-//
-//
-// if (old_loc != loc)
-// {
-// int start;
-// SDL_BlitSurface( bkg, &arrow_area, screen, NULL);
-//
-// start = loc;
-// for (i = start; i < c; i++)
-// {
-// spot.x = 5;
-// spot.y = (i * MENU_FONT_SIZE) + 18;
-// if (i == loc)
-// SDL_BlitSurface(pointer, NULL, screen, &spot);
-// }
-//
-// SDL_Flip(screen);
-// }
-//
-// SDL_Delay(40);
-// old_loc = loc;
-// } /* End of 'while(!stop)' loop */
-//
-// SDL_FreeSurface(pointer);
-// SDL_FreeSurface(left);
-// SDL_FreeSurface(right);
-// SDL_FreeSurface(bkg);
-// pointer = left = right = bkg = NULL;
-//
-// if (stop == 2)
-// {
-// LOG("Player pressed 'Esc' - leaving TestLesson\n");
-// return 1;
-// }
-//
-// /* Getting to here means "stop == 1", try to run chosen script: */
-// if (load_script(fn) != 0)
-// {
-// fprintf(stderr, "load_script() failed to load '%s'\n",fn);
-// return 0; // bail if any errors occur
-// }
-//
-// DEBUGCODE { fprintf(stderr, "Attempting to run script: %s\n", fn); }
-//
-// run_script();
-//
-// /* FIXME - shouldn't we show the cursor if returning in other code paths? */
-// SDL_ShowCursor(1);
-//
-// LOG("Leave TestLesson()\n");
-//
-// return 1;
-}
Modified: tuxtype/trunk/src/titlescreen.c
===================================================================
--- tuxtype/trunk/src/titlescreen.c 2009-01-08 18:06:48 UTC (rev 829)
+++ tuxtype/trunk/src/titlescreen.c 2009-01-08 19:31:57 UTC (rev 830)
@@ -91,7 +91,7 @@
static const char *menu_text[]=
{"", "", "", "", "" ,
"",gettext_noop("Fish Cascade"),gettext_noop("Easy"),gettext_noop("Space Cadet"),gettext_noop("Edit Word Lists"),
- "",gettext_noop("Comet Zap"),gettext_noop("Medium"),gettext_noop("Pilot"),gettext_noop("Practice"),
+ "",gettext_noop("Comet Zap"),gettext_noop("Medium"),gettext_noop("Pilot"),gettext_noop("Phrase Practice"),
"",gettext_noop("Lessons"),gettext_noop("Hard"), gettext_noop("Ace"),gettext_noop("Project Info"),
"", gettext_noop("Options"),gettext_noop("Instructions"),gettext_noop("Commander"),gettext_noop("Setup Language"),
"", gettext_noop("Quit"),gettext_noop("Main Menu"),gettext_noop("Main Menu"),gettext_noop("Main Menu")};
More information about the Tux4kids-commits
mailing list