From 59a71e0cc338d13b57cc1a09914b32db3e2f617d Mon Sep 17 00:00:00 2001 From: Dong-Yiyuan <42213600+Yiyuan-Dong@users.noreply.github.com> Date: Wed, 16 Oct 2024 02:02:55 +0800 Subject: [PATCH] Center the small bullet point icons (#733) * center the small bullet point icons * tweak comments * fix typo --- features/eid_api.lua | 12 +++++++++--- main.lua | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/features/eid_api.lua b/features/eid_api.lua index 99519325..09971c4a 100644 --- a/features/eid_api.lua +++ b/features/eid_api.lua @@ -905,7 +905,7 @@ end -- Searches thru the given string and replaces Iconplaceholders with icons. -- Returns 2 values. the string without the placeholders but with an accurate space between lines. and a table of all Inline Sprites -function EID:filterIconMarkup(text) +function EID:filterIconMarkup(text, renderBulletPointIcon) local spriteTable = {} for word in string.gmatch(text, "{{.-}}") do local textposition = string.find(text, word) @@ -916,6 +916,12 @@ function EID:filterIconMarkup(text) local lookup = EID:getIcon(word) local preceedingTextWidth = EID:getStrWidth(string.sub(text, 0, textposition - 1)) * EID.Scale + -- Center the small bullet point icons by adding an extra left offset to them. + -- If the icon has a positive left offset, that means the offset is already included in the icon itself and we should not add it again + if renderBulletPointIcon and lookup[3] < 11 and (#lookup < 5 or lookup[5] <= 0) then + preceedingTextWidth = preceedingTextWidth + math.floor((12 - lookup[3]) / 2) * EID.Scale + end + table.insert(spriteTable, {lookup, preceedingTextWidth, callback}) text = string.gsub(text, word, EID:generatePlaceholderString(lookup[3]), 1) end @@ -1166,12 +1172,12 @@ end -- needs to be called in a render Callback -- args: string, Vector(int, int), Vector(float,float), KColor obj, bool -- Returns the last used KColor -function EID:renderString(str, position, scale, kcolor) +function EID:renderString(str, position, scale, kcolor, renderBulletPointIcon) str = EID:replaceShortMarkupStrings(str) local textPartsTable = EID:filterColorMarkup(str, kcolor) local offsetX = 0 for _, textPart in ipairs(textPartsTable) do - local strFiltered, spriteTable = EID:filterIconMarkup(textPart[1]) + local strFiltered, spriteTable = EID:filterIconMarkup(textPart[1], renderBulletPointIcon) EID:renderInlineIcons(spriteTable, position.X + offsetX, position.Y) if strFiltered then -- prevent possible crash when strFiltered is nil EID.font:DrawStringScaledUTF8(strFiltered, position.X + offsetX, position.Y, scale.X, scale.Y, textPart[2], 0, false) diff --git a/main.lua b/main.lua index a12e6081..c7b34b94 100644 --- a/main.lua +++ b/main.lua @@ -728,7 +728,7 @@ function EID:printBulletPoints(description, renderPos) local bpIcon, rejectedIcon = 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) + textColor = EID:renderString(bpIcon, renderPos + Vector(-3 * EID.Scale, 0), textScale , textColor, true) else if rejectedIcon then lineToPrint = string.gsub(lineToPrint, rejectedIcon .. " ", "", 1) end textColor = EID:renderString(bpIcon, renderPos, textScale , textColor)