From 9a45e2e714171393c7fd127386ca9ef6cfb99b65 Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Thu, 20 May 2021 22:17:14 +0200 Subject: [PATCH] Added feature to hide cards an pill descriptions, when they are not accessible --- content/entities2.xml | 5 +++ eid_config.lua | 19 +++++++++++ main.lua | 73 +++++++++++++++++++++++++++++++------------ metadata.xml | 2 +- mod_config_menu.lua | 67 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 content/entities2.xml diff --git a/content/entities2.xml b/content/entities2.xml new file mode 100644 index 00000000..01c4a91a --- /dev/null +++ b/content/entities2.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/eid_config.lua b/eid_config.lua index 585f60f6..8957c18c 100644 --- a/eid_config.lua +++ b/eid_config.lua @@ -55,6 +55,10 @@ EID.DefaultConfig = { -- Hide the descriptions when in battle -- Default = false ["HideInBattle"] = false, + -- Toggle obstruction based hiding, when the player has flight + -- Default = true + ["DisableObstructionOnFlight"] = true, + -------------CURSE------------- -- Disable informations when the floor has curse of the blind ( ? - Items) @@ -63,6 +67,7 @@ EID.DefaultConfig = { -- Disable Item informations for the second Treasure room item on alt paths -- Default = true ["DisableOnAltPath"] = true, + ----------ITEM NAMES----------- -- Toggle Display of Collectible / Card and Pill names @@ -83,6 +88,7 @@ EID.DefaultConfig = { -- Set the color-name of the Itemname description text. Color names can be found& defined in "eid_data.lua" -- Default = "ColorEIDObjName" ["ItemNameColor"] = "ColorEIDObjName", + -------TRANSFORMATIONS--------- -- Toggle Display of Transformation text @@ -94,6 +100,7 @@ EID.DefaultConfig = { -- Set the color-name of the Transformation description text. Color names can be found& defined in "eid_data.lua" -- Default = "ColorEIDTransform" ["TransformationColor"] = "ColorEIDTransform", + ------------CARDS-------------- -- Toggle Display of Card / Rune descriptions @@ -102,6 +109,10 @@ EID.DefaultConfig = { -- Toggle Display of Card / Rune descriptions when its a shop item -- Default = false ["DisplayCardInfoShop"] = false, + -- Toggle Display of Card / Rune descriptions when its not accessable with walking. AKA behind rock, blocks, spikes + -- Default = false + ["DisplayObstructedCardInfo"] = false, + ------------PILLS-------------- -- Toggle Display of Pill descriptions @@ -110,19 +121,25 @@ EID.DefaultConfig = { -- Toggle Display of Pill descriptions when its a shop item -- Default = true ["DisplayPillInfoShop"] = true, + -- Toggle Display of Pill descriptions when its not accessable with walking. AKA behind rock, blocks, spikes + -- Default = true + ["DisplayObstructedPillInfo"] = true, -- Toggle Display of Pill descriptions that arent known to you yet -- Default = false ["ShowUnidentifiedPillDescriptions"] = false, + --------Sacrifice Room--------- -- Toggle Display of next Sacrifice room Payout descriptions -- Default = true ["DisplaySacrificeInfo"] = true, + --------Dice Room--------- -- Toggle Display of Diceroom descriptions -- Default = true ["DisplayDiceInfo"] = true, + ---------Bag of Crafting----------- -- Display-modes for Bag of Crafting descriptions @@ -134,7 +151,9 @@ EID.DefaultConfig = { -- Higher numbers can cause more lag! -- Default = 7 ["BagOfCraftingResults"] = 7, + -------------MISC--------------- + -- Changes the number of Results shown for the additional Spindown dice description -- Default = 3 ["SpindownDiceResults"] = 3, diff --git a/main.lua b/main.lua index 45388ee2..00476012 100644 --- a/main.lua +++ b/main.lua @@ -168,7 +168,6 @@ if REPENTANCE then EID.lastHidePosition[curRoomIndex] = pickup.Position end EID.altPathItemCounter[curRoomIndex] = curCounter + 1 - print(EID.altPathItemCounter[curRoomIndex]) end end EID:AddCallback(ModCallbacks.MC_POST_PICKUP_UPDATE, EID.onCollectibleInit, PickupVariant.PICKUP_COLLECTIBLE) @@ -323,7 +322,7 @@ function EID:renderIndicator(entity) repDiv = 255 end local sprite = entity:GetSprite() - local entityPos = Game():GetRoom():WorldToScreenPosition(entity.Position) + local entityPos = Isaac.WorldToScreen(entity.Position) if EID.Config["Indicator"] == "blink" then local c = 255 - math.floor(255 * ((entity.FrameCount % 40) / 40)) sprite.Color = Color(1, 1, 1, 1, c/repDiv, c/repDiv, c/repDiv) @@ -352,7 +351,7 @@ function EID:renderIndicator(entity) if entity.Variant == 100 and not entity:ToPickup():IsShopItem() then ArrowOffset = Vector(0, -62) end - ArrowSprite:Render(Game():GetRoom():WorldToScreenPosition(entity.Position + ArrowOffset), nullVector, nullVector) + ArrowSprite:Render(Isaac.WorldToScreen(entity.Position + ArrowOffset), nullVector, nullVector) end end @@ -466,6 +465,51 @@ local function handleBagOfCraftingRendering() return true end + +--------------------------------------------------------------------------- +---------------------------On Update Function------------------------------ + +EID.lastDescriptionEntity = nil +EID.lastDist = 0 +EID.pathCheckerEntity = nil +EID.hasValidWalkingpath = true + +function EID:onGameUpdate() + EID.lastDescriptionEntity = nil + EID.lastDist = 10000 + local player = Isaac.GetPlayer(0) + for i, entity in ipairs(Isaac.GetRoomEntities()) do + if EID:hasDescription(entity) and entity.FrameCount > 0 then + local diff = entity.Position:__sub(player.Position) + if diff:Length() < EID.lastDist then + EID.lastDescriptionEntity = entity + EID.lastDist = diff:Length() + end + end + end + if not EID.Config["DisplayObstructedCardInfo"] or not EID.Config["DisplayObstructedPillInfo"] then + if EID.lastDescriptionEntity == nil or (EID.Config["DisableObstructionOnFlight"] and player.CanFly) then + if EID.pathCheckerEntity ~= nil then + EID.pathCheckerEntity:Remove() + EID.pathCheckerEntity = nil + EID.hasValidWalkingpath = true + end + return + end + if EID.pathCheckerEntity == nil then + EID.pathCheckerEntity = Isaac.Spawn(17, 69420, 0, player.Position, nullVector, nil) -- Spawns the EID Helper entity + EID.pathCheckerEntity:AddEntityFlags (EntityFlag.FLAG_PERSISTENT) + elseif not EID.pathCheckerEntity:Exists() then + EID.pathCheckerEntity = nil + else + EID.pathCheckerEntity.Position = player.Position + EID.hasValidWalkingpath = EID.pathCheckerEntity:ToNPC().Pathfinder:HasPathToPos ( EID.lastDescriptionEntity.Position, false ) + end + end +end +EID:AddCallback(ModCallbacks.MC_POST_UPDATE, EID.onGameUpdate) + + --------------------------------------------------------------------------- ---------------------------On Render Function------------------------------ @@ -513,30 +557,19 @@ local function onRender(t) return end - local closest = nil - local dist = 10000 - for i, entity in ipairs(Isaac.GetRoomEntities()) do - if EID:hasDescription(entity) and entity.FrameCount > 0 then - local diff = entity.Position:__sub(player.Position) - if diff:Length() < dist then - closest = entity - dist = diff:Length() - end - end - end + local closest = EID.lastDescriptionEntity - if dist / 40 > tonumber(EID.Config["MaxDistance"]) or not closest.Type == EntityType.ENTITY_PICKUP then + if EID.lastDist / 40 > tonumber(EID.Config["MaxDistance"]) then if Game():GetRoom():GetType() == RoomType.ROOM_SACRIFICE and EID.Config["DisplaySacrificeInfo"] then local curRoomIndex = Game():GetLevel():GetCurrentRoomIndex() EID:printDescription(EID:getDescriptionObj(-999, -1, EID.sacrificeCounter[curRoomIndex] or 1)) end return end - + if closest == nil then return end - EID.lastDescriptionEntity = closest EID.isDisplaying = true --Handle Indicators @@ -617,14 +650,14 @@ local function onRender(t) EID:printDescription(descriptionObj) elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then --Handle Cards & Runes - if closest:ToPickup():IsShopItem() and not EID.Config["DisplayCardInfoShop"] then + if (closest:ToPickup():IsShopItem() and not EID.Config["DisplayCardInfoShop"]) or (not EID.Config["DisplayObstructedCardInfo"] and not EID.hasValidWalkingpath) then EID:renderQuestionMark() return end EID:printDescription(EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType)) elseif closest.Variant == PickupVariant.PICKUP_PILL then --Handle Pills - if closest:ToPickup():IsShopItem() and not EID.Config["DisplayPillInfoShop"] then + if (closest:ToPickup():IsShopItem() and not EID.Config["DisplayPillInfoShop"]) or (not EID.Config["DisplayObstructedPillInfo"] and not EID.hasValidWalkingpath) then EID:renderQuestionMark() return end @@ -656,7 +689,7 @@ end EID:AddCallback(ModCallbacks.MC_POST_RENDER, onRender) --- only save and load configs when using MCM. Otherwise Config file changes arent calid +-- only save and load configs when using MCM. Otherwise Config file changes arent valid if EID.MCMLoaded then local json = require("json") -------------------------------- diff --git a/metadata.xml b/metadata.xml index 2cfc4f78..97c59d09 100644 --- a/metadata.xml +++ b/metadata.xml @@ -86,7 +86,7 @@ https://moddingofisaac.com/mod/1079/external-item-descriptions - Jake for the sweet [b]German[/b] language pack - [url=https://steamcommunity.com/id/whytefang/]adc[/url] for creating an awesome new Languagepack and providing ideas for new functionalities - 3.43 + 3.44 Public diff --git a/mod_config_menu.lua b/mod_config_menu.lua index d0be102a..6b535a89 100644 --- a/mod_config_menu.lua +++ b/mod_config_menu.lua @@ -381,6 +381,73 @@ if MCMLoaded then end } ) + + --------Obstruction--------- + MCM.AddSpace("EID", "Display") + MCM.AddText("EID", "Display", "Display Infos when obstructed") + + MCM.AddSetting( + "EID", + "Display", + { + Type = ModConfigMenu.OptionType.BOOLEAN, + CurrentSetting = function() + return EID.Config["DisableObstructionOnFlight"] + end, + Display = function() + local onOff = "False" + if EID.Config["DisableObstructionOnFlight"] then + onOff = "True" + end + return "Show again when having flight: " .. onOff + end, + OnChange = function(currentBool) + EID.Config["DisableObstructionOnFlight"] = currentBool + end + } + ) + + MCM.AddSetting( + "EID", + "Display", + { + Type = ModConfigMenu.OptionType.BOOLEAN, + CurrentSetting = function() + return EID.Config["DisplayObstructedCardInfo"] + end, + Display = function() + local onOff = "False" + if EID.Config["DisplayObstructedCardInfo"] then + onOff = "True" + end + return "Card Infos: " .. onOff + end, + OnChange = function(currentBool) + EID.Config["DisplayObstructedCardInfo"] = currentBool + end + } + ) + + MCM.AddSetting( + "EID", + "Display", + { + Type = ModConfigMenu.OptionType.BOOLEAN, + CurrentSetting = function() + return EID.Config["DisplayObstructedPillInfo"] + end, + Display = function() + local onOff = "False" + if EID.Config["DisplayObstructedPillInfo"] then + onOff = "True" + end + return "Pill Infos: " .. onOff + end, + OnChange = function(currentBool) + EID.Config["DisplayObstructedPillInfo"] = currentBool + end + } + ) MCM.AddSpace("EID", "Display") MCM.AddText("EID", "Display", "Display Infos in Shops")