Added UI for readealing
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@278 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
10e8c1f0e6
commit
d69fdbacb9
3 changed files with 74 additions and 4 deletions
|
@ -10,6 +10,8 @@ public class MockPlayerPanel implements IPlayerPanel {
|
||||||
/** */
|
/** */
|
||||||
public MockEvent endTurnEvent = new MockEvent();
|
public MockEvent endTurnEvent = new MockEvent();
|
||||||
/** */
|
/** */
|
||||||
|
public MockEvent redealEvent = new MockEvent();
|
||||||
|
/** */
|
||||||
public MockEvent sortByGroupsEvent = new MockEvent();
|
public MockEvent sortByGroupsEvent = new MockEvent();
|
||||||
/** */
|
/** */
|
||||||
public MockEvent sortByRunsEvent = new MockEvent();
|
public MockEvent sortByRunsEvent = new MockEvent();
|
||||||
|
@ -35,4 +37,9 @@ public class MockPlayerPanel implements IPlayerPanel {
|
||||||
return endTurnEvent;
|
return endTurnEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent getRedealEvent() {
|
||||||
|
return redealEvent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ public interface IPlayerPanel {
|
||||||
* Sets the time the player has left for his turn
|
* Sets the time the player has left for his turn
|
||||||
*
|
*
|
||||||
* @param time
|
* @param time
|
||||||
* the time left
|
* the time left
|
||||||
*/
|
*/
|
||||||
public void setTimeLeft(int time);
|
public void setTimeLeft(int time);
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ public interface IPlayerPanel {
|
||||||
public IEvent getSortByGroupsEvent();
|
public IEvent getSortByGroupsEvent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sort by runs event is emitted when the player wants to sort his stones
|
* The sort by runs event is emitted when the player wants to sort his
|
||||||
* by runs
|
* stones by runs
|
||||||
*
|
*
|
||||||
* @return the event
|
* @return the event
|
||||||
*/
|
*/
|
||||||
|
@ -36,4 +36,11 @@ public interface IPlayerPanel {
|
||||||
* @return the event
|
* @return the event
|
||||||
*/
|
*/
|
||||||
public IEvent getEndTurnEvent();
|
public IEvent getEndTurnEvent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The redeal event is emitted when the player wants to get new stones
|
||||||
|
*
|
||||||
|
* @return the event
|
||||||
|
*/
|
||||||
|
IEvent getRedealEvent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,14 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
private JButton handRowDownButton;
|
private JButton handRowDownButton;
|
||||||
private JProgressBar timeBar;
|
private JProgressBar timeBar;
|
||||||
private JButton endTurnButton;
|
private JButton endTurnButton;
|
||||||
|
private JButton keepStonesButton;
|
||||||
|
private JButton redealButton;
|
||||||
|
|
||||||
|
|
||||||
private Event sortByGroupsEvent = new Event();
|
private Event sortByGroupsEvent = new Event();
|
||||||
private Event sortByRunsEvent = new Event();
|
private Event sortByRunsEvent = new Event();
|
||||||
private Event endTurnEvent = new Event();
|
private Event endTurnEvent = new Event();
|
||||||
|
private Event redealEvent = new Event();
|
||||||
|
|
||||||
HandPanel getHandPanel() {
|
HandPanel getHandPanel() {
|
||||||
return hand;
|
return hand;
|
||||||
|
@ -91,6 +95,11 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
return endTurnEvent;
|
return endTurnEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent getRedealEvent() {
|
||||||
|
return redealEvent;
|
||||||
|
}
|
||||||
|
|
||||||
private void createLeftPanel() {
|
private void createLeftPanel() {
|
||||||
leftPanel = new JPanel();
|
leftPanel = new JPanel();
|
||||||
leftPanel.setLayout(null);
|
leftPanel.setLayout(null);
|
||||||
|
@ -159,7 +168,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
timeBar.setStringPainted(true);
|
timeBar.setStringPainted(true);
|
||||||
rightPanel.add(timeBar);
|
rightPanel.add(timeBar);
|
||||||
|
|
||||||
endTurnButton = new JButton("Zug beenden");
|
endTurnButton = new JButton("---");
|
||||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(0));
|
endTurnButton.setFont(endTurnButton.getFont().deriveFont(0));
|
||||||
endTurnButton.setMargin(new Insets(0, 0, 0, 0));
|
endTurnButton.setMargin(new Insets(0, 0, 0, 0));
|
||||||
endTurnButton.addActionListener(new ActionListener() {
|
endTurnButton.addActionListener(new ActionListener() {
|
||||||
|
@ -171,6 +180,30 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
|
|
||||||
rightPanel.add(endTurnButton);
|
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());
|
rightPanel.addComponentListener(new RightPanelResizeListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +258,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
|
|
||||||
addComponentListener(rescaleListener);
|
addComponentListener(rescaleListener);
|
||||||
hand.addComponentListener(rescaleListener);
|
hand.addComponentListener(rescaleListener);
|
||||||
|
|
||||||
|
setEndTurnMode(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LeftPanelResizeListener extends ComponentAdapter {
|
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 firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
||||||
int buttonWidth = width;
|
int buttonWidth = width;
|
||||||
|
int smallButtonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
|
||||||
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
||||||
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
||||||
|
float smallFontSize = (float) Math.sqrt(smallButtonWidth * buttonHeight) / 5;
|
||||||
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
||||||
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,
|
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
||||||
buttonWidth, buttonHeight);
|
buttonWidth, buttonHeight);
|
||||||
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue