Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resize bug with Enum Widgets #489

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading