View: Refactor bottom panel display

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@354 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-31 18:25:47 +02:00
parent 03b3bf2340
commit bc04d21afb
10 changed files with 122 additions and 186 deletions

View file

@ -4,6 +4,7 @@ import jrummikub.model.GameSettings;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.view.IView;
import jrummikub.view.IView.BottomPanelType;
/**
* The application control controls the settings for a new games and create the
@ -27,8 +28,7 @@ public class ApplicationControl {
*/
public void startApplication() {
view.showScorePanel(false);
view.enableWinPanel(false);
view.showInterface(false);
view.setBottomPanel(BottomPanelType.START_GAME_PANEL);
SettingsControl settingsControl = new SettingsControl(view,
new GameSettings());
settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
@ -42,7 +42,6 @@ public class ApplicationControl {
startApplication();
}
});
view.showInterface(true);
gameControl.startGame();
}

View file

@ -14,6 +14,7 @@ import jrummikub.util.IEvent;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.view.IView;
import jrummikub.view.IView.BottomPanelType;
/**
* Controls a Game, at some point including all Rounds, starts new Rounds
@ -128,7 +129,7 @@ public class GameControl {
gameState.getScores().add(roundScore);
roundControl = null;
view.enableWinPanel(true);
view.setBottomPanel(BottomPanelType.WIN_PANEL);
view.getScorePanel().setPlayers(gameSettings.getPlayerList());
view.getScorePanel().setScores(gameState.getScores());

View file

@ -1,5 +1,7 @@
package jrummikub.control;
import static jrummikub.control.turn.TurnControlFactory.Type.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@ -7,7 +9,6 @@ import java.util.Set;
import jrummikub.control.turn.ITurnControl;
import jrummikub.control.turn.TurnControlFactory;
import static jrummikub.control.turn.TurnControlFactory.Type.*;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
import jrummikub.model.IPlayer;
@ -25,6 +26,7 @@ import jrummikub.util.IEvent1;
import jrummikub.util.IListener;
import jrummikub.util.Pair;
import jrummikub.view.IView;
import jrummikub.view.IView.BottomPanelType;
/**
* Controller that manages a single round of rummikub
@ -82,18 +84,15 @@ public class RoundControl {
.getTurnControlType() == HUMAN;
clonedTable = (ITable) roundState.getTable().clone();
if (isHuman) {
view.enableStartTurnPanel(true);
} else {
view.enableThinkPanel(true);
}
view.setBottomPanel(isHuman ? BottomPanelType.START_TURN_PANEL
: BottomPanelType.COMPUTER_HAND_PANEL);
view.getTablePanel().setStoneSets(clonedTable.clone());
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
.getName());
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()
.getColor());
view.setHasLaidOut(roundState.getActivePlayer().getLaidOut());
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut());
if (!isHuman)
startTurn();
@ -156,7 +155,6 @@ public class RoundControl {
}
private void endOfTurn() {
view.enableThinkPanel(false);
turnControl = null;
if (roundState.getTurnNumber() >= 1) {
checkTurn();

View file

@ -18,6 +18,7 @@ import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.IListener2;
import jrummikub.util.Pair;
import jrummikub.view.IView.BottomPanelType;
/**
* Controller for a single turn made by a human player
@ -87,7 +88,7 @@ public class HumanTurnControl extends AbstractTurnControl {
view.getHandPanel().setStones(hand.clone());
view.getHandPanel().resetCurrentRow();
view.enableStartTurnPanel(false);
view.setBottomPanel(BottomPanelType.HUMAN_HAND_PANEL);
timer.startTimer();
}

View file

@ -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,18 +55,10 @@ 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);
/**
* Enables or disables the player's StartTurnPanel
*
* @param enable
* enable/disable
*/
public void enableStartTurnPanel(boolean enable);
/**
* The start turn event is emitted when the player wants to start his turn
*
@ -74,14 +66,6 @@ public interface IView {
*/
public IEvent getStartTurnEvent();
/**
* Enables or disables the panel shown when a player has won
*
* @param enable
* enable/disable
*/
public void enableWinPanel(boolean enable);
/**
* The quit event is emitted when the player wants to quit the game
*
@ -100,7 +84,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 +92,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);
@ -117,40 +101,29 @@ public interface IView {
* along with the name
*
* @param color
* the current player's 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
* specifies if the current player has laid out or not
* specifies if the current player has laid out or not
*/
public void setHasLaidOut(boolean hasLaidOut);
public void setCurrentPlayerHasLaidOut(boolean hasLaidOut);
/**
* Is emitted if the player wants to end the game and start a new one
*
* @return newGameEvent
*/
IEvent getNewGameEvent();
public 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);
public void setBottomPanel(BottomPanelType type);
/**
* Enables or disables the panel shown while the computer player is making a
* move
*
* @param b
* specifies if the interface is enabled or disabled
*/
public void enableThinkPanel(boolean b);
public enum BottomPanelType {
START_GAME_PANEL, START_TURN_PANEL, HUMAN_HAND_PANEL, COMPUTER_HAND_PANEL, WIN_PANEL
}
}

View file

@ -160,19 +160,15 @@ public class View extends JFrame implements IView {
playerPanel.getHandPanel().setSelectedStones(stones);
}
@Override
public void enableStartTurnPanel(boolean enable) {
playerPanel.setVisible(!enable);
startTurnPanel.setVisible(enable);
winPanel.setVisible(false);
}
@Override
public void enableWinPanel(boolean enable) {
playerPanel.setVisible(!enable);
startTurnPanel.setVisible(false);
winPanel.setVisible(enable);
}
/*
* @Override public void enableStartTurnPanel(boolean enable) {
* playerPanel.setVisible(!enable); startTurnPanel.setVisible(enable);
* winPanel.setVisible(false); }
*
* @Override public void enableWinPanel(boolean enable) {
* playerPanel.setVisible(!enable); startTurnPanel.setVisible(false);
* winPanel.setVisible(enable); }
*/
@Override
public void showSettingsPanel(boolean show) {
@ -196,7 +192,7 @@ public class View extends JFrame implements IView {
}
@Override
public void setHasLaidOut(boolean hasLaidOut) {
public void setCurrentPlayerHasLaidOut(boolean hasLaidOut) {
playerPanel.setHasLaidOut(hasLaidOut);
}
@ -260,19 +256,18 @@ public class View extends JFrame implements IView {
}
@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);
}
}
public void setBottomPanel(BottomPanelType type) {
startTurnPanel.setVisible(type == BottomPanelType.START_TURN_PANEL);
winPanel.setVisible(type == BottomPanelType.WIN_PANEL);
playerPanel.setVisible(type != BottomPanelType.START_TURN_PANEL
&& type != BottomPanelType.WIN_PANEL);
@Override
public void enableThinkPanel(boolean enable) {
playerPanel.enableButtons(!enable);
if (type == BottomPanelType.START_GAME_PANEL) {
table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList());
playerPanel.getHandPanel().setStones(createDecorationStones());
}
playerPanel.showButtons(type != BottomPanelType.START_GAME_PANEL);
playerPanel.enableButtons(type != BottomPanelType.COMPUTER_HAND_PANEL);
}
}