Skip to content

Commit

Permalink
Merge pull request #489 from ferriarnus/resizewidget
Browse files Browse the repository at this point in the history
Fix resize bug with Enum Widgets
  • Loading branch information
Rover656 authored Nov 11, 2023
2 parents c39cbc3 + 5c5c885 commit 0e4b5f1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/java/com/enderio/core/client/gui/screen/EIOScreen.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -45,10 +47,21 @@ public void resize(Minecraft pMinecraft, int pWidth, int pHeight) {
oldEditBoxValues.put(editBox.getMessage().getString(), editBox.getValue());
}
editBoxList.clear();
Map<String, Boolean> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class EnumIconWidget<T extends Enum<T> & IIcon, U extends Screen & IEnder

private boolean isExpanded = false;

private boolean expandNext = false;

private int mouseButton = 0;

private final U addedOn;
Expand Down Expand Up @@ -125,6 +127,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);
Expand Down Expand Up @@ -161,6 +168,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<LateTooltipData> tooltips = new ArrayList<>();
Expand Down Expand Up @@ -214,6 +234,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 {
Expand Down

0 comments on commit 0e4b5f1

Please sign in to comment.