-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.
This commit is contained in:
Vas Crabb 2023-03-23 03:39:54 +11:00
parent 38aef3891a
commit 00f317b3d3
4 changed files with 19 additions and 13 deletions

View File

@ -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)

View File

@ -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

View File

@ -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')

View File

@ -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();