PGN datei auswählbar
Einzelne Games als Button angezeigt(Man kann sie noch nicht starten)PGN
parent
a19130bb86
commit
8e45acb0b3
|
@ -1,4 +1,6 @@
|
||||||
package de.hs_mannheim.informatik.chess.main;
|
package de.hs_mannheim.informatik.chess.main;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.chess.controller.Controller;
|
import de.hs_mannheim.informatik.chess.controller.Controller;
|
||||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||||
import de.hs_mannheim.informatik.chess.view.GameGui;
|
import de.hs_mannheim.informatik.chess.view.GameGui;
|
||||||
|
|
|
@ -1,12 +1,25 @@
|
||||||
package de.hs_mannheim.informatik.chess.view;
|
package de.hs_mannheim.informatik.chess.view;
|
||||||
|
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||||
|
import com.github.bhlangonijr.chesslib.game.Game;
|
||||||
|
import java.util.List;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Cursor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class MainGui {
|
public class MainGui {
|
||||||
|
|
||||||
private JFrame frame;
|
private JFrame frame;
|
||||||
private Runnable onStartGame;
|
private Runnable onStartGame;
|
||||||
|
private ChessEngine engine = new ChessEngine();
|
||||||
|
|
||||||
public MainGui(Runnable onStartGame) {
|
public MainGui(Runnable onStartGame) {
|
||||||
this.onStartGame = onStartGame;
|
this.onStartGame = onStartGame;
|
||||||
|
@ -74,6 +87,54 @@ public class MainGui {
|
||||||
frame.dispose(); // Hauptmenü schließen
|
frame.dispose(); // Hauptmenü schließen
|
||||||
onStartGame.run(); // **Ruft den Callback auf**
|
onStartGame.run(); // **Ruft den Callback auf**
|
||||||
});
|
});
|
||||||
|
|
||||||
|
btnLoadGame.addActionListener(e -> {
|
||||||
|
JFileChooser chooser = new JFileChooser();
|
||||||
|
int result = chooser.showOpenDialog(frame);
|
||||||
|
if (result == JFileChooser.APPROVE_OPTION) {
|
||||||
|
String path = chooser.getSelectedFile().getAbsolutePath();
|
||||||
|
try {
|
||||||
|
List<Game> games = engine.loadGamesFromPgn(path);
|
||||||
|
zeigeGeladeneSpiele(games);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
JOptionPane.showMessageDialog(frame, "Fehler beim Laden der PGN-Datei:\n" + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void zeigeGeladeneSpiele(List<Game> games) {
|
||||||
|
JFrame gameListFrame = new JFrame("Geladene Partien");
|
||||||
|
gameListFrame.setSize(600, 800);
|
||||||
|
gameListFrame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
JScrollPane scrollPane = new JScrollPane(panel);
|
||||||
|
|
||||||
|
int index = 1;
|
||||||
|
for (Game game : games) {
|
||||||
|
String white = game.getWhitePlayer().getName();
|
||||||
|
String black = game.getBlackPlayer().getName();
|
||||||
|
String title = "Spiel " + index++ + ": " + white + " vs. " + black;
|
||||||
|
|
||||||
|
JButton gameButton = new JButton(title);
|
||||||
|
gameButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
gameButton.addActionListener(e -> {
|
||||||
|
System.out.println("Ausgewähltes Spiel:\n" + game);
|
||||||
|
JOptionPane.showMessageDialog(gameListFrame,
|
||||||
|
"Noch keine Replay-Ansicht.\n" +
|
||||||
|
"Spiel: " + white + " vs. " + black);
|
||||||
|
});
|
||||||
|
|
||||||
|
panel.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||||
|
panel.add(gameButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
gameListFrame.add(scrollPane);
|
||||||
|
gameListFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper für Button Styling
|
// Helper für Button Styling
|
||||||
|
|
Loading…
Reference in New Issue