forked from Quantx/CC2-UI-Enhancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_radar.lua
More file actions
executable file
·136 lines (113 loc) · 4.35 KB
/
screen_radar.lua
File metadata and controls
executable file
·136 lines (113 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
g_tick = 0
g_radius = 56
g_scan_increment_count = 64
g_scan_layer_count = 4
g_layer_colors = {
color8(255, 0, 0, 255),
color8(255, 255, 0, 255),
color8(0, 255, 0, 255),
color8(0, 0, 255, 255),
}
g_max_scan_distance = 400
g_depth_data = {}
g_scan_cursor = 1
function arc_position(x, y, radius, angle)
return (x + (radius * math.cos(angle - (math.pi * 0.5)))), (y + (radius * math.sin(angle - (math.pi * 0.5))))
end
function parse()
end
function begin()
begin_load()
g_depth_data = {}
g_scan_cursor = 1
for i=1, g_scan_layer_count do
g_depth_data[i] = {}
for j=1, g_scan_increment_count do
local scan_angle = math.pi * 2 * (j - 1) / g_scan_increment_count
local ax, ay = arc_position(64, 64, g_radius, scan_angle)
g_depth_data[i][j] =
{
depth = g_max_scan_distance,
nx = ax,
ny = ay,
fx = ax,
fy = ay,
}
end
end
end
function update(screen_w, screen_h, ticks)
g_tick = g_tick + ticks
g_scan_cursor = g_scan_cursor + ticks
local scan_angle = math.pi * 2 * (g_scan_cursor - 1) / g_scan_increment_count
if g_scan_cursor > g_scan_increment_count then
g_scan_cursor = 1
end
if update_screen_overrides(screen_w, screen_h, ticks) then return end
local this_vehicle = update_get_screen_vehicle()
if this_vehicle:get() then
local this_vehicle_object = update_get_vehicle_by_id(this_vehicle:get_id())
if this_vehicle_object:get() then
if this_vehicle_object:get_sensor_count() > 0 then
for i=1, g_scan_layer_count do
g_depth_data[i][g_scan_cursor].depth = math.min(g_max_scan_distance, this_vehicle_object:get_carrier_raycast(scan_angle, -0.02 * i))
local nx, ny = arc_position(64, 64, g_depth_data[i][g_scan_cursor].depth * (g_radius - 1) / g_max_scan_distance, scan_angle)
g_depth_data[i][g_scan_cursor].nx = nx
g_depth_data[i][g_scan_cursor].ny = ny
end
end
end
end
local min_distance = g_max_scan_distance
for j=1, g_scan_increment_count do
min_distance = math.min(min_distance, g_depth_data[g_scan_layer_count][j].depth)
end
for i=g_scan_layer_count, 1, -1 do
update_ui_begin_triangles()
for j=1, g_scan_increment_count do
local cursor_next = (j + ticks)
if cursor_next > g_scan_increment_count then
cursor_next = 1
end
local v0 = vec2(g_depth_data[i][j].nx, g_depth_data[i][j].ny)
local v1 = vec2(g_depth_data[i][j].fx, g_depth_data[i][j].fy)
local v2 = vec2(g_depth_data[i][cursor_next].fx, g_depth_data[i][cursor_next].fy)
local v3 = vec2(g_depth_data[i][cursor_next].nx, g_depth_data[i][cursor_next].ny)
update_ui_add_triangle(v0, v1, v2, g_layer_colors[i])
update_ui_add_triangle(v2, v3, v0, g_layer_colors[i])
end
update_ui_end_triangles()
end
local ax, ay = arc_position(64, 64, g_radius, scan_angle)
update_ui_line(64, 64, ax, ay, color_white)
local warning_blink_rate = iff(min_distance < 50, 10, 30)
local is_pulse_warning = g_tick % warning_blink_rate == math.floor(warning_blink_rate / 2)
local is_blink_warning = g_tick % warning_blink_rate > math.floor(warning_blink_rate / 2)
local warning_sound = 7
if min_distance < 50 then
if is_blink_warning then
update_ui_rectangle(11, 105, 106, 14, color_status_bad)
update_ui_text(0, 108, update_get_loc(e_loc.upp_collision), 128, 1, color_black, 0)
end
if is_pulse_warning then
update_play_sound(warning_sound)
end
elseif min_distance < 100 then
if is_blink_warning then
update_ui_rectangle(11, 105, 106, 14, color_status_warning)
update_ui_text(0, 108, update_get_loc(e_loc.upp_warning), 128, 1, color_black, 0)
end
if is_pulse_warning then
update_play_sound(warning_sound)
end
end
end
function input_event(event, action)
if action == e_input_action.release then
if event == e_input.back then
update_set_screen_state_exit()
end
end
end
function input_axis(x, y, z, w)
end