Disable pause function in network mode

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@536 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-06-21 03:52:25 +02:00
parent 9b5f3648ed
commit b62babba45
9 changed files with 117 additions and 89 deletions

View file

@ -76,6 +76,11 @@ public class RoundControl {
private Event1<Score> endOfRoundEvent = new Event1<Score>();
protected List<Connection> connections = new ArrayList<Connection>();
private boolean roundFinished;
private boolean mayPause;
public RoundControl(IRoundState roundState, IView view) {
this(roundState, view, true);
}
/**
* Create a new RoundControl using the given gameState and view
@ -85,9 +90,10 @@ public class RoundControl {
* @param view
* view used for user interaction
*/
public RoundControl(IRoundState roundState, IView view) {
protected RoundControl(IRoundState roundState, IView view, boolean mayPause) {
this.roundState = roundState;
this.view = view;
this.mayPause = mayPause;
}
/**
@ -221,7 +227,8 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(turnMode);
}
turnControl.setup(new ITurnControl.TurnInfo(roundState, turnMode),
turnControl.setup(
new ITurnControl.TurnInfo(roundState, turnMode, mayPause),
roundState.getGameSettings(), view);
turnControl.getEndOfTurnEvent().add(
new IListener2<IRoundState, InvalidTurnInfo>() {

View file

@ -15,7 +15,7 @@ public class NetworkRoundControl extends RoundControl {
public NetworkRoundControl(IRoundState roundState, IView view,
final IConnectionControl connectionControl, boolean startActive) {
super(roundState, view);
super(roundState, view, false);
this.connectionControl = connectionControl;
currentlyActive = startActive;

View file

@ -53,8 +53,4 @@ public class NetworkTurnControl extends AbstractTurnControl {
@Override
protected void timeOut() {
}
@Override
protected void pauseTurn() {
}
}

View file

@ -59,6 +59,10 @@ public abstract class AbstractTurnControl implements ITurnControl {
}
protected void pauseTurn() {
if (!turnInfo.isMayPause()) {
return;
}
timer.stopTimer();
view.enablePauseMode(true);
}
@ -108,6 +112,8 @@ public abstract class AbstractTurnControl implements ITurnControl {
resumeTurn();
}
}));
view.setMayPause(info.isMayPause());
}
protected void cleanUp() {

View file

@ -73,6 +73,8 @@ public interface ITurnControl {
private TurnMode turnMode;
private boolean mayPause;
/**
* Creates a new TurnInfo instance
*
@ -81,7 +83,7 @@ public interface ITurnControl {
* @param turnMode
* the turn mode
*/
public TurnInfo(IRoundState roundState, TurnMode turnMode) {
public TurnInfo(IRoundState roundState, TurnMode turnMode, boolean mayPause) {
this.roundState = roundState;
oldTable = roundState.getTable();
@ -91,6 +93,8 @@ public interface ITurnControl {
this.hand = (IHand) oldHand.clone();
this.turnMode = turnMode;
this.mayPause = mayPause;
}
public IRoundState getRoundState() {
@ -150,5 +154,9 @@ public interface ITurnControl {
public TurnMode getTurnMode() {
return turnMode;
}
public boolean isMayPause() {
return mayPause;
}
}
}

View file

@ -57,7 +57,7 @@ public interface IView {
* Sets the current player's name
*
* @param playerName
* the player name
* the player name
*/
public void setCurrentPlayerName(String playerName);
@ -65,7 +65,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);
@ -102,7 +102,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);
@ -110,7 +110,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);
@ -119,16 +119,16 @@ 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 setCurrentPlayerHasLaidOut(boolean hasLaidOut);
@ -143,13 +143,13 @@ public interface IView {
* Sets the bottom panels type
*
* @param type
* the type of the bottom panel
* the type of the bottom panel
*/
public void setBottomPanel(BottomPanelType type);
/**
* The menu new game event is emitted when the user selects the new game
* menu entry
* The menu new game event is emitted when the user selects the new game menu
* entry
*
* @return the event
*/
@ -224,7 +224,7 @@ public interface IView {
* Show/hide login panel
*
* @param show
* true = login panel is shown
* true = login panel is shown
*/
public void showLoginPanel(boolean show);
@ -232,7 +232,7 @@ public interface IView {
* Enable/disable pause mode
*
* @param enable
* true = enable
* true = enable
*/
public void enablePauseMode(boolean enable);
@ -240,7 +240,7 @@ public interface IView {
* Show/hide game list panel
*
* @param show
* true = show
* true = show
*/
public void showGameListPanel(boolean show);
@ -248,7 +248,7 @@ public interface IView {
* Show/hide side panel
*
* @param show
* true to show
* true to show
*/
void showSidePanel(boolean show);
@ -256,7 +256,7 @@ public interface IView {
* Is set if a player tried to lay out less than initial meld threshold
*
* @param points
* initial meld threshold
* initial meld threshold
*/
public void setInitialMeldError(int points);
@ -264,7 +264,7 @@ public interface IView {
* Show stone collection
*
* @param enable
* showing collection
* showing collection
*/
public void setStoneCollectionHidden(boolean enable);
@ -277,7 +277,7 @@ public interface IView {
* Set invalid sets to enable showing
*
* @param sets
* invalid sets on table
* invalid sets on table
*/
public void setInvalidStoneSets(Collection<StoneSet> sets);
@ -290,7 +290,7 @@ public interface IView {
* Enables/disables saving in menu bar
*
* @param enable
* saving possible
* saving possible
*/
public void enableSave(boolean enable);
@ -298,7 +298,7 @@ public interface IView {
* Sets the quit warning panel visible
*
* @param show
* is visible
* is visible
*/
public void showQuitWarningPanel(boolean show);
@ -333,7 +333,7 @@ public interface IView {
* Set the connect panel visible
*
* @param show
* is visible
* is visible
*/
public void showConnectPanel(boolean show);
@ -344,6 +344,8 @@ public interface IView {
*/
public IConnectPanel getConnectPanel();
public void setMayPause(boolean mayPause);
/**
* Different types of bottom panels
*/

View file

@ -6,6 +6,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.text.DecimalFormat;
import java.util.Collections;
@ -60,6 +61,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private Event redealEvent = new Event();
private Event pauseEvent = new Event();
private int leftPanelWidth;
private boolean mayPause = true;
private ComponentListener leftPanelResizeListener = new LeftPanelResizeListener();
private ComponentListener rightPanelResizeListener = new RightPanelResizeListener();
HandPanel getHandPanel() {
return hand;
@ -157,7 +162,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
}
});
leftPanel.addComponentListener(new LeftPanelResizeListener());
leftPanel.addComponentListener(leftPanelResizeListener);
}
private void createRightPanel() {
@ -188,7 +193,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
createRightPanelButtons();
rightPanel.addComponentListener(new RightPanelResizeListener());
rightPanel.addComponentListener(rightPanelResizeListener);
}
private void createRightPanelButtons() {
@ -237,7 +242,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
Insets insets = getInsets();
int x = insets.left, y = insets.top, width = getWidth() - insets.left
- insets.right, height = getHeight() - insets.top - insets.bottom;
int boardWidth = hand.rescale(height);
int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO);
int meanPanelWidth = (width - boardWidth) / 2;
@ -252,7 +257,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
leftPanel.validate();
rightPanel.validate();
}
int getLeftPanelWidth() {
return leftPanelWidth;
}
@ -342,6 +347,11 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
hand.setEnabled(enable);
}
void setMayPause(boolean mayPause) {
this.mayPause = mayPause;
rightPanelResizeListener.componentResized(null);
}
private class LeftPanelResizeListener extends ComponentAdapter {
@Override
public void componentResized(ComponentEvent e) {
@ -427,12 +437,17 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
}
private void rescaleTimeBar(int x, int y, int width, int firstLineHeight) {
timeBar.setBounds(x, y, width - firstLineHeight - SIDE_PANEL_SEPARATOR,
firstLineHeight);
pauseButton.setBounds(x + width - firstLineHeight, y, firstLineHeight,
firstLineHeight);
pauseButton.setIcon(ImageUtil
.createPauseIcon((int) (firstLineHeight * 0.5f)));
if (mayPause) {
timeBar.setBounds(x, y, width - firstLineHeight - SIDE_PANEL_SEPARATOR,
firstLineHeight);
pauseButton.setBounds(x + width - firstLineHeight, y, firstLineHeight,
firstLineHeight);
pauseButton.setIcon(ImageUtil
.createPauseIcon((int) (firstLineHeight * 0.5f)));
} else {
timeBar.setBounds(x, y, width, firstLineHeight);
pauseButton.setBounds(0, 0, 0, 0);
}
}
private void rescaleUpDownButtons(int handButtonWidth, float fontSize) {

View file

@ -123,22 +123,14 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
void createPauseStoneSets() {
pauseStoneSets = new ArrayList<Pair<StoneSet, Position>>();
Stone stoneCoffee1 = new Stone(-'\u2615', StoneColor.BLACK);
Stone stoneP = new Stone(-'P', StoneColor.BLACK);
Stone stonea = new Stone(-'a', StoneColor.ORANGE);
Stone stoneu = new Stone(-'u', StoneColor.BLUE);
Stone stones = new Stone(-'s', StoneColor.RED);
Stone stonee = new Stone(-'e', StoneColor.BLACK);
Stone stoneCoffee2 = new Stone(-'\u2615', StoneColor.RED);
pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(stoneCoffee1),
new Position(-4, 0)));
pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(Arrays.asList(
stoneP, stonea, stoneu, stones, stonee)), new Position(-2.5, 0)));
pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(stoneCoffee2),
new Position(3, 0)));
}
/**

View file

@ -193,8 +193,7 @@ public class View extends JFrame implements IView {
showSettingsPanel(false);
showLoginPanel(false);
showGameListPanel(false);
getHandPanel().setStones(
Collections.<Pair<Stone, Position>> emptyList());
getHandPanel().setStones(Collections.<Pair<Stone, Position>> emptyList());
getTablePanel().setStoneSets(
Collections.<Pair<StoneSet, Position>> emptyList());
setSelectedStones(Collections.<Stone> emptyList());
@ -321,6 +320,7 @@ public class View extends JFrame implements IView {
public void componentResized(ComponentEvent e) {
rescale();
}
@Override
public void componentMoved(ComponentEvent e) {
quitWarningFrame.setLocationRelativeTo(View.this);
@ -355,10 +355,10 @@ public class View extends JFrame implements IView {
quitWarningFrame.add(quitWarningPanel);
quitWarningFrame.setAlwaysOnTop(true);
quitWarningFrame.setUndecorated(true);
//layeredPane.setLayer(quitWarningPanel, JLayeredPane.POPUP_LAYER);
//layeredPane.add(quitWarningPanel);
//quitWarningPanel.setVisible(true);
// layeredPane.setLayer(quitWarningPanel, JLayeredPane.POPUP_LAYER);
// layeredPane.add(quitWarningPanel);
// quitWarningPanel.setVisible(true);
scorePanel = new ScorePanel();
scorePanel.setVisible(false);
layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER);
@ -390,8 +390,7 @@ public class View extends JFrame implements IView {
table = new TablePanel();
mainLayer.add(table);
table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0,
Color.BLACK));
table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.BLACK));
playerPanel = new PlayerPanel();
mainLayer.add(playerPanel);
@ -411,9 +410,14 @@ public class View extends JFrame implements IView {
sidePanel = new SidePanel();
sidePanel.setVisible(false);
mainLayer.add(sidePanel);
sidePanel.setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1,
Color.BLACK), new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0,
Color.GRAY)));
sidePanel
.setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK),
new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.GRAY)));
}
@Override
public void setMayPause(boolean mayPause) {
playerPanel.setMayPause(mayPause);
}
@Override
@ -525,15 +529,14 @@ public class View extends JFrame implements IView {
public void showQuitWarningPanel(boolean show) {
quitWarningFrame.setLocationRelativeTo(this);
quitWarningFrame.setVisible(show);
setEnabled(!show);
/*mainLayer.setEnabled(!show);
menuBar.setEnabled(!show);
settingsPanel.setEnabled(!show);
loginPanel.setEnabled(!show);
scorePanel.setEnabled(!show);
gameListPanel.setEnabled(!show);
connectPanel.setEnabled(!show);*/
/*
* mainLayer.setEnabled(!show); menuBar.setEnabled(!show);
* settingsPanel.setEnabled(!show); loginPanel.setEnabled(!show);
* scorePanel.setEnabled(!show); gameListPanel.setEnabled(!show);
* connectPanel.setEnabled(!show);
*/
}
@Override
@ -597,24 +600,24 @@ public class View extends JFrame implements IView {
@SuppressWarnings("unchecked")
private List<Pair<Stone, Position>> createDecorationStones() {
Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(
-'J', StoneColor.BLACK), new Position(2.5f, 0));
Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(
-'R', StoneColor.ORANGE), new Position(3.5f, 0));
Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(
-'u', StoneColor.BLUE), new Position(4.5f, 0));
Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(
-'m', StoneColor.RED), new Position(5.5f, 0));
Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(
-'m', StoneColor.GREEN), new Position(6.5f, 0));
Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(
-'i', StoneColor.VIOLET), new Position(7.5f, 0));
Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(
-'k', StoneColor.AQUA), new Position(8.5f, 0));
Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(
-'u', StoneColor.GRAY), new Position(9.5f, 0));
Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(
-'b', StoneColor.BLACK), new Position(10.5f, 0));
Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(-'J',
StoneColor.BLACK), new Position(2.5f, 0));
Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(-'R',
StoneColor.ORANGE), new Position(3.5f, 0));
Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(-'u',
StoneColor.BLUE), new Position(4.5f, 0));
Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(-'m',
StoneColor.RED), new Position(5.5f, 0));
Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(-'m',
StoneColor.GREEN), new Position(6.5f, 0));
Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(-'i',
StoneColor.VIOLET), new Position(7.5f, 0));
Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(-'k',
StoneColor.AQUA), new Position(8.5f, 0));
Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(-'u',
StoneColor.GRAY), new Position(9.5f, 0));
Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(-'b',
StoneColor.BLACK), new Position(10.5f, 0));
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(2, 1));
@ -629,9 +632,9 @@ public class View extends JFrame implements IView {
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(11, 1));
return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei,
stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4,
stone5, stone6);
return Arrays
.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek,
stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6);
}
@Override
@ -650,8 +653,7 @@ public class View extends JFrame implements IView {
&& type != BottomPanelType.WIN_PANEL && type != null);
if (type == BottomPanelType.START_GAME_PANEL) {
table.setStoneSets(Collections
.<Pair<StoneSet, Position>> emptyList());
table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList());
playerPanel.getHandPanel().setStones(createDecorationStones());
}