From 3f5f2b92534f10565586a321015d35d6baa84b4a Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 4 Oct 2026 11:13:30 +0200 Subject: [PATCH] =?UTF-8?q?Einige=20Fixes=20bez=C3=BCglich=20der=20Anzeige?= =?UTF-8?q?=20von=20Gegnern=20und=20deren=20Namen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/state/InteractionHudState.java | 6 ++- .../de/blight/game/state/WorldNpcsState.java | 45 ++++++++++++++----- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/blight-game/src/main/java/de/blight/game/state/InteractionHudState.java b/blight-game/src/main/java/de/blight/game/state/InteractionHudState.java index d2b2a14..c99a058 100644 --- a/blight-game/src/main/java/de/blight/game/state/InteractionHudState.java +++ b/blight-game/src/main/java/de/blight/game/state/InteractionHudState.java @@ -12,6 +12,8 @@ import com.jme3.scene.Node; import com.jme3.scene.Spatial; import de.blight.game.config.KeyBindings; import de.blight.game.config.KeyNames; +import de.blight.game.config.MenuScreen; +import de.blight.game.config.OverlayState; import de.blight.lang.TextResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -85,8 +87,8 @@ public class InteractionHudState extends BaseAppState { @Override public void update(float tpf) { - // Label ausblenden wenn Dialog aktiv - if (dialogHud != null && dialogHud.isActive()) { + if ((dialogHud != null && dialogHud.isActive()) + || OverlayState.isAnyOpen() || MenuScreen.isAnyOpen()) { labelText.setCullHint(Spatial.CullHint.Always); return; } diff --git a/blight-game/src/main/java/de/blight/game/state/WorldNpcsState.java b/blight-game/src/main/java/de/blight/game/state/WorldNpcsState.java index 0a585e5..306854c 100644 --- a/blight-game/src/main/java/de/blight/game/state/WorldNpcsState.java +++ b/blight-game/src/main/java/de/blight/game/state/WorldNpcsState.java @@ -47,6 +47,8 @@ import de.blight.common.model.trigger.NpcStatusTrigger; import de.blight.game.animation.AnimationAction; import de.blight.game.animation.AnimationLibrary; import de.blight.game.config.KeyBindings; +import de.blight.game.config.MenuScreen; +import de.blight.game.config.OverlayState; import de.blight.game.combat.CombatStyleBase; import de.blight.game.combat.DamageCalculator; import de.blight.game.combat.MeleeAttackCallback; @@ -593,7 +595,6 @@ public class WorldNpcsState extends BaseAppState implements MeleeAttackCallback for (int i = 0; i < spawned.size(); i++) { SpawnedNpc s = spawned.get(i); - if (s.aggroBehavior.isAttacking()) continue; Vector3f pos = s.visual().getLocalTranslation(); float dx = pos.x - charPos.x; @@ -619,6 +620,7 @@ public class WorldNpcsState extends BaseAppState implements MeleeAttackCallback private final ActionListener interactListener = (name, isPressed, tpf) -> { if (!isPressed || dialogActive || hoveredIdx < 0) return; + if (spawned.get(hoveredIdx).aggroBehavior.isAttacking()) return; startDialog(hoveredIdx); }; @@ -1946,30 +1948,49 @@ public class WorldNpcsState extends BaseAppState implements MeleeAttackCallback } private void updateNpcEnemyHud() { - if (npcEnemyHudNode == null) { return; } - boolean weaponOut = playerInput.isWeaponDrawn(); - if (!weaponOut) { + if (npcEnemyHudNode == null || cam == null || physicsChar == null) { return; } + + if (dialogActive || OverlayState.isAnyOpen() || MenuScreen.isAnyOpen()) { npcEnemyHudNode.setCullHint(Spatial.CullHint.Always); focusedNpcIdx = -1; return; } + + boolean anyAggro = false; + for (SpawnedNpc s : spawned) { + if (s.aggroBehavior.isAttacking()) { anyAggro = true; break; } + } + if (!anyAggro) { + npcEnemyHudNode.setCullHint(Spatial.CullHint.Always); + focusedNpcIdx = -1; + return; + } + Vector3f playerPos = physicsChar.getPhysicsLocation(); + float centerX = cam.getWidth() * 0.5f; + float hMargin = cam.getWidth() * 0.10f; + float screenH = cam.getHeight(); + focusedNpcIdx = -1; - float bestDistSq = 6f * 6f; + float bestDist = Float.MAX_VALUE; for (int i = 0; i < spawned.size(); i++) { SpawnedNpc s = spawned.get(i); - Vector3f npcPos = s.visual().getWorldTranslation(); + if (!s.aggroBehavior.isAttacking()) { continue; } + Vector3f npcPos = s.visual().getWorldTranslation(); + Vector3f headPos = npcPos.add(0f, 1.5f, 0f); + if (headPos.subtract(cam.getLocation()).dot(cam.getDirection()) <= 0f) { continue; } + Vector3f screen = cam.getScreenCoordinates(headPos); + if (Math.abs(screen.x - centerX) > hMargin) { continue; } + if (screen.y < 0f || screen.y > screenH) { continue; } float dx = npcPos.x - playerPos.x; float dz = npcPos.z - playerPos.z; - float distSq = dx * dx + dz * dz; - if (distSq < bestDistSq) { - bestDistSq = distSq; - focusedNpcIdx = i; - } + float d = (float) Math.sqrt(dx * dx + dz * dz); + if (d < bestDist) { bestDist = d; focusedNpcIdx = i; } } + if (focusedNpcIdx >= 0) { SpawnedNpc s = spawned.get(focusedNpcIdx); - float ratio = s.maxHp > 0 ? (float) s.currentHp / s.maxHp : 0f; + float ratio = s.maxHp > 0 ? (float) s.currentHp / s.maxHp : 0f; applyNpcEnemyHpRatio(ratio); npcEnemyHudNode.setCullHint(Spatial.CullHint.Inherit); } else {