package sagittarius.view; 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.kotcrab.vis.ui.VisUI; import com.kotcrab.vis.ui.util.form.SimpleFormValidator; 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 sagittarius.SagittariusGame; public class SettingsScreen extends BaseScreen { @Override public void initialize() { Gdx.input.setInputProcessor(mainStage); // Table creation VisTable table = new VisTable(true); table.setFillParent(true); mainStage.addActor(table); VisLabel errorLabel = new VisLabel(); errorLabel.setColor(Color.RED); VisValidatableTextField gConstField = new VisValidatableTextField(); gConstField.setText(Float.toString(GameScreen.G)); 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); GameScreen.G = Float.parseFloat(gConstField.getText()); } }); VisTextButton returnButton = new VisTextButton("Go Back"); returnButton.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.setActiveScreen( new StartScreen() ); } }); 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.row(); table.add(new VisLabel("G constant:")); table.add(gConstField); table.row(); table.add(saveButton).colspan(2); table.row(); table.add(returnButton).colspan(2); } @Override public void update(float dt) { // } @Override public void dispose() { VisUI.dispose(); super.dispose(); } }