feat: modified a bit the settings menu

This commit is contained in:
Laureηt 2021-05-12 22:40:27 +02:00
parent 8061f7e6da
commit 5059153d89
2 changed files with 15 additions and 25 deletions

View file

@ -28,7 +28,7 @@ public class SagittariusGame extends Game {
@Override @Override
public void create() { public void create() {
VisUI.load(); VisUI.load();
game.setScreen(new StartScreen()); game.setScreen(new SettingsScreen());
} }
} }

View file

@ -4,13 +4,14 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener; import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;
import com.badlogic.gdx.utils.Align;
import com.kotcrab.vis.ui.VisUI; import com.kotcrab.vis.ui.VisUI;
import com.kotcrab.vis.ui.util.form.SimpleFormValidator;
import com.kotcrab.vis.ui.widget.VisCheckBox; import com.kotcrab.vis.ui.widget.VisCheckBox;
import com.kotcrab.vis.ui.widget.VisLabel; import com.kotcrab.vis.ui.widget.VisLabel;
import com.kotcrab.vis.ui.widget.VisTable; import com.kotcrab.vis.ui.widget.VisTable;
import com.kotcrab.vis.ui.widget.VisTextButton; import com.kotcrab.vis.ui.widget.VisTextButton;
import com.kotcrab.vis.ui.widget.VisValidatableTextField; import com.kotcrab.vis.ui.widget.spinner.SimpleFloatSpinnerModel;
import com.kotcrab.vis.ui.widget.spinner.Spinner;
import sagittarius.SagittariusGame; import sagittarius.SagittariusGame;
@ -26,27 +27,27 @@ public class SettingsScreen extends BaseScreen {
table.setFillParent(true); table.setFillParent(true);
uiStage.addActor(table); uiStage.addActor(table);
VisLabel errorLabel = new VisLabel(); // G constant field
errorLabel.setColor(Color.RED); Spinner gConstField = new Spinner("G constant:", new SimpleFloatSpinnerModel(SagittariusGame.G, 1f, 500f, 0.5f, 3));
VisValidatableTextField gConstField = new VisValidatableTextField();
gConstField.setText(Float.toString(SagittariusGame.G));
// dubug mode checkbox
VisCheckBox debugModeBox = new VisCheckBox("debug mode"); VisCheckBox debugModeBox = new VisCheckBox("debug mode");
debugModeBox.setChecked(SagittariusGame.debugMode); debugModeBox.setChecked(SagittariusGame.debugMode);
// save button
VisTextButton saveButton = new VisTextButton("Save"); VisTextButton saveButton = new VisTextButton("Save");
saveButton.addListener(new ActorGestureListener() { saveButton.addListener(new ActorGestureListener() {
@Override @Override
public void tap(InputEvent event, float x, float y, int count, int button) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button); super.tap(event, x, y, count, button);
SagittariusGame.G = Float.parseFloat(gConstField.getText()); SagittariusGame.G = Float.parseFloat(gConstField.getTextField().getText());
SagittariusGame.debugMode = debugModeBox.isChecked(); SagittariusGame.debugMode = debugModeBox.isChecked();
} }
}); });
// go back button
VisTextButton returnButton = new VisTextButton("Go Back"); VisTextButton returnButton = new VisTextButton("Go Back");
returnButton.addListener(new ActorGestureListener() { returnButton.addListener(new ActorGestureListener() {
@Override @Override
@ -56,29 +57,18 @@ public class SettingsScreen extends BaseScreen {
} }
}); });
SimpleFormValidator validator;
validator = new SimpleFormValidator(saveButton, errorLabel, "smooth");
validator.notEmpty(gConstField, "G cannot be empty");
validator.floatNumber(gConstField, "G must be a float");
validator.valueGreaterThan(gConstField, "G must be positive", 0, true);
// Table structure // Table structure
table.add(errorLabel); table.add(gConstField).width(250);
table.row(); table.row();
table.add(new VisLabel("G constant:")); table.add(debugModeBox).align(Align.left);
table.add(gConstField);
table.row(); table.row();
table.add(debugModeBox).colspan(2); table.add(saveButton).width(250);
table.row(); table.row();
table.add(saveButton).colspan(2); table.add(returnButton).width(250);
table.row();
table.add(returnButton).colspan(2);
} }
@Override @Override
public void update(float dt) { public void update(float dt) {}
//
}
@Override @Override
public void dispose() { public void dispose() {