forked from Quantx/CC2-UI-Enhancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractions.lua
More file actions
executable file
·1450 lines (1173 loc) · 45.1 KB
/
interactions.lua
File metadata and controls
executable file
·1450 lines (1173 loc) · 45.1 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_interactions = {
interactions = {},
interactions_ordered = {},
get_interaction_by_input = function(self, input)
for i = 1, #self.interactions do
if self.interactions[i].input == input then return self.interactions[i] end
end
return nil
end,
get_interaction_by_special = function(self, special, text_or_index)
local index = 0
for i = 1, #self.interactions do
if self.interactions[i].special == special then
if text_or_index == nil then
return self.interactions[i]
elseif type(text_or_index) == "string" and self.interactions[i].text == text_or_index then
return self.interactions[i]
elseif type(text_or_index) =="number" and index == text_or_index then
return self.interactions[i]
end
index = index + 1
end
end
return nil
end,
add_interaction = function(self, text, input, special, internal_index)
if get_is_input_valid(input, special) == false then
return
end
local interaction = nil
local special_override = nil
if input < e_game_input.count then
interaction = self:get_interaction_by_input(input)
elseif special < e_ui_interaction_special.count then
-- try to merge gamepad navigation interactions together
if special == e_ui_interaction_special.gamepad_dpad_ud then
interaction = self:get_interaction_by_special(e_ui_interaction_special.gamepad_dpad_lr, text)
elseif special == e_ui_interaction_special.gamepad_dpad_lr then
interaction = self:get_interaction_by_special(e_ui_interaction_special.gamepad_dpad_ud, text)
end
if interaction then
special_override = e_ui_interaction_special.gamepad_dpad_all
elseif get_is_special_interaction_type_multiline(special) then
interaction = self:get_interaction_by_special(special, internal_index)
else
interaction = self:get_interaction_by_special(special)
end
end
if interaction == nil then
interaction = {
text = text,
text_prev = text,
input = input,
special = special,
special_override = nil,
is_visible = true,
anim_factor = 0,
anim_factor_text = 0,
y = nil,
}
table.insert(self.interactions, interaction)
end
interaction.text = text
interaction.is_visible = #text > 0
interaction.special_override = special_override
local is_ordered = false
for _, v in ipairs(self.interactions_ordered) do
if v == interaction then
is_ordered = true
break
end
end
if is_ordered == false then
table.insert(self.interactions_ordered, interaction)
end
end,
update = function(self, delta_time)
-- refresh ordering
for _, v in ipairs(self.interactions) do
if v.is_visible == false then
table.insert(self.interactions_ordered, v)
end
end
self.interactions = self.interactions_ordered
self.interactions_ordered = {}
-- update transitions
local cy = 0
local lerp_factor = 0.02
local fade_duration_millis = 250
local text_char_duration_millis = 30
local indices_remove = {}
for i = 1, #self.interactions do
local interaction = self.interactions[i]
if interaction.text_prev ~= interaction.text then
interaction.anim_factor_text = 0
end
interaction.text_prev = interaction.text
interaction.order_index = -1
if interaction.y == nil then
interaction.y = cy
else
interaction.y = lerp(interaction.y, cy, 1 - math.exp(-lerp_factor * delta_time))
end
local text_anim_duration = #interaction.text * text_char_duration_millis
if interaction.is_visible then
interaction.is_visible = false
if interaction.anim_factor < 1 then
interaction.anim_factor = math.min(interaction.anim_factor + delta_time / fade_duration_millis, 1)
elseif interaction.anim_factor_text < 1 then
interaction.anim_factor_text = math.min(interaction.anim_factor_text + delta_time / text_anim_duration, 1)
end
else
if interaction.anim_factor_text > 0 then
interaction.anim_factor_text = math.max(interaction.anim_factor_text - delta_time / text_anim_duration, 0)
elseif interaction.anim_factor > 0 then
interaction.anim_factor = math.max(interaction.anim_factor - delta_time / fade_duration_millis, 0)
else
table.insert(indices_remove, i)
end
end
if interaction.anim_factor > 0 then
cy = cy + 1
end
end
for i = #indices_remove, 1, -1 do
table.remove(self.interactions, indices_remove[i])
end
end,
}
g_subtitles = {
text = "",
text_pending = nil,
anim_fade = 0,
anim_word = 0,
set_text = function(self, text)
self.text_pending = text
end,
update = function(self, delta_time)
local fade_duration_millis = 250
local clear_duration_millis = 1500
local word_fade_duration_millis = 250
if self.text_pending == self.text then
self.text_pending = nil
end
if self.text_pending == nil then
if #self.text > 0 then
self.anim_fade = 1
self.anim_word = self.anim_word + delta_time / word_fade_duration_millis
end
elseif self.text_pending ~= self.text then
self.anim_word = 1000
if #self.text == 0 then
self.anim_fade = 0
self.anim_word = 0
self.text = self.text_pending
self.text_pending = nil
else
if self.anim_fade > 0 then
local fade_duration = iff(#self.text_pending > 0, fade_duration_millis, clear_duration_millis)
self.anim_fade = math.max(self.anim_fade - delta_time / fade_duration, 0)
else
self.text = self.text_pending
self.anim_word = 0
self.text_pending = nil
end
end
end
end,
}
g_objectives = {
objectives = {},
sound_cooldown = 0,
get_objective = function(self, id)
for _, obj in ipairs(self.objectives) do
if obj.id == id then return obj end
end
return nil
end,
add_objective = function(self, id, text, is_complete, progress, display_type)
local objective = self:get_objective(id)
if objective == nil and is_complete == false then
objective = {
id = id,
text = text,
is_complete = is_complete,
is_visible = true,
anim_text = 0,
anim_fade = 0,
anim_complete = 0,
anim_detail = 0,
progress = progress,
display_type = display_type,
state_change_factor = 1,
is_trigger_complete_sound = false,
x = nil,
y = nil,
}
table.insert(self.objectives, objective)
end
if objective then
objective.is_visible = true
if is_complete == false then
objective.text = text
objective.progress = progress
objective.display_type = display_type
objective.is_trigger_complete_sound = false
end
if objective.is_complete ~= is_complete and is_complete then
objective.is_trigger_complete_sound = true
end
objective.is_complete = is_complete
end
end,
update = function(self, delta_time)
if self.sound_cooldown > delta_time then
self.sound_cooldown = self.sound_cooldown - delta_time
else
self.sound_cooldown = 0
end
local indices_remove = {}
local fade_duration_millis = 200
local text_char_duration_millis = 8
local complete_duration = 1000
local state_change_duration = 500
local detail_duration_in = 500
local detail_duration_out = 100
local is_any_objective_changing_state = false
for i = 1, #self.objectives do
if self.objectives[i].is_complete then
is_any_objective_changing_state = true
break
end
end
for i = 1, #self.objectives do
local objective = self.objectives[i]
local text_anim_duration = text_char_duration_millis * #objective.text
local is_visible = objective.is_visible and objective.is_complete == false
if is_visible then
objective.anim_complete = 0
if is_any_objective_changing_state == false then
if objective.anim_fade < 1 then
objective.anim_fade = math.min(objective.anim_fade + delta_time / fade_duration_millis, 1)
elseif objective.anim_text < 1 then
objective.anim_text = math.min(objective.anim_text + delta_time / text_anim_duration, 1)
elseif objective.state_change_factor > 0 then
objective.state_change_factor = math.max(objective.state_change_factor - delta_time / state_change_duration, 0)
elseif objective.anim_detail < 1 then
objective.anim_detail = math.min(objective.anim_detail + delta_time / detail_duration_in, 1)
end
end
else
if objective.anim_detail > 0 then
objective.anim_detail = math.max(objective.anim_detail - delta_time / detail_duration_out, 0)
end
if objective.is_complete and objective.state_change_factor < 1 then
objective.state_change_factor = math.min(objective.state_change_factor + delta_time / state_change_duration, 1)
elseif objective.is_complete and objective.anim_complete < 1 then
if self.sound_cooldown <= 0 and objective.is_trigger_complete_sound then
update_play_sound(e_audio_effect_type.telemetry_2_radar)
self.sound_cooldown = 500
objective.is_trigger_complete_sound = false
end
objective.anim_complete = math.min(objective.anim_complete + delta_time / complete_duration, 1)
elseif objective.anim_text > 0 then
objective.anim_text = math.max(objective.anim_text - delta_time / text_anim_duration, 0)
elseif objective.anim_fade > 0 then
objective.anim_fade = math.max(objective.anim_fade - delta_time / fade_duration_millis, 0)
else
table.insert(indices_remove, i)
end
end
objective.is_visible = false
end
for i = #indices_remove, 1, -1 do
table.remove(self.objectives, indices_remove[i])
end
end,
}
g_voice_chat = {
peers = {},
get_peer = function(self, id)
for _, peer in ipairs(self.peers) do
if peer.id == id then return peer end
end
return nil
end,
add_peer = function(self, id, name, is_transmitting)
local peer = self:get_peer(id)
if peer == nil and is_transmitting and #self.peers < 6 then
peer = {
id = id,
name = name,
is_transmitting = is_transmitting,
cooldown = 0,
anim_fade = 0,
is_visible = true,
y = nil,
}
table.insert(self.peers, peer)
end
if peer then
peer.is_transmitting = is_transmitting
peer.is_visible = true
peer.cooldown = 0
end
end,
update = function(self, delta_time)
local indices_remove = {}
local lerp_factor = 0.02
local cooldown_duration = 2000
for i = 1, #self.peers do
local peer = self.peers[i]
local is_visible = peer.is_visible
if peer.y == nil then
peer.y = i
else
peer.y = lerp(peer.y, i, 1 - math.exp(-lerp_factor * delta_time))
end
if is_visible then
if peer.anim_fade < 1 then
peer.anim_fade = math.min(peer.anim_fade + delta_time / 100, 1)
end
else
if peer.cooldown < cooldown_duration then
peer.cooldown = peer.cooldown + delta_time
elseif peer.anim_fade > 0 then
peer.anim_fade = math.max(peer.anim_fade - delta_time / 100, 0)
else
table.insert(indices_remove, i)
end
end
peer.is_visible = false
end
for i = #indices_remove, 1, -1 do
table.remove(self.peers, indices_remove[i])
end
end,
}
g_message_box = {
is_visible = false,
type = e_message_box_type.none,
anim_fade = 0,
anim_text = 0,
anim_key = 0,
anim_delay = 0,
anim_appear = 0,
input_cooldown = 0,
text = "",
title = "",
title_col = color_white,
update = function(self, delta_time)
local type = update_get_message_box_type()
is_visible = false
if type ~= e_message_box_type.none then
if self.type ~= type then
self:set_type(type)
end
is_visible = true
end
if self.is_visible ~= is_visible then
self.is_visible = is_visible
if self.is_visible then
self.is_good_ending = is_good_ending
self.input_cooldown = 250
self.anim_key = 0
self.anim_text = 0
self.anim_delay = 0
self.anim_appear = 0
end
end
local fade_in_duration_millis = 500
local fade_out_duration_millis = 500
local text_duration_millis = update_ui_get_text_size(self.text, 10000, 0) * 30
local delay_duration_millis = 1000
local appear_duration = 500
local key_duration_millis = 500
local is_block_input = false
if self.is_visible then
if self.anim_appear < 1 then
self.anim_appear = math.min(self.anim_appear + delta_time / appear_duration, 1)
is_block_input = true
elseif self.anim_delay < 1 then
self.anim_delay = math.min(self.anim_delay + delta_time / delay_duration_millis, 1)
is_block_input = true
elseif self.anim_fade < 1 then
self.anim_fade = math.min(self.anim_fade + delta_time / fade_in_duration_millis, 1)
is_block_input = true
elseif self.anim_text < 1 then
self.anim_text = math.min(self.anim_text + delta_time / text_duration_millis, 1)
is_block_input = true
elseif self.input_cooldown > 0 then
self.input_cooldown = math.max(self.input_cooldown - delta_time, 0)
is_block_input = true
elseif self.anim_key < 1 then
self.anim_key = math.min(self.anim_key + delta_time / key_duration_millis, 1)
end
else
self.input_cooldown = 0
self.anim_key = 1
self.anim_text = 0
if self.anim_fade > 0 then
self.anim_fade = math.max(self.anim_fade - delta_time / fade_out_duration_millis, 0)
elseif self.anim_appear > 0 then
self.anim_appear = math.max(self.anim_appear - delta_time / appear_duration, 0)
end
end
update_set_is_block_input(is_block_input)
end,
set_type = function(self, type)
self.type = type
self.text = "unknown message"
self.title = "unknown message"
self.title_col = color_white
if type == e_message_box_type.tutorial_end_good then
self.title = update_get_loc(e_loc.tut_complete_title)
self.text = update_get_loc(e_loc.tut_complete_message_line_1) .. "\n\n" .. update_get_loc(e_loc.tut_complete_message_line_2) .. "\n\n" .. update_get_loc(e_loc.tut_complete_message_line_3)
self.title_col = color_status_ok
end
end,
}
g_tooltip = {
sx = 0,
sy = 0,
text = "",
is_visible = false,
anim_factor = 0,
}
g_is_render_crosshair = false
g_crosshair_color = color_white
g_is_transmitting_voice = false
g_voice_anim_factor = 0
g_time_since_voice = 5000
g_screen_border = 5
g_animation_time = 0
g_back_width = 0
g_back_height = 0
g_ui_scale = 1
function begin()
begin_load()
end
function update(screen_w, screen_h, delta_time)
g_animation_time = g_animation_time + delta_time
g_interactions:update(delta_time)
g_subtitles:update(delta_time)
g_objectives:update(delta_time)
g_voice_chat:update(delta_time)
g_message_box:update(delta_time)
g_ui_scale = update_get_ui_scale()
local ui_screen_w = screen_w / g_ui_scale
local ui_screen_h = screen_h / g_ui_scale
update_ui_push_scale(g_ui_scale)
if update_get_is_show_controls() then
render_interactions(ui_screen_w, ui_screen_h, delta_time)
end
if update_get_is_show_subtitles() then
render_subtitles(ui_screen_w, ui_screen_h, delta_time)
end
render_voice_chat(ui_screen_w, ui_screen_h, delta_time)
render_objectives(ui_screen_w, ui_screen_h, delta_time)
update_ui_pop_scale()
if update_get_is_show_tooltips() then
render_tooltip(screen_w, screen_h, delta_time)
end
if g_is_render_crosshair and g_message_box.is_visible == false then
render_crosshair(screen_w, screen_h)
end
update_ui_push_scale(g_ui_scale)
render_message_box(ui_screen_w, ui_screen_h, delta_time)
update_ui_pop_scale()
-- test_voice_chat(delta_time)
-- test_objectives(delta_time)
-- test_subtitles(delta_time)
end
function test_voice_chat(delta_time)
g_time_voice_chat = (g_time_voice_chat or 0) + delta_time
local time = g_time_voice_chat % 16000
g_voice_chat_test_xmit1 = iff(g_voice_chat_test_xmit1 == nil, true, g_voice_chat_test_xmit1)
g_voice_chat_test_xmit2 = iff(g_voice_chat_test_xmit2 == nil, true, g_voice_chat_test_xmit2)
g_voice_chat_test_xmit3 = iff(g_voice_chat_test_xmit3 == nil, true, g_voice_chat_test_xmit3)
if math.floor(time) % 10 == 0 and math.random(0, 1) == 0 then g_voice_chat_test_xmit1 = not g_voice_chat_test_xmit1 end
if math.floor(time) % 25 == 0 and math.random(0, 1) == 0 then g_voice_chat_test_xmit2 = not g_voice_chat_test_xmit2 end
if math.floor(time) % 50 == 0 and math.random(0, 1) == 0 then g_voice_chat_test_xmit3 = not g_voice_chat_test_xmit3 end
if time < 5000 then
g_voice_chat:add_peer(1, "peername2withalongname", g_voice_chat_test_xmit1)
elseif time < 10000 then
g_voice_chat:add_peer(1, "peername2withalongname", g_voice_chat_test_xmit3)
g_voice_chat:add_peer(2, "PEERNAME2", g_voice_chat_test_xmit1)
elseif time < 12000 then
g_voice_chat:add_peer(3, "peername3", g_voice_chat_test_xmit2)
g_voice_chat:add_peer(2, "PEERNAME2", g_voice_chat_test_xmit3)
g_voice_chat:add_peer(4, "AnotherPeer", g_voice_chat_test_xmit1)
elseif time < 15000 then
g_voice_chat:add_peer(3, "peername3", g_voice_chat_test_xmit1)
g_voice_chat:add_peer(5, "peer 5", g_voice_chat_test_xmit2)
end
end
function test_objectives(delta_time)
g_time_objectives = (g_time_objectives or 0) + delta_time
local time = g_time_objectives % 20000
if time < 5000 then
g_objectives:add_objective(0, "get in vehicle control seat and then use vehicle button", false, -1, 0)
g_objectives:add_objective(1, "open pause menu", false, -1, 2)
elseif time < 10000 then
g_objectives:add_objective(0, "get in vehicle control seat and then use vehicle button", true, -1, 0)
g_objectives:add_objective(1, "open pause menu", false, -1, 2)
elseif time < 18000 then
g_objectives:add_objective(2, "capture enemy island using seal and virus bots", false, -1, 1)
g_objectives:add_objective(1, "open pause menu", true, -1, 2)
else
g_objectives:add_objective(2, "capture enemy island using seal and virus bots", true, -1, 1)
end
end
function test_subtitles(delta_time)
g_time_subtitles = (g_time_subtitles or 0) + delta_time
local time = g_time_subtitles % 12000
if time < 5000 then
g_subtitles:set_text("Lorem ipsum dolor sit amet, consectetur adipiscing elit sed do eiusmod")
elseif time < 10000 then
g_subtitles:set_text("tempor incididunt ut labore et dolore magna aliqua")
else
g_subtitles:set_text("")
end
end
function on_add_interaction(text, input, special)
if update_get_message_box_type() == e_message_box_type.none then
if get_is_special_interaction_type_multiline(special) then
-- split interactions with multiline formatting into separate interactions;
-- first split by line breaks, then ensure lines don't exceed max length
local max_line_length = 160
local lines = get_text_lines(text)
local lines_clipped = {}
for i = 1, #lines do
local line = lines[i]
local words = get_words_from_string(line)
local built_line = ""
for j = 1, #words do
local built_line_temp = built_line
if built_line_temp == "" then
built_line_temp = words[j]
else
built_line_temp = built_line_temp .. " " .. words[j]
end
if update_ui_get_text_size(built_line_temp, 10000, 0) > max_line_length then
if #built_line > 0 and update_ui_get_text_size(built_line, 10000, 0) <= max_line_length then
table.insert(lines_clipped, built_line)
end
local word = words[j]
while update_ui_get_text_size(word, 10000, 0) > max_line_length do
local word_length = utf8.len(word)
local char_offset = utf8.offset(word, 0, math.min(max_line_length, word_length - 1))
local clipped_word = string.sub(word, 0, char_offset - 1)
table.insert(lines_clipped, clipped_word)
word = string.sub(word, utf8.offset(word, 0, char_offset))
end
built_line = word
else
built_line = built_line_temp
end
end
if #built_line > 0 then
table.insert(lines_clipped, built_line)
end
end
local index = 0
for i = #lines_clipped, 1, -1 do
g_interactions:add_interaction(lines_clipped[i], input, special, index)
index = index + 1
end
else
g_interactions:add_interaction(text, input, special)
end
end
end
function on_set_subtitle(text)
g_subtitles:set_text(text)
end
function on_add_objective(id, text, is_complete, progress, display_type)
if update_get_message_box_type() == e_message_box_type.none then
g_objectives:add_objective(id, text, is_complete, progress, display_type)
end
end
function on_add_peer_voice_transmit(peer_id, peer_name, is_transmitting)
g_voice_chat:add_peer(peer_id, peer_name, is_transmitting)
end
function on_set_highlighted_object(text, sx, sy)
if #text > 0 then
if text ~= g_tooltip.text then
g_tooltip.anim_text = 0
end
g_tooltip.text = text
g_tooltip.sx = sx
g_tooltip.sy = sy
g_tooltip.is_visible = true
end
end
function on_set_is_render_crosshair(is_render, col)
g_is_render_crosshair = is_render
g_crosshair_color = col
end
--------------------------------------------------------------------------------
--
-- CROSSHAIR
--
--------------------------------------------------------------------------------
function render_crosshair(screen_w, screen_h)
local cx = math.floor(screen_w / 2)
local cy = math.floor(screen_h / 2)
local icon_w, icon_h = update_ui_get_image_size(atlas_icons.crosshair)
update_ui_push_alpha(200)
update_ui_image(cx - math.floor(icon_w / 2), cy - math.floor(icon_h / 2), atlas_icons.crosshair, g_crosshair_color, 0)
update_ui_pop_alpha()
end
--------------------------------------------------------------------------------
--
-- INTERACTION CONTROLS UI
--
--------------------------------------------------------------------------------
function render_interactions(screen_w, screen_h, delta_time)
update_ui_push_offset(g_screen_border, screen_h - g_screen_border)
g_time = g_time or 0
g_time = g_time + delta_time
update_ui_rectangle(0, -math.floor(g_back_height + 0.5), math.floor(g_back_width + 0.5), math.floor(g_back_height + 0.5), color_black)
local border = 5
local spacing = 2
local target_back_width = 0
local target_back_height = 0
for k, v in ipairs(g_interactions.interactions) do
local cy = math.floor(border + v.y * (10 + spacing) + 0.5)
local cx = border
local display_text = clip_string(v.text, v.anim_factor_text, true)
local icon_data = get_input_icons(v.input, v.special_override or v.special)
update_ui_push_alpha(math.floor(255 * v.anim_factor))
local icon_w = render_interaction_icon_data(cx, -cy - 10, icon_data, display_text, color_white)
update_ui_pop_alpha()
target_back_width = math.max(target_back_width, cx + border + icon_w)
target_back_height = math.max(target_back_height, cy + 10 + border)
end
if target_back_width == 0 then
target_back_width = g_back_width
end
g_back_width = target_back_width
g_back_height = lerp(g_back_height, target_back_height, 1 - math.exp(-0.05 * delta_time))
update_ui_pop_offset()
end
function render_interaction_icon_data(x, y, icon_data, display_text, text_col)
local color_shadow = color8(0, 0, 0, 200)
update_ui_push_offset(x, y)
local cx = 0
local cy = 0
if #icon_data > 0 then
for i = 1, #icon_data do
local icon = icon_data[i]
local icon_col = icon.icon_col or color_white
if icon.text_col then
text_col = icon.text_col
end
if icon.delim then
update_ui_text(cx + 2, cy + 1, icon.delim, 10, 0, color_shadow, 0)
update_ui_text(cx + 1, cy + 0, icon.delim, 10, 0, color_grey_dark, 0)
cx = cx + 7
elseif icon.icon then
if icon_col ~= color_empty then
update_ui_image(cx + 1, cy + 1, icon.icon, color_shadow, 0)
update_ui_image(cx, cy + 0, icon.icon, icon_col, 0)
end
cx = cx + (icon.icon_w or 10)
elseif icon.text then
imgui_render_key_icon(cx + 1, cy + 1, icon.text, false, color_black)
cx = cx + imgui_render_key_icon(cx, cy + 0, icon.text)
end
end
if #display_text > 0 then
cx = cx + 5
update_ui_text(cx + 1, cy + 1, display_text, 400, 0, color_shadow, 0)
update_ui_text(cx, cy + 0, display_text, 400, 0, text_col, 0)
cx = cx + update_ui_get_text_size(display_text, 10000, 0)
end
end
update_ui_pop_offset()
return cx, cy
end
function get_is_input_valid(game_input, special_input)
local icons = get_input_icons(game_input, special_input)
return #icons > 0
end
function get_input_icons(game_input, special_input)
local icon_datas = {}
local display_inputs = get_display_inputs(game_input, special_input)
local display_input_prev = {}
for _, v in ipairs(display_inputs) do
local icon_data = nil
if v.input and v.input < e_game_input.count then
icon_data = get_game_input_icon(v.input)
elseif v.special and v.special < e_ui_interaction_special.count then
icon_data = get_special_input_icon(v.special)
end
if icon_data ~= nil then
if #icon_datas > 0 then
if special_input == e_ui_interaction_special.map_drag and update_get_active_input_type() == e_active_input.gamepad then
table.insert(icon_datas, { delim = "+"} )
elseif v.input == e_game_input.select_attachment_9 and display_input_prev.input == e_game_input.select_attachment_1 then
table.insert(icon_datas, { delim = "-"} )
else
table.insert(icon_datas, { delim = "/" })
end
end
table.insert(icon_datas, icon_data)
end
display_input_prev = v
end
return icon_datas
end
function get_special_input_icon(special_input)
local color_info = color8(32, 32, 32, 255)
local color_info_desc = color8(5, 5, 5, 255)
local icons_gamepad = {
[e_ui_interaction_special.gamepad_dpad_all] = { icon = atlas_icons.gamepad_icon_special_dpad_all },
[e_ui_interaction_special.gamepad_dpad_ud] = { icon = atlas_icons.gamepad_icon_special_dpad_ud },
[e_ui_interaction_special.gamepad_dpad_lr] = { icon = atlas_icons.gamepad_icon_special_dpad_lr },
[e_ui_interaction_special.map_pan] = { icon = atlas_icons.gamepad_icon_special_ls },
[e_ui_interaction_special.map_zoom] = { icon = atlas_icons.gamepad_icon_special_rs_ud },
[e_ui_interaction_special.info] = { icon = atlas_icons.column_pending, icon_col = color_empty, icon_w = -5, text_col = color_info },
[e_ui_interaction_special.info_desc] = { icon = atlas_icons.column_pending, icon_col = color_empty, icon_w = -5, text_col = color_info_desc },
[e_ui_interaction_special.air_yaw] = { icon = atlas_icons.gamepad_icon_special_rs_lr },
[e_ui_interaction_special.air_pitch] = { icon = atlas_icons.gamepad_icon_special_ls_ud },
[e_ui_interaction_special.air_roll] = { icon = atlas_icons.gamepad_icon_special_ls_lr },
[e_ui_interaction_special.air_throttle] = { icon = atlas_icons.gamepad_icon_special_rs_ud },
[e_ui_interaction_special.vehicle_zoom] = { icon = atlas_icons.gamepad_icon_special_ls_ud },
[e_ui_interaction_special.land_steer] = { icon = atlas_icons.gamepad_icon_special_ls_lr },
[e_ui_interaction_special.land_throttle] = { icon = atlas_icons.gamepad_icon_special_ls_ud },
[e_ui_interaction_special.gamepad_scroll] = { icon = atlas_icons.gamepad_icon_special_rs_ud },
[e_ui_interaction_special.cancel_rebind] = { icon = atlas_icons.gamepad_icon_start },
[e_ui_interaction_special.map_drag] = { icon = atlas_icons.gamepad_icon_special_ls },
}
local icons_keyboard = {
[e_ui_interaction_special.mouse_wheel] = { icon = atlas_icons.mouse_icon_special_scroll },
[e_ui_interaction_special.map_pan] = { icon = atlas_icons.mouse_icon_special_drag },
[e_ui_interaction_special.map_zoom] = { icon = atlas_icons.mouse_icon_special_scroll },
[e_ui_interaction_special.info] = { icon = atlas_icons.column_pending, icon_col = color_empty, icon_w = -5, text_col = color_info },
[e_ui_interaction_special.info_desc] = { icon = atlas_icons.column_pending, icon_col = color_empty, icon_w = -5, text_col = color_info_desc },
[e_ui_interaction_special.vehicle_zoom] = { icon = atlas_icons.mouse_icon_special_scroll },
[e_ui_interaction_special.cancel_rebind] = { text = update_get_key_name(259) },
[e_ui_interaction_special.map_drag] = { icon = atlas_icons.mouse_icon_special_drag },
}
if update_get_active_input_type() == e_active_input.gamepad then
if icons_gamepad[special_input] ~= nil then
return icons_gamepad[special_input]
end
else
if icons_keyboard[special_input] ~= nil then
return icons_keyboard[special_input]
end
end
return nil
end
function get_game_input_icon(game_input)
if update_get_active_input_type() == e_active_input.gamepad then
local button, axis = get_bindings_gamepad(game_input)
if button ~= -1 then
local icon, icon_col = get_gamepad_button_icon(button)
return { icon = icon, icon_col = icon_col }
elseif axis ~= -1 then
local icon, icon_col = get_gamepad_axis_icon(axis)
return { icon = icon, icon_col = icon_col }
end
else
local key, pointer = get_bindings_keyboard(game_input)
if key ~= -1 then
return { text = update_get_key_name(key) }
elseif pointer ~= -1 then
local icon, icon_col = get_pointer_icon(pointer)
return { icon = icon, icon_col = icon_col }
end
end
return nil
end
function get_display_inputs(game_input, special_input)
if update_get_active_input_type() == e_active_input.gamepad then
if game_input == e_game_input.interact_a then
return { { input = e_game_input.interact_a }, { input = e_game_input.interact_a_alt } }
elseif game_input == e_game_input.select_attachment_next or game_input == e_game_input.select_attachment_prev then
return { { input = e_game_input.select_attachment_next}, { input = e_game_input.select_attachment_prev } }
elseif special_input == e_ui_interaction_special.pause then
return { { input = e_game_input.pause} }
elseif special_input == e_ui_interaction_special.map_drag then
return { { special = e_ui_interaction_special.map_drag }, { input = e_game_input.interact_a} }
end
else
if game_input == e_game_input.interact_a then
return { { input = e_game_input.interact_a }, { input = e_game_input.interact_a_alt } }
elseif game_input == e_game_input.select_attachment_next then
return { { input = e_game_input.select_attachment_next}, { input = e_game_input.select_attachment_prev } }
elseif game_input == e_game_input.select_attachment_1 then
return { { input = e_game_input.select_attachment_1}, { input = e_game_input.select_attachment_9 } }
elseif special_input == e_ui_interaction_special.map_zoom then
return { { special = e_ui_interaction_special.map_zoom }, { input = e_game_input.look_up }, { input = e_game_input.look_down } }
elseif special_input == e_ui_interaction_special.map_pan then
return { { special = e_ui_interaction_special.map_pan }, { input = e_game_input.dpad_up }, { input = e_game_input.dpad_left }, { input = e_game_input.dpad_down }, { input = e_game_input.dpad_right } }
elseif special_input == e_ui_interaction_special.air_yaw then
return { { input = e_game_input.look_left }, { input = e_game_input.look_right } }
elseif special_input == e_ui_interaction_special.air_pitch then
return { { input = e_game_input.move_up }, { input = e_game_input.move_down } }
elseif special_input == e_ui_interaction_special.air_roll then
return { { input = e_game_input.move_left }, { input = e_game_input.move_right } }
elseif special_input == e_ui_interaction_special.air_throttle then
return { { input = e_game_input.look_up }, { input = e_game_input.look_down } }
elseif special_input == e_ui_interaction_special.vehicle_zoom then
return { { special = e_ui_interaction_special.vehicle_zoom }, { input = e_game_input.move_up }, { input = e_game_input.move_down } }
elseif special_input == e_ui_interaction_special.land_steer then
return { { input = e_game_input.move_left }, { input = e_game_input.move_right } }
elseif special_input == e_ui_interaction_special.land_throttle then
return { { input = e_game_input.move_up }, { input = e_game_input.move_down } }
elseif special_input == e_ui_interaction_special.pause then
return iff(update_get_keyboard_back_opens_pause(), { { input = e_game_input.pause}, { input = e_game_input.back } }, { { input = e_game_input.pause } })
end
end
return { { input = game_input, special = special_input } }
end
--------------------------------------------------------------------------------
--
-- VOICE CHAT ICON
--
--------------------------------------------------------------------------------
function render_voice_chat(screen_w, screen_h, delta_time)