Skip to content

Commit

Permalink
Fix quite important AH bug (#689)
Browse files Browse the repository at this point in the history
* fix the bug

* press ESC to go back to Auctions browser from the auction view

* hurray for formatting

* Apply suggestions from code review

---------

Co-authored-by: Kevin <92656833+kevinthegreat1@users.noreply.github.com>
  • Loading branch information
viciscat and kevinthegreat1 authored May 14, 2024
1 parent 2d1b82d commit aa24661
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.hysky.skyblocker.utils.render.gui.AbstractCustomHypixelGUI;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.PopupScreen;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.DirectionalLayoutWidget;
import net.minecraft.client.gui.widget.SimplePositioningWidget;
Expand All @@ -21,7 +22,9 @@
import net.minecraft.util.Colors;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

import java.time.Duration;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -55,6 +58,15 @@ public AuctionViewScreen(AuctionHouseScreenHandler handler, PlayerInventory inve
titleY = 4;
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
clickSlot(BACK_BUTTON_SLOT);
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
protected void init() {
super.init();
Expand All @@ -78,10 +90,13 @@ protected void init() {
verticalLayout.forEachChild(this::addDrawableChild);
updateLayout();

addDrawableChild(new ButtonWidget.Builder(Text.literal("<"), button -> this.clickSlot(BACK_BUTTON_SLOT))
ButtonWidget backButton = new ButtonWidget.Builder(Text.literal("<"), button -> this.clickSlot(BACK_BUTTON_SLOT))
.position(x + backgroundWidth - 16, y + 4)
.size(12, 12)
.build());
.tooltip(Tooltip.of(Text.literal("or press ESC!")))
.build();
backButton.setTooltipDelay(Duration.ofSeconds(1));
addDrawableChild(backButton);


}
Expand Down Expand Up @@ -189,7 +204,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {

@Override
public void onSlotChange(AuctionHouseScreenHandler handler, int slotId, ItemStack stack) {
if (stack.isOf(Items.BLACK_STAINED_GLASS_PANE) || slotId == 13) return;
if (stack.isOf(Items.BLACK_STAINED_GLASS_PANE) || slotId == 13 || slotId >= handler.getRows() * 9) return;
assert client != null;
if (stack.isOf(Items.RED_TERRACOTTA)) { // Red terracotta shows up when you can cancel it
changeState(BuyState.CANCELLABLE_AUCTION);
Expand Down

0 comments on commit aa24661

Please sign in to comment.