BoC: Extended Search API; Search reset after restart / new level
This commit is contained in:
1 parent
de1d96a103
commit
4ccb2cc14b
2 files changed
+76
-49
No files matched your search
@@ -237,9 +237,6 @@ local recheckPickups = false
|
|||||||
local customRNGSeed = 0x77777770
|
local customRNGSeed = 0x77777770
|
||||||
local customRNGShift = {0,0,0}
|
local customRNGShift = {0,0,0}
|
||||||
|
|
||||||
local lastSearchValue = "";
|
|
||||||
local lastSearchInputEnabled = false;
|
|
||||||
|
|
||||||
-- Use local RNG functions to possibly reduce processing time a little bit
|
-- Use local RNG functions to possibly reduce processing time a little bit
|
||||||
local function RNGNext()
|
local function RNGNext()
|
||||||
local num = customRNGSeed
|
local num = customRNGSeed
|
||||||
@@ -935,14 +932,12 @@ function EID:handleBagOfCraftingUpdating()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local currentSearchValue = EID:BoCSGetSearchValue()
|
local oldSearchValue = EID:BoCSGetSearchValue()
|
||||||
local currentSearchInputEnabled = EID:BoCSGetSearchInputEnabled()
|
local oldSearchInputEnabled = EID:BoCSGetSearchInputEnabled()
|
||||||
EID:BoCSHandleInput()
|
EID:BoCSHandleInput()
|
||||||
if currentSearchValue ~= lastSearchValue or currentSearchInputEnabled ~= lastSearchInputEnabled then
|
if oldSearchValue ~= EID:BoCSGetSearchValue() or oldSearchInputEnabled ~= EID:BoCSGetSearchInputEnabled() then
|
||||||
refreshNextTick = true
|
refreshNextTick = true
|
||||||
end
|
end
|
||||||
lastSearchValue = currentSearchValue
|
|
||||||
lastSearchInputEnabled = currentSearchInputEnabled
|
|
||||||
|
|
||||||
-- Check for Hold Tab key inputs
|
-- Check for Hold Tab key inputs
|
||||||
if displayingRecipeList and Input.IsActionPressed(EID.Config["BagOfCraftingToggleKey"], EID.bagPlayer.ControllerIndex) then
|
if displayingRecipeList and Input.IsActionPressed(EID.Config["BagOfCraftingToggleKey"], EID.bagPlayer.ControllerIndex) then
|
||||||
|
|||||||
@@ -4,6 +4,18 @@ local searchInputEnabled = false
|
|||||||
local lastBackspaceTrigger = 0
|
local lastBackspaceTrigger = 0
|
||||||
local backspaceStep = 0
|
local backspaceStep = 0
|
||||||
|
|
||||||
|
--- Returns the current search query
|
||||||
|
-- @param newValue new search query
|
||||||
|
function EID:BoCSSetSearchValue(newValue)
|
||||||
|
if newValue == nil then
|
||||||
|
newValue = ""
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
searchValue = newValue
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Returns the current search query
|
--- Returns the current search query
|
||||||
-- @return string
|
-- @return string
|
||||||
function EID:BoCSGetSearchValue()
|
function EID:BoCSGetSearchValue()
|
||||||
@@ -30,7 +42,7 @@ end
|
|||||||
|
|
||||||
--- Gets if the filtering is currently enabled
|
--- Gets if the filtering is currently enabled
|
||||||
function EID:BoCSGetSearchEnabled()
|
function EID:BoCSGetSearchEnabled()
|
||||||
return true
|
return searchValue ~= nil and searchValue ~= ""
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Returns true if the item name is matched
|
--- Returns true if the item name is matched
|
||||||
@@ -135,27 +147,8 @@ function EID:BoCSGetSearchLine()
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
function EID:BoCSHookInputIsButtonTriggered()
|
||||||
-- This is a workaround to block every single Input call that could potentially be
|
|
||||||
-- used from another mod.
|
|
||||||
-- We override the Input functions with our own stubs to prevent other mods from
|
|
||||||
-- doing actions while the user is performing a search.
|
|
||||||
-- This does NOT block the main game from performing actions like toggling fullscreen
|
|
||||||
-- or toggling the pause!--
|
|
||||||
-- Since this could be useful for multiple reasons, this should probably be put
|
|
||||||
-- inside the main.lua instead of leaving this here
|
|
||||||
-- Hooking multiple times WILL impact the performance!--
|
|
||||||
-- I've also added a third parameter called "force"
|
|
||||||
-- This way, we are still able to force the real function to be called instead
|
|
||||||
-- of our modified code--
|
|
||||||
-- This code should not impact the performance in a huge way
|
|
||||||
-- since the first thing we do is check if the searchInput is enabled anyway
|
|
||||||
-- We can allow losing a bit of performance when searching
|
|
||||||
function EID:BoCSHookInput()
|
|
||||||
local oldInputIsButtonTriggered = Input.IsButtonTriggered
|
local oldInputIsButtonTriggered = Input.IsButtonTriggered
|
||||||
local oldInputIsButtonPressed = Input.IsButtonPressed
|
|
||||||
local oldInputIsActionTriggered = Input.IsActionTriggered
|
|
||||||
local oldInputIsActionPressed = Input.IsActionPressed
|
|
||||||
|
|
||||||
Input.IsButtonTriggered = function(key, controller, force)
|
Input.IsButtonTriggered = function(key, controller, force)
|
||||||
if force or not searchInputEnabled then
|
if force or not searchInputEnabled then
|
||||||
@@ -176,6 +169,10 @@ function EID:BoCSHookInput()
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function EID:BoCSHookInputIsButtonPressed()
|
||||||
|
local oldInputIsButtonPressed = Input.IsButtonPressed
|
||||||
|
|
||||||
Input.IsButtonPressed = function(key, controller, force)
|
Input.IsButtonPressed = function(key, controller, force)
|
||||||
if force or not searchInputEnabled then
|
if force or not searchInputEnabled then
|
||||||
@@ -196,26 +193,10 @@ function EID:BoCSHookInput()
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Input.IsActionTriggered = function(key, controller, force)
|
function EID:BoCSHookInputIsActionPressed()
|
||||||
if force or not searchInputEnabled then
|
local oldInputIsActionPressed = Input.IsActionPressed
|
||||||
return oldInputIsActionTriggered(key, controller)
|
|
||||||
end
|
|
||||||
|
|
||||||
local bagPlayer = nil
|
|
||||||
if EID.isRepentance then
|
|
||||||
local hasBag, player = EID:PlayersHaveCollectible(710)
|
|
||||||
if hasBag then
|
|
||||||
bagPlayer = player
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if bagPlayer == nil or controller ~= bagPlayer.ControllerIndex then
|
|
||||||
return oldInputIsActionTriggered(key, controller)
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
Input.IsActionPressed = function(key, controller, force)
|
Input.IsActionPressed = function(key, controller, force)
|
||||||
if force or not searchInputEnabled then
|
if force or not searchInputEnabled then
|
||||||
@@ -236,8 +217,53 @@ function EID:BoCSHookInput()
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Isaac.DebugString("Hooked Input")
|
function EID:BoCSHookInputIsActionTriggered()
|
||||||
|
local oldInputIsActionTriggered = Input.IsActionTriggered
|
||||||
|
|
||||||
|
Input.IsActionTriggered = function(key, controller, force)
|
||||||
|
if force or not searchInputEnabled then
|
||||||
|
return oldInputIsActionTriggered(key, controller)
|
||||||
|
end
|
||||||
|
|
||||||
|
local bagPlayer = nil
|
||||||
|
if EID.isRepentance then
|
||||||
|
local hasBag, player = EID:PlayersHaveCollectible(710)
|
||||||
|
if hasBag then
|
||||||
|
bagPlayer = player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if bagPlayer == nil or controller ~= bagPlayer.ControllerIndex then
|
||||||
|
return oldInputIsActionTriggered(key, controller)
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- This is a workaround to block every single Input call that could potentially be
|
||||||
|
-- used from another mod.
|
||||||
|
-- We override the Input functions with our own stubs to prevent other mods from
|
||||||
|
-- doing actions while the user is performing a search.
|
||||||
|
-- This does NOT block the main game from performing actions like toggling fullscreen
|
||||||
|
-- or toggling the pause!
|
||||||
|
-- Since this could be useful for multiple reasons, this should probably be put
|
||||||
|
-- inside the main.lua instead of leaving this here
|
||||||
|
-- Hooking multiple times WILL impact the performance!
|
||||||
|
-- I've also added a third parameter called "force"
|
||||||
|
-- This way, we are still able to force the real function to be called instead
|
||||||
|
-- of our modified code
|
||||||
|
-- This code should not impact the performance in a huge way
|
||||||
|
-- since the first thing we do is check if the searchInput is enabled anyway
|
||||||
|
-- We can allow losing a bit of performance when searching
|
||||||
|
function EID:BoCSHookInput()
|
||||||
|
EID:BoCSHookInputIsButtonTriggered()
|
||||||
|
EID:BoCSHookInputIsButtonPressed()
|
||||||
|
EID:BoCSHookInputIsActionTriggered()
|
||||||
|
EID:BoCSHookInputIsActionPressed()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Blocks all input actions triggered by the games bindings itself
|
--- Blocks all input actions triggered by the games bindings itself
|
||||||
@@ -265,4 +291,10 @@ function EID:BoCSBlockInputAction(entity, inputHook, buttonAction)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Resets the search query when entering a new level (and starting a new game)
|
||||||
|
function EID:BoCSOnNewLevel()
|
||||||
|
EID:BoCSSetSearchValue("")
|
||||||
|
end
|
||||||
|
|
||||||
EID:BoCSHookInput()
|
EID:BoCSHookInput()
|
||||||
|
EID:AddCallback(ModCallbacks.MC_POST_NEW_LEVEL, EID.BoCSOnNewLevel)
|
||||||
Reference in new issue
Block a user