diff options
author | 2021-10-31 12:31:16 +1100 | |
---|---|---|
committer | 2021-10-31 12:31:16 +1100 | |
commit | d64ea5331b2312f81df464fb22dcef0191216d86 (patch) | |
tree | a3f3784371da401e6a675e5b6b9734b88281a08d /plugins/inputmacro | |
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 'plugins/inputmacro')
-rw-r--r-- | plugins/inputmacro/init.lua | 2 | ||||
-rw-r--r-- | plugins/inputmacro/inputmacro_menu.lua | 199 |
2 files changed, 59 insertions, 142 deletions
diff --git a/plugins/inputmacro/init.lua b/plugins/inputmacro/init.lua index 99e3d61f1d4..4897abee1f5 100644 --- a/plugins/inputmacro/init.lua +++ b/plugins/inputmacro/init.lua @@ -127,7 +127,7 @@ function inputmacro.startplugin() emu.register_frame_done(process_frame) emu.register_start(start) emu.register_stop(stop) - emu.register_menu(menu_callback, menu_populate, _('Input Macros')) + emu.register_menu(menu_callback, menu_populate, _p('plugin-inputmacro', 'Input Macros')) end return exports diff --git a/plugins/inputmacro/inputmacro_menu.lua b/plugins/inputmacro/inputmacro_menu.lua index 7c03d5b95a7..b6b8c9413c0 100644 --- a/plugins/inputmacro/inputmacro_menu.lua +++ b/plugins/inputmacro/inputmacro_menu.lua @@ -9,6 +9,7 @@ local MENU_TYPES = { MACROS = 0, ADD = 1, EDIT = 2, INPUT = 3 } -- Globals +local commonui local macros local menu_stack @@ -51,118 +52,43 @@ end -- Input menu -local input_action +local input_menu local input_start_field -local input_choices -local input_item_first_choice -local input_item_cancel -function handle_input(index, action) - if (action == 'cancel') or ((index == input_item_cancel) and (action == 'select')) then - table.remove(menu_stack) - input_action = nil - return true - elseif action == 'select' then - field = input_choices[index - input_item_first_choice + 1] - if field then - table.remove(menu_stack) - input_action(field) - input_action = nil +function start_input_menu(handler, start_field) + local function supported(f) + if f.is_analog or f.is_toggle then + return false + elseif (f.type_class == 'config') or (f.type_class == 'dipswitch') then + return false + else return true end end - return false -end -function populate_input() - local items = { } - - items[#items + 1] = { _p('plugin-inputmacro', 'Set Input'), '', 'off' } - items[#items + 1] = { '---', '', '' } - - if not input_choices then - local ioport = manager.machine.ioport - - local function supported(f) - if f.is_analog or f.is_toggle then - return false - elseif (f.type_class == 'config') or (f.type_class == 'dipswitch') then - return false - else - return true - end - end - - local function compare(a, b) - if a.device.tag < b.device.tag then - return true - elseif a.device.tag > b.device.tag then - return false - end - groupa = ioport:type_group(a.type, a.player) - groupb = ioport:type_group(b.type, b.player) - if groupa < groupb then - return true - elseif groupa > groupb then - return false - elseif a.type < b.type then - return true - elseif a.type > b.type then - return false - else - return a.name < b.name - end - end - - input_choices = { } - for tag, port in pairs(manager.machine.ioport.ports) do - for name, field in pairs(port.fields) do - if supported(field) then - table.insert(input_choices, field) - end - end - end - table.sort(input_choices, compare) - - local index = 1 - local prev - while index <= #input_choices do - local current = input_choices[index] - if (not prev) or (prev.device.tag ~= current.device.tag) then - table.insert(input_choices, index, false) - index = index + 2 - else - index = index + 1 - end - prev = current + local function action(field) + if field then + handler(field) end + table.remove(menu_stack) + input_menu = nil + input_start_field = nil end - input_item_first_choice = #items + 1 - local selection = input_item_first_choice - for index, field in ipairs(input_choices) do - if field then - items[#items + 1] = { _p('input-name', field.name), '', '' } - if input_start_field and (field.port.tag == input_start_field.port.tag) and (field.mask == input_start_field.mask) and (field.type == input_start_field.type) then - selection = #items - input_start_field = nil - end - else - local device = input_choices[index + 1].device - if device.owner then - items[#items + 1] = { string.format(_('plugin-inputmacro', '%s [root%s]'), device.name, device.tag), '', 'heading' } - else - items[#items + 1] = { string.format(_('plugin-inputmacro', '[root%s]'), device.tag), '', 'heading' } - end - end + if not commonui then + commonui = require('commonui') end - input_start_field = nil + input_menu = commonui.input_selection_menu(action, _p('plugin-inputmacro', 'Set Input'), supported) + input_start_field = start_field + table.insert(menu_stack, MENU_TYPES.INPUT) +end - items[#items + 1] = { '---', '', '' } - items[#items + 1] = { _p('plugin-inputmacro', 'Cancel'), '', '' } - input_item_cancel = #items +function handle_input(index, action) + return input_menu:handle(index, action) +end - return items, selection +function populate_input() + return input_menu:populate(input_start_field) end @@ -176,6 +102,7 @@ local edit_insert_position local edit_name_buffer local edit_items local edit_item_exit +local edit_switch_poller local function current_macro_complete() if not edit_current_macro.binding then @@ -188,36 +115,18 @@ local function current_macro_complete() return true end -local function set_binding() - local input = manager.machine.input - local poller = input:switch_sequence_poller() - manager.machine:popmessage(_p('plugin-inputmacro', 'Enter activation sequence or wait to leave unchanged')) - manager.machine.video:frame_update() - poller:start() - local time = os.clock() - local clearmsg = true - while (not poller:poll()) and (poller.modified or (os.clock() < (time + 1))) do - if poller.modified then - if not poller.valid then - manager.machine:popmessage(_p('plugin-inputmacro', 'Invalid sequence entered')) - clearmsg = false - break +local function handle_edit_items(index, event) + if edit_switch_poller then + if edit_switch_poller:poll() then + if edit_switch_poller.sequence then + edit_current_macro.binding = edit_switch_poller.sequence end - manager.machine:popmessage(input:seq_name(poller.sequence)) - manager.machine.video:frame_update() + edit_switch_poller = nil + return true end + return false end - if clearmsg then - manager.machine:popmessage() - end - if poller.valid then - edit_current_macro.binding = poller.sequence - return true - end - return false -end -local function handle_edit_items(index, event) local command = edit_items[index] local namecancel = false @@ -275,7 +184,11 @@ local function handle_edit_items(index, event) end elseif command.action == 'binding' then if event == 'select' then - return set_binding() + if not commonui then + commonui = require('commonui') + end + edit_switch_poller = commonui.switch_polling_helper() + return true end elseif command.action == 'releaseaction' then if (event == 'select') or (event == 'left') or (event == 'right') then @@ -320,14 +233,13 @@ local function handle_edit_items(index, event) elseif command.action == 'input' then local inputs = edit_current_macro.steps[command.step].inputs if event == 'select' then - input_action = + local hanlder = function(field) inputs[command.input].port = field.port inputs[command.input].field = field end - input_start_field = inputs[command.input].field + start_input_menu(hanlder, inputs[command.input].field) edit_start_selection = index - table.insert(menu_stack, MENU_TYPES.INPUT) return true elseif event == 'clear' then if #inputs > 1 then @@ -338,14 +250,14 @@ local function handle_edit_items(index, event) elseif command.action == 'addinput' then if event == 'select' then local inputs = edit_current_macro.steps[command.step].inputs - input_action = + local handler = function(field) inputs[#inputs + 1] = { port = field.port, field = field } end + start_input_menu(handler) edit_start_selection = index - table.insert(menu_stack, MENU_TYPES.INPUT) return true end elseif command.action == 'deletestep' then @@ -368,7 +280,7 @@ local function handle_edit_items(index, event) elseif command.action == 'addstep' then if event == 'select' then local steps = edit_current_macro.steps - input_action = + local handler = function(field) local newstep = { inputs = { @@ -384,8 +296,8 @@ local function handle_edit_items(index, event) edit_start_step = edit_insert_position edit_insert_position = edit_insert_position + 1 end + start_input_menu(handler) edit_start_selection = index - table.insert(menu_stack, MENU_TYPES.INPUT) return true elseif event == 'left' then edit_insert_position = edit_insert_position - 1 @@ -413,7 +325,7 @@ local function add_edit_items(items) local binding = edit_current_macro.binding local activation = binding and input:seq_name(binding) or _p('plugin-inputmacro', '[not set]') - items[#items + 1] = { _p('plugin-inputmacro', 'Activation sequence'), activation, '' } + items[#items + 1] = { _p('plugin-inputmacro', 'Activation sequence'), activation, edit_switch_poller and 'lr' or '' } edit_items[#items] = { action = 'binding' } local releaseaction = edit_current_macro.earlycancel and _p('plugin-inputmacro', 'Stop immediately') or _p('plugin-inputmacro', 'Complete macro') @@ -484,7 +396,6 @@ local function handle_add(index, event) if handle_edit_items(index, event) then return true elseif event == 'cancel' then - input_choices = nil edit_current_macro = nil edit_menu_active = false edit_items = nil @@ -495,7 +406,6 @@ local function handle_add(index, event) table.insert(macros, edit_current_macro) macros_start_macro = #macros end - input_choices = nil edit_menu_active = false edit_current_macro = nil edit_items = nil @@ -509,7 +419,6 @@ local function handle_edit(index, event) if handle_edit_items(index, event) then return true elseif (event == 'cancel') or ((index == edit_item_exit) and (event == 'select')) then - input_choices = nil edit_current_macro = nil edit_menu_active = false edit_items = nil @@ -537,7 +446,11 @@ local function populate_add() local selection = edit_start_selection edit_start_selection = nil - return items, selection, 'lrrepeat' + if edit_switch_poller then + return edit_switch_poller:overlay(items, selection, 'lrrepeat') + else + return items, selection, 'lrrepeat' + end end local function populate_edit() @@ -554,7 +467,11 @@ local function populate_edit() local selection = edit_start_selection edit_start_selection = nil - return items, selection, 'lrrepeat' + if edit_switch_poller then + return edit_switch_poller:overlay(items, selection, 'lrrepeat') + else + return items, selection, 'lrrepeat' + end end @@ -601,7 +518,7 @@ function populate_macros() local items = { } items[#items + 1] = { _p('plugin-inputmacro', 'Input Macros'), '', 'off' } - items[#items + 1] = { string.format(_p('plugin-inputmacro', 'Press %s to delete'), input:seq_name(ioport:type_seq(ioport:token_to_input_type('UI_CLEAR')))), '', 'off' } + items[#items + 1] = { string.format(_p('plugin-inputmacro', 'Press %s to delete'), manager.ui:get_general_input_setting(ioport:token_to_input_type('UI_CLEAR'))), '', 'off' } items[#items + 1] = { '---', '', '' } macros_item_first_macro = #items + 1 |