From ebe25df27f09968a77cac7d51483f340424670de Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Mon, 21 Aug 2023 22:36:38 +0200 Subject: [PATCH] Fix resize bug with Enum Widgets --- .../core/client/gui/screen/EIOScreen.java | 13 ++++++++++ .../client/gui/widgets/EnumIconWidget.java | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/core/java/com/enderio/core/client/gui/screen/EIOScreen.java b/src/core/java/com/enderio/core/client/gui/screen/EIOScreen.java index cd5ef3f278..d9d19cc557 100644 --- a/src/core/java/com/enderio/core/client/gui/screen/EIOScreen.java +++ b/src/core/java/com/enderio/core/client/gui/screen/EIOScreen.java @@ -1,11 +1,13 @@ package com.enderio.core.client.gui.screen; import com.enderio.api.misc.Vector2i; +import com.enderio.core.client.gui.widgets.EnumIconWidget; import com.enderio.core.common.menu.SyncedMenu; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.components.Renderable; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @@ -41,10 +43,21 @@ public void resize(Minecraft pMinecraft, int pWidth, int pHeight) { oldEditBoxValues.put(editBox.getMessage().getString(), editBox.getValue()); } editBoxList.clear(); + Map oldEnums = new HashMap<>(); + for (Renderable renderable: renderables) { + if (renderable instanceof EnumIconWidget enumIconWidget) { + oldEnums.put(enumIconWidget.getOptionName().getString(), enumIconWidget.isExpanded()); + } + } super.resize(pMinecraft, pWidth, pHeight); for (EditBox editBox : editBoxList) { editBox.setValue(oldEditBoxValues.getOrDefault(editBox.getMessage().getString(), "")); } + for (Renderable renderable: renderables) { + if (renderable instanceof EnumIconWidget enumIconWidget) { + enumIconWidget.setExpanded(oldEnums.getOrDefault(enumIconWidget.getOptionName().getString(), false)); + } + } } @Override diff --git a/src/core/java/com/enderio/core/client/gui/widgets/EnumIconWidget.java b/src/core/java/com/enderio/core/client/gui/widgets/EnumIconWidget.java index 2f3bc34ce7..8ad9b1b52e 100644 --- a/src/core/java/com/enderio/core/client/gui/widgets/EnumIconWidget.java +++ b/src/core/java/com/enderio/core/client/gui/widgets/EnumIconWidget.java @@ -37,6 +37,8 @@ public class EnumIconWidget & IIcon, U extends Screen & IEnder private boolean isExpanded = false; + private boolean expandNext = false; + private int mouseButton = 0; private final U addedOn; @@ -120,6 +122,11 @@ private static int getRow(int index) { @Override public void renderWidget(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { + if (expandNext && Minecraft.getInstance().screen == addedOn) { + Minecraft.getInstance().pushGuiLayer(selection); + expandNext = false; + isExpanded = true; + } if (isHovered && isActive()) { // @formatter:off addedOn.renderTooltipAfterEverything(guiGraphics, List.of(optionName, getter.get().getTooltip().copy().withStyle(ChatFormatting.GRAY)), pMouseX, pMouseY); @@ -156,6 +163,19 @@ public void onGlobalClick(double mouseX, double mouseY) { } } + public boolean isExpanded() { + return isExpanded; + } + + public void setExpanded(Boolean expanded) { + expandNext = expanded; + isExpanded = expanded; + } + + public Component getOptionName() { + return optionName; + } + private class SelectionScreen extends Screen implements IEnderScreen { private final List tooltips = new ArrayList<>(); @@ -209,6 +229,11 @@ public void onClose() { EnumIconWidget.this.isExpanded = false; super.onClose(); } + + @Override + public void resize(Minecraft minecraft, int width, int height) { + minecraft.popGuiLayer(); + } } private class SelectionWidget extends AbstractWidget {