Fix HUD positioning issue
This commit is contained in:
@@ -6,7 +6,7 @@ import com.bartlomiejpluta.base.api.gui.Component;
|
||||
import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.lib.gui.BaseComponent;
|
||||
import lombok.Setter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -14,7 +14,6 @@ public class Bar extends BaseComponent {
|
||||
|
||||
private final Color stroke;
|
||||
private final Color fill;
|
||||
@Setter
|
||||
private float value = 1.0f;
|
||||
private float actualValue = 1.0f;
|
||||
private final float speed = 0.05f;
|
||||
@@ -29,6 +28,10 @@ public class Bar extends BaseComponent {
|
||||
fill.setAlpha(1f);
|
||||
}
|
||||
|
||||
public void setValue(@NonNull Float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void setStrokeColor(Integer hex) {
|
||||
stroke.setRGB(hex);
|
||||
}
|
||||
@@ -53,12 +56,12 @@ public class Bar extends BaseComponent {
|
||||
actualValue += remainingDistance * speed;
|
||||
|
||||
gui.beginPath();
|
||||
gui.drawRectangle(x, y, Math.max(width * actualValue, 0), height);
|
||||
gui.drawRectangle(x + paddingLeft, y + paddingTop, Math.max(width * actualValue, 0), height);
|
||||
gui.setFillColor(fill);
|
||||
gui.fill();
|
||||
gui.closePath();
|
||||
gui.beginPath();
|
||||
gui.drawRectangle(x, y, width, height);
|
||||
gui.drawRectangle(x + paddingLeft, y + paddingTop, width, height);
|
||||
gui.setStrokeColor(stroke);
|
||||
gui.stroke();
|
||||
gui.closePath();
|
||||
|
||||
@@ -6,15 +6,14 @@ import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.gui.Ref;
|
||||
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.lib.gui.TextView;
|
||||
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;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -33,20 +32,15 @@ public class HUD extends BorderLayout {
|
||||
|
||||
private float logVisibilityDuration = 0f;
|
||||
|
||||
private Weapon currentWeapon;
|
||||
|
||||
@Ref("hp")
|
||||
private Bar hp;
|
||||
|
||||
@Ref("debug")
|
||||
private Label debugLbl;
|
||||
private TextView debugTxt;
|
||||
|
||||
@Ref("log")
|
||||
private Label logLbl;
|
||||
|
||||
@Ref("weapon")
|
||||
private IconView weapon;
|
||||
|
||||
public HUD(Context context, GUI gui, Map<String, Component> refs) {
|
||||
super(context, gui, refs);
|
||||
this.player = DemoRunner.instance().getPlayer();
|
||||
@@ -84,14 +78,13 @@ public class HUD extends BorderLayout {
|
||||
}
|
||||
|
||||
|
||||
this.currentWeapon = player.getWeapon();
|
||||
}
|
||||
|
||||
@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\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));
|
||||
debugTxt.setText(String.format("FPS: %.2f\n" + "Mem: %.2f / %.2f [MB]\n" + "Coords: %d : %d\n" + "Pos: %.2f : %.2f\n" + "Entities: %d\n", 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));
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<demo:HUD
|
||||
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
||||
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
||||
padding="20f"
|
||||
height="relative"
|
||||
width="relative">
|
||||
|
||||
@@ -15,10 +16,6 @@
|
||||
height="20f"/>
|
||||
</base:BorderLayout-TopLeft>
|
||||
|
||||
<base:BorderLayout-TopRight>
|
||||
<base:IconView ref="weapon" scale="2f"/>
|
||||
</base:BorderLayout-TopRight>
|
||||
|
||||
<base:BorderLayout-BottomLeft>
|
||||
<base:Label
|
||||
ref="log"
|
||||
@@ -30,13 +27,11 @@
|
||||
fontSize="15f"/>
|
||||
</base:BorderLayout-BottomLeft>
|
||||
|
||||
<base:BorderLayout-BottomRight>
|
||||
<base:Label
|
||||
<base:BorderLayout-BottomRight width="auto" height="auto">
|
||||
<base:TextView
|
||||
ref="debug"
|
||||
font="A.fonts.roboto_regular.uid"
|
||||
width="200f"
|
||||
height="25f"
|
||||
alignment="bottom|right"
|
||||
alignment="top|right"
|
||||
color="0xFFFFFF"
|
||||
fontSize="15f"/>
|
||||
</base:BorderLayout-BottomRight>
|
||||
|
||||
Reference in New Issue
Block a user