Show current game settings
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@486 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
2db77addd9
commit
705698670a
5 changed files with 111 additions and 24 deletions
|
@ -97,6 +97,7 @@ public class GameControl {
|
|||
* Game gets started by initializing the first Round
|
||||
*/
|
||||
public void startGame() {
|
||||
view.getSidePanel().setGameSettings(gameSettings);
|
||||
startRound();
|
||||
}
|
||||
|
||||
|
|
9
src/jrummikub/view/ISidePanel.java
Normal file
9
src/jrummikub/view/ISidePanel.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package jrummikub.view;
|
||||
|
||||
import jrummikub.model.GameSettings;
|
||||
|
||||
public interface ISidePanel {
|
||||
|
||||
public void setGameSettings(GameSettings settings);
|
||||
|
||||
}
|
|
@ -34,6 +34,13 @@ public interface IView {
|
|||
*/
|
||||
public ITablePanel getTablePanel();
|
||||
|
||||
/**
|
||||
* Returns the side panel
|
||||
*
|
||||
* @return the side panel
|
||||
*/
|
||||
public ISidePanel getSidePanel();
|
||||
|
||||
/**
|
||||
* @return the board where the players hand stones are displayed
|
||||
*/
|
||||
|
|
|
@ -24,27 +24,38 @@ import javax.swing.JLabel;
|
|||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.border.MatteBorder;
|
||||
|
||||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.view.ISidePanel;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class SidePanel extends JPanel {
|
||||
RuleInfoPanel ruleInfoPanel;
|
||||
class SidePanel extends JPanel implements ISidePanel {
|
||||
InfoPanel infoPanel;
|
||||
PlayerListPanel playerListPanel;
|
||||
BottomScrollPane playerListScrollPane;
|
||||
private JLabel initialMeldLabel;
|
||||
private JLabel setNumberLabel;
|
||||
private JLabel highestValueLabel;
|
||||
private JLabel handStonesLabel;
|
||||
private JLabel jokerLabel;
|
||||
private JLabel noLimitsLabel;
|
||||
private JLabel colorLabel;
|
||||
|
||||
public SidePanel() {
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
ruleInfoPanel = new RuleInfoPanel();
|
||||
infoPanel = new InfoPanel(createRuleInfoPanel());
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.weightx = 1;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
ruleInfoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK));
|
||||
add(ruleInfoPanel, c);
|
||||
infoPanel.setBorder(new MatteBorder(0, 0, 1, 1, Color.BLACK));
|
||||
add(infoPanel, c);
|
||||
|
||||
playerListPanel = new PlayerListPanel();
|
||||
c.gridx = 0;
|
||||
|
@ -61,12 +72,65 @@ class SidePanel extends JPanel {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameSettings(GameSettings settings) {
|
||||
initialMeldLabel.setText("" + settings.getInitialMeldThreshold());
|
||||
setNumberLabel.setText("" + settings.getStoneSetNumber());
|
||||
highestValueLabel.setText("1 - " + settings.getHighestValue());
|
||||
handStonesLabel.setText("" + settings.getNumberOfStonesDealt());
|
||||
jokerLabel.setText("" + settings.getJokerNumber());
|
||||
colorLabel.setText("" + settings.getStoneColors().size());
|
||||
noLimitsLabel.setVisible(settings.isNoLimits());
|
||||
}
|
||||
|
||||
private JPanel createRuleInfoPanel() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new GridBagLayout());
|
||||
initialMeldLabel = createRuleLine(panel, "Auslegeschranke", 0);
|
||||
setNumberLabel = createRuleLine(panel, "Steinsätze", 1);
|
||||
highestValueLabel = createRuleLine(panel,"Steinwert", 2);
|
||||
handStonesLabel = createRuleLine(panel, "Startsteine", 3);
|
||||
jokerLabel = createRuleLine(panel, "Joker", 4);
|
||||
colorLabel = createRuleLine(panel, "Farben", 5);
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = 6;
|
||||
c.gridwidth = 2;
|
||||
c.weightx = 1;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.anchor = GridBagConstraints.CENTER;
|
||||
noLimitsLabel = new JLabel("No Limits");
|
||||
noLimitsLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
panel.add(noLimitsLabel, c);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JLabel createRuleLine(JPanel panel, String name, int line) {
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = line;
|
||||
c.weightx = 1;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.anchor = GridBagConstraints.WEST;
|
||||
panel.add(new JLabel(name + ": "), c);
|
||||
JLabel label = new JLabel("");
|
||||
label.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
c.weightx = 0;
|
||||
c.gridx = 1;
|
||||
c.anchor = GridBagConstraints.EAST;
|
||||
panel.add(label, c);
|
||||
return label;
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class BottomScrollPane extends JPanel {
|
||||
JComponent content;
|
||||
JViewport viewport;
|
||||
JScrollBar scrollBar;
|
||||
boolean scrollToBottom;
|
||||
|
||||
public BottomScrollPane(JComponent content) {
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
@ -81,18 +145,18 @@ class SidePanel extends JPanel {
|
|||
scrollBar.setBorder(new LineBorder(Color.BLACK, 0));
|
||||
c.weightx = 0;
|
||||
add(scrollBar, c);
|
||||
|
||||
|
||||
ComponentAdapter resizeListener = new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
onResize();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
addComponentListener(resizeListener);
|
||||
|
||||
|
||||
content.addComponentListener(resizeListener);
|
||||
|
||||
|
||||
scrollBar.addAdjustmentListener(new AdjustmentListener() {
|
||||
@Override
|
||||
public void adjustmentValueChanged(AdjustmentEvent arg0) {
|
||||
|
@ -101,18 +165,19 @@ class SidePanel extends JPanel {
|
|||
});
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
|
||||
public void scrollToBottom() {
|
||||
scrollToBottom = true;
|
||||
}
|
||||
|
||||
|
||||
private void onResize() {
|
||||
int oldValue = 0;
|
||||
if (!scrollToBottom) {
|
||||
oldValue = scrollBar.getMaximum() - scrollBar.getVisibleAmount() - scrollBar.getValue();
|
||||
oldValue = scrollBar.getMaximum()
|
||||
- scrollBar.getVisibleAmount() - scrollBar.getValue();
|
||||
}
|
||||
scrollToBottom = false;
|
||||
|
||||
|
||||
int max = content.getHeight();
|
||||
int extent = viewport.getHeight();
|
||||
int value = Math.max(0, max - extent - oldValue);
|
||||
|
@ -120,17 +185,18 @@ class SidePanel extends JPanel {
|
|||
scrollBar.setValues(value, extent, 0, max);
|
||||
scrollViewport();
|
||||
}
|
||||
|
||||
|
||||
private void scrollViewport() {
|
||||
viewport.setViewPosition(new Point(0, scrollBar.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
class RuleInfoPanel extends JPanel {
|
||||
JLabel ruleInfo;
|
||||
static class InfoPanel extends JPanel {
|
||||
JPanel ruleInfoPanel;
|
||||
JCheckBox showRules;
|
||||
|
||||
public RuleInfoPanel() {
|
||||
public InfoPanel(JPanel ruleInfo) {
|
||||
ruleInfoPanel = ruleInfo;
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
showRules = new JCheckBox("Regeln");
|
||||
|
@ -147,16 +213,14 @@ class SidePanel extends JPanel {
|
|||
@Override
|
||||
public void actionPerformed(ActionEvent arg) {
|
||||
boolean selected = showRules.isSelected();
|
||||
ruleInfo.setVisible(selected);
|
||||
ruleInfoPanel.setVisible(selected);
|
||||
showRules.setPressedIcon(selected ? showRules.getIcon()
|
||||
: showRules.getSelectedIcon());
|
||||
}
|
||||
});
|
||||
|
||||
ruleInfo = new JLabel(
|
||||
"<html><center>All work and no play<br>makes Jack a dull boy");
|
||||
ruleInfo.setHorizontalAlignment(JLabel.CENTER);
|
||||
add(ruleInfo, c);
|
||||
c.insets = new Insets(4, 8, 4, 8);
|
||||
add(ruleInfoPanel, c);
|
||||
}
|
||||
|
||||
private void setupTriangleIcons(JCheckBox test) {
|
||||
|
@ -240,7 +304,7 @@ class SidePanel extends JPanel {
|
|||
c.weighty = 0;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
c.gridx = 0;
|
||||
c.gridy = i;
|
||||
c.insets = new Insets(i == 1 ? 0 : 1, 0, 0, 0);
|
||||
|
|
|
@ -39,6 +39,7 @@ import jrummikub.view.ILoginPanel;
|
|||
import jrummikub.view.IPlayerPanel;
|
||||
import jrummikub.view.IScorePanel;
|
||||
import jrummikub.view.ISettingsPanel;
|
||||
import jrummikub.view.ISidePanel;
|
||||
import jrummikub.view.ITablePanel;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
|
@ -101,7 +102,12 @@ public class View extends JFrame implements IView {
|
|||
public ITablePanel getTablePanel() {
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ISidePanel getSidePanel() {
|
||||
return sidePanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHandPanel getHandPanel() {
|
||||
return playerPanel.getHandPanel();
|
||||
|
|
Reference in a new issue