diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-01-14 23:37:16 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-01-15 00:18:03 +0800 |
| commit | b07b0f77ec1327a8f927e4f4559387a0560b02ba (patch) | |
| tree | 8f1cd5891f5d8db5554d402186e5f3c6f055f01d /runtime/src/main/java/me | |
| parent | e266595bcd8645e98074b2bcecb62ae3cc3e52bc (diff) | |
| download | RoughlyEnoughItems-b07b0f77ec1327a8f927e4f4559387a0560b02ba.tar.gz RoughlyEnoughItems-b07b0f77ec1327a8f927e4f4559387a0560b02ba.tar.bz2 RoughlyEnoughItems-b07b0f77ec1327a8f927e4f4559387a0560b02ba.zip | |
Introduce config button menu
Diffstat (limited to 'runtime/src/main/java/me')
20 files changed, 689 insertions, 253 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index d5d89a653..632a371b3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -181,7 +181,12 @@ public class REIRuntimeImpl implements REIRuntime { @Override public ResourceLocation getDefaultDisplayTexture() { - return isDarkThemeEnabled() ? DISPLAY_TEXTURE_DARK : DISPLAY_TEXTURE; + return getDefaultDisplayTexture(isDarkThemeEnabled()); + } + + @Override + public ResourceLocation getDefaultDisplayTexture(boolean darkTheme) { + return darkTheme ? DISPLAY_TEXTURE_DARK : DISPLAY_TEXTURE; } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index d03b482b7..0e21e7103 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -96,6 +96,10 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return appearance.theme == AppearanceTheme.DARK; } + public void setUsingDarkTheme(boolean dark) { + appearance.theme = dark ? AppearanceTheme.DARK : AppearanceTheme.LIGHT; + } + @Override public boolean isGrabbingItems() { return basics.cheatingStyle == ItemCheatingStyle.GRAB; @@ -116,6 +120,10 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return appearance.scrollingEntryListWidget; } + public void setEntryListWidgetScrolled(boolean scrollingEntryListWidget) { + appearance.scrollingEntryListWidget = scrollingEntryListWidget; + } + @Override public boolean shouldAppendModNames() { return advanced.tooltips.appendModNames; @@ -136,16 +144,28 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return appearance.layout.searchFieldLocation; } + public void setSearchFieldLocation(SearchFieldLocation location) { + appearance.layout.searchFieldLocation = location; + } + @Override public DisplayPanelLocation getDisplayPanelLocation() { return advanced.accessibility.displayPanelLocation; } + public void setDisplayPanelLocation(DisplayPanelLocation location) { + advanced.accessibility.displayPanelLocation = location; + } + @Override public boolean isCraftableFilterEnabled() { return appearance.layout.enableCraftableOnlyButton; } + public void setCraftableFilterEnabled(boolean enabled) { + appearance.layout.enableCraftableOnlyButton = enabled; + } + @Override public String getGamemodeCommand() { return advanced.commands.gamemodeCommand; @@ -176,6 +196,10 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return functionality.disableRecipeBook; } + public void setDisableRecipeBook(boolean disableRecipeBook) { + functionality.disableRecipeBook = disableRecipeBook; + } + @Override public boolean doesFixTabCloseContainer() { return functionality.disableRecipeBook; @@ -390,6 +414,10 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return appearance.syntaxHighlightingMode; } + public void setSyntaxHighlightingMode(SyntaxHighlightingMode mode) { + appearance.syntaxHighlightingMode = mode; + } + @Override public SearchMode getTooltipSearchMode() { return advanced.search.tooltipSearch; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java index d9c57ea73..831cfe342 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java @@ -39,6 +39,7 @@ import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.gui.config.DisplayPanelLocation; import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; +import me.shedaniel.rei.api.client.gui.config.SyntaxHighlightingMode; import me.shedaniel.rei.api.client.gui.drag.DraggableStackProvider; import me.shedaniel.rei.api.client.gui.drag.DraggableStackVisitor; import me.shedaniel.rei.api.client.gui.drag.DraggingContext; @@ -62,9 +63,15 @@ import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.REIRuntimeImpl; +import me.shedaniel.rei.impl.client.config.ConfigManagerImpl; +import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; import me.shedaniel.rei.impl.client.gui.craftable.CraftableFilter; import me.shedaniel.rei.impl.client.gui.dragging.CurrentDraggingStack; import me.shedaniel.rei.impl.client.gui.modules.Menu; +import me.shedaniel.rei.impl.client.gui.modules.MenuEntry; +import me.shedaniel.rei.impl.client.gui.modules.entries.SeparatorMenuEntry; +import me.shedaniel.rei.impl.client.gui.modules.entries.SubMenuEntry; +import me.shedaniel.rei.impl.client.gui.modules.entries.ToggleMenuEntry; import me.shedaniel.rei.impl.client.gui.widget.*; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; import me.shedaniel.rei.impl.common.util.Weather; @@ -153,7 +160,7 @@ public class ScreenOverlayImpl extends ScreenOverlay { this.uuid = uuid; this.menu = menu; this.wrappedMenu = wrappedMenu; - this.inBounds = or.or(point -> menu.getBounds().contains(point)).and(and); + this.inBounds = or.or(menu::containsMouse).and(and); } } @@ -237,7 +244,6 @@ public class ScreenOverlayImpl extends ScreenOverlay { this.shouldReloadSearch = false; //Update Variables this.children().clear(); - this.closeOverlayMenu(); this.window = Minecraft.getInstance().getWindow(); this.screenBounds = ScreenRegistry.getInstance().getScreenBounds(Minecraft.getInstance().screen); this.bounds = calculateOverlayBounds(); @@ -277,6 +283,7 @@ public class ScreenOverlayImpl extends ScreenOverlay { } final Rectangle configButtonArea = getConfigButtonArea(); + UUID configButtonUuid = UUID.fromString("4357bc36-0a4e-47d2-8e07-ddc220df4a0f"); widgets.add(configButton = InternalWidgets.wrapLateRenderable( Widgets.withTranslate( InternalWidgets.concatWidgets( @@ -294,6 +301,19 @@ public class ScreenOverlayImpl extends ScreenOverlay { } else { button.removeTint(); } + + boolean isOpened = isMenuOpened(configButtonUuid); + if (isOpened || !isAnyMenuOpened()) { + boolean inBounds = (isNotInExclusionZones(PointHelper.getMouseFloatingX(), PointHelper.getMouseFloatingY()) && button.containsMouse(PointHelper.ofMouse())) || isMenuInBounds(configButtonUuid); + if (isOpened != inBounds) { + if (inBounds) { + Menu menu = new Menu(button.getBounds(), provideConfigButtonMenu(), false); + openMenu(configButtonUuid, menu, button::containsMouse, point -> true); + } else { + closeOverlayMenu(); + } + } + } }) .focusable(false) .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y)) @@ -327,7 +347,7 @@ public class ScreenOverlayImpl extends ScreenOverlay { widgets.add(InternalWidgets.wrapLateRenderable(Widgets.withTranslate(Widgets.createButton(subsetsButtonBounds, ClientHelperImpl.getInstance().isAprilFools.get() ? new TranslatableComponent("text.rei.tiny_potato") : new TranslatableComponent("text.rei.subsets")) .onClick(button -> { proceedOpenMenuOrElse(Menu.SUBSETS, () -> { - openMenu(Menu.SUBSETS, Menu.createSubsetsMenuFromRegistry(new Point(subsetsButtonBounds.x, subsetsButtonBounds.getMaxY())), point -> true, point -> true); + openMenu(Menu.SUBSETS, Menu.createSubsetsMenuFromRegistry(subsetsButtonBounds), point -> true, point -> true); }, menu -> { closeOverlayMenu(); }); @@ -376,6 +396,65 @@ public class ScreenOverlayImpl extends ScreenOverlay { widgets.add(draggingStack); } + private Collection<MenuEntry> provideConfigButtonMenu() { + ConfigObjectImpl config = ConfigManagerImpl.getInstance().getConfig(); + return Arrays.asList( + ToggleMenuEntry.of(new TranslatableComponent("text.rei.cheating"), + config::isCheating, + config::setCheating + ), + new SeparatorMenuEntry(), + ToggleMenuEntry.ofDeciding(new TranslatableComponent("text.rei.config.menu.dark_theme"), + config::isUsingDarkTheme, + dark -> { + config.setUsingDarkTheme(dark); + return false; + } + ), + ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.craftable_filter"), + config::isCraftableFilterEnabled, + config::setCraftableFilterEnabled + ), + new SubMenuEntry(new TranslatableComponent("text.rei.config.menu.display"), Arrays.asList( + ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.display.remove_recipe_book"), + config::doesDisableRecipeBook, + disableRecipeBook -> { + config.setDisableRecipeBook(disableRecipeBook); + Screen screen = Minecraft.getInstance().screen; + + if (screen != null) { + screen.init(minecraft, screen.width, screen.height); + } + } + ), + ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.display.left_side_panel"), + config::isLeftHandSidePanel, + bool -> config.setDisplayPanelLocation(bool ? DisplayPanelLocation.LEFT : DisplayPanelLocation.RIGHT) + ), + ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.display.scrolling_side_panel"), + config::isEntryListWidgetScrolled, + config::setEntryListWidgetScrolled + ), + new SeparatorMenuEntry(), + ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.display.side_search_field"), + () -> config.getSearchFieldLocation() != SearchFieldLocation.CENTER, + bool -> config.setSearchFieldLocation(bool ? SearchFieldLocation.BOTTOM_SIDE : SearchFieldLocation.CENTER) + ), + ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.display.syntax_highlighting"), + () -> config.getSyntaxHighlightingMode() == SyntaxHighlightingMode.COLORFUL || config.getSyntaxHighlightingMode() == SyntaxHighlightingMode.COLORFUL_UNDERSCORED, + bool -> config.setSyntaxHighlightingMode(bool ? SyntaxHighlightingMode.COLORFUL : SyntaxHighlightingMode.PLAIN_UNDERSCORED) + ) + )), + new SeparatorMenuEntry(), + ToggleMenuEntry.ofDeciding(new TranslatableComponent("text.rei.config.menu.config"), + () -> false, + $ -> { + ConfigManager.getInstance().openConfigScreen(REIRuntime.getInstance().getPreviousScreen()); + return false; + }) + ); + } + private Rectangle getSubsetsButtonBounds() { if (ConfigObject.getInstance().isSubsetsEnabled()) { ScreenRegistry registry = ScreenRegistry.getInstance(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/AbstractMenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/AbstractMenuEntry.java new file mode 100644 index 000000000..3b2908d2e --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/AbstractMenuEntry.java @@ -0,0 +1,54 @@ +package me.shedaniel.rei.impl.client.gui.modules; + +public abstract class AbstractMenuEntry extends MenuEntry { + private int x, y, width; + private boolean selected, containsMouse, rendering; + + @Override + public void updateInformation(int xPos, int yPos, boolean selected, boolean containsMouse, boolean rendering, int width) { + this.x = xPos; + this.y = yPos; + this.selected = selected; + this.containsMouse = containsMouse; + this.rendering = rendering; + this.width = width; + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (isRendering() && mouseX >= getX() && mouseX <= getX() + getWidth() && mouseY >= getY() && mouseY < getY() + getEntryHeight()) { + if (onClick(mouseX, mouseY, button)) { + return true; + } + } + return super.mouseClicked(mouseX, mouseY, button); + } + + protected boolean onClick(double mouseX, double mouseY, int button) { + return false; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getWidth() { + return width; + } + + public boolean isSelected() { + return selected; + } + + public boolean containsMouse() { + return containsMouse; + } + + public boolean isRendering() { + return rendering; + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/Menu.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/Menu.java index 7c6505c98..475da54e4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/Menu.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/Menu.java @@ -41,10 +41,13 @@ import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.client.gui.modules.entries.EntryStackSubsetsMenuEntry; +import me.shedaniel.rei.impl.client.gui.modules.entries.SubMenuEntry; import me.shedaniel.rei.impl.client.gui.modules.entries.SubSubsetsMenuEntry; import me.shedaniel.rei.impl.client.gui.widget.LateRenderable; +import net.minecraft.client.Minecraft; import net.minecraft.client.resources.language.I18n; import net.minecraft.core.Registry; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -61,6 +64,8 @@ public class Menu extends WidgetWithBounds implements LateRenderable { public static final UUID GAME_TYPE = UUID.randomUUID(); public final Point menuStartPoint; + public final boolean facingRight; + public final boolean facingDownwards; private final List<MenuEntry> entries = Lists.newArrayList(); public final ScrollingContainer scrolling = new ScrollingContainer() { @Override @@ -83,12 +88,26 @@ public class Menu extends WidgetWithBounds implements LateRenderable { } }; - public Menu(Point menuStartPoint, Collection<MenuEntry> entries) { - this.menuStartPoint = menuStartPoint; - buildEntries(entries); + public Menu(Rectangle menuStart, Collection<MenuEntry> entries, boolean sort) { + buildEntries(entries, sort); + int fullWidth = Minecraft.getInstance().screen.width; + int fullHeight = Minecraft.getInstance().screen.height; + boolean facingRight = true; + this.facingDownwards = fullHeight - menuStart.getMaxY() > menuStart.y; + int y = facingDownwards ? menuStart.getMaxY() : menuStart.y - (scrolling.getMaxScrollHeight() + 2); + boolean hasScrollBar = scrolling.getMaxScrollHeight() > getInnerHeight(y); + int menuWidth = getMaxEntryWidth() + 2 + (hasScrollBar ? 6 : 0); + if (facingRight && fullWidth - menuStart.getMaxX() < menuWidth + 10) { + facingRight = false; + } else if (!facingRight && menuStart.x < menuWidth + 10) { + facingRight = true; + } + this.facingRight = facingRight; + int x = facingRight ? menuStart.x : menuStart.getMaxX() - (getMaxEntryWidth() + 2 + (hasScrollBar ? 6 : 0)); + this.menuStartPoint = new Point(x, y); } - public static Menu createSubsetsMenuFromRegistry(Point menuStartPoint) { + public static Menu createSubsetsMenuFromRegistry(Rectangle menuStart) { EntryRegistry instance = EntryRegistry.getInstance(); List<? extends EntryStack<?>> stacks = instance.getEntryStacks().collect(Collectors.toList()); Map<String, Object> entries = Maps.newHashMap(); @@ -132,7 +151,7 @@ public class Menu extends WidgetWithBounds implements LateRenderable { } } } - return new Menu(menuStartPoint, buildEntries(entries)); + return new Menu(menuStart, buildEntries(entries), true); } private static Map<String, Object> getOrCreateSubEntryInMap(Map<String, Object> parent, String pathSegment) { @@ -166,12 +185,12 @@ public class Menu extends WidgetWithBounds implements LateRenderable { } else { Map<String, Object> entryMap = (Map<String, Object>) entry.getValue(); if (entry.getKey().startsWith("_item_group_")) { - entries.add(new SubSubsetsMenuEntry(I18n.get(entry.getKey().replace("_item_group_", "itemGroup.")), buildEntries(entryMap))); + entries.add(new SubSubsetsMenuEntry(new TranslatableComponent(entry.getKey().replace("_item_group_", "itemGroup.")), buildEntries(entryMap))); } else { String translationKey = "subsets.rei." + entry.getKey().replace(':', '.'); if (!I18n.exists(translationKey)) RoughlyEnoughItemsCore.LOGGER.warn("Subsets menu " + translationKey + " does not have a translation"); - entries.add(new SubSubsetsMenuEntry(I18n.get(translationKey), buildEntries(entryMap))); + entries.add(new SubSubsetsMenuEntry(new TranslatableComponent(translationKey), buildEntries(entryMap))); } } } @@ -179,11 +198,13 @@ public class Menu extends WidgetWithBounds implements LateRenderable { } @SuppressWarnings("deprecation") - private void buildEntries(Collection<MenuEntry> entries) { + private void buildEntries(Collection<MenuEntry> entries, boolean sort) { this.entries.clear(); this.entries.addAll(entries); - this.entries.sort(Comparator.comparing(entry -> entry instanceof SubSubsetsMenuEntry ? 0 : 1) - .thenComparing(entry -> entry instanceof SubSubsetsMenuEntry menuEntry ? menuEntry.text : "")); + if (sort) { + this.entries.sort(Comparator.comparing(entry -> entry instanceof SubMenuEntry ? 0 : 1) + .thenComparing(entry -> entry instanceof SubMenuEntry menuEntry ? menuEntry.text.getString() : "")); + } for (MenuEntry entry : this.entries) { entry.parent = this; } @@ -191,19 +212,19 @@ public class Menu extends WidgetWithBounds implements LateRenderable { @Override public Rectangle getBounds() { - return new Rectangle(menuStartPoint.x, menuStartPoint.y, getMaxEntryWidth() + 2 + (hasScrollBar() ? 6 : 0), getInnerHeight() + 2); + return new Rectangle(menuStartPoint.x, menuStartPoint.y, getMaxEntryWidth() + 2 + (hasScrollBar() ? 6 : 0), getInnerHeight(menuStartPoint.y) + 2); } public Rectangle getInnerBounds() { - return new Rectangle(menuStartPoint.x + 1, menuStartPoint.y + 1, getMaxEntryWidth() + (hasScrollBar() ? 6 : 0), getInnerHeight()); + return new Rectangle(menuStartPoint.x + 1, menuStartPoint.y + 1, getMaxEntryWidth() + (hasScrollBar() ? 6 : 0), getInnerHeight(menuStartPoint.y)); } public boolean hasScrollBar() { - return scrolling.getMaxScrollHeight() > getInnerHeight(); + return scrolling.getMaxScrollHeight() > getInnerHeight(menuStartPoint.y); } - public int getInnerHeight() { - return Math.min(scrolling.getMaxScrollHeight(), minecraft.screen.height - 20 - menuStartPoint.y); + public int getInnerHeight(int y) { + return Math.min(scrolling.getMaxScrollHeight(), minecraft.screen.height - 20 - y); } public int getMaxEntryWidth() { @@ -268,7 +289,7 @@ public class Menu extends WidgetWithBounds implements LateRenderable { return true; } for (MenuEntry child : children()) { - if (child instanceof SubSubsetsMenuEntry) { + if (child instanceof SubMenuEntry) { if (child.mouseScrolled(mouseX, mouseY, amount)) return true; } @@ -277,6 +298,17 @@ public class Menu extends WidgetWithBounds implements LateRenderable { } @Override + public boolean containsMouse(double mouseX, double mouseY) { + if (super.containsMouse(mouseX, mouseY)) return true; + for (MenuEntry child : children()) { + if (child.containsMouse(mouseX, mouseY)) { + return true; + } + } + return false; + } + + @Override public List<MenuEntry> children() { return entries; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/EntryStackSubsetsMenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/EntryStackSubsetsMenuEntry.java index 7ec5bd243..4d6c885c1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/EntryStackSubsetsMenuEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/EntryStackSubsetsMenuEntry.java @@ -36,6 +36,7 @@ import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; +import me.shedaniel.rei.impl.client.gui.modules.AbstractMenuEntry; import me.shedaniel.rei.impl.client.gui.modules.Menu; import me.shedaniel.rei.impl.client.gui.modules.MenuEntry; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -48,14 +49,12 @@ import java.util.List; @ApiStatus.Experimental @ApiStatus.Internal -public class EntryStackSubsetsMenuEntry extends MenuEntry { - final EntryStack stack; - private int x, y, width; - private boolean selected, containsMouse, rendering; +public class EntryStackSubsetsMenuEntry extends AbstractMenuEntry { + final EntryStack<?> stack; private boolean clickedLast = false; private Boolean isFiltered = null; - public EntryStackSubsetsMenuEntry(EntryStack stack) { + public EntryStackSubsetsMenuEntry(EntryStack<?> stack) { this.stack = stack; } @@ -70,27 +69,13 @@ public class EntryStackSubsetsMenuEntry extends MenuEntry { } @Override - public void updateInformation(int xPos, int yPos, boolean selected, boolean containsMouse, boolean rendering, int width) { - this.x = xPos; - this.y = yPos; - this.selected = selected; - this.containsMouse = containsMouse; - this.rendering = rendering; - this.width = width; - } - - @Override public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { if (isFiltered()) { - if (selected) { - fill(matrices, x, y, x + width, y + 18, -26215); - } else { - fill(matrices, x, y, x + width, y + 18, -65536); - } - } else if (selected) { - fill(matrices, x, y, x + width, y + 18, 1174405119); + fill(matrices, getX(), getY(), getX() + getWidth(), getY() + 18, isSelected() ? -26215 : -65536); + } else if (isSelected()) { + fill(matrices, getX(), getY(), getX() + getWidth(), getY() + 18, 1174405119); } - if (containsMouse && mouseX >= x + (width / 2) - 8 && mouseX <= x + (width / 2) + 8 && mouseY >= y + 1 && mouseY <= y + 17) { + if (containsMouse() && mouseX >= getX() + (getWidth() / 2) - 8 && mouseX <= getX() + (getWidth() / 2) + 8 && mouseY >= getY() + 1 && mouseY <= getY() + 17) { REIRuntime.getInstance().queueTooltip(stack.getTooltip(new Point(mouseX, mouseY))); if (RoughlyEnoughItemsCoreClient.isLeftMousePressed && !clickedLast) { clickedLast = true; @@ -113,13 +98,13 @@ public class EntryStackSubsetsMenuEntry extends MenuEntry { } } else if (!RoughlyEnoughItemsCoreClient.isLeftMousePressed) clickedLast = false; } else clickedLast = false; - stack.render(matrices, new Rectangle(x + (width / 2) - 8, y + 1, 16, 16), mouseX, mouseY, delta); + stack.render(matrices, new Rectangle(getX() + (getWidth() / 2) - 8, getY() + 1, 16, 16), mouseX, mouseY, delta); } void recalculateFilter(Menu menu) { for (MenuEntry child : menu.children()) { - if (child instanceof SubSubsetsMenuEntry && ((SubSubsetsMenuEntry) child).getSubsetsMenu() != null) { - recalculateFilter(((SubSubsetsMenuEntry) child).getSubsetsMenu()); + if (child instanceof SubSubsetsMenuEntry && ((SubSubsetsMenuEntry) child).getChildMenu() != null) { + recalculateFilter(((SubSubsetsMenuEntry) child).getChildMenu()); } else if (child instanceof EntryStackSubsetsMenuEntry && EntryStacks.equalsExact(((EntryStackSubsetsMenuEntry) child).stack, stack)) { ((EntryStackSubsetsMenuEntry) child).isFiltered = null; } @@ -128,7 +113,7 @@ public class EntryStackSubsetsMenuEntry extends MenuEntry { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - return rendering && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 18; + return isRendering() && mouseX >= getX() && mouseX <= getX() + getWidth() && mouseY >= getY() && mouseY <= getY() + getEntryHeight(); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/GameModeMenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/GameModeMenuEntry.java index 2657ff640..6cfe7a387 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/GameModeMenuEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/GameModeMenuEntry.java @@ -27,7 +27,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; -import me.shedaniel.rei.impl.client.gui.modules.MenuEntry; +import me.shedaniel.rei.impl.client.gui.modules.AbstractMenuEntry; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.resources.sounds.SimpleSoundInstance; @@ -39,11 +39,9 @@ import java.util.Collections; import java.util.List; import java.util.Locale; -public class GameModeMenuEntr |
