diff --git a/QuickStackToBag/Lua/Autorun/init.lua b/QuickStackToBag/Lua/Autorun/init.lua index 228dc98..2bda458 100644 --- a/QuickStackToBag/Lua/Autorun/init.lua +++ b/QuickStackToBag/Lua/Autorun/init.lua @@ -20,6 +20,7 @@ MyModGlobal = { RELOAD = Keys.R, STACK_TO_CURSOR = Keys.G, LOOT = Keys.L, + SONAR = Keys.X, NESTED_CONTAINERS = true, DEBUG_MODE = true, }, @@ -63,6 +64,7 @@ local cursormacroer = require("Cyka.cursormacroer") local quickunload = require("Cyka.quickunload") local quickreload= require("Cyka.quickreload") local quickloot = require("Cyka.quickloot") +local sonarpinger = require("Cyka.sonarpinger") require("Cyka.xpticker") require("Cyka.zoom") @@ -144,3 +146,8 @@ Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptab if not PlayerInput.KeyHit(MyModGlobal.CONFIG.LOOT) then return end quickloot.tryLoot() end, Hook.HookMethodType.After) + +Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable) + if not PlayerInput.KeyHit(MyModGlobal.CONFIG.SONAR) then return end + sonarpinger.tryPing() +end, Hook.HookMethodType.After) diff --git a/QuickStackToBag/Lua/Cyka/sonarpinger.lua b/QuickStackToBag/Lua/Cyka/sonarpinger.lua new file mode 100644 index 0000000..269a4b6 --- /dev/null +++ b/QuickStackToBag/Lua/Cyka/sonarpinger.lua @@ -0,0 +1,72 @@ +-- luacheck: globals Character MyModGlobal LuaUserData Descriptors Timer +local dump = require("Cyka.dump") + +-- LuaUserData.MakeMethodAccessible(Descriptors["Barotrauma.Sonar"], "UpdateGUIElements") + +-- Make sure we have access to the Sonar enum types +-- LuaUserData.RegisterType(Descriptors["Barotrauma.Items.Components.Sonar+Mode"]) + +local function getSonarObjectInFocus() + local character = Character.Controlled + if not character then + MyModGlobal.debugPrint("No controlled character") + return nil, nil + end + + local selectedItem = character.SelectedItem + if not selectedItem then + MyModGlobal.debugPrint("No selected item") + return nil, nil + end + + -- Check if the selected item is in fact the repairable object itself + for _, component in pairs(selectedItem.Components) do + if component.name == "Sonar" then + return selectedItem, component + end + end + + return nil, nil +end + +local function tryPing() + local character = Character.Controlled + if not character then + MyModGlobal.debugPrint("No controlled character") + return + end + + local submarine = character.Submarine + if not submarine then + MyModGlobal.debugPrint("No submarine") + return + end + + local sonar, sonarComponent = getSonarObjectInFocus() + if not sonar or not sonarComponent then + MyModGlobal.debugPrint("No sonar or sonar component") + return + end + + local sonarButton = sonarComponent.SonarModeSwitch + if not sonarButton then + MyModGlobal.debugPrint("No sonar button") + return + end + + sonarButton.Selected = not sonarButton.Selected + if sonarButton.Selected then + -- Active + sonarComponent.CurrentMode = 0 + Timer.Wait(function() + sonarComponent.CurrentMode = 1 + end, 100) + else + -- Passive + sonarComponent.CurrentMode = 1 + end +end + +return { + tryPing = tryPing, +} diff --git a/QuickStackToBag/Lua/Cyka/zoom.lua b/QuickStackToBag/Lua/Cyka/zoom.lua index 0ed9a3b..f3bc355 100644 --- a/QuickStackToBag/Lua/Cyka/zoom.lua +++ b/QuickStackToBag/Lua/Cyka/zoom.lua @@ -7,9 +7,9 @@ local smoothZoom = false -- smooth or step local zStep = 0.5 -- step size for when smoothZoom=false local zSpeed = 0.02 -- speed for when smoothZoom=true -local zMin = 0.1 -- minimum zoom modifier +local zMin = 0.5 -- minimum zoom modifier local zMax = 2.5 -- maximum zoom modifier -local zStart = 1.5 -- default zoom level +local zStart = 0.5 -- default zoom level local zKey = Keys.P -- zoom key local dKey = Keys.NumPad1 -- decrease zoom key