From 50325b19e0cbba4e63a19aaee3799fafce2f5ed3 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Tue, 7 Nov 2006 03:13:54 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@515 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/console.cpp | 62 ++++++++++++++++++++++++++++++++----- source/src/protos.h | 2 ++ source/src/renderextras.cpp | 2 +- source/src/rendertext.cpp | 2 +- 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/source/src/console.cpp b/source/src/console.cpp index 659e968c..59f164e1 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -12,6 +12,7 @@ int conskip = 0; bool saycommandon = false; string commandbuf; +int commandpos = -1; void setconskip(int n) { @@ -60,6 +61,14 @@ bool fullconsole = false; void toggleconsole() { fullconsole = !fullconsole; }; COMMAND(toggleconsole, ARG_NONE); +void rendercommand(int x, int y) +{ + s_sprintfd(s)("> %s", commandbuf); + int offset = text_width(s, commandpos>=0 ? commandpos+2 : -1); + blendbox(x+offset, y, x+offset+char_width(commandpos>=0 ? commandbuf[commandpos] : '_'), y+FONTH, true); + draw_text(s, x, y); +}; + void renderconsole() // render buffer taking into account time & scrolling { if(fullconsole) @@ -117,6 +126,7 @@ void saycommand(char *init) // turns input to the comman if(!editmode) keyrepeat(saycommandon); if(!init) init = ""; s_strcpy(commandbuf, init); + commandpos = -1; }; void mapmsg(char *s) { s_strncpy(hdr.maptitle, s, 128); }; @@ -187,26 +197,50 @@ void keypress(int code, bool isdown, int cooked) switch(code) { case SDLK_RETURN: + case SDLK_KP_ENTER: break; - case SDLK_BACKSPACE: - case SDLK_LEFT: + case SDLK_DELETE: { - for(int i = 0; commandbuf[i]; i++) if(!commandbuf[i+1]) commandbuf[i] = 0; + int len = (int)strlen(commandbuf); + if(commandpos<0) break; + memmove(&commandbuf[commandpos], &commandbuf[commandpos+1], len - commandpos); resetcomplete(); + if(commandpos>=len-1) commandpos = -1; break; }; - + + case SDLK_BACKSPACE: + { + int len = (int)strlen(commandbuf), i = commandpos>=0 ? commandpos : len; + if(i<1) break; + memmove(&commandbuf[i-1], &commandbuf[i], len - i + 1); + resetcomplete(); + if(commandpos>0) commandpos--; + else if(!commandpos && len<=1) commandpos = -1; + break; + }; + + case SDLK_LEFT: + if(commandpos>0) commandpos--; + else if(commandpos<0) commandpos = (int)strlen(commandbuf)-1; + break; + + case SDLK_RIGHT: + if(commandpos>=0 && ++commandpos>=(int)strlen(commandbuf)) commandpos = -1; + break; + case SDLK_UP: if(histpos) s_strcpy(commandbuf, vhistory[--histpos]); break; - + case SDLK_DOWN: if(histpos=0 && commandpos>=(int)strlen(commandbuf)) commandpos = -1; break; case SDLK_v: @@ -214,7 +248,21 @@ void keypress(int code, bool isdown, int cooked) default: resetcomplete(); - if(cooked) { char add[] = { cooked, 0 }; s_strcat(commandbuf, add); }; + if(cooked) + { + size_t len = (int)strlen(commandbuf); + if(len+1 %s_", 20, 1570, command); + if(getcurcommand()) rendercommand(20, 1570); else if(closeent[0]) draw_text(closeent, 20, 1570); else if(player || (bot && (player=bot))) draw_text(player->name, 20, 1570); diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 556c5d52..befe8264 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -100,7 +100,7 @@ short char_coords[96][4] = {310,448,363,512}, //~ }; -int char_width(int c, int x = 0) +int char_width(int c, int x) { if(c=='\t') x = (x+PIXELTAB)/PIXELTAB*PIXELTAB; else if(c==' ') x += FONTH/2;