From 5059153d897bdbc0f74b65ab31e938301aba535f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 12 May 2021 22:40:27 +0200 Subject: [PATCH] feat: modified a bit the settings menu --- core/src/sagittarius/SagittariusGame.java | 2 +- core/src/sagittarius/view/SettingsScreen.java | 38 +++++++------------ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/core/src/sagittarius/SagittariusGame.java b/core/src/sagittarius/SagittariusGame.java index f07989a..001fdc1 100644 --- a/core/src/sagittarius/SagittariusGame.java +++ b/core/src/sagittarius/SagittariusGame.java @@ -28,7 +28,7 @@ public class SagittariusGame extends Game { @Override public void create() { VisUI.load(); - game.setScreen(new StartScreen()); + game.setScreen(new SettingsScreen()); } } diff --git a/core/src/sagittarius/view/SettingsScreen.java b/core/src/sagittarius/view/SettingsScreen.java index 943226c..7691124 100644 --- a/core/src/sagittarius/view/SettingsScreen.java +++ b/core/src/sagittarius/view/SettingsScreen.java @@ -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() {