-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfrmEdit.vb
More file actions
1601 lines (1495 loc) · 70.7 KB
/
frmEdit.vb
File metadata and controls
1601 lines (1495 loc) · 70.7 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
Imports System.Text.RegularExpressions
Imports System.Xml
Imports HidSharp
Public Class frmEdit
Private valLS As Point
Private valRS As Point
Private valLT As Integer
Private valRT As Integer
Private loopTarget As clsAction
Private groupTarget As clsActionGroup
Private asLastTime As Integer = 0
Private activeFile As clsScriptFile
Private activeScript As clsScript
Private activeGroup As clsActionGroup = Nothing
Private Sub frmEdit_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
saveSettings()
End Sub
Private Sub saveSettings()
SaveSetting(Application.ProductName, "Settings", "Controller1", txtController1.Text)
SaveSetting(Application.ProductName, "Settings", "Controller2", txtController2.Text)
SaveSetting(Application.ProductName, "Settings", "Controller3", txtController3.Text)
SaveSetting(Application.ProductName, "Settings", "Controller4", txtController4.Text)
SaveSetting(Application.ProductName, "Settings", "Precompile", IIf(cbPrecompile.Checked, "True", "False"))
SaveSetting(Application.ProductName, "Settings", "Trace", IIf(cbTrace.Checked, "True", "False"))
SaveSetting(Application.ProductName, "Settings", "SyncWait", IIf(cbSyncWait.Checked, "True", "False"))
SaveSetting(Application.ProductName, "Settings", "Sync", IIf(cbSync.Checked, "True", "False"))
SaveSetting(Application.ProductName, "Settings", "SyncIP", txtSync.Text)
SaveSetting(Application.ProductName, "Settings", "SpeedNudge", nudSpeed.Value.ToString())
End Sub
Private Sub frmEdit_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim tTip As New ToolTip
tTip.AutomaticDelay = 1000
tTip.SetToolTip(btnAdd, "Add Action")
tTip.SetToolTip(btnApply, "Apply Changes")
tTip.SetToolTip(btnMoveDown, "Move Down")
tTip.SetToolTip(btnMoveUp, "Move Up")
tTip.SetToolTip(btnDelete, "Delete Action")
tTip.SetToolTip(btnPlayPause, "Play Script")
tTip.SetToolTip(btnStop, "Stop Script")
AddHandler btnA.Click, AddressOf cb_Click
AddHandler btnB.Click, AddressOf cb_Click
AddHandler btnX.Click, AddressOf cb_Click
AddHandler btnY.Click, AddressOf cb_Click
AddHandler btnLS.Click, AddressOf cb_Click
AddHandler btnLB.Click, AddressOf cb_Click
AddHandler btnLT.Click, AddressOf cb_Click
AddHandler btnRS.Click, AddressOf cb_Click
AddHandler btnRB.Click, AddressOf cb_Click
AddHandler btnRT.Click, AddressOf cb_Click
AddHandler btnDD.Click, AddressOf cb_Click
AddHandler btnDL.Click, AddressOf cb_Click
AddHandler btnDR.Click, AddressOf cb_Click
AddHandler btnDU.Click, AddressOf cb_Click
AddHandler btnBack.Click, AddressOf cb_Click
AddHandler btnStart.Click, AddressOf cb_Click
AddHandler btnGuide.Click, AddressOf cb_Click
AddHandler pbRS.MouseDown, AddressOf pb_MouseDown
AddHandler pbLS.MouseDown, AddressOf pb_MouseDown
AddHandler pbRS.DoubleClick, AddressOf pb_DoubleClick
AddHandler pbLS.DoubleClick, AddressOf pb_DoubleClick
AddHandler txtLSX.Validated, AddressOf txtTS_Validating
AddHandler txtLSY.Validated, AddressOf txtTS_Validating
AddHandler txtRSX.Validated, AddressOf txtTS_Validating
AddHandler txtRSY.Validated, AddressOf txtTS_Validating
AddHandler txtLT.Validated, AddressOf txtTrigger_Validating
AddHandler txtRT.Validated, AddressOf txtTrigger_Validating
AddHandler btnLT.Click, AddressOf cTrigger_Click
AddHandler btnRT.Click, AddressOf cTrigger_Click
clearScript()
blankScript()
txtController1.Text = GetSetting(Application.ProductName, "Settings", "Controller1", "CM1")
txtController2.Text = GetSetting(Application.ProductName, "Settings", "Controller2", "CM2")
txtController3.Text = GetSetting(Application.ProductName, "Settings", "Controller3", "CM3")
txtController4.Text = GetSetting(Application.ProductName, "Settings", "Controller4", "CM4")
cbPrecompile.Checked = (GetSetting(Application.ProductName, "Settings", "Precompile", "True") = "True")
cbTrace.Checked = (GetSetting(Application.ProductName, "Settings", "Trace", "True") = "True")
cbSync.Checked = (GetSetting(Application.ProductName, "Settings", "Sync", "False") = "True")
cbSyncWait.Checked = (GetSetting(Application.ProductName, "Settings", "SyncWait", "False") = "True")
txtSync.Text = GetSetting(Application.ProductName, "Settings", "SyncIP", "97.82.214.2")
nudSpeed.Value = CInt(GetSetting(Application.ProductName, "Settings", "SpeedNudge", "100"))
End Sub
Private Sub clearScript()
rbPress.Checked = True
valLS = New Point(-32768, -32768)
valRS = New Point(-32768, -32768)
valLT = -1
valRT = -1
drawPB(pbLS)
drawPB(pbRS)
refreshLT()
refreshRT()
cmbAdd.SelectedIndex = 0
loopTarget = Nothing
txtFlowTarget.Text = vbNullString
txtGame.Text = vbNullString
txtTitle.Text = vbNullString
txtDesc.Text = vbNullString
cbControllerIP.SelectedIndex = 0
If Not activeFile Is Nothing Then activeFile.groups.Clear()
activeFile = New clsScriptFile
lbGroups.Items.Clear()
lbActions.Items.Clear()
End Sub
Private Sub blankScript()
activeFile = New clsScriptFile
Dim g As New clsActionGroup(mainGroup)
activeFile.groups.Add(g.name, g)
lbGroups.Items.Add(g)
activeGroup = g
lbGroups.SelectedItem = g
refreshGroup()
End Sub
Private Sub cb_Click(sender As System.Object, e As System.EventArgs)
Dim btn As Button = CType(sender, Button)
btn.FlatAppearance.BorderSize = 1 - btn.FlatAppearance.BorderSize
End Sub
Private Sub cTrigger_Click(sender As System.Object, e As System.EventArgs)
Dim btn As Button = CType(sender, Button)
If btn Is btnLT Then
valLT = IIf(btn.FlatAppearance.BorderSize, 255, -1)
refreshLT()
End If
If btn Is btnRT Then
valRT = IIf(btn.FlatAppearance.BorderSize, 255, -1)
refreshRT()
End If
End Sub
Private Sub refreshLT()
txtLT.Text = IIf(valLT >= 0, valLT, vbNullString)
btnLT.FlatAppearance.BorderSize = IIf(valLT >= 0, 1, 0)
End Sub
Private Sub refreshRT()
txtRT.Text = IIf(valRT >= 0, valRT, vbNullString)
btnRT.FlatAppearance.BorderSize = IIf(valRT >= 0, 1, 0)
End Sub
Private Sub drawPB(pb As PictureBox)
Dim x As Integer = 0
Dim y As Integer = 0
If pb Is pbLS Then
x = valLS.X
y = valLS.Y
txtLSX.Text = IIf(x > -32768, Math.Round(x / 256, 2), vbNullString)
txtLSY.Text = IIf(y > -32768, Math.Round(y / 256, 2), vbNullString)
End If
If pb Is pbRS Then
x = valRS.X
y = valRS.Y
txtRSX.Text = IIf(x > -32768, Math.Round(x / 256, 2), vbNullString)
txtRSY.Text = IIf(y > -32768, Math.Round(y / 256, 2), vbNullString)
End If
Dim px As Integer = (CDec(x) / 256 + 147) * 52 / 254
Dim py As Integer = (CDec(y) / 256 + 147) * 52 / 254
With pb
.Image = New Bitmap(.Width, .Height)
Dim g As Graphics = Graphics.FromImage(.Image)
g.Clear(.BackColor)
g.DrawImage(.BackgroundImage, New Point((.Width - .BackgroundImage.Width) / 2 - 1, (.Height - .BackgroundImage.Height) / 2 - 1))
g.DrawRectangle(Pens.White, New Rectangle(4, 4, .Width - 11, .Height - 11))
If x > -32768 And y > -32768 Then g.FillRectangle(Brushes.Red, New Rectangle(px - 1, py - 1, 3, 3))
g.Dispose()
.Invalidate()
End With
End Sub
Private Sub pb_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs)
Dim px As Integer
Dim py As Integer
If e.Button = Windows.Forms.MouseButtons.Right Then
px = 30
py = 30
Else
px = e.X
py = e.Y
End If
If px > 56 Then px = 56
If px < 4 Then px = 4
If py > 56 Then py = 56
If py < 4 Then py = 4
Dim pb As PictureBox = CType(sender, PictureBox)
If pb Is pbLS Then
valLS.X = Math.Round(CDec(px) * 254 / 52 - 147) * 256
valLS.Y = Math.Round(CDec(py) * 254 / 52 - 147) * 256
End If
If pb Is pbRS Then
valRS.X = Math.Round(CDec(px) * 254 / 52 - 147) * 256
valRS.Y = Math.Round(CDec(py) * 254 / 52 - 147) * 256
End If
drawPB(pb)
End Sub
Private Sub pb_DoubleClick(sender As Object, e As System.EventArgs)
If sender Is pbLS Then
valLS.X = -32768
valLS.Y = -32768
End If
If sender Is pbRS Then
valRS.X = -32768
valRS.Y = -32768
End If
drawPB(sender)
End Sub
Private Sub txtTS_Validating(sender As Object, e As System.EventArgs)
Dim txt As TextBox = CType(sender, TextBox)
If Trim(txt.Text) = vbNullString Then
txt.Text = vbNullString
If txt Is txtLSX Or txt Is txtLSY Then
valLS.X = -32768
valLS.Y = -32768
drawPB(pbLS)
End If
If txt Is txtRSX Or txt Is txtRSY Then
valRS.X = -32768
valRS.Y = -32768
drawPB(pbRS)
End If
Exit Sub
End If
If Not IsNumeric(txt.Text) Then
If txt Is txtLSX Then txt.Text = valLS.X / 256
If txt Is txtLSY Then txt.Text = valLS.Y / 256
If txt Is txtRSX Then txt.Text = valRS.X / 256
If txt Is txtRSY Then txt.Text = valRS.Y / 256
End If
Dim val As Integer = CDec(txt.Text) * 256
If val < -32767 Then val = -32767
If val > 32767 Then val = 32767
If txt Is txtLSX Then
valLS.X = val
drawPB(pbLS)
End If
If txt Is txtLSY Then
valLS.Y = val
drawPB(pbLS)
End If
If txt Is txtRSX Then
valRS.X = val
drawPB(pbRS)
End If
If txt Is txtRSY Then
valRS.Y = val
drawPB(pbRS)
End If
End Sub
Private Sub txtTrigger_Validating(sender As Object, e As System.EventArgs)
Dim txt As TextBox = CType(sender, TextBox)
If Trim(txt.Text) = vbNullString Then
txt.Text = vbNullString
If txt Is txtLT Then
valLT = -1
refreshLT()
End If
If txt Is txtRT Then
valRT = -1
refreshRT()
End If
Exit Sub
End If
If Not IsNumeric(txt.Text) Then
If txt Is txtLT Then txt.Text = IIf(valLT > 0, valLT, vbNullString)
If txt Is txtRT Then txt.Text = IIf(valRT > 0, valRT, vbNullString)
Exit Sub
End If
Dim val As Integer = Math.Round(CDec(txt.Text))
If val < 0 Then val = 0
If val > 255 Then val = 255
If txt Is txtLT Then
valLT = val
refreshLT()
End If
If txt Is txtRT Then
valRT = val
refreshRT()
End If
End Sub
Private Sub rbPress_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbPress.CheckedChanged
With rbPress
If .Checked Then
lblControllerHold.Visible = .Checked
txtControllerHold.Visible = .Checked
lblControllerWait.Visible = .Checked
txtControllerWait.Visible = .Checked
lblControllerRepeat.Visible = .Checked
txtControllerRepeat.Visible = .Checked
End If
End With
End Sub
Private Sub rbRelease_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbRelease.CheckedChanged
With rbRelease
If .Checked Then
lblControllerHold.Visible = Not .Checked
txtControllerHold.Visible = Not .Checked
lblControllerWait.Visible = Not .Checked
txtControllerWait.Visible = Not .Checked
lblControllerRepeat.Visible = Not .Checked
txtControllerRepeat.Visible = Not .Checked
End If
End With
End Sub
Private Sub rbHold_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbHold.CheckedChanged
With rbHold
If .Checked Then
lblControllerHold.Visible = Not .Checked
txtControllerHold.Visible = Not .Checked
lblControllerWait.Visible = Not .Checked
txtControllerWait.Visible = Not .Checked
lblControllerRepeat.Visible = Not .Checked
txtControllerRepeat.Visible = Not .Checked
End If
End With
End Sub
Private Sub rbWait_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbWait.CheckedChanged
With rbWait
If .Checked Then
lblFlowWait.Visible = .Checked
txtFlowWait.Visible = .Checked
lblFlowMaxWait.Visible = Not .Checked
txtFlowMaxWait.Visible = Not .Checked
lblFlowRepeat.Visible = Not .Checked
txtFlowRepeat.Visible = Not .Checked
lblFlowTarget.Visible = Not .Checked
txtFlowTarget.Visible = Not .Checked
btnFlowTarget.Visible = Not .Checked
End If
End With
End Sub
Private Sub rbWaitRandom_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbWaitRandom.CheckedChanged
With rbWaitRandom
If .Checked Then
lblFlowWait.Visible = .Checked
txtFlowWait.Visible = .Checked
lblFlowMaxWait.Visible = .Checked
txtFlowMaxWait.Visible = .Checked
lblFlowRepeat.Visible = Not .Checked
txtFlowRepeat.Visible = Not .Checked
lblFlowTarget.Visible = Not .Checked
txtFlowTarget.Visible = Not .Checked
btnFlowTarget.Visible = Not .Checked
End If
End With
End Sub
Private Sub rbLoop_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbLoop.CheckedChanged
With rbLoop
If .Checked Then
lblFlowWait.Visible = Not .Checked
txtFlowWait.Visible = Not .Checked
lblFlowMaxWait.Visible = Not .Checked
txtFlowMaxWait.Visible = Not .Checked
lblFlowRepeat.Visible = .Checked
txtFlowRepeat.Visible = .Checked
lblFlowTarget.Visible = .Checked
txtFlowTarget.Visible = .Checked
btnFlowTarget.Visible = .Checked
End If
End With
End Sub
Private Sub rbGroup_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbGroup.CheckedChanged
With rbGroup
If .Checked Then
lblFlowWait.Visible = Not .Checked
txtFlowWait.Visible = Not .Checked
lblFlowMaxWait.Visible = Not .Checked
txtFlowMaxWait.Visible = Not .Checked
lblFlowRepeat.Visible = .Checked
txtFlowRepeat.Visible = .Checked
lblFlowTarget.Visible = .Checked
txtFlowTarget.Visible = .Checked
btnFlowTarget.Visible = .Checked
End If
End With
End Sub
Private Sub rbInputVideo_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbInputVideo.CheckedChanged
With rbInputVideo
If .Checked Then
gbVideo.Visible = .Checked
End If
End With
End Sub
Private Sub rbInputAudio_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbInputAudio.CheckedChanged
With rbInputAudio
If .Checked Then
gbVideo.Visible = Not .Checked
MsgBox("Not yet supported.")
End If
End With
End Sub
Private Sub rbInputRumble_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbInputRumble.CheckedChanged
With rbInputRumble
If .Checked Then
gbVideo.Visible = Not .Checked
MsgBox("Not yet supported.")
End If
End With
End Sub
'code add
'code update
'code delete
'code move up/down
'load
'save
'play
'stop
'pause
'continue
'select controller
'Edit ui:
'Store path when loading, default to save as that
'Entries for the 4 main instruction types
'Add to (before/after/1st/last)
'Delete selected
'Internally goto should probably link to another instruction, and just display the line number on tostring
'Would have tostring for display (with line #) and serialize to save to file
'Script name
'Save script
'Load script
'Test script (pick controller)
'Stop script
'Pause/continue script
'Playback ui
'Can open multiple windows
'Sections have compact/expanded view
'Controller section, pick method and port
'Manual section, controller view.
'Script section, pick script, view current position
'Run section, stop/pause/continue/start/start all
'"Compile" to list of just press and release events with links back to parent instructions. But how do we show when wait is active or goto or interleaved press & hold.
'Waits could compile as null presses
'Maybe just leave out loop updating?
' btnUp = &H100
'btnDown = &H200
'btnLeft = &H400
'btnRight = &H800
'btnStart = &H1000
'btnBack = &H2000
'btnL3 = &H4000
'btnR3 = &H8000
'btnLB = &H1
'btnRB = &H2
'btnGuide = &H4
'btnA = &H10
'btnB = &H20
'btnX = &H40
'btnY = &H80
Public Function btnToMap() As Integer
Return (btnDU.FlatAppearance.BorderSize * &H100) _
Or (btnDD.FlatAppearance.BorderSize * &H200) _
Or (btnDL.FlatAppearance.BorderSize * &H400) _
Or (btnDR.FlatAppearance.BorderSize * &H800) _
Or (btnStart.FlatAppearance.BorderSize * &H1000) _
Or (btnBack.FlatAppearance.BorderSize * &H2000) _
Or (btnLS.FlatAppearance.BorderSize * &H4000) _
Or (btnRS.FlatAppearance.BorderSize * &H8000) _
Or (btnLB.FlatAppearance.BorderSize * &H1) _
Or (btnRB.FlatAppearance.BorderSize * &H2) _
Or (btnGuide.FlatAppearance.BorderSize * &H4) _
Or (btnA.FlatAppearance.BorderSize * &H10) _
Or (btnB.FlatAppearance.BorderSize * &H20) _
Or (btnX.FlatAppearance.BorderSize * &H40) _
Or (btnY.FlatAppearance.BorderSize * &H80)
End Function
Public Sub mapToBtn(map As Integer)
btnDU.FlatAppearance.BorderSize = IIf(map And &H100, 1, 0)
btnDD.FlatAppearance.BorderSize = IIf(map And &H200, 1, 0)
btnDL.FlatAppearance.BorderSize = IIf(map And &H400, 1, 0)
btnDR.FlatAppearance.BorderSize = IIf(map And &H800, 1, 0)
btnStart.FlatAppearance.BorderSize = IIf(map And &H1000, 1, 0)
btnBack.FlatAppearance.BorderSize = IIf(map And &H2000, 1, 0)
btnLS.FlatAppearance.BorderSize = IIf(map And &H4000, 1, 0)
btnRS.FlatAppearance.BorderSize = IIf(map And &H8000, 1, 0)
btnLB.FlatAppearance.BorderSize = IIf(map And &H1, 1, 0)
btnRB.FlatAppearance.BorderSize = IIf(map And &H2, 1, 0)
btnGuide.FlatAppearance.BorderSize = IIf(map And &H4, 1, 0)
btnA.FlatAppearance.BorderSize = IIf(map And &H10, 1, 0)
btnB.FlatAppearance.BorderSize = IIf(map And &H20, 1, 0)
btnX.FlatAppearance.BorderSize = IIf(map And &H40, 1, 0)
btnY.FlatAppearance.BorderSize = IIf(map And &H80, 1, 0)
End Sub
Private Function createAction() As clsAction
Dim action As clsAction = Nothing
If tcActions.SelectedTab Is tpController Then
If rbRelease.Checked Then action = New clsActionRelease(cbControllerIP.SelectedItem, btnToMap, valLT, valRT, valLS, valRS, activeGroup)
If rbHold.Checked Then action = New clsActionHold(cbControllerIP.SelectedItem, btnToMap, valLT, valRT, valLS, valRS, activeGroup)
If rbPress.Checked Then action = New clsActionPress(cbControllerIP.SelectedItem, btnToMap, valLT, valRT, valLS, valRS, unformatMS(txtControllerHold.Text), unformatMS(txtControllerWait.Text), CInt(txtControllerRepeat.Text), activeGroup)
ElseIf tcActions.SelectedTab Is tpFlow Then
If rbWait.Checked Then action = New clsActionWait(unformatMS(txtFlowWait.Text), activeGroup)
If rbWaitRandom.Checked Then action = New clsActionWaitRandom(unformatMS(txtFlowWait.Text), unformatMS(txtFlowMaxWait.Text), activeGroup)
If rbLoop.Checked Then
If loopTarget Is Nothing Then MsgBox("You must select a target") Else action = New clsActionLoop(loopTarget, CInt(txtFlowRepeat.Text), activeGroup)
End If
If rbGroup.Checked Then
If groupTarget Is Nothing Then MsgBox("You must select a target") Else action = New clsActionAGroup(groupTarget, CInt(txtFlowRepeat.Text), activeGroup)
End If
ElseIf tcActions.SelectedTab Is tpInput Then
If rbInputVideo.Checked Then action = New clsActionInputVideo(unformatMS(txtInputInterval.Text), unformatMS(txtInputDuration.Text), New Point(txtVideoPixelX.Text, txtVideoPixelY.Text), btnVideoColorMin.BackColor, btnVideoColorMax.BackColor, activeGroup)
'If rbInputAudio.Checked Then action = New clsActionInputAudio(txtInputInterval.Text, txtInputDuration.Text, <source>,<minvol>,<maxvol>)
'If rbInputRumble.Checked Then action = New clsActionInputRumble(txtInputInterval.Text, txtInputDuration.Text, <controller>,<rumbletype>,<minval>,<maxval>)
'todo: create input actions
ElseIf tcActions.SelectedTab Is tpOutput Then
If rbOutputAudio.Checked Then
If txtOutputAudio.Text = vbNullString OrElse Not IO.File.Exists(txtOutputAudio.Text) Then
MsgBox("You must select a valid audio file")
Else
action = New clsActionOutputAudio(txtOutputAudio.Text, unformatMS(txtSkip.Text), activeGroup)
Dim ai As clsActionOutput = action
End If
End If
End If
Return action
End Function
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
Dim action As clsAction = createAction()
If action Is Nothing Then Exit Sub
Dim index As Integer = activeGroup.actions.Count
Select Case Me.cmbAdd.Text
Case "Last"
Case "After"
If lbActions.SelectedItems.Count > 0 Then
index = lbActions.SelectedItems(lbActions.SelectedItems.Count - 1).index + 1
Else
index = lbActions.Items.Count
End If
Case "Before"
If lbActions.SelectedItems.Count > 0 Then
index = lbActions.SelectedItems(0).index
Else
index = 0
End If
Case "First"
index = 0
End Select
action.index = index
activeGroup.actions.Insert(index, action)
lbActions.Items.Insert(index, action)
For i As Integer = index + 1 To activeGroup.actions.Count - 1
activeGroup.actions(i).index += 1
lbActions.Items(i).Refresh(lbActions)
Next
End Sub
Private Sub txtNumeric_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txtFlowRepeat.Validating, txtControllerRepeat.Validating, txtVideoPixelX.Validating, txtVideoPixelY.Validating
Dim re As New Regex("^\d+$")
If Not re.IsMatch(sender.text) Then
e.Cancel = True
MsgBox("You may only enter numbers in this field.")
End If
End Sub
Private Sub txtTime_Validation(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txtControllerWait.Validating, txtControllerHold.Validating, txtFlowWait.Validating, txtFlowMaxWait.Validating, txtInputInterval.Validating, txtInputDuration.Validating, txtSkip.Validating
Dim ms As Long = unformatMS(sender.text)
If ms = -1 Then
e.Cancel = True
MsgBox("You may only enter times in this field." & vbCrLf & "Valid formats are:" & vbCrLf &
"1:02:03.004" & vbCrLf &
"62:03.004" & vbCrLf &
"3723.004" & vbCrLf &
"1h2m3s4ms" & vbCrLf &
"62m3s4ms" & vbCrLf &
"3723s4ms" & vbCrLf &
"3723004ms" & vbCrLf)
End If
sender.text = formatMS(ms)
End Sub
Private Sub btnTgt_Click(sender As System.Object, e As System.EventArgs) Handles btnFlowTarget.Click
If rbLoop.Checked Then
loopTarget = lbActions.SelectedItem
txtFlowTarget.Text = loopTarget.index + 1
End If
If rbGroup.Checked Then
groupTarget = lbGroups.SelectedItem
If groupTarget Is activeGroup OrElse groupTarget.containsGroup(activeGroup) Then
MsgBox("A group can't link to itself.")
groupTarget = Nothing
txtFlowTarget.Text = vbNullString
Else
txtFlowTarget.Text = groupTarget.name
End If
End If
End Sub
Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
If lbActions.SelectedItems.Count = 0 Then Exit Sub
Dim lstRemove As New List(Of clsAction)
For Each action As clsAction In lbActions.SelectedItems
lstRemove.Add(action)
Next
lbActions.BeginUpdate()
For Each action In lstRemove
activeGroup.actions.Remove(action)
lbActions.Items.Remove(action)
action.delete()
Next
For i = lstRemove(0).index To activeGroup.actions.Count - 1
activeGroup.actions(i).index = i
Next
If activeGroup.actions.Count - lstRemove(0).index > 500 Then
lbActions.RefreshItems()
For i = lstRemove(0).index To activeGroup.actions.Count - 1
lbActions.Items(i).Refresh(lbActions, False)
Next
Else
For i = lstRemove(0).index To activeGroup.actions.Count - 1
lbActions.Items(i).Refresh(lbActions)
Next
End If
lbActions.EndUpdate()
End Sub
Private Sub btnMoveUp_Click(sender As System.Object, e As System.EventArgs) Handles btnMoveUp.Click
'any internals are moved after, then move it before the one previous (if not at beginning)
If lbActions.SelectedItems.Count = 0 Then Exit Sub
Dim startindex As Integer = lbActions.SelectedItems(0).index
If startindex < 1 Then Exit Sub
Dim endIndex As Integer = lbActions.SelectedItems(lbActions.SelectedItems.Count - 1).index
Dim lstMove As New List(Of clsAction)
For Each action As clsAction In lbActions.SelectedItems
lstMove.Add(action)
Next
lbActions.BeginUpdate()
For Each action In lstMove
activeGroup.actions.Remove(action)
lbActions.Items.Remove(action)
Next
For i As Integer = lstMove.Count - 1 To 0 Step -1
activeGroup.actions.Insert(startindex - 1, lstMove(i))
lbActions.Items.Insert(startindex - 1, lstMove(i))
Next
For i As Integer = startindex - 1 To endIndex
activeGroup.actions(i).index = i
lbActions.Items(i).refresh(lbActions)
Next
For Each action In lstMove
lbActions.SelectedItems.Add(action)
Next
lbActions.EndUpdate()
End Sub
Private Sub btnMoveDown_Click(sender As System.Object, e As System.EventArgs) Handles btnMoveDown.Click
If lbActions.SelectedItems.Count = 0 Then Exit Sub
Dim endIndex As Integer = lbActions.SelectedItems(lbActions.SelectedItems.Count - 1).index
If endIndex > lbActions.Items.Count - 2 Then Exit Sub
Dim startindex As Integer = lbActions.SelectedItems(0).index
Dim lstMove As New List(Of clsAction)
For Each action As clsAction In lbActions.SelectedItems
lstMove.Add(action)
Next
lbActions.BeginUpdate()
For Each action In lstMove
activeGroup.actions.Remove(action)
lbActions.Items.Remove(action)
Next
For i As Integer = 0 To lstMove.Count - 1
activeGroup.actions.Insert(startindex + i + 1, lstMove(i))
lbActions.Items.Insert(startindex + i + 1, lstMove(i))
Next
For i As Integer = startindex To endIndex + 1
activeGroup.actions(i).index = i
lbActions.Items(i).refresh(lbActions)
Next
For Each action In lstMove
lbActions.SelectedItems.Add(action)
Next
lbActions.EndUpdate()
End Sub
Private Sub lbActions_DoubleClick(sender As Object, e As System.EventArgs) Handles lbActions.DoubleClick
If lbActions.SelectedItems.Count <> 1 Then Exit Sub
Dim action As clsAction = lbActions.SelectedItem
Select Case action.getActType
Case ActionType.actWait
Dim aWait As clsActionWait = action
tcActions.SelectedTab = tpFlow
rbWait.Checked = True
With aWait
txtFlowWait.Text = formatMS(.delay)
End With
Case ActionType.actWaitRandom
Dim aWaitRandom As clsActionWaitRandom = action
tcActions.SelectedTab = tpFlow
rbWaitRandom.Checked = True
With aWaitRandom
txtFlowWait.Text = formatMS(.minDelay)
txtFlowMaxWait.Text = formatMS(.maxDelay)
End With
Case ActionType.actLoop
Dim aLoop As clsActionLoop = action
tcActions.SelectedTab = tpFlow
rbLoop.Checked = True
With aLoop
txtFlowRepeat.Text = .repeat
loopTarget = .target
txtFlowTarget.Text = .target.index + 1
End With
Case ActionType.actGroup
Dim aGroup As clsActionAGroup = action
tcActions.SelectedTab = tpFlow
rbGroup.Checked = True
With aGroup
txtFlowRepeat.Text = .repeat
groupTarget = .target
txtFlowTarget.Text = .target.name
End With
Case ActionType.actHold
Dim aHold As clsActionHold = action
tcActions.SelectedTab = tpController
rbHold.Checked = True
With aHold
mapToBtn(.buttonMask)
valLT = IIf(.LTDefined, .LT, -1)
refreshLT()
valRT = IIf(.RTDefined, .RT, -1)
refreshRT()
If .LS.X = -32768 Or .LS.Y = -32768 Then
valLS.X = -32768
valLS.Y = -32768
Else
valLS.X = .LS.X
valLS.Y = .LS.Y
End If
drawPB(pbLS)
If .RS.X = -32768 Or .RS.Y = -32768 Then
valRS.X = -32768
valRS.Y = -32768
Else
valRS.X = .RS.X
valRS.Y = .RS.Y
End If
drawPB(pbRS)
cbControllerIP.SelectedIndex = aHold.controllerNumber - 1
End With
Case ActionType.actPress
Dim aPress As clsActionPress = action
tcActions.SelectedTab = tpController
rbPress.Checked = True
With aPress
mapToBtn(.buttonMask)
valLT = IIf(.LTDefined, .LT, -1)
refreshLT()
valRT = IIf(.RTDefined, .RT, -1)
refreshRT()
If .LS.X = -128 Or .LS.Y = -128 Then
valLS.X = -32768
valLS.Y = -32768
Else
valLS.X = .LS.X
valLS.Y = .LS.Y
End If
drawPB(pbLS)
If .RS.X = -32768 Or .RS.Y = -32768 Then
valRS.X = -32768
valRS.Y = -32768
Else
valRS.X = .RS.X
valRS.Y = .RS.Y
End If
drawPB(pbRS)
txtControllerRepeat.Text = .repeat
txtControllerWait.Text = formatMS(.waitTime)
txtControllerHold.Text = formatMS(.holdTime)
End With
cbControllerIP.SelectedIndex = aPress.controllerNumber - 1
Case ActionType.actRelease
Dim aRelease As clsActionRelease = action
tcActions.SelectedTab = tpController
rbRelease.Checked = True
With aRelease
mapToBtn(.buttonMask)
valLT = IIf(.LTDefined, 0, -1)
refreshLT()
valRT = IIf(.RTDefined, 0, -1)
refreshRT()
End With
cbControllerIP.SelectedIndex = aRelease.controllerNumber - 1
Case ActionType.actInputVideo
Dim aInputVideo As clsActionInputVideo = action
tcActions.SelectedTab = tpInput
With aInputVideo
txtInputInterval.Text = formatMS(.interval)
txtInputDuration.Text = formatMS(.duration)
txtVideoPixelX.Text = .pixel.X
txtVideoPixelY.Text = .pixel.Y
btnVideoColorMin.BackColor = .minColor
btnVideoColorMax.BackColor = .maxColor
End With
Case ActionType.actInputAudio
tcActions.SelectedTab = tpInput
'todo: populate control
Case ActionType.actInputRumble
tcActions.SelectedTab = tpInput
'todo: populate control
Case ActionType.actOutputAudio
Dim aOutputAudio As clsActionOutputAudio = action
tcActions.SelectedTab = tpOutput
txtOutputAudio.Text = Join(aOutputAudio.paths.ToArray, "|")
txtSkip.Text = formatMS(aOutputAudio.skipMS)
End Select
End Sub
Private Sub btnApply_Click(sender As System.Object, e As System.EventArgs) Handles btnApply.Click
If lbActions.SelectedItems.Count <> 1 Then Exit Sub
Dim action As clsAction = createAction()
Dim oldAction As clsAction = lbActions.SelectedItem
action.index = oldAction.index
For Each referrer In oldAction.referrers
referrer.target = action
action.referrers.Add(referrer)
Next
activeGroup.actions(lbActions.SelectedIndex) = action
lbActions.Items(lbActions.SelectedIndex) = action
action.refresh(lbActions)
oldAction.referrers.Clear()
oldAction.delete()
End Sub
Private Sub NewToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles NewToolStripMenuItem.Click
clearScript()
blankScript()
End Sub
Private Sub OpenToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenToolStripMenuItem.Click
fdOpen.FileName = vbNullString
fdOpen.InitialDirectory = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) & "\scripts"
fdOpen.ShowDialog()
If fdOpen.FileName = vbNullString Then Exit Sub
loadScript(fdOpen.FileName)
End Sub
Private Sub SaveToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveToolStripMenuItem.Click
MenuStrip1.Focus()
If activeFile.path = vbNullString Then
SaveAsToolStripMenuItem_Click(sender, e)
Exit Sub
End If
activeFile.saveScriptXML()
End Sub
Private Sub SaveAsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
MenuStrip1.Focus()
fdSave.InitialDirectory = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) & "\scripts"
If activeFile.path <> vbNullString Then
fdSave.FileName = activeFile.path
Else
If txtGame.Text = vbNullString Then
If txtTitle.Text = vbNullString Then
fdSave.FileName = vbNullString
Else
fdSave.FileName = fdSave.InitialDirectory & "\" & txtTitle.Text & ".axb"
End If
Else
If txtTitle.Text = vbNullString Then
fdSave.FileName = fdSave.InitialDirectory & "\" & txtGame.Text & ".axb"
Else
fdSave.FileName = fdSave.InitialDirectory & "\" & txtGame.Text & " - " & txtTitle.Text & ".axb"
End If
End If
End If
fdSave.ShowDialog()
If fdSave.FileName = vbNullString Then Exit Sub
activeFile.saveScriptXML(fdSave.FileName)
End Sub
'Private Sub saveScript(path As String)
' Dim sb As New System.Text.StringBuilder
' sb.AppendLine("#" & txtGame.Text)
' sb.AppendLine("#" & txtTitle.Text)
' For Each line As String In txtDesc.Lines
' sb.AppendLine("#" & line)
' Next
' For Each action As clsAction In lbActions.Items
' sb.AppendLine(action.serialize)
' Next
' IO.File.WriteAllText(path, sb.ToString)
'End Sub
Private Sub loadScript(path As String)
loadScript(clsScriptFile.loadScriptXML(path))
End Sub
Private Sub loadScript(sf As clsScriptFile)
clearScript()
activeFile = sf
txtGame.Text = activeFile.game
txtTitle.Text = activeFile.title
txtDesc.Text = activeFile.description
For Each g As clsActionGroup In activeFile.groups.Values
lbGroups.Items.Add(g)
Next
If activeFile.groups.ContainsKey(mainGroup) Then activeGroup = activeFile.groups(mainGroup) Else activeGroup = lbGroups.Items(0)
lbGroups.SelectedItem = activeGroup
linkActions()
refreshGroup()
End Sub
Private Sub linkActions()
For Each group In activeFile.groups.Values
For Each action As clsAction In group.actions
If action.getActType = ActionType.actLoop Then
Dim aLoop As clsActionLoop = action
aLoop.linkTarget(group.actions)
End If
If action.getActType = ActionType.actGroup Then
Dim aGroup As clsActionAGroup = action
aGroup.linkTarget(activeFile.groups)
End If
Next
Next
End Sub
Private Sub refreshGroup()
lbGroups.SelectedItem = activeGroup
lbActions.Items.Clear()
txtFlowTarget.Text = vbNullString
groupTarget = Nothing
loopTarget = Nothing
If activeGroup.actions.Count = 0 Then Exit Sub
'Dim oc As New ListBox.ObjectCollection(lbActions, activeGroup.actions.ToArray)
'Dim oc As New ListBox.ObjectCollection(lbActions)
lbActions.Items.AddRange(activeGroup.actions.ToArray)
'lbActions.BeginUpdate()
'For Each a As clsAction In activeGroup.actions
'lbActions.Items.Add(a)
'Next
'lbActions.EndUpdate()
End Sub
Private Sub btnPlayPause_Click(sender As System.Object, e As System.EventArgs) Handles btnPlayPause.Click
If activeScript Is Nothing Then
If Not activeGroup Is activeFile.groups(mainGroup) Then
activeGroup = activeFile.groups(mainGroup)
refreshGroup()
End If
Dim actions As New Generic.List(Of clsAction)
For Each action As clsAction In activeGroup.actions
actions.Add(action)
If action.getActType = ActionType.actGroup Then
Dim agAction As clsActionAGroup = action
For i As Integer = 1 To agAction.repeat
actions.AddRange(agAction.target.getActions())
Next
End If
Next
tmrScriptStatus.Enabled = True
btnStop.Enabled = True
btnFaster.Enabled = True
btnSlower.Enabled = True
Dim controllerIPS As New Dictionary(Of Byte, String)
If txtController1.Text <> vbNullString Then controllerIPS.Add(1, txtController1.Text)
If txtController2.Text <> vbNullString Then controllerIPS.Add(2, txtController2.Text)
If txtController3.Text <> vbNullString Then controllerIPS.Add(3, txtController3.Text)
If txtController4.Text <> vbNullString Then controllerIPS.Add(4, txtController4.Text)
activeScript = New clsScript(actions, controllerIPS)
If activeScript.state = clsScript.scriptState.scriptError Then
activeScript = Nothing
tmrScriptStatus.Enabled = False
btnStop.Enabled = False
btnFaster.Enabled = False
btnSlower.Enabled = False