diff options
| author | 2021-11-05 02:46:04 +1100 | |
|---|---|---|
| committer | 2021-11-05 02:46:04 +1100 | |
| commit | de9ed121867b8665060fb91fc1dbee0dfa3ca6fa (patch) | |
| tree | 790bf80e2da36d3c9cc0542514a96aae2fe7b467 /plugins/autofire | |
| parent | f196989f8bbd8163b58aaf20f64904eafbfea52f (diff) | |
plugins: Reduced amnesia for autofire and inputmacro plugins.
Made autofire and inputmacro plugins capable of remembering settings if
the host input device for the binding is missing or if an input for a
slot device that isn't present is referenced.
Diffstat (limited to 'plugins/autofire')
| -rw-r--r-- | plugins/autofire/autofire_menu.lua | 58 | ||||
| -rw-r--r-- | plugins/autofire/autofire_save.lua | 13 | ||||
| -rw-r--r-- | plugins/autofire/init.lua | 11 |
3 files changed, 49 insertions, 33 deletions
diff --git a/plugins/autofire/autofire_menu.lua b/plugins/autofire/autofire_menu.lua index f614c1523fc..dea692dd74b 100644 --- a/plugins/autofire/autofire_menu.lua +++ b/plugins/autofire/autofire_menu.lua @@ -71,9 +71,9 @@ local function populate_main_menu(buttons) local ioport = manager.machine.ioport local input = manager.machine.input local menu = {} - menu[#menu + 1] = {_p('plugin-autofire', 'Autofire buttons'), '', 'off'} - menu[#menu + 1] = {string.format(_p('plugin-autofire', 'Press %s to delete'), manager.ui:get_general_input_setting(ioport:token_to_input_type('UI_CLEAR'))), '', 'off'} - menu[#menu + 1] = {'---', '', ''} + table.insert(menu, {_p('plugin-autofire', 'Autofire buttons'), '', 'off'}) + table.insert(menu, {string.format(_p('plugin-autofire', 'Press %s to delete'), manager.ui:get_general_input_setting(ioport:token_to_input_type('UI_CLEAR'))), '', 'off'}) + table.insert(menu, {'---', '', ''}) header_height = #menu -- Use frame rate of first screen or 60Hz if no screens @@ -88,21 +88,25 @@ local function populate_main_menu(buttons) -- Round rate to two decimal places local rate = freq / (button.on_frames + button.off_frames) rate = math.floor(rate * 100) / 100 - local text = string.format(_p('plugin-autofire', '%s [%g Hz]'), _p('input-name', button.button.name), rate) - local subtext = input:seq_name(button.key) - menu[#menu + 1] = {text, subtext, ''} + local text + if button.button then + text = string.format(_p('plugin-autofire', '%s [%g Hz]'), _p('input-name', button.button.name), rate) + else + text = string.format(_p('plugin-autofire', 'n/a [%g Hz]'), rate) + end + table.insert(menu, {text, input:seq_name(button.key), ''}) if index == initial_button then main_selection_save = #menu end end else - menu[#menu + 1] = {_p('plugin-autofire', '[no autofire buttons]'), '', 'off'} + table.insert(menu, {_p('plugin-autofire', '[no autofire buttons]'), '', 'off'}) end initial_button = nil content_height = #menu - menu[#menu + 1] = {'---', '', ''} - menu[#menu + 1] = {_p('plugin-autofire', 'Add autofire button'), '', ''} + table.insert(menu, {'---', '', ''}) + table.insert(menu, {_p('plugin-autofire', 'Add autofire button'), '', ''}) local selection = main_selection_save main_selection_save = nil @@ -139,15 +143,22 @@ end -- Add/edit menus (mostly identical) local function populate_configure_menu(menu) - local button_name = current_button.button and _p('input-name', current_button.button.name) or _p('plugin-autofire', '[not set]') + local button_name + if current_button.button then + button_name = _p('input-name', current_button.button.name) + elseif current_button.port then + button_name = _p('plugin-autofire', 'n/a') + else + button_name = _p('plugin-autofire', '[not set]') + end local key_name = current_button.key and manager.machine.input:seq_name(current_button.key) or _p('plugin-autofire', '[not set]') - menu[#menu + 1] = {_p('plugin-autofire', 'Input'), button_name, ''} + table.insert(menu, {_p('plugin-autofire', 'Input'), button_name, ''}) if not (configure_menu_active or configure_selection_save) then configure_selection_save = #menu end - menu[#menu + 1] = {_p('plugin-autofire', 'Hotkey'), key_name, hotkey_poller and 'lr' or ''} - menu[#menu + 1] = {_p('plugin-autofire', 'On frames'), current_button.on_frames, current_button.on_frames > 1 and 'lr' or 'r'} - menu[#menu + 1] = {_p('plugin-autofire', 'Off frames'), current_button.off_frames, current_button.off_frames > 1 and 'lr' or 'r'} + table.insert(menu, {_p('plugin-autofire', 'Hotkey'), key_name, hotkey_poller and 'lr' or ''}) + table.insert(menu, {_p('plugin-autofire', 'On frames'), current_button.on_frames, current_button.on_frames > 1 and 'lr' or 'r'}) + table.insert(menu, {_p('plugin-autofire', 'Off frames'), current_button.off_frames, current_button.off_frames > 1 and 'lr' or 'r'}) configure_menu_active = true end @@ -157,6 +168,7 @@ local function handle_configure_menu(index, event) if hotkey_poller:poll() then if hotkey_poller.sequence then current_button.key = hotkey_poller.sequence + current_button.key_cfg = manager.machine.input:seq_to_tokens(hotkey_poller.sequence) end hotkey_poller = nil return true @@ -215,15 +227,15 @@ end local function populate_edit_menu() local menu = {} - menu[#menu + 1] = {_p('plugin-autofire', 'Edit autofire button'), '', 'off'} - menu[#menu + 1] = {'---', '', ''} + table.insert(menu, {_p('plugin-autofire', 'Edit autofire button'), '', 'off'}) + table.insert(menu, {'---', '', ''}) header_height = #menu populate_configure_menu(menu) content_height = #menu - menu[#menu + 1] = {'---', '', ''} - menu[#menu + 1] = {_p('plugin-autofire', 'Done'), '', ''} + table.insert(menu, {'---', '', ''}) + table.insert(menu, {_p('plugin-autofire', 'Done'), '', ''}) local selection = configure_selection_save configure_selection_save = nil @@ -248,18 +260,18 @@ end local function populate_add_menu() local menu = {} - menu[#menu + 1] = {_p('plugin-autofire', 'Add autofire button'), '', 'off'} - menu[#menu + 1] = {'---', '', ''} + table.insert(menu, {_p('plugin-autofire', 'Add autofire button'), '', 'off'}) + table.insert(menu, {'---', '', ''}) header_height = #menu populate_configure_menu(menu) content_height = #menu - menu[#menu + 1] = {'---', '', ''} + table.insert(menu, {'---', '', ''}) if is_button_complete(current_button) then - menu[#menu + 1] = {_p('plugin-autofire', 'Create'), '', ''} + table.insert(menu, {_p('plugin-autofire', 'Create'), '', ''}) else - menu[#menu + 1] = {_p('plugin-autofire', 'Cancel'), '', ''} + table.insert(menu, {_p('plugin-autofire', 'Cancel'), '', ''}) end local selection = configure_selection_save diff --git a/plugins/autofire/autofire_save.lua b/plugins/autofire/autofire_save.lua index f9222bea02a..1ebe06561e1 100644 --- a/plugins/autofire/autofire_save.lua +++ b/plugins/autofire/autofire_save.lua @@ -16,6 +16,7 @@ local function initialize_button(settings) mask = settings.mask, type = ioport:token_to_input_type(settings.type), key = manager.machine.input:seq_from_tokens(settings.key), + key_cfg = settings.key, on_frames = settings.on_frames, off_frames = settings.off_frames, counter = 0 @@ -25,9 +26,9 @@ local function initialize_button(settings) local field = port:field(settings.mask) if field and (field.type == new_button.type) then new_button.button = field - return new_button end end + return new_button end return nil end @@ -35,15 +36,15 @@ end local function serialize_settings(button_list) local settings = {} for index, button in ipairs(button_list) do - setting = { + local setting = { port = button.port, - mask = button.button.mask, - type = manager.machine.ioport:input_type_to_token(button.button.type), - key = manager.machine.input:seq_to_tokens(button.key), + mask = button.mask, + type = manager.machine.ioport:input_type_to_token(button.type), + key = button.key_cfg, on_frames = button.on_frames, off_frames = button.off_frames } - settings[#settings + 1] = setting + table.insert(settings, setting) end return settings end diff --git a/plugins/autofire/init.lua b/plugins/autofire/init.lua index 034d69833e9..136af661dc9 100644 --- a/plugins/autofire/init.lua +++ b/plugins/autofire/init.lua @@ -16,6 +16,7 @@ function autofire.startplugin() -- 'mask' - mask of the button field being autofired -- 'type' - input type of the button being autofired -- 'key' - input_seq of the keybinding + -- 'key_cfg' - configuration string for the keybinding -- 'on_frames' - number of frames button is pressed -- 'off_frames' - number of frames button is released -- 'button' - reference to ioport_field @@ -43,10 +44,12 @@ function autofire.startplugin() local button_states = {} for i, button in ipairs(buttons) do - local key = button.port .. '\0' .. button.mask .. '.' .. button.type - local state = button_states[key] or {0, button.button} - state[1] = process_button(button) | state[1] - button_states[key] = state + if button.button then + local key = button.port .. '\0' .. button.mask .. '.' .. button.type + local state = button_states[key] or {0, button.button} + state[1] = process_button(button) | state[1] + button_states[key] = state + end end for i, state in pairs(button_states) do state[2]:set_value(state[1]) |
