Skip to content

Commit 1275953

Browse files
authored
Revert "Make killmessages support hex color (#69)" (#336)
This reverts commit 8bb20de.
1 parent b4ecc71 commit 1275953

File tree

1 file changed

+28
-69
lines changed

1 file changed

+28
-69
lines changed

[gameplay]/killmessages/utils/textlib.lua

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,28 @@ local g_screenX,g_screenY = guiGetScreenSize()
55
local visibleText = {}
66
------
77
local defaults = {
8-
fX = 0.5,
9-
fY = 0.5,
10-
bRelativePosition = true,
8+
fX = 0.5,
9+
fY = 0.5,
10+
bRelativePosition = true,
1111
strText = "",
12-
bVerticalAlign = "center",
13-
bHorizontalAlign = "center",
12+
bVerticalAlign = "center",
13+
bHorizontalAlign = "center",
1414
tColor = {255,255,255,255},
1515
fScale = 1,
1616
strFont = "default",
1717
strType = "normal",
1818
tAttributes = {},
1919
bPostGUI = false,
20-
bColorCoded = true,
2120
bClip = false,
2221
bWordWrap = true,
2322
bVisible = true,
24-
tBoundingBox = false, --If a bounding box is not set, it will not be used.
25-
bRelativeBoundingBox = true,
23+
tBoundingBox = false, --If a bounding box is not set, it will not be used.
24+
bRelativeBoundingBox = true,
2625
}
2726

2827
local validFonts = {
2928
default = true,
30-
["default-bold"] = true,
29+
["default-bold"] = true,
3130
clear = true,
3231
arial = true,
3332
pricedown = true,
@@ -49,19 +48,19 @@ local validAlignTypes = {
4948
right = true,
5049
}
5150

52-
function dxText:create(text, x, y, relative)
51+
function dxText:create( text, x, y, relative )
5352
assert(not self.fX, "attempt to call method 'create' (a nil value)")
54-
if type(text) ~= "string" or not tonumber(x) or not tonumber(y) then
55-
outputDebugString("dxText:create - Bad argument",0,112,112,112)
53+
if ( type(text) ~= "string" ) or ( not tonumber(x) ) or ( not tonumber(y) ) then
54+
outputDebugString ( "dxText:create - Bad argument", 0, 112, 112, 112 )
5655
return false
5756
end
5857
local new = {}
59-
setmetatable(new, dxText_mt)
58+
setmetatable( new, dxText_mt )
6059
--Add default settings
6160
for i,v in pairs(defaults) do
6261
new[i] = v
6362
end
64-
idAssign = idAssign+1
63+
idAssign = idAssign + 1
6564
new.id = idPrefix..idAssign
6665
new.strText = text or new.strText
6766
new.fX = x or new.fX
@@ -80,7 +79,7 @@ function dxText:text(text)
8079
end
8180

8281
function dxText:position(x,y,relative)
83-
if not tonumber(x) then return self.fX,self.fY end
82+
if not tonumber(x) then return self.fX, self.fY end
8483
self.fX = x
8584
self.fY = y
8685
if type(relative) == "boolean" then
@@ -96,7 +95,7 @@ function dxText:color(r,g,b,a)
9695
g = g or self.tColor[2]
9796
b = b or self.tColor[3]
9897
a = a or self.tColor[4]
99-
self.tColor = {r,g,b,a}
98+
self.tColor = { r,g,b,a }
10099
return true
101100
end
102101

@@ -124,20 +123,15 @@ function dxText:destroy()
124123
end
125124

126125
function dxText:extent()
127-
if self.bColorCoded then
128-
text = string.gsub(self.strText,"#%x%x%x%x%x%x","")
129-
else
130-
text = self.strText
131-
end
132-
local extent = dxGetTextWidth(text,self.fScale,self.strFont)
126+
local extent = dxGetTextWidth ( self.strText, self.fScale, self.strFont )
133127
if self.strType == "stroke" or self.strType == "border" then
134128
extent = extent + self.tAttributes[1]
135129
end
136130
return extent
137131
end
138132

139133
function dxText:height()
140-
local height = dxGetFontHeight(self.fScale, self.strFont)
134+
local height = dxGetFontHeight ( self.fScale, self.strFont )
141135
if self.strType == "stroke" or self.strType == "border" then
142136
height = height + self.tAttributes[1]
143137
end
@@ -169,16 +163,16 @@ function dxText:wordWrap(bool)
169163
end
170164

171165
function dxText:type(type,...)
172-
if not validTypes[type] then return self.strType,unpack(self.tAttributes) end
166+
if not validTypes[type] then return self.strType, unpack(self.tAttributes) end
173167
self.strType = type
174168
self.tAttributes = {...}
175169
return true
176170
end
177171

178172
function dxText:align(horzA, vertA)
179-
if not validAlignTypes[horzA] then return self.bHorizontalAlign,self.bVerticalAlign end
173+
if not validAlignTypes[horzA] then return self.bHorizontalAlign, self.bVerticalAlign end
180174
vertA = vertA or self.bVerticalAlign
181-
self.bHorizontalAlign,self.bVerticalAlign = horzA,vertA
175+
self.bHorizontalAlign, self.bVerticalAlign = horzA, vertA
182176
return true
183177
end
184178

@@ -202,42 +196,7 @@ function dxText:boundingBox(left,top,right,bottom,relative)
202196
return true
203197
end
204198

205-
function dxCreateCustomDX(text,left,top,right,bottom,color,scale,font,alignX,alignY,clip,wordBreak,postGUI)
206-
if not text or not left or not top then
207-
return false
208-
end
209-
local xOffset = nil
210-
local fpat = "(.-)#(%x%x%x%x%x%x)"
211-
local s,e,cap,col = text:find(fpat,1)
212-
local last_end = 1
213-
if not alignX then
214-
alignX = "left"
215-
elseif alignX == "center" then
216-
xOffset = -(dxGetTextWidth(string.gsub(text,"#%x%x%x%x%x%x",""),scale,font)/2)
217-
else
218-
xOffset = 0
219-
end
220-
while s do
221-
if cap == "" and col then
222-
color = tocolor(tonumber("0x"..col:sub(1,2)), tonumber("0x"..col:sub(3,4)), tonumber("0x"..col:sub(5,6)),255)
223-
end
224-
if s ~= 1 or cap ~= "" then
225-
dxDrawText(cap,left+xOffset,top,left+xOffset,bottom,color,scale,font,alignX,alignY,false,false,postGUI)
226-
xOffset = xOffset+dxGetTextWidth(cap,scale,font)
227-
color = tocolor(tonumber("0x"..col:sub(1,2)), tonumber("0x"..col:sub(3,4)), tonumber("0x"..col:sub(5,6)),255)
228-
end
229-
last_end = e+1
230-
s,e,cap,col = text:find(fpat,last_end)
231-
end
232-
if last_end <= #text then
233-
cap = text:sub(last_end)
234-
dxDrawText(cap,left+xOffset,top,left+xOffset,bottom,color,scale,font,alignX,alignY,false,false,postGUI)
235-
xOffset = xOffset+dxGetTextWidth(cap,scale,font)
236-
end
237-
return true
238-
end
239-
240-
addEventHandler("onClientRender",getRootElement(),
199+
addEventHandler ( "onClientRender", getRootElement(),
241200
function()
242201
for self,_ in pairs(visibleText) do
243202
while true do
@@ -296,8 +255,8 @@ addEventHandler("onClientRender",getRootElement(),
296255
if outlinesize > 0 then
297256
for offsetX=-outlinesize,outlinesize,outlinesize do
298257
for offsetY=-outlinesize,outlinesize,outlinesize do
299-
if not offsetX == 0 and offsetY == 0 then
300-
dxCreateCustomDX(self.strText,l+offsetX,t+offsetY,r+offsetX,b+offsetY,tocolor(att2,att3,att4,att5),self.fScale,self.strFont,self.bHorizontalAlign,self.bVerticalAlign,self.bClip,self.bWordWrap,self.bPostGUI,self.bColorCoded)
258+
if not (offsetX == 0 and offsetY == 0) then
259+
dxDrawText(self.strText, l + offsetX, t + offsetY, r + offsetX, b + offsetY, tocolor(att2, att3, att4, att5), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI )
301260
end
302261
end
303262
end
@@ -308,19 +267,19 @@ addEventHandler("onClientRender",getRootElement(),
308267
att3 = att3 or 0
309268
att4 = att4 or 0
310269
att5 = att5 or self.tColor[4]
311-
dxCreateCustomDX(self.strText,l+shadowDist,t+shadowDist,r+shadowDist,b+shadowDist,tocolor(att2,att3,att4,att5),self.fScale,self.strFont,self.bHorizontalAlign,self.bVerticalAlign,self.bClip,self.bWordWrap,self.bPostGUI,self.bColorCoded)
270+
dxDrawText(self.strText, l + shadowDist, t + shadowDist, r + shadowDist, b + shadowDist, tocolor(att2, att3, att4, att5), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI )
312271
end
313-
dxCreateCustomDX(self.strText,l,t,r,b,tocolor(unpack(self.tColor)),self.fScale,self.strFont,self.bHorizontalAlign,self.bVerticalAlign,self.bClip,self.bWordWrap,self.bPostGUI,self.bColorCoded)
272+
dxDrawText ( self.strText, l, t, r, b, tocolor(unpack(self.tColor)), self.fScale, self.strFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI )
314273
break
315274
end
316275
end
317276
end
318277
)
319278

320-
if addEvent("updateDisplays",true) then
321-
addEventHandler("updateDisplays",getRootElement(),
279+
if addEvent ( "updateDisplays", true ) then
280+
addEventHandler ( "updateDisplays", getRootElement(),
322281
function(self)
323-
setmetatable(self,dxText_mt)
282+
setmetatable( self, dxText_mt )
324283
--Remove any old ones with the same id
325284
for text,_ in pairs(visibleText) do
326285
if text.id == self.id then

0 commit comments

Comments
 (0)