2021-04-16 11:43:59 +00:00
|
|
|
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);
|
2021-04-16 11:48:57 +00:00
|
|
|
|
2021-04-16 11:43:59 +00:00
|
|
|
VisLabel errorLabel = new VisLabel();
|
|
|
|
errorLabel.setColor(Color.RED);
|
|
|
|
|
|
|
|
VisValidatableTextField gConstField = new VisValidatableTextField();
|
2021-04-16 11:48:57 +00:00
|
|
|
gConstField.setText(Float.toString(GameScreen.G));
|
|
|
|
|
2021-04-16 11:43:59 +00:00
|
|
|
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);
|
2021-04-16 11:48:57 +00:00
|
|
|
|
2021-04-16 11:43:59 +00:00
|
|
|
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();
|
2021-04-16 11:48:57 +00:00
|
|
|
table.add(saveButton).colspan(2);
|
2021-04-16 11:43:59 +00:00
|
|
|
table.row();
|
2021-04-16 11:48:57 +00:00
|
|
|
table.add(returnButton).colspan(2);
|
2021-04-16 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(float dt) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dispose() {
|
|
|
|
VisUI.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|