Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ neoForge {
}

dependencies {
compileOnly "maven.modrinth:no-mans-land:${no_mans_land_version}"
compileOnly "me.shedaniel.cloth:cloth-config-neoforge:${cloth_config_version}"
compileOnly "dev.emi:emi-xplat-mojmap:${emi_version}"
compileOnly "maven.modrinth:entitytexturefeatures:${etf_version}-neoforge-1.21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.evandev.fieldguide.client.FieldGuideClient;
import com.evandev.fieldguide.client.gui.util.Bounds;
import com.evandev.fieldguide.client.gui.widget.TabButton;
import com.evandev.fieldguide.compat.nomansland.NoMansLandCompat;
import com.evandev.fieldguide.config.ServerConfig;
import com.evandev.fieldguide.api.Category;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -57,6 +58,24 @@ protected void init() {
initCategories();
}

@Override
public void removed() {
super.removed();
if (this.minecraft != null) {
Minecraft minecraft = this.minecraft;
minecraft.tell(() -> {
Screen current = minecraft.screen;
if (current == null || !current.getClass().getName().startsWith("com.evandev.fieldguide."))
NoMansLandCompat.stopReplay();
});
}
}

@Override
public boolean isPauseScreen() {
return !NoMansLandCompat.isAvailable();
}

private void initCategories() {
// Sort categories
this.sortedCategories.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import com.evandev.fieldguide.client.gui.util.Bounds;
import com.evandev.fieldguide.client.gui.util.EntryRenderHelper;
import com.evandev.fieldguide.client.gui.widget.FieldGuideSearchBox;
import com.evandev.fieldguide.client.gui.widget.FriendMoonWidget;
import com.evandev.fieldguide.client.gui.widget.PageTurnButton;
import com.evandev.fieldguide.client.gui.widget.PaginatedGridWidget;
import com.evandev.fieldguide.client.gui.widget.VariantOverviewWidget;
import com.evandev.fieldguide.client.manager.ClientTextManager;
import com.evandev.fieldguide.client.progress.ProgressManager;
import com.evandev.fieldguide.compat.cobblemon.ClientFieldGuideCobblemonCompat;
import com.evandev.fieldguide.compat.exposure.ClientExposureCompat;
import com.evandev.fieldguide.compat.nomansland.NoMansLandCompat;
import com.evandev.fieldguide.compat.scholar.ScholarCompat;
import com.evandev.fieldguide.config.ClientConfig;
import com.evandev.fieldguide.config.ServerConfig;
Expand Down Expand Up @@ -82,6 +84,9 @@ public class FieldGuideEntryScreen extends BookScreen {
private PageTurnButton prevVariantButton;
private PageTurnButton nextVariantButton;
private VariantOverviewWidget variantOverviewWidget;
private FriendMoonWidget friendMoonWidget;
private int descX, descY, descW;
private boolean replayResetForScreen = false;

private float hoverScale = 1.0f;
private long lastRenderTime = 0;
Expand Down Expand Up @@ -172,6 +177,10 @@ private void updateWidgetVisibility() {
widget.visible = !overviewVisible;
}

if (this.friendMoonWidget != null) {
this.friendMoonWidget.visible = !overviewVisible;
}

if (this.prevVariantButton != null) {
this.prevVariantButton.visible = !overviewVisible;
this.prevVariantButton.active = currentVariantIndex > 0;
Expand Down Expand Up @@ -227,6 +236,7 @@ protected void init() {

setupNavigationButtons();
refreshExposureWidgets();
setupFriendMoonWidget(unlocked);

if (unlocked && ServerConfig.get().enableCopyingPages) {
boolean hasPaper = this.minecraft != null && this.minecraft.player != null && (this.minecraft.player.isCreative() || this.minecraft.player.getInventory().contains(Items.PAPER.getDefaultInstance()));
Expand Down Expand Up @@ -262,6 +272,34 @@ public void playDownSound(SoundManager handler) {
}
}

private void setupFriendMoonWidget(boolean unlocked) {
this.friendMoonWidget = null;
if (!replayResetForScreen) {
NoMansLandCompat.stopReplay();
replayResetForScreen = true;
}
if (!unlocked || !NoMansLandCompat.isAvailable() || !NoMansLandCompat.isIntegrationUnlocked()) return;

List<ResourceLocation> dialogues = NoMansLandCompat.getDialoguesForEntry(EntryResolver.resolveCoreEntry(entry));
if (dialogues.isEmpty()) return;

int iconSize = 16;
int iconX = this.leftPageBounds.left() + this.leftPageBounds.width() - iconSize - 12;
int iconY = this.leftPageBounds.top() + 12;

if (Services.PLATFORM.isModLoaded("exposure")) {
String variantId = (!entityVariants.isEmpty() && currentVariantIndex < entityVariants.size())
? entityVariants.get(currentVariantIndex).id() : null;
if (!ClientExposureCompat.willRenderAddPhotoButton(entry, variantId)) return;
iconY += iconSize + 2;
}

this.friendMoonWidget = new FriendMoonWidget(iconX, iconY, iconSize, dialogues,
() -> ClientFieldGuideManager.getEntryDescription(entry, this.initialVariant));
this.addRenderableWidget(this.friendMoonWidget);
updateWidgetVisibility();
}

private void setupTextWidgets(boolean unlocked) {
int textX = this.rightPageBounds.left() + 6;
int titleY = this.leftPageBounds.top() + 8;
Expand Down Expand Up @@ -308,6 +346,10 @@ private void setupTextWidgets(boolean unlocked) {
int textAreaHeight = this.rightPageBounds.bottom() - 29 - textY;
int maxLines = textAreaHeight / LINE_HEIGHT;

this.descX = textX;
this.descY = textY;
this.descW = textAreaWidth;

String initialDesc = ClientFieldGuideManager.getEntryDescription(entry, this.initialVariant);
if (!ServerConfig.get().disableEditingDescriptions) {
this.descriptionWidget = ScholarCompat.createTextArea(this.font, textX, textY, textAreaWidth, textAreaHeight, maxLines, LINE_HEIGHT, ClientConfig.get().getTextColorInt(), true, FieldGuideLimits.MAX_ENTRY_DESCRIPTION_LENGTH, initialDesc,
Expand Down Expand Up @@ -414,6 +456,9 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.variantOverviewWidget.mouseClicked(mouseX, mouseY, button)) return true;
}

if (this.friendMoonWidget != null && this.friendMoonWidget.visible
&& this.friendMoonWidget.mouseClicked(mouseX, mouseY, button)) return true;

if (super.mouseClicked(mouseX, mouseY, button)) return true;

List<Season> seasons = SeasonsAPI.getGrowingSeasons(entry);
Expand Down Expand Up @@ -593,7 +638,12 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
} else {
textY += LINE_HEIGHT; // Buffer
}
guiGraphics.drawWordWrap(font, Component.literal(ClientFieldGuideManager.getEntryDescription(entry)), titleX, textY, textAreaWidth, ClientConfig.get().getTextColorInt());
this.descX = titleX;
this.descY = textY;
this.descW = textAreaWidth;
if (!NoMansLandCompat.isReplayActive()) {
guiGraphics.drawWordWrap(font, Component.literal(ClientFieldGuideManager.getEntryDescription(entry)), titleX, textY, textAreaWidth, ClientConfig.get().getTextColorInt());
}
}
}

Expand Down Expand Up @@ -691,7 +741,13 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
}

guiGraphics.pose().popPose();

boolean replaying = ClientFieldGuideManager.isUnlocked(entry) && NoMansLandCompat.isReplayActive();
if (this.descriptionWidget != null) this.descriptionWidget.visible = !replaying;
super.render(guiGraphics, mouseX, mouseY, partialTick);
if (replaying) {
NoMansLandCompat.renderDescriptionRewrite(guiGraphics, this.font, descX, descY, descW, ClientConfig.get().getTextColorInt());
}
}

private void renderSeasons(GuiGraphics guiGraphics, int x, int y, int mouseX, int mouseY) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.evandev.fieldguide.client.gui.widget;

import com.evandev.fieldguide.Constants;
import com.evandev.fieldguide.compat.nomansland.NoMansLandCompat;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.function.Supplier;

public class FriendMoonWidget extends AbstractWidget {
public static final ResourceLocation IDLE = texture("idle");
public static final ResourceLocation HOVER = texture("hover");
public static final ResourceLocation TALKING = texture("talking");
public static final ResourceLocation UNHEARD = texture("unheard");
private static final float TALK_FRAME_SPEED = 1f / 3f;

private static ResourceLocation texture(String name) {
return ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "textures/gui/friend_moon/" + name + ".png");
}

private final List<ResourceLocation> dialogues;
private final Supplier<String> descriptionSupplier;
private float talkProgress = 0f;

public FriendMoonWidget(int x, int y, int size, List<ResourceLocation> dialogues, Supplier<String> descriptionSupplier) {
super(x, y, size, size, Component.translatable("gui.fieldguide.friend_moon"));
this.dialogues = dialogues;
this.descriptionSupplier = descriptionSupplier;
}

@Override
protected void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
boolean heard = !NoMansLandCompat.getHeardDialogues(dialogues).isEmpty();
boolean replayActive = NoMansLandCompat.isReplayActive();
this.active = heard && !replayActive;

ResourceLocation texture;
if (replayActive) {
if (NoMansLandCompat.isReplayTyping()) {
float delta = Minecraft.getInstance().getTimer().getGameTimeDeltaTicks();
talkProgress = (talkProgress + (delta * TALK_FRAME_SPEED)) % 2f;
texture = (((int) talkProgress) == 1) ? TALKING : HOVER;
} else {
talkProgress = 0f;
texture = HOVER;
}
} else if (!heard) {
talkProgress = 0f;
texture = UNHEARD;
} else {
talkProgress = 0f;
texture = this.isHovered() ? HOVER : IDLE;
}

RenderSystem.enableBlend();
guiGraphics.blit(texture, getX(), getY(), 0, 0, this.width, this.height, this.width, this.height);
RenderSystem.disableBlend();
}

@Override
public void onClick(double mouseX, double mouseY) {
if (NoMansLandCompat.isReplayActive()) return;
List<ResourceLocation> heard = NoMansLandCompat.getHeardDialogues(dialogues);
if (heard.isEmpty() || Minecraft.getInstance().player == null) return;
ResourceLocation pick = heard.get(Minecraft.getInstance().player.getRandom().nextInt(heard.size()));
NoMansLandCompat.startReplay(pick, descriptionSupplier.get());
}

@Override
public void playDownSound(@NotNull SoundManager handler) {
if (NoMansLandCompat.getHeardDialogues(dialogues).isEmpty()) return;
handler.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 0.9F, 0.25F));
}

@Override
protected void updateWidgetNarration(@NotNull NarrationElementOutput narrationElementOutput) {
this.defaultButtonNarrationText(narrationElementOutput);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public class ClientExposureCompat {
private static final WidgetSprites ADD_PHOTO_SPRITES = new WidgetSprites(ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "widget/exposure/add_photo"), ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "widget/exposure/add_photo_highlighted"));
private static final ResourceLocation MISSING_PHOTOGRAPH_BACKGROUND = ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "textures/gui/exposure/missing_photograph.png");

public static boolean willRenderAddPhotoButton(Object entry, String variantId) {
if (!ClientFieldGuideManager.isUnlocked(entry)) return false;
if (variantId != null && !variantId.isEmpty() && !ServerConfig.get().unlockAllVariants
&& !ClientFieldGuideManager.isVariantUnlocked(entry, variantId)) return false;
if (!ClientConfig.get().exposureAddPhotographButton) return false;
return ProgressManager.getInstance().getPhotograph(entry, variantId).isEmpty();
}

public static void setupExposureWidgets(FieldGuideEntryScreen screen, Object entry, String variantId) {
if (!ClientFieldGuideManager.isUnlocked(entry)) return;

Expand Down
Loading
Loading