Moved "Split into multiple lines" feature into seperate function
This commit is contained in:
1 parent
b1447e1636
commit
b1d021648d
4 files changed
+40
-27
No files matched your search
+34
-5
@@ -257,7 +257,7 @@ end
|
|||||||
|
|
||||||
-- Searches thru the given string and replaces Iconplaceholders with icons.
|
-- 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
|
-- 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:filterIconMarkup(text, textPosX, textPosY)
|
||||||
local spriteTable = {}
|
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)
|
||||||
@@ -269,7 +269,7 @@ function EID:filterMarkup(text, textPosX, textPosY)
|
|||||||
return text, spriteTable
|
return text, spriteTable
|
||||||
end
|
end
|
||||||
|
|
||||||
--renders a list of given inline sprite objects returned by the "EID:filterMarkup()" function
|
--renders a list of given inline sprite objects returned by the "EID:filterIconMarkup()" function
|
||||||
-- Table entry format: {EID.InlineIcons Object, Width of text preceeding the icon}
|
-- Table entry format: {EID.InlineIcons Object, Width of text preceeding the icon}
|
||||||
function EID:renderInlineIcons(spriteTable, posX, posY)
|
function EID:renderInlineIcons(spriteTable, posX, posY)
|
||||||
for _,sprite in ipairs(spriteTable) do
|
for _,sprite in ipairs(spriteTable) do
|
||||||
@@ -328,10 +328,39 @@ function EID:filterColorMarkup(text, baseKColor)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(textPartsTable,{string.sub(text, lastPosition), lastColor,0})
|
table.insert(textPartsTable,{string.sub(text, lastPosition), lastColor, 0})
|
||||||
return textPartsTable
|
return textPartsTable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Fits a given string to a specific width
|
||||||
|
-- returns the string as a table of lines
|
||||||
|
function EID:fitTextToWidth(str, textboxWidth)
|
||||||
|
local formatedLines = {}
|
||||||
|
local curLength = 0
|
||||||
|
local text = ""
|
||||||
|
for word in string.gmatch(str, "([^%s]+)") do
|
||||||
|
local colorFiltered = EID:filterColorMarkup(word, EID:getTextColor())
|
||||||
|
local filteredWord = ""
|
||||||
|
for _,filtered in ipairs(colorFiltered) do
|
||||||
|
filteredWord = filteredWord..filtered[1]
|
||||||
|
end
|
||||||
|
local strFiltered, spriteTable = EID:filterIconMarkup(filteredWord, 0, 0)
|
||||||
|
local wordLength = EID:getStrWidth(strFiltered)
|
||||||
|
|
||||||
|
if curLength + wordLength <= textboxWidth or curLength < 12 then
|
||||||
|
text = text .. word .. " "
|
||||||
|
curLength = curLength + wordLength
|
||||||
|
else
|
||||||
|
print(text)
|
||||||
|
table.insert(formatedLines, text)
|
||||||
|
text = word .. " "
|
||||||
|
curLength = wordLength
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(formatedLines, text)
|
||||||
|
return formatedLines
|
||||||
|
end
|
||||||
|
|
||||||
-- Renders a given string using the EID Custom font. This will also apply any markup and render icons
|
-- Renders a given string using the EID Custom font. This will also apply any markup and render icons
|
||||||
-- needs to be called in a render Callback
|
-- needs to be called in a render Callback
|
||||||
-- args: string, Vector(int, int), Vector(float,float), KColor obj, bool
|
-- args: string, Vector(int, int), Vector(float,float), KColor obj, bool
|
||||||
@@ -342,9 +371,9 @@ function EID:renderString(str, position, scale, kcolor)
|
|||||||
local textPartsTable = EID:filterColorMarkup(str, kcolor)
|
local textPartsTable = EID:filterColorMarkup(str, kcolor)
|
||||||
local offsetX = 0
|
local offsetX = 0
|
||||||
for i, textPart in ipairs(textPartsTable) do
|
for i, textPart in ipairs(textPartsTable) do
|
||||||
local strFiltered, spriteTable = EID:filterMarkup(textPart[1], position.X, position.Y)
|
local strFiltered, spriteTable = EID:filterIconMarkup(textPart[1], position.X, position.Y)
|
||||||
EID:renderInlineIcons(spriteTable, position.X, position.Y)
|
EID:renderInlineIcons(spriteTable, position.X, position.Y)
|
||||||
EID.font:DrawStringScaledUTF8(strFiltered, position.X+offsetX, position.Y, scale.X, scale.Y, textPart[2], 0, false)
|
EID.font:DrawStringScaledUTF8(strFiltered, position.X + offsetX, position.Y, scale.X, scale.Y, textPart[2], 0, false)
|
||||||
offsetX = offsetX + textPart[3]
|
offsetX = offsetX + textPart[3]
|
||||||
end
|
end
|
||||||
return textPartsTable[#textPartsTable][2]
|
return textPartsTable[#textPartsTable][2]
|
||||||
|
|||||||
+2
-2
@@ -163,7 +163,7 @@ EID.InlineColors ={
|
|||||||
return EID:interpolateColors(colors[primaryColorIndex], colors[secondaryColorIndex], (animTime%(colorFractions+1))/colorFractions)
|
return EID:interpolateColors(colors[primaryColorIndex], colors[secondaryColorIndex], (animTime%(colorFractions+1))/colorFractions)
|
||||||
end,
|
end,
|
||||||
-- Text will blink frequently
|
-- Text will blink frequently
|
||||||
["ColorBlink"] = function (color)
|
["ColorBlink"] = function (color)
|
||||||
local maxAnimTime = 40
|
local maxAnimTime = 40
|
||||||
local animTime = Game():GetFrameCount() % maxAnimTime
|
local animTime = Game():GetFrameCount() % maxAnimTime
|
||||||
color = EID:copyKColor(color) or EID:getTextColor()
|
color = EID:copyKColor(color) or EID:getTextColor()
|
||||||
@@ -175,7 +175,7 @@ EID.InlineColors ={
|
|||||||
return color
|
return color
|
||||||
end,
|
end,
|
||||||
-- Text will fade in and out
|
-- Text will fade in and out
|
||||||
["ColorFade"] = function (color)
|
["ColorFade"] = function (color)
|
||||||
local maxAnimTime = 30
|
local maxAnimTime = 30
|
||||||
local animTime = Game():GetFrameCount() % (maxAnimTime+10)
|
local animTime = Game():GetFrameCount() % (maxAnimTime+10)
|
||||||
color = EID:copyKColor(color) or EID:getTextColor()
|
color = EID:copyKColor(color) or EID:getTextColor()
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ __eidItemTransformations[2] = "Some Test Transformation"
|
|||||||
------ Test: Add all transformations to spoon bender ------
|
------ Test: Add all transformations to spoon bender ------
|
||||||
__eidItemTransformations[3] = "1,2,3,4,5,6,7,8,9,10,11,12,13"
|
__eidItemTransformations[3] = "1,2,3,4,5,6,7,8,9,10,11,12,13"
|
||||||
|
|
||||||
|
------ Test: Description with colors ------
|
||||||
|
__eidItemDescriptions[3] = "Some {{ColorRed}}long ass Test string with a lot of Words that sound interesting#With{{ColorBlink}} cool {{CR}}{{ColorRed}}C{{ColorGreen}}o{{ColorBlue}}l{{ColorYellow}}o{{ColorOrange}}r{{ColorPink}}s{{ColorWhite}} and a high amount of nifty {{ColorRainbow}}Swag "
|
||||||
|
|
||||||
local function onDebugRender(t)
|
local function onDebugRender(t)
|
||||||
for i, v in ipairs(charsToDebug) do
|
for i, v in ipairs(charsToDebug) do
|
||||||
local pos = Vector(EIDConfig["XPosition"], EIDConfig["YPosition"] - 15 + ((i - 1) * 14))
|
local pos = Vector(EIDConfig["XPosition"], EIDConfig["YPosition"] - 15 + ((i - 1) * 14))
|
||||||
|
|||||||
@@ -178,27 +178,8 @@ end
|
|||||||
function printBulletPoints(description, padding)
|
function printBulletPoints(description, padding)
|
||||||
local textboxWidth = tonumber(EIDConfig["TextboxWidth"]) * 4
|
local textboxWidth = tonumber(EIDConfig["TextboxWidth"]) * 4
|
||||||
description = EID:replaceShortMarkupStrings(description)
|
description = EID:replaceShortMarkupStrings(description)
|
||||||
|
|
||||||
for line in string.gmatch(description, "([^#]+)") do
|
for line in string.gmatch(description, "([^#]+)") do
|
||||||
line = string.gsub(line, "([^%s])({{)", function(a,b) return a.." "..b end) -- add space between icons, if not already existing
|
local formatedLines = EID:fitTextToWidth(line, textboxWidth)
|
||||||
local formatedLines = {}
|
|
||||||
local text = ""
|
|
||||||
local curLength = 0
|
|
||||||
for word in string.gmatch(line, "([^%s]+)") do
|
|
||||||
local wordLength = EID:getStrWidth(word)
|
|
||||||
if EID:getIcon(word) ~= EID.InlineIcons["ERROR"] then
|
|
||||||
wordLength = EID:getIcon(word)[3]
|
|
||||||
end
|
|
||||||
if curLength + wordLength <= textboxWidth or curLength < 12 then
|
|
||||||
text = text .. word .. " "
|
|
||||||
curLength = curLength + wordLength
|
|
||||||
else
|
|
||||||
table.insert(formatedLines, text)
|
|
||||||
text = word .. " "
|
|
||||||
curLength = wordLength
|
|
||||||
end
|
|
||||||
end
|
|
||||||
table.insert(formatedLines, text)
|
|
||||||
local textColor = EID:getTextColor()
|
local textColor = EID:getTextColor()
|
||||||
for i, lineToPrint in ipairs(formatedLines) do
|
for i, lineToPrint in ipairs(formatedLines) do
|
||||||
-- render bulletpoint
|
-- render bulletpoint
|
||||||
|
|||||||
Reference in new issue
Block a user