[Tux4kids-commits] r651 - tuxtype/trunk/src
mobin-guest at alioth.debian.org
mobin-guest at alioth.debian.org
Mon Aug 18 14:28:21 UTC 2008
Author: mobin-guest
Date: 2008-08-18 14:28:20 +0000 (Mon, 18 Aug 2008)
New Revision: 651
Modified:
tuxtype/trunk/src/globals.h
tuxtype/trunk/src/titlescreen.c
tuxtype/trunk/src/titlescreen.h
Log:
GUI for Editing Word List Implemented
Modified: tuxtype/trunk/src/globals.h
===================================================================
--- tuxtype/trunk/src/globals.h 2008-08-18 12:38:50 UTC (rev 650)
+++ tuxtype/trunk/src/globals.h 2008-08-18 14:28:20 UTC (rev 651)
@@ -177,8 +177,8 @@
QUIT_GAME, CASCADE, OPTIONS, LESSONS,
INSTRUCT_CASCADE, CASCADE1, CASCADE2, CASCADE3, CASCADE4,
INSTRUCT_LASER, LASER1, LASER2, LASER3, LASER4,
- FREETYPE, ASDF, ALL, MAIN, SET_LANGUAGE, PROJECT_INFO, EDIT_WORDLIST,
- LEVEL1, LEVEL2, LEVEL3, LEVEL4, LASER, INSTRUCT, NOT_CODED, NONE};
+ FREETYPE, ASDF, ALL, MAIN, SET_LANGUAGE, PROJECT_INFO, NOT_CODED,
+ LEVEL1, LEVEL2, LEVEL3, LEVEL4, LASER, INSTRUCT, EDIT_WORDLIST, NONE};
/* Title sequence constants */
#define PRE_ANIM_FRAMES 10
Modified: tuxtype/trunk/src/titlescreen.c
===================================================================
--- tuxtype/trunk/src/titlescreen.c 2008-08-18 12:38:50 UTC (rev 650)
+++ tuxtype/trunk/src/titlescreen.c 2008-08-18 14:28:20 UTC (rev 651)
@@ -59,7 +59,8 @@
/* Local function prototypes: */
static int chooseWordlist(void);
static void draw_button(int id, sprite* s);
-static void not_implemented(void);
+static void ChooseWord(char *words_file);
+static void ChooseFile(void);
static int load_media(void);
static void load_menu(void);
static void unload_media(void);
@@ -513,9 +514,9 @@
}
- if (menu_opt == NOT_CODED)
+ if (menu_opt == EDIT_WORDLIST)
{
- not_implemented();
+ ChooseFile();
redraw = 1;
}
@@ -718,7 +719,7 @@
if (!found)
{
fprintf(stderr, "LoadKeyboard(): Error finding file for keyboard setup!\n");
- return 0;
+ return;
}
fp=fopen(fn,"r");
@@ -1589,7 +1590,446 @@
return 1;
}
+static void ChooseFile(void)
+{
+ SDL_Surface* titles[MAX_WORD_LISTS] = {NULL};
+ SDL_Surface* select[MAX_WORD_LISTS] = {NULL};
+ SDL_Surface *photo = NULL;
+ SDL_Surface* bkg = NULL;
+ TTF_Font* font = NULL;
+ SDL_Rect titleRects[8];
+ int stop = 0;
+ int loc = 0;
+ int old_loc = 1;
+ int themes = 0;
+ int i;
+ unsigned char fn[FNLEN];
+ unsigned char wordTypes[MAX_WORD_LISTS][FNLEN];
+ unsigned char fileNames[MAX_WORD_LISTS][FNLEN];
+ int old_use_english;
+ char old_theme_path[FNLEN];
+ FILE *fp;
+ DIR* themesDir = NULL;
+ struct dirent* themesFile = NULL;
+
+ /* save previous settings in case we back out: */
+ old_use_english = settings.use_english;
+ strncpy(old_theme_path, settings.theme_data_path, FNLEN - 1);
+
+ sprintf(fn , "%s/words", settings.theme_data_path);
+
+ themesDir = opendir(fn);
+
+ if (!themesDir)
+ {
+ fprintf(stderr, "Choosefile() - cannot open themes directory!");
+ return;
+ }
+
+ do
+ {
+ themesFile = readdir(themesDir);
+ if (!themesFile)
+ break;
+
+ /* we ignore any hidden file and CVS */
+
+ if (themesFile->d_name[0] == '.')
+ continue;
+
+ if (strcmp("CVS", themesFile->d_name)==0)
+ continue;
+
+
+ sprintf(fn, "%s/words/%s", settings.theme_data_path, themesFile->d_name);
+
+
+ /* CheckFile() returns 2 if dir, 1 if file, 0 if neither: */
+ if (CheckFile(fn) == 1) {
+ fp=fopen(fn,"r");
+ /* HACK: we should get the names from file :) */
+ fscanf(fp, "%[^\n]\n", wordTypes[themes]);
+ /* Make sure theme name is capitalized: */
+ wordTypes[themes][0] = toupper(wordTypes[themes][0]);
+ fclose(fp);
+ strncpy( fileNames[themes++], themesFile->d_name, FNLEN-1 );
+
+ }
+ } while (1);
+
+ closedir(themesDir);
+
+ settings.use_english = 1;
+ // HACK: is font empty now???
+ font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+
+
+ for (i = 0; i<themes; i++) {
+ titles[i] = BlackOutline( wordTypes[i], font, &white );
+ select[i] = BlackOutline( wordTypes[i], font, &yellow);
+ }
+
+
+ TTF_CloseFont(font);
+ font = NULL;
+
+ settings.use_english = old_use_english;
+
+ bkg = LoadImage("main_bkg.png", IMG_REGULAR);
+
+
+ /* set initial rect sizes */
+ titleRects[0].y = 150;
+ 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;
+ }
+
+
+ while (!stop) {
+ while (SDL_PollEvent(&event))
+ switch (event.type) {
+ case SDL_QUIT:
+ exit(0);
+ break;
+ case SDL_MOUSEMOTION:
+ for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++)
+ if (inRect( titleRects[i], event.motion.x, event.motion.y )) {
+ loc = loc-(loc%8)+i;
+ break;
+ }
+
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+
+ for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++)
+ if (inRect(titleRects[i], event.button.x, event.button.y)) {
+ loc = loc-(loc%8)+i;
+ ChooseWord(fileNames[loc]);
+ break;
+ }
+ break;
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ settings.use_english = old_use_english;
+ strncpy(settings.theme_data_path, old_theme_path, FNLEN - 1);
+ stop = 1;
+ break;
+ }
+ if (event.key.keysym.sym == SDLK_RETURN) {
+ ChooseWord(fileNames[loc]);
+ loc=0;
+ 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;
+ }
+
+ if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
+ if (loc-(loc%8)+8 < themes)
+ 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<themes)
+ loc++;
+ }
+ }
+
+ if (old_loc != loc) {
+ int start;
+
+ SDL_BlitSurface( bkg, NULL, screen, NULL );
+
+ //if (loc) SetupPaths(fileNames[loc]); else SetupPaths(NULL);
+
+ start = loc - (loc % 8);
+ for (i = start; i<MIN(start+8,themes); i++) {
+ titleRects[i%8].x = 320 - (titles[i]->w/2);
+ if (i == loc)
+ SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
+ else
+ SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
+ }
+
+ SDL_UpdateRect(screen, 0, 0, 0 ,0);
+ }
+ SDL_Delay(40);
+ old_loc = loc;
+ }
+
+ /* --- clear graphics before quitting --- */
+
+ for (i = 0; i<themes; i++)
+ {
+ SDL_FreeSurface(titles[i]);
+ SDL_FreeSurface(select[i]);
+ }
+
+
+ SDL_FreeSurface(bkg);
+
+ bkg = NULL; /* the other pointers are going out of scope so we don't */
+ /* have to worry about setting them to NULL */
+}
+
+
+static void ChooseWord(char *words_file)
+{
+ SDL_Surface* titles[MAX_WORD_LISTS] = {NULL};
+ SDL_Surface* select[MAX_WORD_LISTS] = {NULL};
+ SDL_Surface* left = NULL, *right = NULL;
+ SDL_Rect leftRect, rightRect;
+ SDL_Surface *photo = NULL;
+ SDL_Surface* bkg = NULL;
+ TTF_Font* font = NULL;
+ SDL_Rect worldRect, photoRect;
+ SDL_Rect titleRects[8];
+ int stop = 0;
+ int loc = 0;
+ int old_loc = 1;
+
+ FILE *fp;
+
+ int start,themes = 0;
+ int i,len;
+ unsigned char fn[FNLEN];
+ unsigned char str[FNLEN];
+ unsigned char editWordW[MAX_WORD_LISTS][FNLEN];
+ unsigned char editWordY[MAX_WORD_LISTS][FNLEN];
+
+ wchar_t temp[FNLEN];
+
+ int old_use_english;
+ char old_theme_path[FNLEN];
+
+
+
+ /* save previous settings in case we back out: */
+ old_use_english = settings.use_english;
+ strncpy(old_theme_path, settings.theme_data_path, FNLEN - 1);
+
+ sprintf(fn , "%s/words/%s", settings.theme_data_path,words_file);
+
+ fp=fopen(fn,"r");
+ fscanf(fp, "%[^\n]\n", str);
+
+ while(!feof(fp))
+ {
+ /* HACK: we should get the strings from file :) */
+ fscanf(fp, "%[^\n]\n", editWordW[themes]);
+ strcpy(editWordY[themes++],editWordW[themes]);
+ }
+
+ fclose(fp);
+
+ settings.use_english = 1;
+ // HACK: is font empty now???
+ font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+
+ for (i = 0; i<themes; i++) {
+ titles[i] = BlackOutline( editWordW[i], font, &white );
+ strcat(editWordY[i],"|");
+ select[i] = BlackOutline( editWordY[i], font, &yellow);
+ }
+
+ TTF_CloseFont(font);
+ font = NULL;
+
+ settings.use_english = old_use_english;
+ strncpy(settings.theme_data_path, old_theme_path, FNLEN - 1);
+
+ bkg = LoadImage("main_bkg.png", IMG_REGULAR);
+
+ left = LoadImage("left.png", IMG_ALPHA);
+ leftRect.w = left->w; leftRect.h = left->h;
+ leftRect.x = 320 - 100 - (leftRect.w/2); leftRect.y = 430;
+
+ right = LoadImage("right.png", IMG_ALPHA);
+ rightRect.w = right->w; rightRect.h = right->h;
+ rightRect.x = 320 + 100 - (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;
+ }
+
+
+ while (!stop) {
+ while (SDL_PollEvent(&event))
+ switch (event.type) {
+ case SDL_QUIT:
+ exit(0);
+ break;
+ case SDL_MOUSEMOTION:
+ 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 < themes) {
+ loc=loc-(loc%8)+8;
+ break;
+ }
+ for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++)
+ if (inRect( titleRects[i], event.motion.x, event.motion.y )) {
+ loc = loc-(loc%8)+i;
+ break;
+ }
+
+ break;
+
+ case SDL_KEYDOWN:
+ i=1;
+ if (event.key.keysym.sym == SDLK_BACKSPACE) {
+ font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+
+ len=ConvertFromUTF8(temp,editWordW[loc]);
+ temp[len-1]=temp[len];
+ len=ConvertToUTF8(temp,editWordW[loc]);
+ titles[loc] = BlackOutline(editWordW[loc], font, &white );
+ len=ConvertFromUTF8(temp,editWordY[loc]);
+ temp[len-2]=temp[len-1];
+ temp[len-1]=temp[len];
+ len=ConvertToUTF8(temp,editWordY[loc]);
+ select[loc] = BlackOutline(editWordY[loc], font, &yellow);
+ TTF_CloseFont(font);
+ font = NULL;
+ break;
+ }
+
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ settings.use_english = old_use_english;
+ strncpy(settings.theme_data_path, old_theme_path, FNLEN - 1);
+ 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;
+ break;
+ }
+
+ if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
+ if (loc-(loc%8)+8 < themes)
+ loc=(loc-(loc%8)+8);
+ break;
+ }
+
+
+ if (event.key.keysym.sym == SDLK_UP) {
+ if (loc > 0)
+ loc--;
+ break;
+ }
+
+ if (event.key.keysym.sym == SDLK_DOWN) {
+ if (loc+1<themes)
+ loc++;
+ break;
+ }
+ switch (event.key.keysym.sym){
+ case SDLK_RALT:
+ case SDLK_LALT:
+ case SDLK_RSHIFT:
+ case SDLK_LSHIFT:
+ case SDLK_RCTRL:
+ case SDLK_LCTRL:i=0;
+ break;
+ }
+ if(i){
+
+ font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+
+ len=ConvertFromUTF8(temp,editWordW[loc]);
+ temp[len]=event.key.keysym.unicode;
+ temp[len+1]=0;
+ ConvertToUTF8(temp,editWordW[loc]);
+ titles[loc] = BlackOutline(editWordW[loc], font, &white );
+
+ len=ConvertFromUTF8(temp,editWordY[loc]);
+ temp[len+1]=0;
+ temp[len]=temp[len-1];
+ temp[len-1]=event.key.keysym.unicode;
+ ConvertToUTF8(temp,editWordY[loc]);
+ select[loc] = BlackOutline(editWordY[loc], font, &yellow);
+ TTF_CloseFont(font);
+ font = NULL;
+ i=0;
+ break;
+ }
+ }
+ if(!stop){
+ SDL_BlitSurface( bkg, NULL, screen, NULL );
+
+// if (loc) SetupPaths(fileNames[loc]); else SetupPaths(NULL);
+
+ start = loc - (loc % 8);
+ for (i = start; i<MIN(start+8,themes); i++) {
+ titleRects[i%8].x = 320 - (titles[i]->w/2);
+ if (i == loc)
+ SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
+ else
+ SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
+ }
+
+ /* --- draw buttons --- */
+
+ if (start>0)
+ SDL_BlitSurface( left, NULL, screen, &leftRect );
+
+ if (start+8<themes)
+ SDL_BlitSurface( right, NULL, screen, &rightRect );
+
+ SDL_UpdateRect(screen, 0, 0, 0 ,0);
+ }
+ //SDL_Delay(40);
+ old_loc = loc;
+ }
+
+
+ fp=fopen(fn,"w");
+ fseek(fp,0,SEEK_SET);
+ fprintf(fp, "%s\n", str);
+ i=0;
+
+ while(i<themes)
+ {
+ fprintf(fp, "%s\n", editWordW[i++]);
+ i++;
+ }
+
+ fclose(fp);
+
+ /* --- clear graphics before quitting --- */
+
+ for (i = 0; i<themes; i++)
+ {
+ SDL_FreeSurface(titles[i]);
+ SDL_FreeSurface(select[i]);
+ }
+
+ SDL_FreeSurface(bkg);
+ SDL_FreeSurface(left);
+ SDL_FreeSurface(right);
+ bkg = NULL; /* the other pointers are going out of scope so we don't */
+ /* have to worry about setting them to NULL */
+}
Modified: tuxtype/trunk/src/titlescreen.h
===================================================================
--- tuxtype/trunk/src/titlescreen.h 2008-08-18 12:38:50 UTC (rev 650)
+++ tuxtype/trunk/src/titlescreen.h 2008-08-18 14:28:20 UTC (rev 651)
@@ -12,7 +12,7 @@
/* --- define menu structure --- */
/* (these values are all in the Game_Type enum in globals.h) */
const int menu_item[][6]= {{0, 0, 0, 0, 0},
- {0, CASCADE, LEVEL1, LEVEL1, NOT_CODED },
+ {0, CASCADE, LEVEL1, LEVEL1, EDIT_WORDLIST },
{0, LASER, LEVEL2, LEVEL2, FREETYPE },
{0, LESSONS, LEVEL3, LEVEL3, PROJECT_INFO },
{0, OPTIONS, INSTRUCT, LEVEL4, SET_LANGUAGE},
More information about the Tux4kids-commits
mailing list