mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
allow changing keybinds for spectator switching and pinging on mouse and keyboard
This commit is contained in:
parent
d06687c607
commit
534a68af4a
3 changed files with 109 additions and 4 deletions
|
@ -40,8 +40,12 @@ function module.on_world_update()
|
||||||
|
|
||||||
local gui_id = 2
|
local gui_id = 2
|
||||||
|
|
||||||
|
local rebind = tonumber(ModSettingGet("quant.ew.rebind_ping"))
|
||||||
if (not EntityHasTag(ctx.my_player.entity, "polymorphed") or EntityHasTag(ctx.my_player.entity, "ew_notplayer"))
|
if (not EntityHasTag(ctx.my_player.entity, "polymorphed") or EntityHasTag(ctx.my_player.entity, "ew_notplayer"))
|
||||||
and (InputIsMouseButtonJustDown(3) or InputIsJoystickButtonJustDown(0, 18)) then
|
and (
|
||||||
|
((rebind == 42 and InputIsMouseButtonJustDown(3))
|
||||||
|
or (rebind ~= 42 and InputIsKeyJustDown(rebind)))
|
||||||
|
or InputIsJoystickButtonJustDown(0, 18)) then
|
||||||
local x,y
|
local x,y
|
||||||
if GameGetIsGamepadConnected() then
|
if GameGetIsGamepadConnected() then
|
||||||
local tx, ty
|
local tx, ty
|
||||||
|
|
|
@ -299,7 +299,7 @@ function spectate.on_world_update()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if InputIsKeyJustDown(54) or InputIsJoystickButtonJustDown(0, 13) then
|
if InputIsKeyJustDown(tonumber(ModSettingGet("quant.ew.rebind_lspectate"))) or InputIsJoystickButtonJustDown(0, 13) then
|
||||||
camera_player = camera_player - 1
|
camera_player = camera_player - 1
|
||||||
if camera_player < 1 then
|
if camera_player < 1 then
|
||||||
camera_player = last_len
|
camera_player = last_len
|
||||||
|
@ -307,7 +307,7 @@ function spectate.on_world_update()
|
||||||
|
|
||||||
has_switched = true
|
has_switched = true
|
||||||
re_cam = true
|
re_cam = true
|
||||||
elseif InputIsKeyJustDown(55) or InputIsJoystickButtonJustDown(0, 14) then
|
elseif InputIsKeyJustDown(tonumber(ModSettingGet("quant.ew.rebind_rspectate"))) or InputIsJoystickButtonJustDown(0, 14) then
|
||||||
camera_player = camera_player + 1
|
camera_player = camera_player + 1
|
||||||
if camera_player > last_len then
|
if camera_player > last_len then
|
||||||
camera_player = 1
|
camera_player = 1
|
||||||
|
|
|
@ -28,11 +28,111 @@ function mod_setting_change_callback( mod_id, gui, in_main_menu, setting, old_va
|
||||||
end
|
end
|
||||||
|
|
||||||
local mod_id = "quant.ew" -- This should match the name of your mod's folder.
|
local mod_id = "quant.ew" -- This should match the name of your mod's folder.
|
||||||
|
local prfx = mod_id .. "."
|
||||||
mod_settings_version = 1 -- This is a magic global that can be used to migrate settings to new mod versions. call mod_settings_get_version() before mod_settings_update() to get the old value.
|
mod_settings_version = 1 -- This is a magic global that can be used to migrate settings to new mod versions. call mod_settings_get_version() before mod_settings_update() to get the old value.
|
||||||
mod_settings =
|
mod_settings =
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--KEY SWITCHER IS FROM NOITA FAIR MOD <3 thx
|
||||||
|
--- gather keycodes from game file
|
||||||
|
local function gather_key_codes()
|
||||||
|
local arr = {}
|
||||||
|
arr["0"] = GameTextGetTranslatedOrNot("$menuoptions_configurecontrols_action_unbound")
|
||||||
|
local keycodes_all = ModTextFileGetContent("data/scripts/debug/keycodes.lua")
|
||||||
|
for line in keycodes_all:gmatch("Key_.-\n") do
|
||||||
|
local _, key, code = line:match("(Key_)(.+) = (%d+)")
|
||||||
|
arr[code] = key:upper()
|
||||||
|
end
|
||||||
|
return arr
|
||||||
|
end
|
||||||
|
local keycodes = gather_key_codes()
|
||||||
|
|
||||||
|
local function pending_input()
|
||||||
|
for code, _ in pairs(keycodes) do
|
||||||
|
if InputIsKeyJustDown(code) then return code end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function ui_get_input(_, gui, _, im_id, setting)
|
||||||
|
local setting_id = prfx .. setting.id
|
||||||
|
local current = tostring(ModSettingGetNextValue(setting_id)) or "0"
|
||||||
|
local current_key = "[" .. keycodes[current] .. "]"
|
||||||
|
|
||||||
|
if setting.is_waiting_for_input then
|
||||||
|
current_key = GameTextGetTranslatedOrNot("$menuoptions_configurecontrols_pressakey")
|
||||||
|
local new_key = pending_input()
|
||||||
|
if new_key then
|
||||||
|
ModSettingSetNextValue(setting_id, new_key, false)
|
||||||
|
setting.is_waiting_for_input = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
GuiLayoutBeginHorizontal(gui, 0, 0, true, 0, 0)
|
||||||
|
GuiText(gui, mod_setting_group_x_offset, 0, setting.ui_name)
|
||||||
|
|
||||||
|
GuiText(gui, 8, 0, "")
|
||||||
|
local _, _, _, x, y = GuiGetPreviousWidgetInfo(gui)
|
||||||
|
local w, h = GuiGetTextDimensions(gui, current_key)
|
||||||
|
GuiOptionsAddForNextWidget(gui, GUI_OPTION.ForceFocusable)
|
||||||
|
GuiImageNinePiece(gui, im_id, x, y, w, h, 0)
|
||||||
|
local _, _, hovered = GuiGetPreviousWidgetInfo(gui)
|
||||||
|
if hovered then
|
||||||
|
GuiTooltip(gui, setting.ui_description, GameTextGetTranslatedOrNot("$menuoptions_reset_keyboard"))
|
||||||
|
GuiColorSetForNextWidget(gui, 1, 1, 0.7, 1)
|
||||||
|
if InputIsMouseButtonJustDown(1) then setting.is_waiting_for_input = true end
|
||||||
|
if InputIsMouseButtonJustDown(2) then
|
||||||
|
GamePlaySound("ui", "ui/button_click", 0, 0)
|
||||||
|
ModSettingSetNextValue(setting_id, setting.value_default, false)
|
||||||
|
setting.is_waiting_for_input = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
GuiText(gui, 0, 0, current_key)
|
||||||
|
|
||||||
|
GuiLayoutEnd(gui)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function build_settings()
|
||||||
|
local settings = {
|
||||||
|
{
|
||||||
|
category_id = "default_settings",
|
||||||
|
ui_name = "",
|
||||||
|
ui_description = "",
|
||||||
|
settings = {
|
||||||
|
{
|
||||||
|
id = "rebind_ping",
|
||||||
|
ui_name = "Ping button",
|
||||||
|
ui_description = "ping. backspace uses middle mouse button instead.",
|
||||||
|
value_default = "42",
|
||||||
|
ui_fn = ui_get_input,
|
||||||
|
is_waiting_for_input = false,
|
||||||
|
scope = MOD_SETTING_SCOPE_RUNTIME,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id = "rebind_lspectate",
|
||||||
|
ui_name = "spectate left Button",
|
||||||
|
ui_description = "left.",
|
||||||
|
value_default = "54",
|
||||||
|
ui_fn = ui_get_input,
|
||||||
|
is_waiting_for_input = false,
|
||||||
|
scope = MOD_SETTING_SCOPE_RUNTIME,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id = "rebind_rspectate",
|
||||||
|
ui_name = "spectate right Button",
|
||||||
|
ui_description = "right.",
|
||||||
|
value_default = "55",
|
||||||
|
ui_fn = ui_get_input,
|
||||||
|
is_waiting_for_input = false,
|
||||||
|
scope = MOD_SETTING_SCOPE_RUNTIME,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return settings
|
||||||
|
end
|
||||||
|
mod_settings = build_settings()
|
||||||
|
|
||||||
-- This function is called to ensure the correct setting values are visible to the game via ModSettingGet(). your mod's settings don't work if you don't have a function like this defined in settings.lua.
|
-- This function is called to ensure the correct setting values are visible to the game via ModSettingGet(). your mod's settings don't work if you don't have a function like this defined in settings.lua.
|
||||||
-- This function is called:
|
-- This function is called:
|
||||||
-- - when entering the mod settings menu (init_scope will be MOD_SETTINGS_SCOPE_ONLY_SET_DEFAULT)
|
-- - when entering the mod settings menu (init_scope will be MOD_SETTINGS_SCOPE_ONLY_SET_DEFAULT)
|
||||||
|
@ -41,7 +141,8 @@ mod_settings =
|
||||||
-- - at the end of an update when mod settings have been changed via ModSettingsSetNextValue() and the game is unpaused (init_scope will be MOD_SETTINGS_SCOPE_RUNTIME)
|
-- - at the end of an update when mod settings have been changed via ModSettingsSetNextValue() and the game is unpaused (init_scope will be MOD_SETTINGS_SCOPE_RUNTIME)
|
||||||
function ModSettingsUpdate( init_scope )
|
function ModSettingsUpdate( init_scope )
|
||||||
--local old_version = mod_settings_get_version( mod_id ) -- This can be used to migrate some settings between mod versions.
|
--local old_version = mod_settings_get_version( mod_id ) -- This can be used to migrate some settings between mod versions.
|
||||||
mod_settings_update( mod_id, mod_settings, init_scope )
|
mod_settings = build_settings()
|
||||||
|
mod_settings_update(mod_id, mod_settings, init_scope)
|
||||||
if ModIsEnabled(mod_id) and (init_scope == 0 or init_scope == 1) then
|
if ModIsEnabled(mod_id) and (init_scope == 0 or init_scope == 1) then
|
||||||
print("Running early init fn")
|
print("Running early init fn")
|
||||||
early_init()
|
early_init()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue