diff options
Diffstat (limited to 'src/interface.c')
| -rw-r--r-- | src/interface.c | 88 |
1 files changed, 62 insertions, 26 deletions
diff --git a/src/interface.c b/src/interface.c index 5e8eed4..8ba00a5 100644 --- a/src/interface.c +++ b/src/interface.c @@ -479,7 +479,7 @@ void draw_svf_ui(pixel *vid_buf) c = svf_login ? 255 : 128; drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", c, c, c, 255); if (svf_open) - drawtext(vid_buf, 58, YRES+(MENUSIZE-12), svf_name, c, c, c, 255); + drawtextmax(vid_buf, 58, YRES+(MENUSIZE-12), 125, svf_name, c, c, c, 255); else drawtext(vid_buf, 58, YRES+(MENUSIZE-12), "[untitled simulation]", c, c, c, 255); drawrect(vid_buf, 37, YRES+(MENUSIZE-16), 150, 14, c, c, c, 255); @@ -505,7 +505,7 @@ void draw_svf_ui(pixel *vid_buf) drawtext(vid_buf, 222, YRES+(MENUSIZE-15), "\x83", c, c, c, 255); if (svf_tags[0]) - drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), 154, svf_tags, c, c, c, 255); + drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), XRES+BARSIZE-405, svf_tags, c, c, c, 255); else drawtext(vid_buf, 240, YRES+(MENUSIZE-12), "[no tags set]", c, c, c, 255); @@ -516,7 +516,7 @@ void draw_svf_ui(pixel *vid_buf) drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255); if (svf_login) - drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), svf_user, 255, 255, 255, 255); + drawtextmax(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), 66, svf_user, 255, 255, 255, 255); else drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), "[sign in]", 255, 255, 255, 255); drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255); @@ -1203,8 +1203,9 @@ finish: int save_name_ui(pixel *vid_buf) { - int x0=(XRES-420)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,nd=0; + int x0=(XRES-420)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,idtxtwidth,nd=0; void *th; + char *save_id_text; ui_edit ed; ui_edit ed2; ui_checkbox cb; @@ -1240,6 +1241,10 @@ int save_name_ui(pixel *vid_buf) ed2.cursor = strlen(svf_description); ed2.multiline = 1; strcpy(ed2.str, svf_description); + + save_id_text = malloc(strlen("Current save id: ")+strlen(svf_id)+1); + sprintf(save_id_text,"Current save id: %s",svf_id); + idtxtwidth = textwidth(save_id_text); cb.x = x0+10; cb.y = y0+53+YRES/4; @@ -1275,6 +1280,12 @@ int save_name_ui(pixel *vid_buf) drawrect(vid_buf, x0, y0+74+YRES/4, 192, 16, 192, 192, 192, 255); draw_line(vid_buf, x0+192, y0, x0+192, y0+90+YRES/4, 150, 150, 150, XRES+BARSIZE); + + if (svf_id[0]) + { + fillrect(vid_buf, (XRES+BARSIZE-idtxtwidth)/2-5, YRES+(MENUSIZE-16), idtxtwidth+10, 14, 0, 0, 0, 255); + drawtext(vid_buf, (XRES+BARSIZE-idtxtwidth)/2, YRES+MENUSIZE-12, save_id_text, 255, 255, 255, 255); + } sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE)); @@ -1332,6 +1343,7 @@ int save_name_ui(pixel *vid_buf) } } free(th); + if (save_id_text) free(save_id_text); return 0; } @@ -2549,7 +2561,8 @@ int search_ui(pixel *vid_buf) memset(v_buf, 0, ((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE); } is_p1 = (exp_res < GRID_X*GRID_Y); - free(results); + if (results) + free(results); active = 0; } @@ -2731,7 +2744,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) int nyd,nyu,ry,lv; float ryf; - char *uri, *uri_2, *o_uri; + char *uri, *uri_2, *o_uri, *save_id_text; void *data, *info_data; save_info *info = malloc(sizeof(save_info)); void *http = NULL, *http_2 = NULL; @@ -2749,6 +2762,9 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) drawrect(vid_buf, 50, 50, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 155); drawrect(vid_buf, 50+(XRES/2)+1, 50, XRES+BARSIZE-100-((XRES/2)+1), YRES+MENUSIZE-100, 155, 155, 155, 255); drawtext(vid_buf, 50+(XRES/4)-textwidth("Loading...")/2, 50+(YRES/4), "Loading...", 255, 255, 255, 128); + + save_id_text = malloc(strlen("Save id: ")+strlen(save_id)+1); + sprintf(save_id_text,"Save id: %s",save_id); ed.x = 57+(XRES/2)+1; ed.y = YRES+MENUSIZE-118; @@ -2824,7 +2840,12 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) data = http_async_req_stop(http, &status, &data_size); if (status == 200) { - pixel *full_save = prerender_save(data, data_size, &imgw, &imgh); + pixel *full_save; + if (!data||!data_size) { + error_ui(vid_buf, 0, "Save data is empty (may be corrupt)"); + break; + } + full_save = prerender_save(data, data_size, &imgw, &imgh); if (full_save!=NULL) { save_pic = rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2); data_ready = 1; @@ -2842,15 +2863,16 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) { http_last_use_2 = time(NULL); info_data = http_async_req_stop(http_2, &status_2, NULL); - if (status_2 == 200) + if (status_2 == 200 || !info_data) { info_ready = info_parse(info_data, info); - if (info_ready==-1) { - error_ui(vid_buf, 0, "Not found"); + if (info_ready<=0) { + error_ui(vid_buf, 0, "Save info not found"); break; } } - free(info_data); + if (info_data) + free(info_data); active_2 = 0; free(http_2); http_2 = NULL; @@ -2933,6 +2955,10 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) drawrect(vid_buf, XRES+BARSIZE-100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255); drawtext(vid_buf, XRES+BARSIZE-90, YRES+MENUSIZE-63, "Submit", 255, 255, 255, 255); } + + cix = textwidth(save_id_text); + fillrect(vid_buf, (XRES+BARSIZE-cix)/2-5, YRES+(MENUSIZE-16), cix+10, 14, 0, 0, 0, 255); + drawtext(vid_buf, (XRES+BARSIZE-cix)/2, YRES+MENUSIZE-12, save_id_text, 255, 255, 255, 255); //Open Button bc = openable?255:150; @@ -3050,7 +3076,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) if (queue_open) { if (info_ready && data_ready) { // Do Open! - status = parse_save(data, data_size, 1, 0, 0); + status = parse_save(data, data_size, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap); if (!status) { //if(svf_last) //free(svf_last); @@ -3119,6 +3145,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) if (!b) break; } + if (save_id_text) free(save_id_text); //Close open connections if (http) http_async_req_close(http); @@ -3546,7 +3573,7 @@ int execute_tagop(pixel *vid_buf, char *op, char *tag) return 1; } - if (result[2]) + if (result && result[2]) { strncpy(svf_tags, result+3, 255); svf_id[15] = 0; @@ -3571,7 +3598,7 @@ void execute_save(pixel *vid_buf) plens[0] = strlen(svf_name); parts[1] = svf_description; plens[1] = strlen(svf_description); - parts[2] = build_save(plens+2, 0, 0, XRES, YRES); + parts[2] = build_save(plens+2, 0, 0, XRES, YRES, bmap, fvx, fvy, signs, parts); parts[3] = build_thumb(plens+3, 1); parts[4] = (svf_publish==1)?"Public":"Private"; plens[4] = strlen((svf_publish==1)?"Public":"Private"); @@ -3604,14 +3631,16 @@ void execute_save(pixel *vid_buf) free(result); return; } - if (result && strncmp(result, "OK", 2)) + if (!result || strncmp(result, "OK", 2)) { + if (!result) + result = mystrdup("Could not save - no reply from server"); error_ui(vid_buf, 0, result); free(result); return; } - if (result[2]) + if (result && result[2]) { strncpy(svf_id, result+3, 15); svf_id[15] = 0; @@ -3845,7 +3874,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show command_history *currentcommand; ui_edit ed; ed.x = 15; - ed.y = 210; + ed.y = 207; ed.w = XRES; ed.nx = 1; ed.def = ""; @@ -3854,9 +3883,14 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show ed.hide = 0; ed.multiline = 0; ed.cursor = 0; + //fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190); memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); fillrect(old_buf, -1, -1, XRES, 220, 0, 0, 0, 190); - + cc = 0; + while(cc < 80){ + fillrect(old_buf, -1, -1+cc, XRES+BARSIZE, 2, 0, 0, 0, 160-(cc*2)); + cc++; + } while (!sdl_poll()) { b = SDL_GetMouseState(&mx, &my); @@ -3864,13 +3898,12 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show my /= sdl_scale; ed.focus = 1; - //clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent? memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); - draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE); - drawtext(vid_buf, 100, 15, "Welcome to The Powder Toy console v.3 (by cracker64)\n" - "Current commands are quit, set, reset, load, create, file, kill, sound\n" //TODO: help command - ,255, 187, 187, 255); - + draw_line(vid_buf, 0, 219, XRES+BARSIZE-1, 219, 228, 228, 228, XRES+BARSIZE); + drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64)\n" + "Current commands are quit, set, reset, load, create, file, kill, sound\n" //TODO: help command + ,255, 255, 255, 255); + cc = 0; currentcommand = last_command; while(cc < 10) @@ -3894,8 +3927,11 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show } } - if(error) - drawtext(vid_buf, 15, 190, error,255, 187, 187, 255); + if(error && ed.str[0]=='\0') + drawtext(vid_buf, 20, 207, error, 255, 127, 127, 200); + + drawtext(vid_buf, 5, 207, ">", 255, 255, 255, 240); + ui_edit_draw(vid_buf, &ed); ui_edit_process(mx, my, b, &ed); sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE)); |
