Skip to content

Commit

Permalink
show poi in cities
Browse files Browse the repository at this point in the history
  • Loading branch information
valoeghese committed Dec 18, 2021
1 parent 5bc1085 commit 2a8e167
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/main/java/tk/valoeghese/fc0/client/Client2fc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
41 changes: 36 additions & 5 deletions src/main/java/tk/valoeghese/fc0/client/screen/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MusicPiece> pickMusic() {
Expand All @@ -424,4 +450,9 @@ private static List<MusicPiece> pickMusic() {
public static final Optional<MusicSettings> 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
}
}
4 changes: 4 additions & 0 deletions src/main/java/tk/valoeghese/fc0/world/kingdom/Kingdom.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file modified src/main/resources/assets/texture/gui/font_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2a8e167

Please sign in to comment.