Divergent/mods/Powered Exo-Skeletons/gamedata/scripts/exo_power_activator_mcm.script

78 lines
2.9 KiB
Plaintext
Raw Normal View History

2024-03-17 20:18:03 -04:00
local mcm_key = DIK_keys.DIK_Z -- your default key
local mcm_id = "exo_power" -- change this
local key_function = "key_func" -- this too if you renamed the function
function key_func()
exo_powers.activate_powers()
end
local mcm_keybinds = ui_mcm and ui_mcm.key_hold
local modifier = 0
local second_key = 0
function on_mcm_load()
local options = {
id = mcm_id, sh = true,
gr = {
{ id = mcm_id , type = "slide" , link = "ui_options_slider_player", text = "ui_mcm_menu_" .. mcm_id, size = {512, 50}, spacing = 20},
{ id = "keybind" , type = "key_bind" , val = 2, def = mcm_key },
{ id = "modifier" , type = ui_mcm.kb_mod_radio , val = 2, def = 0, hint = "mcm_kb_mode" ,
content = {
{ 0, "mcm_kb_mode_press"},
{ 1, "mcm_kb_mode_dtap"},
{ 2, "mcm_kb_mode_hold"}
}
},
{ id = "second_key" , type = ui_mcm.kb_mod_radio, val = 2, def = 0, hint = "mcm_kb_modifier" ,
content = {
{0,"mcm_kb_mod_none"} ,
{1,"mcm_kb_mod_shift"} ,
{2,"mcm_kb_mod_ctrl"},
{3,"mcm_kb_mod_alt"}
}},
{ id = "desc_mcm" , type = "desc" , text = "ui_mcm_" .. mcm_id .. "_mcm", clr = {255, 175 ,0 ,0}, precondition = {function() return not mcm_keybinds end} }
}
}
return options
end
local modes = {
[0] = { ["call"] = {"on_key_press", "on_key_hold"}, ["function"] = function(key) ui_mcm.simple_press(mcm_id, key, key_function) end },
[1] = { ["call"] = {"on_key_press", "on_key_hold"}, ["function"] = function(key) if ui_mcm.double_tap(mcm_id, key) then key_function() end end },
[2] = { ["call"] = {"on_key_hold", "on_key_press"}, ["function"] = function(key) if ui_mcm.key_hold(mcm_id, key) then key_function() end end }
}
function on_key_press(key)
if key ~= mcm_key then return end
if not mcm_keybinds then
key_function()
return
end
if ui_mcm.get_mod_key(second_key) then
modes[modifier]["function"](key)
end
end
function on_key_hold(key)
if key ~= mcm_key then return end
if ui_mcm.get_mod_key(second_key) then
modes[modifier]["function"](key)
end
end
function on_option_change(mcm)
if mcm then
mcm_key = ui_mcm.get(mcm_id .. "/keybind")
modifier = ui_mcm.get(mcm_id .. "/modifier")
second_key = ui_mcm.get(mcm_id .. "/second_key")
RegisterScriptCallback(modes[modifier]["call"][1], this[modes[modifier]["call"][1]])
UnregisterScriptCallback(modes[modifier]["call"][2], this[modes[modifier]["call"][2]])
end
end
function on_game_start()
RegisterScriptCallback("on_option_change", on_option_change)
RegisterScriptCallback("on_key_press", on_key_press)
key_function = this[key_function]
on_option_change(mcm_keybinds)
end