diff --git a/src/main/java/tk/valoeghese/fc0/client/Client2fc.java b/src/main/java/tk/valoeghese/fc0/client/Client2fc.java index ca01f13..3b953ff 100644 --- a/src/main/java/tk/valoeghese/fc0/client/Client2fc.java +++ b/src/main/java/tk/valoeghese/fc0/client/Client2fc.java @@ -2,7 +2,6 @@ import org.joml.AxisAngle4f; import org.joml.Matrix4f; -import org.joml.Vector2f; import org.joml.Vector3f; import org.lwjgl.glfw.GLFWCursorPosCallbackI; import org.lwjgl.openal.AL10; @@ -344,11 +343,18 @@ protected void tick() { this.gameScreen.heightmapWidget.changeText("Heightmap: " + this.player.chunk.getHeightmap(tilePos.x & 0xF, tilePos.z & 0xF)); this.gameScreen.lightingWidget.changeText(this.player.chunk.getLightLevelText(tilePos.x & 0xF, tilePos.y, tilePos.z & 0xF)); + boolean showWidget = this.gameScreen.updatePOI(); + Kingdom kingdom = this.player.chunk.getKingdom(tilePos.x & 0xF, tilePos.z & 0xF); if (this.gameScreen.getCurrentKingdom() != kingdom) { + showWidget = true; this.gameScreen.setCurrentKingdom(kingdom); } + + if (showWidget) { + this.gameScreen.showPOIWidget(); + } } else { this.gameScreen.heightmapWidget.changeText("Loading"); this.gameScreen.lightingWidget.changeText("Loading"); diff --git a/src/main/java/tk/valoeghese/fc0/client/screen/GameScreen.java b/src/main/java/tk/valoeghese/fc0/client/screen/GameScreen.java index abecac8..9ddb5ac 100644 --- a/src/main/java/tk/valoeghese/fc0/client/screen/GameScreen.java +++ b/src/main/java/tk/valoeghese/fc0/client/screen/GameScreen.java @@ -71,6 +71,8 @@ public GameScreen(Client2fc game) { public final Text profilerWidget; private float offset; + private PlaceOfInterest lastPOI; + private final Text.Moveable kingdomWidget; private final ResizableRect healthBar; private final ResizableRect unhealthBar; @@ -399,13 +401,37 @@ public Kingdom getCurrentKingdom() { return this.currentKingdom; } - public void setCurrentKingdom(Kingdom kingdom) { + /** + * Recalculates the stored POI. + * @return if the POI changed. + */ + public boolean updatePOI() { + TilePos position = this.game.getPlayer().getTilePos(); + PlaceOfInterest location = CityGenerator.isInCity(this.game.getWorld(), position.x, position.z, Generator.OVERWORLD_CITY_SIZE) ? PlaceOfInterest.CITY : PlaceOfInterest.KINGDOM; + boolean result = this.lastPOI != location; + this.lastPOI = location; + return result; + } + + public void setCurrentKingdom(@Nullable Kingdom kingdom) { this.currentKingdom = kingdom; - this.cityWidget.changeText(kingdom.debugString()); - String text = kingdom.toString(); - this.kingdomWidget.changeText(text, -Text.widthOf(text.toCharArray()), 0.7f); - this.kingdomShowTime = 1.0f; + if (kingdom != null) { + this.cityWidget.changeText(kingdom.debugString()); + } + } + + public void showPOIWidget() { + if (this.currentKingdom != null) { + String text = switch (this.lastPOI) { + case KINGDOM -> this.currentKingdom.toString(); + case CITY -> "City of " + this.currentKingdom.getName(); + default -> "Missingno"; + }; + + this.kingdomWidget.changeText(text, -Text.widthOf(text.toCharArray()), 0.7f); + this.kingdomShowTime = 1.0f; + } } private static List pickMusic() { @@ -424,4 +450,9 @@ private static List pickMusic() { public static final Optional GAME_MUSIC = Optional.of(new MusicSettings(GameScreen::pickMusic, 600 + 300, 5 * 600 + 300, 0.4f)); private static final float FONT_SCALE = 0.67f; + + private enum PlaceOfInterest { + KINGDOM, + CITY + } } diff --git a/src/main/java/tk/valoeghese/fc0/world/kingdom/Kingdom.java b/src/main/java/tk/valoeghese/fc0/world/kingdom/Kingdom.java index 9490335..69f1948 100644 --- a/src/main/java/tk/valoeghese/fc0/world/kingdom/Kingdom.java +++ b/src/main/java/tk/valoeghese/fc0/world/kingdom/Kingdom.java @@ -175,6 +175,10 @@ private String pickName(Random rand) { return sb.toString(); } + public String getName() { + return this.name; + } + @Override public String toString() { return "Kingdom of " + this.name; diff --git a/src/main/resources/assets/texture/gui/font_atlas.png b/src/main/resources/assets/texture/gui/font_atlas.png index 060e77e..9f1588d 100644 Binary files a/src/main/resources/assets/texture/gui/font_atlas.png and b/src/main/resources/assets/texture/gui/font_atlas.png differ