Improved inline sprite rendering and improved code readability
This commit is contained in:
1 parent
07d53c5a6d
commit
64cd3ecd4f
2 files changed
+55
-55
No files matched your search
+48
-15
@@ -98,8 +98,20 @@ function EID:getLastDescribedEntity()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- returns descriptions from the legacy mod descriptions
|
-- returns descriptions from the legacy mod descriptions
|
||||||
function EID:getModDescription(list, id)
|
function EID:getLegacyModDescription(objTable, id)
|
||||||
return (list) and (list[id])
|
if objTable == "collectibles" then
|
||||||
|
return (__eidItemDescriptions) and (__eidItemDescriptions[id])
|
||||||
|
elseif objTable == "trinkets" then
|
||||||
|
return (__eidTrinketDescriptions) and (__eidTrinketDescriptions[id])
|
||||||
|
elseif objTable == "cards" then
|
||||||
|
return (__eidCardDescriptions) and (__eidCardDescriptions[id])
|
||||||
|
elseif objTable == "pills" then
|
||||||
|
return (__eidPillDescriptions) and (__eidPillDescriptions[id])
|
||||||
|
elseif objTable == "transformation" then
|
||||||
|
return (__eidItemTransformations) and (__eidItemTransformations[id])
|
||||||
|
elseif objTable == "custom" then
|
||||||
|
return (__eidEntityDescriptions) and (__eidEntityDescriptions[id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns the specified object table in the current language.
|
-- returns the specified object table in the current language.
|
||||||
@@ -112,11 +124,20 @@ end
|
|||||||
-- falls back to english if the objID isnt available
|
-- falls back to english if the objID isnt available
|
||||||
function EID:getDescriptionObj(objTable, objID)
|
function EID:getDescriptionObj(objTable, objID)
|
||||||
local tableEntry = EID.descriptions[EIDConfig["Language"]][objTable][tonumber(objID)] or EID.descriptions["en_us"][objTable][tonumber(objID)]
|
local tableEntry = EID.descriptions[EIDConfig["Language"]][objTable][tonumber(objID)] or EID.descriptions["en_us"][objTable][tonumber(objID)]
|
||||||
|
|
||||||
local description = {}
|
local description = {}
|
||||||
description.ID = tonumber(tableEntry[1]) or objID
|
description.ID = tonumber(tableEntry[1]) or objID
|
||||||
description.Name = EID:getObjectName(objID, objTable) or objTable
|
description.Name = EID:getObjectName(objID, objTable) or objTable
|
||||||
description.Description = tableEntry[4] or tableEntry[3] or ""
|
|
||||||
description.Transformation = tableEntry[2] or "0"
|
local legacyModdedDescription = EID:getLegacyModDescription(objTable, objID)
|
||||||
|
description.Description = legacyModdedDescription or tableEntry[4] or tableEntry[3] or tableEntry[2] or "MISSING DESCRIPTION"
|
||||||
|
|
||||||
|
local legacyModdedTransformation = nil
|
||||||
|
if objTable == "collectibles" then
|
||||||
|
legacyModdedTransformation = EID:getLegacyModDescription("transformation", objID)
|
||||||
|
end
|
||||||
|
description.Transformation = legacyModdedTransformation or tableEntry[2] or "0"
|
||||||
|
|
||||||
return description
|
return description
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -210,24 +231,35 @@ function EID:getStrWidth(str)
|
|||||||
return EID.font:GetStringWidthUTF8(str)
|
return EID.font:GetStringWidthUTF8(str)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Searches true the given string and replaces Iconplaceholders with icons.
|
-- Searches thru the given string and replaces Iconplaceholders with icons.
|
||||||
-- Returns the string without the placeholders but with an accurate space between lines.
|
-- Returns 2 values. the string without the placeholders but with an accurate space between lines. and a table of all Inline Sprites
|
||||||
function EID:filterMarkup(text, textPosX, textPosY)
|
function EID:filterMarkup(text, textPosX, textPosY)
|
||||||
|
local spriteTable = {}
|
||||||
for word in string.gmatch(text, "{{.-}}") do
|
for word in string.gmatch(text, "{{.-}}") do
|
||||||
local textposition = string.find(text, word)
|
local textposition = string.find(text, word)
|
||||||
local lookup = EID:getIcon(word) or EID.InlineIcons["ERROR"]
|
local lookup = EID:getIcon(word) or EID.InlineIcons["ERROR"]
|
||||||
local Xoffset = lookup[5] or 0
|
local preceedingTextWidth = EID:getStrWidth(string.sub(text, 0, textposition - 1))*EIDConfig["Scale"]
|
||||||
local prefixTextWidth = EID:getStrWidth(string.sub(text, 0, textposition - 1))*EIDConfig["Scale"]
|
table.insert(spriteTable,{lookup, preceedingTextWidth})
|
||||||
EID.InlineIconSprite:SetFrame(lookup[1], lookup[2])
|
text = string.gsub(text, word, EID:generatePlaceholderString(lookup[3]), 1)
|
||||||
EID.InlineIconSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
|
end
|
||||||
EID.InlineIconSprite:Render(
|
return text, spriteTable
|
||||||
Vector((textPosX + prefixTextWidth + Xoffset -1), textPosY),
|
end
|
||||||
|
|
||||||
|
--renders a list of given inline sprite objects returned by the "EID:filterMarkup()" function
|
||||||
|
-- Table entry format: {EID.InlineIcons Object, Width of text preceeding the icon}
|
||||||
|
function EID:renderInlineIcons(spriteTable, posX, posY)
|
||||||
|
for _,sprite in ipairs(spriteTable) do
|
||||||
|
local Xoffset = sprite[1][5] or -1
|
||||||
|
local Yoffset = sprite[1][6] or 0
|
||||||
|
local spriteObj = sprite[1][7] or EID.InlineIconSprite
|
||||||
|
spriteObj:SetFrame(sprite[1][1], sprite[1][2])
|
||||||
|
spriteObj.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
|
||||||
|
spriteObj:Render(
|
||||||
|
Vector((posX + sprite[2] + Xoffset), posY + Yoffset),
|
||||||
Vector(0, 0),
|
Vector(0, 0),
|
||||||
Vector(0, 0)
|
Vector(0, 0)
|
||||||
)
|
)
|
||||||
text = string.gsub(text, word, EID:generatePlaceholderString(lookup[3]), 1)
|
|
||||||
end
|
end
|
||||||
return text
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns the icon used for the bulletpoint. It will look at the first word in the given string.
|
-- Returns the icon used for the bulletpoint. It will look at the first word in the given string.
|
||||||
@@ -243,7 +275,8 @@ end
|
|||||||
-- args: string, Vector(int, int), Vector(float,float), KColor obj, bool
|
-- args: string, Vector(int, int), Vector(float,float), KColor obj, bool
|
||||||
function EID:renderString(str, position, scale, kcolor)
|
function EID:renderString(str, position, scale, kcolor)
|
||||||
str = EID:replaceShortMarkupStrings(str)
|
str = EID:replaceShortMarkupStrings(str)
|
||||||
str = EID:filterMarkup(str, position.X, position.Y)
|
str, spriteTable = EID:filterMarkup(str, position.X, position.Y)
|
||||||
|
EID:renderInlineIcons(spriteTable, position.X, position.Y)
|
||||||
EID.font:DrawStringScaledUTF8(str, position.X, position.Y, scale.X, scale.Y, kcolor, 0, false)
|
EID.font:DrawStringScaledUTF8(str, position.X, position.Y, scale.X, scale.Y, kcolor, 0, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ function printDescription(desc)
|
|||||||
printBulletPoints(desc.Description, padding)
|
printBulletPoints(desc.Description, padding)
|
||||||
end
|
end
|
||||||
|
|
||||||
function printTrinketDescription(desc, objType)
|
function printTrinketDescription(desc)
|
||||||
local padding = posY()
|
local padding = posY()
|
||||||
--Display Itemname
|
--Display Itemname
|
||||||
if EIDConfig["ShowItemName"] then
|
if EIDConfig["ShowItemName"] then
|
||||||
@@ -354,54 +354,22 @@ local function onRender(t)
|
|||||||
|
|
||||||
--Handle Trinkets
|
--Handle Trinkets
|
||||||
if closest.Variant == PickupVariant.PICKUP_TRINKET then
|
if closest.Variant == PickupVariant.PICKUP_TRINKET then
|
||||||
|
printTrinketDescription(EID:getDescriptionObj("trinkets",closest.SubType))
|
||||||
--Handle Collectibles
|
--Handle Collectibles
|
||||||
if EID:getModDescription(__eidTrinketDescriptions, closest.SubType) then
|
|
||||||
printTrinketDescription(
|
|
||||||
{closest.SubType, EID:getModDescription(__eidTrinketDescriptions, closest.SubType)},
|
|
||||||
"trinkets"
|
|
||||||
)
|
|
||||||
elseif closest.SubType <= 128 then
|
|
||||||
printTrinketDescription(EID:getDescriptionObj("trinkets",closest.SubType), "trinkets")
|
|
||||||
else
|
|
||||||
printTrinketDescription({closest.SubType, EID.itemConfig:GetTrinket(closest.SubType).Description})
|
|
||||||
end
|
|
||||||
elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then
|
elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then
|
||||||
--Handle Cards & Runes
|
|
||||||
if EID:hasCurseBlind() and EIDConfig["DisableOnCurse"] then
|
if EID:hasCurseBlind() and EIDConfig["DisableOnCurse"] then
|
||||||
renderQuestionMark()
|
renderQuestionMark()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if EID:getModDescription(__eidItemDescriptions, closest.SubType) then
|
printDescription(EID:getDescriptionObj("collectibles",closest.SubType))
|
||||||
local tranformation = "0"
|
--Handle Cards & Runes
|
||||||
if EID:getModDescription(__eidItemTransformations, closest.SubType) then
|
|
||||||
tranformation = EID:getModDescription(__eidItemTransformations, closest.SubType)
|
|
||||||
end
|
|
||||||
printDescription({closest.SubType, tranformation, EID:getModDescription(__eidItemDescriptions, closest.SubType)})
|
|
||||||
elseif closest.SubType <= 552 then
|
|
||||||
if EID:getModDescription(__eidItemTransformations, closest.SubType) then
|
|
||||||
printDescription(
|
|
||||||
{
|
|
||||||
closest.SubType,
|
|
||||||
EID:getModDescription(__eidItemTransformations, closest.SubType),
|
|
||||||
EID:getDescriptionObj("collectibles",closest.SubType)[3]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else
|
|
||||||
printDescription(EID:getDescriptionObj("collectibles",closest.SubType))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
printDescription({closest.SubType, "", EID.itemConfig:GetCollectible(closest.SubType).Description})
|
|
||||||
end
|
|
||||||
elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then
|
elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then
|
||||||
--Handle Pills
|
|
||||||
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayCardInfoShop"] then
|
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayCardInfoShop"] then
|
||||||
renderQuestionMark()
|
renderQuestionMark()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if EID:getModDescription(__eidCardDescriptions, closest.SubType) then
|
printTrinketDescription(EID:getDescriptionObj("cards", closest.SubType), "cards")
|
||||||
printTrinketDescription({closest.SubType, EID:getModDescription(__eidCardDescriptions, closest.SubType)}, "cards")
|
if closest.SubType <= 54 then
|
||||||
elseif closest.SubType <= 54 then
|
|
||||||
printTrinketDescription(EID:getDescriptionObj("cards", closest.SubType), "cards")
|
|
||||||
CardSprite:Play(tostring(closest.SubType))
|
CardSprite:Play(tostring(closest.SubType))
|
||||||
CardSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
|
CardSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
|
||||||
CardSprite:Update()
|
CardSprite:Update()
|
||||||
@@ -414,9 +382,8 @@ local function onRender(t)
|
|||||||
Vector(0, 0),
|
Vector(0, 0),
|
||||||
Vector(0, 0)
|
Vector(0, 0)
|
||||||
)
|
)
|
||||||
else
|
|
||||||
printTrinketDescription({closest.SubType, EID.itemConfig:GetCard(closest.SubType).Description})
|
|
||||||
end
|
end
|
||||||
|
--Handle Pills
|
||||||
elseif closest.Variant == PickupVariant.PICKUP_PILL then
|
elseif closest.Variant == PickupVariant.PICKUP_PILL then
|
||||||
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayPillInfoShop"] then
|
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayPillInfoShop"] then
|
||||||
renderQuestionMark()
|
renderQuestionMark()
|
||||||
|
|||||||
Reference in new issue
Block a user