Merge pull request #360 from Buurazu/master

Cache previous description (with animated text color / icon support)
This commit is contained in:
wofsauge authored and GitHub committed 2022-02-01 13:14:13 +01:00
commit 44fe0cdad5
3 files changed
+82 -69

No files matched your search

+15 -9
View File
@@ -653,23 +653,23 @@ function EID:renderInlineIcons(spriteTable, posX, posY)
spriteObj:Update()
end
EID:renderIcon(spriteObj, posX + sprite[2] + Xoffset * EID.Scale, posY + Yoffset * EID.Scale, sprite[3])
EID:renderIcon(spriteObj, posX + sprite[2] + Xoffset * EID.Scale, posY + Yoffset * EID.Scale, sprite[3], sprite[1][1], sprite[1][2])
end
end
-- helper function to render Icons in specific EID settins
function EID:renderIcon(spriteObj, posX, posY, callback)
function EID:renderIcon(spriteObj, posX, posY, callback, animName, animFrame)
spriteObj.Scale = Vector(EID.Scale, EID.Scale)
spriteObj.Color = Color(1, 1, 1, EID.Config["Transparency"], 0, 0, 0)
if callback then
callback(spriteObj)
end
spriteObj:Render(Vector(posX, posY), nullVector, nullVector)
if EID.CachingDescription then
table.insert(EID.CachedIcons, {spriteObj, posX, posY, callback, spriteObj:GetAnimation(), spriteObj:GetFrame()})
table.insert(EID.CachedIcons, {spriteObj, posX, posY, callback, animName or spriteObj:GetAnimation(), animFrame or spriteObj:GetFrame()})
end
spriteObj:Render(Vector(posX, posY), nullVector, nullVector)
end
-- Returns the icon used for the bulletpoint. It will look at the first word in the given string.
@@ -683,6 +683,7 @@ end
-- Gets a KColor from a Markup-string (example Input: "{{ColorText}}")
-- Returns the KColor object and a boolean value indicating if the given string was a color markup or not
local colorFunc = nil
function EID:getColor(str, baseKColor)
local color = baseKColor
local isColorMarkup = false
@@ -690,8 +691,10 @@ function EID:getColor(str, baseKColor)
local strTrimmed = string.gsub(str,"{{(.-)}}",function(a) return a end, 1)
if #strTrimmed <= #str then
if type(EID.InlineColors[strTrimmed]) == "function" then
colorFunc = EID.InlineColors[strTrimmed]
color = EID.InlineColors[strTrimmed](color)
else
if EID.InlineColors[strTrimmed] then colorFunc = nil end
color = EID.InlineColors[strTrimmed] or color
end
isColorMarkup = type(EID.InlineColors[strTrimmed]) ~= type(nil)
@@ -699,6 +702,7 @@ function EID:getColor(str, baseKColor)
end
color = EID:copyKColor(color)
color.Alpha = math.min(color.Alpha, EID.Config["Transparency"])
return color, isColorMarkup
end
@@ -707,6 +711,7 @@ end
function EID:filterColorMarkup(text, baseKColor)
local textPartsTable = {}
local lastColor = baseKColor
local lastFunc = colorFunc
local lastPosition = 0
for word in string.gmatch(text, "{{.-}}") do
local textposition = string.find(text, word)
@@ -715,13 +720,14 @@ function EID:filterColorMarkup(text, baseKColor)
local preceedingText = string.sub(text, lastPosition, textposition - 1)
local preceedingTextWidth = EID:getStrWidth(preceedingText) * EID.Scale
lastPosition = textposition
table.insert(textPartsTable, {preceedingText, lastColor, preceedingTextWidth})
table.insert(textPartsTable, {preceedingText, lastColor, preceedingTextWidth, lastFunc})
lastColor = lookup
lastFunc = colorFunc
text = string.gsub(text, word, "", 1)
end
end
table.insert(textPartsTable, {string.sub(text, lastPosition), lastColor, 0})
table.insert(textPartsTable, {string.sub(text, lastPosition), lastColor, 0, lastFunc})
return textPartsTable
end
@@ -839,7 +845,7 @@ function EID:renderString(str, position, scale, kcolor)
EID:renderInlineIcons(spriteTable, position.X + offsetX, position.Y)
EID.font:DrawStringScaledUTF8(strFiltered, position.X + offsetX, position.Y, scale.X, scale.Y, textPart[2], 0, false)
if EID.CachingDescription then
table.insert(EID.CachedStrings, {strFiltered, position.X + offsetX, position.Y, textPart[2]})
table.insert(EID.CachedStrings, {strFiltered, position.X + offsetX, position.Y, textPart[2], textPart[4], EID.Config["Transparency"]})
end
offsetX = offsetX + EID:getStrWidth(strFiltered) * scale.X
end
@@ -1278,4 +1284,4 @@ function EID:checkPlayersForMissingItems()
EID.SaveGame[EID.Config["SaveGameNumber"]].ItemNeedsPickup[player.QueuedItem.Item.ID] = nil
end
end
end
end
+66 -50
View File
@@ -391,6 +391,7 @@ local function handleScaleKey()
-- press and hold ScaleKey
if Input.IsButtonPressed(ScaleKey, 0) then
if scaleHoldFrame > 60 then
EID.MCM_OptionChanged = true
local scaleConfigName = (EID.Config["DisplayMode"] == "local" and "LocalScale" or "Scale")
if scaleToBigger then
local newScale = EID.Scale + scaleSpeed
@@ -417,6 +418,7 @@ local function handleScaleKey()
end
-- press ScaleKey
if Input.IsButtonTriggered(ScaleKey, 0) then
EID.MCM_OptionChanged = true
scaleHoldFrame = 0
local scale
local scaleConfigName = (EID.Config["DisplayMode"] == "local" and "LocalScale" or "Scale")
@@ -443,13 +445,50 @@ end
---------------------------------------------------------------------------
---------------------------Printing Functions------------------------------
local previousFormattedLines = {}
local previousBulletpoints = {}
local previousDesc = ""
local previousRenderPos = Vector.Zero
EID.CachingDescription = false
EID.CachedIcons = {}
EID.CachedStrings = {}
function EID:printDescription(desc)
local textScale = Vector(EID.Scale, EID.Scale)
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
-- set inline icon to specific frame
if icon[6] >= 0 then
icon[1]:SetFrame(icon[5], icon[6])
-- frame of -1 = it's an animation, let it play
elseif not icon[1]:IsPlaying(icon[5]) or icon[1]:IsFinished(icon[5]) then
icon[1]:Play(icon[5],true)
else
icon[1]:Update()
end
EID:renderIcon(icon[1], icon[2] + localModeDiff.X, icon[3] + localModeDiff.Y, icon[4])
end
for i,str in ipairs(EID.CachedStrings) do
-- check for func (Rainbow, Blink, Fade), reset the color's Alpha to EID.Config["Transparency"] if func
if str[5] then
str[4].Alpha = str[6]
str[4] = str[5](str[4])
end
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
EID.lineHeight = EID.Config["LineHeight"]
if EID.Config["ShowItemIcon"] then
@@ -486,9 +525,6 @@ function EID:printDescription(desc)
end
if EID.Config["ShowItemType"] and (itemType == 3 or itemType == 4) then
local offsetY = 2
if EID.Scale < 1 then
offsetY = -1
end
EID.IconSprite:Play(EID.ItemTypeAnm2Names[itemType])
EID:renderIcon(EID.IconSprite, renderPos.X + offsetX * EID.Scale, renderPos.Y + offsetY * EID.Scale)
if itemType == 3 then
@@ -504,14 +540,8 @@ function EID:printDescription(desc)
EID.InlineIconSprite2:SetFrame("numbers", curItemConfig.MaxCharges)
end
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
offsetX = offsetX + 8
end
--Display Itemname
if EID.Config["ShowItemName"] then
@@ -536,7 +566,7 @@ function EID:printDescription(desc)
local quality = tonumber(EID.itemConfig:GetCollectible(tonumber(desc.ObjSubType)).Quality)
curName = curName.." - {{Quality"..quality.."}}"
end
-- Display the mod this item is from
if desc.ModName then
if EID.Config["ModIndicatorDisplay"] == "Both" or EID.Config["ModIndicatorDisplay"] == "Name only" then
curName = curName .. " {{"..EID.Config["ModIndicatorTextColor"].."}}" .. EID.ModIndicator[desc.ModName].Name
@@ -552,10 +582,10 @@ function EID:printDescription(desc)
textScale,
EID:getNameColor()
)
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
end
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
--Display Transformation
if not (desc.Transformation == "0" or desc.Transformation == "" or desc.Transformation == nil) then
for transform in string.gmatch(desc.Transformation, "([^,]+)") do
@@ -582,48 +612,32 @@ function EID:printDescription(desc)
end
end
end
if previousDesc ~= desc.Description then
EID:clearDescriptionCache()
previousDesc = desc.Description
end
EID:printBulletPoints(desc.Description, renderPos)
end
function EID:clearDescriptionCache()
previousFormattedLines = {}
previousBulletpoints = {}
end
function EID:printBulletPoints(description, renderPos)
local textboxWidth = tonumber(EID.Config["TextboxWidth"])
local textScale = Vector(EID.Scale, EID.Scale)
description = EID:replaceShortMarkupStrings(description)
if #previousFormattedLines == 0 then
for line in string.gmatch(description, "([^#]+)") do
previousBulletpoints[#previousFormattedLines+1] = true
for _,v in ipairs(EID:fitTextToWidth(line, textboxWidth, EID.BreakUtf8CharsLanguage[EID.Config["Language"]])) do
table.insert(previousFormattedLines, v)
for line in string.gmatch(description, "([^#]+)") do
local formatedLines = EID:fitTextToWidth(line, textboxWidth, EID.BreakUtf8CharsLanguage[EID.Config["Language"]])
local textColor = EID:getTextColor()
for i, lineToPrint in ipairs(formatedLines) do
-- 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
textColor = EID:renderString(lineToPrint, renderPos + Vector(12 * EID.Scale, 0), textScale, textColor)
renderPos.Y = renderPos.Y + EID.lineHeight * EID.Scale
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
---------------------------------------------------------------------------
----------------------------Handle New Room--------------------------------
@@ -943,13 +957,15 @@ local searchPartitions = EntityPartition.FAMILIAR + EntityPartition.ENEMY + Enti
EID.lastDescriptionEntity = nil
EID.lastDist = 0
EID.OptionChanged = false
local function onRender(t)
-- Increases by 60 per second, ignores pauses
EID.GameRenderCount = EID.GameRenderCount + 1
EID.OptionChanged = EID.MCM_OptionChanged
EID.MCM_OptionChanged = false
EID:resumeCoroutines()
EID.isDisplaying = false
EID:setPlayer()
EID.TabPreviewID = 0
+1 -10
View File
@@ -137,7 +137,6 @@ function EID:AddBooleanSetting(category, optionName, displayText, params)
OnChange = params.onChangeFunc or function(currentBool)
EID.Config[optionName] = currentBool
EID.MCM_OptionChanged = true
EID.RefreshBagTextbox = true
end,
Info = params.infoText or {}
}
@@ -1028,7 +1027,6 @@ if MCMLoaded then
end,
OnChange = function(currentNum)
EID.MCM_OptionChanged = true
EID.RefreshBagTextbox = true
EID.Config["DisplayBagOfCrafting"] = bagDisplays[currentNum]
end,
Info = {"Always = Always show Results, Hold = Show when holding up bag, Never = Never show results"}
@@ -1051,7 +1049,6 @@ if MCMLoaded then
end,
OnChange = function(currentNum)
EID.MCM_OptionChanged = true
EID.RefreshBagTextbox = true
EID.Config["BagOfCraftingDisplayMode"] = bagDisplayModes[currentNum]
end,
Info = {"Toggle showing a list of recipes, an item preview when bag is full, what item pool/quality you might get, or only the floor pickups"}
@@ -1084,7 +1081,6 @@ if MCMLoaded then
end,
OnChange = function(currentNum)
EID.MCM_OptionChanged = true
EID.RefreshBagTextbox = true
EID.Config["BagOfCraftingResults"] = diceSteps[currentNum + 1]
end,
Info = {"Page size for the preview of items currently craftable with Bag of Crafting"}
@@ -1105,7 +1101,6 @@ if MCMLoaded then
AnIndexOf(combSteps, EID.Config["BagOfCraftingCombinationMax"]) - 1 .. " " .. EID.Config["BagOfCraftingCombinationMax"]
end,
OnChange = function(currentNum)
EID.RefreshBagTextbox = true
EID.Config["BagOfCraftingCombinationMax"] = combSteps[currentNum + 1]
end,
Info = {"Get every recipe for the X best components; setting this high will cause lag spikes (12 = 500 combinations, 14 = 3,000, 16 = 13,000)"}
@@ -1126,7 +1121,6 @@ if MCMLoaded then
AnIndexOf(calcSteps, EID.Config["BagOfCraftingRandomResults"]) - 1 .. " " .. EID.Config["BagOfCraftingRandomResults"]
end,
OnChange = function(currentNum)
EID.RefreshBagTextbox = true
EID.Config["BagOfCraftingRandomResults"] = calcSteps[currentNum + 1]
end,
Info = {"An additional X number of randomly chosen recipes will be checked, changing each pickup spawn/despawn or refresh"}
@@ -1150,7 +1144,6 @@ if MCMLoaded then
end,
OnChange = function(currentBool)
EID.MCM_OptionChanged = true
EID.RefreshBagTextbox = true
EID.Config["BagOfCraftingDisplayNames"] = currentBool
end,
Info = {"If on, each result takes two lines; lower your displayed results accordingly"}
@@ -1182,8 +1175,7 @@ if MCMLoaded then
Type = ModConfigMenu.OptionType.BOOLEAN,
CurrentSetting = function() return true end,
Display = function() return "<---- Clear Bag Content ---->" end,
OnChange = function(currentBool)
EID.RefreshBagTextbox = true
OnChange = function(currentBool)
EID.BagItems = {}
end,
Info = {"Press this to clear all currently detected items on the bag"}
@@ -1198,7 +1190,6 @@ if MCMLoaded then
CurrentSetting = function() return true end,
Display = function() return "<---- Clear Floor item list ---->" end,
OnChange = function(currentBool)
EID.RefreshBagTextbox = true
EID.bagOfCraftingRoomQueries = {}
EID.bagOfCraftingFloorQuery = {}
EID.bagOfCraftingCurPickupCount = -1