From: Tobias Gläßer Date: Fri, 5 Mar 2004 17:38:16 +0000 (+0000) Subject: fixed displaying of text with newlines. level-editor basics work and are a bit more... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e898d244512e4c4f16df58b0545416ab377c0b1f;p=supertux.git fixed displaying of text with newlines. level-editor basics work and are a bit more intuitive now. SVN-Revision: 172 --- diff --git a/src/level.c b/src/level.c index ab14055d8..d6fcfab77 100644 --- a/src/level.c +++ b/src/level.c @@ -25,6 +25,7 @@ void subset_init(st_subset* st_subset) { st_subset->title = NULL; st_subset->description = NULL; + st_subset->name = NULL; st_subset->levels = 0; } @@ -312,7 +313,6 @@ void level_free(st_level* plevel) void level_load_gfx(st_level *plevel) { - level_load_image(&img_brick[0],plevel->theme,"brick0.png", IGNORE_ALPHA); level_load_image(&img_brick[1],plevel->theme,"brick1.png", IGNORE_ALPHA); @@ -365,11 +365,11 @@ void level_free_gfx(void) void level_load_image(texture_type* ptexture, char* theme, char * file, int use_alpha) { char fname[1024]; - + snprintf(fname, 1024, "%s/themes/%s/%s", st_dir, theme, file); if(!faccessible(fname)) snprintf(fname, 1024, "%s/images/themes/%s/%s", DATA_PREFIX, theme, file); - + texture_load(ptexture, fname, use_alpha); } diff --git a/src/leveleditor.c b/src/leveleditor.c index d21d87635..efd01e4a0 100644 --- a/src/leveleditor.c +++ b/src/leveleditor.c @@ -73,7 +73,10 @@ void le_activate_bad_guys(void); void le_new_subset(char *subset_name); void le_highlight_selection(); + void apply_level_settings_menu(); +void update_subset_settings_menu(); +void save_subset_settings_menu(); /* leveleditor internals */ static string_list_type level_subsets; @@ -194,6 +197,9 @@ int leveleditor(int levelnb) case 2: show_menu = NO; break; + case 3: + update_subset_settings_menu(); + break; case 7: done = DONE_LEVELEDITOR; break; @@ -203,16 +209,12 @@ int leveleditor(int levelnb) { switch (menu_check(&level_settings_menu)) { - case 0: - break; - case 1: - show_menu = YES; - break; - case 4: - break; case 13: apply_level_settings_menu(); break; + default: + show_menu = YES; + break; } } else if(current_menu == &subset_load_menu) @@ -226,8 +228,6 @@ int leveleditor(int levelnb) { subset_load(&le_level_subset,level_subsets.item[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(); @@ -257,10 +257,41 @@ int leveleditor(int levelnb) { case 3: le_new_subset(subset_new_menu.item[2].input); + subset_load(&le_level_subset,subset_new_menu.item[2].input); + 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(); + menu_item_change_input(&subset_new_menu.item[2],""); + show_menu = YES; break; } } } + else if(current_menu == &subset_settings_menu) + { + if(strcmp(le_level_subset.title,subset_settings_menu.item[2].input) == 0 && strcmp(le_level_subset.description,subset_settings_menu.item[3].input) == 0 ) + subset_settings_menu.item[5].kind = MN_DEACTIVE; + else + subset_settings_menu.item[5].kind = MN_ACTION; + + switch (i = menu_check(&subset_settings_menu)) + { + case 5: + save_subset_settings_menu(); + show_menu = YES; + break; + } + } } if(done) @@ -339,24 +370,8 @@ int le_init() le_frame = 0; /* support for frames in some tiles, like waves and bad guys */ le_level_changed = NO; - /* - subset_load(&le_level_subset,"default"); - arrays_init(); - loadshared(); - le_set_defaults(); - - - if(level_load(&le_current_level, le_level_subset.name, le_level) != 0) - { - le_quit(); - return 1; - } - if(le_current_level.time_left == 0) - le_current_level.time_left = 255; - - level_load_gfx(&le_current_level); - le_activate_bad_guys(); - */ + subset_init(&le_level_subset); + le_current_level = NULL; le_current_tile = '.'; @@ -415,7 +430,7 @@ int le_init() 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_ACTION,"Save 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)); @@ -454,7 +469,7 @@ void update_level_settings_menu() sprintf(str,"%d",le_current_level->width); string_list_copy(level_settings_menu.item[3].list, dsubdirs("images/themes", "solid0.png")); - string_list_copy(level_settings_menu.item[4].list, dfiles("music/", NULL)); + string_list_copy(level_settings_menu.item[4].list, dfiles("music/", "-fast")); string_list_copy(level_settings_menu.item[5].list, dfiles("images/background", NULL)); if((i = string_list_find(level_settings_menu.item[3].list,le_current_level->theme)) != -1) level_settings_menu.item[3].list->active_item = i; @@ -476,6 +491,12 @@ void update_level_settings_menu() menu_item_change_input(&level_settings_menu.item[11], str); } +void update_subset_settings_menu() +{ + 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); +} + void apply_level_settings_menu() { int i,y,j; @@ -483,7 +504,7 @@ void apply_level_settings_menu() strcpy(le_current_level->name,level_settings_menu.item[2].input); - if(strcmp(le_current_level->theme,string_list_active(level_settings_menu.item[5].list)) != 0) + if(strcmp(le_current_level->bkgd_image,string_list_active(level_settings_menu.item[5].list)) != 0) { strcpy(le_current_level->bkgd_image,string_list_active(level_settings_menu.item[5].list)); i = YES; @@ -532,6 +553,17 @@ void apply_level_settings_menu() le_current_level->bkgd_blue = atoi(level_settings_menu.item[11].input); } +void save_subset_settings_menu() +{ + free(le_level_subset.title); + le_level_subset.title = (char*) malloc(sizeof(char)*(strlen(subset_settings_menu.item[2].input)+1)); + strcpy(le_level_subset.title,subset_settings_menu.item[2].input); + free(le_level_subset.description); + le_level_subset.description = (char*) malloc(sizeof(char)*(strlen(subset_settings_menu.item[3].input)+1)); + strcpy(le_level_subset.description,subset_settings_menu.item[3].input); + subset_save(&le_level_subset); +} + void le_goto_level(int levelnb) { arrays_free(); @@ -1013,7 +1045,45 @@ void le_checkevents() if(button_get_state(&le_next_level_bt) == BN_CLICKED) { if(le_level < le_level_subset.levels) - le_goto_level(++le_level); + { + le_goto_level(++le_level); + } + else + { + st_level new_lev; + char str[1024]; + int d = 0; + sprintf(str,"Level %d doesn't exist.",le_level+1); + text_drawf(&white_text,str,0,-18,A_HMIDDLE,A_VMIDDLE,2,NO_UPDATE); + text_drawf(&white_text,"Do you want to create it?",0,0,A_HMIDDLE,A_VMIDDLE,2,NO_UPDATE); + text_drawf(&red_text,"(Y)es/(N)o",0,20,A_HMIDDLE,A_VMIDDLE,2,NO_UPDATE); + flipscreen(); + while(d == 0) + { + while(SDL_PollEvent(&event)) + switch(event.type) + { + case SDL_KEYDOWN: // key pressed + switch(event.key.keysym.sym) + { + case SDLK_y: + le_default_level(&new_lev); + level_save(&new_lev,le_level_subset.name,++le_level); + le_level_subset.levels = le_level; + le_goto_level(le_level); + d = 1; + break; + case SDLK_n: + d = 1; + break; + } + break; + default: + break; + } + SDL_Delay(50); + } + } } button_event(&le_previous_level_bt,&event); if(button_get_state(&le_previous_level_bt) == BN_CLICKED) @@ -1271,14 +1341,17 @@ void le_showhelp() done = 0; while(done == 0) - while(SDL_PollEvent(&event)) - switch(event.type) - { - case SDL_MOUSEBUTTONDOWN: // mouse pressed - case SDL_KEYDOWN: // key pressed - done = 1; - break; - default: - break; - } + { + while(SDL_PollEvent(&event)) + switch(event.type) + { + case SDL_MOUSEBUTTONDOWN: // mouse pressed + case SDL_KEYDOWN: // key pressed + done = 1; + break; + default: + break; + } + SDL_Delay(50); + } } diff --git a/src/setup.c b/src/setup.c index 5ae1e0fd5..1a1583aed 100644 --- a/src/setup.c +++ b/src/setup.c @@ -161,7 +161,7 @@ string_list_type dsubdirs(char *rel_path, char* expected_file) return sdirs; } -string_list_type dfiles(char *rel_path, char* expected_file) +string_list_type dfiles(char *rel_path, char* exception_str) { DIR *dirStructP; struct dirent *direntp; @@ -183,10 +183,9 @@ string_list_type dfiles(char *rel_path, char* expected_file) if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode)) { - if(expected_file != NULL) + if(exception_str != NULL) { - sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file); - if(!faccessible(filename)) + if(strstr(direntp->d_name,exception_str) != NULL) continue; } @@ -208,19 +207,10 @@ string_list_type dfiles(char *rel_path, char* expected_file) if (stat(absolute_filename, &buf) == 0 && S_ISREG(buf.st_mode)) { - if(expected_file != NULL) + if(exception_str != NULL) { - sprintf(filename,"%s/%s/%s",path,direntp->d_name,expected_file); - if(!faccessible(filename)) - { - continue; - } - else - { - sprintf(filename,"%s/%s/%s/%s",st_dir,rel_path,direntp->d_name,expected_file); - if(faccessible(filename)) - continue; - } + if(strstr(direntp->d_name,exception_str) != NULL) + continue; } string_list_add_item(&sdirs,direntp->d_name); diff --git a/src/setup.h b/src/setup.h index 60470a231..7bfebc4d9 100644 --- a/src/setup.h +++ b/src/setup.h @@ -21,7 +21,7 @@ int faccessible(char *filename); int fcreatedir(char* relative_dir); int fwriteable(char *filename); string_list_type dsubdirs(char *rel_path, char* expected_file); -string_list_type dfiles(char *rel_path, char* expected_file); +string_list_type dfiles(char *rel_path, char* exception_str); void free_strings(char **strings, int num); void st_directory_setup(void); void st_general_setup(void); diff --git a/src/text.c b/src/text.c index 7b9be8635..5edef4802 100644 --- a/src/text.c +++ b/src/text.c @@ -75,7 +75,7 @@ void text_draw(text_type* ptext, char* text, int x, int y, int shadowsize, int u void text_draw_chars(text_type* ptext, texture_type* pchars, char* text, int x, int y, int update) { - int i,len; + int i,j,len; int w, h; len = strlen(text); @@ -83,31 +83,33 @@ int w, h; if(ptext->kind == TEXT_TEXT) { - for( i = 0; i < len; ++i) + for( i = 0, j = 0; i < len; ++i,++j) { if( text[i] >= 'A' && text[i] <= 'Z') - texture_draw_part(pchars, (int)(text[i] - 'A')*w, 0, x+(i*w), y, ptext->w, ptext->h, update); + texture_draw_part(pchars, (int)(text[i] - 'A')*w, 0, x+(j*w), y, ptext->w, ptext->h, update); else if( text[i] >= 'a' && text[i] <= 'z') - texture_draw_part(pchars, (int)(text[i] - 'a')*w, h, x+(i*w), y, ptext->w, ptext->h, update); + texture_draw_part(pchars, (int)(text[i] - 'a')*w, h, x+(j*w), y, ptext->w, ptext->h, update); else if ( text[i] >= '!' && text[i] <= '9') - texture_draw_part(pchars, (int)(text[i] - '!')*w, h*2, x+(i*w), y, ptext->w, ptext->h, update); + texture_draw_part(pchars, (int)(text[i] - '!')*w, h*2, x+(j*w), y, ptext->w, ptext->h, update); else if ( text[i] == '?') - texture_draw_part(pchars, 25*w, h*2, x+(i*w), y, ptext->w, ptext->h, update); + texture_draw_part(pchars, 25*w, h*2, x+(j*w), y, ptext->w, ptext->h, update); else if ( text[i] == '\n') { y += ptext->h + 2; + j = 0; } } } else if(ptext->kind == TEXT_NUM) { - for( i = 0; i < len; ++i) + for( i = 0, j = 0; i < len; ++i, ++j) { if ( text[i] >= '0' && text[i] <= '9') - texture_draw_part(pchars, (int)(text[i] - '0')*w, 0, x+(i*w), y, w, h, update); + texture_draw_part(pchars, (int)(text[i] - '0')*w, 0, x+(j*w), y, w, h, update); else if ( text[i] == '\n') { y += ptext->h + 2; + j = 0; } } } @@ -117,7 +119,7 @@ void text_drawf(text_type* ptext, char* text, int x, int y, int halign, int vali { if(text != NULL) { - if(halign == A_RIGHT) + if(halign == A_RIGHT) /* FIXME: this doesn't work correctly for strings with newlines.*/ x += screen->w - (strlen(text)*ptext->w); else if(halign == A_HMIDDLE) x += screen->w/2 - ((strlen(text)*ptext->w)/2);