11package com .greatorator .tolkienmobs .containers .screens ;
22
33import com .greatorator .tolkienmobs .TolkienMobsConfig ;
4+ import com .greatorator .tolkienmobs .TolkienMobsMain ;
45import com .greatorator .tolkienmobs .block .custom .entity .MilestoneBlockEntity ;
56import com .greatorator .tolkienmobs .containers .MilestoneContainer ;
67import com .greatorator .tolkienmobs .containers .handlers .ToggleButtonFactory ;
@@ -44,11 +45,10 @@ public class MilestoneScreen extends AbstractContainerScreen<MilestoneContainer>
4445 private EditBox milestoneName ;
4546 protected List <AbstractWidget > widgetsToRemove = new ArrayList <>();
4647 protected List <AbstractWidget > widgetsToAdd = new ArrayList <>();
47- private final List <String > locationList = new ArrayList <>();
48- private static final List <AbstractWidget > locationButtons = new ArrayList <>();
48+ private final List <AbstractWidget > locationList = new ArrayList <>();
4949 protected boolean renderablesChanged = false ;
50- public static int maxItemsPerPage = 7 ;
51- public static int currentPage = 1 ;
50+ public static final int maxItemsPerPage = 7 ;
51+ public static int currentPage = 0 ;
5252
5353 public MilestoneScreen (MilestoneContainer container , Inventory inv , Component title ) {
5454 super (container , inv , title );
@@ -81,6 +81,7 @@ public void init() {
8181 addMilestoneMultiplierButton ();
8282 addPaymentMethod ();
8383 }
84+
8485 addLocations ();
8586
8687 int relX = (this .width - this .imageWidth ) / 2 ;
@@ -158,32 +159,15 @@ public void addNameField() {
158159 }
159160
160161 public void addLocations () {
161- List <String > locationOnPage = getItemsForPage ();
162- int yOffset = 0 ;
163-
164- for (String locations : locationOnPage ){
165- int relX = (this .width - this .imageWidth ) / 2 ;
166- int relY = (this .height - this .imageHeight ) / 2 ;
167- int y = 66 + (yOffset * 15 );
168-
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 );
176- if (TolkienMobsConfig .PAYMENT_TYPE .get ()) {
177- addRenderableWidget (ToggleButtonFactory .ITEM_PAYMENT_METHOD_CLIENT (relX + 155 , relY + y , 1 ,
178- (button ) -> {
179- }));
180- } else {
181- addRenderableWidget (ToggleButtonFactory .EXPERIENCE_PAYMENT_METHOD_CLIENT (relX + 155 , relY + y , 1 ,
182- (button ) -> {
183- }));
184- }
185- yOffset +=1 ; // Adjust for next button
186- }
162+ // int startIndex = currentPage * maxItemsPerPage;
163+ // int endIndex = Math.min(startIndex + maxItemsPerPage, getItemsForPage().size());
164+ // TolkienMobsMain.LOGGER.warn(String.valueOf(endIndex));
165+ //
166+ // for (int i = startIndex; i < endIndex; i++) {
167+ // TolkienMobsMain.LOGGER.warn(String.valueOf(i));
168+ //
169+ // getItemsForPage().get(i);
170+ // }
187171 }
188172
189173 public void updateRenderables () {
@@ -222,22 +206,39 @@ public int getPageCount(){
222206 return Math .max ((int ) Math .ceil ((double ) i / maxItemsPerPage ) - 1 , 0 );
223207 }
224208
225- private List <String > getItemsForPage () {
226- int start = currentPage * maxItemsPerPage ;
227- int i = 0 ;
209+ private List <AbstractWidget > getItemsForPage () {
210+ int yOffset = 0 ;
228211
229212 for (MilestoneHandler .MilestoneData data : MilestoneHandler .getKnownByPlayer (Objects .requireNonNull (getMinecraft ().player ))) {
230213 if (data .getUuid ().equals (tileEntity .getUUID ())) continue ;
231- i ++;
232- locationList .add (String .valueOf (data .getName ()));
233- }
234214
235- int end = Math .min (start + maxItemsPerPage , i );
215+ int relX = (this .width - this .imageWidth ) / 2 ;
216+ int relY = (this .height - this .imageHeight ) / 2 ;
217+ int y = 66 + (yOffset * 15 );
218+ locationList .add (
219+ this .addRenderableWidget (Button .builder (Component .literal (data .getName ()),
220+ button -> {
221+ this .tileEntity .sendPacketToServer (output -> output .writeUUID (data .getUuid ()), 3 );
222+ })
223+ .pos (relX + 5 , relY + y )
224+ .size (150 , 15 )
225+ .build ()
226+ )
227+ );
228+ if (TolkienMobsConfig .PAYMENT_TYPE .get ()) {
229+ addRenderableWidget (ToggleButtonFactory .ITEM_PAYMENT_METHOD_CLIENT (relX + 155 , relY + y , this .tileEntity .getItemTravelCost (data ),
230+ (button ) -> {
236231
237- if (start >= end ) {
238- return Collections .emptyList ();
232+ }));
233+ } else {
234+ addRenderableWidget (ToggleButtonFactory .EXPERIENCE_PAYMENT_METHOD_CLIENT (relX + 155 , relY + y , this .tileEntity .getExperienceTravelCost (data ),
235+ (button ) -> {
236+
237+ }));
238+ }
239+ yOffset +=1 ; // Adjust for next button
239240 }
240- return locationList . subList ( start , end ) ;
241+ return locationList ;
241242 }
242243
243244 @ Override
@@ -264,7 +265,7 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
264265 int relY = (this .height - this .imageHeight ) / 2 ;
265266
266267 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+ guiGraphics .drawCenteredString (font , pagesLabel , (relX + 100 - font .width (pagesLabel )), relY + 179 , ColorUtility .DARKGRAY .getColor ());
268269
269270 this .renderTooltip (guiGraphics , mouseX , mouseY );
270271 }
@@ -340,6 +341,22 @@ else if (btn == 1)
340341 return ret ;
341342 }
342343
344+ @ Override
345+ public boolean mouseScrolled (double mouseX , double mouseY , double scrollDeltaX , double scrollDeltaY ) {
346+ if (scrollDeltaY > 0 ) {
347+ // Scroll up, go to previous page
348+ if (this .currentPage > 0 ) {
349+ this .currentPage --;
350+ }
351+ } else {
352+ // Scroll down, go to next page
353+ if (this .currentPage < getPageCount () - 1 ) {
354+ this .currentPage ++;
355+ }
356+ }
357+ return true ;
358+ }
359+
343360 @ Override
344361 public boolean keyPressed (int key , int scancode , int p_keyPressed_3_ ) {
345362 if (getMinecraft ().player .isCreative ()) {
0 commit comments