mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 04:31:09 +00:00
Left/right arrow nav in menu fields
This commit is contained in:
parent
6408cc7099
commit
aae0524687
3 changed files with 60 additions and 66 deletions
|
@ -103,7 +103,6 @@ typedef struct
|
|||
int cursor;
|
||||
int length;
|
||||
int visible_length;
|
||||
int visible_offset;
|
||||
} menufield_s;
|
||||
|
||||
typedef struct
|
||||
|
|
|
@ -311,11 +311,9 @@ 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->type == MTYPE_FIELD)
|
||||
if (item && item->type == MTYPE_FIELD)
|
||||
{
|
||||
if (Field_Key((menufield_s *)item, key))
|
||||
{
|
||||
|
@ -323,7 +321,6 @@ Default_MenuKey(menuframework_s *m, int key)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (menu_key)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
@ -190,31 +191,24 @@ Field_Draw(menufield_s *f)
|
|||
y, tempbuffer);
|
||||
|
||||
if (Menu_ItemAtCursor(f->generic.parent) == f)
|
||||
{
|
||||
if (((int)(Sys_Milliseconds() / 250)) & 1)
|
||||
{
|
||||
int offset;
|
||||
|
||||
if (f->visible_offset)
|
||||
if (f->cursor > f->visible_length)
|
||||
{
|
||||
offset = f->visible_length;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
offset = f->cursor;
|
||||
}
|
||||
|
||||
if (((int)(Sys_Milliseconds() / 250)) & 1)
|
||||
{
|
||||
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--;
|
||||
}
|
||||
break;
|
||||
|
||||
if (f->visible_offset)
|
||||
case K_RIGHTARROW:
|
||||
if (f->buffer[f->cursor] != '\0')
|
||||
{
|
||||
f->visible_offset--;
|
||||
}
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue