-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenu.java
More file actions
130 lines (115 loc) · 4.24 KB
/
Menu.java
File metadata and controls
130 lines (115 loc) · 4.24 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
package com.bc.memorytest;
import com.badlogic.gdx.Gdx;
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.Align;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.bc.memorytest.Globals.AppState;
/**
* Class to handle Main Menu logic.
*
* @author Bill Cassidy
*/
public class Menu
{
private final Label lblTitle;
private final Label lblMainMenu;
private final TextButton btnTrailMakingTest;
private final TextButton btnReactionTimeTest;
private final TextButton btnPairedAssociatesLearningTest;
private final TextButton btnOptions;
private final Table table;
private final Globals globals;
private final Stage stage;
/**
* Menu constructor. All class objects and variables are initialised here.
*
* @param globals
* An initialised Globals object.
*/
public Menu(final Globals globals)
{
this.globals = globals;
stage = new Stage();
// Create widgets.
lblTitle = new Label("MEMORY TEST", globals.skin);
lblTitle.setAlignment(Align.center);
lblMainMenu = new Label("Main Menu", globals.skin);
lblMainMenu.setAlignment(Align.center);
btnTrailMakingTest = new TextButton("Trail Making Test", globals.skin);
btnReactionTimeTest = new TextButton("Reaction Time Test", globals.skin);
btnPairedAssociatesLearningTest = new TextButton("Paired Associates Learning Test", globals.skin);
btnOptions = new TextButton("Options", globals.skin);
// Add listeners.
btnTrailMakingTest.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
globals.appState = AppState.TEST1;
}
});
btnReactionTimeTest.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
globals.appState = AppState.TEST2;
}
});
btnPairedAssociatesLearningTest.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
globals.appState = AppState.TEST3;
}
});
btnOptions.addListener(new ChangeListener()
{
public void changed(ChangeEvent event, Actor actor)
{
Gdx.input.setInputProcessor(null);
globals.appState = AppState.OPTIONS;
}
});
// Create table.
table = new Table(globals.skin);
table.setFillParent(true);
// table.setWidth(globals.resizeViewport.width);
// table.debug();
// Add widgets to table.
table.row().height(50);
table.add(lblTitle).width(700);
table.row().height(50);
table.add(lblMainMenu).width(700);
table.row().height(150);
table.add(btnTrailMakingTest).width(700);
table.row().height(150);
table.add(btnReactionTimeTest).width(700);
table.row().height(150);
table.add(btnPairedAssociatesLearningTest).width(700);
table.row().height(150);
table.add(btnOptions).width(700);
stage.addActor(table);
}
/** Release all resources used by objects that are disposable. */
public void Dispose()
{
stage.dispose();
}
/** Update method called once per frame. Updates all logic before each draw call. */
public void Update()
{
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
if (Gdx.input.getInputProcessor() == null)
Gdx.input.setInputProcessor(stage);
stage.act(Gdx.graphics.getDeltaTime());
}
/** Draw method, called once per frame after logic updates. */
public void Draw()
{
stage.draw();
// Table.drawDebug(stage);
}
}