@@ -849,16 +849,16 @@ function hideTextDraw(textdraw)
849849end
850850
851851function hudGetVerticalScale ()
852- return 0.002232143
852+ return 1.0 / 448.0
853853end
854854
855855function hudGetHorizontalScale ()
856- return 0.0015625
856+ return 1.0 / 640.0
857857end
858858
859859function 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
862862
863863 -- GTA replaces underscores with spaces
864864 textdraw .text = textdraw .text :gsub (" _" , " " )
@@ -937,14 +937,13 @@ function initTextDraw(textdraw)
937937 end
938938
939939 local textWidth = dxGetTextWidth (line :gsub (' #%x%x%x%x%x%x' , ' ' ), scale , font )
940- textdraw . width = math.max ( textdraw . width , textWidth )
940+
941941 if textdraw .align == 1 then
942942 -- left
943- TDXPos = textdraw .x
943+ TDXPos = textdraw .x -- - textWidth
944944 elseif textdraw .align == 2 or not textdraw .align then
945945 -- 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
948947 elseif textdraw .align == 3 then
949948 -- right
950949 TDXPos = textdraw .x - textWidth
@@ -974,53 +973,55 @@ function renderTextDraws()
974973 for id ,textdraw in pairs (g_TextDraws ) do
975974 if textdraw .visible and textdraw .parts and not (textdraw .text :match (' ^%s*$' )) then -- and not textdraw.usebox) then
976975 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
983982
984983 local letterHeight = (textdraw .lheight * textdraw .upscaley or 0.25 )
985984 local letterWidth = (textdraw .lwidth * textdraw .upscalex or 0.5 )
986985
987986 local vertHudScale = hudGetVerticalScale ()
988987 local horHudScale = hudGetHorizontalScale ()
989988
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 ;
992991
993992 local sourceY = screenHeight - ((DEFAULT_SCREEN_HEIGHT - textdraw .y ) * (screenHeight * vertHudScale ))
994993 local sourceX = screenWidth - ((DEFAULT_SCREEN_WIDTH - textdraw .x ) * (screenWidth * horHudScale ))
995994
996995 font = font .font
997996 -- 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)
999999 local boxcolor = textdraw .boxcolor or tocolor (0 , 0 , 0 , 120 * (textdraw .alpha or 1 ))
10001000 local x , y , w , h
1001+ w = textdraw .width
10011002 if textdraw .align == 1 then -- left
1002- x = textdraw . x
1003+ x = sourceX
10031004 if textdraw .boxsize then
10041005 w = textdraw .boxsize [1 ]-- - x
10051006 else
10061007 w = textdraw .width
10071008 end
10081009 elseif textdraw .align == 2 then -- centered
1009- x = textdraw . x
1010+ x = sourceX -- / 2
10101011 if textdraw .boxsize then
10111012 w = textdraw .boxsize [1 ]
10121013 else
10131014 w = textdraw .width
10141015 end
10151016 elseif textdraw .align == 3 then -- right
1016- x = textdraw . x - w
1017+ x = sourceX - w
10171018 if textdraw .boxsize then
1018- w = textdraw . x - textdraw .boxsize [1 ]
1019+ w = sourceX - textdraw .boxsize [1 ]
10191020 else
10201021 w = textdraw .width
10211022 end
10221023 end
1023- y = textdraw . y
1024+ y = sourceY
10241025
10251026 -- Calculates box height
10261027 if textdraw .boxsize and textdraw .text :match (' ^%s*$' ) then
@@ -1029,7 +1030,7 @@ function renderTextDraws()
10291030 h = textdraw .absheight
10301031 end
10311032
1032- dxDrawRectangle (sourceX , sourceY , w * getAspectRatio (), h * getAspectRatio (), boxcolor )
1033+ dxDrawRectangle (x , y , w * getAspectRatio (), h * getAspectRatio (), boxcolor )
10331034 -- outputConsole(string.format("Drawing textdraw box: sourceX: %f, sourceY: %f %s", sourceX, sourceY, textdraw.text))
10341035 end
10351036
@@ -1060,7 +1061,8 @@ function destroyTextDraw(textdraw)
10601061 return
10611062 end
10621063 hideTextDraw (textdraw )
1063- table .removevalue (g_TextDraws , textdraw )
1064+ g_TextDraws [textdraw .clientTDId ] = nil
1065+ -- table.removevalue(g_TextDraws, textdraw)
10641066end
10651067
10661068local gameText = {}
@@ -1081,6 +1083,12 @@ function GameTextForPlayer(text, time, style)
10811083
10821084 destroyAllGameTextsWithStyle (style ) -- So same styles don't overlap
10831085
1086+ --[[
1087+ alignments
1088+ 1 = left
1089+ 2 = center
1090+ 3 = right
1091+ ]]
10841092 gameText [gIndex ] = { text = text , font = 2 }
10851093 if style == 1 then
10861094 gameText [gIndex ].x = 0.9 * 640
@@ -1176,7 +1184,7 @@ function Create3DTextLabel(id, textlabel)
11761184 textlabel .id = id
11771185 textlabel .enabled = false
11781186 g_TextLabels [id ] = textlabel
1179- outputConsole (' Created text label with id ' .. textlabel .id )
1187+ -- outputConsole('Created text label with id ' .. textlabel.id)
11801188end
11811189
11821190function Delete3DTextLabel (id )
@@ -1192,9 +1200,9 @@ function Attach3DTextLabel(textlabel)
11921200end
11931201
11941202function TextDrawCreate (id , textdraw )
1195- textdraw .id = id
1203+ textdraw .clientTDId = id
11961204 textdraw .visible = false
1197- -- outputConsole('Got TextDrawCreate, textdraw.visible is ' .. textdraw.visible )
1205+ -- outputConsole('Got TextDrawCreate, textdraw id ' .. id )
11981206
11991207 g_TextDraws [id ] = textdraw
12001208 if textdraw .x then
@@ -1207,26 +1215,50 @@ function TextDrawCreate(id, textdraw)
12071215 initTextDraw (textdraw )
12081216end
12091217
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+
12101227function TextDrawDestroy (id )
1211- destroyTextDraw (g_TextDraws [id ])
1228+ local clientTDIdx = findTextDrawHandleByID (id )
1229+ if clientTDIdx ~= - 1 then
1230+ destroyTextDraw (g_TextDraws [clientTDIdx ])
1231+ end
12121232end
12131233
12141234function TextDrawHideForPlayer (id )
1215- hideTextDraw (g_TextDraws [id ])
1235+ local clientTDIdx = findTextDrawHandleByID (id )
1236+ if clientTDIdx ~= - 1 then
1237+ hideTextDraw (g_TextDraws [clientTDIdx ])
1238+ end
12161239end
12171240
12181241function TextDrawPropertyChanged (id , prop , newval , skipInit )
12191242 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 )
12211250 return
12221251 end
12231252
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 )
12261255 return
12271256 end
12281257
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+
12301262 textdraw [prop ] = newval
12311263 if prop == ' boxsize' then
12321264 textdraw .boxsize [1 ] = textdraw .boxsize [1 ]
@@ -1242,8 +1274,10 @@ end
12421274function TextDrawShowForPlayer (id )
12431275 -- outputConsole(string.format("TextDrawShowForPlayer trying to show textdraw with id %d", id))
12441276 -- 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
12471281end
12481282
12491283function displayFadingMessage (text , r , g , b , fadeInTime , stayTime , fadeOutTime )
0 commit comments