From: Tobias Gläßer Date: Sun, 7 Mar 2004 15:07:29 +0000 (+0000) Subject: cleanups. Merged credits patch from Ricardo and improved it. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6292b95db76ca3b04b25d9c2a6ab858a306387d7;p=supertux.git cleanups. Merged credits patch from Ricardo and improved it. SVN-Revision: 186 --- diff --git a/src/intro.c b/src/intro.c index f973a14f9..b0db71c3f 100644 --- a/src/intro.c +++ b/src/intro.c @@ -213,7 +213,7 @@ int intro(void) 310, 32 + (copter[0].h), 310, 32 + (copter[0].h), (gown_upset.w) + 20, - 378 + (gown_upset.h) - (copter[0].h), NO_UPDATE); + 376 + (gown_upset.h) - (copter[0].h), NO_UPDATE); for (j = 0; j < (gown_upset.sdl_surface -> w); j++) diff --git a/src/leveleditor.c b/src/leveleditor.c index 07cc15a8d..5ec2e854b 100644 --- a/src/leveleditor.c +++ b/src/leveleditor.c @@ -373,7 +373,6 @@ le_update_buttons(char *theme) for(i = 0; i < bkgd_files.num_items; ++i) { sprintf(filename,"%s/%s",pathname,bkgd_files.item[i]); - printf("%s\n",filename); button_change_icon(&le_bkgd_panel.item[i],filename); } diff --git a/src/setup.c b/src/setup.c index 80f5c339d..4a68ce4e2 100644 --- a/src/setup.c +++ b/src/setup.c @@ -47,9 +47,16 @@ int faccessible(char *filename) { struct stat filestat; if (stat(filename, &filestat) == -1) + { return NO; + } else + { + if(S_ISREG(filestat.st_mode)) return YES; + else + return NO; + } } /* Can we write to this location? */ @@ -252,6 +259,12 @@ void st_directory_setup(void) strlen("/.supertux") + 1)); strcpy(st_dir, home); strcat(st_dir, "/.supertux"); + + /* Remove .supertux config-file from old SuperTux versions */ + if(faccessible(st_dir)) + { + remove(st_dir); + } st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1)); @@ -288,6 +301,7 @@ void st_menu(void) menu_additem(&main_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu)); menu_additem(&main_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu)); menu_additem(&main_menu,menu_item_create(MN_ACTION,"Level editor",0,0)); + menu_additem(&main_menu,menu_item_create(MN_ACTION,"Credits",0,0)); menu_additem(&main_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&main_menu,menu_item_create(MN_ACTION,"Quit",0,0)); diff --git a/src/title.c b/src/title.c index 44510a642..666c5a90e 100644 --- a/src/title.c +++ b/src/title.c @@ -37,14 +37,36 @@ #include "gameloop.h" #include "leveleditor.h" +texture_type bkg_title, img_choose_subset, anim1, anim2; +SDL_Event event; +SDLKey key; +int quit, frame, pict, i; + +void display_credits(); + +void draw_background() +{ + /* Draw the title background: */ + + texture_draw_bg(&bkg_title, NO_UPDATE); + + /* Animate title screen: */ + + pict = (frame / 5) % 3; + + if (pict == 0) + texture_draw_part(&bkg_title, 560, 270, 560, 270, 80, 75, NO_UPDATE); + else if (pict == 1) + texture_draw(&anim1, 560, 270, NO_UPDATE); + else if (pict == 2) + texture_draw(&anim2, 560, 270, NO_UPDATE); +} + /* --- TITLE SCREEN --- */ int title(void) { - texture_type title, img_choose_subset, anim1, anim2; - SDL_Event event; - SDLKey key; - int done, quit, frame, pict, i; + int done; char str[80]; string_list_type level_subsets; level_subsets = dsubdirs("/levels", "info"); @@ -60,11 +82,11 @@ int title(void) /* Load images: */ - texture_load(&title,DATA_PREFIX "/images/title/title.png", IGNORE_ALPHA); + texture_load(&bkg_title,DATA_PREFIX "/images/title/title.png", IGNORE_ALPHA); texture_load(&anim1,DATA_PREFIX "/images/title/title-anim2.png", IGNORE_ALPHA); texture_load(&anim2,DATA_PREFIX "/images/title/title-anim1.png", IGNORE_ALPHA); texture_load(&img_choose_subset,DATA_PREFIX "/images/status/choose-level-subset.png", USE_ALPHA); - + /* --- Main title loop: --- */ done = 0; @@ -73,13 +95,12 @@ int title(void) frame = 0; /* Draw the title background: */ - texture_draw_bg(&title, NO_UPDATE); + texture_draw_bg(&bkg_title, NO_UPDATE); load_hs(); - + while (!done && !quit) { - frame++; /* Handle events: */ while (SDL_PollEvent(&event)) @@ -123,9 +144,8 @@ int title(void) } - /* Draw the title background: */ - - texture_draw_bg(&title, NO_UPDATE); + /* Draw the background: */ + draw_background(); /* Draw the high score: */ sprintf(str, "High score: %d", hs_score); @@ -133,17 +153,6 @@ int title(void) sprintf(str, "by %s", hs_name); text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE); - /* Animate title screen: */ - - pict = (frame / 5) % 3; - - if (pict == 0) - texture_draw_part(&title, 560, 270, 560, 270, 80, 75, NO_UPDATE); - else if (pict == 1) - texture_draw(&anim1, 560, 270, NO_UPDATE); - else if (pict == 2) - texture_draw(&anim2, 560, 270, NO_UPDATE); - /* Don't draw menu, if quit is true */ if(show_menu && !quit) menu_process_current(); @@ -164,13 +173,13 @@ int title(void) if(level_subsets.num_items != 0) { texture_draw(&subset.image,(screen->w - subset.image.w) / 2 + 25,78,NO_UPDATE); - if(level_subsets.num_items > 1) - { - if(i > 0) - texture_draw(&arrow_left,(screen->w / 2) - ((strlen(subset.title)+2)*16)/2,20,NO_UPDATE); - if(i < level_subsets.num_items-1) - texture_draw(&arrow_right,(screen->w / 2) + ((strlen(subset.title))*16)/2,20,NO_UPDATE); - } + if(level_subsets.num_items > 1) + { + if(i > 0) + texture_draw(&arrow_left,(screen->w / 2) - ((strlen(subset.title)+2)*16)/2,20,NO_UPDATE); + if(i < level_subsets.num_items-1) + texture_draw(&arrow_right,(screen->w / 2) + ((strlen(subset.title))*16)/2,20,NO_UPDATE); + } text_drawf(&gold_text, subset.title, 0, 20, A_HMIDDLE, A_TOP, 1, NO_UPDATE); text_drawf(&gold_text, subset.description, 20, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE); } @@ -183,6 +192,7 @@ int title(void) case SDL_QUIT: done = 1; quit = 1; + break; case SDL_KEYDOWN: // key pressed /* Keypress... */ @@ -224,14 +234,17 @@ int title(void) } } break; - case 3: - update_load_save_game_menu(&load_game_menu, YES); - break; + case 3: + update_load_save_game_menu(&load_game_menu, YES); + break; case 5: done = 1; quit = leveleditor(1); break; - case 7: + case 6: + display_credits(); + break; + case 8: quit = 1; break; } @@ -248,13 +261,13 @@ int title(void) flipscreen(); /* Pause: */ - + frame++; SDL_Delay(50); } /* Free surfaces: */ - texture_free(&title); + texture_free(&bkg_title); texture_free(&anim1); texture_free(&anim2); string_list_free(&level_subsets); @@ -263,3 +276,130 @@ int title(void) return(quit); } + +void display_credits() +{ + int done; + int scroll, speed; + timer_type timer; + int n,d; + int length; + FILE* fi; + char temp[1024]; + string_list_type names; + string_list_init(&names); + char filename[1024]; + sprintf(filename,"%s/CREDITS",DATA_PREFIX); + if((fi = fopen(filename,"r")) != NULL) + { + while(fgets(temp, sizeof(temp), fi) != NULL) + { + temp[strlen(temp)-1]='\0'; + string_list_add_item(&names,temp); + } + fclose(fi); + } + else + { + string_list_add_item(&names,"Credits were not found!"); + string_list_add_item(&names,"Shame on the guy, who"); + string_list_add_item(&names,"forgot to include them"); + string_list_add_item(&names,"in your SuperTux distribution."); + } + + + timer_init(&timer, SDL_GetTicks()); + timer_start(&timer, 50); + + scroll = 0; + speed = 1; + done = 0; + + n = d = 0; + + length = names.num_items; + + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + + while(done == 0) + { + /* in case of input, exit */ + while(SDL_PollEvent(&event)) + switch(event.type) + { + case SDL_KEYDOWN: + switch(event.key.keysym.sym) + { + case SDLK_DOWN: + speed -= 1; + break; + case SDLK_UP: + speed += 1; + break; + case SDLK_SPACE: + case SDLK_RETURN: + if(speed >= 0) + scroll += 60; + break; + case SDLK_ESCAPE: + done = 1; + break; + default: + break; + } + break; + case SDL_QUIT: + done = 1; + break; + default: + break; + } + + /* draw the credits */ + + draw_background(); + + text_drawf(&white_big_text, "- Credits -", 0, screen->h-scroll, A_HMIDDLE, A_TOP, 2, NO_UPDATE); + + for(i = 0, n = 0, d = 0; i < length; i++,n++,d++) + { + if(names.item[i] == "") + n--; + else + { + if(names.item[i][0] == ' ') + text_drawf(&white_small_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll-10, A_HMIDDLE, A_TOP, 1, NO_UPDATE); + else if(names.item[i][0] == ' ') + text_drawf(&white_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE); + else if(names.item[i+1][0] == '-' || names.item[i][0] == '-') + text_drawf(&white_big_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE); + else + text_drawf(&blue_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE); + } + } + + texture_draw_part(&bkg_title, 0, 0, 0, 0, 640, 130, NO_UPDATE); + + flipscreen(); + + if(60+screen->h+(n*18)+(d*18)-scroll < 0 && 20+60+screen->h+(n*18)+(d*18)-scroll < 0) + done = 1; + + scroll += speed; + if(scroll < 0) + scroll = 0; + + SDL_Delay(20); + + if(timer_get_left(&timer) < 0) + { + frame++; + timer_start(&timer, 50); + } + } + string_list_free(&names); + + SDL_EnableKeyRepeat(0, 0); // disables key repeating + show_menu = 1; + menu_set_current(&main_menu); +}