Better description caching
This commit is contained in:
1 parent
5d5fa2a475
commit
39df13d62c
1 file changed
+52
-48
@@ -389,6 +389,7 @@ local function handleScaleKey()
|
|||||||
-- press and hold ScaleKey
|
-- press and hold ScaleKey
|
||||||
if Input.IsButtonPressed(ScaleKey, 0) then
|
if Input.IsButtonPressed(ScaleKey, 0) then
|
||||||
if scaleHoldFrame > 60 then
|
if scaleHoldFrame > 60 then
|
||||||
|
EID.MCM_OptionChanged = true
|
||||||
local scaleConfigName = (EID.Config["DisplayMode"] == "local" and "LocalScale" or "Scale")
|
local scaleConfigName = (EID.Config["DisplayMode"] == "local" and "LocalScale" or "Scale")
|
||||||
if scaleToBigger then
|
if scaleToBigger then
|
||||||
local newScale = EID.Scale + scaleSpeed
|
local newScale = EID.Scale + scaleSpeed
|
||||||
@@ -415,6 +416,7 @@ local function handleScaleKey()
|
|||||||
end
|
end
|
||||||
-- press ScaleKey
|
-- press ScaleKey
|
||||||
if Input.IsButtonTriggered(ScaleKey, 0) then
|
if Input.IsButtonTriggered(ScaleKey, 0) then
|
||||||
|
EID.MCM_OptionChanged = true
|
||||||
scaleHoldFrame = 0
|
scaleHoldFrame = 0
|
||||||
local scale
|
local scale
|
||||||
local scaleConfigName = (EID.Config["DisplayMode"] == "local" and "LocalScale" or "Scale")
|
local scaleConfigName = (EID.Config["DisplayMode"] == "local" and "LocalScale" or "Scale")
|
||||||
@@ -441,13 +443,37 @@ end
|
|||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
---------------------------Printing Functions------------------------------
|
---------------------------Printing Functions------------------------------
|
||||||
|
|
||||||
local previousFormattedLines = {}
|
|
||||||
local previousBulletpoints = {}
|
|
||||||
local previousDesc = ""
|
local previousDesc = ""
|
||||||
|
local previousRenderPos = Vector.Zero
|
||||||
|
EID.CachingDescription = false
|
||||||
|
EID.CachedIcons = {}
|
||||||
|
EID.CachedStrings = {}
|
||||||
|
|
||||||
function EID:printDescription(desc)
|
function EID:printDescription(desc)
|
||||||
local textScale = Vector(EID.Scale, EID.Scale)
|
|
||||||
local renderPos = EID:getTextPosition()
|
local renderPos = EID:getTextPosition()
|
||||||
|
|
||||||
|
EID.CachingDescription = false
|
||||||
|
if previousDesc == desc.Description and not EID.OptionChanged and not EID.MCM_OptionChanged then
|
||||||
|
local localModeDiff = renderPos - previousRenderPos
|
||||||
|
-- Drawing our currently saved description
|
||||||
|
for _,icon in ipairs(EID.CachedIcons) do
|
||||||
|
icon[1]:SetFrame(icon[5], icon[6])
|
||||||
|
EID:renderIcon(icon[1], icon[2] + localModeDiff.X, icon[3] + localModeDiff.Y, icon[4])
|
||||||
|
end
|
||||||
|
for i,str in ipairs(EID.CachedStrings) do
|
||||||
|
EID.font:DrawStringScaledUTF8(str[1], str[2] + localModeDiff.X, str[3] + localModeDiff.Y, EID.Scale, EID.Scale, str[4], 0, false)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
else
|
||||||
|
-- Drawing a new description
|
||||||
|
EID.CachingDescription = true
|
||||||
|
EID.CachedIcons = {}
|
||||||
|
EID.CachedStrings = {}
|
||||||
|
previousDesc = desc.Description
|
||||||
|
previousRenderPos = Vector(renderPos.X, renderPos.Y)
|
||||||
|
end
|
||||||
|
|
||||||
|
local textScale = Vector(EID.Scale, EID.Scale)
|
||||||
local offsetX = 0
|
local offsetX = 0
|
||||||
EID.lineHeight = EID.Config["LineHeight"]
|
EID.lineHeight = EID.Config["LineHeight"]
|
||||||
if EID.Config["ShowItemIcon"] then
|
if EID.Config["ShowItemIcon"] then
|
||||||
@@ -484,9 +510,6 @@ function EID:printDescription(desc)
|
|||||||
end
|
end
|
||||||
if EID.Config["ShowItemType"] and (itemType == 3 or itemType == 4) then
|
if EID.Config["ShowItemType"] and (itemType == 3 or itemType == 4) then
|
||||||
local offsetY = 2
|
local offsetY = 2
|
||||||
if EID.Scale < 1 then
|
|
||||||
offsetY = -1
|
|
||||||
end
|
|
||||||
EID.IconSprite:Play(EID.ItemTypeAnm2Names[itemType])
|
EID.IconSprite:Play(EID.ItemTypeAnm2Names[itemType])
|
||||||
EID:renderIcon(EID.IconSprite, renderPos.X + offsetX * EID.Scale, renderPos.Y + offsetY * EID.Scale)
|
EID:renderIcon(EID.IconSprite, renderPos.X + offsetX * EID.Scale, renderPos.Y + offsetY * EID.Scale)
|
||||||
if itemType == 3 then
|
if itemType == 3 then
|
||||||
@@ -502,14 +525,8 @@ function EID:printDescription(desc)
|
|||||||
EID.InlineIconSprite2:SetFrame("numbers", curItemConfig.MaxCharges)
|
EID.InlineIconSprite2:SetFrame("numbers", curItemConfig.MaxCharges)
|
||||||
end
|
end
|
||||||
EID:renderIcon(EID.InlineIconSprite2, renderPos.X + offsetX * EID.Scale, renderPos.Y + offsetY * EID.Scale)
|
EID:renderIcon(EID.InlineIconSprite2, renderPos.X + offsetX * EID.Scale, renderPos.Y + offsetY * EID.Scale)
|
||||||
offsetX = offsetX + 8
|
|
||||||
elseif itemType == 4 then
|
|
||||||
-- familiar
|
|
||||||
offsetX = offsetX + 8
|
|
||||||
end
|
|
||||||
if not EID.Config["ShowItemName"] then
|
|
||||||
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
|
|
||||||
end
|
end
|
||||||
|
offsetX = offsetX + 8
|
||||||
end
|
end
|
||||||
--Display Itemname
|
--Display Itemname
|
||||||
if EID.Config["ShowItemName"] then
|
if EID.Config["ShowItemName"] then
|
||||||
@@ -534,7 +551,7 @@ function EID:printDescription(desc)
|
|||||||
local quality = tonumber(EID.itemConfig:GetCollectible(tonumber(desc.ObjSubType)).Quality)
|
local quality = tonumber(EID.itemConfig:GetCollectible(tonumber(desc.ObjSubType)).Quality)
|
||||||
curName = curName.." - {{Quality"..quality.."}}"
|
curName = curName.." - {{Quality"..quality.."}}"
|
||||||
end
|
end
|
||||||
|
-- Display the mod this item is from
|
||||||
if desc.ModName then
|
if desc.ModName then
|
||||||
if EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Name only" then
|
if EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Name only" then
|
||||||
curName = curName .. " {{"..EID.Config["ModIndicatorTextColor"].."}}" .. EID.ModIndicator[desc.ModName].Name
|
curName = curName .. " {{"..EID.Config["ModIndicatorTextColor"].."}}" .. EID.ModIndicator[desc.ModName].Name
|
||||||
@@ -550,10 +567,10 @@ function EID:printDescription(desc)
|
|||||||
textScale,
|
textScale,
|
||||||
EID:getNameColor()
|
EID:getNameColor()
|
||||||
)
|
)
|
||||||
|
|
||||||
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
|
||||||
|
|
||||||
--Display Transformation
|
--Display Transformation
|
||||||
if not (desc.Transformation == "0" or desc.Transformation == "" or desc.Transformation == nil) then
|
if not (desc.Transformation == "0" or desc.Transformation == "" or desc.Transformation == nil) then
|
||||||
for transform in string.gmatch(desc.Transformation, "([^,]+)") do
|
for transform in string.gmatch(desc.Transformation, "([^,]+)") do
|
||||||
@@ -580,48 +597,32 @@ function EID:printDescription(desc)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if previousDesc ~= desc.Description then
|
|
||||||
EID:clearDescriptionCache()
|
|
||||||
previousDesc = desc.Description
|
|
||||||
end
|
|
||||||
EID:printBulletPoints(desc.Description, renderPos)
|
EID:printBulletPoints(desc.Description, renderPos)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EID:clearDescriptionCache()
|
|
||||||
previousFormattedLines = {}
|
|
||||||
previousBulletpoints = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
function EID:printBulletPoints(description, renderPos)
|
function EID:printBulletPoints(description, renderPos)
|
||||||
local textboxWidth = tonumber(EID.Config["TextboxWidth"])
|
local textboxWidth = tonumber(EID.Config["TextboxWidth"])
|
||||||
local textScale = Vector(EID.Scale, EID.Scale)
|
local textScale = Vector(EID.Scale, EID.Scale)
|
||||||
description = EID:replaceShortMarkupStrings(description)
|
description = EID:replaceShortMarkupStrings(description)
|
||||||
if #previousFormattedLines == 0 then
|
for line in string.gmatch(description, "([^#]+)") do
|
||||||
for line in string.gmatch(description, "([^#]+)") do
|
local formatedLines = EID:fitTextToWidth(line, textboxWidth, EID.BreakUtf8CharsLanguage[EID.Config["Language"]])
|
||||||
previousBulletpoints[#previousFormattedLines+1] = true
|
local textColor = EID:getTextColor()
|
||||||
for _,v in ipairs(EID:fitTextToWidth(line, textboxWidth, EID.BreakUtf8CharsLanguage[EID.Config["Language"]])) do
|
for i, lineToPrint in ipairs(formatedLines) do
|
||||||
table.insert(previousFormattedLines, v)
|
-- render bulletpoint
|
||||||
|
if i == 1 then
|
||||||
|
local bpIcon = EID:handleBulletpointIcon(lineToPrint)
|
||||||
|
if EID:getIcon(bpIcon) ~= EID.InlineIcons["ERROR"] then
|
||||||
|
lineToPrint = string.gsub(lineToPrint, bpIcon .. " ", "", 1)
|
||||||
|
textColor = EID:renderString(bpIcon, renderPos + Vector(-3 * EID.Scale, 0), textScale , textColor)
|
||||||
|
else
|
||||||
|
textColor = EID:renderString(bpIcon, renderPos, textScale , textColor)
|
||||||
|
end
|
||||||
|
EID.LastRenderCallColor = EID:copyKColor(textColor) -- Save line start Color for eventual Color Reset call
|
||||||
end
|
end
|
||||||
|
textColor = EID:renderString(lineToPrint, renderPos + Vector(12 * EID.Scale, 0), textScale, textColor)
|
||||||
|
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local textColor = EID:getTextColor()
|
|
||||||
for i, lineToPrint in ipairs(previousFormattedLines) do
|
|
||||||
-- render bulletpoint
|
|
||||||
if previousBulletpoints[i] then
|
|
||||||
textColor = EID:getTextColor()
|
|
||||||
local bpIcon = EID:handleBulletpointIcon(lineToPrint)
|
|
||||||
if EID:getIcon(bpIcon) ~= EID.InlineIcons["ERROR"] then
|
|
||||||
lineToPrint = string.gsub(lineToPrint, bpIcon .. " ", "", 1)
|
|
||||||
textColor = EID:renderString(bpIcon, renderPos + Vector(-3 * EID.Scale, 0), textScale , textColor)
|
|
||||||
else
|
|
||||||
textColor = EID:renderString(bpIcon, renderPos, textScale , textColor)
|
|
||||||
end
|
|
||||||
EID.LastRenderCallColor = EID:copyKColor(textColor) -- Save line start Color for eventual Color Reset call
|
|
||||||
end
|
|
||||||
textColor = EID:renderString(lineToPrint, renderPos + Vector(12 * EID.Scale, 0), textScale, textColor)
|
|
||||||
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
----------------------------Handle New Room--------------------------------
|
----------------------------Handle New Room--------------------------------
|
||||||
@@ -940,10 +941,13 @@ local searchPartitions = EntityPartition.FAMILIAR + EntityPartition.ENEMY + Enti
|
|||||||
|
|
||||||
EID.lastDescriptionEntity = nil
|
EID.lastDescriptionEntity = nil
|
||||||
EID.lastDist = 0
|
EID.lastDist = 0
|
||||||
|
EID.OptionChanged = false
|
||||||
|
|
||||||
local function onRender(t)
|
local function onRender(t)
|
||||||
-- Increases by 60 per second, ignores pauses
|
-- Increases by 60 per second, ignores pauses
|
||||||
EID.GameRenderCount = EID.GameRenderCount + 1
|
EID.GameRenderCount = EID.GameRenderCount + 1
|
||||||
|
EID.OptionChanged = EID.MCM_OptionChanged
|
||||||
|
EID.MCM_OptionChanged = false
|
||||||
EID:resumeCoroutines()
|
EID:resumeCoroutines()
|
||||||
|
|
||||||
EID.isDisplaying = false
|
EID.isDisplaying = false
|
||||||
|
|||||||
Reference in new issue
Block a user