Skip to content

Commit 58e0307

Browse files
committed
tweaked exposure gui and added photographs to list pages
1 parent 83cc699 commit 58e0307

7 files changed

Lines changed: 86 additions & 13 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.evandev.fieldguide.client.gui.util.EntryRenderHelper;
99
import com.evandev.fieldguide.client.gui.widget.FieldGuideSearchBox;
1010
import com.evandev.fieldguide.client.gui.widget.PageTurnButton;
11+
import com.evandev.fieldguide.client.progress.ProgressManager;
1112
import com.evandev.fieldguide.config.ModConfig;
1213
import com.evandev.fieldguide.data.Category;
1314
import com.evandev.fieldguide.data.CompositeFieldGuideEntry;
@@ -749,6 +750,15 @@ private void renderPageNumber(int page, Bounds bounds, GuiGraphics guiGraphics)
749750
private void renderEntryInGrid(GuiGraphics guiGraphics, Object entry, int x, int y, int scale, boolean unlocked) {
750751
Object coreEntry = entry instanceof CompositeFieldGuideEntry composite ? composite.displayEntry() : entry;
751752

753+
if (unlocked && Services.PLATFORM.isModLoaded("exposure")) {
754+
ItemStack existingPhoto = ProgressManager.getInstance().getPhotograph(entry);
755+
756+
if (!existingPhoto.isEmpty()) {
757+
com.evandev.fieldguide.compat.exposure.ExposureCompat.renderPhotographInGrid(guiGraphics, x - (CELL_SIZE/2), y - (CELL_SIZE/2), CELL_SIZE, CELL_SIZE, existingPhoto);
758+
return;
759+
}
760+
}
761+
752762
if (entry instanceof CompositeFieldGuideEntry composite && composite.displayEntry() instanceof Block block) {
753763
if (composite.structureNbt() != null || (composite.stackedBlocks() != null && !composite.stackedBlocks().isEmpty())) {
754764
EntryRenderHelper.renderStructure(guiGraphics, composite, x, y, CELL_SIZE - 4, !unlocked, false, 1.0F);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ private void renderAttributes(GuiGraphics guiGraphics, LivingEntity entity) {
438438

439439
int xPos = this.leftPageBounds.x_center() - (totalWidth / 2);
440440

441+
guiGraphics.pose().pushPose();
442+
guiGraphics.pose().translate(0, 0, 2);
443+
444+
guiGraphics.blitNineSliced(Constants.WIDGETS_TEXTURE, xPos - 4, yPos - 3, totalWidth + 8, 16, 6, 16, 16, 48, 0);
445+
441446
guiGraphics.blit(Constants.ATTRIBUTES_TEXTURE, xPos, yPos, 0, 0, iconSize, iconSize, 32, 32);
442447
guiGraphics.drawString(this.font, health, xPos + iconSize + iconSpacing, yPos + 1, ModConfig.get().getTextColorInt(), false);
443448

@@ -446,5 +451,6 @@ private void renderAttributes(GuiGraphics guiGraphics, LivingEntity entity) {
446451
guiGraphics.blit(Constants.ATTRIBUTES_TEXTURE, xPos, yPos, 0, iconSize, iconSize, iconSize, 32, 32);
447452
guiGraphics.drawString(this.font, armor, xPos + iconSize + iconSpacing, yPos + 1, ModConfig.get().getTextColorInt(), false);
448453
}
454+
guiGraphics.pose().popPose();
449455
}
450456
}

common/src/main/java/com/evandev/fieldguide/client/gui/widget/FieldGuidePhotographWidget.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.mojang.blaze3d.vertex.Tesselator;
55
import io.github.mortuusars.exposure.ExposureClient;
66
import io.github.mortuusars.exposure.item.PhotographItem;
7+
import io.github.mortuusars.exposure.render.PhotographRenderProperties;
78
import io.github.mortuusars.exposure.render.PhotographRenderer;
89
import net.minecraft.client.Minecraft;
910
import net.minecraft.client.gui.GuiGraphics;
@@ -15,7 +16,6 @@
1516
import net.minecraft.client.renderer.MultiBufferSource;
1617
import net.minecraft.client.renderer.Rect2i;
1718
import net.minecraft.network.chat.Component;
18-
import net.minecraft.resources.ResourceLocation;
1919
import net.minecraft.world.item.ItemStack;
2020
import org.jetbrains.annotations.NotNull;
2121
import org.joml.Vector2i;
@@ -27,16 +27,13 @@ public class FieldGuidePhotographWidget extends AbstractButton {
2727
private final Supplier<ItemStack> photographGetter;
2828
private final Runnable onLeftClick;
2929
private final Runnable onRightClick;
30-
private final ResourceLocation backgroundTexture;
3130

3231
public FieldGuidePhotographWidget(int x, int y, int width, int height, Rect2i exposureArea,
33-
ResourceLocation backgroundTexture,
3432
Supplier<ItemStack> photographGetter,
3533
Runnable onLeftClick, Runnable onRightClick,
3634
Component tooltipText) {
3735
super(x, y, width, height, Component.empty());
3836
this.exposureArea = exposureArea;
39-
this.backgroundTexture = backgroundTexture;
4037
this.photographGetter = photographGetter;
4138
this.onLeftClick = onLeftClick;
4239
this.onRightClick = onRightClick;
@@ -46,10 +43,16 @@ public FieldGuidePhotographWidget(int x, int y, int width, int height, Rect2i ex
4643

4744
@Override
4845
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);
5046

5147
ItemStack photograph = photographGetter.get();
5248
if (photograph.getItem() instanceof PhotographItem) {
49+
PhotographRenderProperties renderProperties = PhotographRenderProperties.get(photograph);
50+
51+
// Paper
52+
renderTexture(guiGraphics, renderProperties.getAlbumPaperTexture(),
53+
getX(), getY(), 0, 0, 0, width, height, width, height);
54+
55+
// Exposure
5356
guiGraphics.pose().pushPose();
5457
float scale = exposureArea.getWidth() / (float) ExposureClient.getExposureRenderer().getSize();
5558
guiGraphics.pose().translate(exposureArea.getX(), exposureArea.getY(), 1);
@@ -60,6 +63,15 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
6063
bufferSource, LightTexture.FULL_BRIGHT, 255, 255, 255, 255);
6164
bufferSource.endBatch();
6265
guiGraphics.pose().popPose();
66+
67+
// Paper overlay
68+
if (renderProperties.hasAlbumPaperOverlayTexture()) {
69+
guiGraphics.pose().pushPose();
70+
guiGraphics.pose().translate(0, 0, 2);
71+
renderTexture(guiGraphics, renderProperties.getAlbumPaperOverlayTexture(),
72+
getX(), getY(), 0, 0, 0, width, height, width, height);
73+
guiGraphics.pose().popPose();
74+
}
6375
}
6476
}
6577

common/src/main/java/com/evandev/fieldguide/compat/exposure/ExposureCompat.java

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
import com.evandev.fieldguide.client.gui.screens.FieldGuidePhotographScreen;
66
import com.evandev.fieldguide.client.gui.widget.FieldGuidePhotographWidget;
77
import com.evandev.fieldguide.client.progress.ProgressManager;
8+
import com.mojang.blaze3d.vertex.Tesselator;
9+
import io.github.mortuusars.exposure.ExposureClient;
810
import io.github.mortuusars.exposure.gui.screen.ItemListScreen;
911
import io.github.mortuusars.exposure.item.PhotographItem;
12+
import io.github.mortuusars.exposure.render.PhotographRenderProperties;
13+
import io.github.mortuusars.exposure.render.PhotographRenderer;
1014
import io.github.mortuusars.exposure.util.ItemAndStack;
1115
import net.minecraft.ChatFormatting;
1216
import net.minecraft.client.Minecraft;
17+
import net.minecraft.client.gui.GuiGraphics;
1318
import net.minecraft.client.gui.components.ImageButton;
1419
import net.minecraft.client.gui.components.Tooltip;
1520
import net.minecraft.client.gui.screens.Screen;
21+
import net.minecraft.client.renderer.LightTexture;
22+
import net.minecraft.client.renderer.MultiBufferSource;
1623
import net.minecraft.client.renderer.Rect2i;
1724
import net.minecraft.network.chat.Component;
1825
import net.minecraft.resources.ResourceLocation;
@@ -25,7 +32,6 @@
2532

2633
public class ExposureCompat {
2734
private static final ResourceLocation ADD_PHOTO_ICON = new ResourceLocation("fieldguide", "textures/gui/exposure/add_photo.png");
28-
private static final ResourceLocation PHOTOGRAPH_BACKGROUND = new ResourceLocation("fieldguide", "textures/gui/exposure/photograph.png");
2935

3036
public static void setupExposureWidgets(FieldGuideEntryScreen screen, Object entry) {
3137
if (!ClientFieldGuideManager.isUnlocked(entry)) return;
@@ -36,8 +42,8 @@ public static void setupExposureWidgets(FieldGuideEntryScreen screen, Object ent
3642
int leftHeight = screen.getLeftPageBounds().height();
3743

3844
int iconSize = 16;
39-
int iconX = leftX + leftWidth - iconSize - 8;
40-
int iconY = leftY + 10;
45+
int iconX = leftX + leftWidth - iconSize - 12;
46+
int iconY = leftY + 12;
4147

4248
ItemStack existingPhoto = ProgressManager.getInstance().getPhotograph(entry);
4349

@@ -49,12 +55,12 @@ public static void setupExposureWidgets(FieldGuideEntryScreen screen, Object ent
4955
addPhotoButton.setTooltip(Tooltip.create(Component.translatable("gui.fieldguide.add_photograph")));
5056
screen.addWidgetPublic(addPhotoButton);
5157
} else {
52-
int photoWidth = 112;
53-
int photoHeight = 112;
58+
int photoWidth = 108;
59+
int photoHeight = 108;
5460
int photoX = leftX + (leftWidth / 2) - (photoWidth / 2);
55-
int photoY = leftY + (leftHeight / 2) - (photoHeight / 2) - 14;
61+
int photoY = leftY + (leftHeight / 2) - (photoHeight / 2) - 15;
5662

57-
Rect2i exposureArea = new Rect2i(photoX + 8, photoY + 8, photoWidth - 16, photoHeight - 16);
63+
Rect2i exposureArea = new Rect2i(photoX + 6, photoY + 6, photoWidth - 12, photoHeight - 12);
5864

5965
Component tooltipText = Component.empty()
6066
.append(Component.literal("[").withStyle(ChatFormatting.DARK_GRAY))
@@ -66,10 +72,11 @@ public static void setupExposureWidgets(FieldGuideEntryScreen screen, Object ent
6672
.append(Component.literal("Right Click").withStyle(ChatFormatting.GRAY))
6773
.append(Component.literal("] to Remove").withStyle(ChatFormatting.DARK_GRAY));
6874

75+
76+
6977
FieldGuidePhotographWidget photoWidget = new FieldGuidePhotographWidget(
7078
photoX, photoY, photoWidth, photoHeight,
7179
exposureArea,
72-
PHOTOGRAPH_BACKGROUND,
7380
() -> ProgressManager.getInstance().getPhotograph(entry),
7481

7582
() -> Minecraft.getInstance().setScreen(new FieldGuidePhotographScreen(screen, List.of(new ItemAndStack<>(existingPhoto)))),
@@ -85,6 +92,44 @@ public static void setupExposureWidgets(FieldGuideEntryScreen screen, Object ent
8592
}
8693
}
8794

95+
public static void renderPhotographInGrid(GuiGraphics guiGraphics, int x, int y, int width, int height, ItemStack photograph) {
96+
if (photograph.getItem() instanceof PhotographItem) {
97+
PhotographRenderProperties renderProperties = PhotographRenderProperties.get(photograph);
98+
Rect2i exposureArea = new Rect2i(x + 4, y + 4, width - 8, height - 8);
99+
int textureSize = 64;
100+
int sliceSize = width / 2;
101+
102+
// Paper
103+
guiGraphics.blit(renderProperties.getPaperTexture(), x, y, 0, 0, 0, sliceSize, sliceSize, textureSize, textureSize);
104+
guiGraphics.blit(renderProperties.getPaperTexture(), x + sliceSize, y, 0, textureSize - sliceSize, 0, sliceSize, sliceSize, textureSize, textureSize);
105+
guiGraphics.blit(renderProperties.getPaperTexture(), x, y + sliceSize, 0, 0, textureSize - sliceSize, sliceSize, sliceSize, textureSize, textureSize);
106+
guiGraphics.blit(renderProperties.getPaperTexture(), x + sliceSize, y + sliceSize, 0, textureSize - sliceSize, textureSize - sliceSize, sliceSize, sliceSize, textureSize, textureSize);
107+
108+
// Exposure
109+
guiGraphics.pose().pushPose();
110+
float scale = exposureArea.getWidth() / (float) ExposureClient.getExposureRenderer().getSize();
111+
guiGraphics.pose().translate(exposureArea.getX(), exposureArea.getY(), 1);
112+
guiGraphics.pose().scale(scale, scale, scale);
113+
114+
MultiBufferSource.BufferSource bufferSource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
115+
PhotographRenderer.render(photograph, false, false, guiGraphics.pose(),
116+
bufferSource, LightTexture.FULL_BRIGHT, 255, 255, 255, 255);
117+
bufferSource.endBatch();
118+
guiGraphics.pose().popPose();
119+
120+
// Paper overlay
121+
if (renderProperties.hasPaperOverlayTexture()) {
122+
guiGraphics.pose().pushPose();
123+
guiGraphics.pose().translate(0, 0, 2);
124+
guiGraphics.blit(renderProperties.getPaperOverlayTexture(), x, y, 0, 0, 0, sliceSize, sliceSize, textureSize, textureSize);
125+
guiGraphics.blit(renderProperties.getPaperOverlayTexture(), x + sliceSize, y, 0, textureSize - sliceSize, 0, sliceSize, sliceSize, textureSize, textureSize);
126+
guiGraphics.blit(renderProperties.getPaperOverlayTexture(), x, y + sliceSize, 0, 0, textureSize - sliceSize, sliceSize, sliceSize, textureSize, textureSize);
127+
guiGraphics.blit(renderProperties.getPaperOverlayTexture(), x + sliceSize, y + sliceSize, 0, textureSize - sliceSize, textureSize - sliceSize, sliceSize, sliceSize, textureSize, textureSize);
128+
guiGraphics.pose().popPose();
129+
}
130+
}
131+
}
132+
88133
private static void openPhotographSelector(FieldGuideEntryScreen parent, Object entry) {
89134
Player player = Minecraft.getInstance().player;
90135
if (player == null) return;
-218 Bytes
Loading
Binary file not shown.
37 Bytes
Loading

0 commit comments

Comments
 (0)