Added feature to display Item icon next to name and a demo icon when in MCM

This commit is contained in:
Wofsauge committed 2020-11-19 23:03:41 +01:00
1 parent 924bbafca6
commit 7df94cd5d5
5 files changed
+130 -53

No files matched your search

+31 -16
View File
@@ -138,6 +138,18 @@ function EID:addColor(shortcut, kColor, callback)
end
end
-- Overrides all potentially displayed texts and permanently displays the given texts. Can be turned of again using the "EID:hidePermanentText()" function
function EID:displayPermanentText(descriptionObject)
EID.permanentDisplayTextObj = descriptionObject
EID.isDisplayingPermanent = true
end
-- Hides permanently displayed text objects if they exist.
function EID:hidePermanentText()
EID.permanentDisplayTextObj = nil
EID.isDisplayingPermanent = false
end
-- function to turn entity type names into actual ingame ID.Variant pairs
function EID:getIDVariantString(typeName)
if typeName == "collectible" or typeName == "collectibles" then return "5.100"
@@ -205,26 +217,24 @@ end
-- returns the description object of the specified object table translated with the current language
-- falls back to english if the objID isnt available
function EID:getDescriptionObj(objTable, objID)
function EID:getDescriptionObj(objTable, Type, Variant, SubType)
objTable = objTable or "custom"
local tableEntry =
EID.descriptions[EIDConfig["Language"]][objTable][objID] or EID.descriptions["en_us"][objTable][objID] or {}
EID.descriptions[EIDConfig["Language"]][objTable][SubType] or EID.descriptions["en_us"][objTable][SubType] or {}
local description = {}
description.ID = objID
description.ObjectTable = objTable
description.ItemType = Type
description.ItemVariant = Variant
description.ID = SubType
description.Name = EID:getObjectName(objID, objTable) or objTable
description.Name = EID:getObjectName(SubType, objTable) or objTable
local legacyModdedDescription = EID:getLegacyModDescription(objTable, objID)
local legacyModdedDescription = EID:getLegacyModDescription(objTable, SubType)
description.Description = legacyModdedDescription or tableEntry[3] or "MISSING DESCRIPTION"
local itemString = EID:getIDVariantString(objTable)
if itemString ~= nil then
itemString = itemString.."."..objID
else
itemString = objID
end
description.fullItemString = itemString
description.Transformation = EID:getTransformation(itemString)
description.fullItemString = Type.."."..Variant.."."..SubType
description.Transformation = EID:getTransformation(description.fullItemString)
return description
end
@@ -410,8 +420,6 @@ function EID:renderInlineIcons(spriteTable, posX, posY)
local Xoffset = sprite[1][5] or -1
local Yoffset = sprite[1][6] or 0
local spriteObj = sprite[1][7] or EID.InlineIconSprite
spriteObj.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
spriteObj.Color = Color(1, 1, 1, EIDConfig["Transparency"], 0, 0, 0)
if sprite[1][2] >=0 then
spriteObj:SetFrame(sprite[1][1], sprite[1][2])
elseif not spriteObj:IsPlaying(sprite[1][1]) or spriteObj:IsFinished(sprite[1][1]) then
@@ -419,10 +427,17 @@ function EID:renderInlineIcons(spriteTable, posX, posY)
else
spriteObj:Update()
end
spriteObj:Render(Vector((posX + sprite[2] + Xoffset), posY + Yoffset), Vector(0, 0), Vector(0, 0))
EID:renderIcon(spriteObj, posX + sprite[2] + Xoffset, posY + Yoffset)
end
end
-- helper function to render Icons in specific EID settins
function EID:renderIcon(spriteObj, posX,posY)
spriteObj.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
spriteObj.Color = Color(1, 1, 1, EIDConfig["Transparency"], 0, 0, 0)
spriteObj:Render(Vector(posX, posY), Vector(0, 0), Vector(0, 0))
end
-- Returns the icon used for the bulletpoint. It will look at the first word in the given string.
function EID:handleBulletpointIcon(text)
local firstWord = string.match(text, "([^%s]+)")
+3
View File
@@ -52,6 +52,9 @@ EIDConfig = {
-- Toggle Display of the Item Type and Maximum Charges as an icon
-- Default = true
["ShowItemType"] = true,
-- Toggle Display of Collectible / Trinket Icon next to Itemname
-- Default = true
["ShowItemIcon"] = true,
-- Toggle Display of Collectible / Item descriptions
-- Default = true
["DisplayItemInfo"] = true,
+1 -1
View File
@@ -52,7 +52,7 @@ EID:addEntity(5, 10, 2, "Custom Name", "Custom description") -- Entity
------ Test: adding custom transformation icon ------
local dummySprite = Sprite()
dummySprite:Load("gfx/eid_inline_icons.anm2", true)
EID.InlineIcons["NewTransform1"] = {"hearts", 2, 9, 12, -1, 0,dummySprite}
EID:addIcon("NewTransform1", "hearts", 2, 9, 9, -1, 0, dummySprite)
-- the Transformation icon will try to get an icon with the same name as the transformation, but without any spaces. Default Icon otherwise
EID:createTransformation("NewTransform1", "New transformation") -- Transformation
EID:createTransformation("NewTransform1", "New russian transformation", "ru") -- add Transformation name in russian
+74 -36
View File
@@ -3,6 +3,8 @@ EID.itemConfig = Isaac.GetItemConfig()
EID.descriptions = {} -- Table that holds all translation strings
EID.isDisplayingText = false
EID.isDisplayingPermanent = false
EID.permanentDisplayTextObj = nil
EID.lastDescriptionEntity = nil
local lineHeight = 11
local hideDescToggle = false
@@ -60,6 +62,12 @@ if EIDConfig["Language"] == "en_us_detailed" and EIDConfig["Scale"] > 0.5 then
EIDConfig["Scale"] = 0.5
end
-- MOD CONFIG MENU Compatibility
local MCMLoaded, MCM = pcall(require, "scripts.modconfig")
EID.MCMCompat_isDisplayingEIDTab = false
local MCMCompat_isDisplayingDummyMCMObj = false
local MCMCompat_oldPermanentObj = false
---------------------------------------------------------------------------
-------------------------Handle Sacrifice Room-----------------------------
if EIDConfig["DisplaySacrificeInfo"] then
@@ -88,9 +96,27 @@ end
function EID:printDescription(desc)
local padding = posY()
local itemType = -1
if tonumber(desc.ID) ~= nil then
if tonumber(desc.ID) ~= nil and desc.ItemType == 5 and desc.ItemVariant == 100 then
itemType = EID.itemConfig:GetCollectible(tonumber(desc.ID)).Type or -1
end
local offsetX = 0
if EIDConfig["ShowItemIcon"] then
local iconType = nil
if desc.ItemType == 5 and desc.ItemVariant == 100 then
iconType = "Collectible"
elseif desc.ItemType == 5 and desc.ItemVariant == 350 then
iconType = "Trinket"
end
if iconType ~= nil then
offsetX = offsetX + 16
EID:renderString(
"{{" .. iconType .. desc.ID .. "}}",
Vector(EIDConfig["XPosition"], padding - 4),
Vector(EIDConfig["Scale"], EIDConfig["Scale"]),
EID:getNameColor()
)
end
end
--Display ItemType / Charge
if EIDConfig["ShowItemType"] and (itemType == 3 or itemType == 4) then
local offsetY = 2 * EIDConfig["Scale"]
@@ -98,13 +124,13 @@ function EID:printDescription(desc)
offsetY = -1
end
EID.IconSprite:Play(EID.ItemTypeAnm2Names[itemType])
EID.IconSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
EID.IconSprite:Update()
EID.IconSprite:Render(Vector(EIDConfig["XPosition"], padding + offsetY), Vector(0, 0), Vector(0, 0))
EID:renderIcon(EID.IconSprite, EIDConfig["XPosition"] + offsetX, padding + offsetY)
if itemType == 3 then -- Display Charge
EID.IconSprite:Play(EID.itemConfig:GetCollectible(desc.ID).MaxCharges)
EID.IconSprite:Update()
EID.IconSprite:Render(Vector(EIDConfig["XPosition"], padding + offsetY), Vector(0, 0), Vector(0, 0))
EID:renderIcon(EID.IconSprite, EIDConfig["XPosition"] + offsetX, padding + offsetY)
offsetX = offsetX + 11
elseif itemType == 4 then -- familiar
offsetX = offsetX + 8
end
if not EIDConfig["ShowItemName"] then
padding = padding + lineHeight * EIDConfig["Scale"]
@@ -112,17 +138,9 @@ function EID:printDescription(desc)
end
--Display Itemname
if EIDConfig["ShowItemName"] then
local offset = 0
if EIDConfig["ShowItemType"] then
if itemType == 3 then -- active item
offset = 11
elseif itemType == 4 then -- familiar
offset = 6
end
end
EID:renderString(
desc.Name,
Vector(EIDConfig["XPosition"] + offset, padding - 4),
Vector(EIDConfig["XPosition"] + offsetX, padding - 4),
Vector(EIDConfig["Scale"], EIDConfig["Scale"]),
EID:getNameColor()
)
@@ -144,12 +162,10 @@ function EID:printDescription(desc)
transformLineHeight = math.max(lineHeight, transformSprite[4])
local iconSprite = transformSprite[7] or EID.InlineIconSprite
iconSprite:Play(transformSprite[1])
iconSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
iconSprite.Color = Color(1, 1, 1, EIDConfig["Transparency"], 0, 0, 0)
iconSprite:Render(
Vector(EIDConfig["XPosition"] + iconOffsetX * EIDConfig["Scale"], padding + iconOffsetY * EIDConfig["Scale"]),
Vector(0, 0),
Vector(0, 0)
EID:renderIcon(
iconSprite,
EIDConfig["XPosition"] + iconOffsetX * EIDConfig["Scale"],
padding + iconOffsetY * EIDConfig["Scale"]
)
end
if EIDConfig["TransformationText"] then
@@ -199,13 +215,7 @@ end
function EID:renderQuestionMark()
EID.IconSprite:Play("CurseOfBlind")
EID.IconSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
EID.IconSprite:Update()
EID.IconSprite:Render(
Vector(EIDConfig["XPosition"] + 5 * EIDConfig["Scale"], posY() + 5 * EIDConfig["Scale"]),
Vector(0, 0),
Vector(0, 0)
)
EID:renderIcon(EID.IconSprite, EIDConfig["XPosition"] + 5 * EIDConfig["Scale"], posY() + 5 * EIDConfig["Scale"])
if Isaac.GetPlayer(0):HasCollectible(CollectibleType.COLLECTIBLE_SCHOOLBAG) then
modifiedPosY = EIDConfig["YPosition"] - 30
end
@@ -260,6 +270,34 @@ local function onRender(t)
return
end
if MCMLoaded then
if MCM.IsVisible and EID.permanentDisplayTextObj == nil and EID.MCMCompat_isDisplayingEIDTab then
MCMCompat_oldPermanentObj = EID.permanentDisplayTextObj
local demoDescObj = EID:getDescriptionObj("collectibles", 5, 100, 33)
demoDescObj.Name = "Demo Object Name"
demoDescObj.Transformation = "Demo Transformation"
demoDescObj.Description = "A very cool description as a demonstration of the power of EID!#\1 This is also a cool line#This line loves you {{Heart}}"
EID:displayPermanentText(demoDescObj)
MCMCompat_isDisplayingDummyMCMObj = true
elseif not MCM.IsVisible and MCMCompat_isDisplayingDummyMCMObj then
if MCMCompat_oldPermanentObj == nil then
EID:hidePermanentText()
else
EID.permanentDisplayTextObj = MCMCompat_oldPermanentObj
end
EID.MCMCompat_isDisplayingEIDTab = false
MCMCompat_oldPermanentObj = nil
MCMCompat_isDisplayingDummyMCMObj = false
end
end
if EID.isDisplayingPermanent and EID.permanentDisplayTextObj ~= nil then
print("Display")
EID:printDescription(EID.permanentDisplayTextObj)
EID.isDisplayingText = true
return
end
for i, entity in ipairs(Isaac.GetRoomEntities()) do
if Game():GetRoom():GetType() == RoomType.ROOM_DICE and entity.Type == 1000 and entity.Variant == 76 then
closestDice = entity
@@ -295,42 +333,42 @@ local function onRender(t)
--Handle Indicators
EID:renderIndicator(closest)
--
--Handle Entities (specific)
--[[ if EIDConfig["EnableEntityDescriptions"] and type(closest:GetData()["EID_Description"]) ~= type(nil) then
printTrinketDescription({closest.Type, closest:GetData()["EID_Description"]}, "custom")
return
end
]] --Handle Entities (omni)
]]
--Handle Entities (omni)
local objIDString = closest.Type .. "." .. closest.Variant .. "." .. closest.SubType
local tableEntry =
EID.descriptions[EIDConfig["Language"]]["custom"][objIDString] or EID.descriptions["en_us"]["custom"][objIDString] or
EID:getLegacyModDescription("custom", objIDString) or
nil
if EIDConfig["EnableEntityDescriptions"] and tableEntry ~= nil then
EID:printDescription(EID:getDescriptionObj("custom", objIDString))
EID:printDescription(EID:getDescriptionObj("custom", closest.Type, closest.Variant, closest.SubType))
return
end
--Handle Trinkets
if closest.Variant == PickupVariant.PICKUP_TRINKET then
--Handle Collectibles
EID:printDescription(EID:getDescriptionObj("trinkets", closest.SubType))
EID:printDescription(EID:getDescriptionObj("trinkets", closest.Type, closest.Variant, closest.SubType))
elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then
--Handle Cards & Runes
if EID:hasCurseBlind() and EIDConfig["DisableOnCurse"] then
EID:renderQuestionMark()
return
end
EID:printDescription(EID:getDescriptionObj("collectibles", closest.SubType))
EID:printDescription(EID:getDescriptionObj("collectibles", closest.Type, closest.Variant, closest.SubType))
elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then
--Handle Pills
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayCardInfoShop"] then
EID:renderQuestionMark()
return
end
EID:printDescription(EID:getDescriptionObj("cards", closest.SubType))
EID:printDescription(EID:getDescriptionObj("cards", closest.Type, closest.Variant, closest.SubType))
if closest.SubType <= 54 then
CardSprite:Play(tostring(closest.SubType))
CardSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
@@ -356,7 +394,7 @@ local function onRender(t)
local pillEffect = pool:GetPillEffect(pillColor)
local identified = pool:IsPillIdentified(pillColor)
if (identified or EIDConfig["ShowUnidentifiedPillDescriptions"]) then
EID:printDescription(EID:getDescriptionObj("pills", pillEffect + 1))
EID:printDescription(EID:getDescriptionObj("pills", closest.Type, closest.Variant, pillEffect + 1))
else
EID:renderString(
EID:getDescriptionTable("unidentifiedPill"),
@@ -386,7 +424,7 @@ end
EID:AddCallback(ModCallbacks.MC_POST_RENDER, onRender)
if ModConfigMenu then
if MCMLoaded then
local json = require("json")
--------------------------------
--------Handle Savadata---------
+21
View File
@@ -267,6 +267,7 @@ if ModConfigMenu then
Minimum = 1,
Maximum = 6,
Display = function()
EID.MCMCompat_isDisplayingEIDTab = true;
return "Text Size: " .. EIDConfig["Scale"]
end,
OnChange = function(currentNum)
@@ -397,4 +398,24 @@ if ModConfigMenu then
end
}
)
ModConfigMenu.AddSetting(
"EID",
"Display",
{
Type = ModConfigMenuOptionType.BOOLEAN,
CurrentSetting = function()
return EIDConfig["ShowItemIcon"]
end,
Display = function()
local onOff = "False"
if EIDConfig["ShowItemIcon"] then
onOff = "True"
end
return "Display Item Icon: " .. onOff
end,
OnChange = function(currentBool)
EIDConfig["ShowItemIcon"] = currentBool
end
}
)
end