diff --git a/src/client/menu/header/qmenu.h b/src/client/menu/header/qmenu.h index b648e9e0..124a451e 100644 --- a/src/client/menu/header/qmenu.h +++ b/src/client/menu/header/qmenu.h @@ -103,7 +103,6 @@ typedef struct int cursor; int length; int visible_length; - int visible_offset; } menufield_s; typedef struct diff --git a/src/client/menu/menu.c b/src/client/menu/menu.c index 90f8ea2d..5d1f68a4 100644 --- a/src/client/menu/menu.c +++ b/src/client/menu/menu.c @@ -311,17 +311,14 @@ Default_MenuKey(menuframework_s *m, int key) if (m) { - menucommon_s *item; + menucommon_s *item = Menu_ItemAtCursor(m); - if ((item = Menu_ItemAtCursor(m)) != 0) + if (item && item->type == MTYPE_FIELD) { - if (item->type == MTYPE_FIELD) - { - if (Field_Key((menufield_s *)item, key)) - { - return NULL; - } - } + if (Field_Key((menufield_s *)item, key)) + { + return NULL; + } } } @@ -5237,6 +5234,7 @@ AddressBook_MenuInit(void) for (i = 0; i < NUM_ADDRESSBOOK_ENTRIES; i++) { + menufield_s *f; const cvar_t *adr; char buffer[20]; @@ -5244,19 +5242,22 @@ AddressBook_MenuInit(void) adr = Cvar_Get(buffer, "", CVAR_ARCHIVE); - s_addressbook_fields[i].generic.type = MTYPE_FIELD; - s_addressbook_fields[i].generic.name = 0; - s_addressbook_fields[i].generic.callback = 0; - s_addressbook_fields[i].generic.x = 0; - s_addressbook_fields[i].generic.y = i * 18 + 0; - s_addressbook_fields[i].generic.localdata[0] = i; - s_addressbook_fields[i].cursor = 0; - s_addressbook_fields[i].length = 60; - s_addressbook_fields[i].visible_length = 30; + f = &s_addressbook_fields[i]; - strcpy(s_addressbook_fields[i].buffer, adr->string); + f->generic.type = MTYPE_FIELD; + f->generic.name = 0; + f->generic.callback = 0; + f->generic.x = 0; + f->generic.y = i * 18 + 0; + f->generic.localdata[0] = i; - Menu_AddItem(&s_addressbook_menu, &s_addressbook_fields[i]); + f->length = 60; + f->visible_length = 30; + + Q_strlcpy(f->buffer, adr->string, f->length); + f->cursor = strlen(f->buffer); + + Menu_AddItem(&s_addressbook_menu, f); } } diff --git a/src/client/menu/qmenu.c b/src/client/menu/qmenu.c index f0e55815..4baca74b 100644 --- a/src/client/menu/qmenu.c +++ b/src/client/menu/qmenu.c @@ -166,7 +166,8 @@ Field_Draw(menufield_s *f) n = sizeof(tempbuffer); } - Q_strlcpy(tempbuffer, f->buffer + f->visible_offset, n); + i = (f->cursor > f->visible_length) ? (f->cursor - f->visible_length) : 0; + Q_strlcpy(tempbuffer, f->buffer + i, n); Draw_CharScaled(x + (16 * scale), (y - 4) * scale, 18, scale); @@ -191,30 +192,23 @@ Field_Draw(menufield_s *f) if (Menu_ItemAtCursor(f->generic.parent) == f) { - int offset; - - if (f->visible_offset) - { - offset = f->visible_length; - } - - else - { - offset = f->cursor; - } - if (((int)(Sys_Milliseconds() / 250)) & 1) { + int offset; + + if (f->cursor > f->visible_length) + { + offset = f->visible_length; + } + else + { + offset = f->cursor; + } + Draw_CharScaled( x + (24 * scale) + (offset * (8 * scale)), y * scale, 11, scale); } - else - { - Draw_CharScaled( - x + (24 * scale) + (offset * (8 * scale)), - y * scale, ' ', scale); - } } } @@ -223,36 +217,39 @@ extern int keydown[]; qboolean Field_Key(menufield_s *f, int key) { - if (key > 127) - { - return false; - } + char txt[2]; switch (key) { case K_KP_LEFTARROW: case K_LEFTARROW: - case K_BACKSPACE: - if (f->cursor > 0) { - memmove(&f->buffer[f->cursor - 1], - &f->buffer[f->cursor], - strlen(&f->buffer[f->cursor]) + 1); f->cursor--; - - if (f->visible_offset) - { - f->visible_offset--; - } } + break; + case K_RIGHTARROW: + if (f->buffer[f->cursor] != '\0') + { + f->cursor++; + } + break; + + case K_BACKSPACE: + if (f->cursor > 0) + { + Q_strdel(f->buffer, f->cursor - 1, 1); + f->cursor--; + } break; case K_KP_DEL: case K_DEL: - memmove(&f->buffer[f->cursor], &f->buffer[f->cursor + 1], - strlen(&f->buffer[f->cursor + 1]) + 1); + if (f->buffer[f->cursor] != '\0') + { + Q_strdel(f->buffer, f->cursor, 1); + } break; case K_KP_ENTER: @@ -261,24 +258,21 @@ Field_Key(menufield_s *f, int key) case K_TAB: return false; - case K_SPACE: default: + if (key > 127) + { + return false; + } if (!isdigit(key) && (f->generic.flags & QMF_NUMBERSONLY)) { return false; } - if (f->cursor < f->length) - { - f->buffer[f->cursor++] = key; - f->buffer[f->cursor] = 0; + *txt = key; + *(txt + 1) = '\0'; - if (f->cursor > f->visible_length) - { - f->visible_offset++; - } - } + f->cursor += Q_strins(f->buffer, txt, f->cursor, f->length); } return true;