summaryrefslogtreecommitdiff
path: root/core/src/kz/ilotterytea/maxon/ui
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 /core/src/kz/ilotterytea/maxon/ui
parent5bb8db06b01524bee613776cb9896a85ecbe2862 (diff)
feat: new debug widget
Diffstat (limited to 'core/src/kz/ilotterytea/maxon/ui')
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/DebugInfo.kt56
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/DebugWidget.java56
2 files changed, 56 insertions, 56 deletions
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");
+ }
+}