Disable player panel while settings panel is shown
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@313 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
e4a1246f01
commit
d6b8b23c6d
5 changed files with 106 additions and 47 deletions
|
@ -131,4 +131,10 @@ public class MockView implements IView {
|
|||
return newGameEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showInterface(boolean enable) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ public class ApplicationControl {
|
|||
public void startApplication() {
|
||||
view.showScorePanel(false);
|
||||
view.enableWinPanel(false);
|
||||
view.showInterface(false);
|
||||
SettingsControl settingsControl = new SettingsControl(view,
|
||||
new GameSettings());
|
||||
settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
|
||||
|
@ -41,6 +42,7 @@ public class ApplicationControl {
|
|||
startApplication();
|
||||
}
|
||||
});
|
||||
view.showInterface(true);
|
||||
gameControl.startGame();
|
||||
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public interface IView {
|
|||
* Sets the current player's name
|
||||
*
|
||||
* @param playerName
|
||||
* the player name
|
||||
* the player name
|
||||
*/
|
||||
public void setCurrentPlayerName(String playerName);
|
||||
|
||||
|
@ -55,7 +55,7 @@ public interface IView {
|
|||
* Sets the stones that are to be painted selected
|
||||
*
|
||||
* @param stones
|
||||
* the stones to be painted selected
|
||||
* the stones to be painted selected
|
||||
*/
|
||||
public void setSelectedStones(Collection<Stone> stones);
|
||||
|
||||
|
@ -63,7 +63,7 @@ public interface IView {
|
|||
* Enables or disables the player's StartTurnPanel
|
||||
*
|
||||
* @param enable
|
||||
* enable/disable
|
||||
* enable/disable
|
||||
*/
|
||||
public void enableStartTurnPanel(boolean enable);
|
||||
|
||||
|
@ -78,7 +78,7 @@ public interface IView {
|
|||
* Enables or disables the panel shown when a player has won
|
||||
*
|
||||
* @param enable
|
||||
* enable/disable
|
||||
* enable/disable
|
||||
*/
|
||||
public void enableWinPanel(boolean enable);
|
||||
|
||||
|
@ -100,7 +100,7 @@ public interface IView {
|
|||
* Shows or hides the game settings panel
|
||||
*
|
||||
* @param show
|
||||
* specifies if the panel shall be shown or hidden
|
||||
* specifies if the panel shall be shown or hidden
|
||||
*/
|
||||
public void showSettingsPanel(boolean show);
|
||||
|
||||
|
@ -108,7 +108,7 @@ public interface IView {
|
|||
* Shows or hides the score panel
|
||||
*
|
||||
* @param show
|
||||
* specifies if the panel shall be shown or hidden
|
||||
* specifies if the panel shall be shown or hidden
|
||||
*/
|
||||
public void showScorePanel(boolean show);
|
||||
|
||||
|
@ -116,15 +116,15 @@ public interface IView {
|
|||
* Is used for the PlayerPanel and ScorePanel to display a player's color
|
||||
* along with the name
|
||||
*
|
||||
* @param color
|
||||
* @param color the current player's color
|
||||
*/
|
||||
public void setCurrentPlayerColor(Color color);
|
||||
|
||||
/**
|
||||
* Is used for the PlayerPanel to display if a player has laid out along
|
||||
* with the name
|
||||
* Is used for the PlayerPanel to display if a player has laid out along with
|
||||
* the name
|
||||
*
|
||||
* @param hasLaidOut
|
||||
* @param hasLaidOut specifies if the current player has laid out or not
|
||||
*/
|
||||
public void setHasLaidOut(boolean hasLaidOut);
|
||||
|
||||
|
@ -134,4 +134,12 @@ public interface IView {
|
|||
* @return newGameEvent
|
||||
*/
|
||||
IEvent getNewGameEvent();
|
||||
|
||||
/**
|
||||
* Enables or disables most parts of the interface
|
||||
*
|
||||
* @param enable
|
||||
* specifies if the interface is to be enabled or disabled
|
||||
*/
|
||||
void showInterface(boolean enable);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
* Sets the current player name
|
||||
*
|
||||
* @param playerName
|
||||
* the player name
|
||||
* the player name
|
||||
*/
|
||||
void setCurrentPlayerName(String playerName) {
|
||||
currentPlayerNameLabel.setText(playerName);
|
||||
|
@ -129,8 +129,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
leftPanel.add(hasLaidOutLabel);
|
||||
|
||||
sortByGroupsButton = createButton(leftPanel,
|
||||
"<html><center>Nach Sammlungen sortieren",
|
||||
new ActionListener() {
|
||||
"<html><center>Nach Sammlungen sortieren", new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
sortByGroupsEvent.emit();
|
||||
|
@ -151,8 +150,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
private void createRightPanel() {
|
||||
rightPanel = new JPanel();
|
||||
rightPanel.setLayout(null);
|
||||
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET,
|
||||
SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
||||
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
||||
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
||||
|
||||
handRowUpButton = createButton(rightPanel, "<html><center>\u25B2",
|
||||
new ActionListener() {
|
||||
|
@ -213,8 +212,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
private void rescale() {
|
||||
Insets insets = getInsets();
|
||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||
- insets.right, height = getHeight() - insets.top
|
||||
- insets.bottom;
|
||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||
int boardWidth = hand.getWidth();
|
||||
int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO);
|
||||
int meanPanelWidth = (width - boardWidth) / 2;
|
||||
|
@ -223,8 +221,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
|
||||
leftPanel.setBounds(x, y, leftPanelWidth, height);
|
||||
hand.setBounds(x + leftPanelWidth, y, boardWidth, height);
|
||||
rightPanel.setBounds(x + leftPanelWidth + boardWidth, y,
|
||||
rightPanelWidth, height);
|
||||
rightPanel.setBounds(x + leftPanelWidth + boardWidth, y, rightPanelWidth,
|
||||
height);
|
||||
|
||||
leftPanel.validate();
|
||||
rightPanel.validate();
|
||||
|
@ -232,8 +230,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
|
||||
void updateButtons() {
|
||||
handRowUpButton.setEnabled(hand.canRowUp());
|
||||
handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK
|
||||
: Color.GRAY);
|
||||
handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK : Color.GRAY);
|
||||
handRowDownButton.setEnabled(hand.canRowDown());
|
||||
handRowDownButton.setForeground(hand.canRowDown() ? Color.BLACK
|
||||
: Color.GRAY);
|
||||
|
@ -272,8 +269,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
public void componentResized(ComponentEvent e) {
|
||||
Insets insets = leftPanel.getInsets();
|
||||
int x = insets.left, y = insets.top, width = leftPanel.getWidth()
|
||||
- insets.left - insets.right, height = leftPanel
|
||||
.getHeight() - insets.top - insets.bottom;
|
||||
- insets.left - insets.right, height = leftPanel.getHeight()
|
||||
- insets.top - insets.bottom;
|
||||
|
||||
if (width > SIDE_PANEL_MAX_WIDTH) {
|
||||
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
||||
|
@ -289,22 +286,18 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
|
||||
currentPlayerNameLabel.setBounds(x, y, width, oneLabelHeight);
|
||||
hasLaidOutLabel.setBounds(x, y + oneLabelHeight, width,
|
||||
oneLabelHeight);
|
||||
sortByGroupsButton.setBounds(x, y + labelHeight
|
||||
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR,
|
||||
y + labelHeight + SIDE_PANEL_SEPARATOR, buttonWidth,
|
||||
buttonHeight);
|
||||
hasLaidOutLabel.setBounds(x, y + oneLabelHeight, width, oneLabelHeight);
|
||||
sortByGroupsButton.setBounds(x, y + labelHeight + SIDE_PANEL_SEPARATOR,
|
||||
buttonWidth, buttonHeight);
|
||||
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
|
||||
+ labelHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||
|
||||
currentPlayerNameLabel.setFont(currentPlayerNameLabel.getFont()
|
||||
.deriveFont(fontSize));
|
||||
hasLaidOutLabel.setFont(hasLaidOutLabel.getFont().deriveFont(
|
||||
fontSize));
|
||||
hasLaidOutLabel.setFont(hasLaidOutLabel.getFont().deriveFont(fontSize));
|
||||
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
|
||||
fontSize));
|
||||
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(
|
||||
fontSize));
|
||||
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(fontSize));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,8 +321,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
int smallButtonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
|
||||
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||
float smallFontSize = (float) Math.sqrt(smallButtonWidth
|
||||
* buttonHeight) / 5;
|
||||
float smallFontSize = (float) Math.sqrt(smallButtonWidth * buttonHeight) / 5;
|
||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||
|
||||
|
@ -342,17 +334,16 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
fontSize * 1.5f));
|
||||
|
||||
timeBar.setBounds(x, y, width, firstLineHeight);
|
||||
endTurnButton.setBounds(x, y + firstLineHeight
|
||||
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
||||
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
||||
buttonWidth, buttonHeight);
|
||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
|
||||
|
||||
redealButton.setBounds(x, y + firstLineHeight
|
||||
+ SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
|
||||
redealButton.setFont(redealButton.getFont().deriveFont(
|
||||
smallFontSize));
|
||||
keepStonesButton.setBounds(x + smallButtonWidth
|
||||
+ SIDE_PANEL_SEPARATOR, y + firstLineHeight
|
||||
+ SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
|
||||
redealButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
||||
smallButtonWidth, buttonHeight);
|
||||
redealButton.setFont(redealButton.getFont().deriveFont(smallFontSize));
|
||||
keepStonesButton.setBounds(x + smallButtonWidth + SIDE_PANEL_SEPARATOR, y
|
||||
+ firstLineHeight + SIDE_PANEL_SEPARATOR, smallButtonWidth,
|
||||
buttonHeight);
|
||||
keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(
|
||||
smallFontSize));
|
||||
|
||||
|
@ -371,4 +362,20 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|||
keepStonesButton.setVisible(smallButtons);
|
||||
redealButton.setVisible(smallButtons);
|
||||
}
|
||||
|
||||
void showButtons(boolean show) {
|
||||
currentPlayerNameLabel.setVisible(show);
|
||||
hasLaidOutLabel.setVisible(show);
|
||||
sortByGroupsButton.setVisible(show);
|
||||
sortByRunsButton.setVisible(show);
|
||||
timeBar.setVisible(show);
|
||||
|
||||
if (!show) {
|
||||
handRowDownButton.setEnabled(false);
|
||||
handRowUpButton.setEnabled(false);
|
||||
endTurnButton.setVisible(false);
|
||||
redealButton.setVisible(false);
|
||||
keepStonesButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,22 @@ import java.awt.Color;
|
|||
import java.awt.Insets;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.MatteBorder;
|
||||
|
||||
import jrummikub.model.Position;
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.model.StoneColor;
|
||||
import jrummikub.model.StoneSet;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.util.Pair;
|
||||
import jrummikub.view.IHandPanel;
|
||||
import jrummikub.view.IPlayerPanel;
|
||||
import jrummikub.view.IScorePanel;
|
||||
|
@ -90,8 +97,8 @@ public class View extends JFrame implements IView {
|
|||
mainLayer.add(table);
|
||||
|
||||
playerPanel = new PlayerPanel();
|
||||
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
|
||||
0, Color.BLACK));
|
||||
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
|
||||
Color.BLACK));
|
||||
mainLayer.add(playerPanel);
|
||||
|
||||
startTurnPanel = new StartTurnPanel();
|
||||
|
@ -214,4 +221,33 @@ public class View extends JFrame implements IView {
|
|||
return winPanel.getEndProgramEvent();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Pair<Stone, Position>> createDecorationStones() {
|
||||
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
|
||||
StoneColor.RED), new Position(3.5f, 0));
|
||||
Pair<Stone, Position> stone2 = new Pair<Stone, Position>(new Stone(13,
|
||||
StoneColor.BLACK), new Position(5, 0));
|
||||
Pair<Stone, Position> stone3 = new Pair<Stone, Position>(new Stone(13,
|
||||
StoneColor.ORANGE), new Position(6, 0));
|
||||
Pair<Stone, Position> stone4 = new Pair<Stone, Position>(new Stone(13,
|
||||
StoneColor.BLUE), new Position(7, 0));
|
||||
Pair<Stone, Position> stone5 = new Pair<Stone, Position>(new Stone(13,
|
||||
StoneColor.RED), new Position(8, 0));
|
||||
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
|
||||
StoneColor.BLACK), new Position(9.5f, 0));
|
||||
|
||||
return Arrays.asList(stone1, stone2, stone3, stone4, stone5, stone6);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showInterface(boolean enable) {
|
||||
if (enable) {
|
||||
playerPanel.showButtons(true);
|
||||
} else {
|
||||
List<Pair<StoneSet, Position>> emptyTable = Collections.emptyList();
|
||||
table.setStoneSets(emptyTable);
|
||||
playerPanel.getHandPanel().setStones(createDecorationStones());
|
||||
playerPanel.showButtons(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue