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:
parent
9b5f3648ed
commit
b62babba45
9 changed files with 117 additions and 89 deletions
|
@ -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>() {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -53,8 +53,4 @@ public class NetworkTurnControl extends AbstractTurnControl {
|
|||
@Override
|
||||
protected void timeOut() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void pauseTurn() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -124,8 +124,8 @@ public interface IView {
|
|||
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
|
||||
|
@ -148,8 +148,8 @@ public interface IView {
|
|||
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
|
||||
*/
|
||||
|
@ -344,6 +344,8 @@ public interface IView {
|
|||
*/
|
||||
public IConnectPanel getConnectPanel();
|
||||
|
||||
public void setMayPause(boolean mayPause);
|
||||
|
||||
/**
|
||||
* Different types of bottom panels
|
||||
*/
|
||||
|
|
|
@ -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() {
|
||||
|
@ -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) {
|
||||
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) {
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
@ -356,9 +356,9 @@ public class View extends JFrame implements IView {
|
|||
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
|
||||
|
@ -527,13 +531,12 @@ public class View extends JFrame implements IView {
|
|||
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());
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue