Some additional info to the game end window.

This commit is contained in:
LevelX2 2014-05-01 19:27:26 +02:00
parent c953bf6260
commit 57d1dc0f6d
3 changed files with 129 additions and 83 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo"> <Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<NonVisualComponents> <NonVisualComponents>
<Container class="javax.swing.JPanel" name="jPanel2"> <Container class="javax.swing.JPanel" name="jPanel2">
@ -56,7 +56,7 @@
<Component id="tabPane" min="-2" pref="277" max="-2" attributes="0"/> <Component id="tabPane" min="-2" pref="277" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="btnOk" min="-2" max="-2" attributes="0"/> <Component id="btnOk" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="37" max="32767" attributes="0"/> <EmptySpace min="0" pref="8" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -75,7 +75,9 @@
</Constraint> </Constraint>
</Constraints> </Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
<SubComponents> <SubComponents>
<Container class="javax.swing.JLayeredPane" name="pnlText"> <Container class="javax.swing.JLayeredPane" name="pnlText">
<Properties> <Properties>
@ -90,38 +92,54 @@
<Property name="opaque" type="boolean" value="true"/> <Property name="opaque" type="boolean" value="true"/>
</Properties> </Properties>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout$JLayeredPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<JLayeredPaneConstraints x="20" y="150" width="570" height="90" layer="0" position="-1"/> <AbsoluteConstraints x="20" y="150" width="570" height="90"/>
</Constraint> </Constraint>
</Constraints> </Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
<SubComponents> <SubComponents>
<Component class="javax.swing.JLabel" name="lblGameInfo">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="18" style="3"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="gameInfo"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="11" y="1" width="550" height="25"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="lblMatchInfo"> <Component class="javax.swing.JLabel" name="lblMatchInfo">
<Properties> <Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="24" style="3"/> <Font name="Tahoma" size="18" style="3"/>
</Property> </Property>
<Property name="horizontalAlignment" type="int" value="0"/> <Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="matchInfo"/> <Property name="text" type="java.lang.String" value="matchInfo"/>
</Properties> </Properties>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout$JLayeredPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<JLayeredPaneConstraints x="11" y="42" width="550" height="40" layer="0" position="-1"/> <AbsoluteConstraints x="10" y="30" width="550" height="25"/>
</Constraint> </Constraint>
</Constraints> </Constraints>
</Component> </Component>
<Component class="javax.swing.JLabel" name="lblResultText"> <Component class="javax.swing.JLabel" name="lblAdditionalInfo">
<Properties> <Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="24" style="3"/> <Font name="Tahoma" size="18" style="3"/>
</Property> </Property>
<Property name="horizontalAlignment" type="int" value="0"/> <Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="result text"/> <Property name="text" type="java.lang.String" value="additionalInfo"/>
</Properties> </Properties>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout$JLayeredPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<JLayeredPaneConstraints x="11" y="1" width="550" height="40" layer="0" position="-1"/> <AbsoluteConstraints x="10" y="60" width="550" height="25"/>
</Constraint> </Constraint>
</Constraints> </Constraints>
</Component> </Component>
@ -135,8 +153,8 @@
<Property name="horizontalAlignment" type="int" value="0"/> <Property name="horizontalAlignment" type="int" value="0"/>
</Properties> </Properties>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout$JLayeredPaneConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<JLayeredPaneConstraints x="0" y="0" width="610" height="250" layer="0" position="-1"/> <AbsoluteConstraints x="0" y="0" width="610" height="250"/>
</Constraint> </Constraint>
</Constraints> </Constraints>
</Component> </Component>

View file

