-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.gd
886 lines (660 loc) · 34 KB
/
Main.gd
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
extends Node2D
var A_Controller_pressed: bool = false
var C_Controller_pressed: bool = false
var D_Controller_pressed: bool = false
var A_Controller_start_position: Vector2
var C_Controller_start_position: Vector2
var D_Controller_start_position: Vector2
var A_Controller_limiter: Vector2
var C_Controller_limiter: Vector2
var D_Controller_limiter: Vector2
func A_mouse_loc():
return (A_Controller_start_position + get_local_mouse_position() + $A_Controller.rect_size/2)
func C_mouse_loc():
return (C_Controller_start_position + get_local_mouse_position() + $C_Controller.rect_size/2)
func D_mouse_loc():
return (D_Controller_start_position + get_local_mouse_position() + $D_Controller.rect_size/2)
func A_B_difference():
return ($A_B.points[0] - $A_B.points[1])
func angle_calc(p1, p2, p3):
var p12 = sqrt(pow((p1.x - p2.x),2) + pow((p1.y - p2.y),2))
var p13 = sqrt(pow((p1.x - p3.x),2) + pow((p1.y - p3.y),2))
var p23 = sqrt(pow((p2.x - p3.x),2) + pow((p2.y - p3.y),2))
if (p12 == 0 or p13 == 0 or p23 == 0):
return 0
return (acos(((pow(p12, 2)) + (pow(p13, 2)) - (pow(p23, 2))) / (2 * p12 * p13)) * 180 / PI)
var A_B_slope: int = 0
var C_B_slope: int = 0
func A():
return Vector2(stepify($A_B.points[0].x, 0.01), stepify($A_B.points[0].y, 0.01) )
func B():
return Vector2(stepify($A_B.points[1].x, 0.01), stepify($A_B.points[1].y, 0.01) )
func C():
return Vector2(stepify( $D_B_C.points[0].x, 0.01), stepify( $D_B_C.points[0].y, 0.01) )
func D():
return Vector2(stepify( $D_B_C.points[2].x, 0.01), stepify( $D_B_C.points[2].y, 0.01) )
func A_Controller():
return Vector2(stepify($A_Controller.rect_position.x, 0.01), stepify($A_Controller.rect_position.y, 0.01) )
func C_Controller():
return Vector2(stepify($C_Controller.rect_position.x, 0.01), stepify($C_Controller.rect_position.y, 0.01) )
func D_Controller():
return Vector2(stepify($D_Controller.rect_position.x, 0.01), stepify($D_Controller.rect_position.y, 0.01) )
var A_B_C_Hide: bool = false
var A_B_D_Hide: bool = false
var A_loc: Vector2
var C_loc: Vector2
var D_loc: Vector2
var A_Controller_loc: Vector2
var C_Controller_loc: Vector2
var D_Controller_loc: Vector2
var A_B_C_unite_offset: float
var A_B_D_unite_offset: float
var A_B_C_Cutter_z_index: int
var A_B_C_Cutter2_z_index: int
var A_B_D_Cutter_z_index: int
func _ready():
#adjusting the screen size if the program was running on windows (x86) and centering the window
if (OS.get_name() == 'Windows'):
OS.window_size = Vector2( stepify(OS.get_screen_size().x / 1.2, 1), stepify(OS.get_screen_size().y / 1.2, 1))
OS.center_window()
#----- Connecting 'Buttons' and 'Controller' -----#
$A_Controller.connect('button_down', self, '_on_A_Controller_button_down')
$A_Controller.connect('button_up', self, '_on_A_Controller_button_up')
$C_Controller.connect('button_down', self, '_on_C_Controller_button_down')
$C_Controller.connect('button_up', self, '_on_C_Controller_button_up')
$D_Controller.connect('button_down', self, '_on_D_Controller_button_down')
$D_Controller.connect('button_up', self, '_on_D_Controller_button_up')
$A_B_C_Hide.connect('pressed', self, '_on_A_B_C_Hide_pressed')
$A_B_D_Hide.connect('pressed', self, '_on_A_B_D_Hide_pressed')
$Restore_Button.connect('pressed', self, '_on_Restore_Button_pressed')
#--------------------------------------------------------------------------------#
#----- Centering the pivot to the origin (center of the object) for rotating in a correct way -----#
$A_Controller.rect_pivot_offset = $A_Controller.rect_size/2
$C_Controller.rect_pivot_offset = $C_Controller.rect_size/2
$D_Controller.rect_pivot_offset = $D_Controller.rect_size/2
#--------------------------------------------------------------------------------#
#----- Controlling the rotation of the Controller to make like it's tracking the 'B' point or the center of the display -----#
$C_Controller.rect_rotation = angle_calc( B(), C(), Vector2(0, B().y)) - 90
$D_Controller.rect_rotation = angle_calc(B(), D(), Vector2(0, B().y)) - 90
#--------------------------------------------------------------------------------#
#----- Centering the Controller position to the origin point as this feature is not in the inspector tab. -----#
$A_Controller.rect_position.x = B().x - ($A_Controller.rect_size.x/2)
$C_Controller.rect_position = C() - $C_Controller.rect_size/2
$D_Controller.rect_position = D() - $D_Controller.rect_size/2
# $A_B.points[0] = A()
$A_B.points[0] = A_Controller() + Vector2( round($A_Controller.rect_size.x/2), round($A_Controller.rect_size.y/2) )
#--------------------------------------------------------------------------------#
#----- Aligning the 'Angle_Text's to the left or right based on the 'B' position. B is in the center -----#
# Aligning 'A_Controller_Text'
if (A().x - B().x < 0):
# Left
$A_Controller_Text.rect_position = A_Controller() + $A_Controller.rect_size/2 - $A_Controller_Text.rect_size/2 - Vector2($A_Controller_Text.rect_size.x*1.5, 0)
else:
# Right
$A_Controller_Text.rect_position = A_Controller() + $A_Controller.rect_size/2 - $A_Controller_Text.rect_size/2 + Vector2($A_Controller_Text.rect_size.x*1.5, 0)
# Aligning 'C_Controller_Text'
if (C().x - B().x < 0):
# Left
$C_Controller_Text.rect_position = $C_Controller.rect_position + $C_Controller.rect_size/2 - $C_Controller_Text.rect_size/2 - Vector2($C_Controller_Text.rect_size.x*1.5, 0)
else:
# Right
$C_Controller_Text.rect_position = $C_Controller.rect_position + $C_Controller.rect_size/2 - $C_Controller_Text.rect_size/2 + Vector2($C_Controller_Text.rect_size.x*1.5, 0)
# Aligning 'D_Controller_Text'
if (D().x - B().x < 0):
# Here to the left.
$D_Controller_Text.rect_position = D_Controller() + $D_Controller.rect_size/2 - $D_Controller_Text.rect_size/2 - Vector2($D_Controller_Text.rect_size.x*1.5, 0)
else:
# Here to the right.
$D_Controller_Text.rect_position = D_Controller() + $D_Controller.rect_size/2 - $D_Controller_Text.rect_size/2 + Vector2($D_Controller_Text.rect_size.x*1.5, 0)
#--------------------------------------------------------------------------------#
#----- Calculating where the 'Angle_Text' will be placed based on some matrix calculations :) -----#
#A_B_C_Text
$A_B_C_Text_Director/A_B_C_Text_Director_Follow.unit_offset = (angle_calc(B(), A(), C())/2 + angle_calc(B(), C(), Vector2(C().x, B().y)))/360
#A_B_D_Text
$A_B_D_Text_Director/A_B_D_Text_Director_Follow.unit_offset = .5 - (angle_calc(B(), A(), D())/2 + angle_calc(B(), D(), Vector2(D().x, B().y)))/360
#--------------------------------------------------------------------------------#
#----- Changing the 'Angle_Indicator' to be a 'Cirlce' or a 'Square'. If the angle is 90. Then 'Square', if the angle is not 90. Then 'Circle' ----#
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_C_Circle.visible = true
else:
$A_B_C_Circle.visible = false
if (round(angle_calc(B(), A(), C())) == 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_D_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_D_Cutter.z_index = -4
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_C_Cutter.z_index = -2
if (round(angle_calc(B(), A(), C())) == 90):
$A_B_C_Square.rotation_degrees = 45 - (angle_calc( B(), A(), C() ) / 2 + angle_calc( B(), C(), Vector2(1921, B().y) ) )
$A_B_C_Square.visible = true
$A_B_C_Circle2.visible = false
else:
$A_B_C_Square.visible = false
$A_B_C_Circle2.visible = true
if (round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Square2.rotation_degrees = 225 - (angle_calc( B(), A(), D() ) / 2 + angle_calc( B(), D(), Vector2(1921, B().y) ) )
$A_B_C_Square2.visible = true
else:
$A_B_C_Square2.visible = false
#--------------------------------------------------------------------------------#
#----- Storing Everything position for the Restore button -----#
# Storing the 'z_index'
A_B_C_Cutter_z_index = $A_B_C_Cutter.z_index
A_B_C_Cutter2_z_index = $A_B_C_Cutter2.z_index
A_B_D_Cutter_z_index = $A_B_D_Cutter.z_index
# Storing the 'Points' location.
A_loc = A()
C_loc = C()
D_loc = D()
# Storing the 'Points_Controllers' location.
A_Controller_loc = $A_Controller.rect_position
C_Controller_loc = $C_Controller.rect_position
D_Controller_loc = $D_Controller.rect_position
# Storing the 'Angle_Text' position.
A_B_C_unite_offset = $A_B_C_Text_Director/A_B_C_Text_Director_Follow.unit_offset
A_B_D_unite_offset = $A_B_D_Text_Director/A_B_D_Text_Director_Follow.unit_offset
#--------------------------------------------------------------------------------#
func _process(__data__):
if (A_Controller_pressed):
#----- Checking that equations are not equal to 0 to prevent problems. -----#
var safe1: bool
var safe2: bool
if (C().y - B().y != 0 and (A_mouse_loc().y - B().y) != 0 and (C().y - B().y) != 0 and (C().y - B().y) * (B().y - A_mouse_loc().y) != 0): safe1 = true
else: safe1 = false
if (D().y - B().y != 0 and (A_mouse_loc().y - B().y) != 0 and (D().y - B().y) != 0 and (D().y - B().y) * (B().y - A_mouse_loc().y) != 0): safe2 = true
else: safe2 = false
#--------------------------------------------------------------------------------#
#----- Making some if statements with a 'Controller_limiter'. So, when a thing that unwanted happens, that limitter value will take out that unwanted data from the given mouse_position values and then send it. -----#
# Preventing 'A' from getting under 'B'
if (A_mouse_loc().y > B().y - 1):
A_Controller_limiter.x = 0
A_Controller_limiter.y = A_mouse_loc().y - B().y + 1
# if the slope of the 'A' to the 'B' is interfering with the slope of the 'C' to the 'B'. It means that if the 'A' line is interfering with the 'C' line.
elif (safe1 and (C().x - B().x) / ( C().y - B().y) > (A_mouse_loc().x - B().x) / (A_mouse_loc().y - B().y) and (B().y - C().y > 0) ):
A_Controller_limiter.x = A_mouse_loc().x - ( B().x - ( (C().x - B().x) / (C().y - B().y) ) * (B().y - A_mouse_loc().y) )
A_Controller_limiter.y = 0
# if the slope of the 'A' to the 'B' is interfering with the slope of the 'D' to the 'B'.
elif (safe2 and (D().x - B().x) / ( D().y - B().y) < (A_mouse_loc().x - B().x) / (A_mouse_loc().y - B().y) and (B().y - D().y > 0) ):
A_Controller_limiter.x = A_mouse_loc().x - ( B().x - ( (D().x - B().x) / (D().y - B().y) ) * (B().y - A_mouse_loc().y) )
A_Controller_limiter.y = 0
# No Unwanted data found
else: A_Controller_limiter = Vector2(0,0)
# Positioning the 'Controller'.
$A_Controller.set_position(A_Controller_start_position + get_local_mouse_position() - A_Controller_limiter)
# Rotating the Controller so it will track the 'B' point or the bottom center of the display.
$A_Controller.rect_rotation = angle_calc(B(), A(), Vector2(0, B().y)) - 90
#--------------------------------------------------------------------------------#
# Positioning the 'A' point from the 'Conroller' position data
# A() =
$A_B.points[0] = A_Controller() + Vector2( round($A_Controller.rect_size.x/2), round($A_Controller.rect_size.y/2) )
#----- Aligning the 'Angle_Text' to the left or right based on it's position to the 'B' position -----#
if (A_B_difference().x < 0):
# Left
$A_Controller_Text.rect_position = A_Controller() + $A_Controller.rect_size/2 - $A_Controller_Text.rect_size/2 - Vector2($A_Controller_Text.rect_size.x*1.5, 0)
else:
# Right
$A_Controller_Text.rect_position = A_Controller() + $A_Controller.rect_size/2 - $A_Controller_Text.rect_size/2 + Vector2($A_Controller_Text.rect_size.x*1.5, 0)
#-----------------------------------------------------------------------------------------------------#
#----- Changing the 'Angle_Text' values -----#
$A_B_C_Text_Director/A_B_C_Text_Director_Follow/A_B_C_Text.text = str(round(angle_calc(B(), A(), C())))
$A_B_D_Text_Director/A_B_D_Text_Director_Follow/A_B_D_Text.text = str(round(angle_calc(B(), A(), D())))
#--------------------------------------------------------------------------------#
#----- Calculating where the 'Angle_Text' will be placed based on some matrix calculations :) -----#
$A_B_C_Text_Director/A_B_C_Text_Director_Follow.unit_offset = (angle_calc(B(), A(), C())/2 + angle_calc(B(), C(), Vector2(1921, B().y)))/360
$A_B_D_Text_Director/A_B_D_Text_Director_Follow.unit_offset = .5 - (angle_calc(B(), A(), D())/2 + angle_calc(B(), D(), Vector2(0, B().y)))/360
#--------------------------------------------------------------------------------#
#----- Positioning the Cutter points. The cutter is for cutting the 'Angle_Indicator_Circle'.
$A_B_C_Cutter.polygon[0] = A()
$A_B_C_Cutter.polygon[1] = Vector2( (D().x + A().x)/2, (D().y + A().y)/2 - 500)
$A_B_D_Cutter.polygon[1] = A()
$A_B_D_Cutter.polygon[0] = Vector2( (C().x + A().x)/2, (C().y + A().y)/2 - 500)
#--------------------------------------------------------------------------------#
#----- Changing the 'Angle_Indicator' to be a 'Cirlce' or a 'Square'. If the angle is 90. Then 'Square', if the angle is not 90. Then 'Circle' ----#
# C()
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_C_Circle.visible = true
else:
$A_B_C_Circle.visible = false
if (round(angle_calc(B(), A(), C())) == 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_D_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_D_Cutter.z_index = -4
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_C_Cutter.z_index = -2
# D()
if (round(angle_calc(B(), A(), C())) == 90):
$A_B_C_Square.rotation_degrees = 45 - (angle_calc( B(), A(), C() ) / 2 + angle_calc( B(), C(), Vector2(1921, B().y) ) )
$A_B_C_Square.visible = true
$A_B_C_Circle2.visible = false
else:
$A_B_C_Square.visible = false
$A_B_C_Circle2.visible = true
if (round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Square2.rotation_degrees = 225 - (angle_calc( B(), A(), D() ) / 2 + angle_calc( B(), D(), Vector2(1921, B().y) ) )
$A_B_C_Square2.visible = true
else:
$A_B_C_Square2.visible = false
#--------------------------------------------------------------------------------#
#----- If the Hide Buttons are pressed -----#
if A_B_C_Hide:
$A_B_D_Cutter.z_index = -1
$A_B_C_Square.visible = false
if A_B_D_Hide:
$A_B_C_Cutter.z_index = -1
$A_B_C_Square2.visible = false
#-------------------------------------------#
if (C_Controller_pressed):
#----- Checking that equations are not equal to 0 to prevent problems. -----#
var safe1:bool
var safe2:bool
if ( (A().y - B().y) != 0 and (C_mouse_loc().y - B().y) != 0 and (A().y - B().y) <= 0 and (A().y - B().y) * (B().y - C_mouse_loc().y) != 0): safe1 = true
else: safe2 = false
if (A().y - B().y != 0 or (C_mouse_loc().y - B().y) != 0 or (A().y - B().y) != 0): safe2 = true
else: safe2 = false
#--------------------------------------------------------------------------------#
#----- Making some if statements with a 'Controller_limiter'. So, when a thing that unwanted happens, that limitter value will take out that unwanted data from the given mouse_position values and then send it. -----#
# Preventing 'C' from getting under 'B'
if (C_mouse_loc().y > B().y - 1):
C_Controller_limiter.y = C_mouse_loc().y - B().y + 1
# if the slope of the 'C' to the 'B' is interfering with the slope of the 'A' to the 'B'. It means that if the 'C' line is interfering with the 'A' line.
elif (safe1):
if (A().x - B().x) / ( A().y - B().y) < (C_mouse_loc().x - B().x) / (C_mouse_loc().y - B().y):
C_Controller_limiter.x = C_mouse_loc().x - ( B().x - ( (A().x - B().x) / (A().y - B().y) ) * (B().y - C_mouse_loc().y) )
else:C_Controller_limiter = Vector2(0,0)
# if the slope of the 'A' to the 'B' is interfering with the slope of the 'D' to the 'B'.
elif (safe2):
if ( A().y - B().y >= 0):
if (A().x - B().x > 0):
C_Controller_limiter.y = C_mouse_loc().y - A().y
else: C_Controller_limiter = Vector2(0,0)
else: C_Controller_limiter = Vector2(0,0)
# No unwanted data is found.
else: C_Controller_limiter = Vector2(0,0)
#--------------------------------------------------------------------------------#
#----- Positioning and Rotating the Controller -----#
$C_Controller.set_position(C_Controller_start_position + get_local_mouse_position() - C_Controller_limiter)
# Rotating the Controller so it will track the 'B' point or the bottom center of the display.
$C_Controller.rect_rotation = angle_calc(B(), C(), Vector2(0, B().y)) - 90
#---------------------------------------------------#
# Positioning the 'A' point from the 'Conroller' position data
# C() =
$D_B_C.points[0] = $C_Controller.rect_position + Vector2( round($C_Controller.rect_size.x/2), round($C_Controller.rect_size.y/2) )
#----- Aligning the 'Angle_Text' to the left or right based on it's position to the 'B' position -----#
if (C().x - B().x < 0):
# Left
$C_Controller_Text.rect_position = $C_Controller.rect_position + $C_Controller.rect_size/2 - $C_Controller_Text.rect_size/2 - Vector2($C_Controller_Text.rect_size.x*1.5, 0)
else:
# Right
$C_Controller_Text.rect_position = $C_Controller.rect_position + $C_Controller.rect_size/2 - $C_Controller_Text.rect_size/2 + Vector2($C_Controller_Text.rect_size.x*1.5, 0)
#-----------------------------------------------------------------------------------------------------#
#----- Changing the 'Angle_Text' values -----#
$A_B_C_Text_Director/A_B_C_Text_Director_Follow/A_B_C_Text.text = str(round(angle_calc(B(), A(), C())))
$A_B_C_Text_Director/A_B_C_Text_Director_Follow.unit_offset = (angle_calc( B(), A(), C() ) / 2 + angle_calc( B(), C(), Vector2(1921, B().y) ) )/360
#--------------------------------------------------------------------------------#
#----- Positioning the Cutter points. The cutter is for cutting the 'Angle_Indicator_Circle'.
$A_B_D_Cutter.polygon[3] = C()
$A_B_D_Cutter.polygon[0] = Vector2( (C().x + A().x)/2, (C().y + A().y)/2 - 500)
$A_B_C_Cutter2.polygon[0] = C()
#--------------------------------------------------------------------------------#
#----- Changing the 'Angle_Indicator' to be a 'Cirlce' or a 'Square'. If the angle is 90. Then 'Square', if the angle is not 90. Then 'Circle' ----#
# C()
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_C_Circle.visible = true
else:
$A_B_C_Circle.visible = false
if (round(angle_calc(B(), A(), C())) == 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_D_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_D_Cutter.z_index = -4
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_C_Cutter.z_index = -2
if (round(angle_calc(B(), A(), C())) == 90):
$A_B_C_Square.rotation_degrees = 45 - (angle_calc( B(), A(), C() ) / 2 + angle_calc( B(), C(), Vector2(1921, B().y) ) )
$A_B_C_Square.visible = true
$A_B_C_Circle2.visible = false
else:
$A_B_C_Square.visible = false
$A_B_C_Circle2.visible = true
#--------------------------------------------------------------------------------#
#----- If the Hide Buttons are pressed -----#
if A_B_C_Hide:
$A_B_D_Cutter.z_index = -1
$A_B_C_Square.visible = false
if A_B_D_Hide:
$A_B_C_Cutter.z_index = -1
$A_B_C_Square2.visible = false
#-------------------------------------------#
if (D_Controller_pressed):
#----- Checking that equations are not equal to 0 to prevent problems. -----#
var safe1: bool
var safe2: bool
if (A().y - B().y != 0 and (D_mouse_loc().y - B().y) != 0 and (A().y - B().y) <= 0 and (A().y - B().y) * (B().y - D_mouse_loc().y) != 0):
safe1 = true
else:
safe1 = false
if (A().y - B().y != 0 or (D_mouse_loc().y - B().y) != 0 or (A().y - B().y) != 0):
safe2 = true
else:
safe2 = false
#--------------------------------------------------------------------------------#
#----- Making some if statements with a 'Controller_limiter'. So, when a thing that unwanted happens, that limitter value will take out that unwanted data from the given mouse_position values and then send it. -----#
# Preventing 'D' from getting under 'B'
if (D_mouse_loc().y > B().y - 1):
D_Controller_limiter.y = D_mouse_loc().y - B().y + 1
# if the slope of the 'D' to the 'B' is interfering with the slope of the 'A' to the 'B'. It means that if the 'D' line is interfering with the 'A' line.
elif (safe1):
if (A().x - B().x) / ( A().y - B().y) > (D_mouse_loc().x - B().x) / (D_mouse_loc().y - B().y):
D_Controller_limiter.x = D_mouse_loc().x - ( B().x - ( (A().x - B().x) / (A().y - B().y) ) * (B().y - D_mouse_loc().y) )
else: D_Controller_limiter = Vector2(0,0)
# if the slope of the 'A' to the 'B' is interfering with the slope of the 'D' to the 'B'.
elif (safe2):
if (A().y - B().y >= 0):
if (B().x - A().x > 0):
D_Controller_limiter.y = D_mouse_loc().y - A().y
else: D_Controller_limiter = Vector2(0,0)
else: D_Controller_limiter = Vector2(0,0)
# No unwanted data is found.
else: D_Controller_limiter = Vector2(0,0)
# Positioning the 'Controller'.
$D_Controller.set_position(D_Controller_start_position + get_local_mouse_position() - D_Controller_limiter)
# Rotating the Controller so it will track the 'B' point or the bottom center of the display.
$D_Controller.rect_rotation = angle_calc(B(), D(), Vector2(0, B().y)) - 90
# Positioning the 'A' point from the 'Conroller' position data
# D() =
$D_B_C.points[2] = $D_Controller.rect_position + Vector2( round($D_Controller.rect_size.x/2), round($D_Controller.rect_size.y/2) )
# Aligning the 'Angle_Text' to the left or right based on it's position to the 'B' position
if (D().x - B().x < 0):
# Left
$D_Controller_Text.rect_position = $D_Controller.rect_position + $D_Controller.rect_size/2 - $D_Controller_Text.rect_size/2 - Vector2($D_Controller_Text.rect_size.x*1.5, 0)
else:
# Right
$D_Controller_Text.rect_position = $D_Controller.rect_position + $D_Controller.rect_size/2 - $D_Controller_Text.rect_size/2 + Vector2($D_Controller_Text.rect_size.x*1.5, 0)
#--------------------------------------------------------------------------------#
#----- Changing the 'Angle_Text' values -----#
$A_B_D_Text_Director/A_B_D_Text_Director_Follow/A_B_D_Text.text = str(round(angle_calc(B(), A(), D())))
$A_B_D_Text_Director/A_B_D_Text_Director_Follow.unit_offset = .5 - (angle_calc(B(), A(), D())/2 + angle_calc(B(), D(), Vector2(0, B().y)))/360
#--------------------------------------------------------------------------------#
#----- Positioning the Cutter points. The cutter is for cutting the 'Angle_Indicator_Circle'.
$A_B_C_Cutter.polygon[2] = D()
$A_B_C_Cutter.polygon[1] = Vector2( (D().x + A().x)/2, (D().y + A().y)/2 - 500)
$A_B_C_Cutter2.polygon[2] = D()
#--------------------------------------------------------------------------------#
#----- Changing the 'Angle_Indicator' to be a 'Cirlce' or a 'Square'. If the angle is 90. Then 'Square', if the angle is not 90. Then 'Circle' ----#
# D()
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_C_Circle.visible = true
else:
$A_B_C_Circle.visible = false
if (round(angle_calc(B(), A(), C())) == 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_D_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_D_Cutter.z_index = -4
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_C_Cutter.z_index = -2
if (round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Square2.rotation_degrees = 225 - (angle_calc( B(), A(), D() ) / 2 + angle_calc( B(), D(), Vector2(1921, B().y) ) )
$A_B_C_Square2.visible = true
else:
$A_B_C_Square2.visible = false
#--------------------------------------------------------------------------------#
#----- If the Hide Buttons are pressed -----#
if A_B_C_Hide:
$A_B_D_Cutter.z_index = -1
$A_B_C_Square.visible = false
if A_B_D_Hide:
$A_B_C_Cutter.z_index = -1
$A_B_C_Square2.visible = false
#-------------------------------------------#
#----- A_Controller -----#
func _on_A_Controller_button_down():
A_Controller_start_position = $A_Controller.rect_position - get_local_mouse_position()
A_Controller_pressed = true
func _on_A_Controller_button_up():
A_Controller_pressed = false
#------------------------#
#----- C_Controller -----#
func _on_C_Controller_button_down():
C_Controller_start_position = $C_Controller.rect_position - get_local_mouse_position()
C_Controller_pressed = true
func _on_C_Controller_button_up():
C_Controller_pressed = false
#------------------------#
#----- D_Controller -----#
func _on_D_Controller_button_down():
D_Controller_start_position = $D_Controller.rect_position - get_local_mouse_position()
D_Controller_pressed = true
func _on_D_Controller_button_up():
D_Controller_pressed = false
#-----------------------#
#----- Hide_Buttons -----#
var A_B_C_Hide_toggled: bool = true
# Function for the 'A_B_C_Hide' button.
func _on_A_B_C_Hide_pressed():
if A_B_C_Hide_toggled:
A_B_C_Hide_toggled = false
$A_B_C_Text_Director/A_B_C_Text_Director_Follow/A_B_C_Text.visible = false
A_B_C_Hide = true
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_C_Circle.visible = true
else:
$A_B_C_Circle.visible = false
if (round(angle_calc(B(), A(), C())) == 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_D_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_D_Cutter.z_index = -4
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_C_Cutter.z_index = -2
if (round(angle_calc(B(), A(), C())) == 90):
$A_B_C_Square.rotation_degrees = 45 - (angle_calc( B(), A(), C() ) / 2 + angle_calc( B(), C(), Vector2(1921, B().y) ) )
$A_B_C_Square.visible = true
$A_B_C_Circle2.visible = false
else:
$A_B_C_Square.visible = false
$A_B_C_Circle2.visible = true
if (round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Square2.rotation_degrees = 225 - (angle_calc( B(), A(), D() ) / 2 + angle_calc( B(), D(), Vector2(1921, B().y) ) )
$A_B_C_Square2.visible = true
else:
$A_B_C_Square2.visible = false
if A_B_C_Hide:
$A_B_D_Cutter.z_index = -1
$A_B_C_Square.visible = false
if A_B_D_Hide:
$A_B_C_Cutter.z_index = -1
$A_B_C_Square2.visible = false
return
if !A_B_C_Hide_toggled:
A_B_C_Hide_toggled = true
$A_B_C_Text_Director/A_B_C_Text_Director_Follow/A_B_C_Text.visible = true
A_B_C_Hide = false
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_C_Circle.visible = true
else:
$A_B_C_Circle.visible = false
if (round(angle_calc(B(), A(), C())) == 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_D_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_D_Cutter.z_index = -4
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_C_Cutter.z_index = -2
if (round(angle_calc(B(), A(), C())) == 90):
$A_B_C_Square.rotation_degrees = 45 - (angle_calc( B(), A(), C() ) / 2 + angle_calc( B(), C(), Vector2(1921, B().y) ) )
$A_B_C_Square.visible = true
$A_B_C_Circle2.visible = false
else:
$A_B_C_Square.visible = false
$A_B_C_Circle2.visible = true
if (round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Square2.rotation_degrees = 225 - (angle_calc( B(), A(), D() ) / 2 + angle_calc( B(), D(), Vector2(1921, B().y) ) )
$A_B_C_Square2.visible = true
else:
$A_B_C_Square2.visible = false
if A_B_C_Hide:
$A_B_D_Cutter.z_index = -1
$A_B_C_Square.visible = false
if A_B_D_Hide:
$A_B_C_Cutter.z_index = -1
$A_B_C_Square2.visible = false
return
var A_B_D_Hide_toggled:bool = true
# Function for 'A_B_D_Hide' button
func _on_A_B_D_Hide_pressed():
if A_B_D_Hide_toggled:
A_B_D_Hide_toggled = false
$A_B_D_Text_Director/A_B_D_Text_Director_Follow/A_B_D_Text.visible = false
A_B_D_Hide = true
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_C_Circle.visible = true
else:
$A_B_C_Circle.visible = false
if (round(angle_calc(B(), A(), C())) == 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_D_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_D_Cutter.z_index = -4
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_C_Cutter.z_index = -2
if (round(angle_calc(B(), A(), C())) == 90):
$A_B_C_Square.rotation_degrees = 45 - (angle_calc( B(), A(), C() ) / 2 + angle_calc( B(), C(), Vector2(1921, B().y) ) )
$A_B_C_Square.visible = true
$A_B_C_Circle2.visible = false
else:
$A_B_C_Square.visible = false
$A_B_C_Circle2.visible = true
if (round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Square2.rotation_degrees = 225 - (angle_calc( B(), A(), D() ) / 2 + angle_calc( B(), D(), Vector2(1921, B().y) ) )
$A_B_C_Square2.visible = true
else:
$A_B_C_Square2.visible = false
if A_B_C_Hide:
$A_B_D_Cutter.z_index = -1
$A_B_C_Square.visible = false
if A_B_D_Hide:
$A_B_C_Cutter.z_index = -1
$A_B_C_Square2.visible = false
return
if !A_B_D_Hide_toggled:
A_B_D_Hide_toggled = true
$A_B_D_Text_Director/A_B_D_Text_Director_Follow/A_B_D_Text.visible = true
A_B_D_Hide = false
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_C_Circle.visible = true
else:
$A_B_C_Circle.visible = false
if (round(angle_calc(B(), A(), C())) == 90 and round(angle_calc(B(), A(), D())) != 90):
$A_B_D_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_D_Cutter.z_index = -4
if (round(angle_calc(B(), A(), C())) != 90 and round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Cutter.z_index = -1
$A_B_C_Circle.visible = true
else:
$A_B_C_Cutter.z_index = -2
if (round(angle_calc(B(), A(), C())) == 90):
$A_B_C_Square.rotation_degrees = 45 - (angle_calc( B(), A(), C() ) / 2 + angle_calc( B(), C(), Vector2(1921, B().y) ) )
$A_B_C_Square.visible = true
$A_B_C_Circle2.visible = false
else:
$A_B_C_Square.visible = false
$A_B_C_Circle2.visible = true
if (round(angle_calc(B(), A(), D())) == 90):
$A_B_C_Square2.rotation_degrees = 225 - (angle_calc( B(), A(), D() ) / 2 + angle_calc( B(), D(), Vector2(1921, B().y) ) )
$A_B_C_Square2.visible = true
else:
$A_B_C_Square2.visible = false
if A_B_C_Hide:
$A_B_D_Cutter.z_index = -1
$A_B_C_Square.visible = false
if A_B_D_Hide:
$A_B_C_Cutter.z_index = -1
$A_B_C_Square2.visible = false
return
#--------------------------------------------------------------------------------#
#-----'Restore_Button' to reset everything using the properties that were stored early in the _ready function. -----#
func _on_Restore_Button_pressed():
#----- Points -----#
$A_B.points[0] = A_loc
$D_B_C.points[0] = C_loc
$D_B_C.points[2] = D_loc
#------------------#
#----- Controllers -----#
$A_Controller.rect_position = A_Controller_loc
$C_Controller.rect_position = C_loc - $C_Controller.rect_size/2
$D_Controller.rect_position = D_loc - $D_Controller.rect_size/2
$A_Controller.rect_rotation = angle_calc(B(), A_loc, Vector2(0, B().y)) - 90
$C_Controller.rect_rotation = angle_calc(B(), C_loc, Vector2(0, B().y)) - 90
$D_Controller.rect_rotation = angle_calc(B(), D_loc, Vector2(0, B().y)) - 90
#-----------------------#
#----- Controller_Text -----#
$A_Controller_Text.rect_position = A_Controller_loc + $A_Controller.rect_size/2 - $A_Controller_Text.rect_size/2 + Vector2($A_Controller_Text.rect_size.x*1.5, 0)
$C_Controller_Text.rect_position = $C_Controller.rect_position + $C_Controller.rect_size/2 - $C_Controller_Text.rect_size/2 + Vector2($C_Controller_Text.rect_size.x*1.5, 0)
$D_Controller_Text.rect_position = D_Controller_loc + $D_Controller.rect_size/2 - $D_Controller_Text.rect_size/2 - Vector2($D_Controller_Text.rect_size.x*1.5, 0)
#---------------------------#
#----- Angle_Text -----#
$A_B_C_Text_Director/A_B_C_Text_Director_Follow.unit_offset = A_B_C_unite_offset
$A_B_D_Text_Director/A_B_D_Text_Director_Follow.unit_offset = A_B_D_unite_offset
$A_B_C_Text_Director/A_B_C_Text_Director_Follow/A_B_C_Text.text = '90'
$A_B_D_Text_Director/A_B_D_Text_Director_Follow/A_B_D_Text.text = '90'
$A_B_C_Text_Director/A_B_C_Text_Director_Follow/A_B_C_Text.visible = true
$A_B_D_Text_Director/A_B_D_Text_Director_Follow/A_B_D_Text.visible = true
#----------------------#
#----- Cutters -----#
$A_B_C_Cutter.polygon[0] = A_loc
$A_B_C_Cutter.polygon[2] = D_loc
$A_B_C_Cutter.polygon[1] = Vector2(D_loc.x, A_loc.y)
$A_B_D_Cutter.polygon[1] = A_loc
$A_B_D_Cutter.polygon[3] = C_loc
$A_B_D_Cutter.polygon[0] = Vector2(C_loc.x, A_loc.y)
$A_B_C_Cutter2.polygon[0] = C_loc
$A_B_C_Cutter2.polygon[2] = D_loc
$A_B_C_Cutter.z_index = A_B_C_Cutter_z_index
$A_B_C_Cutter2.z_index = A_B_C_Cutter2_z_index
$A_B_D_Cutter.z_index = A_B_D_Cutter_z_index
#-------------------#
#----- Squares -----#
$A_B_C_Square.rotation_degrees = 45 - (angle_calc( B(), A_loc, C_loc ) / 2 + angle_calc( B(), C_loc, Vector2(1921, B().y) ) )
$A_B_C_Square2.rotation_degrees = 225 - (angle_calc( B(), A_loc, D_loc ) / 2 + angle_calc( B(), D_loc, Vector2(1921, B().y) ) )
$A_B_C_Square.visible = true
$A_B_C_Square2.visible = true
#------------------#
#----- Circles -----#
$A_B_C_Circle.visible = false
$A_B_C_Circle2.visible = false
#-------------------#
#----- Hide_Buttons -----#
A_B_C_Hide_toggled = false
_on_A_B_C_Hide_pressed()
$A_B_C_Hide.pressed = false
A_B_D_Hide_toggled = false
_on_A_B_D_Hide_pressed()
$A_B_D_Hide.pressed = false
#------------------------#
#--------------------------------------------------------------------------------#