forked from JohnnyCheese/TTS_X-Wing2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnassigned Dial.ttslua
1250 lines (1113 loc) · 37.4 KB
/
Unassigned Dial.ttslua
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
menu = require("TTS_xwing/src/Dial/Menu")
button = require("TTS_xwing/src/Dial/Button")
proxy = require("TTS_xwing/src/Dial/Proxy")
-- ~~~~~~
-- Script by dzikakulka
-- Issues, history at: http://github.com/tjakubo2/TTS_xwing
--
-- Token for easy barrel rolls with StarViper Mk.II title
-- ~~~~~~
-- Scripted token properties
__XW_Token = false
__XW_TokenIdle = true
__XW_TokenType = 'helper:Dial'
self.addTag("Flippable")
-- Ref to assigned ship if there is one
assignedShip = nil
playerColor = nil
playerTeam = nil
teamVisibility = ""
openpanel = nil
openbutton = nil
opencolor = "#555555"
closedcolor = "#222222"
setMan = nil
prevMan = nil
manButtonId = nil
clickMode = false
proxyMode = true
finished_setup = true
timeoutDuration = 5
clicktimer = nil
arcCommands = {
Range1 = "r1",
Range2 = "r2",
Range3 = "r3",
FrontArc = "f",
LeftArc = "sl",
RightArc = "sr",
RearArc = "b",
BullseyeArc = "bull",
FullFrontArc = "ff",
FullBackArc = "fb",
FixedArc = "f"
}
arcToCmnd = {
front = "f",
left = "sl",
back = "b",
right = "sr",
frontback = "frontback",
leftright = "leftright",
fullfront = "ff",
fullback = "fb",
bull = "bull",
}
mountToId = {
main = "1",
front = "1",
rear = "2"
}
-- Save self state
function onSave()
if assignedShip ~= nil then
local state = {assignedShipGUID=assignedShip.getGUID(),
owningPlayer=playerColor,
owningPlayerTeam=playerTeam,
clickMode = clickMode,
proxyMode = proxyMode,
timeoutDuration = timeoutDuration
}
return JSON.encode(state)
end
end
firstSet=false
setSinceTemplatePlaced = false -- True if the user has set a movement since the movement template was last placed on the table
templatePlaced = false -- True if the movement template is currently on the table (as far as we can tell based on just dial button clicks, anyway)
exOptions = {}
exOptSelected = false
exOptValue = {}
exOptButtons = { "ExOpt1", "ExOpt2", "ExOpt3", "ExOpt4", "ExOpt5", "ExOpt6", "ExOpt7", "ExOpt8", "ExOpt9", "ExOpt10", "ExOpt11", "ExOpt12", "ExOpt13"}
-- Restore self state
function onLoad(savedData)
--self.UI.setCustomAssets(assetTable)
clearDial()
if savedData ~= nil and savedData ~= "" then
state = JSON.decode(savedData)
clickMode = state.clickMode
proxyMode = state.proxyMode
playerColor = state.owningPlayer
playerTeam = state.playerTeam
local savedShipGuid = state.assignedShipGUID
assignedShip = nil
local dial = self
if savedShipGuid then
Wait.frames(
function()
local savedShip = getObjectFromGUID(savedShipGuid)
if savedShip then
dial.call("assignShip", {ship=savedShip})
end
end, 1)
end
end
timeoutDuration = clickMode and 20 or 2
menu.addToggleItem("clickMode", "click mode", toggleClickMode)
menu.addToggleItem("proxyMode", "proxy mode", toggleProxyMode)
menu.addToggleItem(nil,"Reset dial", resetDial, true)
menu.update()
end
function clearOpenPanel()
if openpanel ~= nil then
self.UI.hide(openpanel)
self.UI.setAttribute(openbutton, "color", closedcolor)
self.UI.setAttribute(openbutton, "textColor", "#FFFFFF")
end
openpanel = nil
openbutton = nil
end
function clearDial()
self.UI.hide('TalonPanel') -- Talon has to come before CenterFU which it is inside -- hide doesn't work when the parent is already hidden (could also use active=false instead)
self.UI.hide("ExecutionOptionsPanel")
self.UI.hide("CenterFD")
self.UI.hide('CenterFU')
self.UI.hide('Setup')
self.UI.hide("ManWin")
self.UI.hide('arcPanel')
self.UI.hide('relocPanel')
self.UI.hide('tokenPanel')
self.UI.hide("setManPeekPanel")
winStat = false
clearOpenPanel()
end
function onFlip()
local face_down = not self.is_face_down
redraw(face_down)
end
function redraw(face_down)
if assignedShip ~= nil then
if not face_down then
clearDial()
self.UI.setAttribute("Main", "rotation", "0 0 0")
if finished_setup then
self.UI.show("CenterFD")
else
self.UI.show('Setup')
end
button.setAttributeFacing("Setup", "Down")
button.setAttributeFacing("proxyPanel", "Down")
else
clearDial()
manSetting()
if finished_setup then
self.UI.show("CenterFU")
else
self.UI.show('Setup')
end
button.setAttributeFacing("Setup", "Up")
button.setAttributeFacing("proxyPanel", "Up")
end
end
end
function getManouverIcons(manouver)
if manouver:sub(1,1) == 'w' then
manColor="White"
elseif manouver:sub(1,1) == 'b' then
manColor="Blue"
elseif manouver:sub(1,1) == 'r' then
manColor="Red"
elseif manouver:sub(1,1) == 'p' then
manColor="Purple"
end
if manouver:sub(-1,-1) == 't' then
manType = "Talon"
elseif manouver:sub(-1,-1) == 's' then
if manouver:sub(2,2) == 't' then
manType = "TurnSloop"
else
manType = "Sloop"
end
elseif manouver:sub(-1,-1) == 'z' then
if manouver:sub(2,2) == 't' then
manType = "TurnSlip"
else
manType = "BankSlip"
end
elseif manouver:sub(-1,-1) == 'r' then
if manouver:sub(2,2) == 'b' then
manType = "ReverseBank"
else
manType = "ReverseStraight"
end
elseif manouver:sub(2,2) == 't' then
manType = "Turn"
elseif manouver:sub(2,2) == 'b' then
manType = "Bank"
elseif manouver:sub(2,2) == 's' then
manType = "Straight"
elseif manouver:sub(2,2) == 'k' then
manType = 'K'
end
local Char= manouver:find("%d")
manSpeed = manouver:sub(Char,Char)
if manouver:sub(3,3) == 'l' then
manBear = "L"
elseif manouver:sub(3,3) == 'r' then
manBear = "R"
else
manBear = ""
end
if manSpeed=="0" and manType=="Straight" then
manType='Stall'
end
return {speed = "Speed"..manSpeed, type = manColor .. manType .. manBear }
end
function manSelect(p, option, id)
if spectReturn(p) == true or option == false then
return
end
firstSet=true
self.UI.setAttribute("ManBtnGroup","allowSwitchOff","false")
manButtonId = id
curMan=string.lower(id)
icons = getManouverIcons(curMan)
speedIcon= icons.speed
typeIcon= icons.type
setMan = curMan:sub(2)
befAft = '_B'
end
function manSetting()
if setStat == true then
self.UI.setAttribute("TypeIcon", "image", typeIcon)
self.UI.setAttribute("SpeedIcon", "image", speedIcon)
self.UI.setAttribute("TypeIcon", "active", "true")
self.UI.setAttribute("SpeedIcon", "active", "true")
self.UI.setAttribute("MoveBtn", "active", "true")
self.UI.setAttribute("MoveBtn", "textColor", "#FFFFFF")
self.UI.setAttribute("UndoBtn", "active", "false")
self.UI.setAttribute("Templ", "active", "true")
self.UI.setAttribute("Templ", "textColor", "#222222") -- Make the text same color as the background since goal is to only have the type / speed icons showing anyway
else
self.UI.setAttribute("TypeIcon", "active", "false")
self.UI.setAttribute("SpeedIcon", "active", "false")
self.UI.setAttribute("MoveBtn", "active", "false")
self.UI.setAttribute("UndoBtn", "active", "false")
self.UI.setAttribute("Templ", "textColor", "#FFFFFF")
-- Hide the template button when there isn't a manuver set, since it's confusing and undefined in some cases what template should be shown then
if not templatePlaced then
self.UI.setAttribute("Templ", "active", "false")
end
end
if firstSet== false then
self.UI.setAttribute("TypeIcon", "active", "false")
self.UI.setAttribute("SpeedIcon", "active", "false")
self.UI.setAttribute("MoveBtn", "active", "false")
self.UI.setAttribute("UndoBtn", "active", "false")
self.UI.setAttribute("Templ", "textColor", "#FFFFFF")
-- Hide the template button when there isn't a manuver set, since it's confusing and undefined in some cases what template should be shown then
if not templatePlaced then
self.UI.setAttribute("Templ", "active", "false")
end
end
-- Remove template if a new manuver has been set since it was shown, since it could be confusing to still show the old template (and to show the new one you would have to click the button twice, which would be confusing)
if setSinceTemplatePlaced and templatePlaced then
deleteTemplate()
end
end
function Undo(p)
if spectReturn(p) == true then
return
end
assignedShip.setDescription("q")
befAft='_B'
self.UI.setAttribute("UndoBtn", "active", "false")
if setStat then
return
elseif prevMan:sub(-1,-1) ~='t' or proxyMode then
setMan = prevMan
setStat = prevMan ~= ""
if setStat then
self.UI.setAttribute("MoveBtn", "active", "true")
self.UI.setAttribute("MoveBtn", "textColor", "#FFFFFF")
self.UI.setAttribute("TypeIcon", "active", "true")
self.UI.setAttribute("SpeedIcon", "active", "true")
self.UI.setAttribute("Templ", "active", "true")
end
else
setMan = prevMan
setStat = true
self.UI.show("TalonPanel")
end
end
function allignShip(P)
if spectReturn(P) == true then
return
end
rot = assignedShip.getRotation()
modint,modfrac = math.modf(rot.y/45)
if modfrac < 0.5 then
rot.y = modint*45
else
rot.y = (modint+1)*45
end
assignedShip.setRotation(rot)
end
function placeShip(P)
if spectReturn(P) == true then
return
end
finished_setup = true
assignedShip.setVar("finished_setup", true)
assignedShip.setLock(true)
redraw(self.is_face_down)
end
setupRotations = {
Rot1DegLBut = -1,
Rot5DegLBut = -5,
Rot225DegLBut = -22.5,
Rot1DegRBut = 1,
Rot5DegRBut = 5,
Rot225DegRBut = 22.5,
}
function setupRot(P, option, id)
if (option ~= '-1') or (spectReturn(P) == true) then
return
end
local rot = assignedShip.getRotation()
rot.y = rot.y + (setupRotations[id] or 0)
assignedShip.setLock(true)
assignedShip.setRotation(rot)
end
setupShifts = {
AdjustFBut = vector(0,0,-0.05),
AdjustBBut = vector(0,0,0.05),
AdjustLBut = vector(0.05,0,0),
AdjustRBut = vector(-0.05,0,0),
}
function setupShift(P, option, id)
if (option ~= '-1') or (spectReturn(P) == true) then
return
end
pos = assignedShip.positionToWorld(setupShifts[id] or vector(0,0,0))
assignedShip.setLock(true)
assignedShip.setPosition(pos)
end
function performMove(P)
if spectReturn(P) == true then
return
end
if setMan ~= nil and setMan ~="" then
self.UI.setAttribute("MoveBtn", "active", "false")
-- Check alternate execution options
--print("curMan:" .. curMan)
if exOptions[curMan] ~= nil and exOptSelected == false then
setupAlternateExecutionPanel(P, exOptions[curMan])
elseif setMan:sub(-1,-1) == 't' then
if proxyMode then
proxy_settings = {
ship_guid = assignedShip.getGUID(),
move_code = setMan,
offsets = {front = 'ft', center = 't', back = 'bt'},
button_func = button.setProxyState,
}
proxy.spawn(proxy_settings)
clearOpenPanel()
exOptSelected = false
setDial(P)
else
self.UI.show("TalonPanel")
return
end
else
self.UI.setAttribute("UndoBtn", "active", "true")
self.UI.setAttribute("UndoBtn", "textColor", "#FFFFFF")
assignedShip.setDescription(setMan)
exOptSelected = false
befAft = '_A'
setDial(P)
end
prevMan = setMan
setMan = nil
Global.call("API_SetDial", {dial=self,set=false})
self.UI.setAttribute(manButtonId, "isOn", "false")
end
end
function setupAlternateExecutionPanel(P, executionOptions)
self.UI.setAttribute("TypeIcon", "active", "false")
self.UI.setAttribute("SpeedIcon", "active", "false")
self.UI.setAttribute("Templ", "active", "false")
self.UI.setAttribute("undoFU", "active", "false")
self.UI.show("ExecutionOptionsPanel")
for i, button in pairs(exOptButtons) do
self.UI.setAttribute(button .. 'But', "active", "false")
end
for i, option in pairs(executionOptions) do
self.UI.setAttribute(exOptButtons[i] .. "But", "active", "true")
exOptValue[exOptButtons[i] .. 'But'] = option
local icons = getManouverIcons(option)
self.UI.setAttribute(exOptButtons[i] .. "TypeIcon", "image", icons.type)
self.UI.setAttribute(exOptButtons[i] .. "SpeedIcon", "image", icons.speed)
end
end
function selectExecuteOption(P, option, id)
if spectReturn(P) == true then
return
end
self.UI.hide("ExecutionOptionsPanel")
exOptSelected = true
setMan = exOptValue[id]:sub(2)
local icons = getManouverIcons(exOptValue[id])
self.UI.setAttribute("TypeIcon", "active", "true")
self.UI.setAttribute("SpeedIcon", "active", "true")
self.UI.setAttribute("Templ", "active", "true")
self.UI.setAttribute("Templ", "textColor", "#222222")
self.UI.setAttribute("undoFU", "active", "true")
self.UI.setAttribute("undoFU", "textColor", "#FFFFFF")
self.UI.setAttribute("TypeIcon", "image", icons.type)
self.UI.setAttribute("SpeedIcon", "image", icons.speed)
performMove(P)
end
function performTalon(P,option,id)
if spectReturn(P) == true then
return
end
self.UI.hide("TalonPanel")
self.UI.setAttribute("UndoBtn", "active", "true")
self.UI.setAttribute("UndoBtn", "textColor", "#FFFFFF")
if id=="TalonMidBtn" then
assignedShip.setDescription(setMan)
elseif id=="TalonReaBtn" then
talonMove = setMan:sub(1,3).."b"..setMan:sub(-1,-1)
assignedShip.setDescription(talonMove)
elseif id=="TalonForBtn" then
talonMove = setMan:sub(1,3).."f"..setMan:sub(-1,-1)
assignedShip.setDescription(talonMove)
end
exOptSelected = false
befAft ='_A'
setDial(P)
prevMan = setMan
setMan = nil
Global.call("API_SetDial", {dial=self,set=false})
self.UI.setAttribute(manButtonId, "isOn", "false")
end
function onPickUp(player_color)
if assignedShip == nil then
pColor = self.held_by_color
end
end
-- Assign a ship to the dial
function assignShip(args)
self.UI.setAttribute("CenterFD", "active", "true")
self.UI.setAttribute("CenterFU", "active", "true")
self.UI.setAttribute("arcPanel", "active", "true")
self.UI.setAttribute("tokenPanel", "active", "true")
self.UI.setAttribute("proxyPanel", "active", "true")
self.UI.hide("proxyPanel")
self.UI.setAttribute("relocPanel", "active", "true")
self.UI.setAttribute("setManPeekPanel", "active", "true")
assignedShip = args.ship
Name=assignedShip.getName()
self.setName(Name)
finished_setup = assignedShip.getVar("finished_setup") or false
--self.UI.setAttribute("DialName", Name)
self.UI.setValue("Name",Name)
self.UI.setValue("SetupName",Name)
shipData=assignedShip.getTable("Data")
if shipData.arcs and shipData.arcs.fixed then
self.UI.setAttribute("FixedArc", "active", "true")
arcCommands['FixedArc'] = "a"
else
self.UI.setAttribute("FixedArc", "active", "false")
end
if shipData.arcs and shipData.arcs.turret then
local buttonname = "TurretArc"
for mount, turret in pairs(shipData.arcs.turret) do
local id = mountToId[mount]
local command_id = id
if mount == "main" then
command_id = ""
end
self.UI.setAttribute("TurretArc" .. id , "active", "true")
self.UI.setAttribute("TurretArc" .. id .. "Panel", "active", "true")
if turret.type[1] == "doubleturret" then
self.UI.setAttribute("TurretArc" .. id .. "Icon", "image", "DoubleTurretArc")
arcCommands["RotateLeft" .. id] = "rot" .. command_id
self.UI.setAttribute("RotateLeft" .. id , "active", "true")
else
arcCommands["RotateLeft" .. id] = "rotl" .. command_id
self.UI.setAttribute("RotateLeft" .. id , "active", "true")
arcCommands["RotateRight" .. id] = "rotr" .. command_id
self.UI.setAttribute("RotateRight" .. id , "active", "true")
end
arcCommands["TurretArc" .. id] = "turret" .. command_id
end
end
exOptions = shipData.executeOptions or {}
self.UI.setAttribute("BackGround", "image", tostring(shipData['Faction']).."BG")
for k,v in pairs(shipData['moveSet']) do
self.UI.setAttribute(string.upper(v), "active", "true")
end
setMan=""
prevMan=""
local repos = false
for k,v in pairs(shipData['actSet']) do
if v == 'F' then
self.UI.setAttribute('FocusBtn', 'active', 'true')
elseif v == 'TL' then
self.UI.setAttribute("TargetLockBtn", 'active', 'true')
elseif v == 'E' then
self.UI.setAttribute("EvadeBtn", 'active', 'true')
elseif v == 'R' then
self.UI.setAttribute("ReinforceBtn", 'active', 'true')
elseif v == 'C' then
self.UI.setAttribute("CalculateBtn", 'active', 'true')
elseif v == 'CL' then
self.UI.setAttribute("CloakBtn", 'active', 'true')
elseif v == 'BR' then
repos = true
button.setBarrelRollState(proxyMode, true)
elseif v == 'B' then
repos = true
self.UI.setAttribute("BoostFD", "active", "true")
self.UI.setAttribute("BoostSBtn", "active", "true")
self.UI.setAttribute("BoostRBtn", "active", "true")
self.UI.setAttribute("BoostLBtn", "active", "true")
elseif v =='Ail' then
repos = true
self.UI.setAttribute("AileronFD", "active", "true")
self.UI.setAttribute("AilSBtn", "active", "true")
self.UI.setAttribute("AilRBtn", "active", "true")
self.UI.setAttribute("AilLBtn", "active", "true")
elseif v =='Piv' then
repos = true
self.UI.setAttribute("PivotFD", "active", "true")
self.UI.setAttribute("PivKBtn", "active", "true")
self.UI.setAttribute("PivRBtn", "active", "true")
self.UI.setAttribute("PivLBtn", "active", "true")
elseif v == 'Dare' then
repos = true
self.UI.setAttribute("BoostFD", "active", "true")
self.UI.setAttribute("BoostFD", "preferredWidth", "330")
self.UI.setAttribute("Boost2FD", "preferredWidth", "330")
self.UI.setAttribute("BoostLTBtn", "active", "true")
self.UI.setAttribute("BoostRTBtn", "active", "true")
self.UI.setAttribute("BoostLT2Btn", "active", "true")
self.UI.setAttribute("BoostRT2Btn", "active", "true")
elseif v == '2B' then
repos = true
self.UI.setAttribute("Boost2FD", "active", "true")
self.UI.setAttribute("BoostS2Btn", "active", "true")
self.UI.setAttribute("BoostL2Btn", "active", "true")
self.UI.setAttribute("BoostR2Btn", "active", "true")
elseif v == '2BR' then
repos = true
button.setBarrelRoll2State(proxyMode, true)
elseif v == 'VR' then
repos = true
button.setViperBarrelRollState(proxyMode, true)
end
end
if repos == false then
self.UI.setAttribute("RelocMenu", "active", "false")
self.UI.setAttribute("RelocMenuFU", "active", "false")
end
Global.call("API_AssignDial", {dial=self, ship=assignedShip, player=pColor})
redraw(self.is_face_down)
end
-- Assign on drop near a small base ship
function onDropped()
if assignedShip == nil then
local spos = self.getPosition()
local nearest = nil
local minDist = 2.89 -- 80mm
for k,ship in pairs(getAllObjects()) do
if ship.tag == 'Figurine' and ship.name ~= '' then
local pos = ship.getPosition()
local dist = math.sqrt(math.pow((spos[1]-pos[1]),2) + math.pow((spos[3]-pos[3]),2))
if dist < minDist then
nearest = ship
minDist = dist
end
end
end
if nearest ~= nil then
if pColor=="White" then
printToAll("Please, pick a color before assigning dials")
else
assignedShip = nearest
playerColor=pColor
playerTeam = nil
teamVisibility = ""
for k, player in pairs(Player.getPlayers()) do
if player.color == playerColor then
if player.team != "None" then
playerTeam = player.team
teamVisibility = "|" .. playerTeam
end
end
end
nearest.setVar('owningPlayer', pColor)
printToAll('Dial assigned to to ' .. nearest.getName(), {0.3, 0.3, 1})
--printToAll('Controlled by the '.. playerColor .. ' player')
--if playerTeam then
--printToAll('Of the '.. tostring(playerTeam) .. ' team')
--end
--sprintToAll('')
self.setRotation(nearest.getRotation())
assignShip({ship=nearest})
end
end
end
end
-- functions called when buttons are pressed
function genericAction(a,b,c,d)
print(a)
print(b)
print(c)
print(d)
end
function focusTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Focus', playerColor, {remove = id ~= '-1'} })
end
function evadeTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Evade', playerColor, {remove = id ~= '-1'} })
end
function tlTok(p, id)
if spectReturn(p) == true then
return
end
if id == '-1' then
Global.call('proxyPerformAction', {assignedShip, 'Target Lock', playerColor})
end
end
function tractorTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Tractor', playerColor, {remove = id ~= '-1'} })
end
function jamTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Jam', playerColor, {remove = id ~= '-1'} })
end
function disarmTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Disarm', playerColor, {remove = id ~= '-1'} })
end
function cloakTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Cloak', playerColor, {remove = id ~= '-1'} })
end
function calcTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Calculate', playerColor, {remove = id ~= '-1'} })
end
function reinforceTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Reinforce', playerColor, {remove = id ~= '-1'} })
end
function stressTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Stress', playerColor, {remove = id ~= '-1'} })
end
function strainTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Strain', playerColor, {remove = id ~= '-1'} })
end
function depleteTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Deplete', playerColor, {remove = id ~= '-1'} })
end
function ionTok(p,id)
if spectReturn(p) == true then
return
end
Global.call('proxyPerformAction', {assignedShip, 'Ion', playerColor, {remove = id ~= '-1'} })
end
reposCommands = {
BoostSBtn = "s1b",
BoostLBtn = "bl1b",
BoostRBtn = "br1b",
BoostLTBtn = "tl1b",
BoostRTBtn = "tr1b",
BoostS2Btn = "s2b",
BoostL2Btn = "bl2b",
BoostR2Btn = "br2b",
BoostLT2Btn = "tl2b",
BoostRT2Btn = "tr2b",
AilLBtn = "bl1",
AilSBtn = "s1",
AilRBtn = "br1",
BarrelLFBtn = "rl1",
BarrelLBtn = "rl2",
BarrelLBBtn = "rl3",
BarrelRFBtn = "rr1",
BarrelRBtn = "rr2",
BarrelRBBtn = "rr3",
BarrelLF2Btn = "cl1",
BarrelL2Btn = "cl2",
BarrelLB2Btn = "cl3",
BarrelRF2Btn = "cr1",
BarrelR2Btn = "cr2",
BarrelRB2Btn = "cr3",
BarrelVLUBtn = "vlf2",
BarrelVLDBtn = "vlb2",
BarrelVRUBtn = "vrf2",
BarrelVRDBtn = "vrb2",
}
function Repos(P, option, id)
if (option ~= '-1') or (spectReturn(P) == true) then
return
end
local move_code = reposCommands[id] or ""
if proxyMode and proxy.isProxyable(move_code) then
proxy_settings = {
ship_guid = assignedShip.getGUID(),
move_code = move_code,
offsets = {front = '1', center = '2', back = '3'},
cancellable = not setStat,
button_func = button.setProxyState,
}
proxy.spawn(proxy_settings)
clearOpenPanel()
else
assignedShip.setDescription(move_code)
end
end
function CancelProxy(player, option, id)
proxy.cancel(assignedShip.getGUID())
end
function Arc(P, option, id)
if spectReturn(P)then
return
end
includeFriendlies = ""
if (option ~= '-1') then
includeFriendlies = "a"
end
assignedShip.setDescription((arcCommands[id] or "") .. includeFriendlies )
end
function pivK(p)
if spectReturn(p) == true then
return
end
assignedShip.setDescription('k0')
end
function pivR(p)
if spectReturn(p) == true then
return
end
assignedShip.setDescription('tr4')
end
function pivL(p)
if spectReturn(p) == true then
return
end
assignedShip.setDescription('tl4')
end
function Window(p)
if winStat == nil then
winStat = false
end
if spectReturn(p) == false then
if winStat == false then
winStat = true
self.UI.show("ManWin")
self.UI.setAttribute("ManWin", "visibility", playerColor .. teamVisibility .. "|Black")
self.UI.setAttribute("ManBtnGroup", "active", "true")
clearOpenPanel()
else
winStat = false
self.UI.setAttribute("ManBtnGroup", "active", "false")
self.UI.hide('ManWin')
end
end
end
function spectReturn(p)
if p.color == 'Black' then
return false
elseif p.color == playerColor then
return false
elseif p.team == playerTeam then
return false
else
return true
end
end
function showSetMan(p)
if spectReturn(p) == true then
return
end
self.UI.show("setManPeekPanel")
self.UI.setAttribute("setManPeekPanel", "visibility", playerColor .. teamVisibility)
self.UI.setAttribute("setManTypeIcon", "image", typeIcon)
self.UI.setAttribute("setManSpeedIcon", "image", speedIcon)
self.UI.setAttribute("setManTypeIcon", "active", "true")
self.UI.setAttribute("setManSpeedIcon", "active", "true")
self.UI.setAttribute("setManPeekPanel", "position", "-100 -150 -50")
self.UI.setAttribute("setManPeekPanel", "rotation", "180 180 0")
end
function hideSetMan(p)
if spectReturn(p) == true then
return
end
self.UI.hide("setManPeekPanel")
end
click_functions = {
ArcMenu = {show= function() showArcMFD() end,
hide= function() hideArcM() end },
ArcMenuFU = {show= function() showArcMFU() end,
hide= function() hideArcM() end },
RelocMenu = {show= function() showRelocMFD() end,
hide= function() hideRelocM() end },
RelocMenuFU = {show= function() showRelocMFU() end,
hide= function() hideRelocM() end },
TokenMenu = {show= function() showTokMFD() end,
hide= function() hideTokM() end },
TokenMenuFU = {show= function() showTokMFU() end,
hide= function() hideTokM() end },
}
hover_functions = {
ArcMenu = function()
stopClicktimer()
showArcMFD()
end,
ArcMenuFU = function()
showArcMFU()
stopClicktimer()
end,
arcPanel = function()
restartClicktimer()
end,
RelocMenu = function()
showRelocMFD()
stopClicktimer()
end,
RelocMenuFU = function()
showRelocMFU()
stopClicktimer()
end,
relocPanel = function()
restartClicktimer()
end,
TokenMenu = function()
showTokMFD()
stopClicktimer()
end,
TokenMenuFU = function()
showTokMFU()
stopClicktimer()
end,
tokenPanel = function()
restartClicktimer()
end,
}
function toggleClickMode(enable)
clickMode = enable
self.UI.setAttribute("arcPanel", "raycastTarget", not clickMode)
self.UI.setAttribute("tokenPanel", "raycastTarget", not clickMode)
self.UI.setAttribute("relocPanel", "raycastTarget", not clickMode)
if clickMode then
timeoutDuration = 20
else
timeoutDuration = 2
end
menu.update()
end
function toggleProxyMode(enable)
proxyMode = enable
button.setBarrelRollState(proxyMode)
button.setBarrelRoll2State(proxyMode)
button.setViperBarrelRollState(proxyMode)
menu.update()
end