From 9ba262a47d743a636fd142931345ca58a3ddff3c Mon Sep 17 00:00:00 2001 From: Arborsm Date: Thu, 4 Apr 2024 22:45:58 +0800 Subject: [PATCH 1/5] remake GTRecipeWidget add oc button --- .../resources/assets/gtceu/lang/en_ud.json | 6 +- .../resources/assets/gtceu/lang/en_us.json | 6 +- .../gtceu/api/recipe/ui/GTRecipeTypeUI.java | 5 +- .../gtceu/data/lang/LangHandler.java | 4 +- .../gtceu/integration/GTRecipeWidget.java | 284 ++++++++++++------ .../resources/assets/gtceu/lang/zh_cn.json | 2 +- 6 files changed, 216 insertions(+), 91 deletions(-) diff --git a/src/generated/resources/assets/gtceu/lang/en_ud.json b/src/generated/resources/assets/gtceu/lang/en_ud.json index 2e17c375f5..f13a4f74cc 100644 --- a/src/generated/resources/assets/gtceu/lang/en_ud.json +++ b/src/generated/resources/assets/gtceu/lang/en_ud.json @@ -3139,6 +3139,10 @@ "gtceu.multiblock.validation_failed": "˙sʇndʇno/sʇnduı ɟo ʇunoɯɐ pıןɐʌuI", "gtceu.multiblock.waiting": "˙buıʇıɐʍ sı ǝuıɥɔɐW :⅁NINᴚⱯM", "gtceu.multiblock.work_paused": "˙pǝsnɐԀ ʞɹoM", + "gtceu.oc.tooltip.0": "%s :uıW", + "gtceu.oc.tooltip.1": "ƆO ǝɥʇ ǝsıɐɹ oʇ ʞɔıןɔ ʇɟǝꞀ", + "gtceu.oc.tooltip.2": "ƆO ǝɥʇ ɹǝʍoן oʇ ʞɔıןɔ ʇɥbıᴚ", + "gtceu.oc.tooltip.3": "ƆO ǝɥʇ ʇǝsǝɹ oʇ ʞɔıןɔ ǝןppıW", "gtceu.ore_washer": "ɹǝɥsɐM ǝɹO", "gtceu.packer": "ɹǝʞɔɐԀ", "gtceu.parallel_hatch_mk5": "˙ןǝןןɐɹɐd uı sǝdıɔǝɹ ㄣ oʇ dn unɹ oʇ sʍoןןⱯ", @@ -3156,7 +3160,7 @@ "gtceu.recipe.cleanroom_sterile.display_name": "ɯooɹuɐǝןƆ ǝןıɹǝʇS", "gtceu.recipe.dimensions": "%s :suoısuǝɯıᗡ", "gtceu.recipe.duration": "sɔǝs ɟᄅ˙'% :uoıʇɐɹnᗡ", - "gtceu.recipe.eu": ")ɹ§%s( ʇ/∩Ǝ p'% :ǝbɐs∩", + "gtceu.recipe.eu": "ʇ/∩Ǝ p'% :ǝbɐs∩", "gtceu.recipe.eu_inverted": "ʇ/∩Ǝ p'% :uoıʇɐɹǝuǝ⅁", "gtceu.recipe.eu_to_start": "∩Ǝ%s :ʇɹɐʇS o⟘ ʎbɹǝuƎ", "gtceu.recipe.explosive": "%s :ǝʌısoןdxƎ", diff --git a/src/generated/resources/assets/gtceu/lang/en_us.json b/src/generated/resources/assets/gtceu/lang/en_us.json index c0ad16f1e2..74fb6da3a6 100644 --- a/src/generated/resources/assets/gtceu/lang/en_us.json +++ b/src/generated/resources/assets/gtceu/lang/en_us.json @@ -3139,6 +3139,10 @@ "gtceu.multiblock.validation_failed": "Invalid amount of inputs/outputs.", "gtceu.multiblock.waiting": "WARNING: Machine is waiting.", "gtceu.multiblock.work_paused": "Work Paused.", + "gtceu.oc.tooltip.0": "Min: %s", + "gtceu.oc.tooltip.1": "Left click to increase the OC", + "gtceu.oc.tooltip.2": "Right click to reduce the OC", + "gtceu.oc.tooltip.3": "Middle click to reset the OC", "gtceu.ore_washer": "Ore Washer", "gtceu.packer": "Packer", "gtceu.parallel_hatch_mk5": "Allows to run up to 4 recipes in parallel.", @@ -3156,7 +3160,7 @@ "gtceu.recipe.cleanroom_sterile.display_name": "Sterile Cleanroom", "gtceu.recipe.dimensions": "Dimensions: %s", "gtceu.recipe.duration": "Duration: %,.2f secs", - "gtceu.recipe.eu": "Usage: %,d EU/t (%s§r)", + "gtceu.recipe.eu": "Usage: %,d EU/t", "gtceu.recipe.eu_inverted": "Generation: %,d EU/t", "gtceu.recipe.eu_to_start": "Energy To Start: %sEU", "gtceu.recipe.explosive": "Explosive: %s", diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java index 1dff7c929f..d5bf841a01 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/ui/GTRecipeTypeUI.java @@ -78,6 +78,8 @@ public class GTRecipeTypeUI { private CompoundTag customUICache; private Size jeiSize; + @Getter + private int originalWidth; /** * @param recipeType the recipemap corresponding to this ui @@ -128,7 +130,8 @@ public Size getJEISize() { Size size = this.jeiSize; if(size == null) { var originalSize = createEditableUITemplate(false, false).createDefault().getSize(); - this.jeiSize = size = new Size(originalSize.width, getPropertyHeightShift() + 5 + originalSize.height); + this.originalWidth = originalSize.width; + this.jeiSize = size = new Size(Math.max(originalWidth, 150), getPropertyHeightShift() + 5 + originalSize.height); } return size; } diff --git a/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java b/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java index 983e09acbd..c1340986bf 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java @@ -48,6 +48,8 @@ public static void init(RegistrateLangProvider provider) { provider.add("recipe.capability.fluid.name", "Fluid"); provider.add("recipe.capability.item.name", "Item"); provider.add("recipe.capability.su.name", "Create Stress"); + multiLang(provider, "gtceu.oc.tooltip", "Min: %s", + "Left click to increase the OC", "Right click to reduce the OC", "Middle click to reset the OC"); provider.add("recipe.condition.rpm.tooltip", "RPM: %d"); provider.add("recipe.condition.thunder.tooltip", "Thunder Level: %d"); @@ -927,7 +929,7 @@ public static void init(RegistrateLangProvider provider) { provider.add("gtceu.universal.tooltip.requires_redstone", "§4Requires Redstone power"); provider.add("gtceu.universal.tooltip.deprecated", "§5WARNING: DEPRECATED. WILL BE REMOVED IN A FUTURE VERSION.§r"); provider.add("gtceu.recipe.total", "Total: %,d EU"); - provider.add("gtceu.recipe.eu", "Usage: %,d EU/t (%s§r)"); + provider.add("gtceu.recipe.eu", "Usage: %,d EU/t"); provider.add("gtceu.recipe.eu_inverted", "Generation: %,d EU/t"); provider.add("gtceu.recipe.duration", "Duration: %,.2f secs"); provider.add("gtceu.recipe.amperage", "Amperage: %,d"); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java index 393aaea773..7df1d91a18 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java @@ -7,32 +7,34 @@ import com.gregtechceu.gtceu.api.gui.GuiTextures; import com.gregtechceu.gtceu.api.gui.WidgetUtils; import com.gregtechceu.gtceu.api.gui.widget.PredicatedButtonWidget; -import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget; import com.gregtechceu.gtceu.api.recipe.GTRecipe; +import com.gregtechceu.gtceu.api.recipe.OverclockingLogic; import com.gregtechceu.gtceu.api.recipe.RecipeCondition; import com.gregtechceu.gtceu.api.recipe.RecipeHelper; import com.gregtechceu.gtceu.api.recipe.content.Content; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; +import com.gregtechceu.gtceu.common.data.GTRecipeTypes; import com.gregtechceu.gtceu.utils.CycleFluidStorage; import com.gregtechceu.gtceu.utils.FormattingUtil; -import com.gregtechceu.gtceu.utils.GTUtil; +import com.lowdragmc.lowdraglib.LDLib; import com.lowdragmc.lowdraglib.gui.compass.CompassManager; import com.lowdragmc.lowdraglib.gui.texture.GuiTextureGroup; -import com.lowdragmc.lowdraglib.gui.texture.ResourceBorderTexture; import com.lowdragmc.lowdraglib.gui.texture.TextTexture; import com.lowdragmc.lowdraglib.gui.widget.*; -import com.lowdragmc.lowdraglib.misc.FluidStorage; import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidStorage; import com.lowdragmc.lowdraglib.utils.CycleItemStackHandler; import com.lowdragmc.lowdraglib.utils.LocalizationUtils; -import com.lowdragmc.lowdraglib.utils.Position; +import it.unimi.dsi.fastutil.longs.LongIntPair; +import lombok.Getter; +import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; +import org.jetbrains.annotations.NotNull; +import org.lwjgl.glfw.GLFW; import java.util.ArrayList; import java.util.Arrays; @@ -41,64 +43,92 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.gregtechceu.gtceu.api.GTValues.*; +import static com.gregtechceu.gtceu.api.GTValues.IV; + /** * @author KilaBash * @date 2023/2/25 * @implNote GTRecipeWidget */ public class GTRecipeWidget extends WidgetGroup { + private final int xOffset; + private final GTRecipe recipe; + private final List recipeParaTexts = new ArrayList<>(); + @Getter + private int tier; + @Getter + private int yOffset; + private LabelWidget voltageTextWidget; + public GTRecipeWidget(GTRecipe recipe) { - super(0, 0, recipe.recipeType.getRecipeUI().getJEISize().width, recipe.recipeType.getRecipeUI().getJEISize().height); + super(getXOffSet(recipe), 0, recipe.recipeType.getRecipeUI().getJEISize().width, recipe.recipeType.getRecipeUI().getJEISize().height); + this.recipe = recipe; + this.xOffset = getXOffSet(recipe); + setRecipeWidget(); + setTierToMin(); + initializeRecipeTextWidget(); + addButtons(); + } + + private static int getXOffSet(GTRecipe recipe) { + if (recipe.recipeType.getRecipeUI().getOriginalWidth() != recipe.recipeType.getRecipeUI().getJEISize().width) { + return (recipe.recipeType.getRecipeUI().getJEISize().width - recipe.recipeType.getRecipeUI().getOriginalWidth()) / 2; + } + return 0; + } + + private void setRecipeWidget() { setClientSideWidget(); List inputStackContents = new ArrayList<>(); inputStackContents.addAll(recipe.getInputContents(ItemRecipeCapability.CAP)); inputStackContents.addAll(recipe.getTickInputContents(ItemRecipeCapability.CAP)); List> inputStacks = inputStackContents.stream().map(content -> content.content) - .map(ItemRecipeCapability.CAP::of) - .map(Ingredient::getItems) - .map(Arrays::stream) - .map(Stream::toList) - .collect(Collectors.toList()); + .map(ItemRecipeCapability.CAP::of) + .map(Ingredient::getItems) + .map(Arrays::stream) + .map(Stream::toList) + .collect(Collectors.toList()); while (inputStacks.size() < recipe.recipeType.getMaxInputs(ItemRecipeCapability.CAP)) inputStacks.add(null); List outputStackContents = new ArrayList<>(); outputStackContents.addAll(recipe.getOutputContents(ItemRecipeCapability.CAP)); outputStackContents.addAll(recipe.getTickOutputContents(ItemRecipeCapability.CAP)); List> outputStacks = outputStackContents.stream().map(content -> content.content) - .map(ItemRecipeCapability.CAP::of) - .map(Ingredient::getItems) - .map(Arrays::stream) - .map(Stream::toList) - .collect(Collectors.toList()); + .map(ItemRecipeCapability.CAP::of) + .map(Ingredient::getItems) + .map(Arrays::stream) + .map(Stream::toList) + .collect(Collectors.toList()); while (outputStacks.size() < recipe.recipeType.getMaxOutputs(ItemRecipeCapability.CAP)) outputStacks.add(null); List inputFluidContents = new ArrayList<>(); inputFluidContents.addAll(recipe.getInputContents(FluidRecipeCapability.CAP)); inputFluidContents.addAll(recipe.getTickInputContents(FluidRecipeCapability.CAP)); List> inputFluids = inputFluidContents.stream().map(content -> content.content) - .map(FluidRecipeCapability.CAP::of) - .map(FluidIngredient::getStacks) - .map(Arrays::stream) - .map(Stream::toList) - .collect(Collectors.toList()); + .map(FluidRecipeCapability.CAP::of) + .map(FluidIngredient::getStacks) + .map(Arrays::stream) + .map(Stream::toList) + .collect(Collectors.toList()); while (inputFluids.size() < recipe.recipeType.getMaxInputs(FluidRecipeCapability.CAP)) inputFluids.add(null); List outputFluidContents = new ArrayList<>(); outputFluidContents.addAll(recipe.getOutputContents(FluidRecipeCapability.CAP)); outputFluidContents.addAll(recipe.getTickOutputContents(FluidRecipeCapability.CAP)); List> outputFluids = outputFluidContents.stream().map(content -> content.content) - .map(FluidRecipeCapability.CAP::of) - .map(FluidIngredient::getStacks) - .map(Arrays::stream) - .map(Stream::toList) - .collect(Collectors.toList()); + .map(FluidRecipeCapability.CAP::of) + .map(FluidIngredient::getStacks) + .map(Arrays::stream) + .map(Stream::toList) + .collect(Collectors.toList()); while (outputFluids.size() < recipe.recipeType.getMaxOutputs(FluidRecipeCapability.CAP)) outputFluids.add(null); WidgetGroup group = recipe.recipeType.getRecipeUI().createUITemplate(ProgressWidget.JEIProgress, - new CycleItemStackHandler(inputStacks), - new CycleItemStackHandler(outputStacks), - new CycleFluidStorage(inputFluids), - new CycleFluidStorage(outputFluids) + new CycleItemStackHandler(inputStacks), + new CycleItemStackHandler(outputStacks), + new CycleFluidStorage(inputFluids), + new CycleFluidStorage(outputFluids) ); // bind item in overlay WidgetUtils.widgetByIdForEach(group, "^%s_[0-9]+$".formatted(ItemRecipeCapability.CAP.slotName(IO.IN)), SlotWidget.class, slot -> { @@ -108,15 +138,7 @@ public GTRecipeWidget(GTRecipe recipe) { slot.setXEIChance(content.chance); slot.setOverlay(content.createOverlay(index >= recipe.getInputContents(ItemRecipeCapability.CAP).size())); slot.setOnAddedTooltips((w, tooltips) -> { - var chance = content.chance; - if (chance < 1) { - tooltips.add(chance == 0 ? - Component.translatable("gtceu.gui.content.chance_0") : - FormattingUtil.formatPercentage2Places("gtceu.gui.content.chance_1", chance * 100)); - if (content.tierChanceBoost > 0) { - tooltips.add(FormattingUtil.formatPercentage2Places("gtceu.gui.content.tier_boost", content.tierChanceBoost * 100)); - } - } + setConsumedChance(content, tooltips); if (index >= recipe.getInputContents(ItemRecipeCapability.CAP).size()) { tooltips.add(Component.translatable("gtceu.gui.content.per_tick")); } @@ -131,15 +153,7 @@ public GTRecipeWidget(GTRecipe recipe) { slot.setXEIChance(content.chance); slot.setOverlay(content.createOverlay(index >= recipe.getOutputContents(ItemRecipeCapability.CAP).size())); slot.setOnAddedTooltips((w, tooltips) -> { - var chance = content.chance; - if (chance < 1) { - tooltips.add(chance == 0 ? - Component.translatable("gtceu.gui.content.chance_0") : - FormattingUtil.formatPercentage2Places("gtceu.gui.content.chance_1", chance * 100)); - if (content.tierChanceBoost > 0) { - tooltips.add(FormattingUtil.formatPercentage2Places("gtceu.gui.content.tier_boost", content.tierChanceBoost * 100)); - } - } + setConsumedChance(content, tooltips); if (index >= recipe.getOutputContents(ItemRecipeCapability.CAP).size()) { tooltips.add(Component.translatable("gtceu.gui.content.per_tick")); } @@ -154,15 +168,7 @@ public GTRecipeWidget(GTRecipe recipe) { tank.setXEIChance(content.chance); tank.setOverlay(content.createOverlay(index >= recipe.getInputContents(FluidRecipeCapability.CAP).size())); tank.setOnAddedTooltips((w, tooltips) -> { - var chance = content.chance; - if (chance < 1) { - tooltips.add(chance == 0 ? - Component.translatable("gtceu.gui.content.chance_0") : - FormattingUtil.formatPercentage2Places("gtceu.gui.content.chance_1", chance * 100)); - if (content.tierChanceBoost > 0) { - tooltips.add(FormattingUtil.formatPercentage2Places("gtceu.gui.content.tier_boost", content.tierChanceBoost * 100)); - } - } + setConsumedChance(content, tooltips); if (index >= recipe.getInputContents(FluidRecipeCapability.CAP).size()) { tooltips.add(Component.translatable("gtceu.gui.content.per_tick")); } @@ -177,15 +183,7 @@ public GTRecipeWidget(GTRecipe recipe) { tank.setXEIChance(content.chance); tank.setOverlay(content.createOverlay(index >= recipe.getOutputContents(FluidRecipeCapability.CAP).size())); tank.setOnAddedTooltips((w, tooltips) -> { - var chance = content.chance; - if (chance < 1) { - tooltips.add(chance == 0 ? - Component.translatable("gtceu.gui.content.chance_0") : - FormattingUtil.formatPercentage2Places("gtceu.gui.content.chance_1", chance * 100)); - if (content.tierChanceBoost > 0) { - tooltips.add(FormattingUtil.formatPercentage2Places("gtceu.gui.content.tier_boost", content.tierChanceBoost * 100)); - } - } + setConsumedChance(content, tooltips); if (index >= recipe.getOutputContents(FluidRecipeCapability.CAP).size()) { tooltips.add(Component.translatable("gtceu.gui.content.per_tick")); } @@ -194,34 +192,148 @@ public GTRecipeWidget(GTRecipe recipe) { }); var size = group.getSize(); addWidget(group); - - int yOffset = 5 + size.height; - addWidget(new LabelWidget(3, yOffset, - LocalizationUtils.format("gtceu.recipe.duration", recipe.duration / 20f))); var EUt = RecipeHelper.getInputEUt(recipe); - boolean isOutput = false; if (EUt == 0) { EUt = RecipeHelper.getOutputEUt(recipe); - isOutput = true; - } - if (EUt > 0) { - addWidget(new LabelWidget(3, yOffset += 10, - LocalizationUtils.format(!isOutput ? "gtceu.recipe.eu" : "gtceu.recipe.eu_inverted", EUt, GTValues.VN[GTUtil.getTierByVoltage(EUt)]))); - addWidget(new LabelWidget(3, yOffset += 10, - LocalizationUtils.format("gtceu.recipe.total", EUt * recipe.duration))); } + int yOffset = 5 + size.height; + this.yOffset = yOffset; + yOffset += EUt > 0 ? 20 : 0; for (RecipeCondition condition : recipe.conditions) { if (condition.getTooltips() == null) continue; - addWidget(new LabelWidget(3, yOffset += 10, condition.getTooltips().getString())); + addWidget(new LabelWidget(3 - xOffset, yOffset += 10, condition.getTooltips().getString())); } for (Function dataInfo : recipe.recipeType.getDataInfos()) { - addWidget(new LabelWidget(3, yOffset += 10, dataInfo.apply(recipe.data))); + addWidget(new LabelWidget(3 - xOffset, yOffset += 10, dataInfo.apply(recipe.data))); } recipe.recipeType.getRecipeUI().appendJEIUI(recipe, this); + } + + private void initializeRecipeTextWidget() { + String tierText = GTValues.VNF[tier]; + int textsY = yOffset - 10; + int duration = recipe.duration; + long inputEUt = RecipeHelper.getInputEUt(recipe); + long outputEUt = RecipeHelper.getOutputEUt(recipe); + List texts = getRecipeParaText(duration, inputEUt, outputEUt); + for (Component text : texts) { + textsY += 10; + LabelWidget labelWidget = new LabelWidget(3 - xOffset, textsY, text).setTextColor(-1).setDropShadow(true); + addWidget(labelWidget); + recipeParaTexts.add(labelWidget); + } + if (inputEUt != 0) { + LabelWidget voltageTextWidget = new LabelWidget(getVoltageXOffset() - xOffset, getSize().height - 10, tierText).setTextColor(-1).setDropShadow(false); + if (recipe.recipeType == GTRecipeTypes.FUSION_RECIPES || recipe.recipeType == GTRecipeTypes.GAS_COLLECTOR_RECIPES) { + voltageTextWidget.setSelfPositionY(getSize().height - 20); + } + // make it clickable + // voltageTextWidget.setBackground(new GuiTextureGroup(GuiTextures.BUTTON)); + addWidget(new ButtonWidget(voltageTextWidget.getPositionX(), voltageTextWidget.getPositionY(), + voltageTextWidget.getSizeWidth(), voltageTextWidget.getSizeHeight(), cd -> setRecipeOC(cd.button)) + .setHoverTooltips( + Component.translatable("gtceu.oc.tooltip.0", GTValues.VNF[getMinTier()]), + Component.translatable("gtceu.oc.tooltip.1"), + Component.translatable("gtceu.oc.tooltip.2"), + Component.translatable("gtceu.oc.tooltip.3") + )); + addWidget(this.voltageTextWidget = voltageTextWidget); + } + } + + @NotNull + private static List getRecipeParaText(int duration, long inputEUt, long outputEUt) { + List texts = new ArrayList<>(); + texts.add(Component.literal(LocalizationUtils.format("gtceu.recipe.duration", duration / 20f))); + if (inputEUt != 0) { + texts.add(Component.literal(LocalizationUtils.format("gtceu.recipe.eu", inputEUt))); + texts.add(Component.literal(LocalizationUtils.format("gtceu.recipe.total", (inputEUt * duration)))); + } + if (outputEUt != 0) { + texts.add(Component.literal(LocalizationUtils.format("gtceu.recipe.eu_inverted", outputEUt))); + texts.add(Component.literal(LocalizationUtils.format("gtceu.recipe.total", (outputEUt * duration)))); + } + return texts; + } + + private void addButtons() { + // add a recipe id getter, btw all the things can only click within the WidgetGroup while using EMI + int x = getSize().width + 3 - this.xOffset, y = 3; + if (LDLib.isEmiLoaded()) { + x = getSize().width - xOffset - 18; + y = getSize().height - 30; + } + addWidget(new PredicatedButtonWidget(x, y, 15, 15, new GuiTextureGroup(GuiTextures.BUTTON, new TextTexture("ID")), cd -> + Minecraft.getInstance().keyboardHandler.setClipboard(recipe.id.toString()), () -> CompassManager.INSTANCE.devMode, CompassManager.INSTANCE.devMode).setHoverTooltips("click to copy: " + recipe.id)); + } + + private int getVoltageXOffset() { + int x = getSize().width - switch (tier) { + case ULV, LuV, ZPM, UHV, UEV, UXV -> 20; + case OpV, MAX -> 22; + case UIV -> 18; + case IV -> 12; + default -> 14; + }; + if (!LDLib.isEmiLoaded()) { + x -= 3; + } + return x; + } + + public void setRecipeOC(int button) { + if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { + setTier(tier + 1); + } else if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { + setTier(tier - 1); + } else if (button == GLFW.GLFW_MOUSE_BUTTON_MIDDLE) { + setTierToMin(); + } + setRecipeTextWidget(); + } + + private void setRecipeTextWidget() { + long inputEUt = RecipeHelper.getInputEUt(recipe); + int duration = recipe.duration; + String tierText = GTValues.VNF[tier]; + if (tier > getMinTier() && inputEUt != 0) { + LongIntPair pair = OverclockingLogic.NON_PERFECT_OVERCLOCK.getLogic().runOverclockingLogic( + recipe, inputEUt, GTValues.V[tier], duration, GTValues.MAX); + duration = pair.rightInt(); + inputEUt = pair.firstLong(); + tierText = tierText.formatted(ChatFormatting.ITALIC); + } + List texts = getRecipeParaText(duration, inputEUt, 0); + for (int i = 0; i < texts.size(); i++) { + recipeParaTexts.get(i).setComponent(texts.get(i)); + } + voltageTextWidget.setText(tierText); + voltageTextWidget.setSelfPositionX(getVoltageXOffset() - xOffset); + detectAndSendChanges(); + updateScreen(); + } + + private void setConsumedChance(Content content, List tooltips) { + var chance = content.chance; + if (chance < 1) { + tooltips.add(chance == 0 ? + Component.translatable("gtceu.gui.content.chance_0") : + FormattingUtil.formatPercentage2Places("gtceu.gui.content.chance_1", chance * 100)); + if (content.tierChanceBoost != 0) { + tooltips.add(FormattingUtil.formatPercentage2Places("gtceu.gui.content.tier_boost", content.tierChanceBoost * 100)); + } + } + } + + private int getMinTier() { + return RecipeHelper.getRecipeEUtTier(recipe); + } + + private void setTier(int tier) { + this.tier = Mth.clamp(tier, getMinTier(), GTValues.MAX); + } - // add recipe id getter - addWidget(new PredicatedButtonWidget(getSize().width + 3,3, 15, 15, new GuiTextureGroup(GuiTextures.BUTTON, new TextTexture("ID")), cd -> { - Minecraft.getInstance().keyboardHandler.setClipboard(recipe.id.toString()); - }, () -> CompassManager.INSTANCE.devMode).setHoverTooltips("click to copy: " + recipe.id)); + private void setTierToMin() { + setTier(getMinTier()); } } diff --git a/src/main/resources/assets/gtceu/lang/zh_cn.json b/src/main/resources/assets/gtceu/lang/zh_cn.json index 2cf0851feb..a0eb683541 100644 --- a/src/main/resources/assets/gtceu/lang/zh_cn.json +++ b/src/main/resources/assets/gtceu/lang/zh_cn.json @@ -3128,7 +3128,7 @@ "gtceu.recipe.cleanroom_sterile.display_name":"无菌超净间", "gtceu.recipe.dimensions":"维度:%s", "gtceu.recipe.duration":"耗时:%,.2f秒", - "gtceu.recipe.eu":"耗能功率:%,d EU/t (%s)", + "gtceu.recipe.eu":"耗能功率:%,d EU/t", "gtceu.recipe.eu_inverted":"产能功率:%,d EU/t", "gtceu.recipe.eu_to_start":"启动耗能:%s EU", "gtceu.recipe.explosive":"爆炸物:%s", From fa1dc499c9b246a2dd07006d1e7e013745dfa003 Mon Sep 17 00:00:00 2001 From: Arborsm Date: Thu, 4 Apr 2024 22:58:13 +0800 Subject: [PATCH 2/5] update lang --- src/generated/resources/assets/gtceu/lang/en_us.json | 2 +- .../java/com/gregtechceu/gtceu/data/lang/LangHandler.java | 2 +- src/main/resources/assets/gtceu/lang/zh_cn.json | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/generated/resources/assets/gtceu/lang/en_us.json b/src/generated/resources/assets/gtceu/lang/en_us.json index 74fb6da3a6..1142c43378 100644 --- a/src/generated/resources/assets/gtceu/lang/en_us.json +++ b/src/generated/resources/assets/gtceu/lang/en_us.json @@ -3141,7 +3141,7 @@ "gtceu.multiblock.work_paused": "Work Paused.", "gtceu.oc.tooltip.0": "Min: %s", "gtceu.oc.tooltip.1": "Left click to increase the OC", - "gtceu.oc.tooltip.2": "Right click to reduce the OC", + "gtceu.oc.tooltip.2": "Right click to decrease the OC", "gtceu.oc.tooltip.3": "Middle click to reset the OC", "gtceu.ore_washer": "Ore Washer", "gtceu.packer": "Packer", diff --git a/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java b/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java index c1340986bf..2790ddae98 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java @@ -49,7 +49,7 @@ public static void init(RegistrateLangProvider provider) { provider.add("recipe.capability.item.name", "Item"); provider.add("recipe.capability.su.name", "Create Stress"); multiLang(provider, "gtceu.oc.tooltip", "Min: %s", - "Left click to increase the OC", "Right click to reduce the OC", "Middle click to reset the OC"); + "Left click to increase the OC", "Right click to decrease the OC", "Middle click to reset the OC"); provider.add("recipe.condition.rpm.tooltip", "RPM: %d"); provider.add("recipe.condition.thunder.tooltip", "Thunder Level: %d"); diff --git a/src/main/resources/assets/gtceu/lang/zh_cn.json b/src/main/resources/assets/gtceu/lang/zh_cn.json index a0eb683541..4573776824 100644 --- a/src/main/resources/assets/gtceu/lang/zh_cn.json +++ b/src/main/resources/assets/gtceu/lang/zh_cn.json @@ -3111,6 +3111,10 @@ "gtceu.multiblock.validation_failed":"输入仓/输出仓数量无效。", "gtceu.multiblock.waiting":"警告:机器待机", "gtceu.multiblock.work_paused":"暂停。", + "gtceu.oc.tooltip.0": "最低 : %s", + "gtceu.oc.tooltip.1": "左键以增加超频等级", + "gtceu.oc.tooltip.2": "右键以降低超频等级", + "gtceu.oc.tooltip.3": "中键以重置超频等级", "gtceu.ore_washer":"洗矿厂", "gtceu.packer":"打包机", "gtceu.parallel_hatch_mk5":"允许并行运行最多4个配方", From ea8085e72c221516e4dc16c8244ca76957981e81 Mon Sep 17 00:00:00 2001 From: Arborsm Date: Fri, 5 Apr 2024 02:02:42 +0800 Subject: [PATCH 3/5] delete hardcode --- .../resources/assets/gtceu/lang/en_us.json | 1 + .../gtceu/api/recipe/GTRecipeType.java | 7 +++++- .../gtceu/common/data/GTRecipeTypes.java | 2 ++ .../gtceu/data/lang/LangHandler.java | 4 ++-- .../gtceu/integration/GTRecipeWidget.java | 22 +++++++++++-------- .../MultiblockInfoDisplayCategory.java | 4 ++-- .../resources/assets/gtceu/lang/zh_cn.json | 1 + 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/generated/resources/assets/gtceu/lang/en_us.json b/src/generated/resources/assets/gtceu/lang/en_us.json index 1142c43378..599f04e46a 100644 --- a/src/generated/resources/assets/gtceu/lang/en_us.json +++ b/src/generated/resources/assets/gtceu/lang/en_us.json @@ -3143,6 +3143,7 @@ "gtceu.oc.tooltip.1": "Left click to increase the OC", "gtceu.oc.tooltip.2": "Right click to decrease the OC", "gtceu.oc.tooltip.3": "Middle click to reset the OC", + "gtceu.oc.tooltip.4": "Hold Shift to change by Perfect OC", "gtceu.ore_washer": "Ore Washer", "gtceu.packer": "Packer", "gtceu.parallel_hatch_mk5": "Allows to run up to 4 recipes in parallel.", diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java index 8bff94332a..bc87f6714f 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java @@ -40,7 +40,6 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import java.util.stream.Collectors; /** * @author KilaBash @@ -84,6 +83,12 @@ public class GTRecipeType implements RecipeType { private CompoundTag customUICache; @Getter private final GTRecipeLookup lookup = new GTRecipeLookup(this); + @Setter + @Getter + private boolean upwardVoltageText = false; + @Setter + @Getter + private int upwardVoltageTextHeight = 20; public GTRecipeType(ResourceLocation registryName, String group, RecipeType... proxyRecipes) { this.registryName = registryName; diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java index b1384f2f5a..f482f9f229 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java @@ -367,6 +367,7 @@ public class GTRecipeTypes { .setSlotOverlay(true, true, GuiTextures.CENTRIFUGE_OVERLAY) .setProgressBar(GuiTextures.PROGRESS_BAR_GAS_COLLECTOR, LEFT_TO_RIGHT) .setMaxTooltips(4) + .setUpwardVoltageText(true) .setSound(GTSoundEntries.COOLING); public final static GTRecipeType ROCK_BREAKER_RECIPES = register("rock_breaker", ELECTRIC).setMaxIOSize(1, 4, 0, 0).setEUIO(IO.IN) @@ -561,6 +562,7 @@ public class GTRecipeTypes { public static final GTRecipeType FUSION_RECIPES = register("fusion_reactor", MULTIBLOCK).setMaxIOSize(0, 0, 2, 1).setEUIO(IO.IN) .setProgressBar(GuiTextures.PROGRESS_BAR_FUSION, LEFT_TO_RIGHT) .setSound(GTSoundEntries.ARC) + .setUpwardVoltageText(true) .addDataInfo(data -> LocalizationUtils.format("gtceu.recipe.eu_to_start", data.getLong("eu_to_start"))); public static final GTRecipeType DUMMY_RECIPES = new GTRecipeType(GTCEu.id("dummy"), DUMMY); diff --git a/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java b/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java index 2790ddae98..9fe597e437 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java @@ -48,8 +48,8 @@ public static void init(RegistrateLangProvider provider) { provider.add("recipe.capability.fluid.name", "Fluid"); provider.add("recipe.capability.item.name", "Item"); provider.add("recipe.capability.su.name", "Create Stress"); - multiLang(provider, "gtceu.oc.tooltip", "Min: %s", - "Left click to increase the OC", "Right click to decrease the OC", "Middle click to reset the OC"); + multiLang(provider, "gtceu.oc.tooltip", "Min: %s", "Left click to increase the OC", + "Right click to decrease the OC", "Middle click to reset the OC", "Hold Shift to change by Perfect OC"); provider.add("recipe.condition.rpm.tooltip", "RPM: %d"); provider.add("recipe.condition.thunder.tooltip", "Thunder Level: %d"); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java index 7df1d91a18..ac3d6996d2 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java @@ -13,7 +13,6 @@ import com.gregtechceu.gtceu.api.recipe.RecipeHelper; import com.gregtechceu.gtceu.api.recipe.content.Content; import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; -import com.gregtechceu.gtceu.common.data.GTRecipeTypes; import com.gregtechceu.gtceu.utils.CycleFluidStorage; import com.gregtechceu.gtceu.utils.FormattingUtil; import com.lowdragmc.lowdraglib.LDLib; @@ -224,18 +223,19 @@ private void initializeRecipeTextWidget() { } if (inputEUt != 0) { LabelWidget voltageTextWidget = new LabelWidget(getVoltageXOffset() - xOffset, getSize().height - 10, tierText).setTextColor(-1).setDropShadow(false); - if (recipe.recipeType == GTRecipeTypes.FUSION_RECIPES || recipe.recipeType == GTRecipeTypes.GAS_COLLECTOR_RECIPES) { - voltageTextWidget.setSelfPositionY(getSize().height - 20); + if (recipe.recipeType.isUpwardVoltageText()) { + voltageTextWidget.setSelfPositionY(getSize().height - recipe.recipeType.getUpwardVoltageTextHeight()); } // make it clickable // voltageTextWidget.setBackground(new GuiTextureGroup(GuiTextures.BUTTON)); addWidget(new ButtonWidget(voltageTextWidget.getPositionX(), voltageTextWidget.getPositionY(), - voltageTextWidget.getSizeWidth(), voltageTextWidget.getSizeHeight(), cd -> setRecipeOC(cd.button)) + voltageTextWidget.getSizeWidth(), voltageTextWidget.getSizeHeight(), cd -> setRecipeOC(cd.button, cd.isShiftClick)) .setHoverTooltips( Component.translatable("gtceu.oc.tooltip.0", GTValues.VNF[getMinTier()]), Component.translatable("gtceu.oc.tooltip.1"), Component.translatable("gtceu.oc.tooltip.2"), - Component.translatable("gtceu.oc.tooltip.3") + Component.translatable("gtceu.oc.tooltip.3"), + Component.translatable("gtceu.oc.tooltip.4") )); addWidget(this.voltageTextWidget = voltageTextWidget); } @@ -281,7 +281,8 @@ private int getVoltageXOffset() { return x; } - public void setRecipeOC(int button) { + public void setRecipeOC(int button, boolean isShiftClick) { + OverclockingLogic oc = OverclockingLogic.NON_PERFECT_OVERCLOCK; if (button == GLFW.GLFW_MOUSE_BUTTON_LEFT) { setTier(tier + 1); } else if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { @@ -289,15 +290,18 @@ public void setRecipeOC(int button) { } else if (button == GLFW.GLFW_MOUSE_BUTTON_MIDDLE) { setTierToMin(); } - setRecipeTextWidget(); + if (isShiftClick) { + oc = OverclockingLogic.PERFECT_OVERCLOCK; + } + setRecipeTextWidget(oc); } - private void setRecipeTextWidget() { + private void setRecipeTextWidget(OverclockingLogic logic) { long inputEUt = RecipeHelper.getInputEUt(recipe); int duration = recipe.duration; String tierText = GTValues.VNF[tier]; if (tier > getMinTier() && inputEUt != 0) { - LongIntPair pair = OverclockingLogic.NON_PERFECT_OVERCLOCK.getLogic().runOverclockingLogic( + LongIntPair pair = logic.getLogic().runOverclockingLogic( recipe, inputEUt, GTValues.V[tier], duration, GTValues.MAX); duration = pair.rightInt(); inputEUt = pair.firstLong(); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/rei/multipage/MultiblockInfoDisplayCategory.java b/src/main/java/com/gregtechceu/gtceu/integration/rei/multipage/MultiblockInfoDisplayCategory.java index bb8b03379a..9578efde83 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/rei/multipage/MultiblockInfoDisplayCategory.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/rei/multipage/MultiblockInfoDisplayCategory.java @@ -41,12 +41,12 @@ public static void registerWorkStations(CategoryRegistry registry) { @Override public int getDisplayHeight() { - return 176 + 8; + return 160 + 8; } @Override public int getDisplayWidth(MultiblockInfoDisplay display) { - return 176 + 8; + return 160 + 8; } @Override diff --git a/src/main/resources/assets/gtceu/lang/zh_cn.json b/src/main/resources/assets/gtceu/lang/zh_cn.json index 4573776824..5210a6cd02 100644 --- a/src/main/resources/assets/gtceu/lang/zh_cn.json +++ b/src/main/resources/assets/gtceu/lang/zh_cn.json @@ -3115,6 +3115,7 @@ "gtceu.oc.tooltip.1": "左键以增加超频等级", "gtceu.oc.tooltip.2": "右键以降低超频等级", "gtceu.oc.tooltip.3": "中键以重置超频等级", + "gtceu.oc.tooltip.4": "按住Shift以完美超频进行调整", "gtceu.ore_washer":"洗矿厂", "gtceu.packer":"打包机", "gtceu.parallel_hatch_mk5":"允许并行运行最多4个配方", From ac42ef9d90b76c60ecc936db73707787bdb41a10 Mon Sep 17 00:00:00 2001 From: Arborsm Date: Fri, 5 Apr 2024 02:13:10 +0800 Subject: [PATCH 4/5] update zh_cn --- src/main/resources/assets/gtceu/lang/zh_cn.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/assets/gtceu/lang/zh_cn.json b/src/main/resources/assets/gtceu/lang/zh_cn.json index 5210a6cd02..2f27fe654d 100644 --- a/src/main/resources/assets/gtceu/lang/zh_cn.json +++ b/src/main/resources/assets/gtceu/lang/zh_cn.json @@ -3112,10 +3112,10 @@ "gtceu.multiblock.waiting":"警告:机器待机", "gtceu.multiblock.work_paused":"暂停。", "gtceu.oc.tooltip.0": "最低 : %s", - "gtceu.oc.tooltip.1": "左键以增加超频等级", - "gtceu.oc.tooltip.2": "右键以降低超频等级", - "gtceu.oc.tooltip.3": "中键以重置超频等级", - "gtceu.oc.tooltip.4": "按住Shift以完美超频进行调整", + "gtceu.oc.tooltip.1": "左键以增加电压等级", + "gtceu.oc.tooltip.2": "右键以降低电压等级", + "gtceu.oc.tooltip.3": "中键以重置电压等级", + "gtceu.oc.tooltip.4": "按住Shift以无损超频进行调整", "gtceu.ore_washer":"洗矿厂", "gtceu.packer":"打包机", "gtceu.parallel_hatch_mk5":"允许并行运行最多4个配方", From f05a21a12a5afe61176e3584addcf8ca901c61cb Mon Sep 17 00:00:00 2001 From: Arborsm Date: Fri, 5 Apr 2024 03:03:34 +0800 Subject: [PATCH 5/5] change name --- .../java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java | 4 ++-- .../java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java | 4 ++-- .../com/gregtechceu/gtceu/integration/GTRecipeWidget.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java index bc87f6714f..cca21ea14e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipeType.java @@ -85,10 +85,10 @@ public class GTRecipeType implements RecipeType { private final GTRecipeLookup lookup = new GTRecipeLookup(this); @Setter @Getter - private boolean upwardVoltageText = false; + private boolean offsetVoltageText = false; @Setter @Getter - private int upwardVoltageTextHeight = 20; + private int voltageTextOffset = 20; public GTRecipeType(ResourceLocation registryName, String group, RecipeType... proxyRecipes) { this.registryName = registryName; diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java index f482f9f229..d56156d377 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTRecipeTypes.java @@ -367,7 +367,7 @@ public class GTRecipeTypes { .setSlotOverlay(true, true, GuiTextures.CENTRIFUGE_OVERLAY) .setProgressBar(GuiTextures.PROGRESS_BAR_GAS_COLLECTOR, LEFT_TO_RIGHT) .setMaxTooltips(4) - .setUpwardVoltageText(true) + .setOffsetVoltageText(true) .setSound(GTSoundEntries.COOLING); public final static GTRecipeType ROCK_BREAKER_RECIPES = register("rock_breaker", ELECTRIC).setMaxIOSize(1, 4, 0, 0).setEUIO(IO.IN) @@ -562,7 +562,7 @@ public class GTRecipeTypes { public static final GTRecipeType FUSION_RECIPES = register("fusion_reactor", MULTIBLOCK).setMaxIOSize(0, 0, 2, 1).setEUIO(IO.IN) .setProgressBar(GuiTextures.PROGRESS_BAR_FUSION, LEFT_TO_RIGHT) .setSound(GTSoundEntries.ARC) - .setUpwardVoltageText(true) + .setOffsetVoltageText(true) .addDataInfo(data -> LocalizationUtils.format("gtceu.recipe.eu_to_start", data.getLong("eu_to_start"))); public static final GTRecipeType DUMMY_RECIPES = new GTRecipeType(GTCEu.id("dummy"), DUMMY); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java b/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java index ac3d6996d2..2b43d57160 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java @@ -223,8 +223,8 @@ private void initializeRecipeTextWidget() { } if (inputEUt != 0) { LabelWidget voltageTextWidget = new LabelWidget(getVoltageXOffset() - xOffset, getSize().height - 10, tierText).setTextColor(-1).setDropShadow(false); - if (recipe.recipeType.isUpwardVoltageText()) { - voltageTextWidget.setSelfPositionY(getSize().height - recipe.recipeType.getUpwardVoltageTextHeight()); + if (recipe.recipeType.isOffsetVoltageText()) { + voltageTextWidget.setSelfPositionY(getSize().height - recipe.recipeType.getVoltageTextOffset()); } // make it clickable // voltageTextWidget.setBackground(new GuiTextureGroup(GuiTextures.BUTTON));