add view controls
parent
f3cd880c9e
commit
b44d2e636f
|
|
@ -30,12 +30,14 @@ public class ButtonMovePieceListener implements ActionListener {
|
||||||
if (this.game.isDraw()) {
|
if (this.game.isDraw()) {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
this.sf.setViewPointer(this.game.getMoveList().size() - 1);
|
this.game.setViewPointer(this.game.getMoveList().size() - 1);
|
||||||
|
this.sf.enableControlPanelButtons();
|
||||||
this.sf.showDraw();
|
this.sf.showDraw();
|
||||||
} else if (this.game.isMate()) {
|
} else if (this.game.isMate()) {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
this.sf.setViewPointer(this.game.getMoveList().size() - 1);
|
this.game.setViewPointer(this.game.getMoveList().size() - 1);
|
||||||
|
this.sf.enableControlPanelButtons();
|
||||||
this.sf.showWin(game.getActivePlayer());
|
this.sf.showWin(game.getActivePlayer());
|
||||||
} else {
|
} else {
|
||||||
this.sf.setBoardMode(BoardMode.normal);
|
this.sf.setBoardMode(BoardMode.normal);
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,26 @@ import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
public class ButtonViewBackListener implements ActionListener {
|
public class ButtonViewBackListener implements ActionListener {
|
||||||
private Game game;
|
private Game game;
|
||||||
|
private SpielFrame sf;
|
||||||
|
|
||||||
public ButtonViewBackListener(Game game) {
|
public ButtonViewBackListener(Game game, SpielFrame sf) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
this.sf = sf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
this.game.setViewPointer(this.game.getViewPointer() - 1);
|
if (this.game.getViewPointer() > 0) {
|
||||||
// TODO Auto-generated method stub
|
this.game.setViewPointer(this.game.getViewPointer() - 1);
|
||||||
|
this.game.loadView();
|
||||||
|
this.sf.setDefaultButtons();
|
||||||
|
this.sf.applyBoardButtons();
|
||||||
|
this.sf.ladeBrett();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,24 @@ import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
public class ButtonViewFirstListener implements ActionListener {
|
public class ButtonViewFirstListener implements ActionListener {
|
||||||
private Game game;
|
private Game game;
|
||||||
|
private SpielFrame sf;
|
||||||
|
|
||||||
public ButtonViewFirstListener(Game game) {
|
public ButtonViewFirstListener(Game game, SpielFrame sf) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
this.sf = sf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
this.game.setViewPointer(0);
|
this.game.setViewPointer(0);
|
||||||
// TODO Auto-generated method stub
|
this.game.loadView();
|
||||||
|
this.sf.setDefaultButtons();
|
||||||
|
this.sf.applyBoardButtons();
|
||||||
|
this.sf.ladeBrett();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,26 @@ import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
public class ButtonViewForwardListener implements ActionListener {
|
public class ButtonViewForwardListener implements ActionListener {
|
||||||
private Game game;
|
private Game game;
|
||||||
|
private SpielFrame sf;
|
||||||
|
|
||||||
public ButtonViewForwardListener(Game game) {
|
public ButtonViewForwardListener(Game game, SpielFrame sf) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
this.sf = sf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
this.game.setViewPointer(this.game.getViewPointer() + 1);
|
if (this.game.getMoveList().size() > this.game.getViewPointer()) {
|
||||||
// TODO Auto-generated method stub
|
this.game.setViewPointer(this.game.getViewPointer() + 1);
|
||||||
|
this.game.loadView();
|
||||||
|
this.sf.setDefaultButtons();
|
||||||
|
this.sf.applyBoardButtons();
|
||||||
|
this.sf.ladeBrett();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,24 @@ import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import de.mannheim.th.chess.domain.Game;
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
public class ButtonViewLastListener implements ActionListener {
|
public class ButtonViewLastListener implements ActionListener {
|
||||||
private Game game;
|
private Game game;
|
||||||
|
private SpielFrame sf;
|
||||||
|
|
||||||
public ButtonViewLastListener(Game game) {
|
public ButtonViewLastListener(Game game, SpielFrame sf) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
this.sf = sf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
this.game.setViewPointer(this.game.getMoveList().size() - 1);
|
this.game.setViewPointer(this.game.getMoveList().size());
|
||||||
// TODO Auto-generated method stub
|
this.game.loadView();
|
||||||
|
this.sf.setDefaultButtons();
|
||||||
|
this.sf.applyBoardButtons();
|
||||||
|
this.sf.ladeBrett();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -329,6 +329,10 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadView() {
|
public void loadView() {
|
||||||
// TODO: add functionality
|
this.board = new Board();
|
||||||
|
this.board.loadFromFen(this.startPosFen);
|
||||||
|
for (int i = 0; i < this.viewPointer; i++) {
|
||||||
|
this.board.doMove(this.movelist.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,13 @@ import de.mannheim.th.chess.utl.Clock;
|
||||||
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonFileSaverListener;
|
import de.mannheim.th.chess.controller.ButtonFileSaverListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonQuickloadListener;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonQuicksaveListener;
|
|
||||||
import de.mannheim.th.chess.controller.ButtonSelectPieceListener;
|
import de.mannheim.th.chess.controller.ButtonSelectPieceListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonToNormalListener;
|
import de.mannheim.th.chess.controller.ButtonToNormalListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonUndoMoveListener;
|
import de.mannheim.th.chess.controller.ButtonUndoMoveListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonViewBackListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonViewFirstListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonViewForwardListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonViewLastListener;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
|
|
@ -62,8 +64,6 @@ public class SpielFrame extends JFrame {
|
||||||
private BoardMode mode;
|
private BoardMode mode;
|
||||||
private Square selectedSquare;
|
private Square selectedSquare;
|
||||||
|
|
||||||
private int viewPointer;
|
|
||||||
|
|
||||||
public enum BoardMode {
|
public enum BoardMode {
|
||||||
normal, pieceSelected, finished
|
normal, pieceSelected, finished
|
||||||
}
|
}
|
||||||
|
|
@ -126,15 +126,12 @@ public class SpielFrame extends JFrame {
|
||||||
*/
|
*/
|
||||||
public void erstelleBrett() {
|
public void erstelleBrett() {
|
||||||
|
|
||||||
this.clearButtons();
|
this.setDefaultButtons();
|
||||||
this.setDefaultBackground();
|
|
||||||
this.setButtonsActions();
|
this.setButtonsActions();
|
||||||
|
this.applyBoardButtons();
|
||||||
|
|
||||||
this.ladeBrett();
|
this.ladeBrett();
|
||||||
|
|
||||||
panelLinks.revalidate();
|
|
||||||
panelLinks.repaint();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int mirrowedGrid(int i) {
|
private int mirrowedGrid(int i) {
|
||||||
|
|
@ -144,7 +141,7 @@ public class SpielFrame extends JFrame {
|
||||||
/**
|
/**
|
||||||
* holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren
|
* holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren
|
||||||
*/
|
*/
|
||||||
private void ladeBrett() {
|
public void ladeBrett() {
|
||||||
// System.out.println(game.toFEN());
|
// System.out.println(game.toFEN());
|
||||||
|
|
||||||
char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray();
|
char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray();
|
||||||
|
|
@ -172,6 +169,10 @@ public class SpielFrame extends JFrame {
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
panelLinks.revalidate();
|
||||||
|
panelLinks.repaint();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -215,6 +216,11 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDefaultButtons() {
|
||||||
|
this.clearButtons();
|
||||||
|
this.setDefaultBackground();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Switches the button actions depending on the boardmode
|
* Switches the button actions depending on the boardmode
|
||||||
*/
|
*/
|
||||||
|
|
@ -262,9 +268,6 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JButton b : buttons) {
|
|
||||||
panelLinks.add(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDraw() {
|
public void showDraw() {
|
||||||
|
|
@ -338,6 +341,11 @@ public class SpielFrame extends JFrame {
|
||||||
viewForwardButton.setEnabled(false);
|
viewForwardButton.setEnabled(false);
|
||||||
viewLastButton.setEnabled(false);
|
viewLastButton.setEnabled(false);
|
||||||
|
|
||||||
|
viewFirstButton.addActionListener(new ButtonViewFirstListener(this.game, this));
|
||||||
|
viewBackButton.addActionListener(new ButtonViewBackListener(this.game, this));
|
||||||
|
viewForwardButton.addActionListener(new ButtonViewForwardListener(this.game, this));
|
||||||
|
viewLastButton.addActionListener(new ButtonViewLastListener(this.game, this));
|
||||||
|
|
||||||
this.controlPanel.add(viewFirstButton);
|
this.controlPanel.add(viewFirstButton);
|
||||||
this.controlPanel.add(viewBackButton);
|
this.controlPanel.add(viewBackButton);
|
||||||
this.controlPanel.add(viewForwardButton);
|
this.controlPanel.add(viewForwardButton);
|
||||||
|
|
@ -435,17 +443,6 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
statistik.add(scrollPane);
|
statistik.add(scrollPane);
|
||||||
|
|
||||||
// TODO: Buttons should be somewhere else
|
|
||||||
JButton quicksave = new JButton();
|
|
||||||
quicksave.addActionListener(new ButtonQuicksaveListener(this.game));
|
|
||||||
quicksave.setText("Quicksave");
|
|
||||||
statistik.add(quicksave);
|
|
||||||
|
|
||||||
JButton quickload = new JButton();
|
|
||||||
quickload.addActionListener(new ButtonQuickloadListener(this.game, this));
|
|
||||||
quickload.setText("Quickload");
|
|
||||||
statistik.add(quickload);
|
|
||||||
|
|
||||||
return statistik;
|
return statistik;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -576,7 +573,7 @@ public class SpielFrame extends JFrame {
|
||||||
return clock;
|
return clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableControlPanelButtons() {
|
public void enableControlPanelButtons() {
|
||||||
for (Component c : this.controlPanel.getComponents()) {
|
for (Component c : this.controlPanel.getComponents()) {
|
||||||
if (c instanceof JButton) {
|
if (c instanceof JButton) {
|
||||||
c.setEnabled(!c.isEnabled());
|
c.setEnabled(!c.isEnabled());
|
||||||
|
|
@ -584,12 +581,10 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setViewPointer(int i) {
|
public void applyBoardButtons() {
|
||||||
this.viewPointer = i;
|
for (JButton b : buttons) {
|
||||||
}
|
panelLinks.add(b);
|
||||||
|
}
|
||||||
public int getViewPointer() {
|
|
||||||
return this.viewPointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue