Skip to content

Commit

Permalink
Merge pull request #133 from einaskoi/per/settingStyle
Browse files Browse the repository at this point in the history
fixed styling and checkstyle errors/bugs
  • Loading branch information
einaskoi authored May 18, 2026
2 parents ab32da4 + fcf7d39 commit 9b523e5
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public class SettingsAppController implements AppController {
* Constructs the Settings controller and initializes UI bindings,
* file validation, and event wiring.
*
* @param settingsApp the settings UI view
* @param settingsApp the settings UI view
* @param filePickerApp the file picker UI view
*/
public SettingsAppController(final SettingsApp settingsApp, final FilePickerApp filePickerApp) {
public SettingsAppController(
final SettingsApp settingsApp,
final FilePickerApp filePickerApp) {
this.settingsApp = settingsApp;
this.filePickerApp = filePickerApp;

Expand All @@ -73,44 +75,55 @@ public SettingsAppController(final SettingsApp settingsApp, final FilePickerApp
}

private void wireControls() {
settingsApp.getMasterVolumeSlider().valueProperty().addListener((obs, ov, nv) ->
AudioManager.get().setMasterVolume(nv.doubleValue() / 100.0));
wireVolumeControls();
if (!settingsApp.isLoggedIn()) {
wireLoggedOutControls();
} else {
wireLoggedInControls();
}
}

settingsApp.getSfxVolumeSlider().valueProperty().addListener((obs, ov, nv) ->
AudioManager.get().setSfxVolume(nv.doubleValue() / 100.0));
private void wireVolumeControls() {
settingsApp.getMasterVolumeSlider().valueProperty().addListener(
(obs, ov, nv) -> AudioManager.get().setMasterVolume(nv.doubleValue() / 100.0));
settingsApp.getSfxVolumeSlider().valueProperty().addListener(
(obs, ov, nv) -> AudioManager.get().setSfxVolume(nv.doubleValue() / 100.0));
settingsApp.getMasterVolumeSlider()
.setValue(AudioManager.get().getMasterVolume() * 100.0);
settingsApp.getSfxVolumeSlider()
.setValue(AudioManager.get().getSfxVolume() * 100.0);
}

settingsApp.getMasterVolumeSlider().setValue(AudioManager.get().getMasterVolume() * 100.0);
settingsApp.getSfxVolumeSlider().setValue(AudioManager.get().getSfxVolume() * 100.0);
private void wireLoggedOutControls() {
settingsApp.getOpenFileChooserButton().setOnAction(event -> openFilePicker());
}

if (!settingsApp.isLoggedIn()) {
settingsApp.getOpenFileChooserButton().setOnAction(event -> openFilePicker());
private void wireLoggedInControls() {
settingsApp.getApplyGradientButton().setOnAction(event -> {
if (onGradientChanged != null) {
onGradientChanged.accept(settingsApp.getGradientConfig());
}
});

} else {
settingsApp.getApplyGradientButton().setOnAction(event -> {
if (onGradientChanged != null) {
onGradientChanged.accept(settingsApp.getGradientConfig());
}
});
settingsApp.getApplyNameButton().setOnAction(event -> {
final String name = settingsApp.getPlayerNameField().getText().trim();
if (!name.isEmpty() && onPlayerNameChanged != null) {
onPlayerNameChanged.accept(name);
settingsApp.getPlayerNameField().clear();
}
});

settingsApp.getApplyNameButton().setOnAction(event -> {
String name = settingsApp.getPlayerNameField().getText().trim();
if (!name.isEmpty() && onPlayerNameChanged != null) {
onPlayerNameChanged.accept(name);
settingsApp.getPlayerNameField().clear();
}
});
settingsApp.getLogoutButton().setOnAction(event -> {
if (onLogout != null) {
onLogout.run();
}
});

settingsApp.getLogoutButton().setOnAction(event -> {
if (onLogout != null) {
onLogout.run();
}
});
settingsApp.getPowerOffButton().setOnAction(event -> {
if (onPowerOff != null) {
onPowerOff.run();
}
});
}
settingsApp.getPowerOffButton().setOnAction(event -> {
if (onPowerOff != null) {
onPowerOff.run();
}
});
}

/**
Expand All @@ -125,7 +138,7 @@ public void setLoggedIn(final boolean status) {

private void openFilePicker() {
if (filePickerApp.getRoot().getParent() == null) {
var parent = settingsApp.getRoot().getParent();
final var parent = settingsApp.getRoot().getParent();
if (parent instanceof Pane pane) {
pane.getChildren().add(filePickerApp.getRoot());
filePickerApp.centerInParent();
Expand Down Expand Up @@ -159,26 +172,56 @@ private void refreshView() {
settingsApp.updateContent();
}

/**
* Sets the callback invoked when the user successfully selects a valid stock file path.
*
* @param callback the runnable to invoke after a successful path selection
*/
public void setOnUserPathSelected(final Runnable callback) {
onUserSelection = callback;
}

/**
* Sets the callback invoked when the selected stock file fails validation.
*
* @param callback the runnable to invoke when file validation fails
*/
public void setOnSelectedFileFailed(final Runnable callback) {
onSelectedFileFailed = callback;
}

/**
* Sets the callback invoked when the user triggers a logout action.
*
* @param callback the runnable to invoke on logout
*/
public void setOnLogout(final Runnable callback) {
onLogout = callback;
}

/**
* Sets the callback invoked when the user triggers the power-off action.
*
* @param callback the runnable to invoke on power-off
*/
public void setOnPowerOff(final Runnable callback) {
onPowerOff = callback;
}

/**
* Sets the callback invoked when the user applies a new player name.
*
* @param callback the consumer to invoke with the newly entered player name
*/
public void setOnPlayerNameChanged(final Consumer<String> callback) {
onPlayerNameChanged = callback;
}

/**
* Sets the callback invoked when the user applies a new gradient configuration.
*
* @param callback the consumer to invoke with the selected gradient config
*/
public void setOnGradientChanged(final Consumer<GradientConfig> callback) {
onGradientChanged = callback;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ private List<Popup> initializeApps(GameController gameController) {
SettingsAppController settingsAppController =
new SettingsAppController(settingsApp, filePickerApp);
settingsAppController.setLoggedIn(true);

settingsAppController.setOnGradientChanged(cfg ->
desktopView.getDesktopPane().setStyle(
SettingsApp.buildCssGradient(cfg.colorA(), cfg.colorB(), cfg.direction())));
Expand Down
Loading

0 comments on commit 9b523e5

Please sign in to comment.