@ -45,13 +45,12 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.game.GamePanel; import mage.client.game.GamePanel;
import mage.client.util.audio.AudioManager;
import mage.client.util.Format; import mage.client.util.Format;
import mage.client.util.ImageHelper; import mage.client.util.ImageHelper;
import mage.client.util.audio.AudioManager;
import mage.client.util.gui.BufferedImageBuilder; import mage.client.util.gui.BufferedImageBuilder;
import mage.view.GameEndView; import mage.view.GameEndView;
import mage.view.PlayerView; import mage.view.PlayerView;
@ -65,7 +64,8 @@ public class GameEndDialog extends MageDialog {
private final DateFormat df = DateFormat.getDateTimeInstance();; private final DateFormat df = DateFormat.getDateTimeInstance();;
/** Creates new form GameEndDialog */ /** Creates new form GameEndDialog
* @param gameEndView */
public GameEndDialog(GameEndView gameEndView) { public GameEndDialog(GameEndView gameEndView) {
initComponents(); initComponents();
@ -80,14 +80,15 @@ public class GameEndDialog extends MageDialog {
ImageIcon icon = new ImageIcon(imageResult); ImageIcon icon = new ImageIcon(imageResult);
lblResultImage.setIcon(icon); lblResultImage.setIcon(icon);
this.lblResultText.setText(gameEndView.getResultMessage()); this.lblGameInfo.setText(gameEndView.getGameInfo());
this.lblMatchInfo.setText(gameEndView.getMatchInfo());
this.lblAdditionalInfo.setText(gameEndView.getAdditionalInfo());
String autoSave = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_LOG_AUTO_SAVE, "true"); String autoSave = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_LOG_AUTO_SAVE, "true");
if (autoSave.equals("true")) { if (autoSave.equals("true")) {
this.saveGameLog(gameEndView); this.saveGameLog(gameEndView);
} }
// game duration // game duration
txtDurationGame.setText(Format.getDuration(gameEndView.getStartTime(), gameEndView.getEndTime())); txtDurationGame.setText(Format.getDuration(gameEndView.getStartTime(), gameEndView.getEndTime()));
txtDurationGame.setToolTipText(new StringBuilder(df.format(gameEndView.getStartTime())).append(" - ").append(df.format(gameEndView.getEndTime())).toString() ); txtDurationGame.setToolTipText(new StringBuilder(df.format(gameEndView.getStartTime())).append(" - ").append(df.format(gameEndView.getEndTime())).toString() );
@ -110,17 +111,6 @@ public class GameEndDialog extends MageDialog {
} }
txtMatchScore.setText(gameEndView.getMatchView().getResult()); txtMatchScore.setText(gameEndView.getMatchView().getResult());
if (gameEndView.getNameMatchWinner() != null) {
if (gameEndView.getClientPlayer().getName().equals(gameEndView.getNameMatchWinner())) {
lblMatchInfo.setText("You won the match!");
} else {
lblMatchInfo.setText(new StringBuilder(gameEndView.getNameMatchWinner()).append(" won the match!").toString());
}
} else {
int winsNeeded = gameEndView.getWinsNeeded() - gameEndView.getWins();
lblMatchInfo.setText(new StringBuilder("You need ").append(winsNeeded == 1 ? "one win ":winsNeeded + " wins ").append("to win the match.").toString());
}
} }
private void saveGameLog(GameEndView gameEndView) { private void saveGameLog(GameEndView gameEndView) {
@ -169,8 +159,9 @@ public class GameEndDialog extends MageDialog {
tabPane = new javax.swing.JTabbedPane(); tabPane = new javax.swing.JTabbedPane();
tabResult = new javax.swing.JLayeredPane(); tabResult = new javax.swing.JLayeredPane();
pnlText = new javax.swing.JLayeredPane(); pnlText = new javax.swing.JLayeredPane();
lblGameInfo = new javax.swing.JLabel();
lblMatchInfo = new javax.swing.JLabel(); lblMatchInfo = new javax.swing.JLabel();
lblResultText = new javax.swing.JLabel(); lblAdditionalInfo = new javax.swing.JLabel();
lblResultImage = new javax.swing.JLabel(); lblResultImage = new javax.swing.JLabel();
tabStatistics = new javax.swing.JPanel(); tabStatistics = new javax.swing.JPanel();
lblDurationGame = new javax.swing.JLabel(); lblDurationGame = new javax.swing.JLabel();
@ -202,25 +193,31 @@ public class GameEndDialog extends MageDialog {
pnlText.setBorder(javax.swing.BorderFactory.createEtchedBorder()); pnlText.setBorder(javax.swing.BorderFactory.createEtchedBorder());
pnlText.setOpaque(true); pnlText.setOpaque(true);
lblMatchInfo.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N lblGameInfo.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
lblGameInfo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblGameInfo.setText("gameInfo");
pnlText.add(lblGameInfo);
lblGameInfo.setBounds(11, 1, 550, 25);
lblMatchInfo.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
lblMatchInfo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); lblMatchInfo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblMatchInfo.setText("matchInfo"); lblMatchInfo.setText("matchInfo");
lblMatchInfo.setBounds(11, 42, 550, 40); pnlText.add(lblMatchInfo);
pnlText.add(lblMatchInfo, javax.swing.JLayeredPane.DEFAULT_LAYER); lblMatchInfo.setBounds(10, 30, 550, 25);
lblResultText.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N lblAdditionalInfo.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
lblResultText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); lblAdditionalInfo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblResultText.setText("result text"); lblAdditionalInfo.setText("additionalInfo");
lblResultText.setBounds(11, 1, 550, 40); pnlText.add(lblAdditionalInfo);
pnlText.add(lblResultText, javax.swing.JLayeredPane.DEFAULT_LAYER); lblAdditionalInfo.setBounds(10, 60, 550, 25);
tabResult.add(pnlText);
pnlText.setBounds(20, 150, 570, 90); pnlText.setBounds(20, 150, 570, 90);
tabResult.add(pnlText, javax.swing.JLayeredPane.DEFAULT_LAYER);
lblResultImage.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N lblResultImage.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
lblResultImage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); lblResultImage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
tabResult.add(lblResultImage);
lblResultImage.setBounds(0, 0, 610, 250); lblResultImage.setBounds(0, 0, 610, 250);
tabResult.add(lblResultImage, javax.swing.JLayeredPane.DEFAULT_LAYER);
tabPane.addTab("Result", tabResult); tabPane.addTab("Result", tabResult);
@ -249,22 +246,17 @@ public class GameEndDialog extends MageDialog {
tabStatisticsLayout.setHorizontalGroup( tabStatisticsLayout.setHorizontalGroup(
tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(tabStatisticsLayout.createSequentialGroup() .addGroup(tabStatisticsLayout.createSequentialGroup()
.addContainerGap()
.addGroup(tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(tabStatisticsLayout.createSequentialGroup() .addComponent(lblPlayerInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap() .addComponent(lblDurationMatch, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblMatchScore, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblPlayerInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblDurationGame, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblDurationMatch, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblLife, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(lblMatchScore, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(tabStatisticsLayout.createSequentialGroup()
.addContainerGap()
.addGroup(tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblDurationGame, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblLife, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtPlayerInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(txtPlayerInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtDurationGame, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE) .addComponent(txtDurationGame, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
.addComponent(txtLife, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE) .addComponent(txtLife, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE)
.addComponent(txtDurationMatch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE) .addComponent(txtDurationMatch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE)
.addComponent(txtMatchScore, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE)) .addComponent(txtMatchScore, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE))
@ -292,7 +284,7 @@ public class GameEndDialog extends MageDialog {
.addGroup(tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(tabStatisticsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblPlayerInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblPlayerInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtPlayerInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(txtPlayerInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(99, Short.MAX_VALUE)) .addContainerGap(105, Short.MAX_VALUE))
); );
tabPane.addTab("Statistics", tabStatistics); tabPane.addTab("Statistics", tabStatistics);
@ -322,7 +314,7 @@ public class GameEndDialog extends MageDialog {
.addComponent(tabPane, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(tabPane, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnOk) .addComponent(btnOk)
.addGap(0, 25, Short.MAX_VALUE)) .addGap(0, 8, Short.MAX_VALUE))
); );
pack(); pack();
@ -335,14 +327,15 @@ public class GameEndDialog extends MageDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnOk; private javax.swing.JButton btnOk;
private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel2;
private javax.swing.JLabel lblAdditionalInfo;
private javax.swing.JLabel lblDurationGame; private javax.swing.JLabel lblDurationGame;
private javax.swing.JLabel lblDurationMatch; private javax.swing.JLabel lblDurationMatch;
private javax.swing.JLabel lblGameInfo;
private javax.swing.JLabel lblLife; private javax.swing.JLabel lblLife;
private javax.swing.JLabel lblMatchInfo; private javax.swing.JLabel lblMatchInfo;
private javax.swing.JLabel lblMatchScore; private javax.swing.JLabel lblMatchScore;
private javax.swing.JLabel lblPlayerInfo; private javax.swing.JLabel lblPlayerInfo;
private javax.swing.JLabel lblResultImage; private javax.swing.JLabel lblResultImage;
private javax.swing.JLabel lblResultText;
private javax.swing.JLayeredPane pnlText; private javax.swing.JLayeredPane pnlText;
private javax.swing.JTabbedPane tabPane; private javax.swing.JTabbedPane tabPane;
private javax.swing.JLayeredPane tabResult; private javax.swing.JLayeredPane tabResult;

View file

@ -45,16 +45,17 @@ import mage.players.Player;
public class GameEndView implements Serializable { public class GameEndView implements Serializable {
private PlayerView clientPlayer = null; private PlayerView clientPlayer = null;
private List<PlayerView> players = new ArrayList<PlayerView>(); private final List<PlayerView> players = new ArrayList<>();
private Date startTime; private final Date startTime;
private Date endTime; private final Date endTime;
private String resultMessage; private String gameInfo;
private final String matchInfo;
private final String additionalInfo;
private boolean won; private boolean won;
private MatchView matchView; private final MatchView matchView;
private int wins; private int wins;
private int loses; private int loses;
private int winsNeeded; private final int winsNeeded;
private String nameMatchWinner = null;
public GameEndView(GameState state, Game game, UUID playerId, Match match) { public GameEndView(GameState state, Game game, UUID playerId, Match match) {
startTime = game.getStartTime(); startTime = game.getStartTime();
@ -68,6 +69,7 @@ public class GameEndView implements Serializable {
if (playerView.getPlayerId().equals(playerId)) { if (playerView.getPlayerId().equals(playerId)) {
clientPlayer = playerView; clientPlayer = playerView;
you = player; you = player;
won = you.hasWon(); // needed to control image
} }
players.add(playerView); players.add(playerView);
if (player.hasWon()) { if (player.hasWon()) {
@ -75,29 +77,58 @@ public class GameEndView implements Serializable {
} }
} }
if (you != null) { if (you != null) {
won = you.hasWon();
if (you.hasWon()) { if (you.hasWon()) {
resultMessage = new StringBuilder("You won the game on turn ").append(game.getTurnNum()).append(".").toString(); gameInfo = new StringBuilder("You won the game on turn ").append(game.getTurnNum()).append(".").toString();
} else if (winner > 0) { } else if (winner > 0) {
resultMessage = new StringBuilder("You lost the game on turn ").append(game.getTurnNum()).append(".").toString(); gameInfo = new StringBuilder("You lost the game on turn ").append(game.getTurnNum()).append(".").toString();
} else { } else {
resultMessage = new StringBuilder("Game is a draw on Turn ").append(game.getTurnNum()).append(".").toString(); gameInfo = new StringBuilder("Game is a draw on Turn ").append(game.getTurnNum()).append(".").toString();
} }
} }
matchView = new MatchView(match); matchView = new MatchView(match);
MatchPlayer matchWinner = null;
winsNeeded = match.getOptions().getWinsNeeded(); winsNeeded = match.getOptions().getWinsNeeded();
for (MatchPlayer mPlayer: match.getPlayers()) { StringBuilder additonalText = new StringBuilder();
if (mPlayer.getPlayer().equals(you)) { for (MatchPlayer matchPlayer: match.getPlayers()) {
wins = mPlayer.getWins(); if (matchPlayer.getPlayer().equals(you)) {
loses = mPlayer.getLoses(); wins = matchPlayer.getWins();
} }
if (mPlayer.getWins() == winsNeeded) { if (matchPlayer.isMatchWinner()) {
nameMatchWinner = mPlayer.getName(); matchWinner = matchPlayer;
}
if (matchPlayer.hasTimerTimeout()) {
if (matchPlayer.getPlayer().equals(you)) {
additonalText.append("You run out of time. ");
} else {
additonalText.append(matchPlayer.getName()).append(" runs out of time. ");
}
} else if (matchPlayer.hasQuit()) {
if (matchPlayer.getPlayer().equals(you)) {
additonalText.append("You have quit the match. ");
} else {
additonalText.append(matchPlayer.getName()).append(" has quit the match. ");
}
} else if (matchPlayer.getPlayer().hasIdleTimeout()) {
if (matchPlayer.getPlayer().equals(you)) {
additonalText.append("You lost the match for beeing idle. ");
} else {
additonalText.append(matchPlayer.getName()).append(" lost for beeing idle. ");
}
} }
} }
if (matchWinner != null) {
if (matchWinner.getPlayer().equals(you)) {
matchInfo = "You won the match!";
} else {
matchInfo = new StringBuilder(matchWinner.getName()).append(" won the match!").toString();
}
} else {
matchInfo = new StringBuilder("You need ").append(winsNeeded - wins == 1 ? "one more win ":winsNeeded - wins + " more wins ").append("to win the match.").toString();
}
additionalInfo = additonalText.toString();
} }
public Date getStartTime() { public Date getStartTime() {
@ -112,8 +143,16 @@ public class GameEndView implements Serializable {
return players; return players;
} }
public String getResultMessage() { public String getGameInfo() {
return resultMessage; return gameInfo;
}
public String getMatchInfo() {
return matchInfo;
}
public String getAdditionalInfo() {
return additionalInfo;
} }
public boolean hasWon() { public boolean hasWon() {
@ -136,10 +175,6 @@ public class GameEndView implements Serializable {
return winsNeeded; return winsNeeded;
} }
public String getNameMatchWinner() {
return nameMatchWinner;
}
public PlayerView getClientPlayer() { public PlayerView getClientPlayer() {
return clientPlayer; return clientPlayer;
} }