11package com .greatorator .tolkienmobs .containers .screens ;
22
33import com .greatorator .tolkienmobs .TolkienMobsConfig ;
4- import com .greatorator .tolkienmobs .TolkienMobsMain ;
54import com .greatorator .tolkienmobs .block .custom .entity .MilestoneBlockEntity ;
65import com .greatorator .tolkienmobs .containers .MilestoneContainer ;
76import com .greatorator .tolkienmobs .containers .handlers .ToggleButtonFactory ;
3029import org .lwjgl .glfw .GLFW ;
3130
3231import java .util .ArrayList ;
32+ import java .util .Collections ;
3333import java .util .List ;
3434import java .util .Objects ;
3535
@@ -44,8 +44,11 @@ public class MilestoneScreen extends AbstractContainerScreen<MilestoneContainer>
4444 private EditBox milestoneName ;
4545 protected List <AbstractWidget > widgetsToRemove = new ArrayList <>();
4646 protected List <AbstractWidget > widgetsToAdd = new ArrayList <>();
47- private final List <AbstractWidget > locationButtons = new ArrayList <>();
47+ private final List <String > locationList = new ArrayList <>();
48+ private static final List <AbstractWidget > locationButtons = new ArrayList <>();
4849 protected boolean renderablesChanged = false ;
50+ public static int maxItemsPerPage = 7 ;
51+ public static int currentPage = 1 ;
4952
5053 public MilestoneScreen (MilestoneContainer container , Inventory inv , Component title ) {
5154 super (container , inv , title );
@@ -79,6 +82,37 @@ public void init() {
7982 addPaymentMethod ();
8083 }
8184 addLocations ();
85+
86+ int relX = (this .width - this .imageWidth ) / 2 ;
87+ int relY = (this .height - this .imageHeight ) / 2 ;
88+
89+ Button prevButton = Button .builder (Component .literal ("<" ), button -> {
90+ // Decrement page and rebuild the screen
91+ if (currentPage > 0 ) {
92+ currentPage --;
93+ this .clearWidgets (); // Clear old widgets
94+ this .init (); // Reinitialize with new page
95+ }
96+ })
97+ .pos (relX + 7 , relY + 173 )
98+ .size (8 , 16 )
99+ .build ();
100+ prevButton .active = currentPage > 0 ;
101+ this .addRenderableWidget (prevButton );
102+
103+ Button nextButton = Button .builder (Component .literal (">" ), button -> {
104+ // Increment page and rebuild the screen
105+ if (currentPage <= getPageCount () - 1 ) {
106+ currentPage ++;
107+ this .clearWidgets ();
108+ this .init ();
109+ }
110+ })
111+ .pos (relX + 161 , relY + 173 )
112+ .size (8 , 16 )
113+ .build ();
114+ nextButton .active = currentPage < getPageCount ();
115+ this .addRenderableWidget (nextButton );
82116 tileEntity .updateClientState ();
83117 }
84118
@@ -124,43 +158,31 @@ public void addNameField() {
124158 }
125159
126160 public void addLocations () {
127- int i = -1 ;
161+ List <String > locationOnPage = getItemsForPage ();
162+ int yOffset = 0 ;
128163
129- for (MilestoneHandler .MilestoneData data : MilestoneHandler .getKnownByPlayer (Objects .requireNonNull (getMinecraft ().player ))) {
130- if (data .getUuid ().equals (tileEntity .getUUID ())) continue ;
131- i ++;
164+ for (String locations : locationOnPage ){
132165 int relX = (this .width - this .imageWidth ) / 2 ;
133166 int relY = (this .height - this .imageHeight ) / 2 ;
167+ int y = 66 + (yOffset * 15 );
134168
135- int y = 66 + (i * 16 );
136- this .locationButtons .add (
137- this .addRenderableWidget (Button .builder (Component .literal (data .getName ()),
138- button -> {
139- TolkienMobsMain .LOGGER .warn ("You teleported!" );
140- TolkienMobsMain .LOGGER .warn (String .valueOf (getMinecraft ().player ));
141- TolkienMobsMain .LOGGER .warn (String .valueOf (data .getUuid ()));
142- TolkienMobsMain .LOGGER .warn (String .valueOf (data .getPos ()));
143- TolkienMobsMain .LOGGER .warn (String .valueOf (data .getWorldKey ()));
144- TolkienMobsMain .LOGGER .warn (data .getName ());
145- this .tileEntity .sendPacketToServer (output -> output .writeUUID (data .getUuid ()), 3 );
146- // PacketDistributor.sendToServer(new MilestoneTeleportUpdateManager(true));
147- })
148- .pos (relX + 5 , relY + y )
149- .size (150 , 16 )
150- .build ()
151- )
152- );
169+ Button itemButton = Button .builder (Component .literal (locations ), button -> {
170+ // this.tileEntity.sendPacketToServer(output -> output.writeUUID(data.getUuid()), 3);
171+ })
172+ .pos (relX + 5 , relY + y )
173+ .size (150 , 15 )
174+ .build ();
175+ this .addRenderableWidget (itemButton );
153176 if (TolkienMobsConfig .PAYMENT_TYPE .get ()) {
154- addRenderableWidget (ToggleButtonFactory .ITEM_PAYMENT_METHOD_CLIENT (relX + 155 , relY + y , this . tileEntity . getItemTravelCost ( data ) ,
177+ addRenderableWidget (ToggleButtonFactory .ITEM_PAYMENT_METHOD_CLIENT (relX + 155 , relY + y , 1 ,
155178 (button ) -> {
156-
157179 }));
158180 } else {
159- addRenderableWidget (ToggleButtonFactory .EXPERIENCE_PAYMENT_METHOD_CLIENT (relX + 155 , relY + y , this . tileEntity . getExperienceTravelCost ( data ) ,
181+ addRenderableWidget (ToggleButtonFactory .EXPERIENCE_PAYMENT_METHOD_CLIENT (relX + 155 , relY + y , 1 ,
160182 (button ) -> {
161-
162183 }));
163184 }
185+ yOffset +=1 ; // Adjust for next button
164186 }
165187 }
166188
@@ -191,6 +213,33 @@ public int adjustNumberButton(int value, int change, int min, int max) {
191213 return value ;
192214 }
193215
216+ public int getPageCount (){
217+ int i = -1 ;
218+ for (MilestoneHandler .MilestoneData data : MilestoneHandler .getKnownByPlayer (Objects .requireNonNull (getMinecraft ().player ))) {
219+ if (data .getUuid ().equals (tileEntity .getUUID ())) continue ;
220+ i ++;
221+ }
222+ return Math .max ((int ) Math .ceil ((double ) i / maxItemsPerPage ) - 1 , 0 );
223+ }
224+
225+ private List <String > getItemsForPage () {
226+ int start = currentPage * maxItemsPerPage ;
227+ int i = 0 ;
228+
229+ for (MilestoneHandler .MilestoneData data : MilestoneHandler .getKnownByPlayer (Objects .requireNonNull (getMinecraft ().player ))) {
230+ if (data .getUuid ().equals (tileEntity .getUUID ())) continue ;
231+ i ++;
232+ locationList .add (String .valueOf (data .getName ()));
233+ }
234+
235+ int end = Math .min (start + maxItemsPerPage , i );
236+
237+ if (start >= end ) {
238+ return Collections .emptyList ();
239+ }
240+ return locationList .subList (start , end );
241+ }
242+
194243 @ Override
195244 protected void renderTooltip (GuiGraphics pGuiGraphics , int pX , int pY ) {
196245 super .renderTooltip (pGuiGraphics , pX , pY );
@@ -203,9 +252,6 @@ protected void renderTooltip(GuiGraphics pGuiGraphics, int pX, int pY) {
203252 if (getMinecraft ().player .isCreative ()) {
204253 this .milestoneName .setTooltip (Tooltip .create (tooltip ));
205254 }
206- // if (){
207- // Component.literal("hello");
208- // }
209255 }
210256
211257 @ Override
@@ -214,6 +260,12 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
214260 if (getMinecraft ().player .isCreative ()) {
215261 this .milestoneName .render (guiGraphics , mouseX , mouseY , partialTicks );
216262 }
263+ int relX = (this .width - this .imageWidth ) / 2 ;
264+ int relY = (this .height - this .imageHeight ) / 2 ;
265+
266+ String pagesLabel = GeneralUtility .withSuffix (currentPage ) + " / " + GeneralUtility .withSuffix (getPageCount ());
267+ guiGraphics .drawString (font , pagesLabel , (relX + 100 - font .width (pagesLabel )), relY + 179 , ColorUtility .DARKGRAY .getColor (), false );
268+
217269 this .renderTooltip (guiGraphics , mouseX , mouseY );
218270 }
219271
0 commit comments