-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/1.21/map info changes (#308)
feat: overhaul minimap info display Configurable components, which can be enabled/disabled/reordered.
- Loading branch information
1 parent
acba792
commit 399c03a
Showing
28 changed files
with
1,068 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.ftb.mods.ftbchunks.api.client.minimap; | ||
|
||
import dev.ftb.mods.ftbchunks.client.map.MapDimension; | ||
import dev.ftb.mods.ftblibrary.math.XZ; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.player.LocalPlayer; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Minimal context for Minimap Info Components | ||
* | ||
* @param minecraft The Minecraft instance (Helper) | ||
* @param player The client player | ||
* @param mapDimension The dimension of the players location | ||
* @param mapChunksPos The chunk for the players location | ||
* @param playerPos the players pos | ||
* @param infoSettings raw settings for this component | ||
*/ | ||
public record MinimapContext( | ||
Minecraft minecraft, | ||
LocalPlayer player, | ||
MapDimension mapDimension, | ||
XZ mapChunksPos, | ||
Vec3 playerPos, | ||
Map<String, String> infoSettings | ||
) { | ||
|
||
public String getSetting(MinimapInfoComponent infoComponent) { | ||
return infoSettings.getOrDefault(infoComponent.id().toString(), ""); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapInfoComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package dev.ftb.mods.ftbchunks.api.client.minimap; | ||
|
||
import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
/** | ||
* An entry point for developers to create custom minimap info components. | ||
*/ | ||
public interface MinimapInfoComponent { | ||
/** | ||
* The ID of this component. | ||
*/ | ||
ResourceLocation id(); | ||
|
||
/** | ||
* Render your component here, the {@link com.mojang.blaze3d.vertex.PoseStack} will already be scaled and | ||
* translated to the correct position (centered by default). We do not provide an X and Y position as | ||
* 0, 0 is the center of the correct location. Use 0, 0 as the center of the component and {@link #height(MinimapContext)} | ||
* to allocate the correct height for the component. | ||
* | ||
* @param context The minimap context | ||
* @param graphics The graphics object see {@link GuiGraphics} | ||
* @param font The font object | ||
*/ | ||
void render(MinimapContext context, GuiGraphics graphics, Font font); | ||
|
||
/** | ||
* Set of Info {@link TranslatedOption} that are used to configure options for rendering the waypoint | ||
* this is exposed in the right click action of Minimap Info GUI | ||
* @return the set of {@link TranslatedOption}. | ||
*/ | ||
default Set<TranslatedOption> getConfigComponents() { | ||
return Set.of(); | ||
} | ||
|
||
/** | ||
* The height of the component is used to allocate the correct space for the component. Failure to return the correct | ||
* height will result in the component overlapping with other components. | ||
* | ||
* @param context The minimap context | ||
* @return The height of the component | ||
*/ | ||
default int height(MinimapContext context) { | ||
return computeLineHeight(context.minecraft(), 1) + 1; | ||
} | ||
|
||
/** | ||
* Checked on each render frame to determine if the height for the component should be allocated | ||
*/ | ||
default boolean shouldRender(MinimapContext context) { | ||
return true; | ||
} | ||
|
||
/** | ||
* Helper method to compute the height of a text component whilst taking into account the font scale | ||
*/ | ||
default int computeLineHeight(Minecraft minecraft, int lines) { | ||
final float fontScale = FTBChunksClientConfig.MINIMAP_FONT_SCALE.get().floatValue(); | ||
return (int) ((minecraft.font.lineHeight + 2) * lines * fontScale); | ||
} | ||
|
||
/** | ||
* Helper method to draw centered text without the faff of calculating the width of the text | ||
*/ | ||
default void drawCenteredText(Font font, GuiGraphics graphics, Component text, int y) { | ||
int textWidth = font.width(text.getVisualOrderText()); | ||
graphics.drawString(font, text, -textWidth / 2, y, 0xFFFFFFFF, true); | ||
} | ||
|
||
|
||
/** | ||
* @return display name render in the Minimap Info Settings GUI | ||
*/ | ||
default Component displayName() { | ||
return Component.translatable("minimap.info." + id().getNamespace() + "." + id().getPath() + ".title"); | ||
} | ||
|
||
/** | ||
* @return hover texted displayed render in the Minimap Info Settings GUI | ||
*/ | ||
default Component description() { | ||
return Component.translatable("minimap.info." + id().getNamespace() + "." + id().getPath() + ".description"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/TranslatedOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.ftb.mods.ftbchunks.api.client.minimap; | ||
|
||
public record TranslatedOption( | ||
String optionName, | ||
String translationKey | ||
) { | ||
|
||
public static TranslatedOption of(String optionName) { | ||
String translatedKey = optionName.toLowerCase().replaceAll("[^a-z0-9]", "_"); | ||
return new TranslatedOption(optionName, "minimap.option." + translatedKey); | ||
} | ||
} |
Oops, something went wrong.