Show in start turn panel if a player has redealed or drawn the last stone
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@570 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
62a55c0a91
commit
d6c4da6224
20 changed files with 358 additions and 252 deletions
|
@ -61,6 +61,10 @@ public interface IView {
|
|||
*/
|
||||
public void setCurrentPlayerName(String playerName);
|
||||
|
||||
public void setRedealedPlayerName(String name);
|
||||
|
||||
public void setLastStonePlayerName(String name);
|
||||
|
||||
/**
|
||||
* Sets the stones that are to be painted selected
|
||||
*
|
||||
|
@ -368,6 +372,10 @@ public interface IView {
|
|||
/** */
|
||||
START_TURN_PANEL,
|
||||
/** */
|
||||
START_REDEAL_TURN_PANEL,
|
||||
/** */
|
||||
START_LAST_TURN_PANEL,
|
||||
/** */
|
||||
INVALID_TURN_PANEL,
|
||||
/** */
|
||||
HUMAN_HAND_PANEL,
|
||||
|
|
|
@ -23,17 +23,23 @@ import jrummikub.view.IView.BottomPanelType;
|
|||
class StartTurnPanel extends JPanel {
|
||||
private final static int PANEL_INSET = 15;
|
||||
private final static int PANEL_SEPARATOR = 10;
|
||||
private final static float PANEL_FIRST_LINE_HEIGHT = 0.375f;
|
||||
private final static float PANEL_FIRST_LINE_HEIGHT = 0.2f;
|
||||
private final static int PANEL_MAX_WIDTH = 180;
|
||||
private final static float MAX_BUTTON_FONT_SIZE = 12;
|
||||
|
||||
private JLabel startTurnLabel;
|
||||
private JLabel extraLabel;
|
||||
private JButton startTurnButton;
|
||||
|
||||
private Event startTurnEvent = new Event();
|
||||
private Event acknowledgeInvalidEvent = new Event();
|
||||
|
||||
private Event buttonEvent = startTurnEvent;
|
||||
private BottomPanelType type;
|
||||
private Color currentPlayerColor;
|
||||
private String currentPlayerName;
|
||||
private String redealedPlayerName;
|
||||
private String lastStonePlayerName;
|
||||
|
||||
/**
|
||||
* Creates a new StartTurnPanel
|
||||
|
@ -49,6 +55,12 @@ class StartTurnPanel extends JPanel {
|
|||
startTurnLabel.putClientProperty("html.disable", Boolean.TRUE);
|
||||
add(startTurnLabel);
|
||||
|
||||
extraLabel = new JLabel();
|
||||
extraLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
extraLabel.setVerticalAlignment(JLabel.CENTER);
|
||||
extraLabel.putClientProperty("html.disable", Boolean.TRUE);
|
||||
add(extraLabel);
|
||||
|
||||
startTurnButton = new JButton("Zug beginnen");
|
||||
startTurnButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
|
@ -66,14 +78,6 @@ class StartTurnPanel extends JPanel {
|
|||
});
|
||||
}
|
||||
|
||||
void setCurrentPlayerName(String playerName) {
|
||||
startTurnLabel.setText(playerName + " ist jetzt an der Reihe.");
|
||||
}
|
||||
|
||||
void setCurrentPlayerColor(Color color) {
|
||||
startTurnLabel.setIcon(ImageUtil.createColorIcon(color, 12, 1));
|
||||
}
|
||||
|
||||
void setInitialMeldError(int points) {
|
||||
startTurnLabel.setIcon(null);
|
||||
startTurnLabel.setText("Es wurden weniger als " + points
|
||||
|
@ -105,34 +109,83 @@ class StartTurnPanel extends JPanel {
|
|||
|
||||
int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT);
|
||||
int buttonWidth = width;
|
||||
int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight;
|
||||
int buttonHeight = height - 2 * PANEL_SEPARATOR - 2 * firstLineHeight;
|
||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
|
||||
startTurnLabel.setBounds(x, y, width, firstLineHeight);
|
||||
startTurnButton.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR,
|
||||
if (type == BottomPanelType.START_REDEAL_TURN_PANEL
|
||||
|| type == BottomPanelType.START_LAST_TURN_PANEL) {
|
||||
startTurnLabel.setBounds(x, y, width, firstLineHeight);
|
||||
extraLabel.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR, width,
|
||||
firstLineHeight);
|
||||
extraLabel.setVisible(true);
|
||||
} else {
|
||||
startTurnLabel.setBounds(x, y, width, 2 * firstLineHeight
|
||||
+ PANEL_SEPARATOR);
|
||||
extraLabel.setVisible(false);
|
||||
}
|
||||
startTurnButton.setBounds(x, y + 2 * firstLineHeight + 2 * PANEL_SEPARATOR,
|
||||
buttonWidth, buttonHeight);
|
||||
startTurnButton.setFont(startTurnButton.getFont().deriveFont(fontSize));
|
||||
}
|
||||
|
||||
public void setType(BottomPanelType type) {
|
||||
void setCurrentPlayerName(String playerName) {
|
||||
currentPlayerName = playerName;
|
||||
update();
|
||||
}
|
||||
|
||||
void setCurrentPlayerColor(Color color) {
|
||||
currentPlayerColor = color;
|
||||
update();
|
||||
}
|
||||
|
||||
void setRedealedPlayerName(String name) {
|
||||
redealedPlayerName = name;
|
||||
update();
|
||||
}
|
||||
|
||||
void setLastStonePlayerName(String name) {
|
||||
lastStonePlayerName = name;
|
||||
update();
|
||||
}
|
||||
|
||||
void setType(BottomPanelType type) {
|
||||
this.type = type;
|
||||
update();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
startTurnLabel
|
||||
.setIcon(ImageUtil.createColorIcon(currentPlayerColor, 12, 1));
|
||||
startTurnLabel.setText(currentPlayerName + " ist jetzt an der Reihe.");
|
||||
extraLabel.setText("");
|
||||
startTurnButton.setText("Zug beginnen");
|
||||
buttonEvent = startTurnEvent;
|
||||
|
||||
switch (type) {
|
||||
case START_TURN_PANEL:
|
||||
startTurnButton.setText("Zug beginnen");
|
||||
buttonEvent = startTurnEvent;
|
||||
break;
|
||||
case INVALID_TURN_PANEL:
|
||||
startTurnLabel.setIcon(null);
|
||||
startTurnLabel.setText("Es liegen ung\u00FCltige Serien auf dem Tisch.");
|
||||
startTurnButton.setText("N\u00E4chster Spieler");
|
||||
buttonEvent = acknowledgeInvalidEvent;
|
||||
break;
|
||||
case START_REDEAL_TURN_PANEL:
|
||||
extraLabel.setText(redealedPlayerName + " hat neu geben lassen.");
|
||||
break;
|
||||
|
||||
case START_LAST_TURN_PANEL:
|
||||
extraLabel.setText(lastStonePlayerName
|
||||
+ " hat den letzten Stein gezogen.");
|
||||
break;
|
||||
|
||||
case INVALID_TURN_PANEL:
|
||||
startTurnLabel.setIcon(null);
|
||||
startTurnLabel
|
||||
.setText("Es liegen ung\u00FCltige Serien auf dem Tisch.");
|
||||
startTurnButton.setText("N\u00E4chster Spieler");
|
||||
buttonEvent = acknowledgeInvalidEvent;
|
||||
break;
|
||||
}
|
||||
|
||||
rescale();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -581,6 +581,16 @@ public class View extends JFrame implements IView {
|
|||
pausePanel.setCurrentPlayerColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRedealedPlayerName(String name) {
|
||||
startTurnPanel.setRedealedPlayerName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastStonePlayerName(String name) {
|
||||
startTurnPanel.setLastStonePlayerName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentPlayerHasLaidOut(boolean hasLaidOut) {
|
||||
playerPanel.setHasLaidOut(hasLaidOut);
|
||||
|
@ -657,7 +667,9 @@ public class View extends JFrame implements IView {
|
|||
}
|
||||
|
||||
private void doSetBottomPanel(BottomPanelType type) {
|
||||
boolean showStartTurnPanel = (type == BottomPanelType.START_TURN_PANEL || type == BottomPanelType.INVALID_TURN_PANEL);
|
||||
boolean showStartTurnPanel = (type == BottomPanelType.START_TURN_PANEL
|
||||
|| type == BottomPanelType.START_REDEAL_TURN_PANEL
|
||||
|| type == BottomPanelType.START_LAST_TURN_PANEL || type == BottomPanelType.INVALID_TURN_PANEL);
|
||||
startTurnPanel.setType(type);
|
||||
startTurnPanel.setVisible(showStartTurnPanel);
|
||||
|
||||
|
|
Reference in a new issue