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
public void create() {
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.scenes.scene2d.InputEvent;
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.util.form.SimpleFormValidator;
import com.kotcrab.vis.ui.widget.VisCheckBox;
import com.kotcrab.vis.ui.widget.VisLabel;
import com.kotcrab.vis.ui.widget.VisTable;
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;
@ -26,27 +27,27 @@ public class SettingsScreen extends BaseScreen {
table.setFillParent(true);
uiStage.addActor(table);
VisLabel errorLabel = new VisLabel();
errorLabel.setColor(Color.RED);
VisValidatableTextField gConstField = new VisValidatableTextField();
gConstField.setText(Float.toString(SagittariusGame.G));
// G constant field
Spinner gConstField = new Spinner("G constant:", new SimpleFloatSpinnerModel(SagittariusGame.G, 1f, 500f, 0.5f, 3));
// dubug mode checkbox
VisCheckBox debugModeBox = new VisCheckBox("debug mode");
debugModeBox.setChecked(SagittariusGame.debugMode);
// save button
VisTextButton saveButton = new VisTextButton("Save");
saveButton.addListener(new ActorGestureListener() {
@Override
public void tap(InputEvent event, float x, float y, int count, int 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();
}
});
// go back button
VisTextButton returnButton = new VisTextButton("Go Back");
returnButton.addListener(new ActorGestureListener() {
@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.add(errorLabel);
table.add(gConstField).width(250);
table.row();
table.add(new VisLabel("G constant:"));
table.add(gConstField);
table.add(debugModeBox).align(Align.left);
table.row();
table.add(debugModeBox).colspan(2);
table.add(saveButton).width(250);
table.row();
table.add(saveButton).colspan(2);
table.row();
table.add(returnButton).colspan(2);
table.add(returnButton).width(250);
}
@Override
public void update(float dt) {
//
}
public void update(float dt) {}
@Override
public void dispose() {