Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember Stage Width/Height #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/app/musicplayer/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ public final class Config {

static {
PREFERENCES.setValue("volume", 50.0);
PREFERENCES.setValue("stageW", 1280);
PREFERENCES.setValue("stageH", 720);
}
}
12 changes: 11 additions & 1 deletion src/main/java/app/musicplayer/FXGLMusicApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

// TODO: serialization version for future updates
// TODO: light and dark themes
// TODO: remember stage width height
// TODO: remember stage width height - DONE
// TODO: remember last played song
// TODO: update to high res app icon
// TODO: consider free streaming music API online
Expand Down Expand Up @@ -98,6 +98,16 @@ private void initJavaFXApp(Stage stage) throws Exception {
log.info("Closing stage");
FXGL.getGameController().exit();
});
// Draw `stage` to the height/width stated.
stage.setWidth(PREFERENCES.getInt("stageW"));
stage.setHeight(PREFERENCES.getInt("stageH"));
// Listener to check for size changes, apply size to preferences.
stage.widthProperty().addListener((o, oldW, newW) -> {
PREFERENCES.setValue("stageW", newW.intValue());
});
stage.heightProperty().addListener((o, oldH, newH) -> {
PREFERENCES.setValue("stageH", newH.intValue());
});

Scene scene = new Scene(view);
scene.getStylesheets().add(FXGL.getAssetLoader().loadCSS("Global.css").getExternalForm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void initEventHandlers() {
song.setArtwork(image);
});

onEvent(NAGIVATE_TO_SONG, event -> {
onEvent(NAVIGATE_TO_SONG, event -> {
PlaylistAndSong data = (PlaylistAndSong) event.getData();

songTableViewController.setPlaylist(data.playlist());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private void navigateToCurrentSong() {
if (!isReady)
return;

fire(new UserDataEvent<>(NAGIVATE_TO_SONG, new PlaylistAndSong(playlist, song)));
fire(new UserDataEvent<>(NAVIGATE_TO_SONG, new PlaylistAndSong(playlist, song)));
}

private void seek(int seconds) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/app/musicplayer/events/UserDataEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class UserDataEvent<T> extends UserEvent {

public static final EventType<UserDataEvent<?>> PLAY_SONG = new EventType<>(ANY, "PLAY_SONG_DATA_EVENT");
public static final EventType<UserDataEvent<?>> LOAD_SONG_ARTWORK = new EventType<>(ANY, "LOAD_SONG_ARTWORK_DATA_EVENT");
public static final EventType<UserDataEvent<?>> NAGIVATE_TO_SONG = new EventType<>(ANY, "NAGIVATE_TO_SONG_DATA_EVENT");
public static final EventType<UserDataEvent<?>> NAVIGATE_TO_SONG = new EventType<>(ANY, "NAVIGATE_TO_SONG_DATA_EVENT");

private T data;

Expand Down