From 0710ab56e7e8f76670dab785b907ccfe868ad1d5 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 22 Nov 2019 17:23:51 +0800 Subject: 3.2.9 --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 9 +- .../java/me/shedaniel/rei/api/ClientHelper.java | 1 + .../java/me/shedaniel/rei/api/ConfigManager.java | 2 +- .../java/me/shedaniel/rei/api/ConfigObject.java | 11 + .../java/me/shedaniel/rei/api/DisplayHelper.java | 2 +- .../java/me/shedaniel/rei/api/EntryRegistry.java | 1 + .../java/me/shedaniel/rei/api/RecipeHelper.java | 20 +- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 32 +- .../me/shedaniel/rei/gui/OverlaySearchField.java | 4 +- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 2 +- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 24 +- .../rei/gui/VillagerRecipeViewingScreen.java | 29 +- .../rei/gui/widget/AutoCraftingButtonWidget.java | 28 +- .../me/shedaniel/rei/gui/widget/ButtonWidget.java | 67 ++-- .../rei/gui/widget/ClickableLabelWidget.java | 53 ++- .../gui/widget/CraftableToggleButtonWidget.java | 6 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 20 +- .../me/shedaniel/rei/gui/widget/LabelWidget.java | 59 +++- .../rei/gui/widget/RecipeChoosePageWidget.java | 2 +- .../shedaniel/rei/gui/widget/TextFieldWidget.java | 7 +- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 10 +- .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 343 ------------------- .../me/shedaniel/rei/impl/OldConfigObjectImpl.java | 381 +++++++++++++++++++++ .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 20 +- .../java/me/shedaniel/rei/impl/ScreenHelper.java | 12 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 4 +- .../autocrafting/DefaultRecipeBookHandler.java | 1 + .../rei/plugin/brewing/DefaultBrewingCategory.java | 5 - .../shedaniel/rei/utils/ClothScreenRegistry.java | 4 +- 29 files changed, 638 insertions(+), 521 deletions(-) delete mode 100644 src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java create mode 100644 src/main/java/me/shedaniel/rei/impl/OldConfigObjectImpl.java (limited to 'src/main/java/me') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index e4c79a060..c4163e1ae 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -10,6 +10,7 @@ import com.google.common.collect.Maps; import me.shedaniel.cloth.hooks.ClothClientHooks; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.annotations.Internal; import me.shedaniel.rei.api.plugins.REIPluginV0; import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.gui.widget.EntryListWidget; @@ -53,11 +54,16 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicLong; +@Internal public class RoughlyEnoughItemsCore implements ClientModInitializer { + @Internal public static final Logger LOGGER; + @SuppressWarnings("deprecation") private static final RecipeHelper RECIPE_HELPER = new RecipeHelperImpl(); + @SuppressWarnings("deprecation") private static final EntryRegistry ENTRY_REGISTRY = new EntryRegistryImpl(); + @SuppressWarnings("deprecation") private static final DisplayHelper DISPLAY_HELPER = new DisplayHelperImpl(); private static final Map plugins = Maps.newHashMap(); private static final ExecutorService SYNC_RECIPES = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "REI-SyncRecipes")); @@ -207,6 +213,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } } + @SuppressWarnings("deprecation") private void registerClothEvents() { final Identifier recipeButtonTex = new Identifier("textures/gui/recipe_button.png"); AtomicLong lastSync = new AtomicLong(-1); @@ -217,10 +224,8 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } lastSync.set(System.currentTimeMillis()); if (ConfigManager.getInstance().getConfig().doesRegisterRecipesInAnotherThread()) { - //noinspection deprecation CompletableFuture.runAsync(() -> ((RecipeHelperImpl) RecipeHelper.getInstance()).recipesLoaded(recipeManager), SYNC_RECIPES); } else { - //noinspection deprecation ((RecipeHelperImpl) RecipeHelper.getInstance()).recipesLoaded(recipeManager); } }); diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index b72e86ea0..331ab73d9 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -18,6 +18,7 @@ public interface ClientHelper { /** * @return the api instance of {@link ClientHelperImpl} */ + @SuppressWarnings("deprecation") static ClientHelper getInstance() { return ClientHelperImpl.instance; } diff --git a/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/src/main/java/me/shedaniel/rei/api/ConfigManager.java index a1ccecbdb..3d14cc131 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -13,8 +13,8 @@ import java.io.IOException; public interface ConfigManager { + @SuppressWarnings("deprecation") static ConfigManager getInstance() { - //noinspection deprecation return RoughlyEnoughItemsCore.getConfigManager(); } diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java index fb5d0e66d..d6cb52a60 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -10,6 +10,7 @@ import me.shedaniel.rei.gui.config.ItemListOrdering; import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.gui.config.SearchFieldLocation; import me.zeroeightsix.fiber.tree.ConfigNode; +import me.zeroeightsix.fiber.tree.ConfigValue; import me.zeroeightsix.fiber.tree.Node; public interface ConfigObject { @@ -18,6 +19,16 @@ public interface ConfigObject { ConfigNode getConfigNode(); + ConfigValue getOverlayVisibleNode(); + + boolean isLighterButtonHover(); + + void setLighterButtonHover(boolean lighterButtonHover); + + boolean isOverlayVisible(); + + void setOverlayVisible(boolean overlayVisible); + boolean isCheating(); void setCheating(boolean cheating); diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index de01337ea..165a61b93 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -16,8 +16,8 @@ import static net.minecraft.util.ActionResult.PASS; public interface DisplayHelper { + @SuppressWarnings("deprecation") static DisplayHelper getInstance() { - //noinspection deprecation return RoughlyEnoughItemsCore.getDisplayHelper(); } diff --git a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java index e2c66bf94..4fe71b5e3 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java +++ b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -14,6 +14,7 @@ import java.util.List; public interface EntryRegistry { + @SuppressWarnings("deprecation") static EntryRegistry getInstance() { return RoughlyEnoughItemsCore.getEntryRegistry(); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index 3ddfdf7a4..cfe5b520b 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -20,8 +20,8 @@ import java.util.function.Predicate; public interface RecipeHelper { + @SuppressWarnings("deprecation") static RecipeHelper getInstance() { - //noinspection deprecation return RoughlyEnoughItemsCore.getRecipeHelper(); } @@ -115,15 +115,15 @@ public interface RecipeHelper { Map, List> getUsagesFor(EntryStack stack); /** - * Gets the optional of the speed crafting button area from a category + * Gets the optional of the auto crafting button area from a category * * @param category the category of the display - * @return the optional of speed crafting button area + * @return the optional of auto crafting button area */ Optional getAutoCraftButtonArea(RecipeCategory category); /** - * Registers a speed crafting button area + * Registers a auto crafting button area * * @param category the category of the button area * @param rectangle the button area @@ -131,21 +131,14 @@ public interface RecipeHelper { void registerAutoCraftButtonArea(Identifier category, ButtonAreaSupplier rectangle); /** - * Removes the speed crafting button + * Removes the auto crafting button * * @param category the category of the button */ - default void removeSpeedCraftButton(Identifier category) { + default void removeAutoCraftButton(Identifier category) { registerAutoCraftButtonArea(category, bounds -> null); } - /** - * @param category the category of the button area - * @deprecated Not required anymore - */ - @Deprecated - void registerDefaultSpeedCraftButtonArea(Identifier category); - /** * Gets the map of all recipes visible to the player * @@ -222,3 +215,4 @@ public interface RecipeHelper { } } + diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index d33b38a67..e79890274 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -34,7 +34,6 @@ import net.minecraft.client.world.ClientWorld; import net.minecraft.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.sound.SoundEvents; -import net.minecraft.text.TranslatableText; import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -73,7 +72,7 @@ public class ContainerScreenOverlay extends Widget { MatrixStack matrixStack_1 = new MatrixStack(); VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer()); matrixStack_1.translate(0.0D, 0.0D, getBlitOffset()); - Matrix4f matrix4f_1 = matrixStack_1.method_23760().method_23761(); + Matrix4f matrix4f_1 = matrixStack_1.peek().getModel(); for (int lineIndex = 0; lineIndex < tooltipLines.size(); lineIndex++) { font.draw(tooltipLines.get(lineIndex), x, currentY, -1, true, matrix4f_1, immediate, false, 0, 15728880); currentY += lineIndex == 0 ? 12 : 10; @@ -100,6 +99,7 @@ public class ContainerScreenOverlay extends Widget { init(false); } + @SuppressWarnings("deprecation") public void init(boolean setPage) { this.shouldReInit = false; //Update Variables @@ -112,7 +112,7 @@ public class ContainerScreenOverlay extends Widget { entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false); if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) { - widgets.add(buttonLeft = new ButtonWidget(rectangle.x, rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16, new TranslatableText("text.rei.left_arrow")) { + widgets.add(buttonLeft = new ButtonWidget(new Rectangle(rectangle.x, rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), I18n.translate("text.rei.left_arrow")) { @Override public void onPressed() { page--; @@ -136,7 +136,7 @@ public class ContainerScreenOverlay extends Widget { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } }); - widgets.add(buttonRight = new ButtonWidget(rectangle.x + rectangle.width - 18, rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16, new TranslatableText("text.rei.right_arrow")) { + widgets.add(buttonRight = new ButtonWidget(new Rectangle(rectangle.x + rectangle.width - 18, rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), I18n.translate("text.rei.right_arrow")) { @Override public void onPressed() { page++; @@ -164,8 +164,8 @@ public class ContainerScreenOverlay extends Widget { if (setPage) page = MathHelper.clamp(page, 0, getTotalPage()); - - widgets.add(new ButtonWidget(ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20, "") { + + widgets.add(new ButtonWidget(new Rectangle(ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20), "") { @Override public void onPressed() { if (Screen.hasShiftDown()) { @@ -179,15 +179,16 @@ public class ContainerScreenOverlay extends Widget { public void render(int mouseX, int mouseY, float delta) { super.render(mouseX, mouseY, delta); GuiLighting.disable(); + Rectangle bounds = getBounds(); if (ClientHelper.getInstance().isCheating() && RoughlyEnoughItemsCore.hasOperatorPermission()) { if (RoughlyEnoughItemsCore.hasPermissionToUsePackets()) - fill(getBounds().x, getBounds().y, getBounds().x + 20, getBounds().y + 20, 721354752); + fill(bounds.x + 1, bounds.y+ 1, bounds.getMaxX() - 1, bounds.getMaxY() - 1, 721354752); else - fill(getBounds().x, getBounds().y, getBounds().x + 20, getBounds().y + 20, 1476440063); + fill(bounds.x+ 1, bounds.y+ 1, bounds.getMaxX() - 1, bounds.getMaxY() - 1, 1476440063); } MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - blit(getBounds().x + 3, getBounds().y + 3, 0, 0, 14, 14); + blit(bounds.x + 3, bounds.y + 3, 0, 0, 14, 14); } @Override @@ -216,7 +217,7 @@ public class ContainerScreenOverlay extends Widget { } }); if (ConfigManager.getInstance().getConfig().doesShowUtilsButtons()) { - widgets.add(new ButtonWidget(ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20, "") { + widgets.add(new ButtonWidget(new Rectangle(ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20), "") { @Override public void onPressed() { MinecraftClient.getInstance().player.sendChatMessage(ConfigManager.getInstance().getConfig().getGamemodeCommand().replaceAll("\\{gamemode}", getNextGameMode(Screen.hasShiftDown()).getName())); @@ -224,7 +225,7 @@ public class ContainerScreenOverlay extends Widget { @Override public void render(int mouseX, int mouseY, float delta) { - text = getGameModeShortText(getCurrentGameMode()); + setText(getGameModeShortText(getCurrentGameMode())); super.render(mouseX, mouseY, delta); } @@ -245,7 +246,7 @@ public class ContainerScreenOverlay extends Widget { }); int xxx = ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10; for (Weather weather : Weather.values()) { - widgets.add(new ButtonWidget(xxx, 35, 20, 20, "") { + widgets.add(new ButtonWidget(new Rectangle(xxx, 35, 20, 20), "") { @Override public void onPressed() { MinecraftClient.getInstance().player.sendChatMessage(ConfigManager.getInstance().getConfig().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT))); @@ -279,11 +280,11 @@ public class ContainerScreenOverlay extends Widget { } } if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) { - widgets.add(new ClickableLabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10, "", getTotalPage() > 0) { + widgets.add(new ClickableLabelWidget(new Point(rectangle.x + (rectangle.width / 2), rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10), "") { @Override public void render(int mouseX, int mouseY, float delta) { page = MathHelper.clamp(page, 0, getTotalPage()); - this.text = String.format("%s/%s", page + 1, getTotalPage() + 1); + setText(String.format("%s/%s", page + 1, getTotalPage() + 1)); super.render(mouseX, mouseY, delta); } @@ -303,11 +304,10 @@ public class ContainerScreenOverlay extends Widget { public boolean changeFocus(boolean boolean_1) { return false; } - }); + }.clickable(getTotalPage() > 0)); buttonLeft.enabled = buttonRight.enabled = getTotalPage() > 0; } if (ScreenHelper.getSearchField() == null) { - //noinspection deprecation ScreenHelper.setSearchField(new OverlaySearchField(0, 0, 0, 0)); } ScreenHelper.getSearchField().getBounds().setBounds(getTextFieldArea()); diff --git a/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java b/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java index 869b401b2..0535ae957 100644 --- a/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java +++ b/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java @@ -30,7 +30,7 @@ public class OverlaySearchField extends TextFieldWidget { public void laterRender(int int_1, int int_2, float float_1) { GuiLighting.disable(); RenderSystem.disableDepthTest(); - setEditableColor(ContainerScreenOverlay.getEntryListWidget().children().isEmpty() && !getText().isEmpty() ? 16733525 : isSearching ? -1313241 : 14737632); + setEditableColor(ContainerScreenOverlay.getEntryListWidget().children().isEmpty() && !getText().isEmpty() ? 16733525 : isSearching ? -852212 : 14737632); setSuggestion(!isFocused() && getText().isEmpty() ? I18n.translate("text.rei.search.field.suggestion") : null); super.render(int_1, int_2, float_1); RenderSystem.enableDepthTest(); @@ -41,7 +41,7 @@ public class OverlaySearchField extends TextFieldWidget { if (!isSearching) super.renderBorder(); else if (this.hasBorder()) { - fill(this.getBounds().x - 1, this.getBounds().y - 1, this.getBounds().x + this.getBounds().width + 1, this.getBounds().y + this.getBounds().height + 1, -1313241); + fill(this.getBounds().x - 1, this.getBounds().y - 1, this.getBounds().x + this.getBounds().width + 1, this.getBounds().y + this.getBounds().height + 1, -852212); fill(this.getBounds().x, this.getBounds().y, this.getBounds().x + this.getBounds().width, this.getBounds().y + this.getBounds().height, -16777216); } } diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index fda8ce246..e9226eea3 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -51,7 +51,7 @@ public class PreRecipeViewingScreen extends Screen { protected void init() { this.children.clear(); this.widgets.clear(); - this.widgets.add(new ButtonWidget(width / 2 - 100, height - 40, 200, 20, I18n.translate("text.rei.select")) { + this.widgets.add(new ButtonWidget(new Rectangle(width / 2 - 100, height - 40, 200, 20), I18n.translate("text.rei.select")) { @Override public void onPressed() { ConfigManager.getInstance().getConfig().setRecipeScreenType(original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER); diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 4e1e98700..8ff213334 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -7,6 +7,7 @@ package me.shedaniel.rei.gui; import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; +import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; @@ -22,7 +23,6 @@ import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.Window; import net.minecraft.sound.SoundEvents; import net.minecraft.text.LiteralText; -import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -129,7 +129,7 @@ public class RecipeViewingScreen extends Screen { this.page = MathHelper.clamp(page, 0, getTotalPages(selectedCategory) - 1); ButtonWidget w, w2; - this.widgets.add(w = new ButtonWidget(bounds.x + 2, bounds.y - 16, 10, 10, new TranslatableText("text.rei.left_arrow")) { + this.widgets.add(w = new ButtonWidget(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), I18n.translate("text.rei.left_arrow")) { @Override public void onPressed() { categoryPages--; @@ -138,7 +138,7 @@ public class RecipeViewingScreen extends Screen { RecipeViewingScreen.this.init(); } }); - this.widgets.add(w2 = new ButtonWidget(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10, new TranslatableText("text.rei.right_arrow")) { + this.widgets.add(w2 = new ButtonWidget(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), I18n.translate("text.rei.right_arrow")) { @Override public void onPressed() { categoryPages++; @@ -148,7 +148,7 @@ public class RecipeViewingScreen extends Screen { } }); w.enabled = w2.enabled = categories.size() > TABS_PER_PAGE; - widgets.add(categoryBack = new ButtonWidget(bounds.getX() + 5, bounds.getY() + 5, 12, 12, new TranslatableText("text.rei.left_arrow")) { + widgets.add(categoryBack = new ButtonWidget(new Rectangle(bounds.getX() + 5, bounds.getY() + 5, 12, 12), I18n.translate("text.rei.left_arrow")) { @Override public void onPressed() { int currentCategoryIndex = categories.indexOf(selectedCategory); @@ -166,10 +166,10 @@ public class RecipeViewingScreen extends Screen { return Optional.ofNullable(I18n.translate("text.rei.previous_category")); } }); - widgets.add(new ClickableLabelWidget(bounds.getCenterX(), bounds.getY() + 7, "") { + widgets.add(new ClickableLabelWidget(new Point(bounds.getCenterX(), bounds.getY() + 7), "") { @Override public void render(int mouseX, int mouseY, float delta) { - this.text = selectedCategory.getCategoryName(); + setText(selectedCategory.getCategoryName()); super.render(mouseX, mouseY, delta); } @@ -184,7 +184,7 @@ public class RecipeViewingScreen extends Screen { ClientHelper.getInstance().executeViewAllRecipesKeyBind(); } }); - widgets.add(categoryNext = new ButtonWidget(bounds.getMaxX() - 17, bounds.getY() + 5, 12, 12, new TranslatableText("text.rei.right_arrow")) { + widgets.add(categoryNext = new ButtonWidget(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 5, 12, 12), I18n.translate("text.rei.right_arrow")) { @Override public void onPressed() { int currentCategoryIndex = categories.indexOf(selectedCategory); @@ -205,7 +205,7 @@ public class RecipeViewingScreen extends Screen { categoryBack.enabled = categories.size() > 1; categoryNext.enabled = categories.size() > 1; - widgets.add(recipeBack = new ButtonWidget(bounds.getX() + 5, bounds.getY() + 21, 12, 12, new TranslatableText("text.rei.left_arrow")) { + widgets.add(recipeBack = new ButtonWidget(new Rectangle(bounds.getX() + 5, bounds.getY() + 21, 12, 12), I18n.translate("text.rei.left_arrow")) { @Override public void onPressed() { page--; @@ -219,10 +219,10 @@ public class RecipeViewingScreen extends Screen { return Optional.ofNullable(I18n.translate("text.rei.previous_page")); } }); - widgets.add(new ClickableLabelWidget(bounds.getCenterX(), bounds.getY() + 23, "", categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight()) { + widgets.add(new ClickableLabelWidget(new Point(bounds.getCenterX(), bounds.getY() + 23), "") { @Override public void render(int mouseX, int mouseY, float delta) { - this.text = String.format("%d/%d", page + 1, getTotalPages(selectedCategory)); + setText(String.format("%d/%d", page + 1, getTotalPages(selectedCategory))); super.render(mouseX, mouseY, delta); } @@ -237,8 +237,8 @@ public class RecipeViewingScreen extends Screen { RecipeViewingScreen.this.choosePageActivated = true; RecipeViewingScreen.this.init(); } - }); - widgets.add(recipeNext = new ButtonWidget(bounds.getMaxX() - 17, bounds.getY() + 21, 12, 12, new TranslatableText("text.rei.right_arrow")) { + }.clickable(categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight())); + widgets.add(recipeNext = new ButtonWidget(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 21, 12, 12), I18n.translate("text.rei.right_arrow")) { @Override public void onPressed() { page++; diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 2abae2b1f..b6579bab8 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -12,6 +12,7 @@ import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget.Interpolation; import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget.Precision; +import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.*; @@ -138,7 +139,7 @@ public class VillagerRecipeViewingScreen extends Screen { int finalIndex = index; RecipeEntry recipeEntry; recipeRenderers.add(recipeEntry = category.getSimpleRenderer(recipeDisplay)); - buttonWidgets.add(new ButtonWidget(bounds.x + 5, 0, recipeEntry.getWidth(), recipeEntry.getHeight(), "") { + buttonWidgets.add(new ButtonWidget(new Rectangle(bounds.x + 5, 0, recipeEntry.getWidth(), recipeEntry.getHeight()), "") { @Override public void onPressed() { selectedRecipeIndex = finalIndex; @@ -192,7 +193,7 @@ public class VillagerRecipeViewingScreen extends Screen { } } ButtonWidget w, w2; - this.widgets.add(w = new ButtonWidget(bounds.x + 2, bounds.y - 16, 10, 10, new TranslatableText("text.rei.left_arrow")) { + this.widgets.add(w = new ButtonWidget(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), new TranslatableText("text.rei.left_arrow")) { @Override public void onPressed() { tabsPage--; @@ -201,7 +202,7 @@ public class VillagerRecipeViewingScreen extends Screen { VillagerRecipeViewingScreen.this.init(); } }); - this.widgets.add(w2 = new ButtonWidget(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10, new TranslatableText("text.rei.right_arrow")) { + this.widgets.add(w2 = new ButtonWidget(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), new TranslatableText("text.rei.right_arrow")) { @Override public void onPressed() { tabsPage++; @@ -212,7 +213,7 @@ public class VillagerRecipeViewingScreen extends Screen { }); w.enabled = w2.enabled = categories.size() > TABS_PER_PAGE; - this.widgets.add(new ClickableLabelWidget(bounds.x + 4 + scrollListBounds.width / 2, bounds.y + 6, categories.get(selectedCategoryIndex).getCategoryName()) { + this.widgets.add(new ClickableLabelWidget(new Point(bounds.x + 4 + scrollListBounds.width / 2, bounds.y + 6), categories.get(selectedCategoryIndex).getCategoryName()) { @Override public void onLabelClicked() { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); @@ -382,7 +383,10 @@ public class VillagerRecipeViewingScreen extends Screen { height -= Math.min((scroll < 0 ? (int) -scroll : scroll > getMaxScroll() ? (int) scroll - getMaxScroll() : 0), height * .95); height = Math.max(10, height); int minY = (int) Math.min(Math.max((int) scroll * (scrollListBounds.height - 2 - height) / getMaxScroll() + scrollListBounds.y + 1, scrollListBounds.y + 1), scrollListBounds.getMaxY() - 1 - height); - double scrollbarPositionMinX = scrollListBounds.getMaxX() - 6, scrollbarPositionMaxX = scrollListBounds.getMaxX() - 2; + int scrollbarPositionMinX = scrollListBounds.getMaxX() - 6, scrollbarPositionMaxX = scrollListBounds.getMaxX() - 1; + boolean hovered = (new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height)).contains(PointHelper.fromMouse()); + float bottomC = (hovered ? .67f : .5f) * (ScreenHelper.isDarkModeEnabled() ? 0.8f : 1f); + float topC = (hovered ? .87f : .67f) * (ScreenHelper.isDarkModeEnabled() ? 0.8f : 1f); GuiLighting.disable(); RenderSystem.disableTexture(); RenderSystem.enableBlend(); @@ -390,11 +394,16 @@ public class VillagerRecipeViewingScreen extends Screen { RenderSystem.blendFuncSeparate(770, 771, 1, 0); RenderSystem.shadeModel(7425); buffer.begin(7, VertexFormats.POSITION_COLOR); - float b = ScreenHelper.isDarkModeEnabled() ? 0.37f : 1f; - buffer.vertex(scrollbarPositionMinX, minY + height, 800).color(b, b, b, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMaxX, minY + height, 800).color(b, b, b, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMaxX, minY, 800).color(b, b, b, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMinX, minY, 800).color(b, b, b, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMinX, minY + height, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMaxX, minY + height, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMaxX, minY, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMinX, minY, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); + tessellator.draw(); + buffer.begin(7, VertexFormats.POSITION_COLOR); + buffer.vertex(scrollbarPositionMinX, minY + height - 1, 800).color(topC, topC, topC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMaxX - 1, minY + height - 1, 800).color(topC, topC, topC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMaxX - 1, minY, 800).color(topC, topC, topC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMinX, minY, 800).color(topC, topC, topC, scrollBarAlpha).next(); tessellator.draw(); RenderSystem.shadeModel(7424); RenderSystem.disableBlend(); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java index 47e770f50..6853d0934 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java @@ -6,7 +6,6 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; -import com.mojang.blaze3d.systems.RenderSystem; import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; @@ -20,7 +19,6 @@ import net.minecraft.client.resource.language.I18n; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.Lazy; -import net.minecraft.util.math.MathHelper; import java.time.LocalDateTime; import java.util.List; @@ -127,27 +125,7 @@ public class AutoCraftingButtonWidget extends ButtonWidget { } } int x = getBounds().x, y = getBounds().y, width = getBounds().width, height = getBounds().height; - minecraft.getTextureManager().bindTexture(ScreenHelper.isDarkModeEnabled() ? BUTTON_LOCATION_DARK : BUTTON_LOCATION); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - int textureOffset = this.getTextureId(isHovered(mouseX, mouseY)); - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(770, 771, 1, 0); - RenderSystem.blendFunc(770, 771); - //Four Corners - blit(x, y, 0, textureOffset * 80, 4, 4); - blit(x + width - 4, y, 252, textureOffset * 80, 4, 4); - blit(x, y + height - 4, 0, textureOffset * 80 + 76, 4, 4); - blit(x + width - 4, y + height - 4, 252, textureOffset * 80 + 76, 4, 4); - - //Sides - blit(x + 4, y, 4, textureOffset * 80, MathHelper.ceil((width - 8) / 2f), 4); - blit(x + 4, y + height - 4, 4, textureOffset * 80 + 76, MathHelper.ceil((width - 8) / 2f), 4); - blit(x + 4 + MathHelper.ceil((width - 8) / 2f), y + height - 4, 252 - MathHelper.floor((width - 8) / 2f), textureOffset * 80 + 76, MathHelper.floor((width - 8) / 2f), 4); - blit(x + 4 + MathHelper.ceil((width - 8) / 2f), y, 252 - MathHelper.floor((width - 8) / 2f), textureOffset * 80, MathHelper.floor((width - 8) / 2f), 4); - for (int i = y + 4; i < y + height - 4; i += 76) { - blit(x, i, 0, 4 + textureOffset * 80, MathHelper.ceil(width / 2f), MathHelper.clamp(y + height - 4 - i, 0, 76)); - blit(x + MathHelper.ceil(width / 2f), i, 256 - MathHelper.floor(width / 2f), 4 + textureOffset * 80, MathHelper.floor(width / 2f), MathHelper.clamp(y + height - 4 - i, 0, 76)); - } + renderBackground(x, y, width, height, this.getTextureId(isHovered(mouseX, mouseY))); int colour = 14737632; if (!this.visible) { @@ -157,7 +135,7 @@ public class AutoCraftingButtonWidget extends ButtonWidget { } fillGradient(x, y, x + width, y + height, color, color); - this.drawCenteredString(font, text, x + width / 2, y + (height - 8) / 2, colour); + this.drawCenteredString(font, getText(), x + width / 2, y + (height - 8) / 2, colour); if (getTooltips().isPresent()) if (!focused && containsMouse(mouseX, mouseY)) @@ -168,7 +146,7 @@ public class AutoCraftingButtonWidget extends ButtonWidget { @Override protected int getTextureId(boolean boolean_1) { - return !visible ? 0 : boolean_1 && enabled ? 2 : 1; + return !visible ? 0 : boolean_1 && enabled ? (ConfigManager.getInstance().getConfig().isLighterButtonHover() ? 4 : 3) : 1; } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java index b22c8b479..e542ec26b 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java @@ -8,6 +8,7 @@ package me.shedaniel.rei.gui.widget; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; +import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.gui.Element; import net.minecraft.client.sound.PositionedSoundInstance; @@ -18,37 +19,38 @@ import net.minecraft.util.math.MathHelper; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; public abstract class ButtonWidget extends WidgetWithBounds { - public static final Identifier BUTTON_LOCATION = new Identifier("roughlyenoughitems", "textures/gui/button.png"); - public static final Identifier BUTTON_LOCATION_DARK = new Identifier("roughlyenoughitems", "textures/gui/button_dark.png"); - public String text; + protected static final Identifier BUTTON_LOCATION = new Identifier("roughlyenoughitems", "textures/gui/button.png"); + protected static final Identifier BUTTON_LOCATION_DARK = new Identifier("roughlyenoughitems", "textures/gui/button_dark.png"); public boolean enabled; public boolean focused; + private String text; private Rectangle bounds; public ButtonWidget(Rectangle rectangle, Text text) { - this(rectangle, text.asFormattedString()); + this(rectangle, Objects.requireNonNull(text).asFormattedString()); } public ButtonWidget(Rectangle rectangle, String text) { - this.bounds = rectangle; + this.bounds = Objects.requireNonNull(rectangle); this.enabled = true; - this.text = text; + this.text = Objects.requireNonNull(text); } - public ButtonWidget(int x, int y, int width, int height, String text) { - this(new Rectangle(x, y, width, height), text); + public Rectangle getBounds() { + return bounds; } - public ButtonWidget(int x, int y, int width, int height, Text text) { - this(new Rectangle(x, y, width, height), text); + public String getText() { + return text; } - public Rectangle getBounds() { - return bounds; + public void setText(String text) { + this.text = text; } protected int getTextureId(boolean boolean_1) { @@ -56,45 +58,48 @@ public abstract class ButtonWidget extends WidgetWithBounds { if (!this.enabled) { int_1 = 0; } else if (boolean_1) { - int_1 = 2; + int_1 = ConfigManager.getInstance().getConfig().isLighterButtonHover() ? 4 : 3; // 2 is the old blue highlight, 3 is the 1.15 outline, 4 is the 1.15 online + light hover } return int_1; } - @Override - public void render(int mouseX, int mouseY, float delta) { - int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height; + protected void renderBackground(int x, int y, int width, int height, int textureOffset) { minecraft.getTextureManager().bindTexture(ScreenHelper.isDarkModeEnabled() ? BUTTON_LOCATION_DARK : BUTTON_LOCATION); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - int textureOffset = this.getTextureId(isHovered(mouseX, mouseY)); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(770, 771, 1, 0); RenderSystem.blendFunc(770, 771); //Four Corners - blit(x, y, 0, textureOffset * 80, 4, 4); - blit(x + width - 4, y, 252, textureOffset * 80, 4, 4); - blit(x, y + height - 4, 0, textureOffset * 80 + 76, 4, 4); - blit(x + width - 4, y + height - 4, 252, textureOffset * 80 + 76, 4, 4); + blit(x, y, getBlitOffset(), 0, textureOffset * 80, 4, 4, 512, 256); + blit(x + width - 4, y, getBlitOffset(), 252, textureOffset * 80, 4, 4, 512, 256); + blit(x, y + height - 4, getBlitOffset(), 0, textureOffset * 80 + 76, 4, 4, 512, 256); + blit(x + width - 4, y + height - 4, getBlitOffset(), 252, textureOffset * 80 + 76, 4, 4, 512, 256); //Sides - blit(x + 4, y, 4, textureOffset * 80, MathHelper.ceil((width - 8) / 2f), 4); - blit(x + 4, y + height - 4, 4, textureOffset * 80 + 76, MathHelper.ceil((width - 8) / 2f), 4); - blit(x + 4 + MathHelper.ceil((width - 8) / 2f), y + height - 4, 252 - MathHelper.floor((width - 8) / 2f), textureOffset * 80 + 76, MathHelper.floor((width - 8) / 2f), 4); - blit(x + 4 + MathHelper.ceil((width - 8) / 2f), y, 252 - MathHelper.floor((width - 8) / 2f), textureOffset * 80, MathHelper.floor((width - 8) / 2f), 4); + blit(x + 4, y, getBlitOffset(), 4, textureOffset * 80, MathHelper.ceil((width - 8) / 2f), 4, 512, 256); + blit(x + 4, y + height - 4, getBlitOffset(), 4, textureOffset * 80 + 76, MathHelper.ceil((width - 8) / 2f), 4, 512, 256); + blit(x + 4 + MathHelper.ceil((width - 8) / 2f), y + height - 4, getBlitOffset(), 252 - MathHelper.floor((width - 8) / 2f), textureOffset * 80 + 76, MathHelper.floor((width - 8) / 2f), 4, 512, 256); + blit(x + 4 + MathHelper.ceil((width - 8) / 2f), y, getBlitOffset(), 252 - MathHelper.floor((width - 8) / 2f), textureOffset * 80, MathHelper.floor((width - 8) / 2f), 4, 512, 256); for (int i = y + 4; i < y + height - 4; i += 76) { - blit(x, i, 0, 4 + textureOffset * 80, MathHelper.ceil(width / 2f), MathHelper.clamp(y + height - 4 - i, 0, 76)); - blit(x + MathHelper.ceil(width / 2f), i, 256 - MathHelper.floor(width / 2f), 4 + textureOffset * 80, MathHelper.floor(width / 2f), MathHelper.clamp(y + height - 4 - i, 0, 76)); + blit(x, i, getBlitOffset(), 0, 4 + textureOffset * 80, MathHelper.ceil(width / 2f), MathHelper.clamp(y + height - 4 - i, 0, 76), 512, 256); + blit(x + MathHelper.ceil(width / 2f), i, getBlitOffset(), 256 - MathHelper.floor(width / 2f), 4 + textureOffset * 80, MathHelper.floor(width / 2f), MathHelper.clamp(y + height - 4 - i, 0, 76), 512, 256); } + } + + @Override + public void render(int mouseX, int mouseY, float delta) { + int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height; + renderBackground(x, y, width, height, this.getTextureId(isHovered(mouseX, mouseY))); - int colour = 14737632; + int color = 14737632; if (!this.enabled) { - colour = 10526880; + color = 10526880; } else if (isHovered(mouseX, mouseY)) { - colour = 16777120; + color = 16777120; } - this.drawCenteredString(font, text, x + width / 2, y + (height - 8) / 2, colour); + this.drawCenteredString(font, getText(), x + width / 2, y + (height - 8) / 2, color); if (getTooltips().isPresent()) if (!focused && containsMouse(mouseX, mouseY)) diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ClickableLabelWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ClickableLabelWidget.java index 14a6b9f83..697d78782 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ClickableLabelWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ClickableLabelWidget.java @@ -13,17 +13,28 @@ import java.util.Optional; public abstract class ClickableLabelWidget extends LabelWidget { public boolean focused; - public boolean clickable; - public int hoveredColor; + private boolean clickable = true; + private int hoveredColor; + @Deprecated public ClickableLabelWidget(int x, int y, String text, boolean clickable) { - super(x, y, text); - this.clickable = clickable; - this.hoveredColor = ScreenHelper.isDarkModeEnabled() ? -1 : 0xFF66FFCC; + this(new Point(x, y), text, clickable); } + @Deprecated public ClickableLabelWidget(int x, int y, String text) { - this(x, y, text, true); + this(new Point(x, y), text, true); + } + + @Deprecated + public ClickableLabelWidget(Point point, String text, boolean clickable) { + this(point, text); + clickable(clickable); + } + + public ClickableLabelWidget(Point point, String text) { + super(point, text); + this.hoveredColor = ScreenHelper.isDarkModeEnabled() ? -1 : 0xFF66FFCC; } public LabelWidget hoveredColor(int hoveredColor) { @@ -31,21 +42,31 @@ public abstract class ClickableLabelWidget extends LabelWidget { return this; } + public LabelWidget clickable(boolean clickable) { + this.clickable = clickable; + return this; + } + + public boolean isClickable() { + return clickable; + } + @Override public void render(int mouseX, int mouseY, float delta) { int color = getDefaultColor(); - if (clickable && isHovered(mouseX, mouseY)) + if (isClickable() && isHovered(mouseX, mouseY)) color = getHoveredColor(); - int width = font.getStringWidth(text); + Point pos = getPosition(); + int width = font.getStringWidth(getText()); if (isHasShadows()) - font.drawWithShadow(text, x - width / 2, y, color); + font.drawWithShadow(getText(), pos.x - width / 2, pos.y, color); else - font.draw(text, x - width / 2, y, color); - if (clickable && getTooltips().isPresent()) + font.draw(getText(), pos.x - width / 2, pos.y, color); + if (isClickable() && getTooltips().isPresent()) if (!focused && containsMouse(mouseX, mouseY)) ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(getTooltips().get().split("\n"))); else if (focused) - ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(new Point(x, y), getTooltips().get().split("\n"))); + ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(pos, getTooltips().get().split("\n"))); } public int getHoveredColor() { @@ -54,7 +75,7 @@ public abstract class ClickableLabelWidget extends LabelWidget { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (button == 0 && clickable && containsMouse(mouseX, mouseY)) { + if (button == 0 && isClickable() && containsMouse(mouseX, mouseY)) { onLabelClicked(); return true; } @@ -67,7 +88,7 @@ public abstract class ClickableLabelWidget extends LabelWidget { @Override public boolean keyPressed(int int_1, int int_2, int int_3) { - if (!clickable || !focused) + if (!isClickable() || !focused) return false; if (int_1 != 257 && int_1 != 32 && int_1 != 335) return false; @@ -77,14 +98,14 @@ public abstract class ClickableLabelWidget extends LabelWidget { @Override public boolean changeFocus(boolean boolean_1) { - if (!clickable) + if (!isClickable()) return false; this.focused = !this.focused; return true; } public boolean isHovered(int mouseX, int mouseY) { - return clickable && (containsMouse(mouseX, mouseY) || focused); + return isClickable() && (containsMouse(mouseX, mouseY) || focused); } public abstract void onLabelClicked(); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java index cc641f49e..be56a10ef 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java @@ -36,16 +36,16 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget { GuiLighting.disable(); super.render(mouseX, mouseY, delta); - // GuiLighting.enableForItems(); this.itemRenderer.zOffset = getBlitOffset(); - this.itemRenderer.renderGuiItem(new ItemStack(Blocks.CRAFTING_TABLE), getBounds().x + 2, getBounds().y + 2); + Rectangle bounds = getBounds(); + this.itemRenderer.renderGuiItem(new ItemStack(Blocks.CRAFTING_TABLE), bounds.x + 2, bounds.y + 2); this.itemRenderer.zOffset = 0.0F; GuiLighting.disable(); MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); int color = ConfigManager.getInstance().isCraftableOnlyEnabled() ? 939579655 : 956235776; setBlitOffset(getBlitOffset() + 10); - this.fillGradient(getBounds().x, getBounds().y, getBounds().x + getBounds().width, getBounds().y + getBounds().height, color, color); + this.fillGradient(bounds.x + 1, bounds.y + 1, bounds.getMaxX() - 1, bounds.getMaxY() - 1, color, color); setBlitOffset(0); } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java index 24ae350b8..bcf21bb75 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java @@ -313,7 +313,10 @@ public class EntryListWidget extends Widget { scrollBarHeight = MathHelper.clamp(scrollBarHeight, 32, rectangle.height - 8); scrollBarHeight = (int) ((double) scrollBarHeight - Math.min((double) (this.scroll < 0.0D ? (int) (-this.scroll) : (this.scroll > (double) this.getMaxScroll() ? (int) this.scroll - this.getMaxScroll() : 0)), (double) scrollBarHeight * 0.75D)); int minY = (int) Math.min(Math.max((int) this.getScroll() * (rectangle.height - scrollBarHeight) / maxScroll + rectangle.y, rectangle.y), rectangle.getMaxY() - scrollBarHeight); - double scrollbarPositionMinX = rectangle.getMaxX() - 6, scrollbarPositionMaxX = rectangle.getMaxX() - 1; + int scrollbarPositionMinX = rectangle.getMaxX() - 5, scrollbarPositionMaxX = rectangle.getMaxX(); + boolean hovered = (new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, scrollBarHeight)).contains(PointHelper.fromMouse()); + float bottomC = (hovered ? .67f : .5f) * (ScreenHelper.isDarkModeEnabled() ? 0.8f : 1f); + float topC = (hovered ? .87f : .67f) * (ScreenHelper.isDarkModeEnabled() ? 0.8f : 1f); GuiLighting.disable(); RenderSystem.disableTexture(); RenderSystem.enableBlend(); @@ -321,11 +324,16 @@ public class EntryListWidget extends Widget { RenderSystem.blendFuncSeparate(770, 771, 1, 0); RenderSystem.shadeModel(7425); buffer.begin(7, VertexFormats.POSITION_COLOR); - float b = ScreenHelper.isDarkModeEnabled() ? 0.8f : 1f; - buffer.vertex(scrollbarPositionMinX, minY + scrollBarHeight, 1000D).color(b, b, b, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMaxX, minY + scrollBarHeight, 1000D).color(b, b, b, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMaxX, minY, 1000D).color(b, b, b, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMinX, minY, 1000D).color(b, b, b, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMinX, minY + scrollBarHeight, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMaxX, minY + scrollBarHeight, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMaxX, minY, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMinX, minY, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); + tessellator.draw(); + buffer.begin(7, VertexFormats.POSITION_COLOR); + buffer.vertex(scrollbarPositionMinX, minY + scrollBarHeight - 1, 800).color(topC, topC, topC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMaxX - 1, minY + scrollBarHeight - 1, 800).color(topC, topC, topC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMaxX - 1, minY, 800).color(topC, topC, topC, scrollBarAlpha).next(); + buffer.vertex(scrollbarPositionMinX, minY, 800).color(topC, topC, topC, scrollBarAlpha).next(); tessellator.draw(); RenderSystem.shadeModel(7424); RenderSystem.disableBlend(); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java index 7392b257a..6edb9b004 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/LabelWidget.java @@ -5,6 +5,7 @@ package me.shedaniel.rei.gui.widget; +import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.gui.Element; @@ -14,19 +15,36 @@ import java.util.List; public class LabelWidget extends WidgetWithBounds { - public int x; - public int y; - public String text; + private Point pos; + private String text; private int defaultColor; private boolean hasShadows = true; + private boolean centered = true; + @Deprecated public LabelWidget(int x, int y, String text) { - this.x = x; - this.y = y; + this(new Point(x, y), text); + } + + public LabelWidget(Point point, String text) { + this.pos = point; this.text = text; this.defaultColor = ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : -1; } + public boolean isCentered() { + return centered; + } + + public void setCentered(boolean centered) { + this.centered = centered; + } + + public LabelWidget centered() { + setCentered(true); + return this; + } + public boolean isHasShadows() { return hasShadows; } @@ -35,6 +53,11 @@ public class LabelWidget extends WidgetWithBounds { this.hasShadows = hasShadows; } + public LabelWidget noShadow() { + setHasShadows(false); + return this; + } + public int getDefaultColor() { return defaultColor; } @@ -43,6 +66,24 @@ public class LabelWidget extends WidgetWithBounds { this.defaultColor = defaultColor; } + public Point getPosition() { + return pos; + } + + public LabelWidget setPosition(Point position) { + this.pos = position; + return this; + } + + public String getText() { + return text; + } + + public LabelWidget setText(String text) { + this.text = text; + return this; + } + public LabelWidget color(int defaultColor) { this.defaultColor = defaultColor; return this; @@ -51,7 +92,8 @@ public class LabelWidget extends WidgetWithBounds { @Override public Rectangle getBounds() { int width = font.getStringWidth(text); - return new Rectangle(x - width / 2 - 1, y - 5, width + 2, 14); + Point pos = getPosition(); + return new Rectangle(pos.x - width / 2 - 1, pos.y - 5, width + 2, 14); } @Override @@ -62,9 +104,10 @@ public class LabelWidget extends WidgetWithBounds { @Override public void render(int mouseX, int mouseY, float delta) { int width = font.getStringWidth(text); + Point pos = getPosition(); if (hasShadows) - font.drawWithShadow(text, x - width / 2, y, defaultColor); - else font.draw(text, x - width / 2, y, defaultColor); + font.drawWithShadow(text, pos.x - width / 2, pos.y, defaultColor); + else font.draw(text, pos.x - width / 2, pos.y, defaultColor); } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java index 7d9ea24de..1dd78ddf9 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java @@ -116,7 +116,7 @@ public class RecipeChoosePageWidget extends DraggableWidget { return stringBuilder_1.toString(); }; textFieldWidget.setText(String.valueOf(currentPage + 1)); - widgets.add(btnDone = new ButtonWidget(bounds.x + bounds.width - 45, bounds.y + bounds.height + 3, 40, 20, I18n.translate("gui.done")) { + widgets.add(btnDone = new ButtonWidget(new Rectangle(bounds.x + bounds.width - 45, bounds.y + bounds.height + 3, 40, 20), I18n.translate("gui.done")) { @Override public void onPressed() { recipeViewingScreen.page = MathHelper.clamp(getIntFromString(textFieldWidget.getText()).orElse(0) - 1, 0, recipeViewingScreen.getTotalPages(recipeViewingScreen.getSelectedCategory()) - 1); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java index b823a6030..fe07f23c6 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java @@ -9,6 +9,8 @@ import com.google.common.base.Predicates; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.math.api.Rectangle; +import me.shedaniel.math.impl.PointHelper; +import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.SharedConstants; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.render.BufferBuilder; @@ -387,7 +389,10 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { public void renderBorder() { if (this.hasBorder()) { - fill(this.bounds.x - 1, this.bounds.y - 1, this.bounds.x + this.bounds.width + 1, this.bounds.y + this.bounds.height + 1, -6250336); + if (containsMouse(PointHelper.fromMouse()) || focused) + fill(this.bounds.x - 1, this.bounds.y - 1, this.bounds.x + this.bounds.width + 1, this.bounds.y + this.bounds.height + 1, ScreenHelper.isDarkModeEnabled() ? 0xffffbb4d : -1); + else + fill(this.bounds.x - 1, this.bounds.y - 1, this.bounds.x + this.bounds.width + 1, this.bounds.y + this.bounds.height + 1, -6250336); fill(this.bounds.x, this.bounds.y, this.bounds.x + this.bounds.width, this.bounds.y + this.bounds.height, -16777216); } } diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java index 37da90e2a..212284db9 100644 --- a/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java @@ -46,7 +46,7 @@ public class ConfigManagerImpl implements ConfigManager { configFile.getParentFile().mkdirs(); if (!configFile.exists() && !configFile.createNewFile()) { RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config."); - config = new ConfigObjectImpl(); + config = new OldConfigObjectImpl(); return; } try { @@ -54,7 +54,7 @@ public class ConfigManagerImpl implements ConfigManager { } catch (Exception e) { e.printStackTrace(); RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config."); - config = new ConfigObjectImpl(); + config = new OldConfigObjectImpl(); return; } } @@ -64,13 +64,13 @@ public class ConfigManagerImpl implements ConfigManager { configFile.getParentFile().mkdirs(); if (!configFile.exists() || !configFile.canRead()) { RoughlyEnoughItemsCore.LOGGER.warn("[REI] Config not found! Creating one."); - config = new ConfigObjectImpl(); + config = new OldConfigObjectImpl(); saveConfig(); return; } boolean failed = false; try { - config = new ConfigObjectImpl(); + config = new OldConfigObjectImpl(); new JanksonSettings().deserialize(config.getConfigNode(), Files.newInputStream(configFile.toPath())); } catch (Exception e) { e.printStackTrace(); @@ -78,7 +78,7 @@ public class ConfigManagerImpl implements ConfigManager { } if (failed || config == null) { RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to load config! Overwriting with default config."); - config = new ConfigObjectImpl(); + config = new OldConfigObjectImpl(); } saveConfig(); } diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java deleted file mode 100644 index 345f647fc..000000000 --- a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.impl; - -import me.shedaniel.rei.api.ConfigObject; -import me.shedaniel.rei.api.annotations.Internal; -import me.shedaniel.rei.gui.config.*; -import me.zeroeightsix.fiber.exception.FiberException; -import me.zeroeightsix.fiber.tree.ConfigNode; -import me.zeroeightsix.fiber.tree.ConfigValue; -import me.zeroeightsix.fiber.tree.Node; - -@Deprecated -@Internal -public class ConfigObjectImpl implements ConfigObject { - - public ConfigNode configNode = new ConfigNode(); - - private Node general = configNode.fork("!general"); - private Node appearance = configNode.fork("appearance"); - private Node modules = configNode.fork("modules"); - private Node technical = configNode.fork("technical"); - - private ConfigValue cheating = ConfigValue.builder(Boolean.class) - .withParent(general) - .withDefaultValue(false) - .withComment("Declares whether cheating mode is on.") - .withName("cheating") - .build(); - - private ConfigValue itemListOrdering = ConfigValue.builder(ItemListOrderingConfig.class) - .withParent(appearance) - .withDefaultValue(ItemListOrderingConfig.REGISTRY_ASCENDING) - .withComment("The