feat: added a debugMode checkbox to settings

This commit is contained in:
Laureηt 2021-04-16 13:57:02 +02:00
parent 0355d98baf
commit eff5fc1f99
4 changed files with 19 additions and 9 deletions

View file

@ -8,8 +8,12 @@ import sagittarius.view.StartScreen;
public class SagittariusGame extends Game { public class SagittariusGame extends Game {
// Constants
public static float G = 100;
public static boolean debugMode = true;
private static Game game; private static Game game;
public SagittariusGame() { public SagittariusGame() {
game = this; game = this;
} }

View file

@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import sagittarius.SagittariusGame;
import sagittarius.view.GameScreen; import sagittarius.view.GameScreen;
public class Arrow extends BaseActor { public class Arrow extends BaseActor {
@ -88,7 +89,7 @@ public class Arrow extends BaseActor {
float len2 = dx*dx + dy*dy; float len2 = dx*dx + dy*dy;
float coeff = GameScreen.G * ((Planet) actor).getMass() * (float) Math.pow(len2, -3/2); float coeff = SagittariusGame.G * ((Planet) actor).getMass() * (float) Math.pow(len2, -3/2);
float gravityX = coeff * dx; float gravityX = coeff * dx;
float gravityY = coeff * dy; float gravityY = coeff * dy;

View file

@ -6,6 +6,7 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
import sagittarius.SagittariusGame;
import sagittarius.model.*; import sagittarius.model.*;
public class GameScreen extends BaseScreen { public class GameScreen extends BaseScreen {
@ -22,9 +23,6 @@ public class GameScreen extends BaseScreen {
public static Group arrows; public static Group arrows;
public static Group players; public static Group players;
// Constants
public static float G = 100;
public static int playerTurn; public static int playerTurn;
// ---------- METHODs ---------- // ---------- METHODs ----------
@ -72,8 +70,8 @@ public class GameScreen extends BaseScreen {
MouseInfo mouseInfo = new MouseInfo(); MouseInfo mouseInfo = new MouseInfo();
uiStage.addActor(mouseInfo); uiStage.addActor(mouseInfo);
mainStage.setDebugAll(true); // TODO: disable later mainStage.setDebugAll(SagittariusGame.debugMode);
uiStage.setDebugAll(true); // TODO: disable later uiStage.setDebugAll(SagittariusGame.debugMode);
// game turns // game turns
playerTurn = 0; playerTurn = 0;

View file

@ -6,6 +6,7 @@ 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.kotcrab.vis.ui.VisUI; import com.kotcrab.vis.ui.VisUI;
import com.kotcrab.vis.ui.util.form.SimpleFormValidator; 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.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;
@ -29,7 +30,10 @@ public class SettingsScreen extends BaseScreen {
errorLabel.setColor(Color.RED); errorLabel.setColor(Color.RED);
VisValidatableTextField gConstField = new VisValidatableTextField(); VisValidatableTextField gConstField = new VisValidatableTextField();
gConstField.setText(Float.toString(GameScreen.G)); gConstField.setText(Float.toString(SagittariusGame.G));
VisCheckBox debugModeBox = new VisCheckBox("debug mode");
debugModeBox.setChecked(SagittariusGame.debugMode);
VisTextButton saveButton = new VisTextButton("Save"); VisTextButton saveButton = new VisTextButton("Save");
saveButton.addListener(new ActorGestureListener() { saveButton.addListener(new ActorGestureListener() {
@ -37,7 +41,8 @@ public class SettingsScreen extends BaseScreen {
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);
GameScreen.G = Float.parseFloat(gConstField.getText()); SagittariusGame.G = Float.parseFloat(gConstField.getText());
SagittariusGame.debugMode = debugModeBox.isChecked();
} }
}); });
@ -63,6 +68,8 @@ public class SettingsScreen extends BaseScreen {
table.add(new VisLabel("G constant:")); table.add(new VisLabel("G constant:"));
table.add(gConstField); table.add(gConstField);
table.row(); table.row();
table.add(debugModeBox).colspan(2);
table.row();
table.add(saveButton).colspan(2); table.add(saveButton).colspan(2);
table.row(); table.row();
table.add(returnButton).colspan(2); table.add(returnButton).colspan(2);