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.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.CannotWriteException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.audio.mp3.MP3File;

View File

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