Apply BASE API improvements

This commit is contained in:
2022-08-30 19:14:33 +02:00
parent 18883b66c2
commit c86f042cf8
11 changed files with 73 additions and 29 deletions

View File

@@ -19,7 +19,6 @@ import static java.lang.String.format;
public class EquipmentWindow extends DecoratedWindow {
private final DemoRunner runner;
private final Player player;
private final Window eqItemMenuWindow;
@@ -45,8 +44,7 @@ public class EquipmentWindow extends DecoratedWindow {
public EquipmentWindow(Context context, GUI gui, Map<String, Component> refs) {
super(context, gui, refs);
this.runner = (DemoRunner) context.getGameRunner();
this.player = runner.getPlayer();
this.player = context.getGlobal("player", Player.class);
this.eqItemMenuWindow = gui.inflateWindow(A.widgets.eq_item_menu.uid);
this.eqItemMenu = eqItemMenuWindow.reference("menu", VOptionChoice.class);
this.useBtn = eqItemMenuWindow.reference("use", Button.class);

View File

@@ -8,10 +8,10 @@ import com.bartlomiejpluta.base.api.screen.Screen;
import com.bartlomiejpluta.base.lib.gui.BorderLayout;
import com.bartlomiejpluta.base.lib.gui.IconView;
import com.bartlomiejpluta.base.lib.gui.Label;
import com.bartlomiejpluta.base.util.profiler.FPSProfiler;
import com.bartlomiejpluta.demo.entity.Player;
import com.bartlomiejpluta.demo.event.EnemyDiedEvent;
import com.bartlomiejpluta.demo.event.HitEvent;
import com.bartlomiejpluta.demo.runner.DemoRunner;
import com.bartlomiejpluta.demo.util.LimitedQueue;
import com.bartlomiejpluta.demo.world.weapon.Weapon;
import lombok.extern.slf4j.Slf4j;
@@ -24,11 +24,12 @@ public class HUD extends BorderLayout {
private static final int MAX_LOG_SIZE = 10;
private static final float LOG_VISIBILITY_DURATION = 8000f;
private static final float LOG_VISIBILITY_FADING_OUT = 1000f;
private final DemoRunner runner;
private final Player player;
private final Runtime runtime;
private final LimitedQueue<String> logger = new LimitedQueue<>(MAX_LOG_SIZE);
private final FPSProfiler fpsProfiler;
private float logVisibilityDuration = 0f;
private Weapon currentWeapon;
@@ -47,8 +48,8 @@ public class HUD extends BorderLayout {
public HUD(Context context, GUI gui, Map<String, Component> refs) {
super(context, gui, refs);
this.runner = (DemoRunner) context.getGameRunner();
this.player = runner.getPlayer();
this.player = context.getGlobal("player", Player.class);
this.fpsProfiler = context.getGlobal("fps-profiler", FPSProfiler.class);
this.runtime = Runtime.getRuntime();
context.addEventListener(HitEvent.TYPE, this::logHitEvent);
context.addEventListener(EnemyDiedEvent.TYPE, this::logEnemyDiedEvent);
@@ -89,7 +90,7 @@ public class HUD extends BorderLayout {
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\n" + "Entities: %d", runner.instantFPS(), runtime.totalMemory() / 1024f / 1024f, runtime.maxMemory() / 1024f / 1024f, coords.x(), coords.y(), pos.x(), pos.y(), player.getLayer().getEntities().size() - 1));
debugLbl.setText(String.format("FPS: %.2f\n" + "Mem: %.2f / %.2f [MB]\n" + "Coords: %d : %d\n" + "Pos: %.2f : %.2f\n" + "Entities: %d", fpsProfiler.getInstantFPS(), runtime.totalMemory() / 1024f / 1024f, runtime.maxMemory() / 1024f / 1024f, coords.x(), coords.y(), pos.x(), pos.y(), player.getLayer().getEntities().size() - 1));
logLbl.setAlpha(Math.min(1f, logVisibilityDuration / LOG_VISIBILITY_FADING_OUT));

View File

@@ -26,7 +26,7 @@ public class LootWindow extends DecoratedWindow implements Inflatable {
public LootWindow(Context context, GUI gui, Map<String, Component> refs) {
super(context, gui, refs);
this.player = ((DemoRunner) context.getGameRunner()).getPlayer();
this.player = context.getGlobal("player", Player.class);
}
@Override