summaryrefslogtreecommitdiff
path: root/src/interface.c
diff options
context:
space:
mode:
authorCracker64 <cracker642@gmail.com>2011-02-11 00:46:34 (GMT)
committer Cracker64 <cracker642@gmail.com>2011-02-11 00:46:34 (GMT)
commite882dfecf91bbad8480422418f163686e60b64b6 (patch)
tree7687a19b0891f67da347e3c9e2a093ef14483b0e /src/interface.c
parent30d86813fcc642cdb2e68c59b5e1db2992a741bc (diff)
downloadpowder-e882dfecf91bbad8480422418f163686e60b64b6.zip
powder-e882dfecf91bbad8480422418f163686e60b64b6.tar.gz
update with latest
Diffstat (limited to 'src/interface.c')
-rw-r--r--src/interface.c72
1 files changed, 27 insertions, 45 deletions
diff --git a/src/interface.c b/src/interface.c
index 31d885a..32c83a1 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -96,7 +96,7 @@ void get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
memset(buff, 0, sizeof(buff));
for(sldr=3; signs[i].text[sldr-1] != '|'; sldr++)
startm = sldr + 1;
-
+
sldr = startm;
while(signs[i].text[sldr] != '}')
{
@@ -105,7 +105,7 @@ void get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
}
*w = textwidth(buff) + 5;
}
-
+
//Ususal width
if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$"))
*w = textwidth(signs[i].text) + 5;
@@ -867,26 +867,26 @@ void login_ui(pixel *vid_buf)
if (res && !strncmp(res, "OK ", 3))
{
char *s_id,*u_e,*nres;
- printf("\n{%s}\n", res);
+ printf("{%s}\n", res);
s_id = strchr(res+3, ' ');
if (!s_id)
goto fail;
*(s_id++) = 0;
-
+
u_e = strchr(s_id, ' ');
- if (!u_e){
+ if (!u_e) {
u_e = malloc(1);
memset(u_e, 0, 1);
}
else
*(u_e++) = 0;
-
+
strcpy(svf_user_id, res+3);
strcpy(svf_session_id, s_id);
nres = mystrdup(u_e);
-
- printf("\n{%s} {%s} {%s}\n", svf_user_id, svf_session_id, nres);
-
+
+ printf("{%s} {%s} {%s}\n", svf_user_id, svf_session_id, nres);
+
if (!strncmp(nres, "ADMIN", 5))
{
svf_admin = 1;
@@ -3862,22 +3862,22 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
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, 100, 15, "Welcome to The Powder Toy console v.2 (by cracker64)\n"
- "Current commands are quit, set, reset, load, create, file, kill, sound\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"
- "You can now use particle names (ex. set type all deut)\n"
- "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n"
- "To load a save use load saveID (ex. load 1337)\n"
- "Create particles with 'create deut x,y' where x and y are the coords\n"
- "Run scripts from file 'file filename'\n"
- "You can delete/kill a particle with 'kill x,y'"
- "Play a sound with (sound blah.wav)"
- ,255, 187, 187, 255);
-
+ "Current commands are quit, set, reset, load, create, file, kill, sound\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"
+ "You can now use particle names (ex. set type all deut)\n"
+ "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n"
+ "To load a save use load saveID (ex. load 1337)\n"
+ "Create particles with 'create deut x,y' where x and y are the coords\n"
+ "Run scripts from file 'file filename'\n"
+ "You can delete/kill a particle with 'kill x,y'"
+ "Play a sound with (sound blah.wav)"
+ ,255, 187, 187, 255);
+
cc = 0;
currentcommand = last_command;
while(cc < 10)
@@ -3957,19 +3957,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
int console_parse_type(char *txt, int *element, char *err)
{
- int i = atoi(txt);
- char num[4];
- if (i>=0 && i<PT_NUM)
- {
- sprintf(num,"%d",i);
- if (strcmp(txt,num)==0)
- {
- *element = i;
- strcpy(err,"");
- return 1;
- }
- }
- i = -1;
+ int i = -1;
// alternative names for some elements
if (strcasecmp(txt,"C4")==0) i = PT_PLEX;
else if (strcasecmp(txt,"C5")==0) i = PT_C5;
@@ -3995,13 +3983,7 @@ int console_parse_coords(char *txt, int *x, int *y, char *err)
{
// TODO: use regex?
int nx = -1, ny = -1;
- sscanf(txt,"%d,%d",&nx,&ny);
- if (nx<0 && nx>=XRES)
- {
- strcpy(err,"Invalid coordinates");
- return 0;
- }
- if (ny<0 && ny>=YRES)
+ if (sscanf(txt,"%d,%d",&nx,&ny)!=2 || nx<0 || nx>=XRES || ny<0 || ny>=YRES)
{
strcpy(err,"Invalid coordinates");
return 0;
@@ -4012,9 +3994,10 @@ int console_parse_coords(char *txt, int *x, int *y, char *err)
}
int console_parse_partref(char *txt, int *which, char *err)
{
+ strcpy(err,"");
// TODO: use regex?
int i = -1, nx, ny;
- if (console_parse_coords(txt, &nx, &ny, err))
+ if (strchr(txt,',') && console_parse_coords(txt, &nx, &ny, err))
{
i = pmap[ny][nx];
if (!i || (i>>8)>=NPART)
@@ -4025,7 +4008,6 @@ int console_parse_partref(char *txt, int *which, char *err)
else if (txt)
{
char *num = (char*)malloc(strlen(txt)+3);
- strcpy(err,""); // suppress error message from failed coordinate parsing
i = atoi(txt);
sprintf(num,"%d",i);
if (!txt || strcmp(txt,num)!=0)
@@ -4038,6 +4020,6 @@ int console_parse_partref(char *txt, int *which, char *err)
strcpy(err,"");
return 1;
}
- strcpy(err,"Particle does not exist");
+ if (strcmp(err,"")==0) strcpy(err,"Particle does not exist");
return 0;
}