package eu.semberal.migmang.graphics;
import eu.semberal.migmang.enums.GameColor;
import eu.semberal.migmang.enums.PlayerType;
import eu.semberal.migmang.events.MigmangGameEvent;
import eu.semberal.migmang.logic.*;
import java.io.File;
import javax.swing.JOptionPane;
/**
*
* @author lukas.sembera
*/
public class Graphics implements HumanMoveGenerator, GraphicsListener {
private MainFrame mainFrame;
private MoveHistoryDialog moveHistoryDialog;
private WindowEventsListener windowEventsListener;
public Graphics() {
mainFrame = new MainFrame(this);
mainFrame.setVisible(true);
moveHistoryDialog = new MoveHistoryDialog(mainFrame, false);
mainFrame.getBoardComponent().updateBoardVariables(true);
}
@Override
public void attachWindowEventsListener(WindowEventsListener m) {
this.windowEventsListener = m;
}
@Override
public void redraw(Board s) {
mainFrame.getBoardComponent().setBoard(s);
mainFrame.getBoardComponent().updatePiecesCoordinates(true);
}
void fireNewGameStarted(int bilyObtiznost, int cernyObtiznost,
PlayerType bilyTyp, PlayerType cernyTyp) {
windowEventsListener.onGameStarted(new MigmangGameEvent(this, bilyObtiznost, cernyObtiznost, bilyTyp, cernyTyp));
}
void fireGameClosed() {
windowEventsListener.onGameClosed();
}
@Override
public void move(Board board, GameColor color, MoveContainer container) {
mainFrame.getBoardComponent().setBoard(board);
mainFrame.getBoardComponent().updatePiecesCoordinates(false);
mainFrame.getBoardComponent().allowMove(color, container);
}
@Override
public void onQuitGame() {
disableMoves();
mainFrame.setComponentsEnabled(false);
mainFrame.setReplayButtonsEnabled(false);
moveHistoryDialog.clearList();
}
void fireUndoMove() {
windowEventsListener.onMoveBackward();
}
void fireRedoMove() {
windowEventsListener.onMoveForward();
}
void fireGameDataChanged(int bilyObtiznost, int cernyObtiznost, PlayerType bilyTyp, PlayerType cernyTyp) {
windowEventsListener.onGameDataChanged(new MigmangGameEvent(this, bilyObtiznost, cernyObtiznost, bilyTyp, cernyTyp));
}
void fireSaveGame(File kamUlozit) {
windowEventsListener.onSaveGame(kamUlozit);
}
void fireLoadReplay(File f) {
windowEventsListener.loadReplayRequested(f);
}
void fireLoadGame(File odkudNacist) {
windowEventsListener.onLoadGame(odkudNacist);
}
void fireQuitReplayMode() {
boolean res = windowEventsListener.quitReplayMode();
if (res) {
mainFrame.setReplayButtonsEnabled(false);
}
}
@Override
public void disableMoves() {
mainFrame.getBoardComponent().allowMove(null, null);
}
void fireChangePausedState() {
windowEventsListener.onTogglePausedState();
}
void openMoveHistory() {
moveHistoryDialog.setVisible(!moveHistoryDialog.isVisible());
}
GameStatus getGameStatus() {
return windowEventsListener.getGameStatus();
}
@Override
public void onStartGame(boolean isReplay) {
mainFrame.setComponentsEnabled(true);
if (isReplay) {
mainFrame.setReplayButtonsEnabled(true);
}
}
@Override
public void addMove(Move t) {
moveHistoryDialog.addMove(t);
}
@Override
public void dropLastMove() {
moveHistoryDialog.dropLastMove();
}
public void fireMoveToStart() {
windowEventsListener.onMoveToStartRequested();
}
public void fireMoveToEnd() {
windowEventsListener.moveToEndRequested();
}
@Override
public void showImportantMessage(String title, String text, int type) {
JOptionPane.showMessageDialog(mainFrame, text, title, type);
}
@Override
public void showMessage(String text) {
mainFrame.showInStatusBar(text);
}
public void fireBetMoveRequest() {
windowEventsListener.onBestMoveHintRequest();
}
}