-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest1.java
More file actions
1494 lines (1329 loc) · 60 KB
/
Test1.java
File metadata and controls
1494 lines (1329 loc) · 60 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
package com.bc.memorytest;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.bc.memorytest.Globals.AppState;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.badlogic.gdx.utils.StringBuilder;
/**
* Class to handle all Trail Making Test logic.
*
* @author Bill Cassidy
*/
public final class Test1 implements InputProcessor
{
private final Array<Sprite> numberSprites;
private final Array<Sprite> letterSprites;
private final Array<Sprite> numLetSprites; // alternating numbers & letters
private Array<Sprite> currentSprites;
private final Array<Vector2> positionsABSample;
private final Array<Vector2> positionsAFull;
private final Array<Vector2> positionsBFull;
private final Globals globals;
private final Sprite hand;
private State state;
private State nextState;
private State oldState;
private TestSize testSize;
private TestType testType;
private final Vector3 touchPos;
private int correctCirclesTouched;
private int currentlyTouchedCircle;
private final ShapeRenderer shapeRenderer;
private final Array<Vector2> drawPoints;
private int demoState;
private int handPosIndex;
private final Vector2 beginPos;
private final Vector2 endPos;
private final Vector2 handStartPos;
private final Vector2 handCurrentPos;
private final Vector2 handEndPos;
private final int handOffsetX;
private final int handOffsetY;
private final Tween tween;
private Vector2 vect2A; // re-usable Vector2
private Vector2 vect2B; // re-usable Vector2
private final int demoPointOffset;
private final Stage stage;
private final Label lblTrailMaking;
private final Label lblTestComplete;
private final TextButton btnMainMenu;
private final TextButton btnDemoA;
private final TextButton btnDemoB;
private final TextButton btnPartASample;
private final TextButton btnPartAFull;
private final TextButton btnPartBSample;
private final TextButton btnPartBFull;
private final Table tblMenu;
private final Table tblTestComplete;
private final TextButton btnBackToTrailMakingMenu;
private float handWidth;
private float handHeight;
private float waitElapsed;
private final float waitInterval;
private final String demoAInstructions;
private final String demoBInstructions;
private final String partASampleInstructions;
private final String partAFullInstructions;
private final String partBSampleInstructions;
private final String partBFullInstructions;
private final String strBegin;
private final String strEnd;
private final String reason1ErrorMsg;
private final String reason2ErrorMsg;
private final String reason3ErrorMsg;
private final String reason4ErrorMsg;
private final String testCompleteMsg1;
private final String testCompleteMsg2;
private final String testCompleteMsg3;
private final String testCompleteMsg4;
private final String strFileName;
private final String strQuote;
private final String strQuoteStop;
private final String strDemoComplete;
private final StringBuilder sbErrorMsg;
private float handInterval;
private float handElapsed;
private long dateTime;
private float timer;
private float finalTestTime;
public String[] testTypes;
public int testTypeTakenIndex;
private int reason1ErrorCount;
private int reason2ErrorCount;
private int reason3ErrorCount;
private int reason4ErrorCount;
private boolean testStarted;
private final String[] typeBChars;
private int lastCorrectCircleTouched;
private int lastIncorrectCircleTouched;
private int nextCorrectCircle;
//private boolean doDrawPoints;
private boolean firstCircleTouched;
private boolean touchErrorFlag;
private final float beginStringPosXOffset;
private final float beginStringPosYOffset;
private final float endStringPosXOffset;
private final float endStringPosYOffset;
private final int maxDrawPoints;
private int drawPointsCounter;
/** Enumerator used to indicate the test type. */
private enum TestType
{
TEST_A_SAMPLE,
TEST_A_FULL,
TEST_B_SAMPLE,
TEST_B_FULL
}
/** Enumerator used to indicate the number of circles the test type requires. */
private enum TestSize
{
SAMPLE(8), //8 circles
FULL(25); //25 circles
private final int val;
private TestSize(int v) { val = v; }
public int getVal() { return val; }
}
/** Enumerator used to indicate the state of the test. */
private enum State
{
MENU,
DEMO,
TEST_A_SAMPLE,
TEST_A_FULL,
TEST_B_SAMPLE,
TEST_B_FULL,
WAIT,
TEST_COMPLETE,
TEST_ERROR,
SAVE,
END
}
/** Enumerator used to indicate the type of touch event that has occured. */
private enum TouchType
{
TOUCH_DOWN,
DRAG
}
/**
* Test1 constructor. All class objects and variables are initialised here.
*
* @param globals
* An initialised Globals object.
*
* @param shapeRenderer
* An initialised ShapeRenderer object.
*/
public Test1(final Globals globals, ShapeRenderer shapeRenderer)
{
this.globals = globals;
this.shapeRenderer = shapeRenderer;
stage = new Stage();
// Test type codes used for save file.
testTypes = new String[4];
testTypes[0] = "AS"; // Part A Sample.
testTypes[1] = "AF"; // Part A Full.
testTypes[2] = "BS"; // Part B Sample.
testTypes[3] = "BF"; // Part B Full.
drawPoints = new Array<Vector2>();
numberSprites = new Array<Sprite>();
letterSprites = new Array<Sprite>();
numLetSprites = new Array<Sprite>();
currentSprites = new Array<Sprite>();
// Set positions for sample tests (A & B).
float yOffset = 135;
positionsABSample = new Array<Vector2>();
positionsABSample.add(new Vector2(587, 408 + yOffset)); // 1 | 1
positionsABSample.add(new Vector2(720, 222 + yOffset)); // 2 | A
positionsABSample.add(new Vector2(852, 385 + yOffset)); // 3 | 2
positionsABSample.add(new Vector2(719, 384 + yOffset)); // 4 | B
positionsABSample.add(new Vector2(746, 546 + yOffset)); // 5 | 3
positionsABSample.add(new Vector2(285, 488 + yOffset)); // 6 | C
positionsABSample.add(new Vector2(339, 263 + yOffset)); // 7 | 4
positionsABSample.add(new Vector2(525, 211 + yOffset)); // 8 | D
// Set positions for Part A full test.
positionsAFull = new Array<Vector2>();
positionsAFull.add(new Vector2(780, 223 + yOffset)); // 1
positionsAFull.add(new Vector2(885, 394 + yOffset)); // 2
positionsAFull.add(new Vector2(989, 204 + yOffset)); // 3
positionsAFull.add(new Vector2(584, 139 + yOffset)); // 4
positionsAFull.add(new Vector2(620, 434 + yOffset)); // 5
positionsAFull.add(new Vector2(695, 312 + yOffset)); // 6
positionsAFull.add(new Vector2(780, 509 + yOffset)); // 7
positionsAFull.add(new Vector2(932, 610 + yOffset)); // 8
positionsAFull.add(new Vector2(1070, 550 + yOffset)); // 9
positionsAFull.add(new Vector2(950, 497 + yOffset)); // 10
positionsAFull.add(new Vector2(1185, 272 + yOffset)); // 11
positionsAFull.add(new Vector2(1204, 689 + yOffset)); // 12
positionsAFull.add(new Vector2(634, 645 + yOffset)); // 13
positionsAFull.add(new Vector2(822, 730 + yOffset)); // 14
positionsAFull.add(new Vector2(62, 725 + yOffset)); // 15
positionsAFull.add(new Vector2(290, 610 + yOffset)); // 16
positionsAFull.add(new Vector2(5, 359 + yOffset)); // 17
positionsAFull.add(new Vector2(369, 384 + yOffset)); // 18
positionsAFull.add(new Vector2(244, 142 + yOffset)); // 19
positionsAFull.add(new Vector2(170, 265 + yOffset)); // 20
positionsAFull.add(new Vector2(77, 44 + yOffset)); // 21
positionsAFull.add(new Vector2(480, 39 + yOffset)); // 22
positionsAFull.add(new Vector2(1020, 25 + yOffset)); // 23
positionsAFull.add(new Vector2(885, 104 + yOffset)); // 24
positionsAFull.add(new Vector2(1157, 141 + yOffset)); // 25
// Set positions for Part B full test.
positionsBFull = new Array<Vector2>();
positionsBFull.add(new Vector2(498, 420 + yOffset)); // 1
positionsBFull.add(new Vector2(770, 305 + yOffset)); // A
positionsBFull.add(new Vector2(836, 511 + yOffset)); // 2
positionsBFull.add(new Vector2(287, 487 + yOffset)); // B
positionsBFull.add(new Vector2(379, 399 + yOffset)); // 3
positionsBFull.add(new Vector2(518, 301 + yOffset)); // C
positionsBFull.add(new Vector2(262, 333 + yOffset)); // 4
positionsBFull.add(new Vector2(257, 131 + yOffset)); // D
positionsBFull.add(new Vector2(480, 133 + yOffset)); // 5
positionsBFull.add(new Vector2(960, 147 + yOffset)); // E
positionsBFull.add(new Vector2(939, 373 + yOffset)); // 6
positionsBFull.add(new Vector2(995, 553 + yOffset)); // F
positionsBFull.add(new Vector2(484, 600 + yOffset)); // 7
positionsBFull.add(new Vector2(300, 730 + yOffset)); // G
positionsBFull.add(new Vector2(70, 704 + yOffset)); // 8
positionsBFull.add(new Vector2(277, 625 + yOffset)); // H
positionsBFull.add(new Vector2(108, 540 + yOffset)); // 9
positionsBFull.add(new Vector2(142, 276 + yOffset)); // I
positionsBFull.add(new Vector2(46, 43 + yOffset)); // 10
positionsBFull.add(new Vector2(790, 34 + yOffset)); // J
positionsBFull.add(new Vector2(1185, 56 + yOffset)); // 11
positionsBFull.add(new Vector2(1203, 730 + yOffset)); // K
positionsBFull.add(new Vector2(904, 680 + yOffset)); // 12
positionsBFull.add(new Vector2(619, 731 + yOffset)); // L
positionsBFull.add(new Vector2(420, 730 + yOffset)); // 13
// Set characters used for displaying errors to examinee.
typeBChars = new String[positionsBFull.size];
typeBChars[0] = "1";
typeBChars[1] = "A";
typeBChars[2] = "2";
typeBChars[3] = "B";
typeBChars[4] = "3";
typeBChars[5] = "C";
typeBChars[6] = "4";
typeBChars[7] = "D";
typeBChars[8] = "5";
typeBChars[9] = "E";
typeBChars[10] = "6";
typeBChars[11] = "F";
typeBChars[12] = "7";
typeBChars[13] = "G";
typeBChars[14] = "8";
typeBChars[15] = "H";
typeBChars[16] = "9";
typeBChars[17] = "I";
typeBChars[18] = "10";
typeBChars[19] = "J";
typeBChars[20] = "11";
typeBChars[21] = "K";
typeBChars[22] = "12";
typeBChars[23] = "L";
typeBChars[24] = "13";
beginPos = new Vector2(0, 0);
endPos = new Vector2(0, 0);
touchPos = new Vector3(0, 0, 0);
handStartPos = new Vector2(0, 0);
handCurrentPos = new Vector2(0, 0);
handEndPos = new Vector2(0, 0);
vect2A = new Vector2(0, 0);
vect2B = new Vector2(0, 0);
handOffsetX = 116;
handOffsetY = 20;
tween = new Tween(2);
demoPointOffset = 150;
waitInterval = 0.35f;
handInterval = 0.89f;
sbErrorMsg = new StringBuilder();
maxDrawPoints = 10000;
beginStringPosXOffset = 8;
beginStringPosYOffset = 34;
endStringPosXOffset = 5;
endStringPosYOffset = 34;
// Set Sprites for letters.
int count = 12;
for (int i = 0; i < count; i++)
{
letterSprites.add(new Sprite(globals.spritesAtlas.createSprite("Circle" + (char)(65 + i))));
letterSprites.get(i).setSize(70, 70);
letterSprites.get(i).flip(false, true);
letterSprites.get(i).getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
// Set Sprites for numbers.
count = 25;
for (int i = 0; i < count; i++)
{
numberSprites.add(new Sprite(globals.spritesAtlas.createSprite("Circle" + (i + 1))));
numberSprites.get(i).setSize(70, 70);
numberSprites.get(i).flip(false, true);
numberSprites.get(i).getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
// Set Sprites for numbers & letters.
for (int i = 0; i < count; i++)
{
numLetSprites.add(new Sprite(globals.spritesAtlas.createSprite("Circle" + (i + 1))));
if (i < 12)
numLetSprites.add(new Sprite(globals.spritesAtlas.createSprite("Circle" + (char)(65 + i))));
}
// Sprites are loaded upside down, so flip them all. Set linear filter so scaling across screen sizes is smooth.
for (Sprite sprite : numLetSprites)
{
sprite.flip(false, true);
sprite.setSize(70, 70);
sprite.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
// Set demo hand Sprite.
hand = new Sprite(globals.spritesAtlas.createSprite("Hand"));
hand.flip(false, true);
hand.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
// Create widgets.
lblTrailMaking = new Label("Trail Making Menu", globals.skin);
lblTrailMaking.setAlignment(Align.center);
btnDemoA = new TextButton("Watch Part A Demo", globals.skin);
btnDemoB = new TextButton("Watch Part B Demo", globals.skin);
btnPartASample = new TextButton("Part A Sample", globals.skin);
btnPartAFull = new TextButton("Part A Full", globals.skin);
btnPartBSample = new TextButton("Part B Sample", globals.skin);
btnPartBFull = new TextButton("Part B Full", globals.skin);
btnMainMenu = new TextButton("Main Menu", globals.skin);
btnBackToTrailMakingMenu = new TextButton("Back to Trail Making Menu", globals.skin);
lblTestComplete = new Label("", globals.skin);
lblTestComplete.setAlignment(Align.center);
testCompleteMsg1 = "Thank you, part A sample test completed.";
testCompleteMsg2 = "Thank you, part A test completed.";
testCompleteMsg3 = "Thank you, part B sample test completed.";
testCompleteMsg4 = "Thank you, part B test completed.";
reason1ErrorMsg = "You started with the wrong circle.\nYou must start at the circle marked '1'.";
reason2ErrorMsg = "The last circle touched was not the next in sequence.\nContinue from circle marked ";
reason3ErrorMsg = "Please keep the pen on the screen, and continue from circle marked ";
reason4ErrorMsg = "No circle touched. Continue from circle marked ";
strBegin = "Begin";
strEnd = "End";
strFileName = "tmt.csv";
strQuote = "'";
strQuoteStop = "'.";
strDemoComplete = "Demonstration completed. Tap screen to return to menu.";
// Create Menu table.
tblMenu = new Table(globals.skin);
tblMenu.setFillParent(true);
// Create Test Complete table.
tblTestComplete = new Table(globals.skin);
tblTestComplete.setFillParent(true);
demoAInstructions =
"You are about to view a demonstration that will show you how\n" +
"to complete the Part A tests. On the screen you will see some\n" +
"circles with numbers in them. You will see a hand drawing a line\n"+
"between the circles. The hand starts at the circle marked 1,\n" +
"and moves between each circle in numerical order. The correct\n" +
"order is 1 to 2, 2 to 3, 3 to 4, and so on. The demo ends when\n" +
"all circles have been touched in the correct order.\n\n" +
"Don't worry if you don't understand how the test works at first.\n" +
"You will be able to watch the demonstration as many times as you\n" +
"want before starting the actual tests.";
demoBInstructions =
"You will now view a demonstration that will show you how to\n" +
"complete the Part B tests. On the screen you will see some\n" +
"circles with numbers and letters in them. You will see a hand\n" +
"drawing a line between the circles. The finger starts at the circle\n" +
"marked 1, and moves between each circle in the following order:\n" +
"1 to A, A to 2, 2 to B, B to 3, 3 to C, and so on. The demo ends\n" +
"when all circles have been touched in the correct order.\n\n" +
"Don't worry if you don't understand how the test works at first.\n" +
"You will be able to watch the demonstration as many times as you\n" +
"want before starting the actual tests.";
partASampleInstructions =
"When the sample test starts, you will be shown some circles with\n" +
"numbers in them. Begin at number 1 and draw a line from 1 to 2,\n" +
"2 to 3, 3 to 4, and so on, in order, until you reach the end (the\n" +
"circle marked 'END').\n\n"+
"Draw the lines as fast as you can. Do not lift the pen from the\n" +
"screen. If you make a mistake, a message will appear at the bottom\n" +
"of the screen telling you what you did wrong and how to continue.";
partAFullInstructions =
"On this test are numbers from 1 to 25. Do this test the same way\n" +
"as the sample test you have just completed. Begin at number 1 and\n" +
"draw a line from 1 to 2, 2 to 3, 3 to 4, and so on, in order until\n" +
"you reach the end. Remember, work as fast as you can.";
partBSampleInstructions =
"In this test there are some numbers and letters. Begin at number 1 and\n" +
"draw a line from 1 to A, A to 2, 2 to B, B to 3, 3 to C, and so on,\n" +
"in order until you reach the end. Remember, first you have a number\n" +
"(1) then a letter (A), then a number (2), then a letter (B), and so\n" +
"on. Draw the lines as fast as you can.";
partBFullInstructions =
"In this final test there are both numbers and letters. Do this test\n" +
"the same way as the previous sample test. Begin at number 1 and draw\n" +
"a line from 1 to A, A to 2, 2 to B, B to 3, 3 to C, and so on, in\n" +
"order, until you reach the end (the circle marked 'END')\n\n" +
"Remember, first you have a number (1), then a letter (B), and so on.\n" +
"Do not skip around, but go from one circle to the next in the proper\n" +
"order. Draw the lines as fast as you can.";
// Add listeners.
btnDemoA.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
new Dialog("Demonstration Part A Instructions", globals.skin, "dialog")
{
protected void result (Object object)
{
//System.out.println("Chosen: " + object);
if (object.equals(true))
SetTestType(TestType.TEST_A_SAMPLE, true);
}
}.text(demoAInstructions)
.button("Cancel", false)
.button("Start Demo", true)
.show(stage);
}
});
btnDemoB.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
new Dialog("Demonstration Part B Instructions", globals.skin, "dialog")
{
protected void result (Object object)
{
//System.out.println("Chosen: " + object);
if (object.equals(true))
SetTestType(TestType.TEST_B_SAMPLE, true);
}
}.text(demoBInstructions)
.button("Cancel", false)
.button("Start Demo", true)
.show(stage);
}
});
btnPartASample.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
new Dialog("Part A Sample Instructions", globals.skin, "dialog")
{
protected void result (Object object)
{
//System.out.println("Chosen: " + object);
if (object.equals(true))
SetTestType(TestType.TEST_A_SAMPLE, false);
}
}.text(partASampleInstructions)
.button("Cancel", false)
.button("Start Part A Sample", true)
.show(stage);
}
});
btnPartAFull.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
new Dialog("Part A Instructions", globals.skin, "dialog")
{
protected void result (Object object)
{
//System.out.println("Chosen: " + object);
if (object.equals(true))
SetTestType(TestType.TEST_A_FULL, false);
}
}.text(partAFullInstructions)
.button("Cancel", false)
.button("Start Part A", true)
.show(stage);
}
});
btnPartBSample.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
new Dialog("Part B Sample Instructions", globals.skin, "dialog")
{
protected void result (Object object)
{
//System.out.println("Chosen: " + object);
if (object.equals(true))
SetTestType(TestType.TEST_B_SAMPLE, false);
}
}.text(partBSampleInstructions)
.button("Cancel", false)
.button("Start Part B Sample", true)
.show(stage);
}
});
btnPartBFull.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
new Dialog("Part B Instructions", globals.skin, "dialog")
{
protected void result (Object object)
{
//System.out.println("Chosen: " + object);
if (object.equals(true))
SetTestType(TestType.TEST_B_FULL, false);
}
}.text(partBFullInstructions)
.button("Cancel", false)
.button("Start Part B", true)
.show(stage);
}
});
btnMainMenu.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
Gdx.input.setInputProcessor(null);
state = null;
globals.appState = AppState.MENU;
}
});
btnBackToTrailMakingMenu.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
Setup();
}
});
}
/** Release all resources used by objects that are disposable. */
public void Dispose()
{
stage.dispose();
}
/** Method to setup a stage when menus are being displayed. The state should be set before calling this method.
*
* @param actor
* An initialised Table object.
*/
private void SetStage(Table table)
{
tblMenu.clear();
tblTestComplete.clear();
// Add relevant widgets to table.
switch (state)
{
case MENU: // Add widgets to Menu table.
tblMenu.row().height(150).colspan(2);
tblMenu.add(lblTrailMaking).width(1000);
tblMenu.row().height(150);
tblMenu.add(btnDemoA).width(500);
tblMenu.add(btnDemoB).width(500);
tblMenu.row().height(150);
tblMenu.add(btnPartASample).width(500);
tblMenu.add(btnPartBSample).width(500);
tblMenu.row().height(150);
tblMenu.add(btnPartAFull).width(500);
tblMenu.add(btnPartBFull).width(500);
tblMenu.row().height(150).colspan(2);
tblMenu.add(btnMainMenu).width(1000);
break;
case TEST_COMPLETE: // Add widgets to Test Complete table.
tblTestComplete.row().height(90);
tblTestComplete.add(lblTestComplete).width(700);
tblTestComplete.row().height(150);
tblTestComplete.add(btnBackToTrailMakingMenu).width(700);
break;
}
// Setup stage.
stage.clear();
stage.addActor(table);
Gdx.input.setInputProcessor(stage);
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
/** Reset states and variables. To be called before Menu is shown. */
private void Setup()
{
state = State.MENU;
correctCirclesTouched = 0;
currentlyTouchedCircle = 0;
shapeRenderer.setColor(Color.BLACK);
demoState = 1;
SetStage(tblMenu);
//drawPoints.size = 0;
hand.setPosition(2000, 2000);
Gdx.input.setInputProcessor(stage);
waitElapsed = 0;
nextCorrectCircle = 0;
lastCorrectCircleTouched = -1;
//doDrawPoints = false;
firstCircleTouched = false;
touchErrorFlag = true;
globals.doScreenshot = false;
}
/** Sets the sprites and menu state for the selected test type.
*
* @param testType
* A valid TestType enum value indicating the type of test that will be shown.
*
* @param isDemo
* Boolean indicating if the next State should be set to DEMO.
*/
private void SetTestType(TestType testType, boolean isDemo)
{
this.testType = testType;
SetPositions(testType);
globals.Resize();
waitElapsed = 0;
handElapsed = 0;
handInterval = 0.89f;
reason1ErrorCount = 0;
reason2ErrorCount = 0;
reason3ErrorCount = 0;
reason4ErrorCount = 0;
testStarted = false;
drawPoints.clear();
// Pre-fill drawPoints array so we don't need to create a new Vector2 every time a new draw point is added.
for (int i = 0; i < maxDrawPoints; i++)
{
drawPoints.add(new Vector2(-1, -1));
}
drawPointsCounter = 0;
if (isDemo)
state = State.DEMO;
switch (testType)
{
case TEST_A_SAMPLE:
testTypeTakenIndex = 0;
currentSprites = numberSprites;
if (!isDemo)
state = State.TEST_A_SAMPLE;
break;
case TEST_A_FULL:
testTypeTakenIndex = 1;
currentSprites = numberSprites;
if (!isDemo)
state = State.TEST_A_FULL;
break;
case TEST_B_SAMPLE:
testTypeTakenIndex = 2;
currentSprites = numLetSprites;
if (!isDemo)
state = State.TEST_B_SAMPLE;
break;
case TEST_B_FULL:
testTypeTakenIndex = 3;
currentSprites = numLetSprites;
if (!isDemo)
state = State.TEST_B_FULL;
break;
}
SetBEStringPos(testType);
for (Sprite sprite : currentSprites)
sprite.setColor(1, 1, 1, 1);
if (!isDemo)
{
Gdx.input.setInputProcessor(this);
}
dateTime = System.currentTimeMillis(); // Calendar.getInstance().getTimeInMillis();
}
/**
* Set the positions of the Begin & End strings.
*
* @param testType
* A valid TestType enum value indicating the type of test that will be shown.
*/
private void SetBEStringPos(TestType testType)
{
switch (testType)
{
case TEST_A_SAMPLE:
case TEST_B_SAMPLE:
beginPos.x = positionsABSample.get(0).x - beginStringPosXOffset;
beginPos.y = positionsABSample.get(0).y - beginStringPosYOffset;
endPos.x = positionsABSample.get(positionsABSample.size - 1).x + endStringPosXOffset;
endPos.y = positionsABSample.get(positionsABSample.size - 1).y - endStringPosYOffset;
break;
case TEST_A_FULL:
beginPos.x = positionsAFull.get(0).x - beginStringPosXOffset;
beginPos.y = positionsAFull.get(0).y - beginStringPosYOffset;
endPos.x = positionsAFull.get(positionsAFull.size - 1).x + endStringPosXOffset;
endPos.y = positionsAFull.get(positionsAFull.size - 1).y - endStringPosYOffset;
break;
case TEST_B_FULL:
beginPos.x = positionsBFull.get(0).x - beginStringPosXOffset;
beginPos.y = positionsBFull.get(0).y - beginStringPosYOffset;
endPos.x = positionsBFull.get(positionsBFull.size - 1).x + endStringPosXOffset;
endPos.y = positionsBFull.get(positionsBFull.size - 1).y - endStringPosYOffset;
break;
}
}
/**
* Set the circle Sprite positions for each test type.
*
* @param testType
* TestType enumerator value indicating the type of test used.
*/
private void SetPositions(TestType testType)
{
switch (testType)
{
case TEST_A_SAMPLE:
testSize = TestSize.SAMPLE;
for (int i = 0; i < TestSize.SAMPLE.getVal(); i++)
numberSprites.get(i).setPosition(positionsABSample.get(i).x, positionsABSample.get(i).y);
break;
case TEST_A_FULL:
testSize = TestSize.FULL;
for (int i = 0; i < TestSize.FULL.getVal(); i++)
numberSprites.get(i).setPosition(positionsAFull.get(i).x, positionsAFull.get(i).y);
break;
case TEST_B_SAMPLE:
testSize = TestSize.SAMPLE;
for (int i = 0; i < TestSize.SAMPLE.getVal(); i++)
numLetSprites.get(i).setPosition(positionsABSample.get(i).x, positionsABSample.get(i).y);
break;
case TEST_B_FULL:
testSize = TestSize.FULL;
for (int i = 0; i < TestSize.FULL.getVal(); i++)
numLetSprites.get(i).setPosition(positionsBFull.get(i).x, positionsBFull.get(i).y);
break;
}
}
/** Update method called once per frame. Updates all logic before each draw call. */
public void Update()
{
if (state == null)
Setup();
if (Gdx.input.getInputProcessor() == null)
Gdx.input.setInputProcessor(stage);
switch (state)
{
case MENU:
stage.act(Gdx.graphics.getDeltaTime());
break;
case DEMO: // Display a demonstration showing how to do the test.
if (Gdx.input.isTouched())
Setup();
PlotPoints();
switch (demoState)
{
case 1: // Initialise...
handPosIndex = 0;
handWidth = 630;
handHeight = 891;
hand.setSize(handWidth, handHeight);
demoState = 2;
break;
case 2: // Scale hand sprite towards first circle.
handWidth -= 2.90f;
handHeight -= 2.90f;
hand.setSize(handWidth, handHeight);
hand.setPosition(
currentSprites.get(handPosIndex).getX() - handOffsetX,
currentSprites.get(handPosIndex).getY() + handOffsetY);
if (handWidth <= 420)
demoState = 3;
break;
case 3: // Set Start & End position vectors.
handStartPos.x = currentSprites.get(handPosIndex).getX() - handOffsetX;
handStartPos.y = currentSprites.get(handPosIndex).getY() + handOffsetY;
hand.setPosition(handStartPos.x, handStartPos.y);
handEndPos.x = currentSprites.get(handPosIndex + 1).getX() - handOffsetX;
handEndPos.y = currentSprites.get(handPosIndex + 1).getY() + handOffsetY;
tween.time = 0;
demoState = 4;
currentSprites.get(handPosIndex).setColor(180, 233, 252, 0.10f);
break;
case 4: // Pause hand for "handInterval" seconds.
handElapsed += Gdx.graphics.getDeltaTime();
if (handElapsed > handInterval)
{
handElapsed = 0;
demoState = 5;
handInterval = 0.05f;
}
break;
case 5: // Move hand from current "Start" to "End" point.
handCurrentPos.x = tween.apply(handStartPos.x, handEndPos.x, Interpolation.fade);
handCurrentPos.y = tween.apply(handStartPos.y, handEndPos.y, Interpolation.fade);
tween.update(Gdx.graphics.getDeltaTime());
hand.setPosition(handCurrentPos.x, handCurrentPos.y);
//drawPoints.add(new Vector2(handCurrentPos.x + demoPointOffset, handCurrentPos.y));
if (drawPointsCounter < maxDrawPoints)
{
drawPoints.get(drawPointsCounter).x = handCurrentPos.x + demoPointOffset;
drawPoints.get(drawPointsCounter).y = handCurrentPos.y;
drawPointsCounter++;
}
// Repeat sequence until all points have been traversed.
if (handPosIndex == testSize.getVal() - 1)
{
demoState = 6; // display demo complete message
}
else
{
if (handCurrentPos.x == handEndPos.x && handCurrentPos.y == handEndPos.y)
{
currentSprites.get(handPosIndex).setColor(180, 233, 252, 0.10f);
handPosIndex++;
demoState = 3;
}
}
break;
}
break;
case TEST_A_SAMPLE: // Running sample test using just numbers.
case TEST_A_FULL: // Running full test using just numbers.
case TEST_B_SAMPLE: // Running sample test using alphbetical letters & numbers.
case TEST_B_FULL: // Running full test using alphbetical letters & numbers.
case TEST_ERROR:
PlotPoints();
timer += Gdx.graphics.getDeltaTime();
break;
case WAIT: // Test completed or failed, pause for "waitInterval" seconds then proceed to appropriate State.
timer += Gdx.graphics.getDeltaTime();
PlotPoints();
waitElapsed += Gdx.graphics.getDeltaTime();
if (waitElapsed > waitInterval)
{
waitElapsed = 0;
if (nextState == State.TEST_COMPLETE)
{
switch (testType)
{
case TEST_A_SAMPLE:
lblTestComplete.setText(testCompleteMsg1);
break;
case TEST_A_FULL:
lblTestComplete.setText(testCompleteMsg2);
break;
case TEST_B_SAMPLE:
lblTestComplete.setText(testCompleteMsg3);
break;
case TEST_B_FULL:
lblTestComplete.setText(testCompleteMsg4);
break;
}
finalTestTime = timer;
state = State.SAVE;
Save();
globals.doScreenshot = true;
state = State.SAVE;
//state = State.TEST_COMPLETE;
//SetStage(tblTestComplete);
}
else if (nextState == State.TEST_ERROR)
{
state = State.TEST_ERROR;
//SetStage(tblTestFailed);
//lblFailedReason.setText(failedReasonStrings[failedReasonIndex]);
}
}
break;
case SAVE:
state = State.END;
break;
case END:
state = State.TEST_COMPLETE;
SetStage(tblTestComplete);
break;
}
}
/** Plot all user-painted lines. */
private void PlotPoints()
{
shapeRenderer.begin(ShapeType.Line);
//int count = drawPoints.size - 1;
for (int i = 0; i < drawPointsCounter - 1; i++)
{
vect2A = drawPoints.get(i);
vect2B = drawPoints.get(i + 1);
// Skip to next point if there's a break (specified by -1).
if (vect2A.x == -1 || vect2B.x == -1)
continue;
shapeRenderer.line(vect2A.x, vect2A.y, vect2B.x, vect2B.y);