cleaned up imports; options page slight improvement;

This commit is contained in:
Harrison Deng 2018-09-04 20:19:28 -05:00
parent 1f1025dcce
commit ab48262ff8
2 changed files with 21 additions and 22 deletions

View File

@ -6,7 +6,6 @@ import java.util.Date;
import org.jaudiotagger.audio.AudioFileIO; import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.exceptions.CannotReadException; import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.CannotWriteException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.audio.mp3.MP3File; import org.jaudiotagger.audio.mp3.MP3File;

View File

@ -1,12 +1,9 @@
package zero1hd.rhythmbullet.desktop.screens.main; package zero1hd.rhythmbullet.desktop.screens.main;
import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Formatter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar; import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar;
@ -27,13 +24,13 @@ public class OptionsPage extends Page {
private TextField directoryField; private TextField directoryField;
private float musicSearchTimer; private float musicSearchTimer;
private Preferences prefs; private Preferences prefs;
private NumberFormat formatter; private NumberFormat percentFormat;
public OptionsPage(MusicController musicController, Skin skin, Preferences preferences, ChangeListener backButtonListener, ChangeListener graphicsButtonListener, ChangeListener controlsButtonListener) { public OptionsPage(MusicController musicController, Skin skin, Preferences preferences, ChangeListener backButtonListener, ChangeListener graphicsButtonListener, ChangeListener controlsButtonListener) {
super(-1, 0, "General", skin); super(-1, 0, "General", skin);
this.prefs = preferences; this.prefs = preferences;
formatter = NumberFormat.getPercentInstance(); percentFormat = NumberFormat.getPercentInstance();
formatter.setMaximumFractionDigits(1); percentFormat.setMaximumFractionDigits(1);
//Back button //Back button
TextButton backButton = new TextButton("Back", skin); TextButton backButton = new TextButton("Back", skin);
@ -43,44 +40,43 @@ public class OptionsPage extends Page {
addActor(backButton); addActor(backButton);
optionsTable = new Table(); optionsTable = new Table();
optionsTable.defaults().center().space(10f); optionsTable.defaults().space(10f);
optionsTable.setSize(getWidth(), getHeight());
addActor(optionsTable); addActor(optionsTable);
Label musicVolSliderLabel = new Label("Music Volume: ", skin); Label musicVolSliderLabel = new Label("Music Volume: ", skin);
optionsTable.add(musicVolSliderLabel); optionsTable.add(musicVolSliderLabel);
musicVolSlider = new Slider(0, 100, 0.1f, false, skin); musicVolSlider = new Slider(0, 100, 0.1f, false, skin);
musicVolSlider.setValue(preferences.getFloat("music vol", 100f)*100f); musicVolSlider.setValue(preferences.getFloat("music vol", 100f));
optionsTable.add(musicVolSlider).minWidth(0.3f*getWidth()); optionsTable.add(musicVolSlider).minWidth(0.3f*getWidth());
final Label musicVolPercentage = new Label(MathUtils.round(musicVolSlider.getValue()) + "%", skin); final Label musicVolPercentage = new Label(percentFormat.format(musicVolSlider.getPercent()), skin);
musicVolSlider.addListener(new ChangeListener() { musicVolSlider.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
musicVolPercentage.setText(MathUtils.round(musicVolSlider.getValue()) + "%"); musicVolPercentage.setText(percentFormat.format(musicVolSlider.getPercent()));
musicController.getCurrentMusic().setVolume(musicVolSlider.getPercent()); musicController.getCurrentMusic().setVolume(musicVolSlider.getPercent());
preferences.putFloat("music vol", musicVolSlider.getValue());
preferences.putFloat("music vol", musicVolSlider.getPercent());
} }
}); });
optionsTable.add(musicVolPercentage); optionsTable.add(musicVolPercentage).expandX().left();
optionsTable.row(); optionsTable.row();
Label fxVolSliderLabel = new Label("FX Volume: ", skin); Label fxVolSliderLabel = new Label("FX Volume: ", skin);
optionsTable.add(fxVolSliderLabel); optionsTable.add(fxVolSliderLabel);
fxVolSlider = new Slider(0, 100, 0.1f, false, skin); fxVolSlider = new Slider(0, 100, 0.1f, false, skin);
fxVolSlider.setValue(preferences.getFloat("fx vol", 100f)*100f); fxVolSlider.setValue(preferences.getFloat("fx vol", 100f));
optionsTable.add(fxVolSlider).fillX(); optionsTable.add(fxVolSlider).fillX();
final Label fxVolPercentage = new Label(MathUtils.round(fxVolSlider.getValue()) + "%", skin); final Label fxVolPercentage = new Label(percentFormat.format(fxVolSlider.getPercent()), skin);
fxVolSlider.addListener(new ChangeListener() { fxVolSlider.addListener(new ChangeListener() {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
fxVolPercentage.setText(MathUtils.round(fxVolSlider.getValue()) + "%"); fxVolPercentage.setText(percentFormat.format(fxVolSlider.getPercent()));
preferences.putFloat("fx vol", fxVolSlider.getPercent()); preferences.putFloat("fx vol", fxVolSlider.getValue());
} }
}); });
optionsTable.add(fxVolPercentage); optionsTable.add(fxVolPercentage).left();
optionsTable.row(); optionsTable.row();
@ -140,7 +136,7 @@ public class OptionsPage extends Page {
refreshTime -= delta; refreshTime -= delta;
if (refreshTime <= 0) { if (refreshTime <= 0) {
refreshTime = 4; refreshTime = 4;
String formatted = formatter.format(((float)(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(float)Runtime.getRuntime().totalMemory())); String formatted = percentFormat.format(((float)(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(float)Runtime.getRuntime().totalMemory()));
setText("Current usage (JVM): " + formatted); setText("Current usage (JVM): " + formatted);
} }
super.act(delta); super.act(delta);
@ -148,13 +144,17 @@ public class OptionsPage extends Page {
}; };
optionsTable.add(usageLabel).colspan(2); optionsTable.add(usageLabel).colspan(2);
optionsTable.pack();
optionsTable.setX((getWidth()-optionsTable.getWidth())/2f);
optionsTable.setSize(getWidth() - optionsTable.getX(), backButton.getY());
} }
public void saveOptions() { public void saveOptions() {
prefs.putString("music dir", directoryField.getText()); prefs.putString("music dir", directoryField.getText());
Gdx.app.debug("Preferences", "Saved all basic options page values."); Gdx.app.debug("Preferences", "Saved all basic options page values.");
} }
@Override @Override
public void dispose() { public void dispose() {
saveOptions(); saveOptions();