summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-06-10 00:43:01 +0500
committerilotterytea <iltsu@alright.party>2024-06-10 00:43:01 +0500
commit20117df6c86db32dd7c5654193f5fe97ed06ad1d (patch)
tree9230e6974084197d600d42140112f09744c695a7
parent5bb8db06b01524bee613776cb9896a85ecbe2862 (diff)
feat: new debug widget
-rw-r--r--core/src/kz/ilotterytea/maxon/MaxonConstants.java1
-rw-r--r--core/src/kz/ilotterytea/maxon/MaxonGame.java2
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/MenuScreen.java3
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java4
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java3
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/DebugInfo.kt56
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/DebugWidget.java56
7 files changed, 68 insertions, 57 deletions
diff --git a/core/src/kz/ilotterytea/maxon/MaxonConstants.java b/core/src/kz/ilotterytea/maxon/MaxonConstants.java
index c9f7878..2f84a79 100644
--- a/core/src/kz/ilotterytea/maxon/MaxonConstants.java
+++ b/core/src/kz/ilotterytea/maxon/MaxonConstants.java
@@ -13,6 +13,7 @@ import java.text.SimpleDateFormat;
public class MaxonConstants {
public static final String GAME_NAME = "Maxon Petting Simulator";
public static final String GAME_APP_ID = "maxon";
+ public static final String GAME_APP_PACKAGE = "kz.ilotterytea." + GAME_APP_ID;
public static final String GAME_VERSION = "Alpha 1.2";
public static final String GAME_GHTAG = "alpha-1.2";
public static final String GAME_MAIN_DEVELOPER = "ilotterytea";
diff --git a/core/src/kz/ilotterytea/maxon/MaxonGame.java b/core/src/kz/ilotterytea/maxon/MaxonGame.java
index 680f1c6..0e3f9bc 100644
--- a/core/src/kz/ilotterytea/maxon/MaxonGame.java
+++ b/core/src/kz/ilotterytea/maxon/MaxonGame.java
@@ -36,7 +36,7 @@ public class MaxonGame extends Game {
public void create () {
batch = new SpriteBatch();
shapeRenderer = new ShapeRenderer();
- prefs = Gdx.app.getPreferences("Maxoning");
+ prefs = Gdx.app.getPreferences(MaxonConstants.GAME_APP_PACKAGE);
locale = new I18N(Gdx.files.internal("i18n/" + prefs.getString("lang", "en_us") + ".json"));
prefs.putInteger("width", Gdx.graphics.getWidth());
diff --git a/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java b/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java
index b61f6ee..5ae30ef 100644
--- a/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java
+++ b/core/src/kz/ilotterytea/maxon/screens/MenuScreen.java
@@ -328,6 +328,9 @@ public class MenuScreen implements Screen {
this.stage.addActor(menuTable);
+ DebugWidget debugWidget = new DebugWidget(uiSkin);
+ this.stage.addActor(debugWidget);
+
create3D();
Gdx.input.setInputProcessor(stage);
}
diff --git a/core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java b/core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java
index 8c061af..d173d46 100644
--- a/core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java
+++ b/core/src/kz/ilotterytea/maxon/screens/WelcomeScreen.java
@@ -21,6 +21,7 @@ import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import kz.ilotterytea.maxon.MaxonGame;
import kz.ilotterytea.maxon.screens.game.GameScreen;
+import kz.ilotterytea.maxon.ui.DebugWidget;
import net.mgsx.gltf.scene3d.attributes.PBRCubemapAttribute;
import net.mgsx.gltf.scene3d.attributes.PBRTextureAttribute;
import net.mgsx.gltf.scene3d.lights.DirectionalShadowLight;
@@ -125,6 +126,9 @@ public class WelcomeScreen implements Screen {
tintImage.addAction(Actions.alpha(0.0f, 1.0f));
stage.addActor(tintImage);
+
+ DebugWidget debugWidget = new DebugWidget(skin);
+ this.stage.addActor(debugWidget);
}
@Override
diff --git a/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java b/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java
index 0ff5eaf..3b8d3aa 100644
--- a/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java
+++ b/core/src/kz/ilotterytea/maxon/screens/game/GameScreen.java
@@ -444,6 +444,9 @@ public class GameScreen implements Screen, InputProcessor {
if (!OsUtils.isMobile) {
shopUI.createSavegameUI();
}
+
+ DebugWidget debugWidget = new DebugWidget(uiSkin);
+ this.stage.addActor(debugWidget);
}
@Override
diff --git a/core/src/kz/ilotterytea/maxon/ui/DebugInfo.kt b/core/src/kz/ilotterytea/maxon/ui/DebugInfo.kt
deleted file mode 100644
index 7329725..0000000
--- a/core/src/kz/ilotterytea/maxon/ui/DebugInfo.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-package kz.ilotterytea.maxon.ui
-
-import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.Version
-import com.badlogic.gdx.scenes.scene2d.ui.Label
-import com.badlogic.gdx.scenes.scene2d.ui.Skin
-import com.badlogic.gdx.scenes.scene2d.ui.Table
-import com.badlogic.gdx.utils.Align
-import kz.ilotterytea.maxon.MaxonConstants
-import kz.ilotterytea.maxon.utils.I18N
-
-/**
- * Debug information.
- * @since a_1.0
- * @author ilotterytea
- */
-class DebugInfo(skin: Skin, locale: I18N) : Table() {
- private val i18n = locale
- private var c_fps: Label
- private var c_mem: Label
-
- init {
- val rt = Runtime.getRuntime()
- val usedmem = ((rt.totalMemory() - rt.freeMemory()) / 1024) / 1024
- val totalmem = (rt.totalMemory() / 1024) / 1024
-
- // Version info:
- val ver = Label(i18n.FormattedText("debug.version", MaxonConstants.GAME_VERSION, Version.VERSION, System.getProperty("java.version")), skin, "debug")
- ver.setAlignment(Align.left)
- this.add(ver).fillX().row()
-
- // Frames per second:
- c_fps = Label(i18n.FormattedText("debug.c_fps", Gdx.graphics.framesPerSecond.toString()), skin, "debug")
- c_fps.setAlignment(Align.left)
- this.add(c_fps).fillX().row()
-
- // Memory usage:
- c_mem = Label(i18n.FormattedText("debug.c_mem", usedmem.toString(), totalmem.toString()), skin, "debug")
- c_mem.setAlignment(Align.left)
- this.add(c_mem).fillX().row()
-
- this.align(Align.left)
- this.skin = skin
- this.background("tile_03")
- }
-
- override fun act(delta: Float) {
- val rt = Runtime.getRuntime()
- val usedmem = ((rt.totalMemory() - rt.freeMemory()) / 1024) / 1024
- val totalmem = (rt.totalMemory() / 1024) / 1024
-
- super.act(delta)
- c_fps.setText(i18n.FormattedText("debug.c_fps", Gdx.graphics.framesPerSecond.toString()))
- c_mem.setText(i18n.FormattedText("debug.c_mem", usedmem.toString(), totalmem.toString()))
- }
-} \ No newline at end of file
diff --git a/core/src/kz/ilotterytea/maxon/ui/DebugWidget.java b/core/src/kz/ilotterytea/maxon/ui/DebugWidget.java
new file mode 100644
index 0000000..469f2f4
--- /dev/null
+++ b/core/src/kz/ilotterytea/maxon/ui/DebugWidget.java
@@ -0,0 +1,56 @@
+package kz.ilotterytea.maxon.ui;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input;
+import com.badlogic.gdx.Preferences;
+import com.badlogic.gdx.scenes.scene2d.ui.Label;
+import com.badlogic.gdx.scenes.scene2d.ui.Skin;
+import com.badlogic.gdx.scenes.scene2d.ui.Table;
+import com.badlogic.gdx.utils.Align;
+import kz.ilotterytea.maxon.MaxonConstants;
+
+public class DebugWidget extends Table {
+ private final Label fpsLabel;
+ private final Preferences preferences;
+
+ private boolean isEnabled;
+
+ public DebugWidget(Skin skin) {
+ super();
+ super.pad(16f);
+ super.setFillParent(true);
+ super.align(Align.topRight);
+
+ this.preferences = Gdx.app.getPreferences(MaxonConstants.GAME_APP_PACKAGE);
+ this.isEnabled = preferences.getBoolean("debug", false);
+
+ this.fpsLabel = new Label(Gdx.graphics.getFramesPerSecond() + " fps", skin);
+
+ if (isEnabled) {
+ super.add(fpsLabel);
+ }
+ }
+
+ @Override
+ public void act(float delta) {
+ super.act(delta);
+
+ if (Gdx.input.isKeyJustPressed(Input.Keys.F3)) {
+ isEnabled = !isEnabled;
+ this.preferences.putBoolean("debug", isEnabled);
+ this.preferences.flush();
+
+ if (isEnabled) {
+ super.add(fpsLabel);
+ } else {
+ super.clear();
+ }
+ }
+
+ if (!isEnabled) {
+ return;
+ }
+
+ fpsLabel.setText(Gdx.graphics.getFramesPerSecond() + " fps");
+ }
+}