@@ -849,16 +849,16 @@ function hideTextDraw(textdraw)
849
849
end
850
850
851
851
function hudGetVerticalScale ()
852
- return 0.002232143
852
+ return 1.0 / 448.0
853
853
end
854
854
855
855
function hudGetHorizontalScale ()
856
- return 0.0015625
856
+ return 1.0 / 640.0
857
857
end
858
858
859
859
function initTextDraw (textdraw )
860
- textdraw .id = textdraw .id or (# g_TextDraws + 1 )
861
- g_TextDraws [textdraw .id ] = textdraw
860
+ textdraw .clientTDId = textdraw .clientTDId or (# g_TextDraws + 1 )
861
+ g_TextDraws [textdraw .clientTDId ] = textdraw
862
862
863
863
-- GTA replaces underscores with spaces
864
864
textdraw .text = textdraw .text :gsub (" _" , " " )
@@ -937,14 +937,13 @@ function initTextDraw(textdraw)
937
937
end
938
938
939
939
local textWidth = dxGetTextWidth (line :gsub (' #%x%x%x%x%x%x' , ' ' ), scale , font )
940
- textdraw . width = math.max ( textdraw . width , textWidth )
940
+
941
941
if textdraw .align == 1 then
942
942
-- left
943
- TDXPos = textdraw .x
943
+ TDXPos = textdraw .x -- - textWidth
944
944
elseif textdraw .align == 2 or not textdraw .align then
945
945
-- center
946
- -- outputConsole(string.format("Got centered text %d %d %s", TDXPos, TDYPos, textdraw.text))
947
- TDXPos = 640 / 2 - textWidth / 2
946
+ TDXPos = textdraw .x - textWidth / 2
948
947
elseif textdraw .align == 3 then
949
948
-- right
950
949
TDXPos = textdraw .x - textWidth
@@ -974,53 +973,55 @@ function renderTextDraws()
974
973
for id ,textdraw in pairs (g_TextDraws ) do
975
974
if textdraw .visible and textdraw .parts and not (textdraw .text :match (' ^%s*$' )) then -- and not textdraw.usebox) then
976
975
local font = textDrawFonts [textdraw .font and textdraw .font >= 0 and textdraw .font <= # textDrawFonts and textdraw .font or 0 ]
977
- if textdraw . upscalex == nil then
978
- textdraw .upscalex = 1.0
979
- end
980
- if textdraw . upscaley == nil then
981
- textdraw .upscaley = 1.0
982
- end
976
+
977
+ textdraw .upscalex = textdraw . upscalex or 1.0
978
+ textdraw . upscaley = textdraw . upscaley or 1.0
979
+
980
+ textdraw .lheight = textdraw . lheight or 0.5
981
+ textdraw . lwidth = textdraw . lwidth or 0.5
983
982
984
983
local letterHeight = (textdraw .lheight * textdraw .upscaley or 0.25 )
985
984
local letterWidth = (textdraw .lwidth * textdraw .upscalex or 0.5 )
986
985
987
986
local vertHudScale = hudGetVerticalScale ()
988
987
local horHudScale = hudGetHorizontalScale ()
989
988
990
- local scaley = SCREEN_SCALE_Y ( screenHeight * vertHudScale * letterHeight * 0.175 ) -- This should replicate what the game does
991
- local scalex = SCREEN_SCALE_X ( screenWidth * horHudScale * letterWidth * 0.35 )
989
+ local scalex = screenWidth * horHudScale * letterWidth ;
990
+ local scaley = screenHeight * vertHudScale * letterHeight * 0.5 ;
992
991
993
992
local sourceY = screenHeight - ((DEFAULT_SCREEN_HEIGHT - textdraw .y ) * (screenHeight * vertHudScale ))
994
993
local sourceX = screenWidth - ((DEFAULT_SCREEN_WIDTH - textdraw .x ) * (screenWidth * horHudScale ))
995
994
996
995
font = font .font
997
996
-- Process box alignments
998
- if textdraw .usebox then
997
+ if textdraw .usebox ~= nil and textdraw .usebox ~= 0 then
998
+ -- outputConsole('textdraw uses box: ' .. textdraw.text)
999
999
local boxcolor = textdraw .boxcolor or tocolor (0 , 0 , 0 , 120 * (textdraw .alpha or 1 ))
1000
1000
local x , y , w , h
1001
+ w = textdraw .width
1001
1002
if textdraw .align == 1 then -- left
1002
- x = textdraw . x
1003
+ x = sourceX
1003
1004
if textdraw .boxsize then
1004
1005
w = textdraw .boxsize [1 ]-- - x
1005
1006
else
1006
1007
w = textdraw .width
1007
1008
end
1008
1009
elseif textdraw .align == 2 then -- centered
1009
- x = textdraw . x
1010
+ x = sourceX -- / 2
1010
1011
if textdraw .boxsize then
1011
1012
w = textdraw .boxsize [1 ]
1012
1013
else
1013
1014
w = textdraw .width
1014
1015
end
1015
1016
elseif textdraw .align == 3 then -- right
1016
- x = textdraw . x - w
1017
+ x = sourceX - w
1017
1018
if textdraw .boxsize then
1018
- w = textdraw . x - textdraw .boxsize [1 ]
1019
+ w = sourceX - textdraw .boxsize [1 ]
1019
1020
else
1020
1021
w = textdraw .width
1021
1022
end
1022
1023
end
1023
- y = textdraw . y
1024
+ y = sourceY
1024
1025
1025
1026
-- Calculates box height
1026
1027
if textdraw .boxsize and textdraw .text :match (' ^%s*$' ) then
@@ -1029,7 +1030,7 @@ function renderTextDraws()
1029
1030
h = textdraw .absheight
1030
1031
end
1031
1032
1032
- dxDrawRectangle (sourceX , sourceY , w * getAspectRatio (), h * getAspectRatio (), boxcolor )
1033
+ dxDrawRectangle (x , y , w * getAspectRatio (), h * getAspectRatio (), boxcolor )
1033
1034
-- outputConsole(string.format("Drawing textdraw box: sourceX: %f, sourceY: %f %s", sourceX, sourceY, textdraw.text))
1034
1035
end
1035
1036
@@ -1060,7 +1061,8 @@ function destroyTextDraw(textdraw)
1060
1061
return
1061
1062
end
1062
1063
hideTextDraw (textdraw )
1063
- table .removevalue (g_TextDraws , textdraw )
1064
+ g_TextDraws [textdraw .clientTDId ] = nil
1065
+ -- table.removevalue(g_TextDraws, textdraw)
1064
1066
end
1065
1067
1066
1068
local gameText = {}
@@ -1081,6 +1083,12 @@ function GameTextForPlayer(text, time, style)
1081
1083
1082
1084
destroyAllGameTextsWithStyle (style ) -- So same styles don't overlap
1083
1085
1086
+ --[[
1087
+ alignments
1088
+ 1 = left
1089
+ 2 = center
1090
+ 3 = right
1091
+ ]]
1084
1092
gameText [gIndex ] = { text = text , font = 2 }
1085
1093
if style == 1 then
1086
1094
gameText [gIndex ].x = 0.9 * 640
@@ -1176,7 +1184,7 @@ function Create3DTextLabel(id, textlabel)
1176
1184
textlabel .id = id
1177
1185
textlabel .enabled = false
1178
1186
g_TextLabels [id ] = textlabel
1179
- outputConsole (' Created text label with id ' .. textlabel .id )
1187
+ -- outputConsole('Created text label with id ' .. textlabel.id)
1180
1188
end
1181
1189
1182
1190
function Delete3DTextLabel (id )
@@ -1192,9 +1200,9 @@ function Attach3DTextLabel(textlabel)
1192
1200
end
1193
1201
1194
1202
function TextDrawCreate (id , textdraw )
1195
- textdraw .id = id
1203
+ textdraw .clientTDId = id
1196
1204
textdraw .visible = false
1197
- -- outputConsole('Got TextDrawCreate, textdraw.visible is ' .. textdraw.visible )
1205
+ -- outputConsole('Got TextDrawCreate, textdraw id ' .. id )
1198
1206
1199
1207
g_TextDraws [id ] = textdraw
1200
1208
if textdraw .x then
@@ -1207,26 +1215,50 @@ function TextDrawCreate(id, textdraw)
1207
1215
initTextDraw (textdraw )
1208
1216
end
1209
1217
1218
+ function findTextDrawHandleByID (id )
1219
+ for _ ,textdraw in pairs (g_TextDraws ) do
1220
+ if textdraw .clientTDId == id then
1221
+ return textdraw .clientTDId
1222
+ end
1223
+ end
1224
+ return - 1
1225
+ end
1226
+
1210
1227
function TextDrawDestroy (id )
1211
- destroyTextDraw (g_TextDraws [id ])
1228
+ local clientTDIdx = findTextDrawHandleByID (id )
1229
+ if clientTDIdx ~= - 1 then
1230
+ destroyTextDraw (g_TextDraws [clientTDIdx ])
1231
+ end
1212
1232
end
1213
1233
1214
1234
function TextDrawHideForPlayer (id )
1215
- hideTextDraw (g_TextDraws [id ])
1235
+ local clientTDIdx = findTextDrawHandleByID (id )
1236
+ if clientTDIdx ~= - 1 then
1237
+ hideTextDraw (g_TextDraws [clientTDIdx ])
1238
+ end
1216
1239
end
1217
1240
1218
1241
function TextDrawPropertyChanged (id , prop , newval , skipInit )
1219
1242
if g_TextDraws == nil then
1220
- outputConsole (' Error: g_TextDraws is nil' )
1243
+ outputConsole (' [TextDrawPropertyChanged] Error: g_TextDraws is nil' )
1244
+ return
1245
+ end
1246
+
1247
+ local clientTDIdx = findTextDrawHandleByID (id )
1248
+ if clientTDIdx == - 1 then
1249
+ outputConsole (' [TextDrawPropertyChanged] Error: g_TextDraws couldn\' t find handle for id: ' .. id )
1221
1250
return
1222
1251
end
1223
1252
1224
- if g_TextDraws [id ] == nil then
1225
- outputConsole (' Error: g_TextDraws is nil at index: ' .. id )
1253
+ if g_TextDraws [clientTDIdx ] == nil then
1254
+ outputConsole (' [TextDrawPropertyChanged] Error: g_TextDraws is nil at index: ' .. clientTDIdx )
1226
1255
return
1227
1256
end
1228
1257
1229
- local textdraw = g_TextDraws [id ]
1258
+ local textdraw = g_TextDraws [clientTDIdx ]
1259
+
1260
+ -- outputConsole('[TextDrawPropertyChanged]: Received new property ' .. prop .. ' - ' .. newval .. ' for ' .. textdraw.text)
1261
+
1230
1262
textdraw [prop ] = newval
1231
1263
if prop == ' boxsize' then
1232
1264
textdraw .boxsize [1 ] = textdraw .boxsize [1 ]
@@ -1242,8 +1274,10 @@ end
1242
1274
function TextDrawShowForPlayer (id )
1243
1275
-- outputConsole(string.format("TextDrawShowForPlayer trying to show textdraw with id %d", id))
1244
1276
-- outputConsole(string.format("TextDrawShowForPlayer trying to show textdraw with text %s", g_TextDraws[id].text))
1245
-
1246
- showTextDraw (g_TextDraws [id ])
1277
+ local clientTDIdx = findTextDrawHandleByID (id )
1278
+ if clientTDIdx ~= - 1 then
1279
+ showTextDraw (g_TextDraws [clientTDIdx ])
1280
+ end
1247
1281
end
1248
1282
1249
1283
function displayFadingMessage (text , r , g , b , fadeInTime , stayTime , fadeOutTime )
0 commit comments