From 3c938b4819a033dc996a021f2b818297346426ac Mon Sep 17 00:00:00 2001 From: Lenni0451 <20379977+Lenni0451@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:52:11 +0100 Subject: [PATCH] Keep player settings and window position --- .../noteblocktool/frames/SongPlayerFrame.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/raphimc/noteblocktool/frames/SongPlayerFrame.java b/src/main/java/net/raphimc/noteblocktool/frames/SongPlayerFrame.java index 1d259b6..05099ff 100644 --- a/src/main/java/net/raphimc/noteblocktool/frames/SongPlayerFrame.java +++ b/src/main/java/net/raphimc/noteblocktool/frames/SongPlayerFrame.java @@ -47,14 +47,26 @@ public class SongPlayerFrame extends JFrame implements ISongPlayerCallback { private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##"); private static SongPlayerFrame instance; private static SoundSystem forcedSoundSystem; + private static Point lastPosition; + private static int lastMaxSounds = 256; + private static int lastVolume = 50; public static void open(final ListFrame.LoadedSong song) { open(song, song.getSong().getView()); } public static void open(final ListFrame.LoadedSong song, final SongView view) { - if (instance != null) instance.dispose(); + if (instance != null && instance.isVisible()) { + lastPosition = instance.getLocation(); + lastMaxSounds = (int) instance.maxSoundsSpinner.getValue(); + lastVolume = instance.volumeSlider.getValue(); + instance.dispose(); + } instance = new SongPlayerFrame(song, view); + if (lastPosition != null) instance.setLocation(lastPosition); + instance.maxSoundsSpinner.setValue(lastMaxSounds); + instance.volumeSlider.setValue(lastVolume); + instance.setVisible(true); } @@ -63,7 +75,7 @@ public static void open(final ListFrame.LoadedSong song, final SongView view) private final Timer updateTimer; private final JComboBox soundSystemComboBox = new JComboBox<>(new String[]{SoundSystem.OPENAL.getName(), SoundSystem.JAVAX.getName()}); private final JSpinner maxSoundsSpinner = new JSpinner(new SpinnerNumberModel(256, 64, 8192, 64)); - private final JSlider volumeSlider = new JSlider(0, 100, 100); + private final JSlider volumeSlider = new JSlider(0, 100, 50); private final JButton playStopButton = new JButton("Play"); private final JButton pauseResumeButton = new JButton("Pause"); private final JSlider progressSlider = new JSlider(0, 100, 0); @@ -94,7 +106,6 @@ private SongPlayerFrame(final ListFrame.LoadedSong song, final SongView view) this.playStopButton.doClick(); this.setMinimumSize(this.getSize()); - this.setVisible(true); } private SongView getSongView(final SongView view) { @@ -119,7 +130,11 @@ private void initComponents() { GBC.create(northPanel).grid(1, gridy++).insets(5, 0, 0, 5).weightx(1).fill(GBC.HORIZONTAL).add(this.soundSystemComboBox); GBC.create(northPanel).grid(0, gridy).insets(5, 5, 0, 5).anchor(GBC.LINE_START).add(new JLabel("Max Sounds:")); - GBC.create(northPanel).grid(1, gridy++).insets(5, 0, 0, 5).weightx(1).fill(GBC.HORIZONTAL).add(this.maxSoundsSpinner); + GBC.create(northPanel).grid(1, gridy++).insets(5, 0, 0, 5).weightx(1).fill(GBC.HORIZONTAL).add(this.maxSoundsSpinner, () -> { + this.maxSoundsSpinner.addChangeListener(e -> { + lastMaxSounds = (int) this.maxSoundsSpinner.getValue(); + }); + }); GBC.create(northPanel).grid(0, gridy).insets(5, 5, 5, 5).anchor(GBC.LINE_START).add(new JLabel("Volume:")); GBC.create(northPanel).grid(1, gridy++).insets(5, 0, 5, 5).weightx(1).fill(GBC.HORIZONTAL).add(this.volumeSlider, () -> { @@ -130,6 +145,7 @@ private void initComponents() { this.volumeSlider.addChangeListener(e -> { this.volume = this.volumeSlider.getValue() / 100F; if (this.soundSystem.equals(SoundSystem.OPENAL)) OpenALSoundSystem.setMasterVolume(this.volume); + lastVolume = this.volumeSlider.getValue(); }); }); } @@ -237,6 +253,7 @@ private void initFrameHandler() { @Override public void windowClosing(WindowEvent e) { SongPlayerFrame.this.dispose(); + lastPosition = SongPlayerFrame.this.getLocation(); } @Override