From 00f317b3d321d25b3ca404870beb7e12b092c376 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Thu, 23 Mar 2023 03:39:54 +1100 Subject: [PATCH] -ui/menu.cpp: Don't pass IPT_UI_BACK event to the implementation when dismissing the menu. -plugins/autofire, plugins/inputmacro: Don't be so eager to create empty settings folders. --- plugins/autofire/autofire_save.lua | 6 +++--- plugins/autofire/init.lua | 13 +++++++++---- plugins/inputmacro/inputmacro_persist.lua | 10 +++++----- src/frontend/mame/ui/menu.cpp | 3 ++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/plugins/autofire/autofire_save.lua b/plugins/autofire/autofire_save.lua index 52586c461ad..f863b003f4d 100644 --- a/plugins/autofire/autofire_save.lua +++ b/plugins/autofire/autofire_save.lua @@ -75,9 +75,7 @@ end function lib:save_settings(buttons) local path = get_settings_path() local attr = lfs.attributes(path) - if not attr then - lfs.mkdir(path) - elseif attr.mode ~= 'directory' then + if attr and (attr.mode ~= 'directory') then emu.print_error(string.format('Error saving autofire settings: "%s" is not a directory', path)) return end @@ -85,6 +83,8 @@ function lib:save_settings(buttons) if #buttons == 0 then os.remove(filename) return + elseif not attr then + lfs.mkdir(path) end local json = require('json') local settings = serialize_settings(buttons) diff --git a/plugins/autofire/init.lua b/plugins/autofire/init.lua index 9e4743718cb..ab5e7b11f47 100644 --- a/plugins/autofire/init.lua +++ b/plugins/autofire/init.lua @@ -23,13 +23,12 @@ function autofire.startplugin() -- 'counter' - position in autofire cycle local buttons = {} + local input_manager local menu_handler local function process_frame() - local input = manager.machine.input - local function process_button(button) - local pressed = input:seq_pressed(button.key) + local pressed = input_manager:seq_pressed(button.key) if pressed then local state = button.counter < button.on_frames and 1 or 0 button.counter = (button.counter + 1) % (button.on_frames + button.off_frames) @@ -65,6 +64,8 @@ function autofire.startplugin() if loader then buttons = loader:load_settings() end + + input_manager = manager.machine.input end local function save_settings() @@ -74,6 +75,7 @@ function autofire.startplugin() end menu_handler = nil + input_manager = nil buttons = {} end @@ -87,7 +89,10 @@ function autofire.startplugin() local function menu_populate() if not menu_handler then - menu_handler = require('autofire/autofire_menu') + local status, msg = pcall(function () menu_handler = require('autofire/autofire_menu') end) + if not status then + emu.print_error(string.format('Error loading autofire menu: %s', msg)) + end if menu_handler then menu_handler:init_menu(buttons) end diff --git a/plugins/inputmacro/inputmacro_persist.lua b/plugins/inputmacro/inputmacro_persist.lua index 6519f3a048a..b8670800fa4 100644 --- a/plugins/inputmacro/inputmacro_persist.lua +++ b/plugins/inputmacro/inputmacro_persist.lua @@ -101,7 +101,7 @@ end local lib = { } function lib:load_settings() - filename = settings_path() .. '/' .. settings_filename() + local filename = settings_path() .. '/' .. settings_filename() local file = io.open(filename, 'r') if not file then return { } @@ -127,17 +127,17 @@ end function lib:save_settings(macros) local path = settings_path() local stat = lfs.attributes(path) - if not stat then - lfs.mkdir(path) - elseif stat.mode ~= 'directory' then + if stat and (stat.mode ~= 'directory') then emu.print_error(string.format('Error saving input macros: "%s" is not a directory', path)) return end - filename = path .. '/' .. settings_filename() + local filename = path .. '/' .. settings_filename() if #macros == 0 then os.remove(filename) return + elseif not stat then + lfs.mkdir(path) end local json = require('json') diff --git a/src/frontend/mame/ui/menu.cpp b/src/frontend/mame/ui/menu.cpp index f3273752299..a0a1cb20bc0 100644 --- a/src/frontend/mame/ui/menu.cpp +++ b/src/frontend/mame/ui/menu.cpp @@ -1032,7 +1032,7 @@ void menu::handle_keys(uint32_t flags, int &iptkey) { if (is_last_selected() && m_needs_prev_menu_item) { - iptkey = IPT_UI_BACK; + iptkey = IPT_INVALID; stack_pop(); if (is_special_main_menu()) machine().schedule_exit(); @@ -1059,6 +1059,7 @@ void menu::handle_keys(uint32_t flags, int &iptkey) { if (!custom_ui_back()) { + iptkey = IPT_INVALID; stack_pop(); if (is_special_main_menu()) machine().schedule_exit();