Advertisement
supinus

Untitled

Mar 14th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.27 KB | None | 0 0
  1. --because this is specific to this car, I"m going to make a table that draws the gears quickly. This can be edited for future cars.
  2. local gearT = {
  3. [-1] = "R",
  4. [0] = "N",
  5. [1] = "1",
  6. [2] = "2",
  7. [3] = "3",
  8. [4] = "4",
  9. [5] = "5",
  10. [6] = "6",
  11. [7] = "7",
  12. [8] = "8"
  13.  
  14. }
  15.  
  16. local Icons = {
  17. ["EML"] = "assets/icons/EML_ON.png",
  18. ["ABS"] = "assets/icons/ABS_ON.png",
  19. ["ESC"] = "assets/icons/ESC.png",
  20. ["ILEFT"] = "assets/icons/INDICATOR_LEFT.png",
  21. ["IRIGHT"] = "assets/icons/INDICATOR_RIGHT.png",
  22. ["LIGHT_HIGHBEAM"] = "assets/icons/LIGHT_HIGHBEAM.png",
  23. ["LIGHT_PARKING"] = "assets/icons/LIGHT_PARKING.png",
  24. ["SPEEDLIMIT"] = "assets/icons/speedlimit2.png"
  25. }
  26. local indicatorActive
  27. setInterval(function() indicatorActive = not indicatorActive end, 1/2.6)
  28.  
  29.  
  30. --load the cluster video LUTs into memory so we can refer to them later. Interestingly they are very non-linear, but this fixes that.
  31. if ac.getPatchVersionCode() > 2080 then
  32. rpmLUT = ac.DataLUT11.load("assets/cluster/rpm_frames_2/rpm-frame.lut")
  33. speedLUT = ac.DataLUT11.load("assets/cluster/speed_frames_2/speed-frame.lut")
  34. ac.log("LUT Files loaded")
  35. end
  36. local carRPM = 0
  37. local carSpeed = 0
  38.  
  39. local rpmframe
  40. local rpmmaxframe = 300
  41. local rpmposition = vec2(2300,600)
  42. local rpmsize = vec2(580,540):scale(2.1)
  43.  
  44. --load speed video and set it"s settings accordingly.
  45. local speedframe
  46. local speedmaxframe = 300
  47. local speedsize = vec2(580,540):scale(2.1)
  48. local speedposition = vec2(500,600)
  49.  
  50. --speedlimit target location vec2(1320, 1480)
  51. local speedLimPosVert = 2000
  52. local speedLimPosAnim = false
  53.  
  54. local rpmStartUp = 0
  55. local SpeedStartUp = 0
  56. local dashReady = false
  57.  
  58. function update(dt)
  59. ui.setAsynchronousImagesLoading(false)
  60. if rpmStartUp < rpmmaxframe then
  61. rpmStartUp = rpmStartUp + 1
  62. ui.drawImage("./assets/frames_rpm/rpm".. rpmStartUp ..".jpg", rpmposition, vec2(rpmposition.x+rpmsize.x, rpmposition.y+rpmsize.y))
  63. end
  64. if SpeedStartUp < speedmaxframe then
  65. SpeedStartUp = SpeedStartUp + 1
  66. ui.drawImage("./assets/frames_speed/speed".. SpeedStartUp ..".jpg", speedposition, vec2(speedposition.x+speedsize.x, speedposition.y+speedsize.y))
  67. end
  68.  
  69. local time = string.format("%02d:%02d",sim.timeHours,sim.timeMinutes)
  70. local temp = "+" .. sim.ambientTemperature .. "C"
  71. local distance = (car.fuel * sim.trackLengthM ) / car.fuelPerLap .. "km"
  72.  
  73. if ac.getPatchVersionCode() < 2080 and rpmStartUp == 300 and SpeedStartUp == 300 then
  74. ui.setAsynchronousImagesLoading(false)
  75. ac.debug("Render method", "Old")
  76. --rpmframe = math.floor(0.0404*car.rpm)
  77. carRPM = math.applyLag(carRPM, car.rpm, 0.8, dt)
  78.  
  79. rpmframe = math.min(rpmmaxframe, (rpmmaxframe/7400)*carRPM+10)
  80. rpmframe = math.floor(rpmframe)
  81. ui.drawImage("./assets/frames_rpm/rpm"..rpmframe..".jpg", rpmposition, vec2(rpmposition.x+rpmsize.x, rpmposition.y+rpmsize.y))
  82.  
  83. if car.speedKmh >= 0 and car.speedKmh <= 20 then
  84. speedframe = (53/20)*car.speedKmh
  85. elseif car.speedKmh > 20 and car.speedKmh <= 60 then
  86. speedframe = ((103-53)/(60-20))*car.speedKmh+(53-(((103-53)/(60-20))*20))
  87. elseif car.speedKmh > 60 and car.speedKmh <= 100 then
  88. speedframe = ((150-103)/(100-60))*car.speedKmh+(103-(((150-103)/(100-60))*60))
  89. elseif car.speedKmh > 100 and car.speedKmh <= 140 then
  90. speedframe = ((182-150)/(140-100))*car.speedKmh+(150-(((182-150)/(140-100))*100))
  91. elseif car.speedKmh > 140 and car.speedKmh <= 200 then
  92. speedframe = ((219-182)/(200-140))*car.speedKmh+(182-(((219-182)/(200-140))*140))
  93. elseif car.speedKmh > 200 and car.speedKmh <= 260 then
  94. speedframe = ((256-219)/(260-200))*car.speedKmh+(219-(((256-219)/(260-200))*200))
  95. elseif car.speedKmh > 260 then
  96. speedframe = ((299-256)/(320-260))*car.speedKmh+(256-(((299-256)/(320-260))*260))
  97. end
  98. ui.drawImage("./assets/frames_speed/speed" .. math.min(speedmaxframe, math.floor(speedframe)) .. ".jpg", speedposition, vec2(speedposition.x+speedsize.x, speedposition.y+speedsize.y))
  99.  
  100. elseif ac.getPatchVersionCode() > 2080 and rpmStartUp == 300 and SpeedStartUp == 300 then
  101. ac.debug("Render method", "New")
  102. carRPM = math.applyLag(carRPM, car.rpm, 0.5, dt)
  103. rpmframe = math.applyLag(rpmframe, rpmLUT:get(carRPM),0.5,dt)
  104. rpmframe = math.round(rpmframe,0)
  105. ui.drawImage("./assets/frames_rpm/rpm"..rpmframe..".jpg", rpmposition, vec2(rpmposition.x+rpmsize.x, rpmposition.y+rpmsize.y))
  106.  
  107. carSpeed = math.applyLag(carSpeed, car.speedKmh, 0.5, dt)
  108. speedframe = math.applyLag(speedframe, speedLUT:get(carSpeed), 0.5, dt)
  109. speedframe = math.round(speedframe,0)
  110. ui.drawImage("./assets/frames_speed/speed" .. math.min(speedmaxframe, math.floor(speedframe)) .. ".jpg", speedposition, vec2(speedposition.x+speedsize.x, speedposition.y+speedsize.y))
  111. end
  112.  
  113. ----- Dash loading thing -----
  114. if dashReady == false then
  115. if rpmStartUp == rpmmaxframe and SpeedStartUp == speedmaxframe then
  116. display.text{
  117. text = "DASH READY",
  118. pos = vec2(1820,1190),
  119. letter = vec2(20, 40):scale(2),
  120. font = "fonts/340i",
  121. color = rgbm.colors.green,
  122. alignment = 0,
  123. width = 1000,
  124. spacing = 0
  125. }
  126. setTimeout(function () dashReady = true end, 2.5)
  127. else
  128. display.text{
  129. text = " DASH \nINITIALISING",
  130. pos = vec2(1660,1190),
  131. letter = vec2(20, 40):scale(2),
  132. font = "fonts/340i",
  133. color = rgbm.colors.white,
  134. alignment = 1,
  135. width = 1000,
  136. spacing = 0
  137. }
  138. end
  139. end
  140.  
  141. ----- Current Music that"s playing -----
  142. if dashReady then
  143. local music = ac.currentlyPlaying()
  144. if music.hasCover then
  145. display.image{
  146. image = music,
  147. pos = vec2(1840,1100),
  148. size = vec2(100,100):scale(3),
  149. color = rgbm.colors.white,
  150. uvStart = vec2(0, 0),
  151. uvEnd = vec2(1, 1)
  152. }
  153. end
  154. display.text{
  155. text = music.title,
  156. pos = vec2(1600,1450),
  157. letter = vec2(20, 40):scale(1.8),
  158. font = "e92_big",
  159. color = rgbm.colors.white,
  160. alignment = 0.5,
  161. width = 800,
  162. spacing = 0
  163. }
  164. display.text{
  165. text = music.artist,
  166. pos = vec2(1600,1520),
  167. letter = vec2(20, 40):scale(1.2),
  168. font = "e92_big",
  169. color = rgbm.colors.red,
  170. alignment = 0.5,
  171. width = 800,
  172. spacing = 0
  173. }
  174. display.horizontalBar({
  175. text = "",
  176. pos = vec2(1700,1580),
  177. size = vec2(600, 10),
  178. delta = 0,
  179. activeColor = rgbm(0.5,0.2,0, 1),
  180. inactiveColor = rgbm.colors.transparent,
  181. total = 100,
  182. active = math.floor(math.lerpInvSat(music.trackPosition,0,music.trackDuration)*100)
  183. })
  184. end
  185. ----- speed -----
  186. display.text {
  187. text = math.round(car.speedKmh, 0),
  188. pos = vec2(1060,1190),
  189. color = rgbm(1,1,1,1),
  190. letter = vec2(95, 100),
  191. font = "e92_big",
  192. width = 200,
  193. alignment = 1
  194. }
  195. ----- S next to gear -----
  196. display.text {
  197. text = "S",
  198. pos = vec2(2575,1190),
  199. color = rgbm(1,1,1,1),
  200. letter = vec2(95, 100),
  201. font = "fonts/340i",
  202. width = 200,
  203. alignment = 1
  204. }
  205.  
  206. ----- draw the current gear but looking in the table created at the start. Much faster than before -----
  207. display.text {
  208. text = gearT[car.gear],
  209. pos = vec2(2665,1190),
  210. color = rgbm(1,1,1,1),
  211. letter = vec2(95, 100),
  212. font = "fonts/340i",
  213. width = 200,
  214. alignment = 1
  215. }
  216.  
  217. ui.drawImage("./assets/icons/gaz_icon.png", vec2(745, 1625) ,vec2(745+38, 1625+38) , rgbm(1,1,1,1))
  218.  
  219. if car.fuelPerLap ~= 0 then
  220. display.text {
  221. text = distance,
  222. pos = vec2(786, 1622),
  223. color = rgbm(1,1,1,1),
  224. letter = vec2(45, 55),
  225. font = "fonts/m4_font",
  226. width = 100,
  227. alignment = 1
  228. }
  229. else
  230. display.text {
  231. text = "500",
  232. pos = vec2(786, 1622),
  233. color = rgbm(1,1,1,1),
  234. letter = vec2(45, 55),
  235. font = "fonts/m4_font",
  236. width = 100,
  237. alignment = 1
  238. }
  239.  
  240. display.text {
  241. text = "km",
  242. pos = vec2(900, 1618),
  243. color = rgbm(1,1,1,1),
  244. letter = vec2(45, 200),
  245. font = "fonts/arial_hd",
  246. width = 100,
  247. alignment = 1
  248. }
  249. end
  250.  
  251. --clock?
  252. display.text {
  253. text = time,
  254. pos = vec2(1070, 1622),
  255. color = rgbm(1,1,1,1),
  256. letter = vec2(45, 55),
  257. font = "fonts/m4_font",
  258. width = 100,
  259. alignment = 1
  260. }
  261.  
  262. display.rect {
  263. pos = vec2(2870, 1635),
  264. size = vec2(250, 60),
  265. color = rgbm(0, 0, 0, 1)
  266. }
  267.  
  268. ----- outside temp ------
  269. local temp = "+" .. sim.ambientTemperature
  270. ui.drawRectFilled(vec2(2900, 1630),vec2(3130, 1695),rgbm(0,0,0,0.5), 20)
  271. display.text {
  272. text = temp,
  273. pos = vec2(2920, 1610),
  274. color = rgbm(1,1,1,1),
  275. letter = vec2(35, 70):scale(1.5),
  276. font = "bmw",
  277. width = 100,
  278. alignment = 1
  279. }
  280. display.text {
  281. text = " @",
  282. pos = vec2(3040, 1630),
  283. color = rgbm(0.9,0.9,0.9,1),
  284. letter = vec2(20, 60):scale(1.4),
  285. font = "e92_big",
  286. width = 100,
  287. alignment = 1
  288. }
  289.  
  290. ----- speedlimit -----
  291. local speedLimPos = vec2(1320, speedLimPosVert)
  292. if car.isInPitlane and speedLimPosVert > 1480 and not speedLimPosAnim then
  293. speedLimPosVert = speedLimPosVert - 10
  294.  
  295. ui.drawImage(Icons.SPEEDLIMIT, speedLimPos, vec2(speedLimPos.x+125,speedLimPos.y+125),rgbm.colors.white,vec2(0,0), vec2(1,1),true)
  296. display.text{
  297. text = car.speedLimiter,
  298. pos = vec2(speedLimPos.x+15, speedLimPos.y+25),
  299. color = rgbm(0,0,0,1),
  300. letter = vec2(20, 50):scale(1.6),
  301. font = "bmw",
  302. width = 100,
  303. alignment = 0.5
  304. }
  305. if speedLimPosVert == 1480 then
  306. speedLimPosAnim = true
  307. end
  308. elseif car.isInPitlane and speedLimPosVert == 1480 then
  309. ui.drawImage(Icons.SPEEDLIMIT, vec2(1320, 1480), vec2(speedLimPos.x+125,speedLimPos.y+125),rgbm.colors.white,vec2(0,0), vec2(1,1),true)
  310. display.text{
  311. text = car.speedLimiter,
  312. pos = vec2(speedLimPos.x+15, speedLimPos.y+25),
  313. color = rgbm(0,0,0,1),
  314. letter = vec2(20, 50):scale(1.6),
  315. font = "bmw",
  316. width = 100,
  317. alignment = 0.5
  318. }
  319. elseif not car.isInPitlane and speedLimPosVert < 2000 and speedLimPosAnim then
  320. speedLimPosVert = speedLimPosVert + 10
  321.  
  322. ui.drawImage(Icons.SPEEDLIMIT, speedLimPos, vec2(speedLimPos.x+125,speedLimPos.y+125),rgbm.colors.white,vec2(0,0), vec2(1,1),true)
  323. display.text{
  324. text = car.speedLimiter,
  325. pos = vec2(speedLimPos.x+15, speedLimPos.y+25),
  326. color = rgbm(0,0,0,1),
  327. letter = vec2(20, 50):scale(1.6),
  328. font = "bmw",
  329. width = 100,
  330. alignment = 0.5
  331. }
  332. if speedLimPosVert == 2000 then
  333. speedLimPosAnim = false
  334. end
  335. end
  336.  
  337. ----- other icons -----
  338. if not car.lowBeams and car.headlightsActive then
  339. ui.drawImage(Icons.LIGHT_HIGHBEAM, vec2(510, 1218),vec2(510+80, 1218+80) , rgbm(0,0,255,1))
  340. end
  341. if car.headlightsActive then
  342. ui.drawImage(Icons.LIGHT_PARKING, vec2(510, 1418),vec2(510+80, 1418+80) , rgbm(0.1,1,0.1,1))
  343. end
  344.  
  345. if car.tractionControlInAction then
  346. setInterval(function() tractionControlInAction = not tractionControlInAction end, 0.15, "tractionControlInAction")
  347. lasttrue = os.clock()
  348. elseif (os.clock() - lasttrue > 0.5) then
  349. clearInterval("tractionControlInAction")
  350. tractionControlInAction = false
  351.  
  352. end
  353.  
  354. if car.tractionControlMode == 0 or tractionControlInAction then
  355. ui.drawImage(Icons.ESC, vec2(3445, 1423),vec2(3445+80, 1423+80) , rgbm(25,2,0,1))
  356. end
  357.  
  358. if not lasttrueTC then
  359. lasttrueTC = 0
  360. end
  361. if car.tractionControlInAction then
  362. setInterval(function() tractionControlInAction = not tractionControlInAction end, 0.15, "tractionControlInAction")
  363. lasttrueTC = os.clock()
  364. elseif (os.clock() - lasttrueTC > 0.5) then
  365. clearInterval("tractionControlInAction")
  366. tractionControlInAction = false
  367.  
  368. end
  369. if car.tractionControlMode == 0 or tractionControlInAction then
  370. ui.drawImage(Icons.ESC, vec2(3445, 1423),vec2(3445+80, 1423+80) , rgbm(25,2,0,1))
  371. end
  372. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement