diff options
author | 2021-10-31 12:31:16 +1100 | |
---|---|---|
committer | 2021-10-31 12:31:16 +1100 | |
commit | d64ea5331b2312f81df464fb22dcef0191216d86 (patch) | |
tree | a3f3784371da401e6a675e5b6b9734b88281a08d /src/frontend/mame/ui/inputmap.cpp | |
parent | cfffc54b61cabc5ef9533396bf87324eb5eeb63e (diff) |
-frontend: Refactored menu event handling and fixed a number of issues. (#8777)
* Moved common code for drawing about box, info viewer, and other text box menus to a base class; removed the last of the info viewer logic and the multi-line item hack from the base menu class.
* Added previous/next group navigation for general inputs and plugin input selection menus.
* Moved message catalog logic to lib/util, allowing osd and emu to use localised messages.
* Made the base menu class use the UI manager’s feature for holding session state rather than a static map and mutex.
* Improved menu event handling model, and fixed many issues, particularly with menus behaving badly when hidden/shown.
* Added better support for menus that don’t participate in the usual menu stack, like the menuless sliders and the save/load state menus.
* Made a number of menus refresh state when being shown after being hidden (fixes MT08121 among other issues).
* Fixed indication of mounted slot option in the slot option details menu.
* Improved appearance of background menus when emulation isn't running - draw all menus in the stack, and darken the background menus to make the edges of the active menu clearer.
* Fixed locale issues in -listxml.
-debugger: Made GUI debuggers more uniform.
* Added new memory view features to Win32 debugger.
* Fixed spelling of hexadecimal in Cocoa debugger and added decimal address option.
* Fixed duplicate keyboard shortcut in Cocoa debugger (Shift-Cmd-D was both new device window and 64-bit float format).
* Made keyboard shortcuts slightly more consistent across debuggers.
-plugins: Moved input selection menu and sequence polling code to a common library. Fixed the issue that prevented keyboard inputs being mapped with -steadykey on.
-docs: Started adding some documentation for MAME's internal UI, and updated the list of example front-ends.
-Regenerated message catalog sources. For translators, the new strings are mostly:
* The names of the inputs provided by the OS-dependent layer for things like fullscreen and video features. These show up in the user interface inputs menu.
* The names for automatically generated views. These show up in the video options menu - test with a system with a lot of screens to see more variants.
* The input macro plugin UI.
* A few format strings for analog input assignments.
* A few strings for the about box header.
Diffstat (limited to 'src/frontend/mame/ui/inputmap.cpp')
-rw-r--r-- | src/frontend/mame/ui/inputmap.cpp | 95 |
1 files changed, 75 insertions, 20 deletions
diff --git a/src/frontend/mame/ui/inputmap.cpp b/src/frontend/mame/ui/inputmap.cpp index 5ddf7864adf..a651795ef6c 100644 --- a/src/frontend/mame/ui/inputmap.cpp +++ b/src/frontend/mame/ui/inputmap.cpp @@ -45,12 +45,11 @@ void menu_input_groups::populate(float &customtop, float &custombottom) item_append(menu_item_type::SEPARATOR); } -void menu_input_groups::handle() +void menu_input_groups::handle(event const *ev) { // process the menu - const event *const menu_event = process(0); - if (menu_event && menu_event->iptkey == IPT_UI_SELECT) - menu::stack_push<menu_input_general>(ui(), container(), int(uintptr_t(menu_event->itemref) - 1)); + if (ev && (ev->iptkey == IPT_UI_SELECT)) + menu::stack_push<menu_input_general>(ui(), container(), int(uintptr_t(ev->itemref) - 1)); } @@ -243,6 +242,7 @@ void menu_input_specific::update_input(input_item_data &seqchangeditem) /*------------------------------------------------- menu_input - display a menu for inputs -------------------------------------------------*/ + menu_input::menu_input(mame_ui_manager &mui, render_container &container) : menu(mui, container) , data() @@ -254,12 +254,20 @@ menu_input::menu_input(mame_ui_manager &mui, render_container &container) , record_next(false) , modified_ticks(0) { + set_process_flags(PROCESS_LR_ALWAYS); } menu_input::~menu_input() { } +void menu_input::menu_activated() +{ + // scripts can change settings out from under us + reset(reset_options::REMEMBER_REF); +} + + /*------------------------------------------------- toggle_none_default - toggle between "NONE" and the default item @@ -329,13 +337,12 @@ void menu_input::custom_render(void *selectedref, float top, float bottom, float } } -void menu_input::handle() +void menu_input::handle(event const *ev) { input_item_data *seqchangeditem = nullptr; bool invalidate = false; // process the menu - const event *const menu_event = process(pollingitem ? PROCESS_NOKEYS : PROCESS_LR_ALWAYS); if (pollingitem) { // if we are polling, handle as a special case @@ -349,6 +356,7 @@ void menu_input::handle() { // if UI_CANCEL is pressed, abort pollingitem = nullptr; + set_process_flags(PROCESS_LR_ALWAYS); if (!seq_poll->modified() || modified_ticks == osd_ticks()) { // cancelled immediately - toggle between default and none @@ -366,6 +374,7 @@ void menu_input::handle() else if (seq_poll->poll()) // poll again; if finished, update the sequence { pollingitem = nullptr; + set_process_flags(PROCESS_LR_ALWAYS); if (seq_poll->valid()) { record_next = true; @@ -382,13 +391,15 @@ void menu_input::handle() seq_poll.reset(); } } - else if (menu_event && menu_event->itemref) + else if (ev && ev->itemref) { // otherwise, handle the events - input_item_data &item = *reinterpret_cast<input_item_data *>(menu_event->itemref); - switch (menu_event->iptkey) + input_item_data &item = *reinterpret_cast<input_item_data *>(ev->itemref); + input_item_data *newsel = &item; + switch (ev->iptkey) { case IPT_UI_SELECT: // an item was selected: begin polling + set_process_flags(PROCESS_NOKEYS); errormsg.clear(); erroritem = nullptr; modified_ticks = 0; @@ -415,14 +426,63 @@ void menu_input::handle() break; case IPT_UI_LEFT: // flip between set and append - case IPT_UI_RIGHT: // not very discoverable, but with the prompt it isn't opaque + case IPT_UI_RIGHT: // not very discoverable, but with the prompt it isn't completely opaque if (record_next || !item.seq.empty()) record_next = !record_next; break; + + case IPT_UI_PREV_GROUP: + { + auto current = std::distance(data.data(), &item); + bool found_break = false; + while (0 < current) + { + if (!found_break) + { + if (data[--current].owner != item.owner) + found_break = true; + } + else if (data[current].owner != data[current - 1].owner) + { + newsel = &data[current]; + set_selection(newsel); + set_top_line(selected_index() - 1); + break; + } + else + { + --current; + } + if (found_break && !current) + { + newsel = &data[current]; + set_selection(newsel); + set_top_line(selected_index() - 1); + break; + } + } + } + break; + + case IPT_UI_NEXT_GROUP: + { + auto current = std::distance(data.data(), &item); + while (data.size() > ++current) + { + if (data[current].owner != item.owner) + { + newsel = &data[current]; + set_selection(newsel); + set_top_line(selected_index() - 1); + break; + } + } + } + break; } // if the selection changed, reset the "record next" flag - if (&item != lastitem) + if (newsel != lastitem) { if (erroritem) { @@ -460,15 +520,14 @@ void menu_input::populate_sorted(float &customtop, float &custombottom) const char *nameformat[INPUT_TYPE_TOTAL] = { nullptr }; // create a mini lookup table for name format based on type - nameformat[INPUT_TYPE_DIGITAL] = "%s"; - nameformat[INPUT_TYPE_ANALOG] = "%s Analog"; - nameformat[INPUT_TYPE_ANALOG_INC] = "%s Analog Inc"; - nameformat[INPUT_TYPE_ANALOG_DEC] = "%s Analog Dec"; + nameformat[INPUT_TYPE_DIGITAL] = "%1$s"; + nameformat[INPUT_TYPE_ANALOG] = _("input-name", "%1$s Analog"); + nameformat[INPUT_TYPE_ANALOG_INC] = _("input-name", "%1$s Analog Inc"); + nameformat[INPUT_TYPE_ANALOG_DEC] = _("input-name", "%1$s Analog Dec"); // build the menu std::string text, subtext; const device_t *prev_owner = nullptr; - bool first_entry = true; for (input_item_data &item : data) { // generate the name of the item itself, based off the base name and the type @@ -476,10 +535,6 @@ void menu_input::populate_sorted(float &customtop, float &custombottom) if (item.owner && (item.owner != prev_owner)) { - if (first_entry) - first_entry = false; - else - item_append(menu_item_type::SEPARATOR); if (item.owner->owner()) item_append(string_format(_("%1$s [root%2$s]"), item.owner->type().fullname(), item.owner->tag()), FLAG_UI_HEADING | FLAG_DISABLE, nullptr); else |