-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuiController.java
50 lines (43 loc) · 1.44 KB
/
GuiController.java
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
import Game.*;
import com.trolltech.qt.QSignalEmitter;
import GUI.Signals;
import com.trolltech.qt.gui.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.LinkedList;
public class GuiController extends QSignalEmitter implements Controller{
/*Emit when file->save is invoked*/
private Signals signals = new Signals();
private Game.Controller gameController = new Game.Controller();
private QMainWindow mainWin;
public GuiController(){
String[] args = new String[0];
QApplication app = new QApplication(args);
setupGui(); signals.saveGame.connect(this, "saveGame()");
signals.exitApplication.connect(app, "exit()"); app.exec();
this.setupGui();
}
private void setupGui(){
mainWin = new QMainWindow();
QWidget centralWidget = new QWidget(mainWin);
mainWin.setCentralWidget(centralWidget);
setupMenuBar();
mainWin.show();
}
private void setupMenuBar(){
QMenuBar menuBar = new QMenuBar(mainWin);
QMenu fileMenu = new QMenu("File");
menuBar.addMenu(fileMenu);
fileMenu.addAction("Save", signals.saveGame);
fileMenu.addAction("Exit", signals.exitApplication);
mainWin.setMenuBar(menuBar);
}
@Override
public void startGame(){
}
public void saveGame(){
Persistence.saveMoves(gameController.getMoves());
}
}