summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2017-07-11 22:06:09 -0500
committer cracyc <cracyc@users.noreply.github.com>2017-07-11 22:06:09 -0500
commit40b37af1c3b4d095f187ba42c7bb9e27010069ef (patch)
tree382b1b8614ee81a507b7c7820cd9bb34c03a0ec6 /plugins
parentfae8777edf497497189c39fada16d16f74d777ce (diff)
plugins/cheat: add ui support for joystick hotkeys [Carl]
Diffstat (limited to 'plugins')
-rw-r--r--plugins/cheat/init.lua101
1 files changed, 71 insertions, 30 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua
index dd31f2bcefc..1ea52abdbe3 100644
--- a/plugins/cheat/init.lua
+++ b/plugins/cheat/init.lua
@@ -125,7 +125,16 @@ function cheat.startplugin()
local keymap = require("cheat/keycodemap")
cheat.hotkeys.keys = manager:machine():input():seq_from_tokens(val.keys)
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.pressed = false
end
@@ -145,9 +154,16 @@ function cheat.startplugin()
if #hotkey.keys > 0 then
hotkey.keys = hotkey.keys .. " "
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
- hotkeys[#hotkeys + 1] = hotkey
end
end
if #hotkeys > 0 then
@@ -338,6 +354,7 @@ function cheat.startplugin()
local hotkeysel = 0
local hotkey = 1
local hotmod = 1
+ local hotmode = 1
local hotkeylist = {}
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
@@ -350,65 +367,89 @@ function cheat.startplugin()
end
local keys = {"1","2","3","4","5","6","7","8","9","0"}
local mods = {"LSHFT","RSHFT","LALT","RALT","LCTRL","RCTRL","LWIN","RWIN","MENU"}
+ local mode = {"Key", "Joy"}
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 = {}
hkmenu[1] = {"Set hotkey", "", "off"}
hkmenu[2] = {cheat.desc, "", "off"}
hkmenu[3] = {"Current Keys", cheat.hotkeys and table.concat(cheat.hotkeys.keysstr, " ") or "None", "off"}
hkmenu[4] = {"---", "", "off"}
- hkmenu[5] = {"Key", keys[hotkey], "lr"}
- if hotkey == 1 then
- hkmenu[5][3] = "r"
- elseif hotkey == #keys then
- hkmenu[5][3] = "l"
- end
- hkmenu[6] = {"Modifier", mods[hotmod], "lr"}
- if hotkey == 1 then
- hkmenu[6][3] = "r"
- elseif hotkey == #keys then
- hkmenu[6][3] = "l"
- end
- hkmenu[7] = {"---", "", ""}
- hkmenu[8] = {"Done", "", ""}
- hkmenu[9] = {"Clear and Exit", "", ""}
- hkmenu[10] = {"Cancel", "", ""}
+ hkmenu[5] = {"Hotkey Type", mode[hotmode], menu_lim(hotmode, 1, 2)}
+ if hotmode == 2 then
+ hkmenu[6] = {"Stick", hotkey, menu_lim(hotkey, 1, 9)}
+ hkmenu[7] = {"Button", hotmod, menu_lim(hotmod, 0, 9)}
+ else
+ hkmenu[6] = {"Key", keys[hotkey], menu_lim(hotkey, 1, #keys)}
+ hkmenu[7] = {"Modifier", mods[hotmod], menu_lim(hotmod, 1, #mods)}
+ end
+ hkmenu[8] = {"---", "", ""}
+ hkmenu[9] = {"Done", "", ""}
+ hkmenu[10] = {"Clear and Exit", "", ""}
+ hkmenu[11] = {"Cancel", "", ""}
return hkmenu
end
local function hkcbfunc(cheat, index, event)
if event == "right" then
- if index == 5 then
- hotkey = math.min(hotkey + 1, #keys)
+ if index == 5 and hotmode == 1 then
+ hotmode = 2
+ hotkey = 1
+ hotmod = 0
return true
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
end
elseif event == "left" then
- if index == 5 then
- hotkey = math.max(hotkey - 1, 1)
+ if index == 5 and hotmode == 2 then
+ hotmode = 1
+ hotkey = 1
+ hotmod = 1
return true
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
end
elseif event == "select" then
- if index == 8 then
+ if index == 9 then
local keymap = require("cheat/keycodemap")
cheat.hotkeys = {}
- cheat.hotkeys.keys = manager:machine():input():seq_from_tokens(keymap[keys[hotkey]] .. " " .. keymap[mods[hotmod]])
- cheat.hotkeys.keysstr = {keys[hotkey], mods[hotmod]}
+ if hotmode == 2 then
+ 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
hotkeysel = 0
hotkeymenu = false
return true
- elseif index == 9 then
+ elseif index == 10 then
cheat.hotkeys = nil
hotkeysel = 0
hotkeymenu = false
return true
- elseif index == 10 then
+ elseif index == 11 then
hotkeysel = 0
return true
end