-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathscreen_holomap.lua
More file actions
1975 lines (1542 loc) · 82 KB
/
Copy pathscreen_holomap.lua
File metadata and controls
1975 lines (1542 loc) · 82 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
g_colors = {
backlight_default = color8(0, 2, 10, 255),
glow_default = color8(64, 204, 255, 255),
island_low_default = color8(0, 32, 64, 255),
island_high_default = color8(0, 255, 255, 255),
base_layer_default = color8(0, 5, 5, 255),
grid_1_default = color8(0, 123, 201, 255),
grid_2_default = color8(0, 26, 52, 128),
holo = color8(0, 255, 255, 255),
good = color8(0, 128, 255, 255),
bad = color_status_bad
}
g_map_x = 0
g_map_z = 0
g_map_size = 2000
g_map_x_offset = 0
g_map_z_offset = 0
g_map_size_offset = 0
g_button_mode = 0
g_is_map_pos_initialised = false
g_override = false
g_override_x = -64000
g_override_z = -64000
g_override_zoom = 16000
g_ui = nil
g_is_render_holomap = true
g_is_render_holomap_tiles = true
g_is_render_holomap_vehicles = true
g_is_render_holomap_missiles = true
g_is_render_holomap_grids = true
g_is_render_holomap_backlight = true
g_is_render_team_capture = true
g_is_override_holomap_island_color = false
g_holomap_override_island_color_low = g_colors.island_low_default
g_holomap_override_island_color_high = g_colors.island_high_default
g_holomap_override_base_layer_color = g_colors.base_layer_default
g_holomap_backlight_color = g_colors.backlight_default
g_holomap_glow_color = g_colors.glow_default
g_holomap_grid_1_color = g_colors.grid_1_default
g_holomap_grid_2_color = g_colors.grid_2_default
g_blend_tick = 0
g_prev_pos_x = 0
g_prev_pos_y = 0
g_prev_size = (64 * 1024)
g_next_pos_x = 0
g_next_pos_y = 0
g_next_size = (64 * 1024)
g_is_pointer_hovered = false
g_pointer_pos_x = 0
g_pointer_pos_y = 0
g_pointer_pos_x_prev = 0
g_pointer_pos_y_prev = 0
g_is_pointer_pressed = false
g_is_mouse_mode = false
g_startup_op_num = 0
g_startup_phase = 0
g_startup_phase_anim = 0
holomap_startup_phases = {
memchk = 0,
bios = 1,
sys = 2,
manual = 3,
finish = 4
}
g_is_ruler = false
g_is_ruler_set = false
g_ruler_x = 0
g_ruler_y = 0
g_highlighted_waypoint_id = 0
g_highlighted_vehicle_id = 0
g_selection_vehicle_id = 0
g_selected_bay_index = -1
g_color_attack_order = color_status_dark_red
g_color_airlift_order = color_status_ok
g_color_waypoint = color8(0, 255, 255, 8)
g_is_dismiss_pressed = false
g_animation_time = 0
g_dismiss_counter = 0
g_dismiss_duration = 20
g_notification_time = 0
g_focus_mode = 0
function parse()
g_prev_pos_x = g_next_pos_x
g_prev_pos_y = g_next_pos_y
g_prev_size = g_next_size
g_blend_tick = 0
g_is_map_pos_initialised = parse_bool("is_map_init", g_is_map_pos_initialised)
g_next_pos_x = parse_f32("map_x", g_next_pos_x)
g_next_pos_y = parse_f32("map_y", g_next_pos_y)
g_next_size = parse_f32("map_size", g_next_size)
-- End of original parse calls
g_is_mouse_mode = parse_bool("", g_is_mouse_mode)
g_is_ruler = parse_bool("", g_is_ruler)
g_ruler_x = parse_f32("", g_ruler_x)
g_ruler_y = parse_f32("", g_ruler_y)
g_highlighted_waypoint_id = parse_s32("", g_highlighted_waypoint_id)
g_highlighted_vehicle_id = parse_s32("", g_highlighted_vehicle_id)
g_selection_vehicle_id = parse_s32("map_selection", g_selection_vehicle_id)
g_selected_bay_index = parse_s32("", g_selected_bay_index)
end
function begin()
g_ui = lib_imgui:create_ui()
begin_load()
begin_load_inventory_data()
g_next_pos_x = parse_f32(g_next_pos_x)
g_next_pos_y = parse_f32(g_next_pos_y)
g_next_size = parse_f32(g_next_size)
end
function update(screen_w, screen_h, ticks)
g_is_mouse_mode = update_get_active_input_type() == e_active_input.keyboard
g_animation_time = g_animation_time + ticks
local screen_vehicle = update_get_screen_vehicle()
local screen_team = update_get_screen_team_id()
local is_local = update_get_is_focus_local()
local world_x = 0
local world_y = 0
local drydock, waypoint = get_team_drydock()
if is_local then
if not g_is_mouse_mode then
g_pointer_pos_x = screen_w / 2
g_pointer_pos_y = screen_h / 2
end
world_x, world_y = get_world_from_holomap( g_pointer_pos_x, g_pointer_pos_y, screen_w, screen_h )
if drydock ~= nil then
drydock:clear_waypoints()
drydock:add_waypoint(world_x, world_y)
waypoint = nil
end
elseif waypoint ~= nil then
local waypoint_pos = waypoint:get_position_xz()
world_x = waypoint_pos:x()
world_y = waypoint_pos:y()
g_pointer_pos_x, g_pointer_pos_y = get_holomap_from_world( world_x, world_y, screen_w, screen_h )
end
if g_focus_mode ~= 0 then
if g_focus_mode == 1 then
focus_carrier()
elseif g_focus_mode == 2 then
focus_world()
end
g_startup_phase = holomap_startup_phases.finish
g_focus_mode = 0
end
if holomap_override(screen_w, screen_h, ticks) then
-- if g_is_mouse_mode and is_local then
-- render_cursor(world_x, world_y, screen_w, screen_h)
-- end
return
end
local function step(a, b, c)
return a + clamp(b - a, -c, c)
end
if g_map_size_offset > 0 then
g_map_x_offset = lerp(g_map_x_offset, 0, 0.15)
g_map_z_offset = lerp(g_map_z_offset, 0, 0.15)
if math.abs(g_map_x_offset) < 1000 then
g_map_size_offset = step(g_map_size_offset, 0, 4000)
end
else
g_map_size_offset = step(g_map_size_offset, 0, 4000)
if math.abs(g_map_size_offset) < 1000 then
g_map_x_offset = lerp(g_map_x_offset, 0, 0.15)
g_map_z_offset = lerp(g_map_z_offset, 0, 0.15)
end
end
if g_is_map_pos_initialised == false then
g_is_map_pos_initialised = true
if screen_vehicle:get() and screen_vehicle:get_dock_state() == e_vehicle_dock_state.docked then
local pos = screen_vehicle:get_position_xz()
g_map_x = pos:x()
g_map_z = pos:y()
g_map_size = 5000
focus_world()
end
end
update_add_ui_interaction_special(update_get_loc(e_loc.interaction_pan), e_ui_interaction_special.map_pan)
update_add_ui_interaction_special(update_get_loc(e_loc.interaction_zoom), e_ui_interaction_special.map_zoom)
update_add_ui_interaction(update_get_loc(e_loc.interaction_bearing), e_game_input.interact_a)
if screen_vehicle:get() and screen_vehicle:get_dock_state() ~= e_vehicle_dock_state.docked then
if not g_is_mouse_mode and g_highlighted_vehicle_id > 0 and g_highlighted_waypoint_id == 0 then
local vehicle = update_get_map_vehicle_by_id(g_highlighted_vehicle_id)
if g_highlighted_vehicle_id == screen_vehicle:get_id() then
update_add_ui_interaction(update_get_loc(e_loc.interaction_carrier), e_game_input.interact_b)
elseif vehicle:get() and vehicle:get_team() == screen_team then
update_add_ui_interaction(update_get_loc(e_loc.interaction_vehicle), e_game_input.interact_b)
end
elseif g_highlighted_vehicle_id == screen_vehicle:get_id() then
if g_highlighted_waypoint_id > 0 then
update_add_ui_interaction("remove carrier waypoint", e_game_input.interact_b)
elseif g_is_mouse_mode then
update_add_ui_interaction("remove all carrier waypoints", e_game_input.interact_b)
end
else
update_add_ui_interaction("set carrier waypoint", e_game_input.interact_b)
end
end
if is_local then
g_next_pos_x = g_map_x
g_next_pos_y = g_map_z
g_next_size = g_map_size
else
g_blend_tick = g_blend_tick + ticks
local blend_factor = clamp(g_blend_tick / 10.0, 0.0, 1.0)
g_map_x = lerp(g_prev_pos_x, g_next_pos_x, blend_factor)
g_map_z = lerp(g_prev_pos_y, g_next_pos_y, blend_factor)
g_map_size = lerp(g_prev_size, g_next_size, blend_factor)
end
if is_local and (g_is_mouse_mode and g_is_pointer_hovered) and g_highlighted_vehicle_id == 0 and g_highlighted_waypoint_id == 0 and not update_get_is_notification_holomap_set() then
local pointer_dx = g_pointer_pos_x - g_pointer_pos_x_prev
local pointer_dy = g_pointer_pos_y - g_pointer_pos_y_prev
if g_is_pointer_pressed then
g_map_x = g_map_x - pointer_dx * g_map_size * 0.005
g_map_z = g_map_z + pointer_dy * g_map_size * 0.005
end
end
update_set_screen_background_type(g_button_mode + 1)
update_set_screen_background_is_render_islands(false)
update_set_screen_map_position_scale(g_map_x + g_map_x_offset, g_map_z + g_map_z_offset, g_map_size + g_map_size_offset)
g_is_render_holomap = true
g_is_render_holomap_tiles = true
g_is_render_holomap_vehicles = true
g_is_render_holomap_missiles = true
g_is_render_holomap_grids = true
g_is_render_holomap_backlight = true
g_is_render_team_capture = true
g_is_override_holomap_island_color = false
g_holomap_override_island_color_low = g_colors.island_low_default
g_holomap_override_island_color_high = g_colors.island_high_default
g_holomap_override_base_layer_color = g_colors.base_layer_default
g_holomap_backlight_color = g_colors.backlight_default
g_holomap_glow_color = g_colors.glow_default
g_holomap_grid_1_color = g_colors.grid_1_default
g_holomap_grid_2_color = g_colors.grid_2_default
update_ui_rectangle(0, 0, screen_w, screen_h, color8(0, 0, 0, 220))
g_ui:begin_ui()
if update_get_is_notification_holomap_set() then
g_notification_time = g_notification_time + ticks
update_set_screen_background_type(0)
update_set_screen_background_is_render_islands(false)
local notification = update_get_notification_holomap()
local notification_col = get_notification_color(notification)
g_holomap_backlight_color = color8(notification_col:r(), notification_col:g(), notification_col:b(), 10)
g_holomap_glow_color = notification_col
local border_col = notification_col
local border_padding = 8
local border_thickness = 4
local border_w = 32
local border_h = 24
update_ui_rectangle(border_padding, border_padding, border_w, border_thickness, border_col)
update_ui_rectangle(border_padding, border_padding, border_thickness, border_h, border_col)
update_ui_rectangle(screen_w - border_padding - border_w, border_padding, border_w, border_thickness, border_col)
update_ui_rectangle(screen_w - border_padding - border_thickness, border_padding, border_thickness, border_h, border_col)
update_ui_rectangle(border_padding, screen_h - border_padding - border_thickness, border_w, border_thickness, border_col)
update_ui_rectangle(border_padding, screen_h - border_padding - border_h, border_thickness, border_h, border_col)
update_ui_rectangle(screen_w - border_padding - border_w, screen_h - border_padding - border_thickness, border_w, border_thickness, border_col)
update_ui_rectangle(screen_w - border_padding - border_thickness, screen_h - border_padding - border_h, border_thickness, border_h, border_col)
if notification:get() then
render_notification_display(screen_w, screen_h, notification)
end
local is_dismiss = g_is_dismiss_pressed or (g_is_pointer_pressed and g_is_pointer_hovered and g_is_mouse_mode)
if g_notification_time >= 30 then
local color_dismiss = color_white
update_ui_push_offset(screen_w / 2, screen_h - 34)
if is_dismiss then
local dismiss_factor = clamp(g_dismiss_counter / g_dismiss_duration, 0, 1)
update_ui_rectangle(-30, -2, 60 * dismiss_factor, 13, color_dismiss)
end
update_ui_rectangle_outline(-30, -2, 60, 13, iff(is_dismiss, color_dismiss, iff(g_animation_time % 20 > 10, color_white, color_black)))
update_ui_text(-30, 0, update_get_loc(e_loc.upp_dismiss), 60, 1, iff(is_dismiss, color_dismiss, color_white), 0)
update_ui_pop_offset()
end
if is_dismiss then
g_dismiss_counter = g_dismiss_counter + ticks
else
g_dismiss_counter = 0
end
if g_dismiss_counter > g_dismiss_duration then
g_dismiss_counter = 0
g_is_dismiss_pressed = false
g_is_pointer_pressed = false
update_map_dismiss_notification()
end
else
local vehicle_count = update_get_map_vehicle_count()
local cur_map_zoom = g_map_size + g_map_size_offset
-- draw island names
if cur_map_zoom < 95000 then
local island_count = update_get_tile_count()
for i = 0, island_count - 1, 1 do
local island = update_get_tile_by_index(i)
if island ~= nil and island:get() then
local island_color = update_get_team_color(island:get_team_control())
local island_pos = island:get_position_xz()
local island_size = island:get_size()
local screen_pos_x = 0
local screen_pos_y = 0
if cur_map_zoom < 16000 then
screen_pos_x, screen_pos_y = get_holomap_from_world(island_pos:x(), island_pos:y() + (island_size:y() / 2), screen_w, screen_h)
else
screen_pos_x, screen_pos_y = get_holomap_from_world(island_pos:x(), island_pos:y(), screen_w, screen_h)
screen_pos_y = screen_pos_y - 27
end
local command_center_count = island:get_command_center_count()
if command_center_count > 0 then
--local command_center_position = island:get_command_center_position(0)
--local cmd_pos_x, cmd_pos_y = get_holomap_from_world(command_center_position:x(), command_center_position:y(), screen_w, screen_h)
local island_capture = island:get_team_capture()
local island_team = island:get_team_control()
local island_capture_progress = island:get_team_capture_progress()
local team_color = update_get_team_color(island_capture)
if island_capture ~= island_team and island_capture ~= -1 and island_capture_progress > 0 then
update_ui_rectangle(screen_pos_x - 13, screen_pos_y - 16, 26, 5, color_black)
update_ui_rectangle(screen_pos_x - 12, screen_pos_y - 15, 24 * island_capture_progress, 3, team_color)
end
end
update_ui_text(screen_pos_x - 64, screen_pos_y, island:get_name(), 128, 1, island_color, 0)
local category_data = g_item_categories[island:get_facility_category()]
if island:get_team_control() ~= screen_team then
local difficulty_level = island:get_difficulty_level() + 2
local icon_w = 6
local icon_spacing = 2
local total_w = icon_w * difficulty_level + icon_spacing * (difficulty_level - 1)
for i = 0, difficulty_level - 1 do
if i == 0 then
update_ui_image(screen_pos_x - total_w / 2 + (icon_w + icon_spacing) * i, screen_pos_y + 10, category_data.icon, island_color, 0)
elseif i >= 2 then
update_ui_image(screen_pos_x - total_w / 2 + (icon_w + icon_spacing) * i, screen_pos_y + 10, atlas_icons.column_difficulty, island_color, 0)
end
end
else
update_ui_image(screen_pos_x - 4, screen_pos_y + 10, category_data.icon, island_color, 0)
end
end
end
end
-- find hovered vehilce or waypoint
if is_local and (not g_is_mouse_mode or g_is_pointer_hovered) then
g_highlighted_vehicle_id = 0
g_highlighted_waypoint_id = 0
local highlighted_distance_best = 4 * math.max( 1, 2000 / cur_map_zoom )
for i = 0, vehicle_count - 1, 1 do
local vehicle = update_get_map_vehicle_by_index(i)
if vehicle:get() then
local vehicle_definition_index = vehicle:get_definition_index()
if vehicle_definition_index ~= e_game_object_type.chassis_spaceship and vehicle_definition_index ~= e_game_object_type.drydock then
local vehicle_team = vehicle:get_team()
local vehicle_attached_parent_id = vehicle:get_attached_parent_id()
if vehicle_attached_parent_id == 0 and vehicle:get_is_visible() and vehicle:get_is_observation_revealed() then
local vehicle_pos_xz = vehicle:get_position_xz()
local screen_pos_x, screen_pos_y = get_holomap_from_world(vehicle_pos_xz:x(), vehicle_pos_xz:y(), screen_w, screen_h)
local vehicle_distance_to_cursor = vec2_dist( vec2( screen_pos_x, screen_pos_y ), vec2( g_pointer_pos_x, g_pointer_pos_y ) )
if vehicle_distance_to_cursor < highlighted_distance_best then
g_highlighted_vehicle_id = vehicle:get_id()
g_highlighted_waypoint_id = 0
highlighted_distance_best = vehicle_distance_to_cursor
end
end
if vehicle_team == screen_team then
local waypoint_count = vehicle:get_waypoint_count()
for j = 0, waypoint_count - 1, 1 do
local waypoint = vehicle:get_waypoint(j)
local waypoint_type = waypoint:get_type()
if waypoint_type == e_waypoint_type.move or waypoint_type == e_waypoint_type.deploy then
local waypoint_pos = waypoint:get_position_xz(j)
local waypoint_screen_pos_x, waypoint_screen_pos_y = get_holomap_from_world(waypoint_pos:x(), waypoint_pos:y(), screen_w, screen_h)
local waypoint_distance_to_cursor = vec2_dist( vec2( waypoint_screen_pos_x, waypoint_screen_pos_y ), vec2( g_pointer_pos_x, g_pointer_pos_y ) )
if waypoint_distance_to_cursor < highlighted_distance_best then
g_highlighted_vehicle_id = vehicle:get_id()
g_highlighted_waypoint_id = waypoint:get_id()
highlighted_distance_best = waypoint_distance_to_cursor
end
end
end
end
end
end
end
end
-- render vehicle stuff
for i = 0, vehicle_count - 1, 1 do
local vehicle = update_get_map_vehicle_by_index(i)
local vehicle_pos_xz = vehicle:get_position_xz()
local screen_pos_x, screen_pos_y = get_holomap_from_world(vehicle_pos_xz:x(), vehicle_pos_xz:y(), screen_w, screen_h)
local vehicle_team = vehicle:get_team()
local vehicle_attached_parent_id = vehicle:get_attached_parent_id()
local vehicle_support_id = vehicle:get_supporting_vehicle_id()
local vehicle_definition_index = vehicle:get_definition_index()
local is_render_vehicle_icon = vehicle_attached_parent_id == 0
local waypoint_count = vehicle:get_waypoint_count()
local waypoint_pos_x_prev = screen_pos_x
local waypoint_pos_y_prev = screen_pos_y
if vehicle_team == screen_team and vehicle_definition_index ~= e_game_object_type.chassis_sea_barge and vehicle_definition_index ~= e_game_object_type.drydock then
local waypoint_remove = -1
local waypoint_color = g_color_waypoint
if g_highlighted_vehicle_id == vehicle:get_id() and g_highlighted_waypoint_id == 0 then
waypoint_color = color8(255, 255, 255, 255)
end
local vehicle_dock_state = vehicle:get_dock_state()
local vehicle_dock_queue_id = vehicle:get_dock_queue_vehicle_id()
if (vehicle_dock_state == e_vehicle_dock_state.dock_queue or vehicle_dock_state == e_vehicle_dock_state.docking) and vehicle_dock_queue_id ~= 0 and is_render_vehicle_icon then
local parent_vehicle = update_get_map_vehicle_by_id(vehicle_dock_queue_id)
if parent_vehicle:get() then
local parent_pos_xz = parent_vehicle:get_position_xz()
local parent_screen_pos_x, parent_screen_pos_y = get_holomap_from_world(parent_pos_xz:x(), parent_pos_xz:y(), screen_w, screen_h)
render_dashed_line(screen_pos_x, screen_pos_y, parent_screen_pos_x, parent_screen_pos_y, waypoint_color)
end
end
if vehicle_support_id ~= 0 then
local parent_vehicle = update_get_map_vehicle_by_id(vehicle_support_id)
if parent_vehicle:get() then
local parent_pos_xz = parent_vehicle:get_position_xz()
local parent_screen_pos_x, parent_screen_pos_y = get_holomap_from_world(parent_pos_xz:x(), parent_pos_xz:y(), screen_w, screen_h)
render_dashed_line(screen_pos_x, screen_pos_y, parent_screen_pos_x, parent_screen_pos_y, waypoint_color)
end
else
local waypoint_path = vehicle:get_waypoint_path()
local waypoint_start_index = 0
-- Computed path to next waypoint
if #waypoint_path > 0 then
waypoint_start_index = 1
for i = 1, #waypoint_path do
local waypoint_screen_pos_x, waypoint_screen_pos_y = get_holomap_from_world(waypoint_path[i]:x(), waypoint_path[i]:y(), screen_w, screen_h)
update_ui_line(waypoint_pos_x_prev, waypoint_pos_y_prev, waypoint_screen_pos_x, waypoint_screen_pos_y, waypoint_color)
update_ui_rectangle(waypoint_screen_pos_x - 1, waypoint_screen_pos_y - 1, 2, 2, waypoint_color)
waypoint_pos_x_prev = waypoint_screen_pos_x
waypoint_pos_y_prev = waypoint_screen_pos_y
end
if waypoint_count > 0 then
local waypoint = vehicle:get_waypoint(0)
local waypoint_pos = waypoint:get_position_xz()
local path_end_x, path_end_y = get_holomap_from_world(waypoint_pos:x(), waypoint_pos:y(), screen_w, screen_h)
update_ui_line(waypoint_pos_x_prev, waypoint_pos_y_prev, path_end_x, path_end_y, waypoint_color)
end
end
waypoint_pos_x_prev = screen_pos_x
waypoint_pos_y_prev = screen_pos_y
if is_render_vehicle_icon == false then
if vehicle_attached_parent_id ~= 0 then
local parent_vehicle = update_get_map_vehicle_by_id(vehicle_attached_parent_id)
if parent_vehicle:get() then
local parent_vehicle_pos_xz = parent_vehicle:get_position_xz()
waypoint_pos_x_prev, waypoint_pos_y_prev = get_holomap_from_world(parent_vehicle_pos_xz:x(), parent_vehicle_pos_xz:y(), screen_w, screen_h)
end
end
end
-- Draw waypoint lines
for j = 0, waypoint_count - 1, 1 do
local waypoint = vehicle:get_waypoint(j)
local waypoint_pos = waypoint:get_position_xz()
local waypoint_screen_pos_x, waypoint_screen_pos_y = get_holomap_from_world(waypoint_pos:x(), waypoint_pos:y(), screen_w, screen_h)
if j >= waypoint_start_index then
update_ui_line(waypoint_pos_x_prev, waypoint_pos_y_prev, waypoint_screen_pos_x, waypoint_screen_pos_y, waypoint_color)
end
waypoint_pos_x_prev = waypoint_screen_pos_x
waypoint_pos_y_prev = waypoint_screen_pos_y
local waypoint_repeat_index = waypoint:get_repeat_index(j)
if waypoint_repeat_index >= 0 then
local waypoint_repeat = vehicle:get_waypoint(waypoint_repeat_index)
local waypoint_repeat_pos = waypoint_repeat:get_position_xz()
local repeat_screen_pos_x, repeat_screen_pos_y = get_holomap_from_world(waypoint_repeat_pos:x(), waypoint_repeat_pos:y(), screen_w, screen_h)
update_ui_line(waypoint_screen_pos_x, waypoint_screen_pos_y, repeat_screen_pos_x, repeat_screen_pos_y, waypoint_color)
update_ui_image((waypoint_screen_pos_x + repeat_screen_pos_x) / 2 - 4, (waypoint_screen_pos_y + repeat_screen_pos_y) / 2 - 4, atlas_icons.map_icon_loop, waypoint_color, 0)
end
local attack_target_count = waypoint:get_attack_target_count()
for k = 0, attack_target_count - 1, 1 do
local is_valid = waypoint:get_attack_target_is_valid(k)
if is_valid then
local attack_target_pos = waypoint:get_attack_target_position_xz(k)
local attack_target_attack_type = waypoint:get_attack_target_attack_type(k)
local attack_target_icon = get_attack_type_icon(attack_target_attack_type)
local attack_target_screen_pos_x, attack_target_screen_pos_y = get_holomap_from_world(attack_target_pos:x(), attack_target_pos:y(), screen_w, screen_h)
local color = g_color_attack_order
if attack_target_attack_type == e_attack_type.airlift then
color = g_color_airlift_order
end
update_ui_line(waypoint_screen_pos_x, waypoint_screen_pos_y, attack_target_screen_pos_x, attack_target_screen_pos_y, color)
update_ui_image(attack_target_screen_pos_x - 8, attack_target_screen_pos_y - 8, atlas_icons.map_icon_attack, color, 0)
update_ui_image(attack_target_screen_pos_x - 4, attack_target_screen_pos_y - 4 - 8, attack_target_icon, color, 0)
end
end
end
-- Draw waypoint icons
for j = 0, waypoint_count - 1, 1 do
local waypoint = vehicle:get_waypoint(j)
local waypoint_pos = waypoint:get_position_xz()
local waypoint_distance = vec2_dist( vehicle_pos_xz, waypoint_pos )
if vehicle_definition_index == e_game_object_type.chassis_carrier and waypoint_distance < 500 then
waypoint_remove = j
end
local waypoint_screen_pos_x, waypoint_screen_pos_y = get_holomap_from_world(waypoint_pos:x(), waypoint_pos:y(), screen_w, screen_h)
local waypoint_color = g_color_waypoint
local is_group_a = waypoint:get_is_wait_group(0)
local is_group_b = waypoint:get_is_wait_group(1)
local is_group_c = waypoint:get_is_wait_group(2)
local is_group_d = waypoint:get_is_wait_group(3)
local group_text = ""
if is_group_a then group_text = group_text..update_get_loc(e_loc.upp_acronym_alpha) end
if is_group_b then group_text = group_text..update_get_loc(e_loc.upp_acronym_beta) end
if is_group_c then group_text = group_text..update_get_loc(e_loc.upp_acronym_charlie) end
if is_group_d then group_text = group_text..update_get_loc(e_loc.upp_acronym_delta) end
local is_group = (is_group_a or is_group_b or is_group_c or is_group_d)
local is_deploy = waypoint:get_type() == e_waypoint_type.deploy
if g_highlighted_vehicle_id == vehicle:get_id() and g_highlighted_waypoint_id == 0 then
waypoint_color = color8(255, 255, 255, 255)
elseif g_highlighted_vehicle_id == vehicle:get_id() and g_highlighted_waypoint_id == waypoint:get_id() then
waypoint_color = color8(255, 255, 255, 255)
elseif is_deploy then
waypoint_color = g_color_airlift_order
elseif is_group then
waypoint_color = g_color_attack_order
end
update_ui_image(waypoint_screen_pos_x - 4, waypoint_screen_pos_y - 4, atlas_icons.map_icon_waypoint, waypoint_color, 0)
if is_deploy then
update_ui_image(waypoint_screen_pos_x - 4, waypoint_screen_pos_y - 11, atlas_icons.icon_deploy_vehicle, waypoint_color, 0)
elseif is_group then
update_ui_text(waypoint_screen_pos_x - 64, waypoint_screen_pos_y - 13, group_text, 128, 1, waypoint_color, 0)
end
end
end
local attack_target_type = vehicle:get_attack_target_type()
if attack_target_type ~= e_attack_type.none then
local attack_target_pos = vehicle:get_attack_target_position_xz()
local attack_target_attack_type = vehicle:get_attack_target_type()
local attack_target_icon = get_attack_type_icon(attack_target_attack_type)
local attack_target_screen_pos_x, attack_target_screen_pos_y = get_holomap_from_world(attack_target_pos:x(), attack_target_pos:y(), screen_w, screen_h)
local color = g_color_attack_order
if attack_target_attack_type == e_attack_type.airlift then
color = g_color_airlift_order
end
render_dashed_line(screen_pos_x, screen_pos_y, attack_target_screen_pos_x, attack_target_screen_pos_y, color)
update_ui_image(attack_target_screen_pos_x - 4, attack_target_screen_pos_y - 4, atlas_icons.map_icon_waypoint, color, 0)
update_ui_image(attack_target_screen_pos_x - 4, attack_target_screen_pos_y - 4 - 8, attack_target_icon, color, 0)
update_ui_text(attack_target_screen_pos_x - 4, attack_target_screen_pos_y - 4 - 8, attack_target_attack_type, 128, 0, color_black, 0)
end
-- Waypoint cleanup for the carrier
if waypoint_remove > -1 then
local waypoint_path = {}
for i = waypoint_remove + 1, waypoint_count - 1, 1 do
local waypoint = vehicle:get_waypoint(i)
waypoint_path[#waypoint_path + 1] = waypoint:get_position_xz()
end
vehicle:clear_waypoints()
for i = 1, #waypoint_path, 1 do
vehicle:add_waypoint(waypoint_path[i]:x(), waypoint_path[i]:y())
end
end
end
end
local cy = screen_h - 15
local cx = 15
local icon_col = color_grey_mid
local text_col = color_grey_mid
if g_is_ruler then
if is_local and not g_is_ruler_set and (not g_is_mouse_mode or g_is_pointer_hovered) then
g_ruler_x = world_x
g_ruler_y = world_y
g_is_ruler_set = true
end
local drag_x, drag_y = get_holomap_from_world(g_ruler_x, g_ruler_y, screen_w, screen_h)
local team_col = update_get_team_color(update_get_screen_team_id())
update_ui_circle(drag_x, drag_y, 2, 4, team_col)
update_ui_line(drag_x, drag_y, g_pointer_pos_x, g_pointer_pos_y, team_col)
local dist_screen = vec2_dist(vec2(drag_x, drag_y), vec2(g_pointer_pos_x, g_pointer_pos_y))
local angle = math.atan(g_pointer_pos_y - drag_y, g_pointer_pos_x - drag_x)
local bearing = 90 + angle / math.pi * 180
if bearing < 0 then bearing = bearing + 360 end
if dist_screen > 5 then
local function rotate(x, y, a)
local s = math.sin(a)
local c = math.cos(a)
return x * c - y * s, x * s + y * c
end
local rad = 10
if dist_screen > rad then
local step = math.pi / 180 * 20
local bearing_rad = bearing / 180 * math.pi
update_ui_push_offset(drag_x, drag_y)
update_ui_begin_triangles()
for a = 0, bearing_rad, step do
local a_next = math.min(bearing_rad, a + step)
local p0 = vec2(rotate(0, -rad, a))
local p1 = vec2(rotate(0, -rad, a_next))
update_ui_add_triangle(vec2(0, 0), p0, p1, mult_alpha(team_col, 0.1))
update_ui_line(math.floor(p0:x()), math.floor(p0:y()), math.floor(p1:x()), math.floor(p1:y()), team_col)
end
update_ui_end_triangles()
update_ui_pop_offset()
end
update_ui_push_offset(g_pointer_pos_x, g_pointer_pos_y)
update_ui_begin_triangles()
update_ui_add_triangle(vec2(rotate(0, 0, angle)), vec2(rotate(-10, -4, angle)), vec2(rotate(-10, 4, angle)), team_col)
update_ui_end_triangles()
update_ui_pop_offset()
end
-- Show bearing in lower left corner
update_ui_image(cx, cy, atlas_icons.column_angle, icon_col, 0)
update_ui_text(cx + 15, cy, string.format("%.0f deg", bearing), 100, 0, text_col, 0)
cy = cy - 10
-- Show bearing next to pointer
-- X offset makes the text appear next to a hovered island or unit, instead of overlapping.
local pointer_disp_x_offset = 10
local pointer_disp_x = g_pointer_pos_x + pointer_disp_x_offset
local pointer_disp_y = g_pointer_pos_y
update_ui_text(pointer_disp_x, pointer_disp_y, string.format("%.0f deg", bearing), 100, 0, text_col, 0)
pointer_disp_y = pointer_disp_y - 10
local dist = vec2_dist(vec2(g_ruler_x, g_ruler_y), vec2(world_x, world_y))
local dist_string = ""
if dist < 10000 then
dist_string = string.format("%.0f ", dist) .. update_get_loc(e_loc.acronym_meters)
else
dist_string = string.format("%.2f ", dist / 1000) .. update_get_loc(e_loc.acronym_kilometers)
end
-- Show distance in lower left corner
update_ui_image(cx, cy, atlas_icons.column_distance, icon_col, 0)
update_ui_text(cx + 15, cy, dist_string, 100, 0, text_col, 0)
cy = cy - 10
-- Show distance next to pointer
update_ui_text(pointer_disp_x, pointer_disp_y, dist_string, 100, 0, text_col, 0)
else
if g_highlighted_vehicle_id > 0 then
local highlighted_vehicle = update_get_map_vehicle_by_id(g_highlighted_vehicle_id)
if highlighted_vehicle:get() then
local vehicle_definition_index = highlighted_vehicle:get_definition_index()
if g_highlighted_waypoint_id > 0 then
local highlighted_waypoint = highlighted_vehicle:get_waypoint_by_id(g_highlighted_waypoint_id)
if get_is_vehicle_air(vehicle_definition_index) then
local alt_str = string.format( "%.0f ", highlighted_waypoint:get_altitude() ) .. update_get_loc(e_loc.acronym_meters)
local alt_width = update_ui_get_text_size(alt_str, 10000, 0) + 4
render_tooltip(10, 10, screen_w - 20, screen_h - 20, g_pointer_pos_x, g_pointer_pos_y, alt_width, 14, 10, function(w, h) update_ui_text(2, 2, alt_str, w - 4, 0, color_white, 0) end)
end
else
-- render vehicle tooltip
local peers = iff( highlighted_vehicle:get_team() == screen_team, get_vehicle_controlling_peers(highlighted_vehicle), {} )
local tool_height = 21 + (#peers * 10)
render_tooltip(10, 10, screen_w - 20, screen_h - 20, g_pointer_pos_x, g_pointer_pos_y, 128, tool_height, 10, function(w, h) render_vehicle_tooltip(w, h, highlighted_vehicle, peers) end)
if vehicle_definition_index ~= e_game_object_type.chassis_carrier then
if highlighted_vehicle:get_team() == screen_team or highlighted_vehicle:get_is_observation_weapon_revealed() then
local weapon_range = get_vehicle_weapon_range(highlighted_vehicle)
local vehicle_pos_xz = highlighted_vehicle:get_position_xz()
if weapon_range > 0 then
render_weapon_radius(vehicle_pos_xz:x(), vehicle_pos_xz:y(), weapon_range, screen_w, screen_h)
end
end
end
end
end
end
end
render_map_scale(screen_w, screen_h)
update_ui_text(cx, cy, "Y", 100, 0, icon_col, 0)
update_ui_text(cx + 15, cy, string.format("%.0f", world_y), 100, 0, text_col, 0)
cy = cy - 10
update_ui_text(cx, cy, "X", 100, 0, icon_col, 0)
update_ui_text(cx + 15, cy, string.format("%.0f", world_x), 100, 0, text_col, 0)
cy = cy - 10
local label_x = 24
local label_y = 16
local label_w = screen_w - 2 * label_x
local label_h = 10
update_ui_push_offset(label_x, label_y)
update_ui_rectangle(0, 0, label_w, label_h, color_black)
local now = update_get_logic_tick()
if g_button_mode == 0 then
update_ui_text(1, 1, "MISSION TIME: " .. format_time( now / 30 ), label_w, 0, color_white, 0)
-- draw timeline
local timeline_w = 100
update_ui_rectangle( label_w - timeline_w - 1, 1, timeline_w, 8, color_white )
update_ui_rectangle( label_w - timeline_w, 1, timeline_w - 2, 8, color_black )
update_ui_rectangle( label_w - timeline_w, label_h / 2 - 1, timeline_w - 2, 2, color_white )
update_ui_rectangle( label_w - timeline_w / 2, 1, 1, 8, color_white )
update_ui_push_clip( label_w - timeline_w, 0, timeline_w - 2, 10 )
local day_len = 54000 -- 30 minutes in ticks
local time = now - 8100 -- Time since midnight on the first day
local timeline_pos = label_w - ((timeline_w / day_len) * (time % day_len))
local cy = label_h / 2 - 4
local color_sun = color8( 255, 255, 0, 255 )
local color_moon = color8( 0, 0, 255, 255 )
update_ui_image(timeline_pos + timeline_w, cy, atlas_icons.map_icon_surface, color_moon, 0)
update_ui_image(timeline_pos + timeline_w / 2, cy, atlas_icons.map_icon_surface, color_sun, 0)
update_ui_image(timeline_pos, cy, atlas_icons.map_icon_surface, color_moon, 0)
update_ui_image(timeline_pos - timeline_w / 2, cy, atlas_icons.map_icon_surface, color_sun, 0)
update_ui_image(timeline_pos - timeline_w, cy, atlas_icons.map_icon_surface, color_moon, 0)
update_ui_pop_clip()
elseif g_button_mode == 1 then
update_ui_text(1, 1, string.format(update_get_loc(e_loc.upp_wind)..": %.2f", update_get_weather_wind_velocity(world_x, world_y)), label_w, 0, color_white, 0)
elseif g_button_mode == 2 then
update_ui_text(1, 1, string.format(update_get_loc(e_loc.upp_precipitation)..": %.0f%%", update_get_weather_precipitation_factor(world_x, world_y) * 100), label_w, 0, color_white, 0)
local cx = label_w - 42
update_ui_image(cx, 1, atlas_icons.column_power, color_white, 0)
cx = cx + 5
update_ui_text(cx, 1, string.format(": %.0f%%", update_get_weather_lightning_factor(world_x, world_y) * 100), label_w, 0, color_white, 0)
elseif g_button_mode == 3 then
update_ui_text(1, 1, string.format(update_get_loc(e_loc.upp_visibility)..": %.0f%%", update_get_weather_fog_factor(world_x, world_y) * 100), label_w, 0, color_white, 0)
elseif g_button_mode == 4 then
update_ui_text(1, 1, string.format(update_get_loc(e_loc.upp_ocean_current)..": %.2f", update_get_ocean_current_velocity(world_x, world_y)), label_w, 0, color_white, 0)
elseif g_button_mode == 5 then
update_ui_text(1, 1, string.format(update_get_loc(e_loc.upp_ocean_depth)..": %.2f", update_get_ocean_depth_factor(world_x, world_y)), label_w, 0, color_white, 0)
end
update_ui_pop_offset()
-- render cursor last
render_cursor(world_x, world_y, screen_w, screen_h)
g_dismiss_counter = 0
g_notification_time = 0
end
if (not g_is_mouse_mode or g_is_pointer_hovered) then
g_pointer_pos_x_prev = g_pointer_pos_x
g_pointer_pos_y_prev = g_pointer_pos_y
end
g_ui:end_ui()
end
function render_cursor(world_x, world_y, screen_w, screen_h)
if not (update_get_is_focus_local() and g_is_mouse_mode) then
local cursor_x, cursor_y = get_holomap_from_world(world_x, world_y, screen_w, screen_h)
update_ui_image_rot(cursor_x, cursor_y, atlas_icons.map_icon_crosshair, color_white, 0)
end
end
function input_event(event, action)
g_ui:input_event(event, action)
local screen_vehicle = update_get_screen_vehicle()
if not g_is_mouse_mode then
g_pointer_pos_x = 256
g_pointer_pos_y = 128
end
local world_x, world_y = get_world_from_holomap(g_pointer_pos_x, g_pointer_pos_y, 512, 256)
if event == e_input.action_a then
g_is_dismiss_pressed = action == e_input_action.press
g_is_ruler = action == e_input_action.press
elseif event == e_input.action_b then
if action == e_input_action.press then
if (not g_is_mouse_mode) and g_highlighted_vehicle_id > 0 and g_highlighted_waypoint_id == 0 then
local vehicle = update_get_map_vehicle_by_id(g_highlighted_vehicle_id)
if vehicle:get() and vehicle:get_team() == screen_vehicle:get_team() then
g_selection_vehicle_id = g_highlighted_vehicle_id
end
elseif (not g_is_mouse_mode or g_is_pointer_hovered) and screen_vehicle:get() and screen_vehicle:get_dock_state() ~= e_vehicle_dock_state.docked then
local waypoint_count = screen_vehicle:get_waypoint_count()
-- Delete waypoint
if g_highlighted_vehicle_id == screen_vehicle:get_id() and g_highlighted_waypoint_id > 0 then
local waypoint_path = {}
for i = 0, waypoint_count - 1, 1 do
local waypoint = screen_vehicle:get_waypoint(i)
if waypoint:get_id() ~= g_highlighted_waypoint_id then
waypoint_path[#waypoint_path + 1] = waypoint:get_position_xz()
end
end
screen_vehicle:clear_waypoints()
for i = 1, #waypoint_path, 1 do
screen_vehicle:add_waypoint(waypoint_path[i]:x(), waypoint_path[i]:y())
end
elseif g_is_mouse_mode or g_highlighted_vehicle_id == 0 then
-- Add new waypoint
if g_highlighted_vehicle_id == screen_vehicle:get_id() then
screen_vehicle:clear_waypoints()
elseif waypoint_count < 20 then
screen_vehicle:add_waypoint(world_x, world_y)
end
end
end
end
elseif event == e_input.pointer_1 then
g_is_pointer_pressed = action == e_input_action.press
if g_is_pointer_pressed and g_highlighted_vehicle_id > 0 and g_highlighted_waypoint_id == 0 then
local vehicle = update_get_map_vehicle_by_id(g_highlighted_vehicle_id)
if vehicle:get() and vehicle:get_team() == screen_vehicle:get_team() then
g_selection_vehicle_id = g_highlighted_vehicle_id
end
end
elseif event == e_input.back and action == e_input_action.press then
if g_selection_vehicle_id > 0 then
g_selection_vehicle_id = 0
else
g_is_ruler = false
local drydock, waypoint = get_team_drydock()
if waypoint ~= nil then
local waypoint_pos = waypoint:get_position_xz()
drydock:clear_waypoints()
drydock:add_waypoint(waypoint_pos:x(), waypoint_pos:y())
end
update_set_screen_state_exit()
end
end
if not g_is_ruler then
g_is_ruler_set = false
end
end
function input_axis(x, y, z, w)
if not g_override and not update_get_is_notification_holomap_set() then
g_map_x = g_map_x + x * g_map_size * 0.02