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

This commit is contained in:
Simon Robertshaw 2011-09-30 13:57:32 +01:00
parent 1759d0bd46
commit f5a9f43b77
5 changed files with 232 additions and 6 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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++)

View File

@ -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<x0+xsize && my>=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<UI_WALLSTART+UI_WALLCOUNT; n++)
{
if (n!=SPC_AIR&&n!=SPC_HEAT&&n!=SPC_COOL&&n!=SPC_VACUUM&&n!=SPC_WIND&&n!=SPC_PGRV&&n!=SPC_NGRV)
if (n!=SPC_AIR&&n!=SPC_HEAT&&n!=SPC_COOL&&n!=SPC_VACUUM&&n!=SPC_WIND&&n!=SPC_PGRV&&n!=SPC_NGRV&&n!=SPC_PROP)
{
/*if (x-18<=2)
{
@ -1957,7 +2101,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<UI_WALLSTART+UI_WALLCOUNT; n++)
{
if (n==SPC_AIR||n==SPC_HEAT||n==SPC_COOL||n==SPC_VACUUM||n==SPC_WIND||n==SPC_PGRV||n==SPC_NGRV)
if (n==SPC_AIR||n==SPC_HEAT||n==SPC_COOL||n==SPC_VACUUM||n==SPC_WIND||n==SPC_PGRV||n==SPC_NGRV||n==SPC_PROP)
{
/*if (x-18<=0)
{

View File

@ -261,7 +261,13 @@ int try_move(int i, int x, int y, int nx, int ny)
int temp_bin = (int)((parts[r>>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 && t<PT_NUM && !ptypes[t].enabled)
return -1;
if(t==SPC_PROP) {
return -1; //Prop tool works on a mouse click basic, make sure it doesn't do anything here
}
if (t==SPC_HEAT||t==SPC_COOL)
{
@ -2510,6 +2519,8 @@ void clear_area(int area_x, int area_y, int area_w, int area_h)
void create_box(int x1, int y1, int x2, int y2, int c, int flags)
{
int i, j;
if (c==SPC_PROP)
return 0;
if (x1>x2)
{
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<XRES-CELL)
{
if ((pmap[y][x2+1]&0xFF)!=parttype || bitmap[(y*XRES)+x2+1])
{
break;
}
x2++;
}
for (x=x1; x<=x2; x++)
{
i = pmap[y][x]>>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 (y<YRES-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;
return 1;
}
int flood_prop(int x, int y, size_t propoffset, void * propvalue, int proptype)
{
int r = 0;
char * bitmap = malloc(XRES*YRES); //Bitmap for checking
memset(bitmap, 0, XRES*YRES);
r = pmap[y][x];
flood_prop_2(x, y, propoffset, propvalue, proptype, r&0xFF, bitmap);
}
int flood_parts(int x, int y, int fullc, int cm, int bm, int flags)
{
int c = fullc&0xFF;
int x1, x2, dy = (c<PT_NUM)?1:CELL;
int co = c;
if (c==SPC_PROP)
return 0;
if (cm==PT_INST&&co==PT_SPRK)
if ((pmap[y][x]&0xFF)==PT_SPRK)
return 0;
@ -2707,8 +2774,13 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags)
int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0;//n;
int wall = c - 100;
if (c==SPC_WIND)
if (c==SPC_WIND){
return 0;
}
if(c==SPC_PROP){
prop_edit_ui(vid_buf, x, y);
return 0;
}
for (r=UI_ACTUALSTART; r<=UI_ACTUALSTART+UI_WALLCOUNT; r++)
{
if (wall==r)
@ -2915,6 +2987,8 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flag
{
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
float e, de;
if (c==SPC_PROP)
return;
if (cp)
{
y = x1;