diff --git a/jsettlers.common/src/main/java/jsettlers/common/menu/FakeMapGame.java b/jsettlers.common/src/main/java/jsettlers/common/menu/FakeMapGame.java index 5a1f02ff6f..cf229cc908 100644 --- a/jsettlers.common/src/main/java/jsettlers/common/menu/FakeMapGame.java +++ b/jsettlers.common/src/main/java/jsettlers/common/menu/FakeMapGame.java @@ -14,6 +14,7 @@ *******************************************************************************/ package jsettlers.common.menu; +import java8.util.function.Consumer; import jsettlers.common.map.IGraphicsGrid; import jsettlers.common.player.IInGamePlayer; import jsettlers.common.statistics.IGameTimeProvider; @@ -53,7 +54,12 @@ public IInGamePlayer getInGamePlayer() { } @Override - public void setGameExitListener(IGameExitListener exitListener) { + public IInGamePlayer[] getAllInGamePlayers() { + return null; + } + + @Override + public void setGameExitListener(Consumer exitListener) { } @Override diff --git a/jsettlers.common/src/main/java/jsettlers/common/menu/IStartedGame.java b/jsettlers.common/src/main/java/jsettlers/common/menu/IStartedGame.java index a70a891646..6ef655bfeb 100644 --- a/jsettlers.common/src/main/java/jsettlers/common/menu/IStartedGame.java +++ b/jsettlers.common/src/main/java/jsettlers/common/menu/IStartedGame.java @@ -14,7 +14,9 @@ *******************************************************************************/ package jsettlers.common.menu; +import java8.util.function.Consumer; import jsettlers.common.map.IGraphicsGrid; +import jsettlers.common.player.IEndgameStatistic; import jsettlers.common.player.IInGamePlayer; import jsettlers.common.statistics.IGameTimeProvider; @@ -27,21 +29,27 @@ public interface IStartedGame { /** * Gets the grid that should be displayed to the user. - * + * * @return */ IGraphicsGrid getMap(); /** * Gets an {@link IGameTimeProvider} implementation used to supply the UI with game time information. - * + * * @return */ IGameTimeProvider getGameTimeProvider(); + /** + * + * @return null or all {@link IInGamePlayer}s + */ + IInGamePlayer[] getAllInGamePlayers(); + IInGamePlayer getInGamePlayer(); - void setGameExitListener(IGameExitListener exitListener); + void setGameExitListener(Consumer exitListener); boolean isShutdownFinished(); diff --git a/jsettlers.common/src/main/java/jsettlers/common/player/IEndgameStatistic.java b/jsettlers.common/src/main/java/jsettlers/common/player/IEndgameStatistic.java index ad87e7c2ce..ab94f1c64b 100644 --- a/jsettlers.common/src/main/java/jsettlers/common/player/IEndgameStatistic.java +++ b/jsettlers.common/src/main/java/jsettlers/common/player/IEndgameStatistic.java @@ -22,4 +22,8 @@ public interface IEndgameStatistic { short getAmountOfProducedSoldiers(); short getAmountOfProducedMana(); short getAmountOfProducedGold(); + + String getName(); + + byte getTeam(); } diff --git a/jsettlers.graphics/src/main/resources/jsettlers/graphics/localization/labels_de.properties b/jsettlers.graphics/src/main/resources/jsettlers/graphics/localization/labels_de.properties index 713155347c..6d4b1e751a 100644 --- a/jsettlers.graphics/src/main/resources/jsettlers/graphics/localization/labels_de.properties +++ b/jsettlers.graphics/src/main/resources/jsettlers/graphics/localization/labels_de.properties @@ -368,6 +368,13 @@ join-game-panel-map-slot = Position join-game-panel-team = Team join-game-panel-send-chat-messageLabel = Senden +stats-panel-exit = Weiter +stats-panel-name = Name +stats-panel-team = Team +stats-panel-manna = Manna +stats-panel-gold = Gold +stats-panel-soldiers = rekrutierte Soldaten + peace-time-WITHOUT = keine player-type-HUMAN = Mensch player-type-AI_VERY_EASY = Computer (sehr einfach) diff --git a/jsettlers.graphics/src/main/resources/jsettlers/graphics/localization/labels_en.properties b/jsettlers.graphics/src/main/resources/jsettlers/graphics/localization/labels_en.properties index a0f62417b7..6106fd924b 100644 --- a/jsettlers.graphics/src/main/resources/jsettlers/graphics/localization/labels_en.properties +++ b/jsettlers.graphics/src/main/resources/jsettlers/graphics/localization/labels_en.properties @@ -370,6 +370,13 @@ join-game-panel-map-slot = Position join-game-panel-team = Team join-game-panel-send-chat-messageLabel = Send +stats-panel-exit = Next +stats-panel-name = Name +stats-panel-team = Team +stats-panel-manna = Manna +stats-panel-gold = Gold +stats-panel-soldiers = recruted soldiers + peace-time-WITHOUT = without player-type-HUMAN = Human player-type-AI_VERY_EASY = Computer (very easy) diff --git a/jsettlers.logic/src/main/java/jsettlers/logic/player/EndgameStatistic.java b/jsettlers.logic/src/main/java/jsettlers/logic/player/EndgameStatistic.java index 282a7eccc0..5ebe08a0aa 100644 --- a/jsettlers.logic/src/main/java/jsettlers/logic/player/EndgameStatistic.java +++ b/jsettlers.logic/src/main/java/jsettlers/logic/player/EndgameStatistic.java @@ -14,6 +14,7 @@ *******************************************************************************/ package jsettlers.logic.player; +import jsettlers.common.ai.EPlayerType; import jsettlers.common.player.IEndgameStatistic; import java.io.Serializable; @@ -22,14 +23,14 @@ * @author codingberlin */ public class EndgameStatistic implements IEndgameStatistic, Serializable { - private static final long serialVersionUID = -1352905249487671842L; + private static final long serialVersionUID = -1352905249487671843L; - private MannaInformation mannaInformation; + private Player player; private short amountOfProducedSoldiers = 0; private short amountOfProducedGold = 0; - public EndgameStatistic(MannaInformation mannaInformation) { - this.mannaInformation = mannaInformation; + public EndgameStatistic(Player player) { + this.player = player; } @Override @@ -39,7 +40,7 @@ public short getAmountOfProducedSoldiers() { @Override public short getAmountOfProducedMana() { - return mannaInformation.getAmountOfManna(); + return player.getMannaInformation().getAmountOfManna(); } @Override @@ -47,6 +48,16 @@ public short getAmountOfProducedGold() { return amountOfProducedGold; } + @Override + public String getName() { + return player.getPlayerType().toString(); + } + + @Override + public byte getTeam() { + return player.getTeamId(); + } + public void incrementAmountOfProducedSoldiers() { amountOfProducedSoldiers++; } diff --git a/jsettlers.logic/src/main/java/jsettlers/logic/player/Player.java b/jsettlers.logic/src/main/java/jsettlers/logic/player/Player.java index 781a99bee9..4543bf8e76 100644 --- a/jsettlers.logic/src/main/java/jsettlers/logic/player/Player.java +++ b/jsettlers.logic/src/main/java/jsettlers/logic/player/Player.java @@ -43,8 +43,9 @@ public class Player implements Serializable, IMessenger, IInGamePlayer, IOffersC private final Team team; private final byte numberOfPlayers; private final MannaInformation mannaInformation = new MannaInformation(); - private final MaterialCounts materialCounts = new MaterialCounts(); - private final EndgameStatistic endgameStatistic = new EndgameStatistic(mannaInformation); + + private final MaterialCounts materialCounts = new MaterialCounts(); + private final EndgameStatistic endgameStatistic = new EndgameStatistic(this); private EWinState winState; diff --git a/jsettlers.logic/src/main/java/jsettlers/main/JSettlersGame.java b/jsettlers.logic/src/main/java/jsettlers/main/JSettlersGame.java index 086e733a57..79038b51c6 100644 --- a/jsettlers.logic/src/main/java/jsettlers/main/JSettlersGame.java +++ b/jsettlers.logic/src/main/java/jsettlers/main/JSettlersGame.java @@ -25,12 +25,13 @@ import java.util.Date; import java.util.Locale; +import java8.util.function.Consumer; + import jsettlers.ai.highlevel.AiExecutor; import jsettlers.common.CommonConstants; import jsettlers.common.map.IGraphicsGrid; import jsettlers.common.menu.EGameError; import jsettlers.common.menu.EProgressState; -import jsettlers.common.menu.IGameExitListener; import jsettlers.common.menu.IMapInterfaceConnector; import jsettlers.common.menu.IStartedGame; import jsettlers.common.menu.IStartingGame; @@ -165,24 +166,11 @@ public synchronized IStartingGame start() { public void stop() { synchronized (stopMutex) { - printEndgameStatistic(); stopped = true; stopMutex.notifyAll(); } } - // TODO remove me when an EndgameStatistic screen exists. - private void printEndgameStatistic() { - PartitionsGrid partitionsGrid = gameRunner.getMainGrid().getPartitionsGrid(); - System.out.println("Endgame statistic:"); - for (byte playerId = 0; playerId < partitionsGrid.getNumberOfPlayers(); playerId++) { - Player player = partitionsGrid.getPlayer(playerId); - if (player != null) { - System.out.println("Player " + playerId + ": " + player.getEndgameStatistic()); - } - } - } - protected OutputStream createReplayWriteStream() throws IOException { final String replayFilename = getLogFile(mapCreator, "_replay.log"); return ResourceManager.writeUserFile(replayFilename); @@ -194,7 +182,7 @@ public class GameRunner implements Runnable, IStartingGame, IStartedGame, IGameS private GameTimeProvider gameTimeProvider; private EProgressState progressState; private float progress; - private IGameExitListener exitListener; + private Consumer exitListener; private boolean gameRunning; private AiExecutor aiExecutor; private WinLoseTracker winLoseTracker; @@ -287,7 +275,7 @@ public void run() { } finally { shutdownFinished = true; if (exitListener != null) { - exitListener.gameExited(this); + exitListener.accept(this); } } } @@ -368,6 +356,11 @@ public IInGamePlayer getInGamePlayer() { return mainGrid.getPartitionsGrid().getPlayer(playerId); } + @Override + public IInGamePlayer[] getAllInGamePlayers() { + return mainGrid.getPartitionsGrid().getPlayers(); + } + @Override public boolean isShutdownFinished() { return shutdownFinished; @@ -384,7 +377,7 @@ public void stopGame() { } @Override - public void setGameExitListener(IGameExitListener exitListener) { + public void setGameExitListener(Consumer exitListener) { this.exitListener = exitListener; } diff --git a/jsettlers.main.android/src/main/java/jsettlers/main/android/core/controls/GameMenu.java b/jsettlers.main.android/src/main/java/jsettlers/main/android/core/controls/GameMenu.java index 9e8c11845d..2245476dae 100644 --- a/jsettlers.main.android/src/main/java/jsettlers/main/android/core/controls/GameMenu.java +++ b/jsettlers.main.android/src/main/java/jsettlers/main/android/core/controls/GameMenu.java @@ -24,10 +24,10 @@ import android.widget.Toast; import go.graphics.android.AndroidSoundPlayer; +import java8.util.function.Consumer; import jsettlers.common.action.Action; import jsettlers.common.action.EActionType; import jsettlers.common.action.SetSpeedAction; -import jsettlers.common.menu.IGameExitListener; import jsettlers.common.menu.IStartedGame; import jsettlers.main.android.R; import jsettlers.main.android.gameplay.gamemenu.GameSpeedLiveData; @@ -35,7 +35,7 @@ /** * GameMenu is a singleton within the scope of a started game */ -public class GameMenu implements IGameExitListener { +public class GameMenu implements Consumer { public enum GameState { PLAYING, CONFIRM_QUIT, @@ -148,7 +148,7 @@ public boolean isMultiplayer() { * IGameExitedListener implementation */ @Override - public void gameExited(IStartedGame game) { + public void accept(IStartedGame game) { gameState.postValue(GameState.QUITTED); } } diff --git a/jsettlers.main.swing/src/main/java/jsettlers/main/swing/JSettlersFrame.java b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/JSettlersFrame.java index da23250481..b108abc67b 100644 --- a/jsettlers.main.swing/src/main/java/jsettlers/main/swing/JSettlersFrame.java +++ b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/JSettlersFrame.java @@ -47,6 +47,7 @@ import jsettlers.main.swing.menu.joinpanel.JoinGamePanel; import jsettlers.main.swing.menu.mainmenu.MainMenuPanel; import jsettlers.main.swing.menu.startinggamemenu.StartingGamePanel; +import jsettlers.main.swing.menu.statspanel.EndgameStatsPanel; import jsettlers.main.swing.settings.SettingsManager; import jsettlers.main.swing.settings.UiPlayer; @@ -58,6 +59,7 @@ public class JSettlersFrame extends JFrame { private final IMultiplayerConnector multiPlayerConnector; private final MainMenuPanel mainPanel; + private final EndgameStatsPanel endgameStatsPanel = new EndgameStatsPanel(this); private final StartingGamePanel startingGamePanel = new StartingGamePanel(this); private final JoinGamePanel joinGamePanel = new JoinGamePanel(this); private final SoundPlayer soundPlayer = new SwingSoundPlayer(SettingsManager.getInstance()); @@ -194,10 +196,15 @@ public void showJoinMultiplayerMenu(IJoinPhaseMultiplayerGameConnector joinPhase setNewContentPane(joinGamePanel); } + public void showEndgameStatistics(IStartedGame game) { + endgameStatsPanel.setGame(game); + setNewContentPane(endgameStatsPanel); + } + public IMapInterfaceConnector showStartedGame(IStartedGame startedGame) { MapContent content = new MapContent(startedGame, soundPlayer, SettingsManager.getInstance().getFpsLimit(), ETextDrawPosition.TOP_RIGHT); SwingUtilities.invokeLater(() -> setContent(content)); - startedGame.setGameExitListener(exitGame -> SwingUtilities.invokeLater(this::showMainMenu)); + startedGame.setGameExitListener(exitGame -> SwingUtilities.invokeLater(() -> showEndgameStatistics(exitGame))); return content.getInterfaceConnector(); } } diff --git a/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/ELFStyle.java b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/ELFStyle.java index 800f88e6b0..db60610a42 100644 --- a/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/ELFStyle.java +++ b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/ELFStyle.java @@ -79,7 +79,12 @@ public enum ELFStyle { /** * Combobox in settler style */ - COMBOBOX; + COMBOBOX, + + /** + * Tables in settlers label style + */ + TABLE; /** * Key used for putClientProperty diff --git a/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/JSettlersLookAndFeel.java b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/JSettlersLookAndFeel.java index cb056a72fd..36139e3d7a 100644 --- a/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/JSettlersLookAndFeel.java +++ b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/JSettlersLookAndFeel.java @@ -29,6 +29,7 @@ import jsettlers.main.swing.lookandfeel.factory.ProgressBarUiFactory; import jsettlers.main.swing.lookandfeel.factory.ScrollPaneUiFactory; import jsettlers.main.swing.lookandfeel.factory.ScrollbarUiFactory; +import jsettlers.main.swing.lookandfeel.factory.TableUiFactory; import jsettlers.main.swing.lookandfeel.factory.TextAreaUiFactory; import jsettlers.main.swing.lookandfeel.factory.TextFieldUiFactory; import jsettlers.main.swing.lookandfeel.factory.ToggleButtonUiFactory; @@ -67,6 +68,7 @@ public static void install() throws JSettlersLookAndFeelExecption { TextFieldUiFactory.FORWARD.loadFromType("TextFieldUI"); ButtonUiFactory.FORWARD.loadFromType("ButtonUI"); LabelUiFactory.FORWARD.loadFromType("LabelUI"); + TableUiFactory.FORWARD.loadFromType("TableUI"); // Panel handles all UI types // PanelUiFactory.FORWARD.loadFromType("PanelUI"); // ScrollPane handles all UI types @@ -102,6 +104,7 @@ public static void install() throws JSettlersLookAndFeelExecption { "ProgressBarUI", ProgressBarUiFactory.class.getName(), "TextAreaUI", TextAreaUiFactory.class.getName(), "ComboBoxUI", ComboboxUiFactory.class.getName(), + "TableUI", TableUiFactory.class.getName(), }; UIManager.getDefaults().putDefaults(uiFactories); diff --git a/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/components/StoneBackgroundTable.java b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/components/StoneBackgroundTable.java new file mode 100644 index 0000000000..001adbb5df --- /dev/null +++ b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/components/StoneBackgroundTable.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2019 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package jsettlers.main.swing.lookandfeel.components; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.image.BufferedImage; + +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.plaf.basic.BasicTableUI; +import javax.swing.table.DefaultTableCellRenderer; + +import jsettlers.main.swing.lookandfeel.ELFStyle; +import jsettlers.main.swing.lookandfeel.factory.LabelUiFactory; +import jsettlers.main.swing.lookandfeel.ui.UIDefaults; +import jsettlers.main.swing.lookandfeel.ui.img.UiImageLoader; + +public class StoneBackgroundTable extends BasicTableUI { + /** + * Foreground color + */ + private final Color foregroundColor; + + /** + * Background Image + */ + private final BufferedImage backgroundImage = UiImageLoader.get("ui_static_info_bg/ui_static-info-bg.png"); + + + /** + * Constructor + * + * @param foregroundColor + * Foreground color of the Label + */ + public StoneBackgroundTable(Color foregroundColor) { + this.foregroundColor = foregroundColor; + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + c.setForeground(foregroundColor); + c.setFont(UIDefaults.FONT); + c.setOpaque(false); + + JTable table = (JTable)c; + table.setGridColor(Color.WHITE); + table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { + @Override + public Component getTableCellRendererComponent(JTable jTable, Object o, boolean b, boolean b1, int i, int i1) { + JComponent comp = new JLabel(o+""); + comp.putClientProperty(ELFStyle.KEY, i == 0 ? ELFStyle.LABEL_HEADER : ELFStyle.LABEL_LONG); + LabelUiFactory.createUI(comp).installUI(comp); + return comp; + } + }); + } + @Override + public void paint(Graphics g, JComponent c) { + // Repeat the graphic as much as needed, the graphic is designed for this, so the start fits to the end of the graphic + for (int i = 0; i < c.getWidth(); i += backgroundImage.getWidth()) { + g.drawImage(backgroundImage, i, 0, c); + } + super.paint(g, c); + } +} diff --git a/jsettlers.common/src/main/java/jsettlers/common/menu/IGameExitListener.java b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/factory/TableUiFactory.java similarity index 56% rename from jsettlers.common/src/main/java/jsettlers/common/menu/IGameExitListener.java rename to jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/factory/TableUiFactory.java index c5cc4f277e..c0c4c09f4a 100644 --- a/jsettlers.common/src/main/java/jsettlers/common/menu/IGameExitListener.java +++ b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/lookandfeel/factory/TableUiFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 + * Copyright (c) 2019 * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, @@ -12,19 +12,42 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. *******************************************************************************/ -package jsettlers.common.menu; +package jsettlers.main.swing.lookandfeel.factory; -/** - * This listener gets notified when the game is exited. - * - * @author michael - */ -public interface IGameExitListener { +import javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; + +import jsettlers.main.swing.lookandfeel.ELFStyle; +import jsettlers.main.swing.lookandfeel.components.StoneBackgroundTable; +import jsettlers.main.swing.lookandfeel.ui.UIDefaults; + +public class TableUiFactory { + + /** + * Forward calls + */ + public static final ForwardFactory FORWARD = new ForwardFactory(); /** - * Called only once before the game is finally destroyed. - * - * @param game - * The game that was started before. Is valid during the call, but should not be used afterwards. + * This is only a factory so no objects need to be created. */ - void gameExited(IStartedGame game); + private TableUiFactory() { + } + + private static final StoneBackgroundTable labelShort = new StoneBackgroundTable(UIDefaults.LABEL_TEXT_COLOR); + + /** + * Create PLAF + * + * @param c + * Component which need the UI + * @return UI + */ + public static ComponentUI createUI(JComponent c) { + Object style = c.getClientProperty(ELFStyle.KEY); + if(ELFStyle.TABLE == style) { + return labelShort; + } + + return FORWARD.create(c); + } } diff --git a/jsettlers.main.swing/src/main/java/jsettlers/main/swing/menu/statspanel/EndgameStatsPanel.java b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/menu/statspanel/EndgameStatsPanel.java new file mode 100644 index 0000000000..154ec4ffea --- /dev/null +++ b/jsettlers.main.swing/src/main/java/jsettlers/main/swing/menu/statspanel/EndgameStatsPanel.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2019 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package jsettlers.main.swing.menu.statspanel; + +import java.awt.BorderLayout; + +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.SwingUtilities; +import javax.swing.table.DefaultTableModel; + +import jsettlers.common.menu.IStartedGame; +import jsettlers.common.player.IEndgameStatistic; +import jsettlers.common.player.IInGamePlayer; +import jsettlers.graphics.localization.Labels; +import jsettlers.main.swing.JSettlersFrame; +import jsettlers.main.swing.lookandfeel.ELFStyle; +import jsettlers.main.swing.lookandfeel.components.BackgroundPanel; + +public class EndgameStatsPanel extends BackgroundPanel { + private JTable statsTable = new JTable(); + + public EndgameStatsPanel(JSettlersFrame settlersFrame) { + JPanel mainPane = new JPanel(); + mainPane.setLayout(new BorderLayout()); + + statsTable.setEnabled(false); + statsTable.putClientProperty(ELFStyle.KEY, ELFStyle.TABLE); + mainPane.add(statsTable, BorderLayout.NORTH); + + JButton exit = new JButton(Labels.getString("stats-panel-exit")); + exit.putClientProperty(ELFStyle.KEY, ELFStyle.BUTTON_STONE); + exit.addActionListener(actionEvent -> settlersFrame.showMainMenu()); + mainPane.add(exit, BorderLayout.SOUTH); + + add(mainPane); + SwingUtilities.updateComponentTreeUI(this); + } + + private static final String[] columns = new String[] { + Labels.getString("stats-panel-name"), + Labels.getString("stats-panel-team"), + Labels.getString("stats-panel-manna"), + Labels.getString("stats-panel-gold"), + Labels.getString("stats-panel-soldiers"), + }; + + public void setGame(IStartedGame game) { + IInGamePlayer[] players = game.getAllInGamePlayers(); + String[][] values = new String[players.length+1][]; + values[0] = columns; + for(int i = 0; i != players.length; i++) values[i+1] = getPlayerRow(players[i]); + + statsTable.setModel(new DefaultTableModel(values, columns)); + } + + private String[] getPlayerRow(IInGamePlayer player) { + String[] row = new String[5]; + IEndgameStatistic igs = player.getEndgameStatistic(); + + row[0] = igs.getName(); + row[1] = "" + igs.getTeam(); + row[2] = "" + igs.getAmountOfProducedMana(); + row[3] = "" + igs.getAmountOfProducedGold(); + row[4] = "" + igs.getAmountOfProducedSoldiers(); + + return row; + } +}