mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-26 17:34:35 +02:00
Merge with crackers console
This commit is contained in:
@@ -139,6 +139,7 @@ int gol[XRES][YRES];
|
|||||||
int gol2[XRES][YRES][NGOL];
|
int gol2[XRES][YRES][NGOL];
|
||||||
int SEC;
|
int SEC;
|
||||||
int SEC2;
|
int SEC2;
|
||||||
|
int console_mode;
|
||||||
int REPLACE_MODE;
|
int REPLACE_MODE;
|
||||||
int CURRENT_BRUSH;
|
int CURRENT_BRUSH;
|
||||||
int GRID_MODE;
|
int GRID_MODE;
|
||||||
|
@@ -226,5 +226,7 @@ void open_link(char *uri);
|
|||||||
|
|
||||||
int report_ui(pixel *vid_buf, char *save_id);
|
int report_ui(pixel *vid_buf, char *save_id);
|
||||||
|
|
||||||
|
char *console_ui(pixel *vid_buf, char error[255]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -3809,3 +3809,54 @@ void open_link(char *uri) {
|
|||||||
printf("Cannot open browser\n");
|
printf("Cannot open browser\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show previous commands
|
||||||
|
int mx,my,b,bq;
|
||||||
|
ui_edit ed;
|
||||||
|
ed.x = 15;
|
||||||
|
ed.y = 210;
|
||||||
|
ed.w = XRES;
|
||||||
|
ed.nx = 1;
|
||||||
|
ed.def = "";
|
||||||
|
strcpy(ed.str, "");
|
||||||
|
ed.focus = 1;
|
||||||
|
ed.hide = 0;
|
||||||
|
ed.multiline = 0;
|
||||||
|
ed.cursor = 0;
|
||||||
|
//fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190);
|
||||||
|
while (!sdl_poll())
|
||||||
|
{
|
||||||
|
bq = b;
|
||||||
|
b = SDL_GetMouseState(&mx, &my);
|
||||||
|
mx /= sdl_scale;
|
||||||
|
my /= sdl_scale;
|
||||||
|
ed.focus = 1;
|
||||||
|
|
||||||
|
clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent?
|
||||||
|
draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE);
|
||||||
|
drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.1 (by cracker64)\n"
|
||||||
|
"Current commands are quit, set, reset, load\n"
|
||||||
|
"You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n"
|
||||||
|
"You can also use 'all' instead of a particle number to do it to everything\n"
|
||||||
|
"Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n"
|
||||||
|
"To load a save use load saveID (ex. load 1337)"
|
||||||
|
,255, 187, 187, 255);
|
||||||
|
if(error)
|
||||||
|
drawtext(vid_buf, 15, 190, error,255, 187, 187, 255);
|
||||||
|
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));
|
||||||
|
if (sdl_key==SDLK_RETURN)
|
||||||
|
{
|
||||||
|
return ed.str;
|
||||||
|
}
|
||||||
|
if (sdl_key==SDLK_ESCAPE || sdl_key==SDLK_BACKQUOTE)
|
||||||
|
{
|
||||||
|
console_mode = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
272
src/main.c
272
src/main.c
@@ -1121,6 +1121,7 @@ int main(int argc, char *argv[])
|
|||||||
pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
|
pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
|
||||||
void *http_ver_check;
|
void *http_ver_check;
|
||||||
char *ver_data=NULL, *tmp;
|
char *ver_data=NULL, *tmp;
|
||||||
|
char error[255];
|
||||||
int i, j, bq, fire_fc=0, do_check=0, old_version=0, http_ret=0, major, minor, old_ver_len;
|
int i, j, bq, fire_fc=0, do_check=0, old_version=0, http_ret=0, major, minor, old_ver_len;
|
||||||
#ifdef INTERNAL
|
#ifdef INTERNAL
|
||||||
int vs = 0;
|
int vs = 0;
|
||||||
@@ -1487,8 +1488,13 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
if ((sdl_mod & (KMOD_RCTRL) )&&( sdl_mod & (KMOD_RALT)))
|
if ((sdl_mod & (KMOD_RCTRL) )&&( sdl_mod & (KMOD_RALT)))
|
||||||
active_menu = 11;
|
active_menu = 11;
|
||||||
if (sdl_key==SDLK_INSERT || sdl_key==SDLK_BACKQUOTE)
|
if (sdl_key==SDLK_INSERT)// || sdl_key==SDLK_BACKQUOTE)
|
||||||
REPLACE_MODE = !REPLACE_MODE;
|
REPLACE_MODE = !REPLACE_MODE;
|
||||||
|
if (sdl_key==SDLK_BACKQUOTE)
|
||||||
|
{
|
||||||
|
console_mode = !console_mode;
|
||||||
|
hud_enable = !console_mode;
|
||||||
|
}
|
||||||
if (sdl_key=='g')
|
if (sdl_key=='g')
|
||||||
{
|
{
|
||||||
if (sdl_mod & (KMOD_SHIFT))
|
if (sdl_mod & (KMOD_SHIFT))
|
||||||
@@ -1690,6 +1696,268 @@ int main(int argc, char *argv[])
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(console_mode)
|
||||||
|
{
|
||||||
|
int nx,ny;
|
||||||
|
char *console;
|
||||||
|
char *console2;
|
||||||
|
char *console3;
|
||||||
|
char *console4;
|
||||||
|
char *console5;
|
||||||
|
//char error[255] = "error!";
|
||||||
|
sys_pause = 1;
|
||||||
|
console = console_ui(vid_buf,error);
|
||||||
|
strcpy(error,"");
|
||||||
|
if(console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0)
|
||||||
|
{
|
||||||
|
console2 = strtok(console, " ");
|
||||||
|
console3 = strtok(NULL, " ");
|
||||||
|
console4 = strtok(NULL, " ");
|
||||||
|
console5 = strtok(NULL, " ");
|
||||||
|
if(strcmp(console2, "quit")==0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(strcmp(console2, "load")==0 && console3)
|
||||||
|
{
|
||||||
|
j = atoi(console3);
|
||||||
|
if(j)
|
||||||
|
{
|
||||||
|
open_ui(vid_buf, console3, NULL);
|
||||||
|
console_mode = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(strcmp(console2, "reset")==0 && console3)
|
||||||
|
{
|
||||||
|
if(strcmp(console3, "pressure")==0)
|
||||||
|
{
|
||||||
|
for (nx = 0; nx<XRES/CELL; nx++)
|
||||||
|
for (ny = 0; ny<YRES/CELL; ny++)
|
||||||
|
{
|
||||||
|
pv[ny][nx] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(strcmp(console3, "velocity")==0)
|
||||||
|
{
|
||||||
|
for (nx = 0; nx<XRES/CELL; nx++)
|
||||||
|
for (ny = 0; ny<YRES/CELL; ny++)
|
||||||
|
{
|
||||||
|
vx[ny][nx] = 0;
|
||||||
|
vy[ny][nx] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(strcmp(console3, "sparks")==0)
|
||||||
|
{
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type==PT_SPRK)
|
||||||
|
{
|
||||||
|
parts[i].type = parts[i].ctype;
|
||||||
|
parts[i].life = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(strcmp(console3, "temp")==0)
|
||||||
|
{
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
parts[i].temp = ptypes[parts[i].type].heat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(strcmp(console2, "set")==0 && console3 && console4 && console5)
|
||||||
|
{
|
||||||
|
if(strcmp(console3, "life")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].life = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].life = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(console3, "type")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].type = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].type = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(console3, "temp")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].temp = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].temp = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(console3, "tmp")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].tmp = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].tmp = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(console3, "x")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].x = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].x = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(console3, "y")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].y = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].y = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(console3, "ctype")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].ctype = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].ctype = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(console3, "vx")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].vx = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].vx = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp(console3, "vy")==0)
|
||||||
|
{
|
||||||
|
if(strcmp(console4, "all")==0)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
for(i=0;i<NPART;i++)
|
||||||
|
{
|
||||||
|
if(parts[i].type)
|
||||||
|
parts[i].vy = j;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
i = atoi(console4);
|
||||||
|
if(parts[i].type)
|
||||||
|
{
|
||||||
|
j = atoi(console5);
|
||||||
|
parts[i].vy = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sprintf(error, "Invalid Command", console2);
|
||||||
|
}
|
||||||
|
if(!console_mode)
|
||||||
|
hud_enable = 1;
|
||||||
|
}
|
||||||
|
|
||||||
bq = b;
|
bq = b;
|
||||||
b = SDL_GetMouseState(&x, &y);
|
b = SDL_GetMouseState(&x, &y);
|
||||||
@@ -1741,7 +2009,7 @@ int main(int argc, char *argv[])
|
|||||||
int tctype = parts[cr>>8].ctype;
|
int tctype = parts[cr>>8].ctype;
|
||||||
if (tctype>=PT_NUM)
|
if (tctype>=PT_NUM)
|
||||||
tctype = 0;
|
tctype = 0;
|
||||||
sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[tctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life);
|
sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d, #%d", ptypes[cr&0xFF].name, ptypes[tctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life ,cr>>8);
|
||||||
//sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[parts[cr>>8].ctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life);
|
//sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[parts[cr>>8].ctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life);
|
||||||
} else {
|
} else {
|
||||||
sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", ptypes[cr&0xFF].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f);
|
sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", ptypes[cr&0xFF].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f);
|
||||||
|
Reference in New Issue
Block a user