plugins: fix cheatfind menu flags and write xml cheat text to ui container so it's not sideways on rotated screens

This commit is contained in:
cracyc 2021-11-03 20:01:07 -05:00
parent 18a6113655
commit fe0fbb87c2
3 changed files with 30 additions and 27 deletions

View File

@ -172,7 +172,7 @@ function xml.conv_cheat(data)
end end
local function convert_output(data) local function convert_output(data)
local str = "draw_text(screen," local str = "draw_text(ui,"
if data["align"] then if data["align"] then
str = str .. data["align"] str = str .. data["align"]
else else
@ -276,6 +276,7 @@ function xml.conv_cheat(data)
if output then if output then
data["cheat"][count]["screen"] = {} data["cheat"][count]["screen"] = {}
data["cheat"][count]["screen"]["screen"] = ":screen" data["cheat"][count]["screen"]["screen"] = ":screen"
data["cheat"][count]["screen"]["ui"] = "ui"
end end
end end
return data["cheat"] return data["cheat"]

View File

@ -522,7 +522,9 @@ function cheat.startplugin()
if cheat.screen then if cheat.screen then
for name, screen in pairs(cheat.screen) do for name, screen in pairs(cheat.screen) do
local scr = manager.machine.screens[screen] local scr = manager.machine.screens[screen]
if not scr then if screen == "ui" then
scr = manager.machine.render.ui_container
elseif not scr then
local tag local tag
local nxt, coll = manager.machine.screens:pairs() local nxt, coll = manager.machine.screens:pairs()
tag, scr = nxt(coll) -- get any screen tag, scr = nxt(coll) -- get any screen

View File

@ -360,7 +360,7 @@ function cheatfind.startplugin()
local function menu_lim(val, min, max, menuitem) local function menu_lim(val, min, max, menuitem)
if min == max then if min == max then
menuitem[3] = 0 menuitem[3] = "on"
elseif val == min then elseif val == min then
menuitem[3] = "r" menuitem[3] = "r"
elseif val == max then elseif val == max then
@ -389,7 +389,7 @@ function cheatfind.startplugin()
menu[#menu + 1] = function() return { "---", "", "off" }, nil end menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function() menu[#menu + 1] = function()
local c = { _("Default"), _("Custom") } local c = { _("Default"), _("Custom") }
local m = { _("Cheat Name"), c[name], 0 } local m = { _("Cheat Name"), c[name], "on" }
menu_lim(name, 1, #c, m) menu_lim(name, 1, #c, m)
local function f(event) local function f(event)
local r local r
@ -403,12 +403,12 @@ function cheatfind.startplugin()
end end
if name == 2 then if name == 2 then
menu[#menu + 1] = function() menu[#menu + 1] = function()
local m = { _("Player"), cplayer[name_player], 0 } local m = { _("Player"), cplayer[name_player], "on" }
menu_lim(name_player, 1, #cplayer, m) menu_lim(name_player, 1, #cplayer, m)
return m, function(event) local r name_player, r = incdec(event, name_player, 1, #cplayer) return r end return m, function(event) local r name_player, r = incdec(event, name_player, 1, #cplayer) return r end
end end
menu[#menu + 1] = function() menu[#menu + 1] = function()
local m = { _("Type"), ctype[name_type] .. (name_type == #ctype and (#name_other ~= 0 and name_other or _("(empty)")) or ""), 0 } local m = { _("Type"), ctype[name_type] .. (name_type == #ctype and (#name_other ~= 0 and name_other or _("(empty)")) or ""), "on" }
menu_lim(name_type, 1, #ctype, m) menu_lim(name_type, 1, #ctype, m)
local function f(event) local function f(event)
local r local r
@ -433,7 +433,7 @@ function cheatfind.startplugin()
end end
end end
menu[#menu + 1] = function() menu[#menu + 1] = function()
local m = { _("Save"), "", 0 } local m = { _("Save"), "", "on" }
local function f(event) local function f(event)
if event == "select" then if event == "select" then
local desc local desc
@ -489,12 +489,12 @@ function cheatfind.startplugin()
end end
return m, f return m, f
end end
menu[#menu + 1] = function() return { _("Cancel"), "", 0 }, function(event) if event == "select" then cheat_save = nil return true end end end menu[#menu + 1] = function() return { _("Cancel"), "", "on" }, function(event) if event == "select" then cheat_save = nil return true end end end
return menu_prepare() return menu_prepare()
end end
menu[#menu + 1] = function() menu[#menu + 1] = function()
local m = { _("CPU or RAM"), devtable[devsel].name, 0 } local m = { _("CPU or RAM"), devtable[devsel].name, "on" }
menu_lim(devsel, 1, #devtable, m) menu_lim(devsel, 1, #devtable, m)
local function f(event) local function f(event)
if (event == "left" or event == "right") and #menu_blocks ~= 0 then if (event == "left" or event == "right") and #menu_blocks ~= 0 then
@ -509,7 +509,7 @@ function cheatfind.startplugin()
menu[#menu + 1] = function() menu[#menu + 1] = function()
local pausetable = { _("Automatic"), _("Manual") } local pausetable = { _("Automatic"), _("Manual") }
local m = { _("Pause Mode"), pausetable[pausesel], 0 } local m = { _("Pause Mode"), pausetable[pausesel], "on" }
menu_lim(pausesel, 1, pausetable, m) menu_lim(pausesel, 1, pausetable, m)
local function f(event) local function f(event)
if (event == "left" or event == "right") then if (event == "left" or event == "right") then
@ -552,7 +552,7 @@ function cheatfind.startplugin()
end end
end end
local opsel = 1 local opsel = 1
return { _("Start new search"), "", 0 }, f return { _("Start new search"), "", "on" }, f
end end
if #menu_blocks ~= 0 then if #menu_blocks ~= 0 then
@ -580,7 +580,7 @@ function cheatfind.startplugin()
end end
return false return false
end end
return { string.format(_("Save current memory state to Slot %d"), #menu_blocks[1] + 1), "", 0 }, f return { string.format(_("Save current memory state to Slot %d"), #menu_blocks[1] + 1), "", "on" }, f
end end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function() menu[#menu + 1] = function()
@ -658,17 +658,17 @@ function cheatfind.startplugin()
elseif optable[opsel] == "nev" then elseif optable[opsel] == "nev" then
expression_text = string.format(slot_val_comp, leftop, "!=", value) expression_text = string.format(slot_val_comp, leftop, "!=", value)
end end
return { expression_text, "", 0 }, f return { expression_text, "", "on" }, f
end end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function() menu[#menu + 1] = function()
local m = { string.format("%d", leftop), "", 0 } local m = { string.format("%d", leftop), "", "on" }
menu_lim(leftop, 1, #menu_blocks[1], m) menu_lim(leftop, 1, #menu_blocks[1], m)
m[1] = string.format(_("Slot %d"), leftop) m[1] = string.format(_("Slot %d"), leftop)
return m, function(event) local r leftop, r = incdec(event, leftop, 1, #menu_blocks[1]) return r end return m, function(event) local r leftop, r = incdec(event, leftop, 1, #menu_blocks[1]) return r end
end end
menu[#menu + 1] = function() menu[#menu + 1] = function()
local m = { _(optable[opsel]), "", 0 } local m = { _(optable[opsel]), "", "on" }
menu_lim(opsel, 1, #optable, m) menu_lim(opsel, 1, #optable, m)
local function f(event) local function f(event)
local r local r
@ -704,7 +704,7 @@ function cheatfind.startplugin()
if optable[opsel]:sub(3, 3) == "v" then if optable[opsel]:sub(3, 3) == "v" then
return nil return nil
end end
local m = { string.format("%d", rightop), "", 0 } local m = { string.format("%d", rightop), "", "on" }
menu_lim(rightop, 1, #menu_blocks[1], m) menu_lim(rightop, 1, #menu_blocks[1], m)
m[1] = string.format(_("Slot %d"), rightop) m[1] = string.format(_("Slot %d"), rightop)
return m, function(event) local r rightop, r = incdec(event, rightop, 1, #menu_blocks[1]) return r end return m, function(event) local r rightop, r = incdec(event, rightop, 1, #menu_blocks[1]) return r end
@ -728,7 +728,7 @@ function cheatfind.startplugin()
end end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function() menu[#menu + 1] = function()
local m = { _("Data Format"), formname[width], 0 } local m = { _("Data Format"), formname[width], "on" }
menu_lim(width, 1, #formtable, m) menu_lim(width, 1, #formtable, m)
return m, function(event) local r width, r = incdec(event, width, 1, #formtable) return r end return m, function(event) local r width, r = incdec(event, width, 1, #formtable) return r end
end end
@ -737,7 +737,7 @@ function cheatfind.startplugin()
local pokevaltable = { _("Slot 1 Value"), _("Last Slot Value"), "0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", local pokevaltable = { _("Slot 1 Value"), _("Last Slot Value"), "0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06",
"0x07", "0x08", "0x09", "0x63 (99)", "0x99", "0xFF (255)" , "0x3E7 (999)", "0x999", "0x270F (9999)", "0x07", "0x08", "0x09", "0x63 (99)", "0x99", "0xFF (255)" , "0x3E7 (999)", "0x999", "0x270F (9999)",
"0x9999", "0xFFFF (65535)" } "0x9999", "0xFFFF (65535)" }
local m = { _("Test/Write Poke Value"), pokevaltable[pokevalsel], 0 } local m = { _("Test/Write Poke Value"), pokevaltable[pokevalsel], "on" }
menu_lim(pokevalsel, 1, #pokevaltable, m) menu_lim(pokevalsel, 1, #pokevaltable, m)
local function f(event) local function f(event)
local r local r
@ -760,7 +760,7 @@ function cheatfind.startplugin()
if optable[opsel] == "bne" or optable[opsel] == "beq" then if optable[opsel] == "bne" or optable[opsel] == "beq" then
return nil return nil
end end
local m = { "BCD", _("Off"), 0 } local m = { "BCD", _("Off"), "on" }
menu_lim(bcd, 0, 1, m) menu_lim(bcd, 0, 1, m)
if bcd == 1 then if bcd == 1 then
m[2] = _("On") m[2] = _("On")
@ -771,7 +771,7 @@ function cheatfind.startplugin()
if formtable[width]:sub(3, 3) == "1" then if formtable[width]:sub(3, 3) == "1" then
return nil return nil
end end
local m = { _("Aligned only"), _("Off"), 0 } local m = { _("Aligned only"), _("Off"), "on" }
menu_lim(align, 0, 1, m) menu_lim(align, 0, 1, m)
if align == 1 then if align == 1 then
m[2] = _("On") m[2] = _("On")
@ -788,7 +788,7 @@ function cheatfind.startplugin()
end end
return false return false
end end
return { _("Undo last search -- #") .. #matches, "", 0 }, f return { _("Undo last search -- #") .. #matches, "", "on" }, f
end end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function() menu[#menu + 1] = function()
@ -959,8 +959,8 @@ function cheatfind.startplugin()
setname = emu.softname():gsub(":", "/") setname = emu.softname():gsub(":", "/")
else else
for name, image in pairs(manager.machine.images) do for name, image in pairs(manager.machine.images) do
if image:exists() and image:software_list_name() ~= "" then if image.exists and image.software_list_name ~= "" then
setname = image:software_list_name() .. "/" .. emu.softname() setname = image.software_list_name .. "/" .. emu.softname()
end end
end end
end end
@ -1002,7 +1002,7 @@ function cheatfind.startplugin()
end end
local modes = { _("Test"), _("Write"), _("Watch") } local modes = { _("Test"), _("Write"), _("Watch") }
local m = { string.format("%08x" .. bitwidth .. bitwidth, match.addr, match.oldval, local m = { string.format("%08x" .. bitwidth .. bitwidth, match.addr, match.oldval,
match.newval), modes[match.mode], 0 } match.newval), modes[match.mode], "on" }
menu_lim(match.mode, 1, #modes, m) menu_lim(match.mode, 1, #modes, m)
local function f(event) local function f(event)
local r local r
@ -1017,7 +1017,7 @@ function cheatfind.startplugin()
end end
if matches[#matches].count > 100 then if matches[#matches].count > 100 then
menu[#menu + 1] = function() menu[#menu + 1] = function()
local m = { _("Page"), matchpg, 0 } local m = { _("Page"), matchpg, "on" }
local max local max
if matchsel == 0 then if matchsel == 0 then
max = math.ceil(matches[#matches].count / 100) - 1 max = math.ceil(matches[#matches].count / 100) - 1
@ -1036,7 +1036,7 @@ function cheatfind.startplugin()
end end
if #watches ~= 0 then if #watches ~= 0 then
menu[#menu + 1] = function() menu[#menu + 1] = function()
return { _("Clear Watches"), "", 0 }, function(event) if event == "select" then watches = {} return true end end return { _("Clear Watches"), "", "on" }, function(event) if event == "select" then watches = {} return true end end
end end
end end
end end
@ -1053,7 +1053,7 @@ function cheatfind.startplugin()
end end
emu.register_menu(menu_callback, menu_populate, _("Cheat Finder")) emu.register_menu(menu_callback, menu_populate, _("Cheat Finder"))
emu.register_frame_done(function () emu.register_frame_done(function ()
local screen = manager.machine.screens:at(1) local screen = manager.machine.render.ui_container
local height = mame_manager.ui.line_height local height = mame_manager.ui.line_height
for num, watch in ipairs(watches) do for num, watch in ipairs(watches) do
screen:draw_text("left", num * height, string.format(watch.format, watch.addr, watch.func())) screen:draw_text("left", num * height, string.format(watch.format, watch.addr, watch.func()))