From: Tobias Gläßer Date: Tue, 2 Mar 2004 15:42:36 +0000 (+0000) Subject: Improved buttons. You can create new level-subsets via the leveleditor now. Better... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b9c029fdfbf54699ff0ebf2a64504ee40f6ec357;p=supertux.git Improved buttons. You can create new level-subsets via the leveleditor now. Better portability. SVN-Revision: 162 --- diff --git a/src/bitmask.c b/src/bitmask.c index 3607f0175..a0be080ad 100644 --- a/src/bitmask.c +++ b/src/bitmask.c @@ -23,7 +23,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include +#include #include "bitmask.h" #define MIN(a,b) ((a) < (b) ? (a) : (b)) diff --git a/src/button.c b/src/button.c index fcd96ce85..f0a8e1c8b 100644 --- a/src/button.c +++ b/src/button.c @@ -85,20 +85,7 @@ void button_free(button_type* pbutton) void button_event(button_type* pbutton, SDL_Event *event) { - if(event->type == SDL_KEYDOWN) - { - SDLKey key = event->key.keysym.sym; - if(key == pbutton->shortcut) - pbutton->state = BN_CLICKED; - } - else if(event->type == SDL_MOUSEMOTION) - { - - if(pbutton->show_info) - { - pbutton->show_info = NO; - } - } +SDLKey key = event->key.keysym.sym; if(event->motion.x > pbutton->x && event->motion.x < pbutton->x + pbutton->w && event->motion.y > pbutton->y && event->motion.y < pbutton->y + pbutton->h) @@ -126,7 +113,7 @@ void button_event(button_type* pbutton, SDL_Event *event) } } } - else + else if(event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) { pbutton->state = -1; if(pbutton->show_info) @@ -134,6 +121,25 @@ void button_event(button_type* pbutton, SDL_Event *event) pbutton->show_info = NO; } } + + if(event->type == SDL_KEYDOWN) + { + if(key == pbutton->shortcut) + pbutton->state = BN_PRESSED; + } + else if(event->type == SDL_KEYUP) + { + if(pbutton->state == BN_PRESSED && key == pbutton->shortcut) + pbutton->state = BN_CLICKED; + } + else if(event->type == SDL_MOUSEMOTION) + { + + if(pbutton->show_info) + { + pbutton->show_info = NO; + } + } } int button_get_state(button_type* pbutton) diff --git a/src/level.c b/src/level.c index 7a8436594..ab14055d8 100644 --- a/src/level.c +++ b/src/level.c @@ -93,7 +93,40 @@ void subset_load(st_subset* st_subset, char *subset) break; } } - st_subset->levels = --i; + st_subset->levels = --i; +} + +void subset_save(st_subset* st_subset) +{ + FILE* fi; + char filename[1024]; + + /* Save data file: */ + sprintf(filename, "/levels/%s/", st_subset->name); + + fcreatedir(filename); + snprintf(filename, 1024, "%s/levels/%s/info", st_dir, st_subset->name); + if(!fwriteable(filename)) + snprintf(filename, 1024, "%s/levels/%s/info", DATA_PREFIX, st_subset->name); + if(fwriteable(filename)) + { + fi = fopen(filename, "w"); + if (fi == NULL) + { + perror(filename); + } + + /* Save title info: */ + fputs(st_subset->title, fi); + fputs("\n", fi); + + /* Save the description: */ + + fputs(st_subset->description, fi); + fputs("\n", fi); + fclose(fi); + + } } void subset_free(st_subset* st_subset) @@ -168,11 +201,11 @@ int level_load(st_level* plevel, char *subset, int level) /* (Level width) */ fgets(str, 10, fi); plevel->width = atoi(str); - + /* (Level gravity) */ fgets(str, 10, fi); plevel->gravity = atof(str); - + /* Set the global gravity to the latest loaded level's gravity */ gravity = plevel->gravity; @@ -250,7 +283,7 @@ void level_save(st_level* plevel, char * subset, int level) fputs(str, fi); sprintf(str, "%2.1f\n", plevel->gravity); /* level gravity */ fputs(str, fi); - + for(y = 0; y < 15; ++y) { fputs((const char*)plevel->tiles[y], fi); diff --git a/src/level.h b/src/level.h index 27c94a7f4..d2fbf8242 100644 --- a/src/level.h +++ b/src/level.h @@ -28,6 +28,7 @@ typedef struct st_subset void subset_init(st_subset* st_subset); void subset_load(st_subset* st_subset, char *subset); +void subset_save(st_subset* st_subset); void subset_free(st_subset* st_subset); #define LEVEL_NAME_MAX 20 diff --git a/src/leveleditor.c b/src/leveleditor.c index 2ed158d93..6d74395e3 100644 --- a/src/leveleditor.c +++ b/src/leveleditor.c @@ -1,3 +1,4 @@ + /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * @@ -70,6 +71,7 @@ void le_testlevel(); void le_showhelp(); void le_set_defaults(void); void le_activate_bad_guys(void); +void le_new_subset(char *subset_name); void le_highlight_selection(); void apply_level_settings_menu(); @@ -225,6 +227,8 @@ int leveleditor(int levelnb) { subset_load(&le_level_subset,level_subsets[i-2]); leveleditor_menu.item[3].kind = MN_GOTO; + menu_item_change_input(&subset_settings_menu.item[2],le_level_subset.title); + menu_item_change_input(&subset_settings_menu.item[3],le_level_subset.description); le_level = 1; arrays_init(); loadshared(); @@ -247,33 +251,16 @@ int leveleditor(int levelnb) if(subset_new_menu.item[2].input[0] == '\0') subset_new_menu.item[3].kind = MN_DEACTIVE; else + { subset_new_menu.item[3].kind = MN_ACTION; - /*switch (i = menu_check(&subset_load_menu)) + switch (i = menu_check(&subset_new_menu)) { - case 0: - break; - default: - if(i != -1) - { - subset_load(&le_level_subset,level_subsets[i-2]); - leveleditor_menu.item[3].kind = MN_GOTO; - le_level = 1; - arrays_init(); - loadshared(); - le_current_level = (st_level*) malloc(sizeof(st_level)); - if(level_load(le_current_level, le_level_subset.name, le_level) != 0) - { - le_quit(); - return 1; - } - le_set_defaults(); - level_load_gfx(le_current_level); - le_activate_bad_guys(); - show_menu = YES; - } + case 3: + le_new_subset(subset_new_menu.item[2].input); break; - }*/ + } + } } } @@ -300,6 +287,45 @@ int leveleditor(int levelnb) return done; } +void le_default_level(st_level* plevel) +{ + int i,y; + strcpy(plevel->name,"UnNamed"); + strcpy(plevel->theme,"antarctica"); + strcpy(plevel->song_title,"Mortimers_chipdisko.mod"); + strcpy(plevel->bkgd_image,"arctis.png"); + plevel->width = 21; + plevel->time_left = 100; + plevel->gravity = 10.; + plevel->bkgd_red = 0; + plevel->bkgd_green = 0; + plevel->bkgd_blue = 0; + + for(i = 0; i < 15; ++i) + { + plevel->tiles[i] = (unsigned char*) malloc((plevel->width+1)*sizeof(unsigned char)); + plevel->tiles[i][plevel->width] = (unsigned char) '\0'; + for(y = 0; y < plevel->width; ++y) + plevel->tiles[i][y] = (unsigned char) '.'; + plevel->tiles[i][plevel->width] = (unsigned char) '\0'; + } +} + +void le_new_subset(char *subset_name) +{ + st_level new_lev; + st_subset new_subset; + new_subset.name = (char*) malloc((strlen(subset_name)+1)*sizeof(char)); + strcpy(new_subset.name,subset_name); + new_subset.title = (char*) malloc((strlen("Unknown Title")+1)*sizeof(char)); + strcpy(new_subset.title,"Unknown Title"); + new_subset.description = (char*) malloc((strlen("No description so far.")+1)*sizeof(char)); + strcpy(new_subset.description,"No description so far."); + subset_save(&new_subset); + le_default_level(&new_lev); + level_save(&new_lev,subset_name,1); +} + int le_init() { int i; @@ -341,15 +367,15 @@ int le_init() texture_load(&le_selection,DATA_PREFIX "/images/leveleditor/select.png", USE_ALPHA); /* Load buttons */ - button_load(&le_next_level_bt,"/images/icons/up.png","Test Level", SDLK_PAGEUP,screen->w-64,0); - button_load(&le_previous_level_bt,"/images/icons/down.png","Test Level",SDLK_PAGEDOWN,screen->w-32,0); + button_load(&le_next_level_bt,"/images/icons/up.png","Next level", SDLK_PAGEUP,screen->w-64,0); + button_load(&le_previous_level_bt,"/images/icons/down.png","Previous level",SDLK_PAGEDOWN,screen->w-32,0); button_load(&le_rubber_bt,"/images/icons/rubber.png","Rubber",SDLK_DELETE,screen->w-64,32); - button_load(&le_select_mode_one_bt,"/images/icons/select-mode1.png","Select Tile",SDLK_F3,screen->w-64,16); - button_load(&le_select_mode_two_bt,"/images/icons/select-mode2.png","Select Tiles",SDLK_F3,screen->w-32,16); - button_load(&le_test_level_bt,"/images/icons/test-level.png","Test Level",SDLK_F4,screen->w-64,screen->h - 64); - button_load(&le_settings_bt,"/images/icons/settings.png","Level settings",SDLK_0,screen->w-32,screen->h - 64); - button_load(&le_move_left_bt,"/images/icons/left.png","Test Level",SDLK_F4,screen->w-64,screen->h - 32); - button_load(&le_move_right_bt,"/images/icons/right.png","Level settings",SDLK_0,screen->w-48,screen->h - 32); + button_load(&le_select_mode_one_bt,"/images/icons/select-mode1.png","Select single tile",SDLK_F3,screen->w-64,16); + button_load(&le_select_mode_two_bt,"/images/icons/select-mode2.png","Select multiple tiles",SDLK_F3,screen->w-32,16); + button_load(&le_test_level_bt,"/images/icons/test-level.png","Test level",SDLK_F4,screen->w-64,screen->h - 64); + button_load(&le_settings_bt,"/images/icons/settings.png","Level settings",SDLK_F5,screen->w-32,screen->h - 64); + button_load(&le_move_left_bt,"/images/icons/left.png","Move left",SDLK_LEFT,screen->w-64,screen->h - 32); + button_load(&le_move_right_bt,"/images/icons/right.png","Move right",SDLK_RIGHT,screen->w-48,screen->h - 32); button_panel_init(&le_bt_panel, screen->w - 64,64, 64, 380); menu_init(&leveleditor_menu); @@ -387,6 +413,11 @@ int le_init() menu_init(&subset_settings_menu); menu_additem(&subset_settings_menu,menu_item_create(MN_LABEL,"Level Subset Settings",0,0)); menu_additem(&subset_settings_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&subset_settings_menu,menu_item_create(MN_TEXTFIELD,"Title",0,0)); + menu_additem(&subset_settings_menu,menu_item_create(MN_TEXTFIELD,"Description",0,0)); + menu_additem(&subset_settings_menu,menu_item_create(MN_HL,"",0,0)); + menu_additem(&subset_settings_menu,menu_item_create(MN_ACTION,"Apply Changes",0,0)); + menu_additem(&subset_settings_menu,menu_item_create(MN_HL,"",0,0)); menu_additem(&subset_settings_menu,menu_item_create(MN_BACK,"Back",0,0)); menu_init(&level_settings_menu); @@ -927,7 +958,7 @@ void le_checkevents() if(le_current_level != NULL) { - if(event.type == SDL_KEYDOWN || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w && + if(event.type == SDL_KEYDOWN || event.type == SDL_KEYUP || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w && event.motion.y > 0 && event.motion.y < screen->h))) { /* Check for button events */ diff --git a/src/player.c b/src/player.c index 9423b1035..8b567cb72 100644 --- a/src/player.c +++ b/src/player.c @@ -124,6 +124,9 @@ void player_level_begin(player_type* pplayer) timer_init(&pplayer->invincible_timer,YES); timer_init(&pplayer->skidding_timer,YES); timer_init(&pplayer->safe_timer,YES); + timer_init(&pplayer->frame_timer,YES); + physic_init(&pplayer->hphysic); + physic_init(&pplayer->vphysic); } void player_action(player_type* pplayer) diff --git a/src/texture.c b/src/texture.c index 2284786c6..05c3d3423 100644 --- a/src/texture.c +++ b/src/texture.c @@ -10,8 +10,8 @@ // // -#include -#include +#include "SDL.h" +#include "SDL_image.h" #include "globals.h" #include "screen.h" #include "setup.h" diff --git a/src/texture.h b/src/texture.h index 9904b2901..3c3d8034f 100644 --- a/src/texture.h +++ b/src/texture.h @@ -13,9 +13,9 @@ #ifndef SUPERTUX_TEXTURE_H #define SUPERTUX_TEXTURE_H -#include +#include "SDL.h" #ifndef NOOPENGL -#include +#include "SDL_opengl.h" #endif /* Texture type */ @@ -25,8 +25,7 @@ typedef struct texture_type GLuint gl_texture; int w; int h; - } -texture_type; + } texture_type; void texture_setup(void); extern void (*texture_load) (texture_type* ptexture, char * file, int use_alpha); diff --git a/src/timer.c b/src/timer.c index eb9cccd8d..2e5b45851 100644 --- a/src/timer.c +++ b/src/timer.c @@ -10,7 +10,7 @@ // // -#include +#include "SDL.h" #include "defines.h" #include "timer.h" diff --git a/src/type.c b/src/type.c index d6f9347b8..69c61f36f 100644 --- a/src/type.c +++ b/src/type.c @@ -10,7 +10,7 @@ // // -#include +#include "SDL_image.h" #include "setup.h" #include "globals.h" #include "screen.h"