Anzeige von Areas aktualisiert
This commit is contained in:
@@ -9,13 +9,17 @@ import com.jme3.audio.AudioNode;
|
||||
import com.jme3.audio.AudioSource;
|
||||
import com.jme3.font.BitmapFont;
|
||||
import com.jme3.font.BitmapText;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import de.blight.common.AreaDefinition;
|
||||
import de.blight.common.AreaDefinitionIO;
|
||||
import de.blight.common.AreaIO;
|
||||
import de.blight.common.PlacedArea;
|
||||
import de.blight.game.config.NinePatch;
|
||||
import de.blight.lang.TextResolver;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -67,7 +71,11 @@ public class MusicSystem extends BaseAppState {
|
||||
private boolean isDaytime = true;
|
||||
|
||||
private BitmapText areaNameText;
|
||||
private float areaNameTimer = 0f;
|
||||
private Node areaNamePanel = null;
|
||||
private Material areaNamePanelMat = null;
|
||||
private float areaNameTimer = 0f;
|
||||
private boolean areaNameFadingIn = false;
|
||||
private float areaNameFadeInElapsed = 0f;
|
||||
|
||||
// ── Lifecycle ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -97,7 +105,6 @@ public class MusicSystem extends BaseAppState {
|
||||
if (def == null) continue;
|
||||
AudioNode day = loadTrack(def.dayTrack());
|
||||
AudioNode night = loadTrack(def.nightTrack());
|
||||
if (day == null && night == null) continue;
|
||||
String rawId = def.id();
|
||||
String shortId = rawId.startsWith("area.") ? rawId.substring("area.".length()) : rawId;
|
||||
data.add(area);
|
||||
@@ -126,7 +133,8 @@ public class MusicSystem extends BaseAppState {
|
||||
phases.clear();
|
||||
activeSlot.clear();
|
||||
pendingSlot.clear();
|
||||
if (areaNameText != null) app.getGuiNode().detachChild(areaNameText);
|
||||
if (areaNamePanel != null) { app.getGuiNode().detachChild(areaNamePanel); areaNamePanel = null; }
|
||||
if (areaNameText != null) app.getGuiNode().detachChild(areaNameText);
|
||||
}
|
||||
|
||||
@Override protected void onEnable() {}
|
||||
@@ -152,15 +160,22 @@ public class MusicSystem extends BaseAppState {
|
||||
|
||||
@Override
|
||||
public void update(float tpf) {
|
||||
// area name display timer
|
||||
if (areaNameTimer > 0f) {
|
||||
// area name display: fade-in → visible → fade-out
|
||||
if (areaNameFadingIn) {
|
||||
areaNameFadeInElapsed += tpf;
|
||||
float alpha = Math.min(areaNameFadeInElapsed / AREA_NAME_FADE, 1f);
|
||||
setAreaNameAlpha(alpha);
|
||||
if (areaNameFadeInElapsed >= AREA_NAME_FADE) {
|
||||
areaNameFadingIn = false;
|
||||
setAreaNameAlpha(1f);
|
||||
}
|
||||
} else if (areaNameTimer > 0f) {
|
||||
areaNameTimer -= tpf;
|
||||
if (areaNameTimer <= 0f) {
|
||||
areaNameText.setColor(new ColorRGBA(1f, 0.95f, 0.8f, 0f));
|
||||
areaNameTimer = 0f;
|
||||
setAreaNameAlpha(0f);
|
||||
} else if (areaNameTimer < AREA_NAME_FADE) {
|
||||
float alpha = areaNameTimer / AREA_NAME_FADE;
|
||||
areaNameText.setColor(new ColorRGBA(1f, 0.95f, 0.8f, alpha));
|
||||
setAreaNameAlpha(areaNameTimer / AREA_NAME_FADE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,15 +220,18 @@ public class MusicSystem extends BaseAppState {
|
||||
private void startArea(int i) {
|
||||
int slot = desiredSlot(i);
|
||||
AudioNode n = nodes.get(i)[slot];
|
||||
if (n == null) return;
|
||||
n.setVolume(0f);
|
||||
n.setLooping(true);
|
||||
rootNode.attachChild(n);
|
||||
n.play();
|
||||
activeSlot.set(i, slot);
|
||||
pendingSlot.set(i, -1);
|
||||
phases.set(i, Phase.FADING_IN);
|
||||
log.info("[MusicSystem] Area {} → slot {} gestartet", i, slot == SLOT_DAY ? "Tag" : "Nacht");
|
||||
if (n != null) {
|
||||
n.setVolume(0f);
|
||||
n.setLooping(true);
|
||||
rootNode.attachChild(n);
|
||||
n.play();
|
||||
activeSlot.set(i, slot);
|
||||
pendingSlot.set(i, -1);
|
||||
phases.set(i, Phase.FADING_IN);
|
||||
log.info("[MusicSystem] Area {} → slot {} gestartet", i, slot == SLOT_DAY ? "Tag" : "Nacht");
|
||||
} else {
|
||||
phases.set(i, Phase.ACTIVE);
|
||||
}
|
||||
showAreaName(i);
|
||||
}
|
||||
|
||||
@@ -286,19 +304,47 @@ public class MusicSystem extends BaseAppState {
|
||||
// ── Area-Name-Anzeige ─────────────────────────────────────────────────────
|
||||
|
||||
private void showAreaName(int i) {
|
||||
String key = i < areaNameKeys.size() ? areaNameKeys.get(i) : "";
|
||||
String shortId = i < areaShortIds.size() ? areaShortIds.get(i) : key;
|
||||
String key = i < areaNameKeys.size() ? areaNameKeys.get(i) : "";
|
||||
String shortId = i < areaShortIds.size() ? areaShortIds.get(i) : key;
|
||||
String resolved = TextResolver.get().resolveOrId(key);
|
||||
String name = resolved.equals(key) ? shortId : resolved;
|
||||
String name = resolved.equals(key) ? shortId : resolved;
|
||||
if (name.isBlank()) return;
|
||||
|
||||
areaNameText.setText(name);
|
||||
float tw = areaNameText.getLineWidth() * 0.5f;
|
||||
float sw = app.getCamera().getWidth();
|
||||
float sh = app.getCamera().getHeight();
|
||||
areaNameText.setLocalTranslation((sw - tw) / 2f, sh - 40f, 0f);
|
||||
areaNameText.setColor(new ColorRGBA(1f, 0.95f, 0.8f, 1f));
|
||||
areaNameTimer = AREA_NAME_SHOW;
|
||||
float tw = areaNameText.getLineWidth() * 0.5f;
|
||||
float th = areaNameText.getLineHeight() * 0.5f;
|
||||
float sw = app.getCamera().getWidth();
|
||||
float sh = app.getCamera().getHeight();
|
||||
|
||||
float padX = 20f, padY = 10f;
|
||||
float textX = Math.round((sw - tw) / 2f);
|
||||
float textY = sh - 40f;
|
||||
float panelX = Math.round(textX - padX);
|
||||
float panelY = Math.round(textY - th - padY);
|
||||
float panelW = Math.round(tw + padX * 2f);
|
||||
float panelH = Math.round(th + padY * 2f);
|
||||
|
||||
areaNameText.setLocalTranslation(textX, textY, 0f);
|
||||
|
||||
if (areaNamePanel != null) app.getGuiNode().detachChild(areaNamePanel);
|
||||
areaNamePanel = NinePatch.panel(assets).build(panelX, panelY, panelW, panelH, -1f);
|
||||
areaNamePanelMat = null;
|
||||
for (Spatial s : areaNamePanel.getChildren()) {
|
||||
if (s instanceof Geometry g) { areaNamePanelMat = g.getMaterial(); break; }
|
||||
}
|
||||
app.getGuiNode().attachChild(areaNamePanel);
|
||||
|
||||
setAreaNameAlpha(0f);
|
||||
areaNameFadingIn = true;
|
||||
areaNameFadeInElapsed = 0f;
|
||||
areaNameTimer = AREA_NAME_SHOW;
|
||||
}
|
||||
|
||||
private void setAreaNameAlpha(float alpha) {
|
||||
areaNameText.setColor(new ColorRGBA(1f, 0.95f, 0.8f, alpha));
|
||||
if (areaNamePanelMat != null) {
|
||||
areaNamePanelMat.setColor("Color", new ColorRGBA(1f, 1f, 1f, alpha));
|
||||
}
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user