blob: 1797baa20a9403b4a88bf234490a98ccb15403ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
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, versionLabel;
private final Preferences preferences;
private boolean isEnabled;
public DebugWidget(Skin skin) {
super();
super.pad(16f);
super.setFillParent(true);
super.align(Align.topRight);
super.setZIndex(10);
this.preferences = Gdx.app.getPreferences(MaxonConstants.GAME_APP_PACKAGE);
this.isEnabled = preferences.getBoolean("debug", false);
this.fpsLabel = new Label(Gdx.graphics.getFramesPerSecond() + " fps", skin);
this.versionLabel = new Label(MaxonConstants.GAME_NAME + " " + MaxonConstants.GAME_VERSION, skin);
if (isEnabled) {
super.add(versionLabel).right().row();
super.add(fpsLabel).right();
}
}
@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(versionLabel).right().row();
super.add(fpsLabel).right();
} else {
super.clear();
}
}
if (!isEnabled) {
return;
}
fpsLabel.setText(Gdx.graphics.getFramesPerSecond() + " fps");
}
}
|