Create simple HUD with debug data
This commit is contained in:
@@ -8,7 +8,8 @@ $9da2c95b-45b7-49e5-957b-c1c8803cdf28(9da2c95b-45b7-49e5-957b-c1c8803cdf28.png
|
||||
$2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttfRoboto RegularB\
|
||||
$ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
|
||||
Start MenuB[
|
||||
$56ca6b39-f949-4212-9c23-312db25887e0(56ca6b39-f949-4212-9c23-312db25887e0.xml Game MenuJ[
|
||||
$56ca6b39-f949-4212-9c23-312db25887e0(56ca6b39-f949-4212-9c23-312db25887e0.xml Game MenuBU
|
||||
$00bd0625-b3b8-4abf-97b7-91f42bce28ec(00bd0625-b3b8-4abf-97b7-91f42bce28ec.xmlHUDJ[
|
||||
$61e67e44-a0cd-4210-8d1e-ccddcd62c78d(61e67e44-a0cd-4210-8d1e-ccddcd62c78d.pngSlash (JZ
|
||||
$e6f067f1-eba0-4e62-99c3-2fd867e6f142(e6f067f1-eba0-4e62-99c3-2fd867e6f142.pngPoof (J[
|
||||
$312cc4e6-8c44-43e7-828a-e7e2a77836f3(312cc4e6-8c44-43e7-828a-e7e2a77836f3.pngArrow (J[
|
||||
|
||||
46
src/main/java/com/bartlomiejpluta/demo/gui/HUD.java
Normal file
46
src/main/java/com/bartlomiejpluta/demo/gui/HUD.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.bartlomiejpluta.demo.gui;
|
||||
|
||||
import com.bartlomiejpluta.base.api.gui.*;
|
||||
import com.bartlomiejpluta.base.lib.gui.*;
|
||||
|
||||
import com.bartlomiejpluta.base.api.screen.*;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.input.*;
|
||||
|
||||
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||
import com.bartlomiejpluta.demo.entity.*;
|
||||
|
||||
public class HUD extends BorderLayout {
|
||||
private final DemoRunner runner;
|
||||
private final Player player;
|
||||
private final Runtime runtime;
|
||||
|
||||
@Ref("debug")
|
||||
private Label debugLbl;
|
||||
|
||||
public HUD(Context context, GUI gui) {
|
||||
super(context, gui);
|
||||
this.runner = (DemoRunner) context.getGameRunner();
|
||||
this.player = runner.getPlayer();
|
||||
this.runtime = Runtime.getRuntime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Screen screen, GUI gui) {
|
||||
var coords = player.getCoordinates();
|
||||
var pos = player.getPosition();
|
||||
debugLbl.setText(String.format(
|
||||
"FPS: %.2f\n" +
|
||||
"Mem: %.2f / %.2f [MB]\n" +
|
||||
"Coords: %d : %d\n" +
|
||||
"Pos: %.2f : %.2f",
|
||||
runner.instantFPS(),
|
||||
runtime.totalMemory() / 1024f / 1024f,
|
||||
runtime.maxMemory() / 1024f / 1024f,
|
||||
coords.x(), coords.y(),
|
||||
pos.x(), pos.y())
|
||||
);
|
||||
|
||||
super.draw(screen, gui);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.input.Input;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.api.runner.GameRunner;
|
||||
import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
import com.bartlomiejpluta.base.util.profiler.FPSProfiler;
|
||||
|
||||
import com.bartlomiejpluta.demo.map.ForrestTempleHandler;
|
||||
import com.bartlomiejpluta.demo.entity.Player;
|
||||
@@ -22,6 +24,7 @@ public class DemoRunner implements GameRunner {
|
||||
private Screen screen;
|
||||
private Context context;
|
||||
private MenuManager menu;
|
||||
private GUI hud;
|
||||
|
||||
@Getter
|
||||
private MeleeWeaponDAO meleeWeaponDAO = new MeleeWeaponDAO();
|
||||
@@ -35,6 +38,8 @@ public class DemoRunner implements GameRunner {
|
||||
@Getter
|
||||
private Player player;
|
||||
|
||||
private final FPSProfiler fpsProfiler = FPSProfiler.create(20);
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
this.context = context;
|
||||
@@ -42,9 +47,10 @@ public class DemoRunner implements GameRunner {
|
||||
|
||||
configureScreen();
|
||||
configureCamera();
|
||||
initDAOs();
|
||||
initMenu();
|
||||
initPlayer();
|
||||
initDAOs();
|
||||
initHUD();
|
||||
initMenu();
|
||||
|
||||
menu.showStartMenu();
|
||||
|
||||
@@ -71,6 +77,13 @@ public class DemoRunner implements GameRunner {
|
||||
this.menu = new MenuManager(this, context);
|
||||
}
|
||||
|
||||
private void initHUD() {
|
||||
hud = context.newGUI();
|
||||
hud.hide();
|
||||
var hudComponent = hud.inflateComponent("00bd0625-b3b8-4abf-97b7-91f42bce28ec");
|
||||
hud.setRoot(hudComponent);
|
||||
}
|
||||
|
||||
private void initPlayer() {
|
||||
this.player = new Player(context, context.createEntity("815a5c5c-4979-42f5-a42a-ccbbff9a97e5"));
|
||||
}
|
||||
@@ -92,10 +105,12 @@ public class DemoRunner implements GameRunner {
|
||||
context.openMap(ForrestTempleHandler.UID);
|
||||
context.getMap().getObjectLayer(ForrestTempleHandler.MAIN_LAYER).addEntity(this.player);
|
||||
context.resume();
|
||||
hud.show();
|
||||
}
|
||||
|
||||
public void returnToStartMenu() {
|
||||
menu.closeAll();
|
||||
hud.hide();
|
||||
context.pause();
|
||||
context.closeMap();
|
||||
menu.disableGameMenu();
|
||||
@@ -106,9 +121,13 @@ public class DemoRunner implements GameRunner {
|
||||
context.close();
|
||||
}
|
||||
|
||||
public double instantFPS() {
|
||||
return fpsProfiler.getInstantFPS();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
fpsProfiler.update(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
26
widgets/00bd0625-b3b8-4abf-97b7-91f42bce28ec.xml
Normal file
26
widgets/00bd0625-b3b8-4abf-97b7-91f42bce28ec.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<demo:HUD
|
||||
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
||||
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
||||
widthMode="SizeMode.RELATIVE"
|
||||
heightMode="SizeMode.RELATIVE"
|
||||
width="1f"
|
||||
height="1f">
|
||||
|
||||
<base:BorderLayout-BottomRight>
|
||||
|
||||
<base:Label
|
||||
ref="debug"
|
||||
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
||||
widthMode="SizeMode.ABSOLUTE"
|
||||
width="200f"
|
||||
height="25f"
|
||||
margin="10f"
|
||||
alignment="GUI.ALIGN_BOTTOM | GUI.ALIGN_RIGHT"
|
||||
color="0xFFFFFF"
|
||||
fontSize="15f"/>
|
||||
|
||||
</base:BorderLayout-BottomRight>
|
||||
|
||||
</demo:HUD>
|
||||
Reference in New Issue
Block a user