Guest User

Untitled

a guest
Sep 24th, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. -- DON'T TOUCH ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
  3. --------------------------------------------------------------------------------
  4. local compass_offset_inches = compass_offset_feet * 12
  5. local compass_radius_inches = compass_radius_feet * 12
  6. local WINDOW_NAME_TEMPLATE = "T_Compass3D_Point"
  7.  
  8. --------------------------------------------------------------------------------
  9. -- Core
  10. --------------------------------------------------------------------------------
  11. Compass3D = Compass3D or {}
  12.  
  13. function Compass3D.OnInitialize()
  14. Compass3D.Camera.OnInitialize()
  15.  
  16. for i = 1, #compass_windows do
  17. local w = compass_windows[i]
  18.  
  19. -- Create UI element
  20. CreateWindowFromTemplate(w.name, WINDOW_NAME_TEMPLATE, "Root")
  21. WindowSetShowing(w.name, true)
  22. WindowSetScale(w.name, w.scale * InterfaceCore.GetScale())
  23. WindowSetTintColor(w.name, w.red, w.green, w.blue)
  24.  
  25. -- Set icon
  26. local texture, tx, ty = GetIconData(w.icon)
  27. DynamicImageSetTexture(w.name .. "_Icon", texture, tx, ty)
  28.  
  29. w.offset_x = w.direction_x * compass_radius_inches
  30. w.offset_y = w.direction_y * compass_radius_inches
  31. end
  32. end
  33.  
  34. function Compass3D.OnShutdown()
  35. Compass3D.Camera.OnShutdown()
  36. for i = 1, #compass_windows do
  37. DestroyWindow(compass_windows[i].name)
  38. end
  39. end
  40.  
  41. function Compass3D.OnUpdate(time_delta_s)
  42. local camera_pivot_x, camera_pivot_y, camera_pivot_z, camera_pivot_zone_id = Compass3D.Camera.GetPivotZonePosition()
  43.  
  44. -- Hide all points if camera is unavailable
  45. if not camera_pivot_x then
  46. for i = 1, #compass_windows do
  47. WindowSetAlpha(compass_windows[i].name, 0)
  48. end
  49. return
  50. end
  51.  
  52. -- Convert screen dimensions to UI-logical pixels
  53. local screen_width, screen_height = GetScreenResolution()
  54. screen_width = screen_width / InterfaceCore.GetScale()
  55. screen_height = screen_height / InterfaceCore.GetScale()
  56. local center_x, center_y = screen_width * 0.5, screen_height * 0.5
  57.  
  58. -- Update every compass point
  59. for i = 1, #compass_windows do
  60. local window = compass_windows[i]
  61.  
  62. -- Calculate world-space position
  63. local world_x = camera_pivot_x + window.offset_x
  64. local world_y = camera_pivot_y + window.offset_y
  65. local world_z = camera_pivot_z + compass_offset_inches
  66.  
  67. -- Project to screen
  68. local visible, screen_x, screen_y = WorldToScreen(world_x, world_y, world_z)
  69. screen_x = screen_x / InterfaceCore.GetScale()
  70. screen_y = screen_y / InterfaceCore.GetScale()
  71.  
  72. -- Set alpha (0 if not visible or off-screen)
  73. local new_alpha = (visible and
  74. screen_x >= 0 and screen_x <= screen_width and
  75. screen_y >= 0 and screen_y <= screen_height)
  76. and window.alpha or 0
  77.  
  78. WindowSetAlpha(window.name, new_alpha)
  79.  
  80. -- Update position if visible
  81. if new_alpha > 0 then
  82. WindowClearAnchors(window.name)
  83. WindowAddAnchor(window.name, "center", "Root", "center",
  84. screen_x - center_x, screen_y - center_y)
  85. end
  86. end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment