forked from zenyr/PocoHud3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHud3_class.lua
4188 lines (3911 loc) · 121 KB
/
Hud3_class.lua
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
---
local ALTFONT = 'fonts/font_eroded'
local FONT = 'fonts/font_medium_mf' -- or tweak_data.hud_present.title_font or tweak_data.hud_players.name_font or 'fonts/font_eroded' or 'core/fonts/system_font'
local FONTLARGE = 'fonts/font_large_mf'
local clGood = cl.YellowGreen
local clBad = cl.Gold
local isNil = function(a) return a == nil end
local inGame = CopDamage ~= nil
local ModPath = rawget(_G,'ModPath') and string.gsub(string.gsub(debug.getinfo(1).short_src,'\\','/'), "^(.+/)[^/]+$", "%1") or PocoDir
local SavePath = rawget(_G,'SavePath') or ModPath
local KitsJSONFileName = SavePath..'hud3_kits.json'
local KarmaJSONFileName = SavePath..'hud3_karma.json'
local LocJSONFileName = ModPath..'hud3_locale$.json'
local LocationJSONFilename = ModPath..'hud3_rooms.json'
local Icon = {
A=57344, B=57345, X=57346, Y=57347, Back=57348, Start=57349,
Skull = 57364, Ghost = 57363, Dot = 1031, Chapter = 1015, Div = 1014, BigDot = 1012,
Times = 215, Divided = 247, LC=139, RC=155, DRC = 1035, Deg = 1024, PM= 1030, No = 1033,
}
for k,v in pairs(Icon) do
Icon[k] = utf8.char(v)
end
local now = function () return managers.player:player_timer():time() --[[TimerManager:game():time()]] end
local PocoEvent = {
In = 'onEnter',
Out = 'onExit',
Pressed = 'onPressed',
Released = 'onReleased',
PressedAlt = 'onPressedAlt',
ReleasedAlt = 'onReleasedAlt',
Click = 'onClick',
WheelUp = 'onWheelUp',
WheelDown = 'onWheelDown',
Move = 'onMove',
}
local O, K, L, me
PocoHud3Class = {
ALTFONT = ALTFONT ,
FONT = FONT ,
FONTLARGE = FONTLARGE,
clGood = clGood ,
clBad = clBad ,
Icon = Icon ,
PocoEvent = PocoEvent,
}
PocoHud3Class.loadVar = function(_O,_me,_L)
O = _O
L = _L
me = _me
clGood = O:get('root','colorPositive')
clBad = O:get('root','colorNegative')
end
local _defaultLocaleData = {
_client_name = 'PocoHud3',
_about_trans_fullList = '{Dansk (DA)|Tan}\nNickyFace, DanishDude93\n{Deutsch (DE)|Tan}\nfallenpenguin, Raxdor, GIider, Hoffy,\nNowRiseAgain, Pixelpille, Sithryl,\nValkein, Zee_, baddog_11\n{Español (ES)|Tan}\nNiccy, BurnBabyBurn\n{Français (FR)|Tan}\nChopper385, Dewk Noukem, Lekousin, Shendow\n{Italiano (IT)|Tan}\nOktober, Nitronik\n{Bahasa Indonesia (ID)|Tan}\nPapin Faizal(papin97)\n{Nederlands (NL)|Tan}\nNickolas Cat, Rezqual\n{Norsk (NO)|Tan}\nikoddn\n{Polski (PL_PL)|Tan}\nMartinz, Kuziz, gmaxpl3\n{Português (PT_PT)|Tan}\nBruno \"Personagem\" Tibério, John Ryder\n{Português (PT_BR)|Tan}\njkisten\n{Русский (RU)|Tan}\ncollboy, Hellsing, troskahtoh\n{Svenska (SV_SE)|Tan}\nTheLovinator, KillYoy, kao172',
_about_trans_special_thanks_list = '{Overkill|White}\nfor a legendary game {& not kicking my arse off|Silver|0.5}\n{Harfatus|White}\nfor a cool injector\n{Olipro|White}\nfor keeping MOD community alive\n{v00d00 & gir489 & 90e|White}\nfor making me able to learn Lua from the humble ground\n{Arkkat|White}\nfor crashing the game for me at least 50 times since alpha stage\n{Tatsuto|White}\nfor PD2Stats.com API\n{You|Yellow}\nfor keeping me way too busy to go out at weekends {/notreally|Silver|0.5}',
_kit_equip_btn_hint = '{_kit_equip_btn_hint1} {_kit_equip_btn_hint2|Tan}\n{_kit_equip_btn_hint3} {_kit_equip_btn_hint4|Red} {_kit_equip_btn_hint5}',
_kit_key_edit_hint = '{_kit_key_edit_hint1} {_kit_key_edit_hint2|Yellow} {_kit_key_edit_hint3}\n{_kit_key_edit_hint4|Silver}\n{_kit_key_edit_hint5|Red}',
_kit_profiler_desc = '{_Chapter} {_kit_profiler_desc1} {_RC|White} {_kit_profiler_desc2|White}',
_kit_save_desc = '{_Chapter} {_kit_save_desc1} {_RC|White} {_kit_save_desc2|White}',
_kit_save_hint = '{_kit_save_hint1|Tan} / {_kit_save_hint2|Tomato} {_kit_save_hint3}',
_kit_saved_kits_title = '{_Chapter} {_kit_saved_kits_title1} {_RC|White} {_kit_saved_kits_title2|White}',
_mob_city_swat = 'a Gensec Elite',
_mob_cop = 'a cop',
_mob_fbi = 'an FBI agent',
_mob_fbi_heavy_swat = 'an FBI heavy SWAT',
_mob_fbi_swat = 'an FBI SWAT',
_mob_gangster = 'a gangster',
_mob_gensec = 'a Gensec guard',
_mob_heavy_swat = 'a heavy SWAT',
_mob_security = 'a guard',
_mob_shield = 'a shield',
_mob_sniper = 'a sniper',
_mob_spooc = 'a cloaker',
_mob_swat = 'a SWAT',
_mob_tank = 'a bulldozer',
_mob_taser = 'a taser',
_msg_around = 'around [1]',
_msg_captured = '[1] has been captured [2]',
_msg_converted = '[1] converted [2] [3]',
_msg_downed = '[1] was downed',
_msg_downedWarning = 'Warning: [1] has been downed [2] times',
_msg_minionLost = '[1] lost a minion to [2] [3].',
_msg_minionShot = '[1] damaged [2] minion for [3]',
_msg_not_implemented = 'Not Implemented for now',
_msg_repenished = '[1] replenished health by [2]% [3]',
_msg_replenishedDown = '(+[1] down)',
_msg_replenishedDownPlu = '(+[1] downs)',
_msg_usedPistolMessiah = 'Used Pistol messiah, [1] left.',
_msg_usedPistolMessiahCharges = '[1] charge',
_msg_usedPistolMessiahChargesPlu = '[1] charges',
_opt_chat_desc = '{_opt_chat_desc_1}\n{_opt_chat_desc_2|White|0.5}\n{_opt_chat_desc_3|White|0.6}\n{_opt_chat_desc_4|White|0.7}\n{_opt_chat_desc_5|White|0.8}\n{_opt_chat_desc_6|White|0.9}\n{_opt_chat_desc_7|White}',
_opt_truncateTags_desc = '{_opt_truncateTags_desc_1} {[Poco]Hud|Tan} > {_Dot|Tan}{Hud|Tan}',
_vanity_resizeCrimenet = '60%,70%,80%,90%,100%,110%,120%,130%',
}
--- miniClass start ---
local TBuff = class()
PocoHud3Class.TBuff = TBuff
function TBuff:init(owner,data)
self.owner = owner
self.ppnl = owner.pnl.buff
self:set(data)
end
function TBuff:set(data)
self.dead = false
local st = self.data and self.data.st
self.data = data
if st and data.et ~= 1 then
self.data.st = st
end
end
function TBuff:_make()
local buffO = O:get('buff')
local style = buffO.style
local vanilla = style == 2
local glowy = style == 3
local size = style==2 and 40 or buffO.buffSize
local data = self.data
local simple = self.owner:_isSimple(data.key)
self.created = true
if simple then
local simpleRadius = buffO.simpleBusySize
local pnl = self.ppnl:panel({x = (self.owner.ww or 0)/2-simpleRadius,y=(self.owner.hh or 0)/2-simpleRadius, w=simpleRadius*2,h=simpleRadius*2})
self.pnl = pnl
local texture = data.good and 'guis/textures/pd2/hud_progress_active' or 'guis/textures/pd2/hud_progress_invalid'
self.pie = CircleBitmapGuiObject:new( pnl, { use_bg = false, x=0,y=0,image = texture, radius = simpleRadius, sides = 64, current = 20, total = 64, blend_mode = 'add', layer = 0} )
elseif vanilla then
local pnl = self.ppnl:panel({x = 0,y=0, w=100,h=100})
self.pnl = pnl
self.lbl = pnl:text{text='', font=FONT, align='center', font_size = size/2, color = data.color or data.good and clGood or clBad, x=1,y=1, layer=2, blend_mode = 'normal'}
self.bg = HUDBGBox_create( pnl, { w = size, h = size, x = 0, y = 0 }, { color = cl.White, blend_mode = 'normal' } )
self.bmp = data.icon and pnl:bitmap( { name='icon', texture=data.icon, texture_rect=data.iconRect, blend_mode = 'add', layer=1, x=0,y=0, color=style==2 and cl.White or data.good and clGood or clBad } ) or nil
local texture = data.good and 'guis/textures/pd2/hud_progress_active' or 'guis/textures/pd2/hud_progress_invalid'
if self.bmp then
if self.bmp:width() > size then
self.bmp:set_size(size,size)
end
self.bmp:set_center(5+size + size/2,size/2)
end
pnl:set_shape(0,0,size*2+5,size*1.25)
pnl:set_position(-100,-100)
else
local pnl = self.ppnl:panel({x = 0,y=0, w=100,h=100})
self.pnl = pnl
self.lbl = pnl:text{text='', font=FONT, font_size = size/4, color = data.color or data.good and clGood or clBad, x=1,y=1, layer=2, blend_mode = 'normal', rotation = 360}
self.bg = pnl:bitmap( { name='bg', texture= 'guis/textures/pd2/hud_tabs',texture_rect= { 105, 34, 19, 19 }, color= cl.Black:with_alpha(0.2), layer=0, x=0,y=0 } )
self.bmp = data.icon and pnl:bitmap( { name='icon', texture=data.icon, texture_rect=data.iconRect, blend_mode = 'add', layer=1, x=0,y=0, color=data.good and clGood or clBad } ) or nil
if glowy then
self.pie = CircleBitmapGuiObject:new( pnl, { use_bg = false, x=0,y=0,image = 'guis/textures/pd2/specialization/progress_ring',
radius = size/2*1.2, sides = 64, current = 20, total = 64, blend_mode = 'add', layer = 0} )
self.pie:set_position( -size*0.1, -size*0.1)
else
local texture = data.good and 'guis/textures/pd2/hud_progress_active' or 'guis/textures/pd2/hud_progress_invalid'
self.pie = CircleBitmapGuiObject:new( pnl, { use_bg = false, x=0,y=0,image = texture, radius = size/2, sides = 64, current = 20, total = 64, blend_mode = 'add', layer = 0} )
self.pie:set_position( 0, 0)
end
if self.bmp then
if self.bmp:width() > 0.7*size then
self.bmp:set_size(0.7*size,0.7*size)
end
self.bmp:set_center(size/2,size/2)
end
pnl:set_shape(0,0,size,size*1.25)
self.bg:set_size(size,size)
pnl:set_position(-100,-100)
end
end
function TBuff:draw(t,x,y)
if not self.dead then
if not self.created then
self:_make()
end
local data = self.data
local st,et = data.st,data.et or 0
local prog = (now()-st)/(et-st)
local style = O:get('buff','style')
local vanilla = style == 2
local glowy = style == 3
local simple = self.owner:_isSimple(data.key)
if (prog >= 1 or prog < 0) and et ~= 1 then
self.dead = true
elseif alive(self.pnl) then
if et == 1 then
prog = st
end
x = self.x and self.x + (x-self.x)/5 or x
y = self.y and self.y + (y-self.y)/5 or y
if not simple then
self.pnl:set_center(x,y)
end
self.x = x
self.y = y
local txts
if simple then
elseif vanilla then
local sTxt = self.owner:_lbl(nil,data.text)
if et == 1 then -- Special
sTxt = sTxt ~= '' and (sTxt or ''):gsub(' ','\n') or _.f(prog*100,1)..'%'
else
sTxt = _.f(et-now(),1)..'s'
end
txts = {{sTxt,cl.White}}
else
if type(data.text)=='table' then
txts = data.text
else
txts = {{data.text and data.text..' ' or '',data.color}}
table.insert(txts,{_.f(et ~= 1 and et-now() or prog*100)..(et == 1 and '%' or 's'),data.good and clGood or clBad})
end
end
if not simple then
self.owner:_lbl(self.lbl,txts)
local _x,_y,w,h = self.lbl:text_rect()
self.lbl:set_size(w,h)
if vanilla then
local ww, hh = self.bg:size()
self.lbl:set_center(ww/2,hh/2)
else
local ww, hh = self.pnl:size()
self.lbl:set_center(ww/2,hh-h/2)
end
end
if self.pie then
if O:get('buff','mirrorDirection') then
self.pie._circle:set_rotation(-(1-prog)*360)
end
self.pie:set_current(1-prog)
end
if not self.dying then
self.pnl:set_alpha(1)
end
end
end
end
function TBuff:_fade(pnl, done_cb, seconds)
local pnl = self.pnl
if not pnl then return end
pnl:set_visible( true )
pnl:set_alpha( 1 )
local t = seconds
while alive(pnl) and t > 0 do
if not self.dead then
self.dying = false
break
end
local dt = coroutine.yield()
t = t - dt
pnl:set_alpha((self.lastD or 1) * t/seconds )
end
if self.dying then
pnl:set_visible( false )
if done_cb then done_cb(pnl) end
end
end
function TBuff:destroy(skipAnim)
local pnl = self.pnl
if self.created and alive(self.ppnl) and alive(pnl) then
if not skipAnim then
if not self.dying then
self.dying = true
pnl:stop()
pnl:animate( callback( self, self, '_fade' ), callback( self, self, 'destroy' , true), 0.25 )
end
else
self.ppnl:remove(self.pnl)
self.owner.buffs[self.data.key] = nil
end
end
end
-------
local TPop = class()
PocoHud3Class.TPop = TPop
function TPop:init(owner,data)
self.owner = owner
self.data = data
self.data.st=now()
self.ppnl = owner.pnl.pop
self:_make()
end
function TPop:_make()
local size = O:get('popup','size')
local pnl = self.ppnl:panel({x = 0, y = 0, w=200, h=100})
local data = self.data
self.pnl = pnl
self.lbl = pnl:text{text='', font=FONT, font_size = size, color = data.color or data.good and clGood or clBad, x=0,y=0, layer=3, blend_mode = 'add'}
local _txt = self.owner:_lbl(self.lbl,data.text)
self.lblBg = pnl:text{text=_txt, font=FONT, font_size = size, color = cl.Black, x=1,y=1, layer=2, blend_mode = 'normal'}
local x,y,w,h = self.lblBg:text_rect()
pnl:set_shape(-100,-100,w,h)
end
function TPop:draw(t)
local isADS = self.owner.ADS
local camPos = self.owner.camPos
if not self.dead and alive(self.pnl) then
local data = self.data
local st,et = data.st,data.et
local prog = (now()-st)/(et-st)
local pos = data.pos + Vector3()
local nl_dir = pos - camPos
mvector3.normalize( nl_dir )
local dot = mvector3.dot( self.owner.nl_cam_forward, nl_dir )
self.pnl:set_visible( dot > 0 )
if dot > 0 then
local pPos = self.owner:_v2p(pos)
if not data.stay then
mvector3.set_y(pPos,pPos.y - math.lerp(100,0, math.pow(1-prog,7)))
end
if prog >= 1 then
self.dead = true
else
local dx,dy,d,ww,hh = 0,0,1,self.owner.ww,self.owner.hh
self.pnl:set_center( pPos.x,pPos.y)
if isADS then
dx = pPos.x - ww/2
dy = pPos.y - hh/2
d = math.clamp((dx*dx+dy*dy)/1000,0,1)
else
d = 1-math.pow(prog,5)
end
d = math.min(d,self.owner:_visibility(false))
self.pnl:set_alpha(math.min(1-prog,d))
end
end
end
end
function TPop:destroy(key)
self.ppnl:remove(self.pnl)
if key then
self.owner.pops[key] = nil
end
end
local TFloat = class()
PocoHud3Class.TFloat = TFloat
function TFloat:init(owner,data)
self.owner = owner
self.category = data.category
self.unit = data.unit
self.key = data.key
self.tag = data.tag or {}
self.temp = data.temp
self.lastT = type(self.temp) == 'number' and self.temp or now()
self.ppnl = owner.pnl.pop
self:_make()
end
function TFloat:__shadow(x)
if x then
self.lblShadow1:set_x(x+1)
self.lblShadow2:set_x(x-1)
else
self.lblShadow1:set_text(self._txts)
self.lblShadow2:set_text(self._txts)
end
end
function TFloat:_make()
local floatO = O:get('float')
local size = floatO.size
local m = floatO.margin
local pnl = self.ppnl:panel({x = 0,y=-size, w=300,h=100})
local texture = 'guis/textures/pd2/hud_health' or 'guis/textures/pd2/hud_progress_32px'
self.pnl = pnl
self.bg = floatO.frame
and HUDBGBox_create(pnl, {x= 0,y= 0,w= 1,h= 1},{color=cl.White:with_alpha(1)})
or pnl:bitmap( { name='blur', texture='guis/textures/test_blur_df', render_template='VertexColorTexturedBlur3D', layer=-1, x=0,y=0 } )
self.pie = CircleBitmapGuiObject:new( pnl, { use_bg = false, x=m,y=m,image = texture, radius = size/2, sides = 64, current = 20, total = 64, blend_mode = 'normal', layer = 4} )
self.pieBg = pnl:bitmap( { name='pieBg', texture='guis/textures/pd2/hud_progress_active', w = size, h = size, layer=3, x=m,y=m, color=cl.Black:with_alpha(0.5) } )
self.lbl = pnl:text{text='text', font=FONT, font_size = size, color = cl.White, x=size+m*2,y=m, layer=3, blend_mode = 'normal'}
self.lblShadow1 = pnl:text{text='shadow', font=FONT, font_size = size, color = cl.Black:with_alpha(0.3), x=1+size+m*2,y=1+m, layer=2, blend_mode = 'normal'}
self.lblShadow2 = pnl:text{text='shadow', font=FONT, font_size = size, color = cl.Black:with_alpha(0.3), x=size+m*2-1,y=1+m, layer=2, blend_mode = 'normal'}
end
local _drillNames = {
drill = 'Drill',
lance = 'Thermal Drill',
uload_database = 'Upload',
votingmachine2 = 'Voting Machine',
hack_suburbia = 'Hacking Machine',
hold_download_keys = 'Encryption Keys', -- Hoxton Breakout
hold_hack_comp = 'Security Clearance', -- Hoxton Breakout Directors PC
hold_analyze_evidence = 'Evidence Analysis', -- Hoxton Breakout
digitalgui = 'Timelock',
huge_lance = 'The Beast',
gen_int_saw = 'Saw', -- Generic saw
apartment_saw = 'Saw', -- Saw
}
local _drillHosts = {
['d2e9092f3a57cefc'] = 'a mini safe',
['e87e439e3e1a7313'] = 'a mini titan safe',
['ad6fb7a483695e19'] = 'a safe',
['dbfbfbb21eddcd30'] = 'a titan safe',
['3e964910f730f3d7'] = 'a huge safe',
['246cc067a20249df'] = 'a huge titan safe',
['8834e3a4da3df5c6'] = 'a tall safe',
['e3ab30d889c6db5f'] = 'a tall titan safe',
['4407f5e571e2f51a'] = 'a door',
['0afafcebe54ae7c4'] = 'a cage door',
['1153b673d51ed6ad'] = 'a Gensec truck',
['04080fd150a77c7f'] = 'a crashed Gensec truck',
['0d07ff22a1333115'] = 'a sniped Gensec truck',
['a8715759c090b251'] = 'a fence door',
['a7b371bf0e3fd30a'] = 'a truck hinge',
['07e2cf254ef76c5e'] = 'a vault cage door',
['d475830b4e6eda32'] = 'a vault door',
['b2928ed7d5b8797e'] = 'a cage door',
['43132b0a273df773'] = 'an office door',
['b8ebd1a5a8426e52'] = 'an artifact safe'
}
local __n = {}
function TFloat:_getName()
local name = self._name or 'Drill'
local host = self._host
local a = not name:find('The ') and 'A' or ''
if a then
local n = name:sub(1,1):lower()
if n == 'a' or n == 'e' or n == 'i' or n == 'o' or n == 'u' then
a = a .. 'n'
end
end
return _.s(a,name:lower(),host and 'on' or nil,host)
end
function TFloat:_getHost()
local mD = self.unit and alive(self.unit) and self.unit:mission_door_device()
local pD = mD and mD._parent_door
local key = pD and pD:name():key()
if key and not _drillHosts[key] then
_(os.date(),'Found a new DrillHost',key,'\n')
end
return key and _drillHosts[key] or nil
end
function TFloat:draw(t)
if not alive(self.unit) or (self.temp and (t-self.lastT>0.5)) and not self.dead then
self.dead = true
end
if self.dead and not self.dying then
self:destroy()
end
if not alive(self.pnl) then
return
end
local floatO = O:get('float')
local verbose = self.owner.verbose
local onScr = floatO.keepOnScreen
local size = floatO.size
local m = floatO.margin
local isADS = self.owner.ADS
local camPos = self.owner.camPos
local category = self.category
local prog,txts = 0,{}
local unit = self.unit
if not alive(unit) then return end
local dx,dy,d,pDist,ww,hh= 0,0,1,0,self.owner.ww,self.owner.hh
if not ww then return end
local pos = self.owner:_pos(unit,true)
local nl_dir = pos - camPos
local dir = pos - camPos
mvector3.normalize( nl_dir )
local dot = mvector3.dot( self.owner.nl_cam_forward, nl_dir )
local pPos = self.owner:_v2p(pos)
local out = false
if onScr and (category == 1 or self.temp) then
local _sm = {floatO.keepOnScreenMarginX,floatO.keepOnScreenMarginY}
local sm = {x = _sm[1]/100, y = _sm[2]/100}
local xm = {x = 1-sm.x, y = 1-sm.y}
if dot < 0
or pPos.x < sm.x*ww or pPos.y < sm.y*hh
or pPos.x > xm.x*ww or pPos.y > xm.y*hh then
local abs = math.abs
local rr = (hh*(0.5-sm.y))/(ww*(0.5-sm.x))
local cV = Vector3(ww/2,hh/2,0)
local dV = pPos:with_z(0) - cV
local mul = 1
mvector3.normalize( dV )
if abs(dV.x * rr) > abs(dV.y) then -- x
mul = ww*(0.5-sm.x)/dV.x
else -- y
mul = hh*(0.5-sm.y)/dV.y
end
out = true
pPos = cV + dV*abs(mul)
end
end
dx = pPos.x - ww/2
dy = pPos.y - hh/2
pDist = dx*dx+dy*dy
self.pnl:set_visible( (onScr and out) or dot > 0 )
if dot > 0 or onScr then
if category == 0 then -- Unit
local cHealth = unit:character_damage() and unit:character_damage()._health and unit:character_damage()._health*10 or 0
local fHealth = cHealth > 0 and unit:character_damage() and (unit:character_damage()._HEALTH_INIT and unit:character_damage()._HEALTH_INIT*10 or unit:character_damage()._health_max and unit:character_damage()._health_max*10 ) or 1
prog = cHealth / fHealth
local cCarry = unit:carry_data()
local isCiv = unit and managers.enemy:is_civilian( unit )
local color = isCiv and cl.Lime or math.lerp( cl.Red:with_alpha(0.8), cl.Yellow, prog )
if self.tag and self.tag.minion then
color = self.owner:_color(self.tag.minion)
end
local distance = unit and mvector3.distance( unit:position(), camPos ) or 0
if cCarry then
color = cl.White
table.insert(txts,{managers.localization:text(tweak_data.carry[cCarry._carry_id].name_id) or 'Bag',color})
else
local isWhisper = managers.groupai:state():whisper_mode()
local pager = isWhisper and unit:interaction()._pager
if pager then
local eT,tT = now()-pager, unit:interaction()._pagerT or 12
local r = eT/tT
local pColor = math.lerp( cl.Red:with_alpha(0.8), cl.Yellow, 1-r )
if r < 1 then
prog = 1 - r
table.insert(txts,{_.s(_.f(tT - eT),'/',_.f(tT)),pColor})
end
end
if pDist > 100000 then
--table.insert(txts,{''})
elseif cHealth == 0 then
table.insert(txts,{Icon.Skull,color})
else
table.insert(txts,{_.f(cHealth)..'/'.._.f(fHealth),color})
if verbose then
table.insert(txts,{' '..math.ceil(dir:length()/100)..'m',cl.White})
end
end
end
pPos = pPos:with_y(pPos.y-size*2)
end
if category == 1 then -- Drill
local tGUI = unit and unit:timer_gui()
local dGUI = unit and unit:digital_gui()
local name
local leftT
if not alive(unit) then
self.dead = true
elseif tGUI then
if tGUI._time_left <= 0 then
self.dead = true
end
name = unit and unit:interaction() and unit:interaction().tweak_data
name = name and name:gsub('_jammed',''):gsub('_upgrade','') or 'drill'
name = _drillNames[name] or name
leftT = tGUI._time_left
prog = 1-tGUI._time_left/tGUI._timer
if pDist < 10000 or verbose then
table.insert(txts,{_.s(name..':',self.owner:_time(tGUI._time_left)..(tGUI._jammed and '!' or ''),'/',self.owner:_time(tGUI._timer)),tGUI._jammed and cl.Red or cl.White})
else
table.insert(txts,{_.s(self.owner:_time(tGUI._time_left))..(tGUI._jammed and '!' or ''),tGUI._jammed and cl.Red or cl.White})
end
elseif dGUI then
dGUI._maxx = math.max( dGUI._maxx or 0, dGUI._timer or 0)
if not (dGUI._ws and dGUI._ws:visible()) or (dGUI._floored_last_timer <= 0) or (dGUI.is_visible and not dGUI:is_visible()) then
return self:destroy(1)
else
self:renew()
end
name = 'digitalgui'
name = _drillNames[name] or 'Timelock'
leftT = dGUI._timer
prog = 1-dGUI._timer/math.max(dGUI._maxx,1)
if pDist < 10000 or self.owner.verbose then
table.insert(txts,{_.s(name..':',self.owner:_time(dGUI._timer),'/',self.owner:_time(dGUI._maxx)),cl.White})
else
table.insert(txts,{_.s(self.owner:_time(dGUI._timer)),cl.White})
end
end
if not self._name then
self._name = name
self._host = self:_getHost()
end
self.isDrill = not not tGUI
if self.isDrill and not self._almost and leftT and leftT <= 10 then
self._almost = true
me:Chat('drillAlmostDone',_.s(self:_getName(),' < 10s left'))
end
end
if category == 2 then -- Deadsimple text
local name = self.tag and self.tag.text
if name and (pDist < 1e6/dir:length() or verbose) then
table.insert(txts,{name,cl.White})
end
pPos = pPos:with_y(pPos.y-size)
self.bg:set_visible(false)
prog = 0
end
if prog > 0 then
self.pie:set_current(prog)
self.pieBg:set_visible(true)
self.lbl:set_x(2*m+size)
self:__shadow(2*m+size)
else
self.pie:set_visible(false)
self.pieBg:set_visible(false)
self.lbl:set_x(m)
self:__shadow(m)
end
if self._txts ~= self.owner:_lbl(nil,txts) then
self._txts = self.owner:_lbl(self.lbl,txts)
self:__shadow()
end
local __,__,w,h = self.lbl:text_rect()
h = math.max(h,size)
self.pnl:set_size(m*2+(w>0 and w+m+1 or 0)+(prog>0 and size or 0),h+2*m)
self.bg:set_size(self.pnl:size())
self.pnl:set_center( pPos.x,pPos.y)
if isADS then
d = math.clamp((pDist-1000)/2000,0.4,1)
else
d = 1
end
d = math.min(d,floatO.opacity/100)
if not (unit and unit:contour() and #(unit:contour()._contour_list or {}) > 0) then
d = math.min(d,self.owner:_visibility(pos))
end
if out then
d = math.min(d,0.5)
end
if not self.dying then
self.pnl:set_alpha(d)
self.lastD = d -- d is for starting alpha
end
end
end
function TFloat:renew(data)
if data then
self.tag = data.tag
if type(data.temp)=='number' then
self.temp = data.temp
self.lastT = math.max(self.lastT,data.temp)
end
end
if self.temp then
self.lastT = math.max(self.lastT,now())
end
self.dead = false
end
function TFloat:destroy(skipAnim)
if self.category == 1 and self.isDrill and not self._done and not me._endGameT then
local r,err = pcall(function()
self._done = true
me:Chat('drillDone',_.s(self:_getName(),'is done'))
end)
if not r then me:err(err) end
end
local pnl = self.pnl
if alive(self.ppnl) and alive(pnl) then
if not skipAnim then
if not self.dying then
self.dying = true
pnl:stop()
pnl:animate( callback( self, TBuff, '_fade' ), callback( self, self, 'destroy' , true), 0.2 )
end
else
self.ppnl:remove(self.pnl)
self.owner.floats[self.key] = nil
end
end
end
local THitDirection = class()
PocoHud3Class.THitDirection = THitDirection
function THitDirection:init(owner,data)
self.owner = owner
self.ppnl = owner.pnl.buff
self.data = data
self.sT = now()
local pnl = self.ppnl:panel{x = 0,y=0, w=200,h=200}
local Opt = O:get('hit')
local rate, color = 1-(data.rate or 1)
color = data.shield and math.lerp( Opt.shieldColor, Opt.shieldColorDepleted, rate ) or math.lerp( Opt.healthColor, Opt.healthColorDepleted, rate )
self.pnl = pnl
local bmp = pnl:bitmap{
name = 'hit', rotation = 360, visible = true,
texture = 'guis/textures/pd2/hitdirection',
color = color,
blend_mode='add', alpha = 1, halign = 'right'
}
self.bmp = bmp
bmp:set_center(100,100)
if Opt.number then
local text = _.f(data.dmg*-10)
local nSize = Opt.numberSize
local font = Opt.numberDefaultFont and FONT or ALTFONT
local lbl = pnl:text{
x = 1,y = 1,font = font, font_size = nSize,
w = nSize*3, h = nSize,
text = text,
color = color,
align = 'center',
layer = 1
}
lbl:set_center(100,100)
self.lbl = lbl
lbl = pnl:text{
x = 1,y = 1,font = font, font_size = nSize,
w = nSize*3, h = nSize,
text = text,
color = cl.Black:with_alpha(0.2),
align = 'center',
layer = 1
}
lbl:set_center(101,101)
self.lbl1 = lbl
lbl = pnl:text{
x = 1,y = 1,font = font, font_size = nSize,
w = nSize*3, h = nSize,
text = text,
color = cl.Black:with_alpha(0.2),
align = 'center',
layer = 1
}
lbl:set_center(99,101)
self.lbl2 = lbl
end
pnl:stop()
local du = Opt.duration
if du == 0 then
du = self.data.time or 2
end
pnl:animate( callback( self, self, 'draw' ), callback( self, self, 'destroy'), du )
end
function THitDirection:draw(pnl, done_cb, seconds)
local pnl = self.pnl
local Opt = O:get('hit')
local ww,hh = self.owner.ww, self.owner.hh
pnl:set_visible( true )
self.bmp:set_alpha( 1 )
local t = seconds
while alive(pnl) and t > 0 do
if self.owner.dead then
break
end
local dt = coroutine.yield()
t = t - dt
local p = t/seconds
self.bmp:set_alpha( math.pow(p,0.5) * Opt.opacity/100 )
local target_vec = self.data.mobPos - self.owner.camPos
local fwd = self.owner.nl_cam_forward
local angle = target_vec:to_polar_with_reference( fwd, math.UP ).spin
local r = Opt.sizeStart + (1-math.pow(p,0.5)) * (Opt.sizeEnd-Opt.sizeStart)
self.bmp:set_rotation(-(angle+90))
if self.lbl then
self.lbl:set_rotation(-(angle))
self.lbl1:set_rotation(-(angle))
self.lbl2:set_rotation(-(angle))
end
pnl:set_center(ww/2-math.sin(angle)*r,hh/2-math.cos(angle)*r)
end
pnl:set_visible( false )
if done_cb then done_cb(pnl) end
end
function THitDirection:destroy()
self.ppnl:remove(self.pnl)
self = nil
end
--- Location start ---
local PocoLocation = {
rooms = {},
r = Draw:pen( 'no_z', cl.Red:with_alpha(0.5) ) ,
g = Draw:pen( 'no_z', cl.Green:with_alpha(0.5) ),
b = Draw:pen( 'no_z', cl.Blue:with_alpha(0.5) ) ,
}
PocoHud3Class.PocoLocation = PocoLocation
function PocoLocation:newRoom(name)
local currentRoom = {}
self.currentName = name
self.currentRoom = currentRoom
_.c('NewRoom',name)
end
function PocoLocation:endRoom()
local lvl = managers.job:current_level_id() or ''
local currentRooms = self.rooms[lvl] or {}
if type(currentRooms) == 'string' then
currentRooms = self.rooms[currentRooms] or {}
end
self.rooms[lvl] = currentRooms
self.currentRooms = currentRooms
local parsedRoom -- {x,y,z,x,y,z}
if self.currentRoom then
local mi,ma = {}, {}
for i,point in pairs(self.currentRoom) do
mi.x = mi.x and math.min(point.x,mi.x) or point.x
mi.y = mi.y and math.min(point.y,mi.y) or point.y
mi.z = mi.z and math.min(point.z,mi.z) or point.z
ma.x = ma.x and math.max(point.x,ma.x) or point.x
ma.y = ma.y and math.max(point.y,ma.y) or point.y
ma.z = ma.z and math.max(point.z,ma.z) or point.z
end
parsedRoom = {mi,ma}
end
if parsedRoom then
currentRooms[self.currentName] = parsedRoom
_.c('EndRoom',self.currentName)
end
end
function PocoLocation:addPoint(pos)
if self.currentRoom then
table.insert(self.currentRoom,pos)
_.c('AddPoint',tostring(pos))
else
_.c('AddPoint','NoRoom')
end
end
function PocoLocation:_drawBox(pen,a,b)
if not (pen and a and a.x) then
return
end
pen:sphere(Vector3(a.x,a.y,a.z),3)
pen:sphere(Vector3(b.x,b.y,b.z),3)
pen:line(Vector3(a.x,a.y,a.z),Vector3(a.x,b.y,a.z))
pen:line(Vector3(a.x,a.y,a.z),Vector3(b.x,a.y,a.z))
pen:line(Vector3(a.x,b.y,a.z),Vector3(b.x,b.y,a.z))
pen:line(Vector3(b.x,a.y,a.z),Vector3(b.x,b.y,a.z))
pen:line(Vector3(a.x,a.y,b.z),Vector3(a.x,b.y,b.z))
pen:line(Vector3(a.x,a.y,b.z),Vector3(b.x,a.y,b.z))
pen:line(Vector3(a.x,b.y,b.z),Vector3(b.x,b.y,b.z))
pen:line(Vector3(b.x,a.y,b.z),Vector3(b.x,b.y,b.z))
pen:line(Vector3(a.x,a.y,a.z),Vector3(a.x,a.y,b.z))
pen:line(Vector3(a.x,b.y,a.z),Vector3(a.x,b.y,b.z))
pen:line(Vector3(b.x,a.y,a.z),Vector3(b.x,a.y,b.z))
pen:line(Vector3(b.x,b.y,a.z),Vector3(b.x,b.y,b.z))
end
function PocoLocation:get(pos,translate)
local found, foundVol
if pos and pos.x then
local x,y,z = pos.x,pos.y,pos.z
for name,room in pairs(self.currentRooms or {}) do
local mi,ma = room[1],room[2]
if (mi.x <= x and ma.x >= x) and
(mi.y <= y and ma.y >= y) and
(mi.z <= z and ma.z >= z) then
local vol = math.abs((ma.x-mi.x)*(ma.y-mi.y)*(ma.z-mi.z))
if not found or foundVol > vol then
found = name
foundVol = vol
end
end
end
end
if found and translate then
return found -- TODO
else
return found,foundVol
end
end
function PocoLocation:update(t,dt)
Poco.room = self
if not self._loaded then
self._loaded = true
self:load()
end
local ff = Poco.ff or _.g('setup:freeflight()')
if ff then
Poco.ff = ff
ff:update(t, dt)
end
if not Poco.roomOn then return end
local fCam = ff and ff:enabled() and ff._camera_object
local pos = fCam and fCam:position() or _.g('managers.player:player_unit():position()')
-- _.d('Room',self:get(pos) or 'None',#(self.currentRooms or {}))
local ray = fCam and World:raycast("ray", fCam:position(), fCam:position() + fCam:rotation():y() * 10000) or _.r()
if ray and ray.position then
local g = 20
local pos = Vector3(math.floor(ray.position.x/g+0.5)*g,math.floor(ray.position.y/g+0.5)*g,math.floor(ray.position.z/g+0.5)*g)
if pos ~= self.pos then
self.pos = pos
self.b:sphere(pos,10)
else
self.r:sphere(pos,10)
end
if now()-(self._lastIn or 0) > 0.5 then
if shift() then
if ctrl() then
self:endRoom()
self._lastIn = now()
else
self:addPoint(pos)
self._lastIn = now()
end
end
end
end
if self.currentRoom then
local mi,ma = {}, {}
for i,point in pairs(self.currentRoom) do
mi.x = mi.x and math.min(point.x,mi.x) or point.x
mi.y = mi.y and math.min(point.y,mi.y) or point.y
mi.z = mi.z and math.min(point.z,mi.z) or point.z
ma.x = ma.x and math.max(point.x,ma.x) or point.x
ma.y = ma.y and math.max(point.y,ma.y) or point.y
ma.z = ma.z and math.max(point.z,ma.z) or point.z
end
if mi.x then
self:_drawBox(self.g,mi,ma)
end
end
for k,room in pairs(self.currentRooms or {}) do
local mi,ma = room[1],room[2]
if mi.x then
self:_drawBox(self.b,mi,ma)
end
end
end
--- End of Location1
--[[
1. _.g('managers.player:player_unit():movement():nav_tracker():nav_segment()')
2. managers.navigation:get_nav_seg_metadata(_1_)
3.
]]
--- End of Location2
function PocoLocation:load()
local f,err = io.open(LocationJSONFilename, 'r')
local result = false
if f then
local t = f:read('*all')
local o = JSON:decode(t)
if type(o) == 'table' then
self.rooms = o
self:endRoom()
result = true
end
f:close()
end
return result
end
function PocoLocation:save()
local f = io.open(LocationJSONFilename, 'w')
if f then
f:write(JSON:encode_pretty(self.rooms))
f:close()
end
end
--- GUI start ---
local Layers = {
Blur = 1001,
Bg = 1002,
TabHeader = 1003
}
local PocoUIElem = class()
local PocoUIHintLabel -- forward-declared
function PocoUIElem:init(parent,config)
config = _.m({
w = 400,h = 20,
}, config)
self.parent = parent
self.config = config or {}
self.ppnl = config.pnl or parent.pnl
self.pnl = self.ppnl:panel({ name = config.name, x=config.x, y=config.y, w = config.w, h = config.h})
self.status = 0
if self.config[PocoEvent.Click] then
self:_bind(PocoEvent.Out, function(self)
self._pressed = nil
end):_bind(PocoEvent.Pressed, function(self,x,y)
self._pressed = true
end):_bind(PocoEvent.Released, function(self,x,y)
if self._pressed then
self._pressed = nil
return self:fire(PocoEvent.Click,x,y)
end
end)
end
if config.hintText then
PocoUIHintLabel.makeHintPanel(self)
end
end
function PocoUIElem:postInit()
for event,eventVal in pairs(PocoEvent) do
if self.config[eventVal] then
self.parent:addHotZone(eventVal,self)
end
end
self._bind = function()
_('Warning:PocoUIElem._bind was called too late')
end
end
function PocoUIElem:set_y(y)
self.pnl:set_y(y)