implement jumps in option menus
Enables shortcuts for option menus. Press a key to immediately jump to the next option menu entry which starts with this key. Hold Alt to jump backwards. Compatible with localized menus (checked on Russian).
This commit is contained in:
parent
eb15d97fe3
commit
7eb12fa9fb
1 changed files with 18 additions and 0 deletions
|
|
@ -201,6 +201,24 @@ class OptionMenu : Menu
|
|||
}
|
||||
return true;
|
||||
}
|
||||
else if (ev.type == UIEvent.Type_Char)
|
||||
{
|
||||
String key = String.Format("%c", ev.keyChar).MakeLower();
|
||||
int itemsNumber = mDesc.mItems.Size();
|
||||
int direction = ev.IsAlt ? -1 : 1;
|
||||
for (int i = 0; i < itemsNumber; ++i)
|
||||
{
|
||||
int index = (mDesc.mSelectedItem + direction * (i + 1) + itemsNumber) % itemsNumber;
|
||||
if (!mDesc.mItems[index].Selectable()) continue;
|
||||
String label = StringTable.Localize(mDesc.mItems[index].mLabel);
|
||||
String firstLabelCharacter = String.Format("%c", label.GetNextCodePoint(0)).MakeLower();
|
||||
if (firstLabelCharacter == key)
|
||||
{
|
||||
mDesc.mSelectedItem = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Super.OnUIEvent(ev);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue