From 5528afb4890157bb8fad1907ff3e64e4d54a40bb Mon Sep 17 00:00:00 2001 From: cracyc Date: Wed, 27 Nov 2019 14:12:02 -0600 Subject: [PATCH] plugins/cheatfind: permit entry of cheat names --- plugins/cheatfind/init.lua | 37 ++++++++++++++++++++++++------ src/frontend/mame/ui/pluginopt.cpp | 4 ++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua index 7c98bf38afa..62b11e8970f 100644 --- a/plugins/cheatfind/init.lua +++ b/plugins/cheatfind/init.lua @@ -280,6 +280,7 @@ function cheatfind.startplugin() local name = 1 local name_player = 1 local name_type = 1 + local name_other = "" local function start() devtable = {} @@ -381,7 +382,7 @@ function cheatfind.startplugin() if cheat_save then local cplayer = { "All", "P1", "P2", "P3", "P4" } - local ctype = { "Infinite Credits", "Infinite Time", "Infinite Lives", "Infinite Energy", "Infinite Ammo", "Infinite Bombs", "Invincibility" } + local ctype = { "Infinite Credits", "Infinite Time", "Infinite Lives", "Infinite Energy", "Infinite Ammo", "Infinite Bombs", "Invincibility", _("Other: ") } menu[#menu + 1] = function() return { _("Save Cheat"), "", "off" }, nil end menu[#menu + 1] = function() return { "---", "", "off" }, nil end menu[#menu + 1] = function() @@ -405,9 +406,28 @@ function cheatfind.startplugin() return m, function(event) local r name_player, r = incdec(event, name_player, 1, #cplayer) return r end end menu[#menu + 1] = function() - local m = { _("Type"), ctype[name_type], 0 } + local m = { _("Type"), ctype[name_type] .. (name_type == #ctype and (#name_other ~= 0 and name_other or _("(empty)")) or ""), 0 } menu_lim(name_type, 1, #ctype, m) - return m, function(event) local r name_type, r = incdec(event, name_type, 1, #ctype) return r end + local function f(event) + local r + name_type, r = incdec(event, name_type, 1, #ctype) + if name_type == #ctype then + local char = tonumber(event) + if char then + if #name_other > 0 and (char == 8 or char == 0x7f) then + name_other = name_other:sub(1, utf8.offset(name_other, -1) - 1) + r = true + elseif char > 0x1f and (char & ~0x7f) ~= 0x80 and (char & ~0xf) ~= 0xfdd0 and (char & ~0xfffe) ~= 0xfffe then + name_other = name_other .. utf8.char(char) + r = true + end + elseif event == "select" or event == "comment" or event == "right" then + manager:machine():popmessage(_("You can enter any type name")) + end + end + return r + end + return m, f end end menu[#menu + 1] = function() @@ -417,10 +437,13 @@ function cheatfind.startplugin() local desc local written = false if name == 2 then - if cplayer[name_player] == "All" then - desc = ctype[name_type] - else - desc = cplayer[name_player] .. " " .. ctype[name_type] + desc = name_type ~= #ctype and ctype[name_type] or name_other + if #desc == 0 then + manager:machine():popmessage(_("Type name is empty")) + return + end + if cplayer[name_player] ~= "All" then + desc = cplayer[name_player] .. " " .. desc end else desc = cheat_save.name diff --git a/src/frontend/mame/ui/pluginopt.cpp b/src/frontend/mame/ui/pluginopt.cpp index d892461a75b..fabd5c44337 100644 --- a/src/frontend/mame/ui/pluginopt.cpp +++ b/src/frontend/mame/ui/pluginopt.cpp @@ -11,6 +11,7 @@ #include "emu.h" #include "ui/pluginopt.h" +#include "ui/utils.h" #include "mame.h" #include "luaengine.h" @@ -99,6 +100,9 @@ void menu_plugin_opt::handle() case IPT_UI_CANCEL: key = "cancel"; break; + case IPT_SPECIAL: + key = std::to_string((u32)menu_event->unichar); + break; default: return; }