Skip to content

Commit

Permalink
Continues work on user friendly game settings panel
Browse files Browse the repository at this point in the history
  • Loading branch information
fathzer committed Feb 15, 2024
1 parent 63d1399 commit 8f521ea
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public class GameSettings {
}

private static final Random RANDOM_GENERATOR = new Random();
private Variant variant = Variant.CHESS960;
private Variant variant = Variant.STANDARD;
private boolean tabletMode = true;
private boolean showPossibleMoves = true;
private boolean touchMove = false;
private boolean startClockAfterFirstMove = false;
private ClockSettings clock = null;
private PlayerSettings player1 = new PlayerSettings();
private ColorSetting player1Color = ColorSetting.RANDOM;
private PlayerSettings player2 = new PlayerSettings(null, new EngineSettings(), null);
private PlayerSettings player2 = new PlayerSettings();

@Getter
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,19 @@ public GameSettingsPanel(GameSettings settings) {
}

private void setSettings(GameSettings settings) {
boolean hasClock = settings.getClock()!=null;
final boolean hasClock = settings.getClock()!=null;
this.timeControlCheckBox.setSelected(hasClock);
this.startAfterFirstMoveCheckBox.setSelected(settings.isStartClockAfterFirstMove());
this.timeDetailsPanel.setSettings(settings.getClock());

this.showMovesCheckBox.setSelected(settings.isShowPossibleMoves());
this.tabletModeCheckBox.setSelected(settings.isTabletMode());
this.touchMoveCheckBox.setSelected(settings.isTouchMove());

this.variantCombo.setSelectedItem(settings.getVariant());

this.player1Panel.setSettings(settings.getPlayer1());
this.player2Panel.setSettings(settings.getPlayer2());
this.player1Panel.setColor(settings.getPlayer1Color());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.awt.GridBagConstraints;

import com.fathzer.jchess.swing.settings.GameSettings.ColorSetting;
import com.fathzer.jchess.swing.settings.GameSettings.EngineSettings;
import com.fathzer.jchess.swing.settings.GameSettings.PlayerSettings;
import com.fathzer.jchess.swing.settings.GameSettings.PlayerType;
import com.fathzer.soft.ajlib.swing.widget.TextWidget;

Expand Down Expand Up @@ -118,6 +120,9 @@ public PlayerSelectionPanel() {
typeCombo.setSelectedIndex(0);
}

public void setColor(ColorSetting player1Color) {
colorComboBox.setSelectedItem(player1Color);
}
void setColorVisible(boolean visible) {
colorLabel.setVisible(visible);
colorComboBox.setVisible(visible);
Expand All @@ -130,4 +135,20 @@ private void setType(PlayerType type) {
engineLabel.setVisible(!isHuman);
engineCombo.setVisible(!isHuman);
}

public void setSettings(PlayerSettings settings) {
final EngineSettings engine = settings.getEngine();
if (engine==null) {
typeCombo.setSelectedItem(PlayerType.HUMAN);
nameTxt.setText(settings.getName());
} else {
typeCombo.setSelectedItem(PlayerType.ENGINE);
engineCombo.setSelectedItem(engine.getName());
}
}

public PlayerSettings getSettings() {
//TODO
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.awt.Insets;
import java.math.BigInteger;

import com.fathzer.games.clock.ClockSettings;
import com.fathzer.soft.ajlib.swing.widget.IntegerWidget;

public class ClockSettingsPanel extends JPanel {
Expand Down Expand Up @@ -88,4 +89,21 @@ public void setEnabled(boolean enabled) {
this.getComponent(i).setEnabled(enabled);
}
}

public void setSettings(ClockSettings clock) {
if (clock==null) {
timeField.setValue((BigInteger)null);
incrementField.setValue((BigInteger)null);
movesBeforeIncrementField.setValue((BigInteger)null);
} else {
timeField.setValue(clock.getInitialTime());
incrementField.setValue(clock.getIncrement());
movesBeforeIncrementField.setValue(clock.getMovesNumberBeforeIncrement());
}
}

public ClockSettings getSettings() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}
}

0 comments on commit 8f521ea

Please sign in to comment.