forked from Quantx/CC2-UI-Enhancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_inventory.lua
More file actions
executable file
·1916 lines (1520 loc) · 74 KB
/
screen_inventory.lua
File metadata and controls
executable file
·1916 lines (1520 loc) · 74 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 = e_loc.upp_map,
render = nil,
input_event = nil,
input_pointer = nil,
input_scroll = nil,
is_overlay = false,
camera_pos_x = 81438,
camera_pos_y = 91753,
camera_size = 256 * 1024,
camera_size_max = 256 * 1024,
camera_size_min = 1024,
cursor_pos_x = 0,
cursor_pos_y = 0,
is_drag_pan_map = false,
hovered_id = 0,
hovered_type = 0,
dragged_id = 0,
dragged_type = 0,
is_map_pos_initialised = false,
selected_facility_id = 0,
selected_facility_item = -1,
selected_facility_queue_item = -1,
selected_barge_id = 0,
selected_panel = 0,
}
g_tab_stock = {
tab_title = e_loc.upp_stock,
render = nil,
input_event = nil,
input_pointer = nil,
input_scroll = nil,
is_overlay = false,
selected_item = -1,
}
g_tab_barges = {
tab_title = e_loc.upp_barges,
render = nil,
input_event = nil,
input_pointer = nil,
input_scroll = nil,
is_overlay = false,
selected_item = -1,
}
g_tabs = {
[0] = g_tab_stock,
[1] = g_tab_map,
[2] = g_tab_barges,
stock = 0,
map = 1,
barges = 2,
}
g_screens = {
menu = 0,
active_tab = 1,
}
g_focused_screen = g_screens.menu
g_active_tab = g_tabs.stock
g_hovered_tab = -1
g_link_types = {
tile = 0,
carrier = 1,
barge = 2
}
g_map_colors = {
barge = color8(0, 255, 64, 255),
factory = color8(255, 128, 0, 255),
carrier = color8(0, 64, 255, 255),
inactive = color_grey_dark,
progress = color_status_bad,
}
g_animation_time = 0
g_input = {}
g_input_axis = { x = 0, y = 0, z = 0, w = 0 }
g_input_repeat_rate = 3
g_input_repeat_delay = 15
g_ui = nil
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
--------------------------------------------------------------------------------
--
-- BEGIN
--
--------------------------------------------------------------------------------
function parse()
g_focused_screen = parse_s32(g_focused_screen)
g_active_tab = parse_s32(g_active_tab)
g_tab_map.camera_pos_x = parse_f32(g_tab_map.camera_pos_x)
g_tab_map.camera_pos_y = parse_f32(g_tab_map.camera_pos_y)
g_tab_map.camera_size = parse_f32(g_tab_map.camera_size)
g_tab_map.cursor_pos_x = parse_f32(g_tab_map.cursor_pos_x)
g_tab_map.cursor_pos_y = parse_f32(g_tab_map.cursor_pos_y)
g_tab_map.selected_facility_id = parse_s32(g_tab_map.selected_facility_id)
g_tab_map.selected_facility_item = parse_s32(g_tab_map.selected_facility_item)
g_tab_map.selected_facility_queue_item = parse_s32(g_tab_map.selected_facility_queue_item)
g_tab_map.selected_panel = parse_s32(g_tab_map.selected_panel)
g_tab_stock.selected_item = parse_s32(g_tab_stock.selected_item)
g_tab_barges.selected_item = parse_s32(g_tab_barges.selected_item)
end
function begin()
begin_load()
begin_load_inventory_data()
g_ui = lib_imgui:create_ui()
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_stock.render = tab_stock_render
g_tab_stock.input_event = tab_stock_input_event
g_tab_stock.input_pointer = tab_stock_input_pointer
g_tab_stock.input_scroll = tab_stock_input_scroll
g_tab_barges.render = tab_barges_render
g_tab_barges.input_event = tab_barges_input_event
g_tab_barges.input_pointer = tab_barges_input_pointer
g_tab_barges.input_scroll = tab_barges_input_scroll
local screen_name = begin_get_screen_name()
if screen_name == "screen_inv_r_large" then
g_active_tab = g_tabs.map
end
end
--------------------------------------------------------------------------------
--
-- UPDATE
--
--------------------------------------------------------------------------------
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 vehicle = update_get_screen_vehicle()
if vehicle:get() == false then return end
if update_screen_overrides(screen_w, screen_h, ticks) then return end
update_interaction_ui()
local is_hoverable = g_focused_screen == g_screens.menu or g_tabs[g_active_tab].is_overlay == false
if g_is_mouse_mode and g_is_pointer_hovered and is_hoverable and update_get_screen_state_active() then
if g_pointer_pos_y > 15 then
g_focused_screen = g_screens.active_tab
else
g_focused_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
local tab_name = update_get_loc(g_tabs[i].tab_title)
local tx = cx
local ty = 4
local tw = update_ui_get_text_size(tab_name, 10000, 1) + 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, tab_name, 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
update_ui_push_clip(0, 15, screen_w, screen_h - 15)
g_ui:begin_ui()
g_tabs[g_active_tab].render(screen_w, screen_h, 0, 15, screen_w, screen_h - 15, g_focused_screen == g_screens.active_tab, vehicle)
g_ui:end_ui()
update_ui_pop_clip()
render_currency_display(screen_w - 10, 5, g_tab_map.selected_facility_id ~= 0 and g_tab_map.selected_facility_item ~= -1)
g_pointer_scroll = 0
g_pointer_pos_x_prev = g_pointer_pos_x
g_pointer_pos_y_prev = g_pointer_pos_y
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 update_interaction_ui()
if update_get_active_input_type() == e_active_input.gamepad then
if g_focused_screen == g_screens.active_tab then
update_add_ui_interaction(update_get_loc(e_loc.interaction_back), e_game_input.back)
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
if g_tab_map.selected_facility_id == 0 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)
if g_tab_map.dragged_id == 0 and g_tab_map.hovered_id ~= 0 then
if g_tab_map.hovered_type == g_link_types.tile then
local tile = update_get_tile_by_id(g_tab_map.hovered_id)
if tile:get() and tile:get_team_control() == update_get_screen_team_id() then
update_add_ui_interaction(update_get_loc(e_loc.interaction_select), e_game_input.interact_a)
end
elseif g_tab_map.hovered_type == g_link_types.barge then
local barge = update_get_map_vehicle_by_id(g_tab_map.hovered_id)
if barge:get() and barge:get_team() == update_get_screen_team_id() then
update_add_ui_interaction(update_get_loc(e_loc.interaction_select), e_game_input.interact_a)
end
end
end
end
end
end
end
--------------------------------------------------------------------------------
--
-- INPUT
--
--------------------------------------------------------------------------------
function get_input(event)
if g_input[event] == nil then
g_input[event] = {
is_pressed = false,
repeat_counter = -g_input_repeat_delay
}
end
return g_input[event]
end
function input_event(event, action)
if event == e_input.pointer_1 then
g_is_pointer_pressed = action == e_input_action.press
end
if g_focused_screen == g_screens.menu then
if event == e_input.back then
if action == e_input_action.press then
exit_screen()
end
elseif event == e_input.left then
if action == e_input_action.press then
set_active_tab((g_active_tab + #g_tabs) % (#g_tabs + 1))
end
elseif event == e_input.right then
if action == e_input_action.press then
set_active_tab((g_active_tab + 1) % (#g_tabs + 1))
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
end
elseif g_focused_screen == g_screens.active_tab then
if g_tabs[g_active_tab].input_event(event, action) then
if g_is_mouse_mode then
exit_screen()
else
g_focused_screen = g_screens.menu
end
end
end
end
function exit_screen()
g_focused_screen = g_screens.menu
g_hovered_tab = -1
update_set_screen_state_exit()
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
--------------------------------------------------------------------------------
--
-- BARGE DISPLAY
--
--------------------------------------------------------------------------------
function tab_barges_render(screen_w, screen_h, x, y, w, h, is_tab_active, screen_vehicle)
local ui = g_ui
g_tab_barges.is_overlay = false
update_ui_push_offset(x, y)
local vehicle_team = screen_vehicle:get_team()
local vehicle_filter = function(v)
return v:get_definition_index() == e_game_object_type.chassis_sea_barge and v:get_team() == vehicle_team
end
local barges = {}
for _, barge in iter_vehicles(vehicle_filter) do
table.insert(barges, barge)
end
ui:begin_window("##barges", 5, 0, w - 10, h, nil, is_tab_active and g_tab_barges.selected_item == -1, 1)
local selected_item = imgui_barge_table(ui, barges)
ui:divider(0, 3)
ui:divider(0, 10)
if selected_item ~= -1 and barges[selected_item] ~= nil then
g_tab_barges.selected_item = barges[selected_item]:get_id()
end
ui:end_window()
local selected_barge = update_get_map_vehicle_by_id(g_tab_barges.selected_item)
if selected_barge:get() then
g_tab_barges.is_overlay = true
update_ui_rectangle(0, 0, screen_w, screen_h, color8(0, 0, 0, 200))
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_ud)
local window = ui:begin_window(update_get_loc(e_loc.upp_barge_id).. " " .. selected_barge:get_id() .. "##selectedbarge", 60, 5, w - 120, h - 20, atlas_icons.column_distance, is_tab_active, 2)
local inventory_capacity = selected_barge:get_inventory_capacity()
local inventory_weight = selected_barge:get_inventory_weight()
ui:header(update_get_loc(e_loc.upp_inventory))
window.label_bias = 0.1
ui:stat(atlas_icons.column_weight, inventory_weight .. "/" .. inventory_capacity, iff(inventory_weight < inventory_capacity, color_status_ok, color_status_bad))
window.label_bias = 0.5
ui:header(update_get_loc(e_loc.upp_actions))
if ui:list_item(update_get_loc(e_loc.upp_show_on_map), true) then
g_tab_barges.selected_item = -1
local barge_pos_xz = selected_barge:get_position_xz()
g_tab_map.camera_pos_x = barge_pos_xz:x()
g_tab_map.camera_pos_y = barge_pos_xz:y()
g_tab_map.camera_size = 4096
set_active_tab(g_tabs.map)
end
local action, destination_id, destination_type = selected_barge:get_barge_state_data()
local pos_xz = get_node_pos_xz(destination_id, destination_type)
if ui:list_item(update_get_loc(e_loc.upp_show_destination), true, pos_xz ~= nil) then
if pos_xz ~= nil then
g_tab_barges.selected_item = -1
local barge_pos_xz = selected_barge:get_position_xz()
g_tab_map.camera_pos_x = pos_xz:x()
g_tab_map.camera_pos_y = pos_xz:y()
g_tab_map.camera_size = 4096
set_active_tab(g_tabs.map)
end
end
if ui:list_item(update_get_loc(e_loc.upp_inventory), true) then
g_tab_barges.selected_item = -1
g_tab_map.selected_barge_id = selected_barge:get_id()
set_active_tab(g_tabs.map)
end
ui:end_window()
else
g_tab_barges.selected_item = -1
if is_tab_active then
if #barges > 0 then
update_add_ui_interaction_special(update_get_loc(e_loc.interaction_navigate), e_ui_interaction_special.gamepad_dpad_ud)
update_add_ui_interaction(update_get_loc(e_loc.interaction_select), e_game_input.interact_a)
end
end
end
update_ui_pop_offset()
end
function tab_barges_input_event(input, action)
if input == e_input.back and action == e_input_action.press then
if g_tab_barges.selected_item ~= -1 then
g_tab_barges.selected_item = -1
else
return true
end
end
g_ui:input_event(input, action)
return false
end
function tab_barges_input_pointer(is_hovered, x, y)
g_ui:input_pointer(is_hovered, x, y)
end
function tab_barges_input_scroll(dy)
g_ui:input_scroll(dy)
end
function imgui_barge_table(ui, barges)
local window = ui:get_window()
local x = window.cx
local y = window.cy
local w, h = ui:get_region()
local selected_item = -1
local column_widths = { 30, 94, 60, 40 }
local column_margins = { 5, 2, 2, 2 }
local header_columns = {
{ w=column_widths[1], margin=column_margins[1], value=update_get_loc(e_loc.upp_id) },
{ w=column_widths[2], margin=column_margins[2], value=atlas_icons.hud_warning },
{ w=column_widths[3], margin=column_margins[3], value=atlas_icons.column_transit },
{ w=column_widths[4], margin=column_margins[4], value=atlas_icons.column_distance },
}
imgui_table_header(ui, header_columns)
for k, barge in pairs(barges) do
local get_action_text = function(action_type, destination_type)
if action_type == e_barge_action.load then
return update_get_loc(e_loc.upp_load_stock)
elseif action_type == e_barge_action.unload then
return update_get_loc(e_loc.upp_unload)
elseif action_type == e_barge_action.load_carrier_stock then
return iff(destination_type == g_link_types.carrier, update_get_loc(e_loc.collect_surplus), update_get_loc(e_loc.collect_order))
elseif action_type == e_barge_action.unload_carrier_stock then
return update_get_loc(e_loc.upp_deliver_order)
end
return "---"
end
local action, destination_id, destination_type = barge:get_barge_state_data()
local dist_to_target = 0
local waypoint = barge:get_waypoint(0)
local text_action = get_action_text(action, destination_type)
local text_destination = "---"
local text_dist = "---"
local col_destination = color_grey_dark
if waypoint:get() then
local waypoint_pos_xz = waypoint:get_position_xz()
local barge_pos_xz = barge:get_position_xz()
dist_to_target = vec2_dist(waypoint_pos_xz, barge_pos_xz)
end
if destination_id ~= 0 then
local label, col = get_node_data(destination_id, destination_type)
if label ~= nil then
text_destination = get_action_text(action, destination_type)
text_destination = label
col_destination = col
end
else
text_action = update_get_loc(e_loc.upp_idle)
end
if dist_to_target > 0 then
text_dist = string.format("%.0fm", math.min(99999, dist_to_target))
end
local columns = {
{ w=column_widths[1], margin=column_margins[1], value=tostring(barge:get_id()) },
{ w=column_widths[2], margin=column_margins[2], value=text_action },
{ w=column_widths[3], margin=column_margins[3], value=text_destination, col=col_destination },
{ w=column_widths[4], margin=column_margins[4], value=text_dist }
}
local is_action = imgui_table_entry(ui, columns, true)
if is_action then
selected_item = k
end
end
return selected_item
end
--------------------------------------------------------------------------------
--
-- MAP DISPLAY
--
--------------------------------------------------------------------------------
function tab_map_render(screen_w, screen_h, x, y, w, h, is_tab_active, screen_vehicle)
if g_tab_map.is_map_pos_initialised == false then
g_tab_map.is_map_pos_initialised = true
focus_world()
end
update_map_cursor_state(screen_w, screen_h)
g_tab_map.is_overlay = false
update_ui_push_clip(x, y, w, h)
render_map_details(screen_vehicle, screen_w, screen_h, is_tab_active and g_tab_map.selected_facility_id == 0)
update_ui_pop_clip()
render_map_ui(screen_w, screen_h, x, y, w, h, screen_vehicle, is_tab_active)
end
function render_map_details(screen_vehicle, screen_w, screen_h, is_tab_active)
update_ui_rectangle(0, 0, screen_w, screen_w, color8(5, 5, 5, 255))
update_set_screen_map_position_scale(g_tab_map.camera_pos_x, g_tab_map.camera_pos_y, g_tab_map.camera_size)
if is_tab_active then
g_tab_map.camera_pos_x = g_tab_map.camera_pos_x + (g_input_axis.x * g_tab_map.camera_size * 0.01)
g_tab_map.camera_pos_y = g_tab_map.camera_pos_y + (g_input_axis.y * g_tab_map.camera_size * 0.01)
input_map_zoom_camera(1 - (g_input_axis.w * 0.1))
if g_is_mouse_mode then
if g_tab_map.is_drag_pan_map then
g_tab_map.camera_pos_x = g_tab_map.camera_pos_x - ((g_pointer_pos_x - g_pointer_pos_x_prev) * g_tab_map.camera_size * 0.005)
g_tab_map.camera_pos_y = g_tab_map.camera_pos_y + ((g_pointer_pos_y - g_pointer_pos_y_prev) * g_tab_map.camera_size * 0.005)
end
end
else
g_tab_map.is_drag_pan_map = false
end
local vehicle_team = screen_vehicle:get_team()
local vehicle_filter = function(v)
local def = v:get_definition_index()
local team = v:get_team()
return team == vehicle_team and (def == e_game_object_type.chassis_sea_barge or def == e_game_object_type.chassis_carrier)
end
local is_render_islands = (g_tab_map.camera_size < (64 * 1024))
update_set_screen_background_is_render_islands(is_render_islands)
for _, vehicle in iter_vehicles(vehicle_filter) do
if vehicle:get_definition_index() ~= e_game_object_type.chassis_carrier then
local waypoint_count = vehicle:get_waypoint_count()
local pos_prev = vehicle:get_position_xz()
for i = 0, waypoint_count do
local waypoint_data = vehicle:get_waypoint(i)
if waypoint_data:get() then
local waypoint_pos = waypoint_data:get_position_xz()
local s0x, s0y = get_screen_from_world(pos_prev:x(), pos_prev:y(), g_tab_map.camera_pos_x, g_tab_map.camera_pos_y, g_tab_map.camera_size, screen_w, screen_h)
local s1x, s1y = get_screen_from_world(waypoint_pos:x(), waypoint_pos:y(), g_tab_map.camera_pos_x, g_tab_map.camera_pos_y, g_tab_map.camera_size, screen_w, screen_h)
update_ui_line(s0x, s0y, s1x, s1y, color_grey_dark)
pos_prev = waypoint_pos
end
end
end
end
for _, link in iter_resource_links() do
render_resource_link(link, screen_w, screen_h)
end
local is_collapse_icons = g_tab_map.camera_size > g_tab_map.camera_size_max * 0.4
local team_color = update_get_team_color(vehicle_team)
local tile_color = color8(16, 16, 16, 255)
for _, tile in iter_tiles() do
local tile_position = tile:get_position_xz()
local screen_pos_x, screen_pos_y = get_screen_from_world(tile_position:x(), tile_position:y(), g_tab_map.camera_pos_x, g_tab_map.camera_pos_y, g_tab_map.camera_size, screen_w, screen_h)
local tile_icon_color = g_map_colors.inactive
if tile:get_team_control() == vehicle_team then
tile_icon_color = g_map_colors.factory
end
local category_data = g_item_categories[tile:get_facility_category()]
local tile_col = iff(is_tile_hovered(tile) or is_tile_dragged(tile), color_white, tile_icon_color)
if is_collapse_icons then
update_ui_rectangle(screen_pos_x - 1, screen_pos_y - 1, 2, 2, tile_col)
else
update_ui_rectangle(screen_pos_x - 5, screen_pos_y - 4, 10, 8, color_black)
update_ui_rectangle(screen_pos_x - 4, screen_pos_y - 5, 8, 10, color_black)
local is_collapse_names = g_tab_map.camera_size < g_tab_map.camera_size_max * 0.2
if is_collapse_names then
update_ui_text(screen_pos_x - 64, screen_pos_y - 16, tile:get_name(), 128, 1, color_black, 0)
end
update_ui_image(screen_pos_x - 4, screen_pos_y - 4, category_data.icon, tile_col, 0)
end
if category_data.index ~= 0 and tile:get_team_control() == vehicle_team then
local production_factor = tile:get_facility_production_factor()
local queue_count = tile:get_facility_production_queue_count()
if queue_count > 0 then
if is_collapse_icons then
if g_animation_time % 30 > 15 then
update_ui_rectangle(screen_pos_x - 1, screen_pos_y - 1, 2, 2, g_map_colors.progress)
end
else
update_ui_rectangle(screen_pos_x - 4, screen_pos_y + 5, 8, 2, color_black)
update_ui_rectangle(screen_pos_x - 4, screen_pos_y + 5, 8 * production_factor, 2, g_map_colors.progress)
end
end
end
end
for _, vehicle in iter_vehicles(vehicle_filter) do
local vehicle_def = vehicle:get_definition_index()
local vehicle_position = vehicle:get_position_xz()
local screen_pos_x, screen_pos_y = get_screen_from_world(vehicle_position:x(), vehicle_position:y(), g_tab_map.camera_pos_x, g_tab_map.camera_pos_y, g_tab_map.camera_size, screen_w, screen_h)
local region_vehicle_icon, icon_offset = get_icon_data_by_definition_index(vehicle_def)
if vehicle_def == e_game_object_type.chassis_sea_barge then
local vehicle_col = iff(is_vehicle_hovered(vehicle) or is_vehicle_dragged(vehicle), color_white, g_map_colors.barge)
if is_collapse_icons then
update_ui_rectangle(screen_pos_x - 1, screen_pos_y - 1, 2, 2, vehicle_col)
else
update_ui_image(screen_pos_x - icon_offset, screen_pos_y - icon_offset, region_vehicle_icon, vehicle_col, 0)
end
local transfer_item = vehicle:get_barge_transfer_item()
if g_item_data[transfer_item] ~= nil then
if is_collapse_icons then
if g_animation_time % 30 > 15 then
update_ui_rectangle(screen_pos_x - 1, screen_pos_y - 1, 2, 2, g_map_colors.progress)
end
else
update_ui_rectangle(screen_pos_x - 4, screen_pos_y + 3, 8, 2, color_black)
update_ui_rectangle(screen_pos_x - 4, screen_pos_y + 3, 8 * get_barge_transfer_progress(vehicle), 2, g_map_colors.progress)
end
end
elseif vehicle_def == e_game_object_type.chassis_carrier then
local vehicle_col = iff(is_vehicle_hovered(vehicle) or is_vehicle_dragged(vehicle), color_white, g_map_colors.carrier)
if is_collapse_icons then
update_ui_rectangle(screen_pos_x - 2, screen_pos_y - 2, 4, 4, vehicle_col)
else
update_ui_image(screen_pos_x - icon_offset, screen_pos_y - icon_offset, region_vehicle_icon, vehicle_col, 0)
end
end
end
if g_tab_map.dragged_id ~= 0 then
local drag_start = get_resource_node_position(g_tab_map.dragged_id, g_tab_map.dragged_type)
if drag_start then
local screen_drag_x, screen_drag_y = get_screen_from_world(drag_start:x(), drag_start:y(), g_tab_map.camera_pos_x, g_tab_map.camera_pos_y, g_tab_map.camera_size, screen_w, screen_h)
update_ui_line(screen_drag_x, screen_drag_y, g_tab_map.cursor_pos_x, g_tab_map.cursor_pos_y, color_white)
end
end
if is_tab_active then
if g_is_mouse_mode == false then
update_ui_image(screen_w / 2 - 5, screen_h / 2 - 5, atlas_icons.map_icon_crosshair, iff(g_tab_map.hovered_id ~= 0, color_black, color_white), 0)
end
if g_is_mouse_mode == false or g_tab_map.is_drag_pan_map == false then
update_map_hovered(screen_w, screen_h, screen_vehicle)
end
else
clear_hover()
clear_drag()
end
end
function render_map_ui(screen_w, screen_h, x, y, w, h, screen_vehicle, is_tab_active)
local ui = g_ui
if is_tab_active then
if g_tab_map.selected_barge_id ~= 0 then
g_tab_map.is_overlay = true
update_ui_rectangle(0, 0, screen_w, screen_h, color8(0, 0, 0, 200))
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_ud)
local selected_barge = update_get_map_vehicle_by_id(g_tab_map.selected_barge_id)
if selected_barge:get() and selected_barge:get_team() == screen_vehicle:get_team() then
ui:begin_window(update_get_loc(e_loc.upp_barge_id).." " .. g_tab_map.selected_barge_id .. "##barge", x + 15, y + 5, w - 30, h - 15, atlas_icons.column_stock, is_tab_active, 2)
local region_w, region_h = ui:get_region()
render_barge_inventory_status(0, 0, region_w, 22, selected_barge)
ui:spacer(22)
imgui_barge_inventory_table(ui, selected_barge, false)
ui:divider(0, 3)
ui:divider(0, 10)
ui:end_window()
else
g_tab_map.selected_barge_id = 0
end
elseif g_tab_map.selected_facility_id ~= 0 then
g_tab_map.is_overlay = true
update_ui_rectangle(0, 0, screen_w, screen_h, color8(0, 0, 0, 200))
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_ud)
local facility_tile = update_get_tile_by_id(g_tab_map.selected_facility_id)
if facility_tile:get() and facility_tile:get_team_control() == screen_vehicle:get_team() then
local category_data = g_item_categories[facility_tile:get_facility_category()]
if category_data.index ~= 0 then
local left_w = w - 75
local right_w = w - left_w
local is_windows_active = is_tab_active and g_tab_map.selected_facility_item == -1 and g_tab_map.selected_facility_queue_item == -1
if is_windows_active and g_is_mouse_mode and g_is_pointer_hovered then
if g_pointer_pos_x > left_w then
g_tab_map.selected_panel = 1
else
g_tab_map.selected_panel = 0
end
end
local window = ui:begin_window(category_data.name .. "##facility", 5, y, left_w - 5, h - 5, category_data.icon, is_windows_active and g_tab_map.selected_panel == 0, 2)
if ui:list_item(update_get_loc(e_loc.upp_queue), true) then
g_tab_map.selected_panel = 1
end
local items_unlocked = {}
local items_locked = {}
local team_data = update_get_team(screen_vehicle:get_team())
if team_data:get() then
for i = 1, category_data.item_count do
local item = category_data.items[i]
if update_get_resource_item_hidden_facility_production(item.index) == false then
if team_data:get_is_blueprint_unlocked(item.index) then
table.insert(items_unlocked, item)
else
table.insert(items_locked, item)
end
end
end
end
local column_widths = { 13, 122, -1 }
local column_margins = { 5, 2, 2 }
if #items_unlocked > 0 then
imgui_table_header(ui, {
{ w=column_widths[1] + column_widths[2], margin=column_margins[1], value=update_get_loc(e_loc.upp_blueprints) },
{ w=column_widths[3], margin=column_margins[3], value=atlas_icons.column_stock }
})
for i = 1, #items_unlocked do
local item_count = math.min(facility_tile:get_facility_inventory_count(items_unlocked[i].index), 99999)
local columns = {
{ w=column_widths[1], margin=column_margins[1], value=atlas_icons.column_stock, col=color_grey_mid, is_border=false },
{ w=column_widths[2], margin=column_margins[2], value=items_unlocked[i].name },
{ w=column_widths[3], margin=column_margins[3], value=tostring(item_count), col=iff(item_count > 0, color_status_ok, color_status_bad) }
}
local is_action = imgui_table_entry(ui, columns, true)
if is_action then
g_tab_map.selected_facility_item = items_unlocked[i].index
end
end
end
if #items_locked > 0 then
imgui_table_header(ui, {
{ w=column_widths[1] + column_widths[2], margin=column_margins[1], value=update_get_loc(e_loc.upp_locked) },
{ w=column_widths[3], margin=column_margins[3], value=atlas_icons.column_stock }
})
for i = 1, #items_locked do
local item_count = math.min(facility_tile:get_facility_inventory_count(items_locked[i].index), 99999)
local columns = {
{ w=column_widths[1], margin=column_margins[1], value=atlas_icons.column_locked, col=color_status_bad, is_border=false },
{ w=column_widths[2], margin=column_margins[2], value=items_locked[i].name, col=color_status_bad },
{ w=column_widths[3], margin=column_margins[3], value=tostring(item_count), col=color_grey_dark }
}
imgui_table_entry(ui, columns, false)
end
end
ui:spacer(5)
ui:end_window()
ui:begin_window(update_get_loc(e_loc.upp_status).."##facilitystatus", left_w, y, right_w - 5, 35, atlas_icons.map_icon_factory, false, 1)
local region_w, region_h = ui:get_region()
render_map_facility_queue(5, 3, region_w - 10, region_h, facility_tile)
ui:end_window()
ui:begin_window(update_get_loc(e_loc.upp_queue).."##facilityqueue", left_w, y + 24, right_w - 5, h - 29, atlas_icons.column_pending, is_windows_active and g_tab_map.selected_panel == 1, 2)
local queue_count = facility_tile:get_facility_production_queue_count()
for i = 0, queue_count - 1 do
local item_type, item_count = facility_tile:get_facility_production_queue_item(i)
local item_data = g_item_data[item_type]
item_count = math.min(item_count, 99999)
if item_data ~= nil then
if imgui_item_button(ui, item_data, "x" .. item_count, true) then
g_tab_map.selected_facility_queue_item = i
end
if i == 0 then
ui:divider(0, 2)
end
end
end
ui:spacer(1)
ui:end_window()
if g_tab_map.selected_facility_queue_item ~= -1 then
update_ui_rectangle(0, 0, screen_w, screen_h, color8(0, 0, 0, 200))
local item_type, item_count = facility_tile:get_facility_production_queue_item(g_tab_map.selected_facility_queue_item)
local item_data = g_item_data[item_type]
if item_data ~= nil then
local window = ui:begin_window(item_data.name .. "##queueitem", 30, y + 10, w - 60, h - 30, atlas_icons.column_pending, true, 2)
imgui_item_description(ui, screen_vehicle, item_data, false)
imgui_table_header(ui, {
{ w=134, margin=5, value=update_get_loc(e_loc.upp_queue) },
{ w=10, margin=0, value=atlas_icons.column_stock },
{ w=-1, margin=0, value="x" .. item_count }
})
ui:spacer(1)
local result = ui:button_group({ "X", "-1", "-10", "-100", "-1000" }, true)
local remove_count = 0
if result == 0 then
remove_count = item_count
elseif result == 1 then
remove_count = 1
elseif result == 2 then
remove_count = 10
elseif result == 3 then
remove_count = 100
elseif result == 4 then
remove_count = 1000
end
if remove_count > 0 then
facility_tile:set_facility_remove_production_queue_item(g_tab_map.selected_facility_queue_item, math.min(remove_count, item_count))
if remove_count >= item_count then
g_tab_map.selected_facility_queue_item = -1
end
end
ui:end_window()
else
g_tab_map.selected_facility_queue_item = -1
end
end
if g_tab_map.selected_facility_item ~= -1 then
update_ui_rectangle(0, 0, screen_w, screen_h, color8(0, 0, 0, 200))
local item = g_item_data[g_tab_map.selected_facility_item]
if item ~= nil then
local window = ui:begin_window(item.name .. "##facilityitem", 30, y + 10, w - 60, h - 30, atlas_icons.column_stock, true, 2)
imgui_item_description(ui, screen_vehicle, item, false)
local production_count = facility_tile:get_facility_production_queue_item_type(item.index)
imgui_table_header(ui, {
{ w=134, margin=5, value=update_get_loc(e_loc.upp_queue) },
{ w=10, margin=0, value=atlas_icons.column_stock },
{ w=-1, margin=0, value="x" .. production_count }
})
ui:spacer(1)
local result = ui:button_group({ "+1", "+10", "+100", "+1000" }, true)
if result == 0 then
facility_tile:set_facility_add_production_queue_item(item.index, 1)
elseif result == 1 then
facility_tile:set_facility_add_production_queue_item(item.index, 10)
elseif result == 2 then
facility_tile:set_facility_add_production_queue_item(item.index, 100)
elseif result == 3 then
facility_tile:set_facility_add_production_queue_item(item.index, 1000)
end
ui:end_window()
else
g_tab_map.selected_facility_item = -1
end
end
else
ui:begin_window(category_data.name .. "##warehouse", x + 15, y + 5, w - 30, h - 15, category_data.icon, is_tab_active, 2)
imgui_facility_inventory_table(ui, facility_tile)
ui:divider(0, 3)
ui:divider(0, 10)
ui:end_window()
end
else
g_tab_map.selected_facility_id = 0
end
else
local zoom_factor = invlerp(g_tab_map.camera_size, g_tab_map.camera_size_min, g_tab_map.camera_size_max)
local world_x, world_y = get_world_from_screen(g_tab_map.cursor_pos_x, g_tab_map.cursor_pos_y, g_tab_map.camera_pos_x, g_tab_map.camera_pos_y,g_tab_map.camera_size, screen_w, screen_h)
update_ui_text(10, screen_h - 13,
string.format("X:%-6.0f ", world_x) ..
string.format("Y:%-6.0f ", world_y) ..
string.format("Z:%.2f", zoom_factor),
w - 10, 0, color_grey_dark, 0
)
if g_tab_map.hovered_id ~= 0 then
local tooltip_w = 128