Skip to content

Commit 6939c58

Browse files
committed
Placeholder compatibility for colour strings.
This is barely any compatibility though since these strings are everywhere, and every single one would need an check if \255 were to stop working. Commented out Script.IsEngineMinVersion because it isn't useful, so I don't want it randomly applying if it happens to decide to work at some later point.
1 parent d2956f4 commit 6939c58

4 files changed

Lines changed: 51 additions & 19 deletions

File tree

LuaUI/Widgets/chili/Controls/editbox.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ end
122122

123123
--// =============================================================================
124124

125+
125126
local function explode(div, str)
126127
str = tostring(str)
127128
local arr = {}
@@ -130,7 +131,7 @@ local function explode(div, str)
130131

131132
while j <= N do
132133
local c = str:sub(j, j)
133-
if c == '\255' then
134+
if c == '\255' or c == '\017' then
134135
j = j + 3
135136
elseif c == div then
136137
arr[#arr + 1] = str:sub(i, j - 1)
@@ -144,7 +145,7 @@ local function explode(div, str)
144145
end
145146

146147
return arr
147-
end
148+
end
148149

149150
--- Sets the EditBox text
150151
-- @string newtext text to be set

LuaUI/Widgets/chili/Headers/util.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,29 @@ function mixColors(c1, c2, a)
495495
}
496496
end
497497

498-
function color2incolor(r, g, b, a)
499-
if type(r) == 'table' then
500-
r, g, b, a = unpack4(r)
498+
if false then --Script.IsEngineMinVersion(2025, 6, 10) then
499+
function color2incolor(r,g,b)
500+
if type(r) == 'table' then
501+
r,g,b = unpack4(r)
502+
end
503+
if r then
504+
return string.char(17, r*255, g*255, b*255)
505+
else
506+
return '\017\255\255\255'
507+
end
501508
end
509+
else
510+
function color2incolor(r,g,b)
511+
if type(r) == 'table' then
512+
r,g,b = unpack4(r)
513+
end
502514

503-
local inColor = '\255\255\255\255'
504-
if r then
505-
inColor = string.char(255, r*255, g*255, b*255)
515+
if r then
516+
return string.char(255, r*255, g*255, b*255)
517+
else
518+
return '\255\255\255\255'
519+
end
506520
end
507-
return inColor
508521
end
509522

510523
function incolor2color(inColor)

LuaUI/Widgets/chili_old/Controls/editbox.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ local function explode(div, str)
112112

113113
while j <= N do
114114
local c = str:sub(j, j)
115-
if c == '\255' then
115+
if c == '\255' or c == '\017' then
116116
j = j + 3
117117
elseif c == div then
118118
arr[#arr + 1] = str:sub(i, j - 1)
@@ -126,7 +126,7 @@ local function explode(div, str)
126126
end
127127

128128
return arr
129-
end
129+
end
130130

131131
--- Sets the EditBox text
132132
-- @string newtext text to be set
@@ -239,6 +239,10 @@ function EditBox:_GeneratePhysicalLines(logicalLineID)
239239
end
240240

241241
local wrappedText = font:WrapText(text, width, height)
242+
if text:find("TEST") then
243+
Spring.Echo("text", text:byte(1, 5))
244+
Spring.Echo("wrappedText", wrappedText:byte(1, 5))
245+
end
242246

243247
local y = 0
244248
local fontLineHeight = font:GetLineHeight() + self.lineSpacing

LuaUI/Widgets/chili_old/Headers/util.lua

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,29 @@ function mixColors(c1, c2, a)
393393
}
394394
end
395395

396-
function color2incolor(r,g,b)
397-
if type(r) == 'table' then
398-
r,g,b = unpack4(r)
396+
if false then --Script.IsEngineMinVersion(2025, 6, 10) then
397+
function color2incolor(r,g,b)
398+
if type(r) == 'table' then
399+
r,g,b = unpack4(r)
400+
end
401+
402+
if r then
403+
return "" --string.char(17, r*255, g*255, b*255)
404+
else
405+
return '\017\255\255\255'
406+
end
399407
end
400-
401-
if r then
402-
return string.char(255, r*255, g*255, b*255)
403-
else
404-
return '\255\255\255\255'
408+
else
409+
function color2incolor(r,g,b)
410+
if type(r) == 'table' then
411+
r,g,b = unpack4(r)
412+
end
413+
414+
if r then
415+
return string.char(255, r*255, g*255, b*255)
416+
else
417+
return '\255\255\255\255'
418+
end
405419
end
406420
end
407421

0 commit comments

Comments
 (0)