diff options
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r-- | src/jrummikub/view/IPlayerPanel.java | 13 | ||||
-rw-r--r-- | src/jrummikub/view/impl/PlayerPanel.java | 58 |
2 files changed, 67 insertions, 4 deletions
diff --git a/src/jrummikub/view/IPlayerPanel.java b/src/jrummikub/view/IPlayerPanel.java index 3fb8709..f1f8f95 100644 --- a/src/jrummikub/view/IPlayerPanel.java +++ b/src/jrummikub/view/IPlayerPanel.java @@ -10,7 +10,7 @@ public interface IPlayerPanel { * Sets the time the player has left for his turn * * @param time - * the time left + * the time left */ public void setTimeLeft(int time); @@ -23,8 +23,8 @@ public interface IPlayerPanel { public IEvent getSortByGroupsEvent(); /** - * The sort by runs event is emitted when the player wants to sort his stones - * by runs + * The sort by runs event is emitted when the player wants to sort his + * stones by runs * * @return the event */ @@ -36,4 +36,11 @@ public interface IPlayerPanel { * @return the event */ public IEvent getEndTurnEvent(); + + /** + * The redeal event is emitted when the player wants to get new stones + * + * @return the event + */ + IEvent getRedealEvent(); } diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index 8a5912d..171e46b 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -45,10 +45,14 @@ class PlayerPanel extends JPanel implements IPlayerPanel { private JButton handRowDownButton; private JProgressBar timeBar; private JButton endTurnButton; + private JButton keepStonesButton; + private JButton redealButton; + private Event sortByGroupsEvent = new Event(); private Event sortByRunsEvent = new Event(); private Event endTurnEvent = new Event(); + private Event redealEvent = new Event(); HandPanel getHandPanel() { return hand; @@ -90,6 +94,11 @@ class PlayerPanel extends JPanel implements IPlayerPanel { public IEvent getEndTurnEvent() { return endTurnEvent; } + + @Override + public IEvent getRedealEvent() { + return redealEvent; + } private void createLeftPanel() { leftPanel = new JPanel(); @@ -159,7 +168,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { timeBar.setStringPainted(true); rightPanel.add(timeBar); - endTurnButton = new JButton("Zug beenden"); + endTurnButton = new JButton("---"); endTurnButton.setFont(endTurnButton.getFont().deriveFont(0)); endTurnButton.setMargin(new Insets(0, 0, 0, 0)); endTurnButton.addActionListener(new ActionListener() { @@ -170,6 +179,30 @@ class PlayerPanel extends JPanel implements IPlayerPanel { }); rightPanel.add(endTurnButton); + + keepStonesButton = new JButton("<html><center>Steine<br>behalten"); + keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(0)); + keepStonesButton.setMargin(new Insets(0, 0, 0, 0)); + keepStonesButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + endTurnEvent.emit(); + } + }); + + rightPanel.add(keepStonesButton); + + redealButton= new JButton("<html><center>Neu<br>geben"); + redealButton.setFont(redealButton.getFont().deriveFont(0)); + redealButton.setMargin(new Insets(0, 0, 0, 0)); + redealButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + redealEvent.emit(); + } + }); + + rightPanel.add(redealButton); rightPanel.addComponentListener(new RightPanelResizeListener()); } @@ -225,6 +258,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel { addComponentListener(rescaleListener); hand.addComponentListener(rescaleListener); + + setEndTurnMode(true, true); } private class LeftPanelResizeListener extends ComponentAdapter { @@ -276,8 +311,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel { int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT); int buttonWidth = width; + 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; if (fontSize > MAX_BUTTON_FONT_SIZE) fontSize = MAX_BUTTON_FONT_SIZE; @@ -293,6 +330,25 @@ class PlayerPanel extends JPanel implements IPlayerPanel { 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); + keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(smallFontSize)); + + } + } + + public void setEndTurnMode(boolean inspectOnly, boolean mayRedeal) { + if (!inspectOnly) { + endTurnButton.setText("Zug beenden"); + } else if (!mayRedeal) { + endTurnButton.setText("Nächster Spieler"); } + boolean smallButtons = mayRedeal && inspectOnly; + endTurnButton.setVisible(!smallButtons); + keepStonesButton.setVisible(smallButtons); + redealButton.setVisible(smallButtons); } } |