Skip to content

Commit 097bba6

Browse files
committed
Exposure compat progress
1 parent 826c9cd commit 097bba6

16 files changed

Lines changed: 203 additions & 54 deletions

File tree

common/src/main/java/com/evandev/fieldguide/client/FieldGuideClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.evandev.fieldguide.Constants;
44
import com.evandev.fieldguide.client.gui.screens.BookScreen;
55
import com.evandev.fieldguide.client.gui.screens.FieldGuideEntryScreen;
6-
import com.evandev.fieldguide.client.gui.screens.FieldGuideScreen;
6+
import com.evandev.fieldguide.client.gui.screens.FieldGuideCategoryScreen;
77
import com.evandev.fieldguide.client.scanning.FieldGuideScanner;
88
import com.evandev.fieldguide.config.ModConfig;
99
import com.evandev.fieldguide.data.Category;
@@ -54,8 +54,8 @@ public static void onClientTick(Minecraft minecraft) {
5454
if (isRecent && lastEntry != null) {
5555
Category targetCategory = manager.getCategoryForEntry(lastEntry);
5656
if (targetCategory != null) {
57-
int page = FieldGuideScreen.getPageForEntry(targetCategory, lastEntry);
58-
FieldGuideScreen mainScreen = new FieldGuideScreen(targetCategory, page);
57+
int page = FieldGuideCategoryScreen.getPageForEntry(targetCategory, lastEntry);
58+
FieldGuideCategoryScreen mainScreen = new FieldGuideCategoryScreen(targetCategory, page);
5959
minecraft.setScreen(new FieldGuideEntryScreen(mainScreen, lastEntry));
6060
return;
6161
}
@@ -65,7 +65,7 @@ public static void onClientTick(Minecraft minecraft) {
6565
if ("last_opened_screen".equals(defaultMode) && BookScreen.lastOpenedScreen != null) {
6666
minecraft.setScreen(BookScreen.lastOpenedScreen);
6767
} else {
68-
minecraft.setScreen(new FieldGuideScreen());
68+
minecraft.setScreen(new FieldGuideCategoryScreen());
6969
}
7070
}
7171
}

common/src/main/java/com/evandev/fieldguide/client/gui/screens/FieldGuideScreen.java renamed to common/src/main/java/com/evandev/fieldguide/client/gui/screens/FieldGuideCategoryScreen.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
import java.util.*;
3838

39-
public class FieldGuideScreen extends BookScreen {
39+
public class FieldGuideCategoryScreen extends BookScreen {
4040
private static final int ITEMS_PER_PAGE = 9;
4141
private static final int ITEMS_PER_VIEW = ITEMS_PER_PAGE * 2;
4242

@@ -63,21 +63,21 @@ public class FieldGuideScreen extends BookScreen {
6363
private PageTurnButton backButton;
6464
private FieldGuideSearchBox searchBox;
6565

66-
public FieldGuideScreen() {
66+
public FieldGuideCategoryScreen() {
6767
super(Component.translatable("title.fieldguide.field_guide"));
6868
}
6969

70-
public FieldGuideScreen(Category initialCategory) {
70+
public FieldGuideCategoryScreen(Category initialCategory) {
7171
this();
7272
this.setSelectedCategory(initialCategory);
7373
}
7474

75-
public FieldGuideScreen(Category initialCategory, int initialPage) {
75+
public FieldGuideCategoryScreen(Category initialCategory, int initialPage) {
7676
this(initialCategory);
7777
this.currentPage = initialPage;
7878
}
7979

80-
public FieldGuideScreen(String searchQuery, Screen parent) {
80+
public FieldGuideCategoryScreen(String searchQuery, Screen parent) {
8181
this();
8282
this.searchQuery = searchQuery;
8383
this.parent = parent;

common/src/main/java/com/evandev/fieldguide/client/gui/screens/FieldGuideEntryScreen.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
import java.util.Locale;
4040

4141
public class FieldGuideEntryScreen extends BookScreen {
42-
private final FieldGuideScreen parent;
42+
private final FieldGuideCategoryScreen parent;
4343
private final Object entry;
4444
private final List<ResourceLocation> spawnBiomes = new ArrayList<>();
4545
private Entity renderedEntity;
4646
private long lastClickTime = 0;
4747

48-
public FieldGuideEntryScreen(FieldGuideScreen parent, Object entry) {
48+
public FieldGuideEntryScreen(FieldGuideCategoryScreen parent, Object entry) {
4949
super(getTitleForEntry(entry));
5050
this.parent = parent;
5151
this.entry = entry;
@@ -58,7 +58,7 @@ private static Component getTitleForEntry(Object entry) {
5858
return Component.translatable("fieldguide.undiscovered");
5959
}
6060

61-
public FieldGuideScreen getParentScreen() {
61+
public FieldGuideCategoryScreen getParentScreen() {
6262
return parent;
6363
}
6464

@@ -184,7 +184,7 @@ private void setupBiomeWidget(boolean unlocked) {
184184
}
185185
}
186186
}, item -> {
187-
if (this.minecraft != null) this.minecraft.setScreen(new FieldGuideScreen("=!" + item, this));
187+
if (this.minecraft != null) this.minecraft.setScreen(new FieldGuideCategoryScreen("=!" + item, this));
188188
}));
189189
}
190190
}
@@ -213,7 +213,7 @@ private void setupDropWidget(boolean unlocked) {
213213
}
214214
}, stack -> {
215215
if (this.minecraft != null)
216-
this.minecraft.setScreen(new FieldGuideScreen("=^" + stack.getHoverName().getString().toLowerCase(Locale.ROOT), this));
216+
this.minecraft.setScreen(new FieldGuideCategoryScreen("=^" + stack.getHoverName().getString().toLowerCase(Locale.ROOT), this));
217217
}));
218218
}
219219
}
@@ -245,7 +245,7 @@ private void setupNavigationButtons() {
245245

246246
this.addRenderableWidget(new FieldGuideSearchBox(this.font, this.width / 2 - 70, this.bounds.bottom() + 5, 140, 20, "", q -> {
247247
if (!q.isEmpty() && this.minecraft != null) {
248-
FieldGuideScreen searchScreen = new FieldGuideScreen(q, this);
248+
FieldGuideCategoryScreen searchScreen = new FieldGuideCategoryScreen(q, this);
249249
searchScreen.setInitialSearchFocus(true);
250250
this.minecraft.setScreen(searchScreen);
251251
}
@@ -362,30 +362,30 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
362362
if (elapsed < 150) bounce = 1.0f - 0.05f * (float) Math.sin((elapsed / 150.0f) * Math.PI);
363363

364364
int xPos = leftPageBounds.x_center();
365-
int yPos = leftPageBounds.y_center() - 18;
365+
int yPos = leftPageBounds.y_center() - 14;
366366

367367
boolean hideEntity = Services.PLATFORM.isModLoaded("exposure") && ExposureCompat.hasPhotograph(entry);
368368
Object renderEntry = entry instanceof CompositeFieldGuideEntry composite ? composite.displayEntry() : entry;
369369

370370
if (entry instanceof CompositeFieldGuideEntry composite && composite.displayEntry() instanceof Block block) {
371371
if (!hideEntity) {
372372
if (composite.structureNbt() != null || (composite.stackedBlocks() != null && !composite.stackedBlocks().isEmpty())) {
373-
EntryRenderHelper.renderStructure(guiGraphics, composite, xPos, yPos, 80, showSilhouette, true, bounce);
373+
EntryRenderHelper.renderStructure(guiGraphics, composite, xPos, yPos, 112, showSilhouette, true, bounce);
374374
} else {
375-
EntryRenderHelper.renderBlock(guiGraphics, block, xPos, yPos, 30.0F, showSilhouette, true, bounce);
375+
EntryRenderHelper.renderBlock(guiGraphics, block, xPos, yPos, 40.0F, showSilhouette, true, bounce);
376376
}
377377
}
378378
} else if (renderEntry instanceof EntityType && renderedEntity instanceof LivingEntity living) {
379379
if (!hideEntity) {
380-
EntryRenderHelper.renderEntityNormalized(guiGraphics, living, xPos, yPos, 100, 100, 80, showSilhouette, ModConfig.get().getDetailsSilhouetteColorInt(), true, bounce);
380+
EntryRenderHelper.renderEntityNormalized(guiGraphics, living, xPos, yPos, 112, 112, 100, showSilhouette, ModConfig.get().getDetailsSilhouetteColorInt(), true, bounce);
381381
}
382382
if (unlocked) {
383383
renderAttributes(guiGraphics, living);
384384
renderAlignment(guiGraphics, living, mouseX, mouseY);
385385
}
386386
} else if (renderEntry instanceof Block block) {
387387
if (!hideEntity) {
388-
EntryRenderHelper.renderBlock(guiGraphics, block, xPos, yPos, 30.0F, showSilhouette, true, bounce);
388+
EntryRenderHelper.renderBlock(guiGraphics, block, xPos, yPos, 40.0F, showSilhouette, true, bounce);
389389
}
390390
}
391391
}

common/src/main/java/com/evandev/fieldguide/client/gui/screens/FieldGuideJournalScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected void init() {
100100

101101
this.searchBox = new FieldGuideSearchBox(this.font, this.width / 2 - 70, this.bounds.bottom() + 5, 140, 20, "", q -> {
102102
if (!q.isEmpty() && this.minecraft != null) {
103-
FieldGuideScreen searchScreen = new FieldGuideScreen(q, this);
103+
FieldGuideCategoryScreen searchScreen = new FieldGuideCategoryScreen(q, this);
104104
searchScreen.setInitialSearchFocus(true);
105105
this.minecraft.setScreen(searchScreen);
106106
}
@@ -164,7 +164,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
164164
public void onTabClick(Category category) {
165165
if (category.getId().getPath().equals("intro")) return;
166166
cleanupEmptyPages();
167-
Objects.requireNonNull(this.minecraft).setScreen(new FieldGuideScreen(category, 0));
167+
Objects.requireNonNull(this.minecraft).setScreen(new FieldGuideCategoryScreen(category, 0));
168168
}
169169

170170
@Override
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.evandev.fieldguide.client.gui.screens;
2+
3+
import io.github.mortuusars.exposure.gui.screen.PhotographScreen;
4+
import io.github.mortuusars.exposure.item.PhotographItem;
5+
import io.github.mortuusars.exposure.util.ItemAndStack;
6+
import net.minecraft.client.Minecraft;
7+
import net.minecraft.client.gui.screens.Screen;
8+
9+
import java.util.List;
10+
11+
public class FieldGuidePhotographScreen extends PhotographScreen {
12+
private final Screen parentScreen;
13+
14+
public FieldGuidePhotographScreen(Screen parentScreen, List<ItemAndStack<PhotographItem>> photographs) {
15+
super(photographs);
16+
this.parentScreen = parentScreen;
17+
}
18+
19+
@Override
20+
public void onClose() {
21+
Minecraft.getInstance().setScreen(this.parentScreen);
22+
}
23+
}

common/src/main/java/com/evandev/fieldguide/client/gui/util/EntryRenderHelper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,19 @@ public static void renderEntityNormalized(GuiGraphics guiGraphics, LivingEntity
113113
float dynamicFactor = getScaleFactorForEntity(entity);
114114
float clampedScale = 85.0F * dynamicFactor * visualScale;
115115
float entityHeight = entity.getBbHeight();
116+
float entityWidth = entity.getBbWidth();
117+
float maxDimension = Math.max(entityHeight, entityWidth);
116118

117-
if (entityHeight * clampedScale > 230.0F) {
118-
clampedScale = 230.0F / entityHeight;
119+
float safetyClamp = isPage ? 250.0F : 230.0F;
120+
121+
if (maxDimension * clampedScale > safetyClamp) {
122+
clampedScale = safetyClamp / maxDimension;
119123
}
120124

121125
PoseStack pose = new PoseStack();
122126
pose.scale(clampedScale, -clampedScale, -clampedScale);
123-
124127
pose.mulPose(Axis.XP.rotationDegrees(30.0F));
125128
pose.mulPose(Axis.YP.rotationDegrees(-30.0F));
126-
127129
pose.translate(0, (entityHeight / -2.0F) + (yOff / clampedScale), 0);
128130

129131
entity.setYRot(0.0F);
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.evandev.fieldguide.client.gui.widget;
2+
3+
import com.mojang.blaze3d.platform.InputConstants;
4+
import com.mojang.blaze3d.vertex.Tesselator;
5+
import io.github.mortuusars.exposure.ExposureClient;
6+
import io.github.mortuusars.exposure.item.PhotographItem;
7+
import io.github.mortuusars.exposure.render.PhotographRenderer;
8+
import net.minecraft.client.Minecraft;
9+
import net.minecraft.client.gui.GuiGraphics;
10+
import net.minecraft.client.gui.components.AbstractButton;
11+
import net.minecraft.client.gui.components.Tooltip;
12+
import net.minecraft.client.gui.narration.NarrationElementOutput;
13+
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
14+
import net.minecraft.client.renderer.LightTexture;
15+
import net.minecraft.client.renderer.MultiBufferSource;
16+
import net.minecraft.client.renderer.Rect2i;
17+
import net.minecraft.network.chat.Component;
18+
import net.minecraft.resources.ResourceLocation;
19+
import net.minecraft.world.item.ItemStack;
20+
import org.jetbrains.annotations.NotNull;
21+
import org.joml.Vector2i;
22+
23+
import java.util.function.Supplier;
24+
25+
public class FieldGuidePhotographWidget extends AbstractButton {
26+
private final Rect2i exposureArea;
27+
private final Supplier<ItemStack> photographGetter;
28+
private final Runnable onLeftClick;
29+
private final Runnable onRightClick;
30+
private final ResourceLocation backgroundTexture;
31+
32+
public FieldGuidePhotographWidget(int x, int y, int width, int height, Rect2i exposureArea,
33+
ResourceLocation backgroundTexture,
34+
Supplier<ItemStack> photographGetter,
35+
Runnable onLeftClick, Runnable onRightClick,
36+
Component tooltipText) {
37+
super(x, y, width, height, Component.empty());
38+
this.exposureArea = exposureArea;
39+
this.backgroundTexture = backgroundTexture;
40+
this.photographGetter = photographGetter;
41+
this.onLeftClick = onLeftClick;
42+
this.onRightClick = onRightClick;
43+
44+
this.setTooltip(Tooltip.create(tooltipText));
45+
}
46+
47+
@Override
48+
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
49+
guiGraphics.blit(backgroundTexture, this.getX(), this.getY(), 0, 0, this.width, this.height, this.width, this.height);
50+
51+
ItemStack photograph = photographGetter.get();
52+
if (photograph.getItem() instanceof PhotographItem) {
53+
guiGraphics.pose().pushPose();
54+
float scale = exposureArea.getWidth() / (float) ExposureClient.getExposureRenderer().getSize();
55+
guiGraphics.pose().translate(exposureArea.getX(), exposureArea.getY(), 1);
56+
guiGraphics.pose().scale(scale, scale, scale);
57+
58+
MultiBufferSource.BufferSource bufferSource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
59+
PhotographRenderer.render(photograph, false, false, guiGraphics.pose(),
60+
bufferSource, LightTexture.FULL_BRIGHT, 255, 255, 255, 255);
61+
bufferSource.endBatch();
62+
guiGraphics.pose().popPose();
63+
}
64+
}
65+
66+
@Override
67+
protected @NotNull ClientTooltipPositioner createTooltipPositioner() {
68+
return (screenWidth, screenHeight, mouseX, mouseY, tooltipWidth, tooltipHeight) -> {
69+
int x = mouseX + 12;
70+
int y = mouseY - 12;
71+
72+
if (x + tooltipWidth > screenWidth) {
73+
x -= 28 + tooltipWidth;
74+
}
75+
if (y + tooltipHeight + 6 > screenHeight) {
76+
y = screenHeight - tooltipHeight - 6;
77+
}
78+
return new Vector2i(x, y);
79+
};
80+
}
81+
82+
@Override
83+
public void onPress() {
84+
onLeftClick.run();
85+
}
86+
87+
@Override
88+
protected boolean clicked(double mouseX, double mouseY) {
89+
return this.active && this.visible
90+
&& mouseX >= this.getX() && mouseY >= this.getY()
91+
&& mouseX < this.getX() + this.width && mouseY < this.getY() + this.height;
92+
}
93+
94+
@Override
95+
public boolean mouseClicked(double mouseX, double mouseY, int button) {
96+
if (this.clicked(mouseX, mouseY)) {
97+
if (button == InputConstants.MOUSE_BUTTON_LEFT) {
98+
this.playDownSound(Minecraft.getInstance().getSoundManager());
99+
this.onPress();
100+
return true;
101+
} else if (button == InputConstants.MOUSE_BUTTON_RIGHT) {
102+
this.playDownSound(Minecraft.getInstance().getSoundManager());
103+
this.onRightClick.run();
104+
return true;
105+
}
106+
}
107+
return false;
108+
}
109+
110+
@Override
111+
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
112+
if (delta > 0 && this.isHovered() && !photographGetter.get().isEmpty()) {
113+
this.onPress();
114+
return true;
115+
}
116+
return super.mouseScrolled(mouseX, mouseY, delta);
117+
}
118+
119+
@Override
120+
protected void updateWidgetNarration(@NotNull NarrationElementOutput output) {
121+
this.defaultButtonNarrationText(output);
122+
}
123+
}

0 commit comments

Comments
 (0)