*** empty log message ***

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@515 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2006-11-07 03:13:54 +00:00
parent 8f5aadbaee
commit 50325b19e0
4 changed files with 59 additions and 9 deletions
+55 -7
View File
@@ -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<vhistory.length()) s_strcpy(commandbuf, vhistory[histpos++]);
break;
case SDLK_TAB:
complete(commandbuf);
if(commandpos>=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<sizeof(commandbuf))
{
if(commandpos<0) commandbuf[len] = cooked;
else
{
memmove(&commandbuf[commandpos+1], &commandbuf[commandpos], len - commandpos);
commandbuf[commandpos++] = cooked;
};
commandbuf[len+1] = '\0';
};
};
};
}
else
+2
View File
@@ -17,6 +17,7 @@ extern void writecfg();
// console
extern void keypress(int code, bool isdown, int cooked);
extern void rendercommand(int x, int y);
extern void renderconsole();
// extern void conoutf(const char *s, int a = 0, int b = 0, int c = 0); Moved to cube.h by Rick
extern char *getcurcommand();
@@ -146,6 +147,7 @@ extern void show_out_of_renderloop_progress(float bar1, const char *text1, float
// rendertext
extern void draw_text(const char *str, int left, int top);
extern void draw_textf(const char *fstr, int left, int top, ...);
extern int char_width(int c, int x = 0);
extern int text_width(const char *str, int limit = -1);
extern int text_visible(const char *str, int max);
extern void draw_envbox(int t, int fogdist);
+1 -1
View File
@@ -363,7 +363,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat
char *command = getcurcommand();
dynent *player = playerincrosshair();
dynent *bot = botincrosshair();
if(command) draw_textf("> %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);
+1 -1
View File
@@ -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;