From f5a9f43b77e8ff5f2db8c8c63b5d2a3e190041e4 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 30 Sep 2011 13:57:32 +0100 Subject: [PATCH] Added extra functions to FILT (determined by tmp, modes are convert, filter and add, convert is default). Added property edit tool, changes the properties of materials --- includes/interface.h | 2 + includes/powder.h | 7 +- src/graphics.c | 3 + src/interface.c | 148 ++++++++++++++++++++++++++++++++++++++++++- src/powder.c | 78 ++++++++++++++++++++++- 5 files changed, 232 insertions(+), 6 deletions(-) diff --git a/includes/interface.h b/includes/interface.h index 18ce8b722..5d59dcfce 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -205,6 +205,8 @@ extern int drawgrav_enable; void menu_count(void); +void prop_edit_ui(pixel *vid_buf, int x, int y); + void get_sign_pos(int i, int *x0, int *y0, int *w, int *h); void add_sign_ui(pixel *vid_buf, int mx, int my); diff --git a/includes/powder.h b/includes/powder.h index fb6499f0e..a7cf5fd4f 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -25,7 +25,7 @@ #define UI_WALLSTART 222 #define UI_ACTUALSTART 122 -#define UI_WALLCOUNT 24 +#define UI_WALLCOUNT 25 #define WL_WALLELEC 122 #define WL_EWALL 123 @@ -50,6 +50,7 @@ #define SPC_WIND 241 #define SPC_PGRV 243 #define SPC_NGRV 244 +#define SPC_PROP 246 #define WL_ALLOWGAS 140 #define WL_GRAV 142 @@ -956,7 +957,7 @@ static wall_type wtypes[] = {PIXPACK(0x0000BB), PIXPACK(0x000000), -1, "Postive gravity tool."}, {PIXPACK(0x000099), PIXPACK(0x000000), -1, "Negative gravity tool."}, {PIXPACK(0xFFAA00), PIXPACK(0xAA5500), 4, "Energy wall, allows only energy type particles to pass"}, - + {PIXPACK(0xFFAA00), PIXPACK(0xAA5500), -1, "Property edit tool"}, }; #define CHANNELS ((int)(MAX_TEMP-73)/100+2) @@ -1003,6 +1004,8 @@ static void create_gain_photon(int pp); void kill_part(int i); +int flood_prop(int x, int y, size_t propoffset, void * propvalue, int proptype); + void detach(int i); void part_change_type(int i, int x, int y, int t); diff --git a/src/graphics.c b/src/graphics.c index 381a86b90..837dc4211 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -860,6 +860,7 @@ int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc) case SPC_WIND: case SPC_PGRV: case SPC_NGRV: + case SPC_PROP: for (j=1; j<15; j++) for (i=1; i<27; i++) vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc; @@ -886,6 +887,8 @@ int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc) drawtext(vid_buf, x+14-textwidth("PGRV")/2, y+4, "PGRV", c, c, c, 255); else if (b==SPC_NGRV) drawtext(vid_buf, x+14-textwidth("NGRV")/2, y+4, "NGRV", c, c, c, 255); + else if (b==SPC_PROP) + drawtext(vid_buf, x+14-textwidth("PROP")/2, y+4, "PROP", c, c, c, 255); break; default: for (j=1; j<15; j++) diff --git a/src/interface.c b/src/interface.c index 86c463f65..aa87ff450 100644 --- a/src/interface.c +++ b/src/interface.c @@ -923,6 +923,150 @@ char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shad return mystrdup(ed.str); } +void prop_edit_ui(pixel *vid_buf, int x, int y) +{ + float valuef; + char valuec; + int valuei; + int format; + size_t propoffset; + int xsize = 244; + int ysize = 87; + int edity, editx, edit2y, edit2x; + int x0=(XRES-xsize)/2,y0=(YRES-MENUSIZE-ysize)/2,b=1,bq,mx,my; + ui_edit ed; + ui_edit ed2; + + edity = y0+30; + editx = x0+12; + + edit2y = y0+50; + edit2x = x0+12; + + ed.x = editx; + ed.y = edity; + ed.w = xsize - 20; + ed.nx = 1; + ed.def = "property"; + ed.focus = 0; + ed.hide = 0; + ed.cursor = 0; + ed.multiline = 0; + ed.str[0] = 0; + + ed2.x = edit2x; + ed2.y = edit2y; + ed2.w = xsize - 20; + ed2.nx = 1; + ed2.def = "value"; + ed2.focus = 0; + ed2.hide = 0; + ed2.cursor = 0; + ed2.multiline = 0; + ed2.str[0] = 0; + strncpy(ed2.str, "0", 254); + strncpy(ed.str, "ctype", 254); + + while (!sdl_poll()) + { + b = SDL_GetMouseState(&mx, &my); + if (!b) + break; + } + + while (!sdl_poll()) + { + bq = b; + b = SDL_GetMouseState(&mx, &my); + mx /= sdl_scale; + my /= sdl_scale; + + clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4); + drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255); + drawtext(vid_buf, x0+8, y0+8, "Change particle property", 160, 160, 255, 255); + //drawtext(vid_buf, x0+8, y0+26, prompt, 255, 255, 255, 255); + + drawrect(vid_buf, ed.x-4, ed.y-5, ed.w+4, 16, 192, 192, 192, 255); + drawrect(vid_buf, ed2.x-4, ed2.y-5, ed.w+4, 16, 192, 192, 192, 255); + + ui_edit_draw(vid_buf, &ed); + ui_edit_process(mx, my, b, &ed); + ui_edit_draw(vid_buf, &ed2); + ui_edit_process(mx, my, b, &ed2); + + drawtext(vid_buf, x0+5, y0+ysize-11, "OK", 255, 255, 255, 255); + drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255); + + sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE)); + + if (b && !bq && mx>=x0 && mx=y0+ysize-16 && my<=y0+ysize) + break; + + if (sdl_key==SDLK_RETURN) + break; + if (sdl_key==SDLK_ESCAPE) + break; + } + + sscanf(ed2.str, "%f", &valuef); + + if (strcmp(ed.str,"type")==0){ + propoffset = offsetof(particle, type); + format = 1; + } else if (strcmp(ed.str,"life")==0){ + propoffset = offsetof(particle, life); + format = 0; + } else if (strcmp(ed.str,"ctype")==0){ + propoffset = offsetof(particle, ctype); + format = 1; + } else if (strcmp(ed.str,"temp")==0){ + propoffset = offsetof(particle, temp); + format = 2; + } else if (strcmp(ed.str,"tmp")==0){ + propoffset = offsetof(particle, tmp); + format = 0; + } else if (strcmp(ed.str,"tmp2")==0){ + propoffset = offsetof(particle, tmp2); + format = 0; + } else if (strcmp(ed.str,"vy")==0){ + propoffset = offsetof(particle, vy); + format = 2; + } else if (strcmp(ed.str,"vx")==0){ + propoffset = offsetof(particle, vx); + format = 2; + } else if (strcmp(ed.str,"x")==0){ + propoffset = offsetof(particle, x); + format = 2; + } else if (strcmp(ed.str,"y")==0){ + propoffset = offsetof(particle, y); + format = 2; + } else if (strcmp(ed.str,"dcolour")==0){ + propoffset = offsetof(particle, dcolour); + format = 0; + } else { + error_ui(vid_buf, 0, "Invalid property"); + } + + if(format==0){ + valuei = (int)valuef; + flood_prop(x, y, propoffset, &valuei, format); + } + if(format==1){ + valuec = (char)valuef; + flood_prop(x, y, propoffset, &valuec, format); + } + if(format==2){ + flood_prop(x, y, propoffset, &valuef, format); + } + + while (!sdl_poll()) + { + b = SDL_GetMouseState(&mx, &my); + if (!b) + break; + } +} + void info_ui(pixel *vid_buf, char *top, char *txt) { int x0=(XRES-240)/2,y0=(YRES-MENUSIZE)/2,b=1,bq,mx,my; @@ -1920,7 +2064,7 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *dae, int b, int bq { for (n = UI_WALLSTART; n>8].temp-273.0f)*0.025f); if (temp_bin < 0) temp_bin = 0; if (temp_bin > 25) temp_bin = 25; - parts[i].ctype = 0x1F << temp_bin; + if(!parts[r>>8].tmp){ + parts[i].ctype = 0x1F << temp_bin; //Assign Colour + } else if(parts[r>>8].tmp==1){ + parts[i].ctype &= 0x1F << temp_bin; //Filter Colour + } else if(parts[r>>8].tmp==2){ + parts[i].ctype |= 0x1F << temp_bin; //Add Colour + } } if (parts[i].type == PT_NEUT && (r&0xFF)==PT_GLAS) { if (rand() < RAND_MAX/10) @@ -660,6 +666,9 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a return -1; if (t>=0 && tx2) { i = x2; @@ -2527,11 +2538,67 @@ void create_box(int x1, int y1, int x2, int y2, int c, int flags) create_parts(i, j, 0, 0, c, flags); } +int flood_prop_2(int x, int y, size_t propoffset, void * propvalue, int proptype, int parttype, char * bitmap) +{ + int x1, x2, i, dy = 1; + x1 = x2 = x; + while (x1>=CELL) + { + if ((pmap[y][x1-1]&0xFF)!=parttype || bitmap[(y*XRES)+x1-1]) + { + break; + } + x1--; + } + while (x2>8; + if(proptype==2){ + *((float*)(((void*)&parts[i])+propoffset)) = *((float*)propvalue); + } else if(proptype==0) { + *((int*)(((void*)&parts[i])+propoffset)) = *((int*)propvalue); + } else if(proptype==1) { + *((char*)(((void*)&parts[i])+propoffset)) = *((char*)propvalue); + } + bitmap[(y*XRES)+x] = 1; + } + if (y>=CELL+dy) + for (x=x1; x<=x2; x++) + if ((pmap[y-dy][x]&0xFF)==parttype && !bitmap[((y-dy)*XRES)+x]) + if (!flood_prop_2(x, y-dy, propoffset, propvalue, proptype, parttype, bitmap)) + return 0; + if (yabs(x2-x1), x, y, dx, dy, sy; float e, de; + if (c==SPC_PROP) + return; if (cp) { y = x1;