From 8e487a87c51da89072c70f9c46e0b0e5d423d45f Mon Sep 17 00:00:00 2001 From: vicisacat Date: Sat, 23 Mar 2024 21:19:33 +0100 Subject: it works ain't that GREAT --- .../skyblock/auction/AuctionBrowserScreen.java | 212 +++++++++++++++++---- 1 file changed, 171 insertions(+), 41 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java index a06b9649..11a41d0c 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/auction/AuctionBrowserScreen.java @@ -5,21 +5,23 @@ import de.hysky.skyblocker.skyblock.auction.widgets.AuctionTypeWidget; import de.hysky.skyblocker.skyblock.auction.widgets.CategoryTabWidget; import de.hysky.skyblocker.skyblock.auction.widgets.RarityWidget; import de.hysky.skyblocker.skyblock.auction.widgets.SortWidget; +import de.hysky.skyblocker.utils.render.gui.AbstractCustomHypixelGUI; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.item.TooltipContext; +import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerListener; +import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; +import net.minecraft.text.Style; import net.minecraft.text.Text; +import net.minecraft.util.Colors; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -27,8 +29,27 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; -public class AuctionBrowserScreen extends HandledScreen implements ScreenHandlerListener { +public class AuctionBrowserScreen extends AbstractCustomHypixelGUI { protected static final Identifier TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/auctions_gui/browser/background.png"); + private static final Identifier SCROLLER_TEXTURE = new Identifier("container/creative_inventory/scroller"); + + private static final Identifier up_arrow_tex = new Identifier(SkyblockerMod.NAMESPACE, "up_arrow_even"); // Put them in their own fields to avoid object allocation on each frame + private static final Identifier down_arrow_tex = new Identifier(SkyblockerMod.NAMESPACE, "down_arrow_even"); + public static final Supplier UP_ARROW = () -> MinecraftClient.getInstance().getGuiAtlasManager().getSprite(up_arrow_tex); + public static final Supplier DOWN_ARROW = () -> MinecraftClient.getInstance().getGuiAtlasManager().getSprite(down_arrow_tex); + + + // SLOTS + public static final int RESET_BUTTON_SLOT = 47; + public static final int SEARCH_BUTTON_SLOT = 48; + public static final int BACK_BUTTON_SLOT = 49; + public static final int SORT_BUTTON_SLOT = 50; + public static final int RARITY_BUTTON_SLOT = 51; + public static final int AUCTION_TYPE_BUTTON_SLOT = 52; + + public static final int PREV_PAGE_BUTTON = 46; + public static final int NEXT_PAGE_BUTTON = 53; + // WIDGETS private SortWidget sortWidget; @@ -36,18 +57,13 @@ public class AuctionBrowserScreen extends HandledScreen categoryTabWidgets = new ArrayList<>(6); - - public static int RESET_SLOT_ID = 45; - - - boolean isWaitingForServer = false; + private String search; public AuctionBrowserScreen(AuctionHouseScreenHandler handler, PlayerInventory inventory) { super(handler, inventory, Text.literal("Auctions Browser")); this.backgroundHeight = 187; this.playerInventoryTitleY = 92; this.titleX = 999; - handler.addListener(this); } @Override @@ -56,13 +72,13 @@ public class AuctionBrowserScreen extends HandledScreen tooltip) { - int ordinal = 0; - for (int j = 0; j < tooltip.size()-3; j++) { - if (j+2 >= tooltip.size()) break; - if (tooltip.get(j+2).getString().contains("▶")) { - ordinal = j; - break; - } + @Override + protected void onMouseClick(Slot slot, int slotId, int button, SlotActionType actionType) { + if (slotId >= handler.getRows()*9) return; + super.onMouseClick(slot, slotId, button, actionType); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (isWaitingForServer) return super.mouseClicked(mouseX, mouseY, button); + if (onScrollbarTop((int)mouseX, (int) mouseY) && prevPageVisible) { + clickSlot(PREV_PAGE_BUTTON); + return true; } - return ordinal; + if (onScrollbarBottom((int)mouseX, (int) mouseY) && nextPageVisible) { + clickSlot(NEXT_PAGE_BUTTON); + return true; + } + + if (onSearchField((int)mouseX, (int) mouseY)) { + clickSlot(SEARCH_BUTTON_SLOT); + return true; + } + return super.mouseClicked(mouseX, mouseY, button); + } + + private boolean onScrollbarTop(int mouseX, int mouseY) { + int localX = mouseX - x; + int localY = mouseY - y; + return localX > 154 && localX < 169 && localY > 6 && localY < 44; + } + + private boolean onScrollbarBottom(int mouseX, int mouseY) { + int localX = mouseX - x; + int localY = mouseY - y; + return localX > 154 && localX < 169 && localY > 43 && localY < 80; + } + private boolean onSearchField(int mouseX, int mouseY) { + int localX = mouseX - x; + int localY = mouseY - y; + return localX > 6 && localX < 97 && localY > 3 && localY < 16; } @Override - public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) { + public void onSlotChange(AuctionHouseScreenHandler handler, int slotId, ItemStack stack) { if (client == null || stack.isEmpty()) return; - if (slotId == 50) { + isWaitingForServer = false; + if (slotId == PREV_PAGE_BUTTON) prevPageVisible = false; + if (slotId == NEXT_PAGE_BUTTON) nextPageVisible = false; + if (slotId == SORT_BUTTON_SLOT) { sortWidget.setCurrent(SortWidget.Option.get(getOrdinal(stack.getTooltip(client.player, TooltipContext.BASIC)))); - } else if (slotId == 52) { + } else if (slotId == AUCTION_TYPE_BUTTON_SLOT) { auctionTypeWidget.setCurrent(AuctionTypeWidget.Option.get(getOrdinal(stack.getTooltip(client.player, TooltipContext.BASIC)))); - } else if (slotId == 51) { + } else if (slotId == RARITY_BUTTON_SLOT) { List tooltip = stack.getTooltip(client.player, TooltipContext.BASIC); int ordinal = getOrdinal(tooltip); String split = tooltip.get(ordinal+2).getString().substring(2); rarityWidget.setText(tooltip.subList(1, tooltip.size()-3), split); - } else if (slotId == 45) { + } else if (slotId == RESET_BUTTON_SLOT) { if (resetFiltersButton != null) resetFiltersButton.active = handler.getSlot(slotId).getStack().isOf(Items.ANVIL); + } else if (slotId < this.handler.getRows()*9 && slotId%9 == 0) { + CategoryTabWidget categoryTabWidget = categoryTabWidgets.get(slotId / 9); + categoryTabWidget.setSlotId(slotId); + categoryTabWidget.setIcon(handler.getSlot(slotId).getStack()); + List tooltip = handler.getSlot(slotId).getStack().getTooltip(client.player, TooltipContext.BASIC); + for (int j = tooltip.size() - 1; j >= 0; j--) { + String lowerCase = tooltip.get(j).getString().toLowerCase(); + if (lowerCase.contains("currently")) { + categoryTabWidget.setToggled(true); + break; + } else if (lowerCase.contains("click")) { + categoryTabWidget.setToggled(false); + break; + } else categoryTabWidget.setToggled(false); + } + } else if (slotId == PREV_PAGE_BUTTON && stack.isOf(Items.ARROW)) { + prevPageVisible = true; + parsePage(stack); + } else if (slotId == NEXT_PAGE_BUTTON && stack.isOf(Items.ARROW)) { + nextPageVisible = true; + parsePage(stack); + } else if (slotId == SEARCH_BUTTON_SLOT) { + List tooltip = stack.getTooltip(client.player, TooltipContext.BASIC); + for (Text text : tooltip) { + String string = text.getString(); + if (string.contains("Filtered:")) { + String[] split = string.split(":"); + if (split.length < 2) { + search = ""; + } else search = split[1].trim(); + break; + } + } } } - @Override - public void removed() { - super.removed(); - handler.removeListener(this); + private static int getOrdinal(List tooltip) { + int ordinal = 0; + for (int j = 0; j < tooltip.size()-3; j++) { + if (j+2 >= tooltip.size()) break; + if (tooltip.get(j+2).getString().contains("▶")) { + ordinal = j; + break; + } + } + return ordinal; + } + + int currentPage = 0; + int totalPages = 1; + private boolean prevPageVisible = false; + private boolean nextPageVisible = false; + private void parsePage(ItemStack stack) { + List tooltip = stack.getTooltip(client.player, TooltipContext.BASIC); + String str = tooltip.get(1).getString().trim(); + str = str.substring(1, str.length() - 1); // remove parentheses + String[] parts = str.split("/"); // split the string + try { + currentPage = Integer.parseInt(parts[0].replace(",", "")); // parse current page + totalPages = Integer.parseInt(parts[1].replace(",", "")); // parse total + } catch (NumberFormatException ignored) {} } @Override - public void onPropertyUpdate(ScreenHandler handler, int property, int value) {} + protected boolean isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int button) { + return mouseX < (double)left - 32 || mouseY < (double)top || mouseX >= (double)(left + this.backgroundWidth) || mouseY >= (double)(top + this.backgroundHeight); + } private static class ScaledTextButtonWidget extends ButtonWidget { -- cgit