diff options
author | vicisacat <victor.branchu@gmail.com> | 2024-03-23 21:19:33 +0100 |
---|---|---|
committer | vicisacat <victor.branchu@gmail.com> | 2024-04-12 17:18:23 +0200 |
commit | 8e487a87c51da89072c70f9c46e0b0e5d423d45f (patch) | |
tree | 7163407dbb3e6025dd5e142d7935289d382aaa9a /src/main/java/de/hysky/skyblocker/utils/render/gui | |
parent | 5b258a6cd798678b2cb98be029443c5048496a86 (diff) | |
download | Skyblocker-8e487a87c51da89072c70f9c46e0b0e5d423d45f.tar.gz Skyblocker-8e487a87c51da89072c70f9c46e0b0e5d423d45f.tar.bz2 Skyblocker-8e487a87c51da89072c70f9c46e0b0e5d423d45f.zip |
it works ain't that GREAT
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils/render/gui')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractCustomHypixelGUI.java | 56 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/render/gui/BarebonesPopupScreen.java | 56 |
2 files changed, 112 insertions, 0 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractCustomHypixelGUI.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractCustomHypixelGUI.java new file mode 100644 index 00000000..4f648b8c --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractCustomHypixelGUI.java @@ -0,0 +1,56 @@ +package de.hysky.skyblocker.utils.render.gui; + +import de.hysky.skyblocker.mixin.accessor.HandledScreenAccessor; +import de.hysky.skyblocker.skyblock.auction.AuctionHouseScreenHandler; +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerListener; +import net.minecraft.screen.slot.SlotActionType; +import net.minecraft.text.Text; + +public abstract class AbstractCustomHypixelGUI<T extends ScreenHandler> extends HandledScreen<T> implements ScreenHandlerListener { + + public boolean isWaitingForServer = true; + public AbstractCustomHypixelGUI(T handler, PlayerInventory inventory, Text title) { + super(handler, inventory, title); + handler.addListener(this); + } + + protected void clickSlot(int slotID, int button) { + if (isWaitingForServer) return; + if (client == null) return; + assert this.client.interactionManager != null; + this.client.interactionManager.clickSlot(handler.syncId, slotID, button, SlotActionType.PICKUP, client.player); + handler.getCursorStack().setCount(0); + isWaitingForServer = true; + } + + protected void clickSlot(int slotID) { + clickSlot(slotID, 0); + } + + public void changeHandler(AuctionHouseScreenHandler newHandler) { + handler.removeListener(this); + ((HandledScreenAccessor) this).setHandler(newHandler); + handler.addListener(this); + } + + @Override + public void removed() { + super.removed(); + handler.removeListener(this); + } + + @Override + public final void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) { + onSlotChange(this.handler, slotId, stack); + isWaitingForServer = false; + } + + protected abstract void onSlotChange(T handler, int slotID, ItemStack stack); + + @Override + public void onPropertyUpdate(ScreenHandler handler, int property, int value) {} +} diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/BarebonesPopupScreen.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/BarebonesPopupScreen.java new file mode 100644 index 00000000..56b07966 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/BarebonesPopupScreen.java @@ -0,0 +1,56 @@ +package de.hysky.skyblocker.utils.render.gui; + +import com.mojang.blaze3d.platform.GlConst; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +/** + * A more bare-bones version of Vanilla's Popup Screen. Meant to be extended. + */ +public class BarebonesPopupScreen extends Screen { + private static final Identifier BACKGROUND_TEXTURE = new Identifier("popup/background"); + private final Screen backgroundScreen; + + protected BarebonesPopupScreen(Text title, Screen backgroundScreen) { + super(title); + this.backgroundScreen = backgroundScreen; + } + + @Override + public void close() { + assert this.client != null; + this.client.setScreen(this.backgroundScreen); + } + + @Override + public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) { + this.backgroundScreen.render(context, -1, -1, delta); + context.draw(); + RenderSystem.clear(GlConst.GL_DEPTH_BUFFER_BIT, MinecraftClient.IS_SYSTEM_MAC); + this.renderInGameBackground(context); + } + + /** + * These are the inner positions and size of the popup, not outer + */ + public static void drawPopupBackground(DrawContext context, int x, int y, int width, int height) { + context.drawGuiTexture(BACKGROUND_TEXTURE, x - 18, y - 18, width + 36, height + 36); + } + + @Override + protected void init() { + super.init(); + this.backgroundScreen.resize(this.client, width, height); + + } + + @Override + public void onDisplayed() { + super.onDisplayed(); + this.backgroundScreen.blur(); + } +}
\ No newline at end of file |