forked from Quantx/CC2-UI-Enhancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpause_menu.lua
More file actions
executable file
·1844 lines (1510 loc) · 77.5 KB
/
pause_menu.lua
File metadata and controls
executable file
·1844 lines (1510 loc) · 77.5 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_tab_map = {
tab_title = "",
render = nil,
begin = nil,
input_event = nil,
input_pointer = nil,
input_scroll = nil,
is_overlay = false,
is_map_pos_initialised = false,
camera_pos_x = 81438,
camera_pos_y = 91753,
camera_size = 256 * 1024,
camera_size_min = 1024,
camera_size_max = 256 * 1024,
}
g_tab_game = {
tab_title = "",
render = nil,
begin = nil,
input_event = nil,
input_pointer = nil,
input_scroll = nil,
is_overlay = false,
ui_container = nil,
screen_index = 0,
confirm_save_slot = nil,
confirm_load_slot = nil,
}
g_tab_options = {
tab_title = "",
render = nil,
begin = nil,
input_event = nil,
input_pointer = nil,
input_scroll = nil,
is_overlay = false,
selected_panel = 0,
hovered_panel = 0,
ui_container = nil
}
g_tab_multiplayer = {
tab_title = "",
render = nil,
begin = nil,
input_event = nil,
input_pointer = nil,
input_scroll = nil,
is_overlay = false,
toast_time = nil,
toast_text = "",
toast_col = color_status_ok,
selected_peer_id = 0,
screen_index = 0,
ui_container = nil
}
g_tab_manual = {
tab_title = "",
render = nil,
begin = nil,
input_event = nil,
input_pointer = nil,
input_scroll = nil,
is_overlay = false,
selected_panel = 0,
hovered_panel = 0,
selected_page = 1,
ui_container = nil,
highlighted_section = {
section_tag_pending = "",
section_key = 0,
content_key = 0,
timer = 0,
scroll_to_section = 0,
}
}
g_tabs = {
[0] = g_tab_map,
[1] = g_tab_manual,
[2] = g_tab_multiplayer,
[3] = g_tab_game,
[4] = g_tab_options,
map = 0,
manual = 1,
multiplayer = 2,
game = 3,
options = 4,
}
g_screens = {
menu = 0,
active_tab = 1,
}
g_focused_screen = g_screens.menu
g_hovered_screen = g_screens.menu
g_active_tab = g_tabs.map
g_hovered_tab = -1
g_input_axis = { x = 0, y = 0, z = 0, w = 0 }
g_text = {
["save_name"] = "savename",
}
g_edit_text = nil
g_text_blink_time = 0
g_keyboard_state = 0
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_pointer_scroll = 0
g_is_mouse_mode = false
g_animation_time = 0
g_tut_is_help_tab_selected = false
function begin()
begin_load()
reset()
g_tab_map.render = tab_map_render
g_tab_map.input_event = tab_map_input_event
g_tab_map.input_pointer = tab_map_input_pointer
g_tab_map.input_scroll = tab_map_input_scroll
g_tab_map.tab_title = update_get_loc(e_loc.upp_map)
g_tab_game.render = tab_game_render
g_tab_game.begin = tab_game_begin
g_tab_game.input_event = tab_game_input_event
g_tab_game.input_pointer = tab_game_input_pointer
g_tab_game.input_scroll = tab_game_input_scroll
g_tab_game.tab_title = update_get_loc(e_loc.upp_game)
g_tab_game.ui_container = lib_imgui:create_ui()
g_tab_options.render = tab_options_render
g_tab_options.input_event = tab_options_input_event
g_tab_options.input_pointer = tab_options_input_pointer
g_tab_options.input_scroll = tab_options_input_scroll
g_tab_options.tab_title = update_get_loc(e_loc.upp_options)
g_tab_options.ui_container = lib_imgui:create_ui()
g_tab_multiplayer.begin = tab_multiplayer_begin
g_tab_multiplayer.render = tab_multiplayer_render
g_tab_multiplayer.input_event = tab_multiplayer_input_event
g_tab_multiplayer.input_pointer = tab_multiplayer_input_pointer
g_tab_multiplayer.input_scroll = tab_multiplayer_input_scroll
g_tab_multiplayer.tab_title = update_get_loc(e_loc.upp_multiplayer)
g_tab_multiplayer.ui_container = lib_imgui:create_ui()
g_tab_manual.render = tab_manual_render
g_tab_manual.input_event = tab_manual_input_event
g_tab_manual.input_pointer = tab_manual_input_pointer
g_tab_manual.input_scroll = tab_manual_input_scroll
g_tab_manual.tab_title = update_get_loc(e_loc.upp_manual)
g_tab_manual.ui_container = lib_imgui:create_ui()
end
function reset()
g_tab_map.is_map_pos_initialised = false
end
function update(screen_w, screen_h, delta_time)
g_tab_map.tab_title = update_get_loc(e_loc.upp_map)
g_tab_game.tab_title = update_get_loc(e_loc.upp_game)
g_tab_options.tab_title = update_get_loc(e_loc.upp_options)
g_tab_multiplayer.tab_title = update_get_loc(e_loc.upp_multiplayer)
g_tab_manual.tab_title = update_get_loc(e_loc.upp_manual)
g_is_mouse_mode = g_is_pointer_hovered and update_get_active_input_type() == e_active_input.keyboard
g_animation_time = g_animation_time + delta_time
g_text_blink_time = g_text_blink_time + delta_time
if update_get_active_input_type() == e_active_input.keyboard then
g_tut_is_help_tab_selected = g_active_tab == g_tabs.manual
else
g_tut_is_help_tab_selected = g_focused_screen == g_screens.active_tab and g_active_tab == g_tabs.manual
end
update_interaction_ui()
local rebinding_keyboard = update_get_rebinding_keyboard()
local rebinding_gamepad = update_get_rebinding_gamepad()
local is_hoverable = g_focused_screen == g_screens.menu or g_tabs[g_active_tab].is_overlay == false
if rebinding_keyboard ~= -1 or rebinding_gamepad ~= -1 then
g_focused_screen = g_screens.active_tab
is_hoverable = false
elseif g_is_mouse_mode and g_is_pointer_hovered and is_hoverable then
if g_pointer_pos_y > 15 then
g_hovered_screen = g_screens.active_tab
else
g_hovered_screen = g_screens.menu
end
end
update_ui_rectangle(0, 0, screen_w, 14, color_black)
update_ui_line(0, 14, screen_w, 14, iff(is_hoverable, iff(g_focused_screen == g_screens.active_tab, color_white, color_highlight), color_grey_dark))
local cx = 10
g_hovered_tab = -1
for i = 0, #g_tabs do
if get_is_tab_visible(i) then
local tx = cx
local ty = 4
local tw = update_ui_get_text_size(g_tabs[i].tab_title, 10000, 0) + 8
local th = 11
local is_hovered = g_is_mouse_mode and g_is_pointer_hovered and point_in_rect(tx, ty, tw, th, g_pointer_pos_x, g_pointer_pos_y) and is_hoverable
if is_hovered then
g_hovered_tab = i
end
render_tab(tx, ty, tw, g_tabs[i].tab_title, get_tab_colors(g_active_tab == i and g_focused_screen == g_screens.active_tab, g_active_tab == i, is_hovered, is_hoverable == false))
cx = cx + tw + 1
end
end
update_ui_push_clip(0, 15, screen_w, screen_h - 15)
g_tabs[g_active_tab].render(screen_w, screen_h, 0, 15, screen_w, screen_h - 15, delta_time, g_focused_screen == g_screens.active_tab)
update_ui_pop_clip()
update_set_is_text_input_mode(get_is_text_input_mode())
g_pointer_scroll = 0
g_pointer_pos_x_prev = g_pointer_pos_x
g_pointer_pos_y_prev = g_pointer_pos_y
end
function update_interaction_ui()
if get_is_text_input_mode() == false then
if g_focused_screen == g_screens.active_tab then
update_add_ui_interaction(update_get_loc(e_loc.interaction_close), e_game_input.pause)
update_add_ui_interaction(update_get_loc(e_loc.interaction_back), e_game_input.back)
else
update_add_ui_interaction(update_get_loc(e_loc.interaction_close), e_game_input.pause)
update_add_ui_interaction(update_get_loc(e_loc.interaction_close), e_game_input.back)
end
end
if get_is_text_input_mode() then
update_add_ui_interaction(update_get_loc(e_loc.interaction_confirm), e_game_input.text_enter)
if update_get_active_input_type() == e_active_input.keyboard then
update_add_ui_interaction("", e_game_input.back)
else
update_add_ui_interaction(update_get_loc(e_loc.interaction_back), e_game_input.back)
update_add_ui_interaction_special(update_get_loc(e_loc.interaction_navigate), e_ui_interaction_special.gamepad_dpad_all)
update_add_ui_interaction(update_get_loc(e_loc.interaction_select), e_game_input.interact_a)
end
elseif update_get_active_input_type() == e_active_input.gamepad then
if g_focused_screen == g_screens.active_tab then
if g_active_tab == g_tabs.options then
update_add_ui_interaction_special(update_get_loc(e_loc.interaction_navigate), e_ui_interaction_special.gamepad_dpad_ud)
elseif g_active_tab == g_tabs.game then
update_add_ui_interaction_special(update_get_loc(e_loc.interaction_navigate), e_ui_interaction_special.gamepad_dpad_ud)
end
elseif g_focused_screen == g_screens.menu then
update_add_ui_interaction_special(update_get_loc(e_loc.interaction_navigate), e_ui_interaction_special.gamepad_dpad_lr)
update_add_ui_interaction(update_get_loc(e_loc.interaction_select), e_game_input.interact_a)
end
elseif g_hovered_tab ~= -1 then
update_add_ui_interaction(update_get_loc(e_loc.interaction_select), e_game_input.interact_a)
end
if g_focused_screen == g_screens.active_tab then
if g_active_tab == g_tabs.map then
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)
end
end
end
function set_active_tab(tab)
if g_active_tab ~= tab then
g_active_tab = tab
if g_tabs[tab] ~= nil and g_tabs[tab].begin ~= nil then
g_tabs[tab].begin()
end
end
end
function previous_tab()
local i = 0
repeat
set_active_tab((g_active_tab + #g_tabs) % (#g_tabs + 1))
i = i + 1
until get_is_tab_visible(g_active_tab) or i > #g_tabs
end
function next_tab()
local i = 0
repeat
set_active_tab((g_active_tab + 1) % (#g_tabs + 1))
i = i + 1
until get_is_tab_visible(g_active_tab) or i > #g_tabs
end
function render_button(x, y, w, text, is_highlighted, is_pressed)
update_ui_push_offset(x, y)
local col = iff(is_pressed, color_white, iff(is_highlighted, color_highlight, color_grey_dark))
update_ui_rectangle(0, 0, w, 10, col)
update_ui_text(12, 1, text, w, 0, color_black, 0)
update_ui_pop_offset()
end
function input_event(event, action)
if event == e_input.pointer_1 then
g_is_pointer_pressed = action == e_input_action.press
end
if event == e_input.pointer_1 then
g_focused_screen = g_hovered_screen
end
if g_edit_text ~= nil and update_get_active_input_type() == e_active_input.keyboard and event ~= e_input.pointer_1 and event ~= e_input.text_backspace and event ~= e_input.text_enter then
return
end
if g_focused_screen == g_screens.menu then
if event == e_input.left then
if action == e_input_action.press then
previous_tab()
end
elseif event == e_input.right then
if action == e_input_action.press then
next_tab()
end
elseif event == e_input.action_a then
if action == e_input_action.press then
g_focused_screen = g_screens.active_tab
end
elseif event == e_input.pointer_1 then
if g_hovered_tab ~= -1 then
set_active_tab(g_hovered_tab)
end
elseif event == e_input.back then
if action == e_input_action.press then
update_exit_pause_menu()
end
end
elseif g_focused_screen == g_screens.active_tab then
if g_tabs[g_active_tab].input_event(event, action) then
g_focused_screen = g_screens.menu
end
end
end
function input_pointer(is_hovered, x, y)
g_is_pointer_hovered = is_hovered
g_pointer_pos_x = x
g_pointer_pos_y = y
g_tabs[g_active_tab].input_pointer(is_hovered, x, y)
end
function input_scroll(dy)
g_pointer_scroll = g_pointer_scroll + dy
g_tabs[g_active_tab].input_scroll(dy)
end
function input_axis(x, y, z, w)
g_input_axis.x = x
g_input_axis.y = y
g_input_axis.z = z
g_input_axis.w = w
end
function input_text(text)
if g_edit_text ~= nil then
g_text[g_edit_text] = g_text[g_edit_text] .. text
g_text[g_edit_text] = clamp_str(g_text[g_edit_text], 128)
g_text_blink_time = 0
end
end
function on_close_pause_menu()
g_tab_game.screen_index = 0
g_tab_game.confirm_save_slot = nil
g_tab_game.confirm_load_slot = nil
end
--------------------------------------------------------------------------------
--
-- TAB MAP
--
--------------------------------------------------------------------------------
function tab_map_render(screen_w, screen_h, x, y, w, h, delta_time, is_active)
update_set_screen_background_type(1)
if g_tab_map.is_map_pos_initialised == false then
g_tab_map.is_map_pos_initialised = true
focus_world()
end
if is_active then
local speed_multiplier = delta_time / 30
g_tab_map.camera_pos_x = g_tab_map.camera_pos_x + g_input_axis.x * g_tab_map.camera_size * 0.01 * speed_multiplier
g_tab_map.camera_pos_y = g_tab_map.camera_pos_y + g_input_axis.y * g_tab_map.camera_size * 0.01 * speed_multiplier
tab_map_zoom(1 - (g_input_axis.w * 0.1 * speed_multiplier))
if g_is_mouse_mode then
tab_map_zoom(1 - g_pointer_scroll * 0.15)
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_tab_map.camera_pos_x = g_tab_map.camera_pos_x - pointer_dx * g_tab_map.camera_size * 0.005 * speed_multiplier
g_tab_map.camera_pos_y = g_tab_map.camera_pos_y + pointer_dy * g_tab_map.camera_size * 0.005 * speed_multiplier
end
end
end
update_set_screen_map_position_scale(g_tab_map.camera_pos_x, g_tab_map.camera_pos_y, g_tab_map.camera_size)
local function world_to_screen(x, y)
return get_screen_from_world(x, y, g_tab_map.camera_pos_x, g_tab_map.camera_pos_y, g_tab_map.camera_size, screen_w, screen_h)
end
local is_render_islands = (g_tab_map.camera_size < (64 * 1024))
update_set_screen_background_is_render_islands(is_render_islands)
-- render tiles
if is_render_islands then
for _, tile in iter_tiles() do
local tile_color = tile:get_team_color()
local position_xz = tile:get_position_xz()
local island_name = tile:get_name()
local label_x, label_y = world_to_screen(position_xz:x(), position_xz:y() + 3000)
update_ui_text(label_x - 64, label_y - 9, island_name, 128, 1, tile_color, 0)
end
else
for _, tile in iter_tiles() do
local tile_color = tile:get_team_color()
local position_xz = tile:get_position_xz()
local screen_x, screen_y = world_to_screen(position_xz:x(), position_xz:y())
update_ui_image(screen_x - 4, screen_y - 4, atlas_icons.map_icon_island, tile_color, 0)
end
end
-- render vehicles
local function filter_vehicles(v)
local def = v:get_definition_index()
return v:get_is_docked() == false and def ~= e_game_object_type.drydock and def ~= e_game_object_type.chassis_spaceship and v:get_is_observation_revealed()
end
for _, vehicle in iter_vehicles(filter_vehicles) do
local icon_region, icon_offset = get_icon_data_by_definition_index(vehicle:get_definition_index())
local team_color = update_get_team_color(vehicle:get_team_id())
local position_xz = vehicle:get_position()
local screen_x, screen_y = world_to_screen(position_xz:x(), position_xz:z())
if vehicle:get_is_visible() then
update_ui_image(screen_x - icon_offset, screen_y - icon_offset, icon_region, team_color, 0)
else
local last_known_position_xz, is_last_known_position_set = vehicle:get_vision_last_known_position_xz()
if is_last_known_position_set then
local screen_x, screen_y = world_to_screen(last_known_position_xz:x(), last_known_position_xz:y())
update_ui_image(screen_x - 2, screen_y - 2, atlas_icons.map_icon_last_known_pos, team_color, 0)
end
end
end
-- render ui
update_ui_push_offset(x, y)
if is_active then
local zoom_factor = invlerp(g_tab_map.camera_size, g_tab_map.camera_size_min, g_tab_map.camera_size_max)
update_ui_text(10, h - 20,
string.format("x:%-6.0f ", g_tab_map.camera_pos_x) ..
string.format("y:%-6.0f ",g_tab_map.camera_pos_y) ..
string.format("z:%.2f", zoom_factor),
w - 10, 0, color_grey_dark, 0
)
end
update_ui_pop_offset()
end
function tab_map_zoom(amount)
g_tab_map.camera_size = g_tab_map.camera_size * amount
g_tab_map.camera_size = math.min(g_tab_map.camera_size, g_tab_map.camera_size_max)
g_tab_map.camera_size = math.max(g_tab_map.camera_size, g_tab_map.camera_size_min)
end
function tab_map_input_event(event, action)
if action == e_input_action.press then
if event == e_input.back then
return true
end
end
return false
end
function tab_map_input_pointer(is_hovered, x, y)
end
function tab_map_input_scroll(dy)
end
function focus_world()
local tile_count = update_get_tile_count()
local function min(a, b)
if a == nil then return b end
return math.min(a, b)
end
local function max(a, b)
if a == nil then return b end
return math.max(a, b)
end
local min_x = nil
local min_z = nil
local max_x = nil
local max_z = nil
for i = 0, tile_count - 1 do
local tile = update_get_tile_by_index(i)
if tile:get() then
local tile_pos_xz = tile:get_position_xz()
local tile_size = tile:get_size()
min_x = min(min_x, tile_pos_xz:x() - tile_size:x() / 2)
min_z = min(min_z, tile_pos_xz:y() - tile_size:y() / 2)
max_x = max(max_x, tile_pos_xz:x() + tile_size:x() / 2)
max_z = max(max_z, tile_pos_xz:y() + tile_size:y() / 2)
end
end
if min_x ~= nil then
g_tab_map.camera_pos_x = (min_x + max_x) / 2
g_tab_map.camera_pos_y = (min_z + max_z) / 2
g_tab_map.camera_size = math.max(max_x - min_x, max_z - min_z) * 1.5
end
end
--------------------------------------------------------------------------------
--
-- TAB GAME
--
--------------------------------------------------------------------------------
function tab_game_begin()
g_tab_game.screen_index = 0
end
function tab_game_render(screen_w, screen_h, x, y, w, h, delta_time, is_tab_active)
update_set_screen_background_type(0)
update_ui_push_offset(x, y)
local ui = g_tab_game.ui_container
g_tab_game.is_overlay = false
ui:begin_ui(delta_time)
local is_active = is_tab_active and g_edit_text == nil
local is_mouse_active = g_is_mouse_mode and g_is_pointer_hovered and g_hovered_screen == g_screens.active_tab
if g_tab_game.screen_index == 0 then
ui:begin_window("##main", 5, 5, w - 10, h - 15, atlas_icons.column_pending, is_active or is_mouse_active, 0, true, is_active)
if ui:list_item(update_get_loc(e_loc.upp_return_to_bridge), true, update_get_is_respawn_menu_option_available()) then
update_ui_event("character_return_to_bridge")
update_exit_pause_menu()
end
ui:divider()
if ui:list_item(update_get_loc(e_loc.upp_save), true, update_get_is_save_game_available()) then
g_tab_game.screen_index = 2
end
if ui:list_item(update_get_loc(e_loc.upp_load), true) then
g_tab_game.screen_index = 1
end
ui:divider()
if ui:list_item(update_get_loc(e_loc.upp_quit), true) then
reset()
update_ui_event("quit_to_menu")
end
if ui:list_item(update_get_loc(e_loc.upp_quit_to_desktop), true) then
update_ui_event("quit_game")
end
ui:divider()
if ui:list_item(update_get_loc(e_loc.upp_report_issue), true) then
update_ui_event("open_feedback_website")
end
ui:end_window()
elseif g_tab_game.screen_index == 1 then
ui:begin_window(update_get_loc(e_loc.upp_load_game), 5, 5, w - 10, h - 15, atlas_icons.column_load, is_active and g_tab_game.confirm_load_slot == nil)
ui:header(update_get_loc(e_loc.upp_save_slots))
local save_slots = update_get_save_slots()
table.sort(save_slots, function(a, b) return a.time > b.time end)
for i, v in ipairs(save_slots) do
if ui:save_slot(i, v.display_name, v.save_name, v.time) then
if #v.save_name > 0 then
g_tab_game.confirm_load_slot = v
end
end
end
ui:end_window()
if g_tab_game.confirm_load_slot ~= nil then
g_tab_game.is_overlay = true
update_ui_rectangle(0, 0, w, h, color8(0, 0, 0, 200))
ui:begin_window(update_get_loc(e_loc.upp_confirm).."##confirm_load", 60, 60, w - 120, h - 135, nil, is_active, 2)
if ui:button(update_get_loc(e_loc.upp_cancel), true, 1) then
g_tab_game.confirm_load_slot = nil
end
if ui:button(update_get_loc(e_loc.upp_confirm), true, 1) then
update_ui_event("load_game", g_tab_game.confirm_load_slot.slot_index)
g_tab_game.confirm_load_slot = nil
end
ui:end_window()
end
elseif g_tab_game.screen_index == 2 then
ui:begin_window(update_get_loc(e_loc.upp_save_game), 5, 5, w - 10, h - 15, atlas_icons.column_save, is_active and g_tab_game.confirm_save_slot == nil)
ui:header(update_get_loc(e_loc.upp_save_slots))
local save_slots = update_get_save_slots()
table.sort(save_slots, function(a, b) return a.time > b.time end)
for i, v in ipairs(save_slots) do
if ui:save_slot(i, v.display_name, v.save_name, v.time) then
g_tab_game.confirm_save_slot = v
if #v.save_name > 0 then
g_text.save_name = v.display_name
else
g_text.save_name = update_string_from_epoch(update_get_time_since_epoch(), "%H:%M:%S %d/%m/%Y")
end
end
end
ui:end_window()
if g_tab_game.confirm_save_slot ~= nil then
g_tab_game.is_overlay = true
update_ui_rectangle(0, 0, w, h, color8(0, 0, 0, 200))
ui.window_col_active = iff(#g_tab_game.confirm_save_slot.save_name > 0, color_status_bad, color_white)
ui:begin_window(iff(#g_tab_game.confirm_save_slot.save_name > 0, update_get_loc(e_loc.upp_overwrite_save).."?", update_get_loc(e_loc.upp_confirm)) .. "##confirm_save", 60, 40, w - 120, h - 100, nil, is_active, 2)
ui:header(update_get_loc(e_loc.upp_save_name))
ui.window_col_active = color_white
if ui:textbox(g_text.save_name) then
g_edit_text = "save_name"
end
ui:divider()
if ui:button(update_get_loc(e_loc.upp_cancel), true, 1) then
g_tab_game.confirm_save_slot = nil
end
if ui:button(update_get_loc(e_loc.upp_confirm), true, 1) then
update_ui_event("save_game", g_tab_game.confirm_save_slot.slot_index, g_text.save_name)
g_tab_game.confirm_save_slot = nil
end
ui:end_window()
end
end
if g_edit_text then
g_tab_game.is_overlay = true
update_ui_rectangle(0, 0, w, h, color8(0, 0, 0, 200))
local display_text = g_text[g_edit_text] .. iff(math.floor(g_text_blink_time / 1000 * 30) % 20 > 10, "$[1]|", "$[2]|")
local border = 32
local text_w, text_h = update_ui_get_text_size(display_text, screen_w - border * 2, 1)
update_ui_push_offset(0, -20)
update_ui_set_text_color(1, color_empty)
update_ui_set_text_color(2, color_highlight)
update_ui_rectangle_outline(border - 6, screen_h / 2 - 5 - text_h - 2, screen_w - border * 2 + 12, text_h + 4, color_button_bg_inactive)
update_ui_text(border, screen_h / 2 - 5 - text_h, display_text, screen_w - border * 2, 1, color_white, 0)
ui:begin_window("##keyboard", 0, screen_h / 2, screen_w, screen_h, nil, true, 1)
local is_done = false
g_keyboard_state, g_text[g_edit_text], is_done = ui:keyboard(g_keyboard_state, g_text[g_edit_text])
if is_done then
g_edit_text = nil
end
ui:end_window()
update_ui_pop_offset()
end
ui:end_ui()
update_ui_pop_offset()
end
function tab_game_input_event(event, action)
if action == e_input_action.press then
if event == e_input.back then
if g_edit_text ~= nil then
g_edit_text = nil
elseif g_tab_game.confirm_save_slot ~= nil then
g_tab_game.confirm_save_slot = nil
elseif g_tab_game.confirm_load_slot ~= nil then
g_tab_game.confirm_load_slot = nil
elseif g_tab_game.screen_index ~= 0 then
g_tab_game.screen_index = 0
else
return true
end
else
g_tab_game.ui_container:input_event(event, action)
end
elseif action == e_input_action.release then
g_tab_game.ui_container:input_event(event, action)
end
return false
end
function tab_game_input_pointer(is_hovered, x, y)
g_tab_game.ui_container:input_pointer(is_hovered, x, y)
end
function tab_game_input_scroll(dy)
g_tab_game.ui_container:input_scroll(dy)
end
--------------------------------------------------------------------------------
--
-- TAB OPTIONS
--
--------------------------------------------------------------------------------
function tab_options_render(screen_w, screen_h, x, y, w, h, delta_time, is_active)
update_set_screen_background_type(0)
update_ui_push_offset(x, y)
local ui = g_tab_options.ui_container
local lx = 5
local lw = 64
local lh = h - 15
local rx = lx + lw + 5
local rw = w - rx - lx
local rebinding_keyboard = update_get_rebinding_keyboard()
local rebinding_gamepad = update_get_rebinding_gamepad()
if rebinding_keyboard ~= -1 or rebinding_gamepad ~= -1 then
g_tab_options.selected_panel = 1
elseif g_is_mouse_mode and g_is_pointer_hovered and ui:get_is_scroll_drag() == false then
if g_pointer_pos_x < lx + lw + 2 then
g_tab_options.hovered_panel = 0
else
g_tab_options.hovered_panel = 1
end
end
local is_mouse_active = g_is_mouse_mode and g_is_pointer_hovered and g_hovered_screen == g_screens.active_tab
local is_panel_0_selected = is_active and g_tab_options.selected_panel == 0
local is_panel_1_selected = is_active and g_tab_options.selected_panel == 1
if is_mouse_active then
is_panel_0_selected = g_tab_options.hovered_panel == 0
is_panel_1_selected = g_tab_options.hovered_panel == 1
end
local is_panel_0_highlight = is_active and g_tab_options.selected_panel == 0
local is_panel_1_highlight = is_active and g_tab_options.selected_panel == 1
ui:begin_ui(delta_time)
local win_main = ui:begin_window("##main", lx, 5, lw, lh, atlas_icons.column_pending, is_panel_0_selected, 0, true, is_panel_0_highlight)
ui:list_item(update_get_loc(e_loc.upp_graphics))
ui:list_item(update_get_loc(e_loc.upp_audio))
ui:list_item(update_get_loc(e_loc.upp_ui))
if update_get_is_vr() then
ui:list_item(update_get_loc(e_loc.upp_vr))
else
ui:list_item(update_get_loc(e_loc.upp_keyboard))
ui:list_item(update_get_loc(e_loc.upp_mouse))
ui:list_item(update_get_loc(e_loc.upp_gamepad))
end
ui:end_window()
imgui_options_menu(ui, rx, 5, rw, lh, is_panel_1_selected, win_main.selected_index_y, is_panel_1_highlight)
ui:end_ui()
update_ui_pop_offset()
end
function tab_options_input_event(event, action)
if action == e_input_action.press then
if event == e_input.pointer_1 then
g_tab_options.selected_panel = g_tab_options.hovered_panel
end
if event == e_input.back then
if g_tab_options.selected_panel == 1 then
g_tab_options.selected_panel = 0
else
return true
end
elseif event == e_input.action_a and g_tab_options.selected_panel == 0 then
g_tab_options.selected_panel = 1
else
g_tab_options.ui_container:input_event(event, action)
end
elseif action == e_input_action.release then
g_tab_options.ui_container:input_event(event, action)
end
return false
end
function tab_options_input_pointer(is_hovered, x, y)
g_tab_options.ui_container:input_pointer(is_hovered, x, y)
end
function tab_options_input_scroll(dy)
g_tab_options.ui_container:input_scroll(dy)
end
--------------------------------------------------------------------------------
--
-- TAB MULTIPLAYER
--
--------------------------------------------------------------------------------
function tab_multiplayer_begin()
g_tab_multiplayer.screen_index = 0
g_tab_multiplayer.selected_peer_id = 0
end
function tab_multiplayer_render(screen_w, screen_h, x, y, w, h, delta_time, is_active)
update_set_screen_background_type(0)
update_ui_push_offset(x, y)
local ui = g_tab_multiplayer.ui_container
ui:begin_ui(delta_time)
local is_mouse_active = g_is_mouse_mode and g_is_pointer_hovered and g_hovered_screen == g_screens.active_tab
if g_tab_multiplayer.screen_index == 0 then
local is_window_active = (is_active or is_mouse_active) and g_tab_multiplayer.selected_peer_id == 0
local win_main = ui:begin_window("##main", 10, 5, w - 20, h - 15, atlas_icons.column_pending, is_window_active, 0, true, is_active and g_tab_multiplayer.selected_peer_id == 0)
if ui:list_item(update_get_loc(e_loc.upp_public_invite), true) then
g_tab_multiplayer.screen_index = 1
end
local column_widths = { 25, 175, 33 }
local column_margins = { 5, 5, 5 }
local header_columns = {
{ w=column_widths[1], margin=column_margins[1], value=atlas_icons.column_controlling_peer },
{ w=column_widths[2], margin=column_margins[2], value=atlas_icons.column_profile },
{ w=column_widths[3], margin=column_margins[3], value=atlas_icons.column_team_control },
}
imgui_table_header(ui, header_columns)
local peer_count = update_get_peer_count()
for i = 0, peer_count - 1 do
local name = update_get_peer_name(i)
local team = update_get_peer_team(i)
local id = update_get_peer_id(i)
local team_col = update_get_team_color(team)
local columns = {
{ w=column_widths[1], margin=column_margins[1], value=tostring(id) },
{ w=column_widths[2], margin=column_margins[2], value=name },
{ w=column_widths[3], margin=column_margins[3], value=function(w, h)
update_ui_image(0, 3, atlas_icons.column_team_control, iff(is_window_active, team_col, color_grey_dark), 0)
update_ui_text(8, 3, tostring(team), w, 0, iff(is_window_active, team_col, color_grey_dark), 0)
end },
}
if imgui_table_entry(ui, columns, update_get_is_hosting_game()) then
g_tab_multiplayer.selected_peer_id = id
end
end
ui:divider(0, 0)
ui:divider(3, 5)
ui:end_window()
if g_tab_multiplayer.selected_peer_id ~= 0 then
local peer_index = get_peer_index_by_id(g_tab_multiplayer.selected_peer_id)
if peer_index ~= -1 then
local name = update_get_peer_name(peer_index)
local win_peer = ui:begin_window(name .. "##peer", 40, 40, w - 80, h - 80, atlas_icons.column_pending, is_active or is_mouse_active, 2, true, is_active)
ui:header(update_get_loc(e_loc.upp_actions))
if ui:list_item(update_get_loc(e_loc.upp_kick_player)) then
update_ui_event("host_kick_player", g_tab_multiplayer.selected_peer_id)
end
ui:end_window()
else
g_tab_multiplayer.selected_peer_id = 0
end
end
elseif g_tab_multiplayer.screen_index == 1 then
local win_main = ui:begin_window(update_get_loc(e_loc.upp_public_invite).."##main", 10, 5, w - 20, h - 15, atlas_icons.column_pending, is_active or is_mouse_active, 0, true, is_active)
if update_get_is_hosting_game() then
ui:header(update_get_loc(e_loc.upp_invite_code))
ui:text_basic(update_get_loc(e_loc.invite_code_desc), color_grey_dark)
local connect_token = update_get_host_connect_token()
local obscured_token = connect_token:sub(1, 3) .. "***********" .. connect_token:sub(#connect_token - 2)
ui:spacer(3)
ui:text_basic(obscured_token, color_grey_mid, nil, 1)
ui:spacer(4)
local button_action = ui:button_group({ update_get_loc(e_loc.copy_code), update_get_loc(e_loc.regenerate_code) }, true)
if button_action == 0 then
update_ui_event("copy_to_clipboard", connect_token)
g_tab_multiplayer.toast_time = g_animation_time
g_tab_multiplayer.toast_text = update_get_loc(e_loc.copied_to_clipboard)
g_tab_multiplayer.toast_col = color_status_ok
elseif button_action == 1 then
update_ui_event("regenerate_host_token")
g_tab_multiplayer.toast_time = g_animation_time
g_tab_multiplayer.toast_text = update_get_loc(e_loc.regenerated_invite_code)
g_tab_multiplayer.toast_col = color_status_warning
end
ui:spacer(5)
end
ui:end_window()
if g_tab_multiplayer.toast_time ~= nil and g_animation_time - g_tab_multiplayer.toast_time < 1500 then
local anim_factor = (g_animation_time - g_tab_multiplayer.toast_time) / 1500
if anim_factor < 0.1 then
anim_factor = anim_factor / 0.1
elseif anim_factor > 0.9 then
anim_factor = 1 - (anim_factor - 0.9) / 0.1