mirror of
https://github.com/holub/mame
synced 2025-07-01 16:19:38 +03:00
plugins/cheat: add ui support for joystick hotkeys [Carl]
This commit is contained in:
parent
fae8777edf
commit
40b37af1c3
@ -125,7 +125,16 @@ function cheat.startplugin()
|
|||||||
local keymap = require("cheat/keycodemap")
|
local keymap = require("cheat/keycodemap")
|
||||||
cheat.hotkeys.keys = manager:machine():input():seq_from_tokens(val.keys)
|
cheat.hotkeys.keys = manager:machine():input():seq_from_tokens(val.keys)
|
||||||
local keysstr = {}
|
local keysstr = {}
|
||||||
val.keys:gsub("([^ ]+)", function(s) keysstr[#keysstr + 1] = keymap[s] return s end)
|
val.keys:gsub("([^ ]+)", function(s)
|
||||||
|
if s:find("KEYCODE_", 1, true) then
|
||||||
|
keysstr[#keysstr + 1] = keymap[s]
|
||||||
|
elseif s:find("JOYCODE_", 1, true) then
|
||||||
|
local stick, button = s:match("JOYCODE_([0-9]+)_BUTTON([0-9]+)")
|
||||||
|
if stick and button then
|
||||||
|
keysstr[#keysstr + 1] = string.format("Joy%dBut%d", stick, button - 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
cheat.hotkeys.keysstr = keysstr
|
cheat.hotkeys.keysstr = keysstr
|
||||||
cheat.hotkeys.pressed = false
|
cheat.hotkeys.pressed = false
|
||||||
end
|
end
|
||||||
@ -145,9 +154,16 @@ function cheat.startplugin()
|
|||||||
if #hotkey.keys > 0 then
|
if #hotkey.keys > 0 then
|
||||||
hotkey.keys = hotkey.keys .. " "
|
hotkey.keys = hotkey.keys .. " "
|
||||||
end
|
end
|
||||||
hotkey.keys = hotkey.keys .. keymap[key]
|
if key:find("Joy", 1, true) then
|
||||||
|
local stick, button = key:match("Joy([0-9]+)But([0-9]+)")
|
||||||
|
hotkey.keys = hotkey.keys .. string.format("JOYCODE_%d_BUTTON%d", stick, button + 1)
|
||||||
|
else
|
||||||
|
hotkey.keys = hotkey.keys .. keymap[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if hotkey.keys ~= "" then
|
||||||
|
hotkeys[#hotkeys + 1] = hotkey
|
||||||
end
|
end
|
||||||
hotkeys[#hotkeys + 1] = hotkey
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #hotkeys > 0 then
|
if #hotkeys > 0 then
|
||||||
@ -338,6 +354,7 @@ function cheat.startplugin()
|
|||||||
local hotkeysel = 0
|
local hotkeysel = 0
|
||||||
local hotkey = 1
|
local hotkey = 1
|
||||||
local hotmod = 1
|
local hotmod = 1
|
||||||
|
local hotmode = 1
|
||||||
local hotkeylist = {}
|
local hotkeylist = {}
|
||||||
local function run_if(func) if func then func() end return func or false end
|
local function run_if(func) if func then func() end return func or false end
|
||||||
local function is_oneshot(cheat) return cheat.script and not cheat.script.run and not cheat.script.off end
|
local function is_oneshot(cheat) return cheat.script and not cheat.script.run and not cheat.script.off end
|
||||||
@ -350,65 +367,89 @@ function cheat.startplugin()
|
|||||||
end
|
end
|
||||||
local keys = {"1","2","3","4","5","6","7","8","9","0"}
|
local keys = {"1","2","3","4","5","6","7","8","9","0"}
|
||||||
local mods = {"LSHFT","RSHFT","LALT","RALT","LCTRL","RCTRL","LWIN","RWIN","MENU"}
|
local mods = {"LSHFT","RSHFT","LALT","RALT","LCTRL","RCTRL","LWIN","RWIN","MENU"}
|
||||||
|
local mode = {"Key", "Joy"}
|
||||||
|
|
||||||
local function hkpopfunc(cheat)
|
local function hkpopfunc(cheat)
|
||||||
|
local function menu_lim(val, min, max)
|
||||||
|
if min == max then
|
||||||
|
return 0
|
||||||
|
elseif val == min then
|
||||||
|
return "r"
|
||||||
|
elseif val == max then
|
||||||
|
return "l"
|
||||||
|
else
|
||||||
|
return "lr"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local hkmenu = {}
|
local hkmenu = {}
|
||||||
hkmenu[1] = {"Set hotkey", "", "off"}
|
hkmenu[1] = {"Set hotkey", "", "off"}
|
||||||
hkmenu[2] = {cheat.desc, "", "off"}
|
hkmenu[2] = {cheat.desc, "", "off"}
|
||||||
hkmenu[3] = {"Current Keys", cheat.hotkeys and table.concat(cheat.hotkeys.keysstr, " ") or "None", "off"}
|
hkmenu[3] = {"Current Keys", cheat.hotkeys and table.concat(cheat.hotkeys.keysstr, " ") or "None", "off"}
|
||||||
hkmenu[4] = {"---", "", "off"}
|
hkmenu[4] = {"---", "", "off"}
|
||||||
hkmenu[5] = {"Key", keys[hotkey], "lr"}
|
hkmenu[5] = {"Hotkey Type", mode[hotmode], menu_lim(hotmode, 1, 2)}
|
||||||
if hotkey == 1 then
|
if hotmode == 2 then
|
||||||
hkmenu[5][3] = "r"
|
hkmenu[6] = {"Stick", hotkey, menu_lim(hotkey, 1, 9)}
|
||||||
elseif hotkey == #keys then
|
hkmenu[7] = {"Button", hotmod, menu_lim(hotmod, 0, 9)}
|
||||||
hkmenu[5][3] = "l"
|
else
|
||||||
|
hkmenu[6] = {"Key", keys[hotkey], menu_lim(hotkey, 1, #keys)}
|
||||||
|
hkmenu[7] = {"Modifier", mods[hotmod], menu_lim(hotmod, 1, #mods)}
|
||||||
end
|
end
|
||||||
hkmenu[6] = {"Modifier", mods[hotmod], "lr"}
|
hkmenu[8] = {"---", "", ""}
|
||||||
if hotkey == 1 then
|
hkmenu[9] = {"Done", "", ""}
|
||||||
hkmenu[6][3] = "r"
|
hkmenu[10] = {"Clear and Exit", "", ""}
|
||||||
elseif hotkey == #keys then
|
hkmenu[11] = {"Cancel", "", ""}
|
||||||
hkmenu[6][3] = "l"
|
|
||||||
end
|
|
||||||
hkmenu[7] = {"---", "", ""}
|
|
||||||
hkmenu[8] = {"Done", "", ""}
|
|
||||||
hkmenu[9] = {"Clear and Exit", "", ""}
|
|
||||||
hkmenu[10] = {"Cancel", "", ""}
|
|
||||||
return hkmenu
|
return hkmenu
|
||||||
end
|
end
|
||||||
|
|
||||||
local function hkcbfunc(cheat, index, event)
|
local function hkcbfunc(cheat, index, event)
|
||||||
if event == "right" then
|
if event == "right" then
|
||||||
if index == 5 then
|
if index == 5 and hotmode == 1 then
|
||||||
hotkey = math.min(hotkey + 1, #keys)
|
hotmode = 2
|
||||||
|
hotkey = 1
|
||||||
|
hotmod = 0
|
||||||
return true
|
return true
|
||||||
elseif index == 6 then
|
elseif index == 6 then
|
||||||
hotmod = math.min(hotmod + 1, #mods)
|
hotkey = math.min(hotkey + 1, hotmode == 2 and 9 or #keys)
|
||||||
|
return true
|
||||||
|
elseif index == 7 then
|
||||||
|
hotmod = math.min(hotmod + 1, hotmode == 2 and 9 or #mods)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif event == "left" then
|
elseif event == "left" then
|
||||||
if index == 5 then
|
if index == 5 and hotmode == 2 then
|
||||||
hotkey = math.max(hotkey - 1, 1)
|
hotmode = 1
|
||||||
|
hotkey = 1
|
||||||
|
hotmod = 1
|
||||||
return true
|
return true
|
||||||
elseif index == 6 then
|
elseif index == 6 then
|
||||||
hotmod = math.max(hotmod - 1, 1)
|
hotkey = math.max(hotkey - 1, 1)
|
||||||
|
return true
|
||||||
|
elseif index == 7 then
|
||||||
|
hotmod = math.max(hotmod - 1, hotmode == 2 and 0 or 1)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif event == "select" then
|
elseif event == "select" then
|
||||||
if index == 8 then
|
if index == 9 then
|
||||||
local keymap = require("cheat/keycodemap")
|
local keymap = require("cheat/keycodemap")
|
||||||
cheat.hotkeys = {}
|
cheat.hotkeys = {}
|
||||||
cheat.hotkeys.keys = manager:machine():input():seq_from_tokens(keymap[keys[hotkey]] .. " " .. keymap[mods[hotmod]])
|
if hotmode == 2 then
|
||||||
cheat.hotkeys.keysstr = {keys[hotkey], mods[hotmod]}
|
cheat.hotkeys.keys = manager:machine():input():seq_from_tokens(string.format("JOYCODE_%d_BUTTON%d", hotkey, hotmod + 1))
|
||||||
|
cheat.hotkeys.keysstr = {string.format("Joy%dBut%d", hotkey, hotmod)}
|
||||||
|
else
|
||||||
|
cheat.hotkeys.keys = manager:machine():input():seq_from_tokens(keymap[keys[hotkey]] .. " " .. keymap[mods[hotmod]])
|
||||||
|
cheat.hotkeys.keysstr = {keys[hotkey], mods[hotmod]}
|
||||||
|
end
|
||||||
cheat.hotkeys.pressed = false
|
cheat.hotkeys.pressed = false
|
||||||
hotkeysel = 0
|
hotkeysel = 0
|
||||||
hotkeymenu = false
|
hotkeymenu = false
|
||||||
return true
|
return true
|
||||||
elseif index == 9 then
|
elseif index == 10 then
|
||||||
cheat.hotkeys = nil
|
cheat.hotkeys = nil
|
||||||
hotkeysel = 0
|
hotkeysel = 0
|
||||||
hotkeymenu = false
|
hotkeymenu = false
|
||||||
return true
|
return true
|
||||||
elseif index == 10 then
|
elseif index == 11 then
|
||||||
hotkeysel = 0
|
hotkeysel = 0
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user