1+ package com .evandev .fieldguide .compat .exposure ;
2+
3+ import com .evandev .fieldguide .client .ClientFieldGuideManager ;
4+ import com .evandev .fieldguide .client .gui .screens .FieldGuideEntryScreen ;
5+ import com .evandev .fieldguide .client .progress .ProgressManager ;
6+ import io .github .mortuusars .exposure .gui .screen .ItemListScreen ;
7+ import io .github .mortuusars .exposure .gui .screen .PhotographScreen ;
8+ import io .github .mortuusars .exposure .gui .screen .album .PhotographSlotButton ;
9+ import io .github .mortuusars .exposure .item .PhotographItem ;
10+ import io .github .mortuusars .exposure .util .ItemAndStack ;
11+ import net .minecraft .ChatFormatting ;
12+ import net .minecraft .client .Minecraft ;
13+ import net .minecraft .client .gui .components .ImageButton ;
14+ import net .minecraft .client .gui .components .Tooltip ;
15+ import net .minecraft .client .gui .screens .Screen ;
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 .entity .player .Player ;
20+ import net .minecraft .world .item .ItemStack ;
21+
22+ import java .util .ArrayList ;
23+ import java .util .List ;
24+ import java .util .function .Consumer ;
25+
26+ public class ExposureCompat {
27+ private static final ResourceLocation ADD_PHOTO_ICON = new ResourceLocation ("fieldguide" , "textures/gui/add_photo.png" );
28+
29+ public static void setupExposureWidgets (FieldGuideEntryScreen screen , Object entry ) {
30+ if (!ClientFieldGuideManager .isUnlocked (entry )) return ;
31+
32+ int leftX = screen .getLeftPageBounds ().left ();
33+ int leftY = screen .getLeftPageBounds ().top ();
34+ int leftWidth = screen .getLeftPageBounds ().width ();
35+ int leftHeight = screen .getLeftPageBounds ().height ();
36+
37+ int iconSize = 16 ;
38+ int iconX = leftX + leftWidth - iconSize - 8 ;
39+ int iconY = leftY + 10 ;
40+
41+ ItemStack existingPhoto = ProgressManager .getInstance ().getPhotograph (entry );
42+
43+ if (existingPhoto .isEmpty ()) {
44+ ImageButton addPhotoButton = new ImageButton (iconX , iconY , iconSize , iconSize , 0 , 0 , iconSize , ADD_PHOTO_ICON , 16 , 32 , btn -> {
45+ openPhotographSelector (screen , entry );
46+ }, Component .translatable ("gui.fieldguide.add_photograph" ));
47+
48+ addPhotoButton .setTooltip (Tooltip .create (Component .translatable ("gui.fieldguide.add_photograph" )));
49+ screen .addWidgetPublic (addPhotoButton );
50+ } else {
51+ int photoWidth = 84 ;
52+ int photoHeight = 84 ;
53+ int photoX = leftX + (leftWidth / 2 ) - (photoWidth / 2 );
54+ int photoY = leftY + (leftHeight / 2 ) - (photoHeight / 2 ) - 18 ;
55+
56+ Rect2i exposureArea = new Rect2i (photoX + 8 , photoY + 8 , photoWidth - 16 , photoHeight - 16 );
57+
58+ PhotographSlotButton photoButton = new PhotographSlotButton (
59+ exposureArea , photoX , photoY , photoWidth , photoHeight ,
60+ 0 , 0 , 0 , new ResourceLocation ("exposure" , "textures/gui/album.png" ), 256 , 256 ,
61+ btn -> {
62+ Minecraft .getInstance ().setScreen (new PhotographScreen (List .of (new ItemAndStack <>(existingPhoto ))));
63+ },
64+ btn -> {
65+ ProgressManager .getInstance ().setPhotograph (entry , ItemStack .EMPTY );
66+ Minecraft .getInstance ().setScreen (new FieldGuideEntryScreen (screen .getParentScreen (), entry ));
67+ },
68+ () -> ProgressManager .getInstance ().getPhotograph (entry ),
69+ true
70+ );
71+
72+ Component tooltipText = Component .empty ()
73+ .append (Component .literal ("[" ).withStyle (ChatFormatting .DARK_GRAY ))
74+ .append (Component .literal ("Left Click" ).withStyle (ChatFormatting .GRAY ))
75+ .append (Component .literal ("] or [" ).withStyle (ChatFormatting .DARK_GRAY ))
76+ .append (Component .literal ("Scroll Up" ).withStyle (ChatFormatting .GRAY ))
77+ .append (Component .literal ("] to View\n " ).withStyle (ChatFormatting .DARK_GRAY ))
78+ .append (Component .literal ("[" ).withStyle (ChatFormatting .DARK_GRAY ))
79+ .append (Component .literal ("Right Click" ).withStyle (ChatFormatting .GRAY ))
80+ .append (Component .literal ("] to Remove" ).withStyle (ChatFormatting .DARK_GRAY ));
81+
82+ photoButton .setTooltip (Tooltip .create (tooltipText ));
83+ screen .addWidgetPublic (photoButton );
84+ }
85+ }
86+
87+ private static void openPhotographSelector (FieldGuideEntryScreen parent , Object entry ) {
88+ Player player = Minecraft .getInstance ().player ;
89+ if (player == null ) return ;
90+
91+ List <ItemStack > photographs = new ArrayList <>();
92+ for (int i = 0 ; i < player .getInventory ().getContainerSize (); i ++) {
93+ ItemStack stack = player .getInventory ().getItem (i );
94+ if (stack .getItem () instanceof PhotographItem ) {
95+ photographs .add (stack );
96+ }
97+ }
98+
99+ Minecraft .getInstance ().setScreen (new PhotographSelectionScreen (parent , photographs , stack -> {
100+ ProgressManager .getInstance ().setPhotograph (entry , stack .copy ());
101+ Minecraft .getInstance ().setScreen (new FieldGuideEntryScreen (parent .getParentScreen (), entry ));
102+ }));
103+ }
104+
105+ public static boolean hasPhotograph (Object entry ) {
106+ return !ProgressManager .getInstance ().getPhotograph (entry ).isEmpty ();
107+ }
108+
109+ private static class PhotographSelectionScreen extends ItemListScreen {
110+ private final Consumer <ItemStack > onSelect ;
111+
112+ public PhotographSelectionScreen (Screen parent , List <ItemStack > items , Consumer <ItemStack > onSelect ) {
113+ super (parent , Component .translatable ("gui.fieldguide.select_photograph" ), items );
114+ this .onSelect = onSelect ;
115+ }
116+
117+ @ Override
118+ public boolean mouseClicked (double mouseX , double mouseY , int button ) {
119+ if (button == 0 && hoveredSlot != null && hoveredSlot .hasItem ()) {
120+ onSelect .accept (hoveredSlot .getItem ());
121+ return true ;
122+ }
123+ return super .mouseClicked (mouseX , mouseY , button );
124+ }
125+ }
126+ }
0 commit comments