From 7eb12fa9fb5950ae221b5f6b89bc6f6019322493 Mon Sep 17 00:00:00 2001 From: Alexander Kromm Date: Wed, 30 Jun 2021 22:26:17 +0700 Subject: [PATCH] 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). --- .../zscript/engine/ui/menu/optionmenu.zs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wadsrc/static/zscript/engine/ui/menu/optionmenu.zs b/wadsrc/static/zscript/engine/ui/menu/optionmenu.zs index d49677718..47ec02069 100644 --- a/wadsrc/static/zscript/engine/ui/menu/optionmenu.zs +++ b/wadsrc/static/zscript/engine/ui/menu/optionmenu.zs @@ -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); }