diff options
Diffstat (limited to 'src/jrummikub/view/impl/View.java')
-rw-r--r-- | src/jrummikub/view/impl/View.java | 87 |
1 files changed, 59 insertions, 28 deletions
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index a6e5efe..8f67433 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -53,10 +53,13 @@ public class View extends JFrame implements IView { private TablePanel table; private PlayerPanel playerPanel; private StartTurnPanel startTurnPanel; + private PausePanel pausePanel; private WinPanel winPanel; private SettingsPanel settingsPanel; private ScorePanel scorePanel; + private BottomPanelType bottomPanelType; + private JFileChooser chooser; private Event menuNewGameEvent = new Event(); @@ -115,11 +118,20 @@ public class View extends JFrame implements IView { } @Override + public IEvent getPauseEvent() { + return playerPanel.getPauseEvent(); + } + + @Override + public IEvent getEndPauseEvent() { + return pausePanel.getEndPauseEvent(); + } + + @Override public void clearView() { showScorePanel(false); showSettingsPanel(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()); @@ -219,14 +231,18 @@ 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(); startTurnPanel.setVisible(false); mainLayer.add(startTurnPanel); + pausePanel = new PausePanel(); + pausePanel.setVisible(false); + mainLayer.add(pausePanel); + winPanel = new WinPanel(); winPanel.setVisible(false); mainLayer.add(winPanel); @@ -251,6 +267,14 @@ public class View extends JFrame implements IView { setVisible(true); } + @Override + public void enablePauseMode(boolean enable) { + table.enablePauseMode(enable); + + doSetBottomPanel(enable ? null : bottomPanelType); + pausePanel.setVisible(enable); + } + private void rescale() { int width = getContentPane().getWidth(), height = getContentPane() .getHeight(); @@ -270,6 +294,7 @@ public class View extends JFrame implements IView { table.validate(); playerPanel.setBounds(0, tableHeight, width, playerPanelHeight); startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight); + pausePanel.setBounds(0, tableHeight, width, playerPanelHeight); winPanel.setBounds(0, tableHeight, width, playerPanelHeight); settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2); scorePanel.setBounds(width / 8, height / 4, width * 3 / 4, height / 2); @@ -295,6 +320,7 @@ public class View extends JFrame implements IView { public void setCurrentPlayerName(String playerName) { playerPanel.setCurrentPlayerName(playerName); startTurnPanel.setCurrentPlayerName(playerName); + pausePanel.setCurrentPlayerName(playerName); } @Override @@ -329,24 +355,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)); @@ -361,21 +387,26 @@ 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 public void setBottomPanel(BottomPanelType type) { + bottomPanelType = type; + + doSetBottomPanel(type); + } + + private void doSetBottomPanel(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); + && 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()); } |