From bbb9bf73d218e74970f3c31e316a07011cefddaa Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Mon, 9 Sep 2024 21:59:03 -0500 Subject: [PATCH 01/17] Work on moving all the strings in our GUIs to supporting scrolling when out of range --- .../client/gui/GuiBioGenerator.java | 2 +- .../client/gui/GuiFissionReactor.java | 8 +- .../gui/GuiFissionReactorLogicAdapter.java | 4 +- .../gui/GuiFusionReactorController.java | 2 +- .../client/gui/GuiFusionReactorFuel.java | 4 +- .../gui/GuiFusionReactorLogicAdapter.java | 6 +- .../client/gui/GuiFusionReactorStats.java | 4 +- .../client/gui/GuiGasGenerator.java | 7 +- .../client/gui/GuiHeatGenerator.java | 2 +- .../client/gui/GuiIndustrialTurbine.java | 2 +- .../client/gui/GuiSolarGenerator.java | 2 +- .../client/gui/GuiTurbineStats.java | 18 +- .../client/gui/GuiWindGenerator.java | 2 +- .../element/button/ReactorLogicButton.java | 10 +- .../emi/recipe/FissionReactorEmiRecipe.java | 2 +- .../jei/FissionReactorRecipeCategory.java | 2 +- .../mekanism/client/gui/GuiBoilerStats.java | 12 +- .../mekanism/client/gui/GuiChemicalTank.java | 2 +- .../client/gui/GuiDimensionalStabilizer.java | 4 +- .../mekanism/client/gui/GuiDynamicTank.java | 4 +- .../mekanism/client/gui/GuiEnergyCube.java | 2 +- .../mekanism/client/gui/GuiFilterHolder.java | 16 +- .../mekanism/client/gui/GuiFluidTank.java | 2 +- .../client/gui/GuiInductionMatrix.java | 4 +- .../client/gui/GuiLaserAmplifier.java | 2 +- .../client/gui/GuiLaserTractorBeam.java | 2 +- .../client/gui/GuiLogisticalSorter.java | 16 +- .../mekanism/client/gui/GuiMatrixStats.java | 18 +- .../java/mekanism/client/gui/GuiMekanism.java | 32 ++- .../client/gui/GuiModificationStation.java | 2 +- .../client/gui/GuiPersonalStorageTile.java | 2 +- .../client/gui/GuiQuantumEntangloporter.java | 2 +- src/main/java/mekanism/client/gui/GuiSPS.java | 2 +- .../mekanism/client/gui/GuiSecurityDesk.java | 13 +- .../mekanism/client/gui/GuiTeleporter.java | 2 +- .../gui/GuiThermalEvaporationController.java | 4 +- .../client/gui/GuiThermoelectricBoiler.java | 2 +- .../java/mekanism/client/gui/GuiUtils.java | 4 - .../java/mekanism/client/gui/IGuiWrapper.java | 15 +- .../client/gui/element/GuiArrowSelection.java | 3 +- .../client/gui/element/GuiDigitalSwitch.java | 4 +- .../client/gui/element/GuiDropdown.java | 5 +- .../client/gui/element/GuiElement.java | 20 +- .../client/gui/element/GuiInnerScreen.java | 38 ++- .../client/gui/element/GuiScreenSwitch.java | 13 +- .../gui/element/button/FilterButton.java | 16 +- .../client/gui/element/button/GuiGasMode.java | 2 +- .../gui/element/button/SideDataButton.java | 2 +- .../element/custom/GuiFrequencySelector.java | 21 +- .../custom/GuiQIOFrequencyDataScreen.java | 10 +- .../gui/element/custom/GuiResizeControls.java | 6 +- .../element/custom/module/BooleanToggle.java | 13 +- .../element/custom/module/ColorSelection.java | 7 +- .../gui/element/custom/module/EnumToggle.java | 40 +-- .../custom/module/GuiModuleScreen.java | 11 +- .../element/scroll/GuiModuleScrollList.java | 12 +- .../gui/element/scroll/GuiSlotScroll.java | 62 ++--- .../gui/element/scroll/GuiTextScrollList.java | 4 +- .../element/scroll/GuiUpgradeScrollList.java | 9 +- .../client/gui/element/text/GuiTextField.java | 7 +- .../gui/element/window/GuiColorWindow.java | 2 +- .../element/window/GuiConfirmationDialog.java | 4 +- .../window/GuiMekaSuitHelmetOptions.java | 12 +- .../element/window/GuiSideConfiguration.java | 14 +- .../element/window/GuiTransporterConfig.java | 4 +- .../gui/element/window/GuiUpgradeWindow.java | 17 +- .../client/gui/element/window/GuiWindow.java | 10 +- .../gui/element/window/filter/GuiFilter.java | 5 +- .../window/filter/GuiFilterHelper.java | 2 + .../filter/GuiOredictionificatorFilter.java | 2 +- .../filter/qio/GuiQIOItemStackFilter.java | 2 +- .../transporter/GuiSorterFilterHelper.java | 15 +- .../transporter/GuiSorterItemStackFilter.java | 2 +- .../client/gui/item/GuiDictionary.java | 6 +- .../gui/item/GuiPersonalStorageItem.java | 2 +- .../client/gui/item/GuiSeismicReader.java | 8 +- .../machine/GuiAdvancedElectricMachine.java | 2 +- .../GuiAntiprotonicNucleosynthesizer.java | 4 +- .../gui/machine/GuiChemicalInfuser.java | 10 +- .../gui/machine/GuiChemicalOxidizer.java | 2 +- .../client/gui/machine/GuiCombiner.java | 2 +- .../client/gui/machine/GuiDigitalMiner.java | 4 +- .../gui/machine/GuiDigitalMinerConfig.java | 17 +- .../gui/machine/GuiElectricMachine.java | 2 +- .../client/gui/machine/GuiElectricPump.java | 4 +- .../client/gui/machine/GuiFactory.java | 2 +- .../gui/machine/GuiFluidicPlenisher.java | 4 +- .../machine/GuiFormulaicAssemblicator.java | 2 +- .../client/gui/machine/GuiFuelwoodHeater.java | 2 +- .../gui/machine/GuiIsotopicCentrifuge.java | 2 +- .../gui/machine/GuiMetallurgicInfuser.java | 2 +- .../gui/machine/GuiNutritionalLiquifier.java | 2 +- .../gui/machine/GuiOredictionificator.java | 2 +- .../mekanism/client/gui/machine/GuiPRC.java | 10 +- .../gui/machine/GuiPaintingMachine.java | 2 +- .../gui/machine/GuiPigmentExtractor.java | 2 +- .../client/gui/machine/GuiPigmentMixer.java | 10 +- .../gui/machine/GuiPrecisionSawmill.java | 2 +- .../gui/machine/GuiResistiveHeater.java | 2 +- .../gui/machine/GuiRotaryCondensentrator.java | 4 +- .../gui/machine/GuiSeismicVibrator.java | 2 +- .../gui/machine/GuiSolarNeutronActivator.java | 2 +- .../client/gui/qio/GuiQIODriveArray.java | 2 +- .../client/gui/qio/GuiQIOFilterHandler.java | 2 +- .../gui/qio/GuiQIOItemFrequencySelect.java | 9 +- .../client/gui/qio/GuiQIOItemViewer.java | 9 +- .../client/gui/qio/GuiQIORedstoneAdapter.java | 2 +- .../gui/qio/GuiQIOTileFrequencySelect.java | 9 +- .../client/gui/robit/GuiRobitCrafting.java | 4 +- .../client/gui/robit/GuiRobitInventory.java | 4 +- .../client/gui/robit/GuiRobitMain.java | 3 +- .../client/gui/robit/GuiRobitRepair.java | 16 +- .../client/gui/robit/GuiRobitSmelting.java | 4 +- .../emi/recipe/FluidToFluidEmiRecipe.java | 2 +- .../emi/recipe/MekanismEmiRecipe.java | 2 +- .../recipe_viewer/jei/BaseRecipeCategory.java | 2 +- .../machine/FluidToFluidRecipeCategory.java | 2 +- .../jei/machine/SawmillRecipeCategory.java | 11 +- .../client/render/IFancyFontRenderer.java | 241 +++++++++++------- .../lookingat/LookingAtElement.java | 33 +-- .../lookingat/jade/JadeTooltipRenderer.java | 16 +- .../lookingat/wthit/WTHITTooltipRenderer.java | 11 +- .../common/util/UnitDisplayUtils.java | 46 +++- .../resources/META-INF/accesstransformer.cfg | 3 + 124 files changed, 655 insertions(+), 532 deletions(-) diff --git a/src/generators/java/mekanism/generators/client/gui/GuiBioGenerator.java b/src/generators/java/mekanism/generators/client/gui/GuiBioGenerator.java index fe8c2d3f24d..79c82a7a375 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiBioGenerator.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiBioGenerator.java @@ -47,7 +47,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFissionReactor.java b/src/generators/java/mekanism/generators/client/gui/GuiFissionReactor.java index 91c63be0a98..c977f55d6f6 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFissionReactor.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFissionReactor.java @@ -66,7 +66,7 @@ protected void addGuiElements() { MekanismLang.TEMPERATURE.translate(tile.getTempColor(), MekanismUtils.getTemperatureDisplay(multiblock.heatCapacitor.getTemperature(), TemperatureUnit.KELVIN, true)), GeneratorsLang.FISSION_DAMAGE.translate(tile.getDamageColor(), tile.getDamageString()) ); - }).spacing(2).recipeViewerCategories(GeneratorsRVRecipeType.FISSION)); + }).spacing(1).recipeViewerCategories(GeneratorsRVRecipeType.FISSION)); addRenderableWidget(new GuiMergedTankGauge<>(() -> tile.getMultiblock().coolantTank, tile::getMultiblock, GaugeType.STANDARD, this, 6, 13) .setLabel(GeneratorsLang.FISSION_COOLANT_TANK.translateColored(EnumColor.AQUA))); addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().fuelTank, () -> tile.getMultiblock().getChemicalTanks((Direction) null), GaugeType.STANDARD, this, 25, 13) @@ -133,9 +133,9 @@ private void updateButtons() { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { updateButtons(); renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); - drawString(guiGraphics, MekanismLang.TEMPERATURE_LONG.translate(""), 6, 93, titleTextColor()); - drawString(guiGraphics, GeneratorsLang.FISSION_HEAT_GRAPH.translate(), 6, 114, titleTextColor()); + renderInventoryText(guiGraphics); + drawScrollingString(guiGraphics, MekanismLang.TEMPERATURE_LONG.translate(""), 0, 93, TextAlignment.LEFT, titleTextColor(), 5, false); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_HEAT_GRAPH.translate(), 0, 114, TextAlignment.LEFT, titleTextColor(), 5, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorLogicAdapter.java b/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorLogicAdapter.java index 7f854a4f6a6..f48ccb33c4b 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorLogicAdapter.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorLogicAdapter.java @@ -48,8 +48,8 @@ private void changeLogic(FissionReactorLogic type) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(tile.logicType.getColor(), tile.logicType), 16, 123, titleTextColor(), 144); - drawCenteredText(guiGraphics, MekanismLang.STATUS.translate(EnumColor.RED, tile.getStatus()), 0, imageWidth, 136, titleTextColor()); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(tile.logicType.getColor(), tile.logicType), 0, 123, TextAlignment.CENTER, titleTextColor(), 16, false); + drawScrollingString(guiGraphics, MekanismLang.STATUS.translate(EnumColor.RED, tile.getStatus()), 0, 136, TextAlignment.CENTER, titleTextColor(), 16, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorController.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorController.java index a057299a21f..8e66d25e483 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorController.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorController.java @@ -52,7 +52,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, MekanismLang.MULTIBLOCK_FORMED.translate(), 8, 16, titleTextColor()); + drawScrollingString(guiGraphics, MekanismLang.MULTIBLOCK_FORMED.translate(), 0, 16, TextAlignment.LEFT, titleTextColor(), 8, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java index 0662b412937..160b8211472 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java @@ -47,8 +47,8 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawCenteredText(guiGraphics, GeneratorsLang.REACTOR_INJECTION_RATE.translate(tile.getMultiblock().getInjectionRate()), 0, imageWidth, 35, titleTextColor()); - drawString(guiGraphics, GeneratorsLang.REACTOR_EDIT_RATE.translate(), 50, 117, titleTextColor()); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_INJECTION_RATE.translate(tile.getMultiblock().getInjectionRate()), 0, 35, TextAlignment.CENTER, titleTextColor(), 16, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_EDIT_RATE.translate(), 4, 117, TextAlignment.RIGHT, titleTextColor(), 94, 2, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java index e3d09b92228..a2aed8db7f1 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java @@ -56,9 +56,9 @@ private void changeLogic(FusionReactorLogic type) { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_LOGIC_ACTIVE_COOLING.translate(EnumColor.RED, OnOff.of(tile.isActiveCooled())), 29, 20, titleTextColor(), 117); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(EnumColor.RED, tile.logicType), 16, 123, titleTextColor(), 144); - drawCenteredText(guiGraphics, MekanismLang.STATUS.translate(EnumColor.RED, tile.checkMode() ? GeneratorsLang.REACTOR_LOGIC_OUTPUTTING : MekanismLang.IDLE), - 0, imageWidth, 136, titleTextColor()); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(EnumColor.RED, tile.logicType), 0, 123, TextAlignment.CENTER, titleTextColor(), 16, false); + drawScrollingString(guiGraphics, MekanismLang.STATUS.translate(EnumColor.RED, tile.checkMode() ? GeneratorsLang.REACTOR_LOGIC_OUTPUTTING : MekanismLang.IDLE), + 0, 136, TextAlignment.CENTER, titleTextColor(), 16, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java index 5b2739f3778..6f79977f557 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java @@ -34,7 +34,7 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, renderTitleText(guiGraphics); FusionReactorMultiblockData multiblock = tile.getMultiblock(); if (multiblock.isFormed()) { - drawString(guiGraphics, GeneratorsLang.REACTOR_PASSIVE.translateColored(EnumColor.DARK_GREEN), 6, 26, titleTextColor()); + drawScrollingString(guiGraphics,GeneratorsLang.REACTOR_PASSIVE.translateColored(EnumColor.DARK_GREEN), 0, 26, TextAlignment.LEFT, titleTextColor(), 6, false); drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_MIN_INJECTION.translate(multiblock.getMinInjectionRate(false)), 16, 36, titleTextColor(), 156); drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_IGNITION.translate(MekanismUtils.getTemperatureDisplay(multiblock.getIgnitionTemperature(false), TemperatureUnit.KELVIN, true)), 16, 46, titleTextColor(), 156); @@ -45,7 +45,7 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_PASSIVE_RATE.translate(EnergyDisplay.of(multiblock.getPassiveGeneration(false, false))), 16, 76, titleTextColor(), 156); - drawString(guiGraphics, GeneratorsLang.REACTOR_ACTIVE.translateColored(EnumColor.DARK_BLUE), 6, 92, titleTextColor()); + drawScrollingString(guiGraphics,GeneratorsLang.REACTOR_ACTIVE.translateColored(EnumColor.DARK_BLUE), 0, 92, TextAlignment.LEFT, titleTextColor(), 6, false); drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_MIN_INJECTION.translate(multiblock.getMinInjectionRate(true)), 16, 102, titleTextColor(), 156); drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_IGNITION.translate(MekanismUtils.getTemperatureDisplay(multiblock.getIgnitionTemperature(true), TemperatureUnit.KELVIN, true)), 16, 112, titleTextColor(), 156); diff --git a/src/generators/java/mekanism/generators/client/gui/GuiGasGenerator.java b/src/generators/java/mekanism/generators/client/gui/GuiGasGenerator.java index a9baec5a9f7..f9640f790cb 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiGasGenerator.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiGasGenerator.java @@ -44,12 +44,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); - Component component = GeneratorsLang.GAS_BURN_RATE.translate(tile.getUsed()); - int left = inventoryLabelX + getStringWidth(playerInventoryTitle) + 4; - int end = imageWidth - 8; - left = Math.max(left, end - getStringWidth(component)); - drawTextScaledBound(guiGraphics, component, left, inventoryLabelY, titleTextColor(), end - left); + renderInventoryTextAndOther(guiGraphics, GeneratorsLang.GAS_BURN_RATE.translate(tile.getUsed())); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiHeatGenerator.java b/src/generators/java/mekanism/generators/client/gui/GuiHeatGenerator.java index fda319dc548..94713ae1488 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiHeatGenerator.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiHeatGenerator.java @@ -48,7 +48,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java b/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java index 92e35f85b8d..5fb7fdf36a4 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java @@ -120,7 +120,7 @@ public double getLevel() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiSolarGenerator.java b/src/generators/java/mekanism/generators/client/gui/GuiSolarGenerator.java index 6f553fd2b95..235b350ce30 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiSolarGenerator.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiSolarGenerator.java @@ -47,7 +47,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiTurbineStats.java b/src/generators/java/mekanism/generators/client/gui/GuiTurbineStats.java index 98129d8cdaf..2813a093137 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiTurbineStats.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiTurbineStats.java @@ -60,21 +60,21 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int lowerVolume = multiblock.lowerVolume; int dispersers = multiblock.getDispersers(); int vents = multiblock.vents; - drawString(guiGraphics, GeneratorsLang.TURBINE_TANK_VOLUME.translate(lowerVolume), 8, 26, titleTextColor()); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_TANK_VOLUME.translate(lowerVolume), 0, 26, TextAlignment.LEFT, titleTextColor(), 8, false); boolean dispersersLimiting = lowerVolume * dispersers * MekanismGeneratorsConfig.generators.turbineDisperserChemicalFlow.get() < vents * MekanismGeneratorsConfig.generators.turbineVentChemicalFlow.get(); boolean ventsLimiting = lowerVolume * dispersers * MekanismGeneratorsConfig.generators.turbineDisperserChemicalFlow.get() > vents * MekanismGeneratorsConfig.generators.turbineVentChemicalFlow.get(); - drawString(guiGraphics, GeneratorsLang.TURBINE_STEAM_FLOW.translate(), 8, 40, subheadingTextColor()); - drawString(guiGraphics, GeneratorsLang.TURBINE_DISPERSERS.translate(dispersers, dispersersLimiting ? limiting : ""), 14, 49, titleTextColor()); - drawString(guiGraphics, GeneratorsLang.TURBINE_VENTS.translate(vents, ventsLimiting ? limiting : ""), 14, 58, titleTextColor()); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_STEAM_FLOW.translate(), 0, 40, TextAlignment.LEFT, subheadingTextColor(), 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_DISPERSERS.translate(dispersers, dispersersLimiting ? limiting : ""), 6, 49, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_VENTS.translate(vents, ventsLimiting ? limiting : ""), 6, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); int coils = multiblock.coils; int blades = multiblock.blades; - drawString(guiGraphics, GeneratorsLang.TURBINE_PRODUCTION.translate(), 8, 72, subheadingTextColor()); - drawString(guiGraphics, GeneratorsLang.TURBINE_BLADES.translate(blades, coils * 4 > blades ? limiting : ""), 14, 81, titleTextColor()); - drawString(guiGraphics, GeneratorsLang.TURBINE_COILS.translate(coils, coils * 4 < blades ? limiting : ""), 14, 90, titleTextColor()); - drawTextScaledBound(guiGraphics, GeneratorsLang.TURBINE_MAX_PRODUCTION.translate(EnergyDisplay.of(multiblock.getMaxProduction())), 8, 104, titleTextColor(), 164); - drawTextScaledBound(guiGraphics, GeneratorsLang.TURBINE_MAX_WATER_OUTPUT.translate(TextUtils.format(multiblock.getMaxWaterOutput())), 8, 113, titleTextColor(), 164); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_PRODUCTION.translate(), 0, 72, TextAlignment.LEFT, subheadingTextColor(), 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_BLADES.translate(blades, coils * 4 > blades ? limiting : ""), 6, 81, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_COILS.translate(coils, coils * 4 < blades ? limiting : ""), 6, 90, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_MAX_PRODUCTION.translate(EnergyDisplay.of(multiblock.getMaxProduction())), 0, 104, TextAlignment.LEFT, titleTextColor(), 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_MAX_WATER_OUTPUT.translate(TextUtils.format(multiblock.getMaxWaterOutput())), 0, 113, TextAlignment.LEFT, titleTextColor(), 8, false); } super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiWindGenerator.java b/src/generators/java/mekanism/generators/client/gui/GuiWindGenerator.java index 1d6da9502ec..c64c514df54 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiWindGenerator.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiWindGenerator.java @@ -60,7 +60,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/element/button/ReactorLogicButton.java b/src/generators/java/mekanism/generators/client/gui/element/button/ReactorLogicButton.java index f8d9cfb9f19..75aa3e8d698 100644 --- a/src/generators/java/mekanism/generators/client/gui/element/button/ReactorLogicButton.java +++ b/src/generators/java/mekanism/generators/client/gui/element/button/ReactorLogicButton.java @@ -27,7 +27,6 @@ public class ReactorLogicButton & IReactorLogicMode tile; - private final int typeOffset; private final Supplier<@Nullable TYPE> modeSupplier; private final Map typeTooltips; private final Consumer onPress; @@ -35,17 +34,16 @@ public class ReactorLogicButton & IReactorLogicMode tile, Class clazz, IntSupplier indexSupplier, Supplier modeList, Consumer onPress) { - this(gui, x, y, index, tile, clazz, onPress, () -> { + this(gui, x, y, tile, clazz, onPress, () -> { int i = indexSupplier.getAsInt() + index; TYPE[] modes = modeList.get(); return i >= 0 && i < modes.length ? modes[i] : null; }); } - private ReactorLogicButton(IGuiWrapper gui, int x, int y, int index, @NotNull IReactorLogic tile, Class clazz, Consumer onPress, Supplier<@Nullable TYPE> modeSupplier) { + private ReactorLogicButton(IGuiWrapper gui, int x, int y, @NotNull IReactorLogic tile, Class clazz, Consumer onPress, Supplier<@Nullable TYPE> modeSupplier) { super(gui, x, y, 128, 22, Component.empty(), (element, mouseX, mouseY) -> ((ReactorLogicButton) element).click()); this.onPress = onPress; - this.typeOffset = 22 * index; this.modeSupplier = modeSupplier; this.tile = tile; this.typeTooltips = new EnumMap<>(clazz); @@ -73,8 +71,8 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { TYPE mode = modeSupplier.get(); if (mode != null) { - gui().renderItem(guiGraphics, mode.getRenderStack(), 20, 35 + typeOffset); - drawString(guiGraphics, TextComponentUtil.build(EnumColor.WHITE, mode), 39, 34 + typeOffset, titleTextColor()); + gui().renderItem(guiGraphics, mode.getRenderStack(), relativeX + 3, relativeY + 3); + drawScrollingString(guiGraphics, TextComponentUtil.build(EnumColor.WHITE, mode), 20, 2, TextAlignment.LEFT, titleTextColor(), width - 20, 2, false); super.renderForeground(guiGraphics, mouseX, mouseY); } } diff --git a/src/generators/java/mekanism/generators/client/recipe_viewer/emi/recipe/FissionReactorEmiRecipe.java b/src/generators/java/mekanism/generators/client/recipe_viewer/emi/recipe/FissionReactorEmiRecipe.java index f7109648d36..f8472bc079c 100644 --- a/src/generators/java/mekanism/generators/client/recipe_viewer/emi/recipe/FissionReactorEmiRecipe.java +++ b/src/generators/java/mekanism/generators/client/recipe_viewer/emi/recipe/FissionReactorEmiRecipe.java @@ -41,7 +41,7 @@ public void addWidgets(WidgetHolder widgetHolder) { GeneratorsLang.FISSION_HEATING_RATE.translate(0), MekanismLang.TEMPERATURE.translate(EnumColor.BRIGHT_GREEN, MekanismUtils.getTemperatureDisplay(HeatAPI.AMBIENT_TEMP, TemperatureUnit.KELVIN, true)), GeneratorsLang.FISSION_DAMAGE.translate(EnumColor.BRIGHT_GREEN, TextUtils.getPercent(0)) - )).spacing(2)); + )).spacing(1)); initTank(widgetHolder, GuiFluidGauge.getDummy(GaugeType.STANDARD, this, 6, 13).setLabel(GeneratorsLang.FISSION_COOLANT_TANK.translateColored(EnumColor.AQUA)), input(0)); initTank(widgetHolder, GuiChemicalGauge.getDummy(GaugeType.STANDARD, this, 25, 13).setLabel(GeneratorsLang.FISSION_FUEL_TANK.translateColored(EnumColor.DARK_GREEN)), input(1)); initTank(widgetHolder, GuiChemicalGauge.getDummy(GaugeType.STANDARD, this, 152, 13).setLabel(GeneratorsLang.FISSION_HEATED_COOLANT_TANK.translateColored(EnumColor.GRAY)), output(0)).recipeContext(this); diff --git a/src/generators/java/mekanism/generators/client/recipe_viewer/jei/FissionReactorRecipeCategory.java b/src/generators/java/mekanism/generators/client/recipe_viewer/jei/FissionReactorRecipeCategory.java index f07f03b85a2..1a29d990be5 100644 --- a/src/generators/java/mekanism/generators/client/recipe_viewer/jei/FissionReactorRecipeCategory.java +++ b/src/generators/java/mekanism/generators/client/recipe_viewer/jei/FissionReactorRecipeCategory.java @@ -41,7 +41,7 @@ public FissionReactorRecipeCategory(IGuiHelper helper, IRecipeViewerRecipeType(this, tile)); addRenderableWidget(new GuiMergedTankGauge<>(() -> tile.getMultiblock().mergedTank, tile::getMultiblock, GaugeType.MEDIUM, this, 7, 16, 34, 56)); @@ -74,7 +74,7 @@ private void addStored(List ret, STACK stack, ToLongFunction< @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiEnergyCube.java b/src/main/java/mekanism/client/gui/GuiEnergyCube.java index d97f2f466c2..ec451ff4e2d 100644 --- a/src/main/java/mekanism/client/gui/GuiEnergyCube.java +++ b/src/main/java/mekanism/client/gui/GuiEnergyCube.java @@ -42,7 +42,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiFilterHolder.java b/src/main/java/mekanism/client/gui/GuiFilterHolder.java index ad3e16af2b0..90a244c604a 100644 --- a/src/main/java/mekanism/client/gui/GuiFilterHolder.java +++ b/src/main/java/mekanism/client/gui/GuiFilterHolder.java @@ -32,6 +32,7 @@ public abstract class GuiFilterHolder, TILE extends Ti * The number of filters that can be displayed */ private static final int FILTER_COUNT = 4; + protected GuiInnerScreen leftScreen; private GuiScrollBar scrollBar; protected GuiFilterHolder(CONTAINER container, Inventory inv, Component title) { @@ -46,7 +47,7 @@ protected GuiFilterHolder(CONTAINER container, Inventory inv, Component title) { @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 9, 17, 85, 140)); + leftScreen = addRenderableWidget(new GuiInnerScreen(this, 9, 17, 85, 140)); //Filter holder addRenderableWidget(new GuiElementHolder(this, 95, 17, 158, 118)); //new filter button border @@ -69,6 +70,17 @@ protected void addGuiElements() { } } + protected void drawScreenText(GuiGraphics guiGraphics, Component text, int y) { + drawScreenText(guiGraphics, text, 0, y); + } + + protected void drawScreenText(GuiGraphics guiGraphics, Component text, int x, int y) { + //TODO: Do we want to make usages of this method eventually set the text to be rendered within the gui element for the screen? + if (leftScreen != null) {//Validate it was properly set + leftScreen.drawScaledScrollingString(guiGraphics, text, x, y, TextAlignment.LEFT, screenTextColor(), leftScreen.getXSize() - x, 5, false, 0.8F); + } + } + private List getRenderStacks(@Nullable IFilter filter) { if (filter != null) { return switch (filter) { @@ -103,6 +115,6 @@ public boolean mouseScrolled(double mouseX, double mouseY, double xDelta, double @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { super.drawForegroundText(guiGraphics, mouseX, mouseY); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiFluidTank.java b/src/main/java/mekanism/client/gui/GuiFluidTank.java index 0710c5ffd8c..1ad239aaaa2 100644 --- a/src/main/java/mekanism/client/gui/GuiFluidTank.java +++ b/src/main/java/mekanism/client/gui/GuiFluidTank.java @@ -30,7 +30,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiInductionMatrix.java b/src/main/java/mekanism/client/gui/GuiInductionMatrix.java index 39809990903..e18f17fd2d6 100644 --- a/src/main/java/mekanism/client/gui/GuiInductionMatrix.java +++ b/src/main/java/mekanism/client/gui/GuiInductionMatrix.java @@ -45,7 +45,7 @@ protected void addGuiElements() { MekanismLang.CAPACITY.translate(EnergyDisplay.of(multiblock.getStorageCap())), MekanismLang.MATRIX_INPUT_AMOUNT.translate(MekanismLang.GENERIC_PER_TICK.translate(EnergyDisplay.of(multiblock.getLastInput()))), MekanismLang.MATRIX_OUTPUT_AMOUNT.translate(MekanismLang.GENERIC_PER_TICK.translate(EnergyDisplay.of(multiblock.getLastOutput())))); - }).spacing(2)); + }).spacing(1)); addRenderableWidget(new GuiMatrixTab(this, tile, MatrixTab.STAT)); addRenderableWidget(new GuiEnergyGauge(new IEnergyInfoHandler() { @Override @@ -69,7 +69,7 @@ public long getMaxEnergy() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java b/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java index 2c6408d97d0..fa1073d0206 100644 --- a/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java +++ b/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java @@ -55,7 +55,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); if (tile.getDelay() > 0) { drawTextScaledBound(guiGraphics, MekanismLang.DELAY.translate(tile.getDelay()), 26, 30, titleTextColor(), 68); } else { diff --git a/src/main/java/mekanism/client/gui/GuiLaserTractorBeam.java b/src/main/java/mekanism/client/gui/GuiLaserTractorBeam.java index ec27c71bbd7..2ae5c10969e 100644 --- a/src/main/java/mekanism/client/gui/GuiLaserTractorBeam.java +++ b/src/main/java/mekanism/client/gui/GuiLaserTractorBeam.java @@ -17,7 +17,7 @@ public GuiLaserTractorBeam(MekanismTileContainer con @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiLogisticalSorter.java b/src/main/java/mekanism/client/gui/GuiLogisticalSorter.java index 6aae778aa10..acfe1b2bdee 100644 --- a/src/main/java/mekanism/client/gui/GuiLogisticalSorter.java +++ b/src/main/java/mekanism/client/gui/GuiLogisticalSorter.java @@ -71,14 +71,14 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, super.drawForegroundText(guiGraphics, mouseX, mouseY); // Write to info display renderTitleText(guiGraphics); - drawTextWithScale(guiGraphics, MekanismLang.FILTER_COUNT.translate(getFilterManager().count()), 14, 21, screenTextColor(), 0.8F); - drawTextWithScale(guiGraphics, MekanismLang.SORTER_SINGLE_ITEM.translate(), 14, 36, screenTextColor(), 0.8F); - drawTextWithScale(guiGraphics, OnOff.of(tile.getSingleItem()).getTextComponent(), 28, 49, screenTextColor(), 0.8F); - drawTextWithScale(guiGraphics, MekanismLang.SORTER_ROUND_ROBIN.translate(), 14, 66, screenTextColor(), 0.8F); - drawTextWithScale(guiGraphics, OnOff.of(tile.getRoundRobin()).getTextComponent(), 28, 79, screenTextColor(), 0.8F); - drawTextWithScale(guiGraphics, MekanismLang.SORTER_AUTO_EJECT.translate(), 14, 96, screenTextColor(), 0.8F); - drawTextWithScale(guiGraphics, OnOff.of(tile.getAutoEject()).getTextComponent(), 28, 109, screenTextColor(), 0.8F); - drawTextWithScale(guiGraphics, MekanismLang.SORTER_DEFAULT.translate(), 14, 126, screenTextColor(), 0.8F); + drawScreenText(guiGraphics, MekanismLang.FILTER_COUNT.translate(getFilterManager().count()), 4); + drawScreenText(guiGraphics, MekanismLang.SORTER_SINGLE_ITEM.translate(), 19); + drawScreenText(guiGraphics, OnOff.of(tile.getSingleItem()).getTextComponent(), 14, 32); + drawScreenText(guiGraphics, MekanismLang.SORTER_ROUND_ROBIN.translate(), 49); + drawScreenText(guiGraphics, OnOff.of(tile.getRoundRobin()).getTextComponent(), 14, 62); + drawScreenText(guiGraphics, MekanismLang.SORTER_AUTO_EJECT.translate(), 79); + drawScreenText(guiGraphics, OnOff.of(tile.getAutoEject()).getTextComponent(), 14, 92); + drawScreenText(guiGraphics, MekanismLang.SORTER_DEFAULT.translate(), 109); } @Override diff --git a/src/main/java/mekanism/client/gui/GuiMatrixStats.java b/src/main/java/mekanism/client/gui/GuiMatrixStats.java index f163b58f77c..c82494410da 100644 --- a/src/main/java/mekanism/client/gui/GuiMatrixStats.java +++ b/src/main/java/mekanism/client/gui/GuiMatrixStats.java @@ -80,17 +80,17 @@ public double getLevel() { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); MatrixMultiblockData multiblock = tile.getMultiblock(); - drawString(guiGraphics, MekanismLang.INPUT.translate(), 53, 26, subheadingTextColor()); - drawString(guiGraphics, EnergyDisplay.of(multiblock.getLastInput(), multiblock.getTransferCap()).getTextComponent(), 59, 35, titleTextColor()); - drawString(guiGraphics, MekanismLang.OUTPUT.translate(), 53, 46, subheadingTextColor()); - drawString(guiGraphics, EnergyDisplay.of(multiblock.getLastOutput(), multiblock.getTransferCap()).getTextComponent(), 59, 55, titleTextColor()); - drawString(guiGraphics, MekanismLang.MATRIX_DIMENSIONS.translate(), 8, 82, subheadingTextColor()); + drawScrollingString(guiGraphics, MekanismLang.INPUT.translate(), 45, 26, TextAlignment.LEFT, subheadingTextColor(), getXSize() - 54, 8, false); + drawScrollingString(guiGraphics, EnergyDisplay.of(multiblock.getLastInput(), multiblock.getTransferCap()).getTextComponent(), 51, 35, TextAlignment.LEFT, titleTextColor(), getXSize() - 60, 8, false); + drawScrollingString(guiGraphics, MekanismLang.OUTPUT.translate(), 45, 46, TextAlignment.LEFT, subheadingTextColor(), getXSize() - 54, 8, false); + drawScrollingString(guiGraphics, EnergyDisplay.of(multiblock.getLastOutput(), multiblock.getTransferCap()).getTextComponent(), 51, 55, TextAlignment.LEFT, titleTextColor(), getXSize() - 60, 8, false); + drawScrollingString(guiGraphics, MekanismLang.MATRIX_DIMENSIONS.translate(), 0, 82, TextAlignment.LEFT, subheadingTextColor(), 8, false); if (multiblock.isFormed()) { - drawString(guiGraphics, MekanismLang.MATRIX_DIMENSION_REPRESENTATION.translate(multiblock.width(), multiblock.height(), multiblock.length()), 14, 91, titleTextColor()); + drawScrollingString(guiGraphics, MekanismLang.MATRIX_DIMENSION_REPRESENTATION.translate(multiblock.width(), multiblock.height(), multiblock.length()), 6, 91, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); } - drawString(guiGraphics, MekanismLang.MATRIX_CONSTITUENTS.translate(), 8, 102, subheadingTextColor()); - drawString(guiGraphics, MekanismLang.MATRIX_CELLS.translate(multiblock.getCellCount()), 14, 111, titleTextColor()); - drawString(guiGraphics, MekanismLang.MATRIX_PROVIDERS.translate(multiblock.getProviderCount()), 14, 120, titleTextColor()); + drawScrollingString(guiGraphics, MekanismLang.MATRIX_CONSTITUENTS.translate(), 0, 102, TextAlignment.LEFT, subheadingTextColor(), 8, false); + drawScrollingString(guiGraphics, MekanismLang.MATRIX_CELLS.translate(multiblock.getCellCount()), 6, 111, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); + drawScrollingString(guiGraphics, MekanismLang.MATRIX_PROVIDERS.translate(multiblock.getProviderCount()), 6, 120, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiMekanism.java b/src/main/java/mekanism/client/gui/GuiMekanism.java index 93f935579bd..27635bc9fc9 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanism.java +++ b/src/main/java/mekanism/client/gui/GuiMekanism.java @@ -13,7 +13,6 @@ import mekanism.client.gui.element.slot.SlotType; import mekanism.client.gui.element.tab.GuiWarningTab; import mekanism.client.gui.element.window.GuiWindow; -import mekanism.client.render.IFancyFontRenderer; import mekanism.client.render.MekanismRenderer; import mekanism.common.Mekanism; import mekanism.common.inventory.container.MekanismContainer; @@ -48,7 +47,7 @@ import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; -public abstract class GuiMekanism extends VirtualSlotContainerScreen implements IGuiWrapper, IFancyFontRenderer { +public abstract class GuiMekanism extends VirtualSlotContainerScreen implements IGuiWrapper { public static final ResourceLocation BASE_BACKGROUND = MekanismUtils.getResource(ResourceType.GUI, "base.png"); public static final ResourceLocation SHADOW = MekanismUtils.getResource(ResourceType.GUI, "shadow.png"); @@ -172,6 +171,24 @@ protected void renderTitleText(GuiGraphics guiGraphics) { drawTitleText(guiGraphics, title, titleLabelY); } + protected void renderTitleTextWithOffset(GuiGraphics guiGraphics, int startPad, int endPad, int maxLengthPad, TextAlignment alignment) { + drawTitleTextTextWithOffset(guiGraphics, title, 0, titleLabelY, startPad, endPad, maxLengthPad, alignment); + } + + protected void renderInventoryText(GuiGraphics guiGraphics) { + drawScrollingString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, TextAlignment.LEFT, titleTextColor(), getXSize() - inventoryLabelX - 6, 0, false); + } + + protected void renderInventoryTextAndOther(GuiGraphics guiGraphics, Component rightAlignedText) { + renderInventoryTextAndOther(guiGraphics, rightAlignedText, 0); + } + + protected void renderInventoryTextAndOther(GuiGraphics guiGraphics, Component rightAlignedText, int rightEndPad) { + drawScrollingString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, TextAlignment.LEFT, titleTextColor(), 56, 0, false); + int rightStart = inventoryLabelX + 54; + drawScrollingString(guiGraphics, rightAlignedText, rightStart, inventoryLabelY, TextAlignment.RIGHT, titleTextColor(), getXSize() - rightStart - rightEndPad, 6, false); + } + protected ResourceLocation getButtonLocation(String name) { return MekanismUtils.getResource(ResourceType.GUI_BUTTON, name + ".png"); } @@ -670,7 +687,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float partialTick, int //Ensure the GL color is white as mods adding an overlay (such as JEI for bookmarks), might have left // it in an unexpected state. MekanismRenderer.resetColor(guiGraphics); - if (width < 8 || height < 8) { + if (getXSize() < 8 || getYSize() < 8) { Mekanism.logger.warn("Gui: {}, was too small to draw the background of. Unable to draw a background for a gui smaller than 8 by 8.", getClass().getSimpleName()); return; } @@ -678,10 +695,11 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float partialTick, int } @Override - @SuppressWarnings("ConstantValue") - public Font getFont() { - //In theory font is never null here, but we validate it in case we are called before init finishes happening - return font == null ? minecraft.font : font; + public Font font() { + //Note: In theory font is never null here, as we should only be calling it after init has happened + // Previously we checked if it was and then fell back to Minecraft's overall font. But as the minecraft + // object we queried was actually null as well, we know that this doesn't ever get called before init + return font; } @Override diff --git a/src/main/java/mekanism/client/gui/GuiModificationStation.java b/src/main/java/mekanism/client/gui/GuiModificationStation.java index 834bf00e7c2..96d535b4165 100644 --- a/src/main/java/mekanism/client/gui/GuiModificationStation.java +++ b/src/main/java/mekanism/client/gui/GuiModificationStation.java @@ -55,7 +55,7 @@ private void onModuleSelected(@Nullable IModule module) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiPersonalStorageTile.java b/src/main/java/mekanism/client/gui/GuiPersonalStorageTile.java index 1d39a535f66..9073859f09c 100644 --- a/src/main/java/mekanism/client/gui/GuiPersonalStorageTile.java +++ b/src/main/java/mekanism/client/gui/GuiPersonalStorageTile.java @@ -19,7 +19,7 @@ public GuiPersonalStorageTile(MekanismTileContainer c @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiQuantumEntangloporter.java b/src/main/java/mekanism/client/gui/GuiQuantumEntangloporter.java index a8d6dbbf2bc..821de71b082 100644 --- a/src/main/java/mekanism/client/gui/GuiQuantumEntangloporter.java +++ b/src/main/java/mekanism/client/gui/GuiQuantumEntangloporter.java @@ -49,7 +49,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/GuiSPS.java b/src/main/java/mekanism/client/gui/GuiSPS.java index e3b3c2a9ad3..4dfc12fbc38 100644 --- a/src/main/java/mekanism/client/gui/GuiSPS.java +++ b/src/main/java/mekanism/client/gui/GuiSPS.java @@ -62,7 +62,7 @@ public double getLevel() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } diff --git a/src/main/java/mekanism/client/gui/GuiSecurityDesk.java b/src/main/java/mekanism/client/gui/GuiSecurityDesk.java index b78deb88c09..952d100f711 100644 --- a/src/main/java/mekanism/client/gui/GuiSecurityDesk.java +++ b/src/main/java/mekanism/client/gui/GuiSecurityDesk.java @@ -179,15 +179,16 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); Component ownerComponent = OwnerDisplay.of(tile.getOwnerUUID(), tile.getOwnerName()).getTextComponent(); - drawString(guiGraphics, ownerComponent, imageWidth - 7 - getStringWidth(ownerComponent), inventoryLabelY, titleTextColor()); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); - drawCenteredText(guiGraphics, MekanismLang.TRUSTED_PLAYERS.translate(), 74, 57, subheadingTextColor()); + renderInventoryTextAndOther(guiGraphics, ownerComponent); + drawScrollingString(guiGraphics, MekanismLang.TRUSTED_PLAYERS.translate(), 13, 57, TextAlignment.CENTER, subheadingTextColor(), 122, 0, false); SecurityFrequency frequency = tile.getFreq(); - if (frequency != null) { - drawString(guiGraphics, MekanismLang.SECURITY.translate(frequency.getSecurity()), 13, 103, titleTextColor()); + Component frequencyText; + if (frequency == null) { + frequencyText = MekanismLang.SECURITY_OFFLINE.translateColored(EnumColor.RED); } else { - drawString(guiGraphics, MekanismLang.SECURITY_OFFLINE.translateColored(EnumColor.RED), 13, 103, titleTextColor()); + frequencyText = MekanismLang.SECURITY.translate(frequency.getSecurity()); } + drawScrollingString(guiGraphics, frequencyText, 13, 103, TextAlignment.LEFT, titleTextColor(), 122, 0, false); drawTextScaledBound(guiGraphics, MekanismLang.SECURITY_ADD.translate(), 13, 70, titleTextColor(), 20); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/GuiTeleporter.java b/src/main/java/mekanism/client/gui/GuiTeleporter.java index b32d85ab5b5..eec15c5570e 100644 --- a/src/main/java/mekanism/client/gui/GuiTeleporter.java +++ b/src/main/java/mekanism/client/gui/GuiTeleporter.java @@ -36,7 +36,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java b/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java index 04e5d7b2249..972b4c85349 100644 --- a/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java +++ b/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java @@ -43,7 +43,7 @@ protected void addGuiElements() { return List.of(MekanismLang.MULTIBLOCK_FORMED.translate(), MekanismLang.EVAPORATION_HEIGHT.translate(multiblock.height()), MekanismLang.TEMPERATURE.translate(MekanismUtils.getTemperatureDisplay(multiblock.getTemperature(), TemperatureUnit.KELVIN, true)), MekanismLang.FLUID_PRODUCTION.translate(Math.round(multiblock.lastGain * 100D) / 100D)); - }).spacing(1).recipeViewerCategories(RecipeViewerRecipeType.EVAPORATING)); + }).clearSpacing().recipeViewerCategories(RecipeViewerRecipeType.EVAPORATING)); addRenderableWidget(new GuiDownArrow(this, 32, 39)); addRenderableWidget(new GuiDownArrow(this, 136, 39)); addRenderableWidget(new GuiHorizontalRateBar(this, new IBarInfoHandler() { @@ -82,7 +82,7 @@ protected void addWarningTab(IWarningTracker warningTracker) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiThermoelectricBoiler.java b/src/main/java/mekanism/client/gui/GuiThermoelectricBoiler.java index 94bada5964f..14cc9daa77f 100644 --- a/src/main/java/mekanism/client/gui/GuiThermoelectricBoiler.java +++ b/src/main/java/mekanism/client/gui/GuiThermoelectricBoiler.java @@ -89,7 +89,7 @@ public double getLevel() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiUtils.java b/src/main/java/mekanism/client/gui/GuiUtils.java index 15434a9ec82..5de91d77ce9 100644 --- a/src/main/java/mekanism/client/gui/GuiUtils.java +++ b/src/main/java/mekanism/client/gui/GuiUtils.java @@ -251,10 +251,6 @@ public interface CharTypedPredicate { boolean test(ELEMENT element, char c, int keyCode); } - public static int drawString(GuiGraphics guiGraphics, Font font, Component component, float x, float y, int color, boolean drawShadow) { - return guiGraphics.drawString(font, component.getVisualOrderText(), x, y, color, drawShadow); - } - public static int drawStringNoFlush(GuiGraphics graphics, Font font, Component component, float x, float y, int color, boolean drawShadow) { return drawStringNoFlush(graphics, graphics.pose().last().pose(), font, component, x, y, color, drawShadow); } diff --git a/src/main/java/mekanism/client/gui/IGuiWrapper.java b/src/main/java/mekanism/client/gui/IGuiWrapper.java index 6896fb2a6eb..e20184ac6ca 100644 --- a/src/main/java/mekanism/client/gui/IGuiWrapper.java +++ b/src/main/java/mekanism/client/gui/IGuiWrapper.java @@ -4,11 +4,11 @@ import java.util.List; import java.util.function.BooleanSupplier; import mekanism.client.gui.element.window.GuiWindow; +import mekanism.client.render.IFancyFontRenderer; import mekanism.common.Mekanism; import mekanism.common.inventory.container.SelectedWindowData; import mekanism.common.inventory.warning.WarningTracker.WarningType; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.events.ContainerEventHandler; import net.minecraft.client.gui.screens.Screen; @@ -17,7 +17,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public interface IGuiWrapper extends ContainerEventHandler { +public interface IGuiWrapper extends ContainerEventHandler, IFancyFontRenderer { @NotNull default ItemStack getCarriedItem() { @@ -28,6 +28,7 @@ default ItemStack getCarriedItem() { int getGuiTop(); + @Override int getXSize(); int getYSize(); @@ -55,18 +56,16 @@ default BooleanSupplier trackWarning(@NotNull WarningType type, @NotNull Boolean return warningSupplier; } - Font getFont(); - default void renderItem(GuiGraphics guiGraphics, @NotNull ItemStack stack, int xAxis, int yAxis) { renderItem(guiGraphics, stack, xAxis, yAxis, 1); } default void renderItem(GuiGraphics guiGraphics, @NotNull ItemStack stack, int xAxis, int yAxis, float scale) { - GuiUtils.renderItem(guiGraphics, stack, xAxis, yAxis, scale, getFont(), null, false); + GuiUtils.renderItem(guiGraphics, stack, xAxis, yAxis, scale, font(), null, false); } default void renderItemTooltip(GuiGraphics guiGraphics, @NotNull ItemStack stack, int xAxis, int yAxis) { - guiGraphics.renderTooltip(getFont(), stack, xAxis, yAxis); + guiGraphics.renderTooltip(font(), stack, xAxis, yAxis); } default void renderItemTooltipWithExtra(GuiGraphics guiGraphics, @NotNull ItemStack stack, int xAxis, int yAxis, List toAppend) { @@ -75,12 +74,12 @@ default void renderItemTooltipWithExtra(GuiGraphics guiGraphics, @NotNull ItemSt } else { List tooltip = new ArrayList<>(Screen.getTooltipFromItem(Minecraft.getInstance(), stack)); tooltip.addAll(toAppend); - guiGraphics.renderTooltip(getFont(), tooltip, stack.getTooltipImage(), stack, xAxis, yAxis); + guiGraphics.renderTooltip(font(), tooltip, stack.getTooltipImage(), stack, xAxis, yAxis); } } default void renderItemWithOverlay(GuiGraphics guiGraphics, @NotNull ItemStack stack, int xAxis, int yAxis, float scale, @Nullable String text) { - GuiUtils.renderItem(guiGraphics, stack, xAxis, yAxis, scale, getFont(), text, true); + GuiUtils.renderItem(guiGraphics, stack, xAxis, yAxis, scale, font(), text, true); } default void setSelectedWindow(SelectedWindowData selectedWindow) { diff --git a/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java b/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java index 3445aab962a..2846f8bb98e 100644 --- a/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java +++ b/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java @@ -40,7 +40,8 @@ public void renderToolTip(@NotNull GuiGraphics guiGraphics, int mouseX, int mous //Mirror vanilla's tooltip rendering offset pose.translate(0, 0, 400); GuiUtils.renderBackgroundTexture(guiGraphics, GuiInnerScreen.SCREEN, GuiInnerScreen.SCREEN_SIZE, GuiInnerScreen.SCREEN_SIZE, tooltipX - 3, tooltipY - 4, getStringWidth(component) + 6, 16, 256, 256); - drawString(guiGraphics, component, tooltipX, tooltipY, screenTextColor()); + //Note: This doesn't need to be a scrolling string as the background is resized to fit it + drawString(guiGraphics, component, tooltipX, tooltipY, screenTextColor(), false); pose.popPose(); } } diff --git a/src/main/java/mekanism/client/gui/element/GuiDigitalSwitch.java b/src/main/java/mekanism/client/gui/element/GuiDigitalSwitch.java index 314357ff104..6f03f7624d2 100644 --- a/src/main/java/mekanism/client/gui/element/GuiDigitalSwitch.java +++ b/src/main/java/mekanism/client/gui/element/GuiDigitalSwitch.java @@ -42,8 +42,8 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - drawScaledCenteredText(guiGraphics, MekanismLang.ON.translate(), relativeX + type.switchX + 8, relativeY + type.switchY, 0x101010, 0.5F); - drawScaledCenteredText(guiGraphics, MekanismLang.OFF.translate(), relativeX + type.switchX + 8, relativeY + type.switchY + 9, 0x101010, 0.5F); + drawScaledScrollingString(guiGraphics, MekanismLang.ON.translate(), type.switchX, type.switchY, TextAlignment.CENTER, 0x101010, BUTTON_SIZE_X, 1, false, 0.5F); + drawScaledScrollingString(guiGraphics, MekanismLang.OFF.translate(), type.switchX, type.switchY + BUTTON_SIZE_Y + 1, TextAlignment.CENTER, 0x101010, BUTTON_SIZE_X, 1, false, 0.5F); } @Override diff --git a/src/main/java/mekanism/client/gui/element/GuiDropdown.java b/src/main/java/mekanism/client/gui/element/GuiDropdown.java index a8932065d6f..c626b7e4acf 100644 --- a/src/main/java/mekanism/client/gui/element/GuiDropdown.java +++ b/src/main/java/mekanism/client/gui/element/GuiDropdown.java @@ -59,12 +59,11 @@ public void onRelease(double mouseX, double mouseY) { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - int maxWidth = width - 11; TYPE current = curType.get(); - drawScaledTextScaledBound(guiGraphics, current.getShortName(), relativeX + 4, relativeY + 2, screenTextColor(), maxWidth, 0.8F); + drawScaledScrollingString(guiGraphics, current.getShortName(), 0, 2, TextAlignment.LEFT, screenTextColor(), 4, false, 0.8F); if (isOpen) { for (int i = 0; i < options.length; i++) { - drawScaledTextScaledBound(guiGraphics, options[i].getShortName(), relativeX + 4, relativeY + 11 + 2 + 10 * i, screenTextColor(), maxWidth, 0.8F); + drawScaledScrollingString(guiGraphics, options[i].getShortName(), 0, 11 + 2 + 10 * i, TextAlignment.LEFT, screenTextColor(), 4, false, 0.8F); } } } diff --git a/src/main/java/mekanism/client/gui/element/GuiElement.java b/src/main/java/mekanism/client/gui/element/GuiElement.java index 9160b0c3177..adc0d93d50a 100644 --- a/src/main/java/mekanism/client/gui/element/GuiElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiElement.java @@ -467,8 +467,8 @@ public boolean mouseScrolled(double mouseX, double mouseY, double xDelta, double } @Override - public Font getFont() { - return guiObj.getFont(); + public Font font() { + return guiObj.font(); } @Override @@ -616,7 +616,11 @@ protected void drawButtonText(GuiGraphics guiGraphics, int mouseX, int mouseY) { //Only attempt to draw the message if we have a message to draw if (!text.getString().isEmpty()) { int color = getButtonTextColor(mouseX, mouseY) | Mth.ceil(alpha * 255.0F) << 24; - drawCenteredTextScaledBound(guiGraphics, text, width - 4, height / 2F - 4, color); + int buttonX = getButtonX(); + int buttonY = getButtonY(); + //TODO - 1.21: Do we want to be passing false to this so that it has no shadow? I believe previously we didn't render the shadow + //TODO - 1.21: Aka do we want to use the one in IFancyFontRenderer? + renderScrollingString(guiGraphics, font(), text, buttonX + 2, buttonY, buttonX + getButtonWidth() - 2, buttonY + getButtonHeight(), color); } } @@ -667,7 +671,6 @@ protected static void playClickSound(Supplier sound) { } private static void playClickSound(@NotNull SoundManager soundHandler, @NotNull Supplier sound, float clickVolume) { - soundHandler.play(SimpleSoundInstance.forUI(sound.get(), 1.0F, clickVolume)); } @@ -677,8 +680,13 @@ protected void drawTiledSprite(GuiGraphics guiGraphics, int xPosition, int yPosi } @Override - public void drawCenteredTextScaledBound(GuiGraphics guiGraphics, Component text, float maxLength, float x, float y, int color) { - IFancyFontRenderer.super.drawCenteredTextScaledBound(guiGraphics, text, maxLength, relativeX + x, relativeY + y, color); + public void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow) { + IFancyFontRenderer.super.drawScrollingString(guiGraphics, text, relativeX + x, relativeY + y, alignment, color, width, maxLengthPad, shadow); + } + + @Override + public void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow, float scale) { + IFancyFontRenderer.super.drawScaledScrollingString(guiGraphics, text, relativeX + x, relativeY + y, alignment, color, width, maxLengthPad, shadow, scale); } public enum ButtonBackground { diff --git a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java index 9624f615ee6..be0362a7ea5 100644 --- a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java +++ b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java @@ -13,6 +13,7 @@ import net.minecraft.client.gui.components.Tooltip; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,7 +31,7 @@ public class GuiInnerScreen extends GuiScalableElement implements IRecipeViewerR private IRecipeViewerRecipeType[] recipeCategories; private boolean centerY; - private int spacing = 1; + private int spacing; private int padding = 3; private float textScale = 1.0F; @@ -55,6 +56,10 @@ public GuiInnerScreen spacing(int spacing) { return this; } + public GuiInnerScreen clearSpacing() { + return spacing(0); + } + public GuiInnerScreen padding(int padding) { this.padding = padding; return this; @@ -76,7 +81,7 @@ public GuiInnerScreen clearFormat() { } public GuiInnerScreen defaultFormat() { - return padding(5).spacing(3).textScale(0.8F).centerY(); + return padding(5).spacing(2).textScale(0.8F).centerY(); } @Override @@ -84,15 +89,26 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); if (renderStrings != null) { List list = renderStrings.get(); - float startY = relativeY + padding; + int lineHeight = getLineHeight(); + int minY = relativeY + padding; + int maxY = minY + lineHeight; + int heightToNextLine = lineHeight + spacing; if (centerY) { - int listSize = list.size(); - int totalHeight = listSize * 8 + spacing * (listSize - 1); - startY = relativeY + (getHeight() - totalHeight) / 2F; + int totalHeight = heightToNextLine * list.size() - spacing; + float center = (getHeight() - totalHeight) / 2F; + //If center is not evenly divisible, this will make it so that when we divide to find the target y in scrolling string + // it gets the correct position + minY = relativeY + Mth.floor(center); + maxY = relativeY + lineHeight + Mth.ceil(center); } + int maxTextWidth = getMaxTextWidth(); + int minX = relativeX + padding; + int maxX = relativeX + maxTextWidth - padding; + int screenTextColor = screenTextColor(); for (Component text : renderStrings.get()) { - drawText(guiGraphics, text, relativeX + padding, startY); - startY += 8 + spacing; + drawScaledScrollingString(guiGraphics, text, minX, minY, maxX, maxY, TextAlignment.LEFT, screenTextColor, false, textScale); + minY += heightToNextLine; + maxY += heightToNextLine; } } } @@ -112,12 +128,8 @@ public void updateTooltip(int mouseX, int mouseY) { setTooltip(lastTooltip); } - private void drawText(GuiGraphics guiGraphics, Component text, float x, float y) { - drawScaledTextScaledBound(guiGraphics, text, x, y, screenTextColor(), getMaxTextWidth(), textScale); - } - protected int getMaxTextWidth() { - return getWidth() - padding * 2; + return getWidth(); } @NotNull diff --git a/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java b/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java index 928e60770fa..9a7f3cebaea 100644 --- a/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java +++ b/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java @@ -15,7 +15,7 @@ public class GuiScreenSwitch extends GuiInnerScreen { private final IClickable onToggle; public GuiScreenSwitch(IGuiWrapper gui, int x, int y, int width, Component buttonName, BooleanSupplier stateSupplier, IClickable onToggle) { - super(gui, x, y, width, GuiDigitalSwitch.BUTTON_SIZE_Y * 2 + 5, () -> Collections.singletonList(buttonName)); + super(gui, x, y, width, GuiDigitalSwitch.BUTTON_SIZE_Y * 2 + 6, () -> Collections.singletonList(buttonName)); this.stateSupplier = stateSupplier; this.onToggle = onToggle; this.active = true; @@ -28,15 +28,18 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks); int buttonSizeX = GuiDigitalSwitch.BUTTON_SIZE_X; int buttonSizeY = GuiDigitalSwitch.BUTTON_SIZE_Y; - guiGraphics.blit(GuiDigitalSwitch.SWITCH, relativeX + width - 2 - buttonSizeX, relativeY + 2, 0, stateSupplier.getAsBoolean() ? 0 : buttonSizeY, buttonSizeX, buttonSizeY, buttonSizeX, buttonSizeY * 2); - guiGraphics.blit(GuiDigitalSwitch.SWITCH, relativeX + width - 2 - buttonSizeX, relativeY + 2 + buttonSizeY + 1, 0, stateSupplier.getAsBoolean() ? buttonSizeY : 0, buttonSizeX, buttonSizeY, buttonSizeX, buttonSizeY * 2); + int buttonXOffset = width - 2 - buttonSizeX; + guiGraphics.blit(GuiDigitalSwitch.SWITCH, relativeX + buttonXOffset, relativeY + 2, 0, stateSupplier.getAsBoolean() ? 0 : buttonSizeY, buttonSizeX, buttonSizeY, buttonSizeX, buttonSizeY * 2); + guiGraphics.blit(GuiDigitalSwitch.SWITCH, relativeX + buttonXOffset, relativeY + 2 + buttonSizeY + 1, 0, stateSupplier.getAsBoolean() ? buttonSizeY : 0, buttonSizeX, buttonSizeY, buttonSizeX, buttonSizeY * 2); } @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - drawScaledCenteredText(guiGraphics, MekanismLang.ON.translate(), relativeX + width - 9, relativeY + 2, 0x101010, 0.5F); - drawScaledCenteredText(guiGraphics, MekanismLang.OFF.translate(), relativeX + width - 9, relativeY + 11, 0x101010, 0.5F); + int buttonSizeX = GuiDigitalSwitch.BUTTON_SIZE_X; + int buttonXOffset = width - 2 - buttonSizeX; + drawScaledScrollingString(guiGraphics, MekanismLang.ON.translate(), buttonXOffset, 2, TextAlignment.CENTER, 0x101010, buttonSizeX, 1, false, 0.5F); + drawScaledScrollingString(guiGraphics, MekanismLang.OFF.translate(), buttonXOffset, 11, TextAlignment.CENTER, 0x101010, buttonSizeX, 1, false, 0.5F); } @Override diff --git a/src/main/java/mekanism/client/gui/element/button/FilterButton.java b/src/main/java/mekanism/client/gui/element/button/FilterButton.java index 404aa3e31aa..f516696085d 100644 --- a/src/main/java/mekanism/client/gui/element/button/FilterButton.java +++ b/src/main/java/mekanism/client/gui/element/button/FilterButton.java @@ -7,6 +7,7 @@ import java.util.function.ObjIntConsumer; import java.util.function.Predicate; import mekanism.api.text.EnumColor; +import mekanism.api.text.TextComponentUtil; import mekanism.client.gui.GuiUtils; import mekanism.client.gui.IGuiWrapper; import mekanism.client.gui.element.slot.GuiSequencedSlotDisplay; @@ -147,18 +148,23 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { guiGraphics.fill(colorX + 1, colorY + 1, colorX + 5, colorY + 5, sorterFilter.color.getPackedColor()); } - drawTextWithScale(guiGraphics, sorterFilter.color == null ? MekanismLang.NO_COLOR.translate() : sorterFilter.color.getName(), relativeX + 22 + 8, relativeY + 12, - titleTextColor(), 0.5f); + Component color = sorterFilter.color == null ? MekanismLang.NO_COLOR.translate() : sorterFilter.color.getName(); + drawScaledScrollingString(guiGraphics, color, 27, 12, TextAlignment.LEFT, titleTextColor(), getSmallTextWidth() - 8, 3, false, 0.7F); } else if (filter instanceof OredictionificatorItemFilter oreDictFilter) { - drawTextWithScale(guiGraphics, oreDictFilter.getResult().getHoverName().copy().append(" (" + BuiltInRegistries.ITEM.getKey(oreDictFilter.getResultElement()).getNamespace() + ")"), relativeX + 22, relativeY + 12, - titleTextColor(), 0.5f); + ItemStack result = oreDictFilter.getResult(); + Component text = TextComponentUtil.build(result, " (", BuiltInRegistries.ITEM.getKey(result.getItem()).getNamespace(), ")"); + drawScaledScrollingString(guiGraphics, text, 19, 12, TextAlignment.LEFT, titleTextColor(), getSmallTextWidth(), 3, false, 0.7F); } else if (filter instanceof QIOItemStackFilter itemFilter) { if (itemFilter.fuzzyMode) { - drawTextWithScale(guiGraphics, MekanismLang.FUZZY_MODE.translate(), relativeX + 22, relativeY + 12, titleTextColor(), 0.5f); + drawScaledScrollingString(guiGraphics, MekanismLang.FUZZY_MODE.translate(), 19, 12, TextAlignment.LEFT, titleTextColor(), getSmallTextWidth(), 3, false, 0.7F); } } } + private int getSmallTextWidth() { + return this.width - RadioButton.RADIO_SIZE - getToggleXShift() - 19; + } + private void drawFilterDescriptor(GuiGraphics guiGraphics, Component component, int x, int y) { drawTextScaledBound(guiGraphics, component, x + 22, y + 3, titleTextColor(), getMaxLength()); } diff --git a/src/main/java/mekanism/client/gui/element/button/GuiGasMode.java b/src/main/java/mekanism/client/gui/element/button/GuiGasMode.java index 91eec01551c..543433e590f 100644 --- a/src/main/java/mekanism/client/gui/element/button/GuiGasMode.java +++ b/src/main/java/mekanism/client/gui/element/button/GuiGasMode.java @@ -51,7 +51,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { //Draw the text next to the button Component component = gasModeSupplier.get().getTextComponent(); if (left) { - drawTextScaledBound(guiGraphics, component, relativeX - 3 - (int) (getStringWidth(component) * getNeededScale(component, 66)), relativeY + 1, titleTextColor(), 66); + drawTextScaledBound(guiGraphics, component, relativeX - 3 - Math.min(getStringWidth(component), 66), relativeY + 1, titleTextColor(), 66); } else { drawTextScaledBound(guiGraphics, component, relativeX + width + 5, relativeY + 1, titleTextColor(), 66); } diff --git a/src/main/java/mekanism/client/gui/element/button/SideDataButton.java b/src/main/java/mekanism/client/gui/element/button/SideDataButton.java index 7a60154ae15..23f2e4cc507 100644 --- a/src/main/java/mekanism/client/gui/element/button/SideDataButton.java +++ b/src/main/java/mekanism/client/gui/element/button/SideDataButton.java @@ -84,7 +84,7 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks); if (!otherBlockItem.isEmpty()) { - GuiUtils.renderItem(guiGraphics, otherBlockItem, this.getRelativeX() + 3, this.getRelativeY() + 3, 1, getFont(), null, true); + GuiUtils.renderItem(guiGraphics, otherBlockItem, this.getRelativeX() + 3, this.getRelativeY() + 3, 1, font(), null, true); } } diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java b/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java index 3179a98f6d7..4918b524b49 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java @@ -37,6 +37,7 @@ import mekanism.common.util.text.OwnerDisplay; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import org.jetbrains.annotations.Nullable; @@ -212,19 +213,23 @@ private void setFrequency(String freq, @Nullable UUID ownerUUID) { public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); FREQ frequency = frequencySelector.getFrequency(); + Object frequencyName; + Component ownerComponent; + Object frequencySecurity; if (frequency == null) { MutableComponent noneComponent = MekanismLang.NONE.translateColored(EnumColor.DARK_RED); - drawString(guiGraphics, MekanismLang.FREQUENCY.translate(noneComponent), 27, yStart + 67, titleTextColor()); - drawString(guiGraphics, MekanismLang.OWNER.translate(noneComponent), 27, yStart + 77, titleTextColor()); - drawString(guiGraphics, MekanismLang.SECURITY.translate(noneComponent), 27, yStart + 87, titleTextColor()); + frequencyName = noneComponent; + ownerComponent = MekanismLang.OWNER.translate(noneComponent); + frequencySecurity = noneComponent; } else { //Color the name the same as the subheading text color should be - MutableComponent name = TextComponentUtil.color(TextComponentUtil.getString(frequency.getName()), subheadingTextColor()); - drawTextScaledBound(guiGraphics, MekanismLang.FREQUENCY.translate(name), 27, yStart + 67, titleTextColor(), getGuiWidth() - 36); - drawString(guiGraphics, OwnerDisplay.of(Minecraft.getInstance().player, frequency.getOwner(), frequency.getOwnerName(), false).getTextComponent(), - 27, yStart + 77, titleTextColor()); - drawString(guiGraphics, MekanismLang.SECURITY.translate(frequency.getSecurity()), 27, yStart + 87, titleTextColor()); + frequencyName = TextComponentUtil.color(TextComponentUtil.getString(frequency.getName()), subheadingTextColor()); + ownerComponent = OwnerDisplay.of(Minecraft.getInstance().player, frequency.getOwner(), frequency.getOwnerName(), false).getTextComponent(); + frequencySecurity = frequency.getSecurity(); } + drawTextScaledBound(guiGraphics, MekanismLang.FREQUENCY.translate(frequencyName), 27, yStart + 67, titleTextColor(), getGuiWidth() - 36); + drawTextScaledBound(guiGraphics, ownerComponent, 27, yStart + 77, titleTextColor(), getGuiWidth() - 36); + drawTextScaledBound(guiGraphics, MekanismLang.SECURITY.translate(frequencySecurity), 27, yStart + 87, titleTextColor(), getGuiWidth() - 36); drawTextScaledBound(guiGraphics, MekanismLang.SET.translate(), 27, yStart + 100, titleTextColor(), 20); } diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiQIOFrequencyDataScreen.java b/src/main/java/mekanism/client/gui/element/custom/GuiQIOFrequencyDataScreen.java index a664c51b8c9..60028f30c88 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiQIOFrequencyDataScreen.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiQIOFrequencyDataScreen.java @@ -33,7 +33,7 @@ public Component getTooltip() { return freq == null ? null : MekanismLang.QIO_ITEMS_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(freq.getTotalItemCount()), TextUtils.format(freq.getTotalItemCountCapacity())); } - }, relativeX + (width / 4) - (50 / 2), relativeY + 20, 50)); + }, relativeX + 11, relativeY + 20, 50)); addChild(new GuiDigitalBar(gui, new IBarInfoHandler() { @Override public double getLevel() { @@ -47,7 +47,7 @@ public Component getTooltip() { return freq == null ? null : MekanismLang.QIO_TYPES_DETAIL.translateColored(EnumColor.GRAY, EnumColor.INDIGO, TextUtils.format(freq.getTotalItemTypes(true)), TextUtils.format(freq.getTotalItemTypeCapacity())); } - }, relativeX + (3 * width / 4) - (50 / 2), relativeY + 20, 50)); + }, relativeX + 83, relativeY + 20, 50)); } @Override @@ -55,9 +55,9 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); QIOFrequency freq = frequencySupplier.get(); if (freq != null) { - drawScaledTextScaledBound(guiGraphics, MekanismLang.FREQUENCY.translate(freq.getName()), relativeX + 5, relativeY + 5, screenTextColor(), width - 10, 0.8F); + drawScaledScrollingString(guiGraphics, MekanismLang.FREQUENCY.translate(freq.getName()), 0, 5, TextAlignment.LEFT, screenTextColor(), 5, false, 0.8F); } - drawScaledCenteredText(guiGraphics, MekanismLang.QIO_ITEMS.translate(), relativeX + (width / 4), relativeY + 32, screenTextColor(), 0.8F); - drawScaledCenteredText(guiGraphics, MekanismLang.QIO_TYPES.translate(), relativeX + (3 * width / 4), relativeY + 32, screenTextColor(), 0.8F); + drawScaledScrollingString(guiGraphics, MekanismLang.QIO_ITEMS.translate(), 11, 32, TextAlignment.CENTER, screenTextColor(), 50, 0, false, 0.8F); + drawScaledScrollingString(guiGraphics, MekanismLang.QIO_TYPES.translate(), 83, 32, TextAlignment.CENTER, screenTextColor(), 50, 0, false, 0.8F); } } diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java b/src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java index 1145438c5c3..ce2d863b7cd 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java @@ -29,10 +29,10 @@ public class GuiResizeControls extends GuiSideHolder { private static final ResourceLocation PLUS = MekanismUtils.getResource(ResourceType.GUI_BUTTON, "plus.png"); public GuiResizeControls(GUI gui, int y) { - super(gui, -26, y, 39, true, false); + super(gui, -26, y, 40, true, false); expandButton = addChild(new MekanismImageButton(gui, relativeX + 4, relativeY + 5, 19, 9, 19, 9, PLUS, (element, mouseX, mouseY) -> handleResize(ResizeType.EXPAND_Y, Screen.hasShiftDown()))); - shrinkButton = addChild(new MekanismImageButton(gui, relativeX + 4, relativeY + 25, 19, 9, 19, 9, MINUS, + shrinkButton = addChild(new MekanismImageButton(gui, relativeX + 4, relativeY + 26, 19, 9, 19, 9, MINUS, (element, mouseX, mouseY) -> handleResize(ResizeType.SHRINK_Y, Screen.hasShiftDown()))); updateButtonState(); active = true; @@ -56,7 +56,7 @@ public void updateTooltip(int mouseX, int mouseY) { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - drawScaledCenteredTextScaledBound(guiGraphics, MekanismLang.HEIGHT.translate(), relativeX + 13.5F, relativeY + 15.5F, titleTextColor(), width - 4, 0.7F); + drawScaledScrollingString(guiGraphics, MekanismLang.HEIGHT.translate(), 0, 16, TextAlignment.CENTER, titleTextColor(), 4, false, 0.60F); } @Override diff --git a/src/main/java/mekanism/client/gui/element/custom/module/BooleanToggle.java b/src/main/java/mekanism/client/gui/element/custom/module/BooleanToggle.java index 7170b1fa90d..51ef789ea5e 100644 --- a/src/main/java/mekanism/client/gui/element/custom/module/BooleanToggle.java +++ b/src/main/java/mekanism/client/gui/element/custom/module/BooleanToggle.java @@ -3,6 +3,7 @@ import mekanism.api.gear.config.ModuleBooleanConfig; import mekanism.client.gui.element.button.RadioButton; import mekanism.client.gui.element.scroll.GuiScrollList; +import mekanism.client.render.IFancyFontRenderer.TextAlignment; import mekanism.common.MekanismLang; import mekanism.common.registries.MekanismSounds; import net.minecraft.client.Minecraft; @@ -41,9 +42,15 @@ private void drawRadio(GuiGraphics guiGraphics, int mouseX, int mouseY, boolean @Override protected void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { int textColor = parent.screenTextColor(); - parent.drawScaledTextScaledBound(guiGraphics, description, getRelativeX() + 3, getRelativeY(), textColor, this.parent.getScreenWidth() - 3 - GuiScrollList.TEXTURE_WIDTH, 0.8F); - parent.drawTextWithScale(guiGraphics, MekanismLang.TRUE.translate(), getRelativeX() + 16, getRelativeY() + 11, textColor, 0.8F); - parent.drawTextWithScale(guiGraphics, MekanismLang.FALSE.translate(), getRelativeX() + 62, getRelativeY() + 11, textColor, 0.8F); + parent.drawScaledScrollingString(guiGraphics, description, xPos, yPos, TextAlignment.LEFT, textColor, parent.getScreenWidth() - GuiScrollList.TEXTURE_WIDTH, + 2, false, 0.8F); + + int trueShift = 4 + RADIO_SIZE; + int falseShift = 50 + RADIO_SIZE; + parent.drawScaledScrollingString(guiGraphics, MekanismLang.TRUE.translate(), xPos + trueShift, yPos + 11, TextAlignment.LEFT, textColor, + 50 - trueShift, 3, false, 0.8F); + parent.drawScaledScrollingString(guiGraphics, MekanismLang.FALSE.translate(), xPos + falseShift, yPos + 11, TextAlignment.LEFT, textColor, + parent.getScreenWidth() - GuiScrollList.TEXTURE_WIDTH - falseShift, 3, false, 0.8F); } @Override diff --git a/src/main/java/mekanism/client/gui/element/custom/module/ColorSelection.java b/src/main/java/mekanism/client/gui/element/custom/module/ColorSelection.java index 69c8e48535e..a76557f53ce 100644 --- a/src/main/java/mekanism/client/gui/element/custom/module/ColorSelection.java +++ b/src/main/java/mekanism/client/gui/element/custom/module/ColorSelection.java @@ -7,9 +7,9 @@ import mekanism.api.gear.config.ModuleColorConfig; import mekanism.client.gui.GuiModuleTweaker; import mekanism.client.gui.GuiUtils; -import mekanism.client.gui.element.scroll.GuiScrollList; import mekanism.client.gui.element.text.GuiTextField; import mekanism.client.gui.element.window.GuiColorWindow; +import mekanism.client.render.IFancyFontRenderer.TextAlignment; import mekanism.common.MekanismLang; import mekanism.common.content.gear.shared.ModuleColorModulationUnit; import mekanism.common.lib.Color; @@ -63,14 +63,15 @@ protected void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY) @Override protected void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { int textColor = parent.screenTextColor(); - parent.drawScaledTextScaledBound(guiGraphics, description, getRelativeX() + 3, getRelativeY(), textColor, this.parent.getScreenWidth() - 3 - GuiScrollList.TEXTURE_WIDTH, 0.8F); + parent.drawScaledScrollingString(guiGraphics, description, xPos, yPos, TextAlignment.LEFT, textColor, OFFSET_X, 3, false, 0.8F); String hex; if (supportsAlpha) { hex = TextUtils.hex(false, 4, data.get()); } else { hex = TextUtils.hex(false, 3, getColor().rgb()); } - parent.drawTextExact(guiGraphics, MekanismLang.GENERIC_HEX.translate(hex), getRelativeX() + 3, getRelativeY() + 11, textColor); + //TODO: Do we want to draw the hex in the RGB color it is set to (intentionally ignore alpha) + parent.drawScrollingString(guiGraphics, MekanismLang.GENERIC_HEX.translate(hex), xPos, yPos + 11, TextAlignment.LEFT, textColor, OFFSET_X, 3, false); } @Override diff --git a/src/main/java/mekanism/client/gui/element/custom/module/EnumToggle.java b/src/main/java/mekanism/client/gui/element/custom/module/EnumToggle.java index dd1e00eb157..90b3c55b49c 100644 --- a/src/main/java/mekanism/client/gui/element/custom/module/EnumToggle.java +++ b/src/main/java/mekanism/client/gui/element/custom/module/EnumToggle.java @@ -6,6 +6,7 @@ import mekanism.api.text.IHasTextComponent; import mekanism.client.gui.GuiUtils; import mekanism.client.gui.element.scroll.GuiScrollList; +import mekanism.client.render.IFancyFontRenderer.TextAlignment; import mekanism.common.MekanismLang; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; @@ -31,7 +32,7 @@ class EnumToggle & IHasTextComponent> extends MiniElemen BAR_LENGTH = this.parent.getScreenWidth() - 24; enumConstants = data.getEnumConstants(); this.optionDistance = (BAR_LENGTH / (enumConstants.size() - 1)); - this.usesIcons = enumConstants.stream().findFirst().filter(option -> option instanceof IHasModeIcon).isPresent(); + this.usesIcons = !enumConstants.isEmpty() && enumConstants.getFirst() instanceof IHasModeIcon; } @Override @@ -53,24 +54,11 @@ protected void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) if (usesIcons) { description = MekanismLang.GENERIC_STORED.translate(description, data.get()); } - parent.drawScaledTextScaledBound(guiGraphics, description, getRelativeX() + 3, getRelativeY(), textColor, this.parent.getScreenWidth() - 3 - GuiScrollList.TEXTURE_WIDTH, 0.8F); + parent.drawScaledScrollingString(guiGraphics, description, xPos, yPos, TextAlignment.LEFT, textColor, parent.getScreenWidth() - GuiScrollList.TEXTURE_WIDTH, + 2, false, 0.8F); for (TYPE option : enumConstants) { Component text = option.getTextComponent(); - //Similar to logic for drawScaledCenteredText except shifts values slightly if they go past the max length - int textWidth = parent.getStringWidth(text); - float widthScaling = usesIcons ? 2.5F : (textWidth / 2F) * TEXT_SCALE; int optionCenter = BAR_START + optionDistance * option.ordinal(); - float left = optionCenter - widthScaling; - if (left < 0) { - left = 0; - } else { - int max = parent.getScreenWidth() - 1; - float objectWidth = usesIcons ? 5 : textWidth * TEXT_SCALE; - int end = xPos + Mth.ceil(left + objectWidth); - if (end > max) { - left -= end - max; - } - } int color = textColor; if (text.getStyle().getColor() != null) { color = 0xFF000000 | text.getStyle().getColor().getValue(); @@ -80,7 +68,25 @@ protected void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) IHasModeIcon hasModeIcon = (IHasModeIcon) option; guiGraphics.blit(hasModeIcon.getModeIcon(), getRelativeX() + optionCenter - 8, getRelativeY() + 19, 0, 0, 16, 16, 16, 16); } else { - parent.drawTextWithScale(guiGraphics, text, getRelativeX() + left, getRelativeY() + 20, textColor, TEXT_SCALE); + //Similar to logic for drawScaledCenteredText except shifts values slightly if they go past the max length + int textWidth = parent.getStringWidth(text); + float objectWidth = textWidth * TEXT_SCALE; + if (optionCenter < objectWidth / 2) { + //Note: We know it will overflow, so it doesn't actually matter if we center it here or not + // We can also take some shortcuts calculating the width, as it goes all the way to zero + parent.drawScaledScrollingString(guiGraphics, text, xPos, yPos + 20, TextAlignment.CENTER, textColor, BAR_START + optionDistance / 2, + 1, false, TEXT_SCALE); + } else { + int max = parent.getScreenWidth() - 1; + int start = xPos + optionCenter - optionDistance / 2; + if (start + Mth.ceil(objectWidth) > max) { + //Note: We know it will overflow, so it doesn't actually matter if we center it here or not + parent.drawScaledScrollingString(guiGraphics, text, start, yPos + 20, TextAlignment.CENTER, textColor, max - start, 1, false, TEXT_SCALE); + } else { + //TODO: For some things like locomotive boosting unit, this is ever so slightly off-center. Do we care enough to adjust it? + parent.drawScaledScrollingString(guiGraphics, text, start, yPos + 20, TextAlignment.CENTER, textColor, optionDistance, 1, false, TEXT_SCALE); + } + } } } } diff --git a/src/main/java/mekanism/client/gui/element/custom/module/GuiModuleScreen.java b/src/main/java/mekanism/client/gui/element/custom/module/GuiModuleScreen.java index 1a4af8a61e3..59fc3ef1ef5 100644 --- a/src/main/java/mekanism/client/gui/element/custom/module/GuiModuleScreen.java +++ b/src/main/java/mekanism/client/gui/element/custom/module/GuiModuleScreen.java @@ -95,7 +95,7 @@ public void setModule(@Nullable Module module) { } private static int getStartY(@Nullable IModule module) { - int startY = 5; + int startY = ELEMENT_SPACER + 1; if (module != null) { if (module.getData().isExclusive(ExclusiveFlag.ANY)) { startY += 13; @@ -191,18 +191,19 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mx, int my, flo public void renderForeground(GuiGraphics guiGraphics, int mx, int my) { super.renderForeground(guiGraphics, mx, my); scissorScreen(guiGraphics, mx, my, (g, mouseX, mouseY, module, shift) -> { - int startY = 5; + int startY = ELEMENT_SPACER + 1; if (module != null) { if (module.getData().isExclusive(ExclusiveFlag.ANY)) { if (startY + 13 > shift) { - drawTextWithScale(g, MekanismLang.MODULE_EXCLUSIVE.translate(), relativeX + 5, relativeY + startY, 0x635BD4, 0.8F); + drawScaledScrollingString(g, MekanismLang.MODULE_EXCLUSIVE.translate(), 2, startY, TextAlignment.LEFT, 0x635BD4, + getScreenWidth() - GuiScrollList.TEXTURE_WIDTH, 2, false, 0.8F); } startY += 13; } if (module.getData().getMaxStackSize() > 1) { if (startY + 13 > shift) { - drawTextWithScale(g, MekanismLang.MODULE_INSTALLED.translate(module.getInstalledCount()), relativeX + 5, relativeY + startY, - screenTextColor(), 0.8F); + drawScaledScrollingString(g, MekanismLang.MODULE_INSTALLED.translate(module.getInstalledCount()), 2, startY, TextAlignment.LEFT, screenTextColor(), + getScreenWidth() - GuiScrollList.TEXTURE_WIDTH, 2, false, 0.8F); } startY += 13; } diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java b/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java index fd6e16e1080..95061846d12 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java @@ -136,7 +136,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { if (instance != null) { boolean enabled = instance.isEnabled(); int color = module.isExclusive(ExclusiveFlag.ANY) ? (enabled ? 0x635BD4 : 0x2E2A69) : (enabled ? titleTextColor() : 0x5E1D1D); - drawScaledTextScaledBound(guiGraphics, TextComponentUtil.build(module), relativeX + 13, relativeY + 3 + multipliedElement, color, 86, 0.7F); + drawScaledScrollingString(guiGraphics, TextComponentUtil.build(module), 12, 3 + multipliedElement, TextAlignment.LEFT, color, barXShift - 14, 2, false, 0.7F); } } }); @@ -195,12 +195,10 @@ public void renderElements(GuiGraphics guiGraphics, int mouseX, int mouseY, floa } private void forEachModule(ObjIntConsumer> consumer) { - for (int i = 0; i < getFocusedElements(); i++) { - int index = getCurrentSelection() + i; - if (index > currentList.size() - 1) { - break; - } - consumer.accept(currentList.get(index), elementHeight * i); + int currentSelection = getCurrentSelection(); + int max = Math.min(getFocusedElements(), currentList.size()); + for (int i = 0; i < max; i++) { + consumer.accept(currentList.get(currentSelection + i), elementHeight * i); } } diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiSlotScroll.java b/src/main/java/mekanism/client/gui/element/scroll/GuiSlotScroll.java index 7f7f8b43d8d..9057b034414 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiSlotScroll.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiSlotScroll.java @@ -1,13 +1,12 @@ package mekanism.client.gui.element.scroll; import com.mojang.blaze3d.vertex.PoseStack; -import java.math.RoundingMode; -import java.text.DecimalFormat; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Supplier; import mekanism.api.text.EnumColor; +import mekanism.api.text.TextComponentUtil; import mekanism.client.gui.IGuiWrapper; import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.slot.GuiSlot; @@ -19,12 +18,13 @@ import mekanism.common.lib.inventory.HashedItem; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; +import mekanism.common.util.UnitDisplayUtils; import mekanism.common.util.text.TextUtils; -import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.Rect2i; import net.minecraft.client.renderer.RenderType; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; @@ -35,7 +35,6 @@ public class GuiSlotScroll extends GuiElement implements IRecipeViewerIngredient private static final ResourceLocation SLOTS = MekanismUtils.getResource(ResourceType.GUI_SLOT, "slots.png"); private static final ResourceLocation SLOTS_DARK = MekanismUtils.getResource(ResourceType.GUI_SLOT, "slots_dark.png"); - private static final DecimalFormat COUNT_FORMAT = Util.make(new DecimalFormat("#.#"), format -> format.setRoundingMode(RoundingMode.FLOOR)); private final GuiScrollBar scrollBar; @@ -67,8 +66,7 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou if (slot >= list.size()) { break; } - int slotX = relativeX + (i % xSlots) * 18, slotY = relativeY + (i / xSlots) * 18; - renderSlot(guiGraphics, list.get(slot), slotX, slotY); + renderSlot(guiGraphics, list.get(slot), 18 * (i % xSlots), 18 * (i / xSlots)); } } } @@ -139,9 +137,18 @@ private void renderSlot(GuiGraphics guiGraphics, IScrollableSlot slot, int slotX if (isSlotEmpty(slot)) { return; } - gui().renderItemWithOverlay(guiGraphics, slot.item().getInternalStack(), slotX + 1, slotY + 1, 1, ""); - if (slot.count() > 1) { - renderSlotText(guiGraphics, getCountText(slot.count()), slotX + 1, slotY + 1); + gui().renderItemWithOverlay(guiGraphics, slot.item().getInternalStack(), relativeX + slotX + 1, relativeY + slotY + 1, 1, ""); + long count = slot.count(); + if (count > 1) { + Component text; + //Note: For cases like 9,999,999 we intentionally display as 9999.9K instead of 10M so that people + // do not think they have more stored than they actually have just because it is rounding up + if (count < 10_000) { + text = TextComponentUtil.getString(Long.toString(count)); + } else { + text = UnitDisplayUtils.getDisplay(count, 1); + } + renderSlotText(guiGraphics, text, slotX + 1, slotY + 1); } } @@ -172,38 +179,21 @@ private boolean isSlotEmpty(IScrollableSlot slot) { return item == null || item.getInternalStack().isEmpty(); } - private void renderSlotText(GuiGraphics guiGraphics, String text, int x, int y) { + private void renderSlotText(GuiGraphics guiGraphics, Component text, int x, int y) { + float scale = 0.6F; + float scaledWidth = getStringWidth(text) * scale; + if (scaledWidth >= 16) { + //If we need a lower scale slightly due to having a lot of text, calculate it + //Note: If it would still overflow, then we just let the scrolling text handle it + scale = 0.5F; + } PoseStack pose = guiGraphics.pose(); pose.pushPose(); - float scale = 0.6F; - int width = getFont().width(text); - //If we need a lower scale due to having a lot of text, calculate it - scale = Math.min(1, 16F / (width * scale)) * scale; - float yAdd = 4 - (scale * 8) / 2F; - pose.translate(x + 16 - width * scale, y + 9 + yAdd, 200F); - pose.scale(scale, scale, scale); - - guiGraphics.drawString(getFont(), text, 0, 0, 0xFFFFFF); + pose.translate(0, 0, 200); + drawScaledScrollingString(guiGraphics, text, x, y + 9, TextAlignment.RIGHT, 0xFFFFFF, 16, 0, true, scale); pose.popPose(); } - private String getCountText(long count) { - //Note: For cases like 9,999,999 we intentionally display as 9999.9K instead of 10M so that people - // do not think they have more stored than they actually have just because it is rounding up - if (count <= 1) { - return null; - } else if (count < 10_000) { - return Long.toString(count); - } else if (count < 10_000_000) { - return COUNT_FORMAT.format(count / 1_000D) + "K"; - } else if (count < 10_000_000_000L) { - return COUNT_FORMAT.format(count / 1_000_000D) + "M"; - } else if (count < 10_000_000_000_000L) { - return COUNT_FORMAT.format(count / 1_000_000_000D) + "B"; - } - return ">10T"; - } - private List getSlotList() { return slotList.get(); } diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiTextScrollList.java b/src/main/java/mekanism/client/gui/element/scroll/GuiTextScrollList.java index 6676ef6d800..2949ec9a747 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiTextScrollList.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiTextScrollList.java @@ -67,8 +67,8 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { for (int i = 0; i < focusedElements; i++) { int index = scrollIndex + i; if (index < maxElements) { - drawScaledTextScaledBound(guiGraphics, TextComponentUtil.getString(textEntries.get(index)), relativeX + 2, relativeY + 2 + elementHeight * i, - screenTextColor(), barXShift - 2, 0.8F); + drawScaledScrollingString(guiGraphics, TextComponentUtil.getString(textEntries.get(index)), 0, 2 + elementHeight * i, TextAlignment.LEFT, + screenTextColor(), barXShift, 2, false, 0.8F); } } } diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java b/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java index bf9315b0c25..f459bc30fa4 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java @@ -143,12 +143,9 @@ public void renderElements(GuiGraphics guiGraphics, int mouseX, int mouseY, floa private void forEachUpgrade(ObjIntConsumer consumer) { Upgrade[] upgrades = getCurrentUpgrades().toArray(new Upgrade[0]); int currentSelection = getCurrentSelection(); - for (int i = 0; i < getFocusedElements(); i++) { - int index = currentSelection + i; - if (index > upgrades.length - 1) { - break; - } - consumer.accept(upgrades[index], elementHeight * i); + int max = Math.min(getFocusedElements(), upgrades.length); + for (int i = 0; i < max; i++) { + consumer.accept(upgrades[currentSelection + i], elementHeight * i); } } diff --git a/src/main/java/mekanism/client/gui/element/text/GuiTextField.java b/src/main/java/mekanism/client/gui/element/text/GuiTextField.java index 3ac28cdce01..e9d0ce33053 100644 --- a/src/main/java/mekanism/client/gui/element/text/GuiTextField.java +++ b/src/main/java/mekanism/client/gui/element/text/GuiTextField.java @@ -60,7 +60,7 @@ public GuiTextField(IGuiWrapper gui, ContainerEventHandler parent, int x, int y, super(gui, x, y, width, height); this.parent = parent; - textField = new ClearingEditBox(getFont(), getX(), getY(), width, height, Component.empty()); + textField = new ClearingEditBox(font(), getX(), getY(), width, height, Component.empty()); textField.setBordered(false); textField.setResponder(s -> { if (responder != null) { @@ -214,10 +214,9 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou textField.render(guiGraphics, mouseX, mouseY, partialTicks); } else { // hacky. we should write our own renderer at some point. - float reverse = (1 / textScale) - 1; - float yAdd = 4 - (textScale * 8) / 2F; + float reverse = (1 - textScale) / textScale; pose.scale(textScale, textScale, textScale); - pose.translate(textField.getX() * reverse, textField.getY() * reverse + yAdd / textScale, 0); + pose.translate(textField.getX() * reverse, (textField.getY() + 4) * reverse, 0); textField.render(guiGraphics, mouseX, mouseY, partialTicks); } pose.popPose(); diff --git a/src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java index 3ceb94abed1..770030e561b 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java @@ -125,7 +125,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { drawTitleText(guiGraphics, MekanismLang.COLOR_PICKER.translate(), 6); ILangEntry entry = handlesAlpha ? MekanismLang.RGBA : MekanismLang.RGB; int textOffset = handlesAlpha ? 6 : 0; - drawTextScaledBound(guiGraphics, entry.translate(), relativeX + 7, relativeY + height - 18F, titleTextColor(), 20 + textOffset); + drawTextScaledBound(guiGraphics, entry.translate(), relativeX + 7, relativeY + height - 18, titleTextColor(), 20 + textOffset); } private void drawTiledGradient(GuiGraphics guiGraphics, int x, int y, int width, int height) { diff --git a/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java b/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java index e47916a8efa..384f94f1c19 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java @@ -27,14 +27,14 @@ private GuiConfirmationDialog(IGuiWrapper gui, int x, int y, int width, int heig public static void show(IGuiWrapper gui, Component title, Runnable onConfirm, DialogType type) { int width = 140; - int height = 33 + WrappedTextRenderer.calculateHeightRequired(gui.getFont(), title, width, width - 10); + int height = 33 + WrappedTextRenderer.calculateHeightRequired(gui.font(), title, width, width - 10); gui.addWindow(new GuiConfirmationDialog(gui, (gui.getXSize() - width) / 2, (gui.getYSize() - height) / 2, width, height, title, onConfirm, type)); } @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - wrappedTextRenderer.renderCentered(guiGraphics, relativeX + (width / 2F), relativeY + 6, titleTextColor(), width - 10); + wrappedTextRenderer.renderCentered(guiGraphics, relativeX, relativeY + 6, titleTextColor(), width - 10); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/GuiMekaSuitHelmetOptions.java b/src/main/java/mekanism/client/gui/element/window/GuiMekaSuitHelmetOptions.java index 654e269b254..68a65e4e379 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiMekaSuitHelmetOptions.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiMekaSuitHelmetOptions.java @@ -59,13 +59,13 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); drawTitleText(guiGraphics, MekanismLang.HELMET_OPTIONS.translate(), 6); - drawTextExact(guiGraphics, MekanismLang.HUD_OVERLAY.translate(), relativeX + 7, relativeY + 20, headingTextColor()); + drawScrollingString(guiGraphics, MekanismLang.HUD_OVERLAY.translate(), 0, 20, TextAlignment.LEFT, headingTextColor(), 7, false); - drawScaledCenteredText(guiGraphics, MekanismLang.DEFAULT.translate(), relativeX + 21, relativeY + 52, subheadingTextColor(), 0.8F); - drawScaledCenteredText(guiGraphics, MekanismLang.WARNING.translate(), relativeX + 70, relativeY + 52, subheadingTextColor(), 0.8F); - drawScaledCenteredText(guiGraphics, MekanismLang.DANGER.translate(), relativeX + 119, relativeY + 52, subheadingTextColor(), 0.8F); + drawScaledScrollingString(guiGraphics, MekanismLang.DEFAULT.translate(), 6, 52, TextAlignment.CENTER, subheadingTextColor(), 32, 0, false, 0.8F); + drawScaledScrollingString(guiGraphics, MekanismLang.WARNING.translate(), 55, 52, TextAlignment.CENTER, subheadingTextColor(), 32, 0, false, 0.8F); + drawScaledScrollingString(guiGraphics, MekanismLang.DANGER.translate(), 104, 52, TextAlignment.CENTER, subheadingTextColor(), 32, 0, false, 0.8F); - drawScaledCenteredText(guiGraphics, MekanismLang.OPACITY.translate(Math.round(MekanismConfig.client.hudOpacity.get() * 100)), relativeX + 70, relativeY + 75, subheadingTextColor(), 0.8F); - drawScaledCenteredText(guiGraphics, MekanismLang.JITTER.translate((int) MekanismConfig.client.hudJitter.get()), relativeX + 70, relativeY + 100, subheadingTextColor(), 0.8F); + drawScaledScrollingString(guiGraphics, MekanismLang.OPACITY.translate(Math.round(MekanismConfig.client.hudOpacity.get() * 100)), 0, 75, TextAlignment.CENTER, subheadingTextColor(), 4, false, 0.8F); + drawScaledScrollingString(guiGraphics, MekanismLang.JITTER.translate((int) MekanismConfig.client.hudJitter.get()), 0, 100, TextAlignment.CENTER, subheadingTextColor(), 4, false, 0.8F); } } diff --git a/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java b/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java index b2d0240ef61..d12c280530c 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java @@ -88,12 +88,12 @@ public GuiSideConfiguration(IGuiWrapper gui, int x, int y, TILE tile, SelectedWi DataType targetType = getTargetType(DataType::getPrevious); return PacketUtils.sendToServer(new PacketBatchConfiguration(this.tile.getBlockPos(), Screen.hasShiftDown() ? null : currentType, targetType)); }, TooltipUtils.create(MekanismLang.SIDE_CONFIG_CLEAR, MekanismLang.SIDE_CONFIG_CLEAR_ALL), TooltipUtils.create(MekanismLang.SIDE_CONFIG_INCREMENT))); - addSideDataButton(RelativeSide.BOTTOM, 68, 92); - addSideDataButton(RelativeSide.TOP, 68, 46); - addSideDataButton(RelativeSide.FRONT, 68, 69); - addSideDataButton(RelativeSide.BACK, 45, 92); - addSideDataButton(RelativeSide.LEFT, 45, 69); - addSideDataButton(RelativeSide.RIGHT, 91, 69); + addSideDataButton(RelativeSide.BOTTOM, 67, 92); + addSideDataButton(RelativeSide.TOP, 67, 46); + addSideDataButton(RelativeSide.FRONT, 67, 69); + addSideDataButton(RelativeSide.BACK, 44, 92); + addSideDataButton(RelativeSide.LEFT, 44, 69); + addSideDataButton(RelativeSide.RIGHT, 90, 69); updateTabs(); ((MekanismContainer) ((GuiMekanism) gui()).getMenu()).startTracking(MekanismContainer.SIDE_CONFIG_WINDOW, this.tile.getConfig()); PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.CONTAINER_TRACK_SIDE_CONFIG, tile, MekanismContainer.SIDE_CONFIG_WINDOW)); @@ -171,7 +171,7 @@ public void updateTabs() { public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); drawTitleText(guiGraphics, MekanismLang.CONFIG_TYPE.translate(currentType), 5); - drawCenteredText(guiGraphics, MekanismLang.SLOTS.translate(), relativeX + 80, relativeY + 120, subheadingTextColor()); + drawScrollingString(guiGraphics, MekanismLang.SLOTS.translate(), 0, 120, TextAlignment.CENTER, subheadingTextColor(), 4, false); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java b/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java index d0f6df8d411..f4809cb73a7 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java @@ -76,8 +76,8 @@ public void close() { public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); drawTitleText(guiGraphics, MekanismLang.TRANSPORTER_CONFIG.translate(), 5); - drawCenteredText(guiGraphics, MekanismLang.INPUT.translate(), relativeX + 51, relativeY + 105, subheadingTextColor()); - drawCenteredText(guiGraphics, MekanismLang.OUTPUT.translate(), relativeX + 121, relativeY + 68, subheadingTextColor()); + drawScrollingString(guiGraphics, MekanismLang.INPUT.translate(), 18, 105, TextAlignment.CENTER, subheadingTextColor(), 68, 0, false); + drawScrollingString(guiGraphics, MekanismLang.OUTPUT.translate(), 86, 68, TextAlignment.CENTER, subheadingTextColor(), width - 86, 4, false); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java index a25a08c4621..fb47396fd79 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java @@ -35,6 +35,7 @@ public class GuiUpgradeWindow extends GuiWindow { private final TileEntityMekanism tile; private final MekanismButton removeButton; private final GuiUpgradeScrollList scrollList; + private final GuiInnerScreen rightScreen; public GuiUpgradeWindow(IGuiWrapper gui, int x, int y, TileEntityMekanism tile, SelectedWindowData windowData) { super(gui, x, y, 156, 76 + 12 * GuiSupportedUpgrades.calculateNeededRows(), windowData); @@ -45,7 +46,7 @@ public GuiUpgradeWindow(IGuiWrapper gui, int x, int y, TileEntityMekanism tile, interactionStrategy = InteractionStrategy.ALL; scrollList = addChild(new GuiUpgradeScrollList(gui, relativeX + 6, relativeY + 18, 66, 50, tile.getComponent(), this::updateEnabledButtons)); addChild(new GuiSupportedUpgrades(gui, relativeX + 6, relativeY + 68, tile.getComponent().getSupportedTypes())); - addChild(new GuiInnerScreen(gui, relativeX + 72, relativeY + 18, 59, 50)); + rightScreen = addChild(new GuiInnerScreen(gui, relativeX + 72, relativeY + 18, 59, 50)); addChild(new GuiProgress(() -> this.tile.getComponent().getScaledUpgradeProgress(), ProgressType.INSTALLING, gui, relativeX + 134, relativeY + 37)); addChild(new GuiProgress(() -> 0, ProgressType.UNINSTALLING, gui, relativeX + 134, relativeY + 59)); removeButton = addChild(new DigitalButton(gui, relativeX + 73, relativeY + 54, 56, 12, MekanismLang.UPGRADE_UNINSTALL, (element, mouseX, mouseY) -> { @@ -81,22 +82,24 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { if (scrollList.hasSelection()) { Upgrade selectedType = scrollList.getSelection(); int amount = tile.getComponent().getUpgrades(selectedType); - int textY = relativeY + 20; WrappedTextRenderer textRenderer = upgradeTypeData.get(selectedType); if (textRenderer == null) { textRenderer = new WrappedTextRenderer(this, MekanismLang.UPGRADE_TYPE.translate(selectedType)); upgradeTypeData.put(selectedType, textRenderer); } - int lines = textRenderer.renderWithScale(guiGraphics, relativeX + 74, textY, screenTextColor(), 56, 0.6F); - textY += 6 * lines + 2; - drawTextWithScale(guiGraphics, MekanismLang.UPGRADE_COUNT.translate(amount, selectedType.getMax()), relativeX + 74, textY, screenTextColor(), 0.6F); + int screenWidth = rightScreen.getWidth() - 2; + int lines = textRenderer.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, screenTextColor(), + screenWidth - 2, 0.6F); + int textY = 4 + 6 * lines; + rightScreen.drawScaledScrollingString(guiGraphics, MekanismLang.UPGRADE_COUNT.translate(amount, selectedType.getMax()), 0, textY, TextAlignment.LEFT, + screenTextColor(), screenWidth, 2, false, 0.6F); for (Component component : UpgradeUtils.getInfo(tile, selectedType)) { //Note: We add the six here instead of after to account for the line above this for loop that draws the upgrade count textY += 6; - drawTextWithScale(guiGraphics, component, relativeX + 74, textY, screenTextColor(), 0.6F); + rightScreen.drawScaledScrollingString(guiGraphics, component, 0, textY, TextAlignment.LEFT, screenTextColor(), screenWidth, 2, false, 0.6F); } } else { - noSelection.renderWithScale(guiGraphics, relativeX + 74, relativeY + 20, screenTextColor(), 56, 0.8F); + noSelection.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, screenTextColor(), 56, 0.8F); } } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/window/GuiWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiWindow.java index 411b9e690e4..ee50786aeca 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiWindow.java @@ -228,18 +228,12 @@ protected boolean isFocusOverlay() { } @Override - public void drawTitleText(GuiGraphics guiGraphics, Component text, float y) { + public void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { if (isFocusOverlay()) { super.drawTitleText(guiGraphics, text, y); } else { //Adjust spacing for close button and any other buttons like side config's auto eject - int leftShift = getTitlePadStart(); - int xSize = getXSize() - leftShift - getTitlePadEnd(); - int maxLength = xSize - 12; - float textWidth = getStringWidth(text); - float scale = Math.min(1, maxLength / textWidth); - float left = relativeX + xSize / 2F; - drawScaledCenteredText(guiGraphics, text, left + leftShift, relativeY + y, titleTextColor(), scale); + drawTitleTextTextWithOffset(guiGraphics, text, relativeX, relativeY + y, getTitlePadStart(), getTitlePadEnd()); } } diff --git a/src/main/java/mekanism/client/gui/element/window/filter/GuiFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/GuiFilter.java index 7e723156892..97ba46d642e 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/GuiFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/GuiFilter.java @@ -108,10 +108,11 @@ protected int getSlotOffset() { } protected int getScreenHeight() { - return 43; + return 42; } - protected int getScreenWidth() { + @Override + public int getScreenWidth() { return 116; } diff --git a/src/main/java/mekanism/client/gui/element/window/filter/GuiFilterHelper.java b/src/main/java/mekanism/client/gui/element/window/filter/GuiFilterHelper.java index 8010950562f..4675b90c884 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/GuiFilterHelper.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/GuiFilterHelper.java @@ -20,4 +20,6 @@ default boolean hasFilterSelect() { int getRelativeY(); IFilter getFilter(); + + int getScreenWidth(); } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/window/filter/GuiOredictionificatorFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/GuiOredictionificatorFilter.java index 1d6ae34cef7..9f97c8d7bea 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/GuiOredictionificatorFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/GuiOredictionificatorFilter.java @@ -35,7 +35,7 @@ private GuiOredictionificatorFilter(IGuiWrapper gui, int x, int y, TileEntityOre @Override protected int getScreenHeight() { - return 53; + return 52; } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/filter/qio/GuiQIOItemStackFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/qio/GuiQIOItemStackFilter.java index 2b7058f3d0d..5d7c3a2950b 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/qio/GuiQIOItemStackFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/qio/GuiQIOItemStackFilter.java @@ -46,6 +46,6 @@ protected QIOItemStackFilter createNewFilter() { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - drawString(guiGraphics, OnOff.of(filter.fuzzyMode).getTextComponent(), relativeX + 161, relativeY + 20, titleTextColor()); + drawScrollingString(guiGraphics, OnOff.of(filter.fuzzyMode).getTextComponent(), 159, 20, TextAlignment.LEFT, titleTextColor(), width - 159, 2, false); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java index e520491cb60..029ac253987 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java @@ -79,16 +79,17 @@ default GuiSorterFilerSelect getFilterSelect(IGuiWrapper gui, TileEntityLogistic } default void renderSorterForeground(GuiGraphics guiGraphics) { - int relativeX = getRelativeX(); - int relativeY = getRelativeY(); SorterFilter filter = getFilter(); - drawString(guiGraphics, OnOff.of(filter.allowDefault).getTextComponent(), relativeX + 161, relativeY + 20, titleTextColor()); - drawString(guiGraphics, MekanismLang.MIN.translate(""), relativeX + 148, relativeY + 32, titleTextColor()); - drawString(guiGraphics, MekanismLang.MAX.translate(""), relativeX + 148, relativeY + 44, titleTextColor()); + int screenEnd = 29 + getScreenWidth(); + drawScrollingString(guiGraphics, OnOff.of(filter.allowDefault).getTextComponent(), 159, 20, TextAlignment.LEFT, titleTextColor(), getXSize() - 159, 2, false); + //Note: We add two to the length, as min and max have two spaces at the end given we aren't actually providing a parameter + //TODO: Do we want to adjust this, and just have separate lang keys for them? + drawScrollingString(guiGraphics, MekanismLang.MIN.translate(""), screenEnd, 32, TextAlignment.LEFT, titleTextColor(), 169 - screenEnd + 2, 1, false); + drawScrollingString(guiGraphics, MekanismLang.MAX.translate(""), screenEnd, 44, TextAlignment.LEFT, titleTextColor(), 169 - screenEnd + 2, 1, false); if (isSingleItem() && filter.sizeMode) { - drawString(guiGraphics, MekanismLang.SORTER_FILTER_SIZE_MODE.translateColored(EnumColor.RED, OnOff.ON), relativeX + 161, relativeY + 58, titleTextColor()); + drawScrollingString(guiGraphics, MekanismLang.SORTER_FILTER_SIZE_MODE.translateColored(EnumColor.RED, OnOff.ON), 159, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 159, 2, false); } else { - drawString(guiGraphics, OnOff.of(filter.sizeMode).getTextComponent(), relativeX + 161, relativeY + 58, titleTextColor()); + drawScrollingString(guiGraphics, OnOff.of(filter.sizeMode).getTextComponent(), 159, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 159, 2, false); } } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterItemStackFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterItemStackFilter.java index 4d716783644..91191a72b1d 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterItemStackFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterItemStackFilter.java @@ -60,7 +60,7 @@ protected SorterItemStackFilter createNewFilter() { public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); renderSorterForeground(guiGraphics); - drawString(guiGraphics, OnOff.of(filter.fuzzyMode).getTextComponent(), relativeX + 161, relativeY + 71, titleTextColor()); + drawScrollingString(guiGraphics, OnOff.of(filter.fuzzyMode).getTextComponent(), 159, 71, TextAlignment.LEFT, titleTextColor(), width - 159, 2, false); } @Override diff --git a/src/main/java/mekanism/client/gui/item/GuiDictionary.java b/src/main/java/mekanism/client/gui/item/GuiDictionary.java index 9f109d9dff2..c4ed6db4a46 100644 --- a/src/main/java/mekanism/client/gui/item/GuiDictionary.java +++ b/src/main/java/mekanism/client/gui/item/GuiDictionary.java @@ -24,6 +24,7 @@ public class GuiDictionary extends GuiMekanism { private GuiTextScrollList scrollList; private GuiDictionaryTarget target; + private GuiDropdown dropdown; private DictionaryTagType currentType = DictionaryTagType.ITEM; public GuiDictionary(DictionaryContainer container, Inventory inv, Component title) { @@ -41,7 +42,7 @@ protected void addGuiElements() { scrollList = addRenderableWidget(new GuiTextScrollList(this, 7, 29, 162, 42)); //TODO: Ideally we would eventually replace this with some sort of tab system as it would probably look better // and could then be limited to just the tags the target supports - addRenderableWidget(new GuiDropdown<>(this, 124, 73, 45, DictionaryTagType.class, () -> currentType, this::setCurrentType)); + dropdown = addRenderableWidget(new GuiDropdown<>(this, 124, 73, 45, DictionaryTagType.class, () -> currentType, this::setCurrentType)); target = addRenderableWidget(new GuiDictionaryTarget(this, 6, 6, this::updateScrollList)); } @@ -60,8 +61,7 @@ private void updateScrollList(Set supportedTypes) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); - drawTextScaledBound(guiGraphics, MekanismLang.DICTIONARY_TAG_TYPE.translate(), 77, inventoryLabelY, titleTextColor(), 45); + renderInventoryTextAndOther(guiGraphics, MekanismLang.DICTIONARY_TAG_TYPE.translate(), imageWidth - dropdown.getRelativeX() - 5); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/item/GuiPersonalStorageItem.java b/src/main/java/mekanism/client/gui/item/GuiPersonalStorageItem.java index 3d2e6807af9..9817a490aa8 100644 --- a/src/main/java/mekanism/client/gui/item/GuiPersonalStorageItem.java +++ b/src/main/java/mekanism/client/gui/item/GuiPersonalStorageItem.java @@ -26,7 +26,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java index 86c9fed303d..c0c2b381885 100644 --- a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java +++ b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java @@ -85,9 +85,9 @@ public GuiSeismicReader(SeismicReaderContainer container, Inventory inv, Compone @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 7, 11, 63, 49)); - addRenderableWidget(new GuiInnerScreen(this, 74, 11, 51, 159)); - scrollBar = addRenderableWidget(new GuiScrollBar(this, 126, 25, 131, blockList::size, () -> 1)); + addRenderableWidget(new GuiInnerScreen(this, 7, 11, 63, 50)); + addRenderableWidget(new GuiInnerScreen(this, 74, 11, 51, 160)); + scrollBar = addRenderableWidget(new GuiScrollBar(this, 126, 25, 132, blockList::size, () -> 1)); addRenderableWidget(new GuiArrowSelection(this, 76, 81, () -> { int currentLayer = scrollBar.getCurrentSelection(); if (currentLayer >= 0) { @@ -97,7 +97,7 @@ protected void addGuiElements() { })); upButton = addRenderableWidget(new MekanismImageButton(this, 126, 11, 14, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "up.png"), (element, mouseX, mouseY) -> scrollBar.adjustScroll(1))); - downButton = addRenderableWidget(new MekanismImageButton(this, 126, 156, 14, + downButton = addRenderableWidget(new MekanismImageButton(this, 126, 157, 14, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "down.png"), (element, mouseX, mouseY) -> scrollBar.adjustScroll(-1))); updateEnabledButtons(); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiAdvancedElectricMachine.java b/src/main/java/mekanism/client/gui/machine/GuiAdvancedElectricMachine.java index 5cc492818a1..9971f3b5dae 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiAdvancedElectricMachine.java +++ b/src/main/java/mekanism/client/gui/machine/GuiAdvancedElectricMachine.java @@ -38,7 +38,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java b/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java index 1a25996ff67..5d94c960840 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java @@ -80,8 +80,8 @@ public double getLevel() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - drawString(guiGraphics, title, (imageWidth - getStringWidth(title)) / 2, titleLabelY, titleTextColor()); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderTitleText(guiGraphics); + renderInventoryText(guiGraphics); drawTextScaledBound(guiGraphics, MekanismLang.PROCESS_RATE.translate(TextUtils.getPercent(tile.getProcessRate())), 48, 76, screenTextColor(), 100); super.drawForegroundText(guiGraphics, mouseX, mouseY); PoseStack pose = guiGraphics.pose(); diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java index 1452157571a..10e29f8bb11 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java @@ -5,6 +5,7 @@ import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; +import mekanism.client.gui.element.gauge.GuiGauge; import mekanism.client.gui.element.progress.GuiProgress; import mekanism.client.gui.element.progress.ProgressType; import mekanism.client.gui.element.tab.GuiEnergyTab; @@ -18,10 +19,11 @@ public class GuiChemicalInfuser extends GuiConfigurableTile> { + private GuiGauge centerGauge; + public GuiChemicalInfuser(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); inventoryLabelY += 2; - titleLabelX = 5; titleLabelY = 5; dynamicSlots = true; } @@ -35,7 +37,7 @@ protected void addGuiElements() { addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getEnergyUsed)); addRenderableWidget(new GuiChemicalGauge(() -> tile.leftTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 25, 13)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_LEFT_INPUT)); - addRenderableWidget(new GuiChemicalGauge(() -> tile.centerTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 79, 4)) + centerGauge = addRenderableWidget(new GuiChemicalGauge(() -> tile.centerTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 79, 4)) .warning(WarningType.NO_SPACE_IN_OUTPUT, tile.getWarningCheck(RecipeError.NOT_ENOUGH_OUTPUT_SPACE)); addRenderableWidget(new GuiChemicalGauge(() -> tile.rightTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 133, 13)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_RIGHT_INPUT)); @@ -47,8 +49,8 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - drawString(guiGraphics, title, titleLabelX, titleLabelY, titleTextColor()); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderTitleTextWithOffset(guiGraphics, 2, getXSize() - centerGauge.getRelativeX(), 3, TextAlignment.LEFT); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java index fb316e4807c..f6444fa0820 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java @@ -38,7 +38,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiCombiner.java b/src/main/java/mekanism/client/gui/machine/GuiCombiner.java index 11d30bbab17..f6f77b122e0 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiCombiner.java +++ b/src/main/java/mekanism/client/gui/machine/GuiCombiner.java @@ -36,7 +36,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiDigitalMiner.java b/src/main/java/mekanism/client/gui/machine/GuiDigitalMiner.java index 2e892e6c7b2..a890e98aff5 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiDigitalMiner.java +++ b/src/main/java/mekanism/client/gui/machine/GuiDigitalMiner.java @@ -71,7 +71,7 @@ protected void addGuiElements() { list.add(tile.searcher.state.getTextComponent()); list.add(MekanismLang.MINER_TO_MINE.translate(TextUtils.format(tile.getToMine()))); return list; - }).spacing(1).clearFormat()); + }).clearSpacing().clearFormat()); addRenderableWidget(new GuiDigitalSwitch(this, 19, 56, EJECT, tile::getDoEject, (element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.AUTO_EJECT_BUTTON, ((GuiDigitalMiner) element.gui()).tile)), SwitchType.LOWER_ICON)) .setTooltip(MekanismLang.AUTO_EJECT); @@ -128,7 +128,7 @@ private void updateEnabledButtons() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java b/src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java index 83591762eaa..1c4482c166d 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java +++ b/src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java @@ -134,21 +134,16 @@ protected void addGenericTabs() { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { super.drawForegroundText(guiGraphics, mouseX, mouseY); renderTitleText(guiGraphics); - drawScaledTextScaledBound(guiGraphics, MekanismLang.FILTER_COUNT.translate(getFilterManager().count()), 14, 22, screenTextColor(), 76, 0.8F); - drawScaledTextScaledBound(guiGraphics, MekanismLang.MINER_RADIUS.translate(tile.getRadius()), 14, 35, screenTextColor(), 76, 0.8F); - drawScaledTextScaledBound(guiGraphics, MekanismLang.MIN_DIGITAL_MINER.translate(tile.getMinY()), 14, 61, screenTextColor(), 76, 0.8F); - drawScaledTextScaledBound(guiGraphics, MekanismLang.MAX_DIGITAL_MINER.translate(tile.getMaxY()), 14, 88, screenTextColor(), 76, 0.8F); + drawScreenText(guiGraphics, MekanismLang.FILTER_COUNT.translate(getFilterManager().count()), 5); + drawScreenText(guiGraphics, MekanismLang.MINER_RADIUS.translate(tile.getRadius()), 18); + drawScreenText(guiGraphics, MekanismLang.MIN_DIGITAL_MINER.translate(tile.getMinY()), 44); + drawScreenText(guiGraphics, MekanismLang.MAX_DIGITAL_MINER.translate(tile.getMaxY()), 71); } @Override - public void drawTitleText(GuiGraphics guiGraphics, Component text, float y) { + public void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { //Adjust spacing for back button - int leftShift = 11; - int xSize = getXSize() - leftShift; - int maxLength = xSize - 12; - float textWidth = getStringWidth(text); - float scale = Math.min(1, maxLength / textWidth); - drawScaledCenteredText(guiGraphics, text, leftShift + xSize / 2F, y, titleTextColor(), scale); + drawTitleTextTextWithOffset(guiGraphics, text, 0, y, 11, 0); } @Override diff --git a/src/main/java/mekanism/client/gui/machine/GuiElectricMachine.java b/src/main/java/mekanism/client/gui/machine/GuiElectricMachine.java index a518d3d105c..bbfd2f8548e 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiElectricMachine.java +++ b/src/main/java/mekanism/client/gui/machine/GuiElectricMachine.java @@ -36,7 +36,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java b/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java index 0ce87fdc0c0..3cd6b95fd03 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java +++ b/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java @@ -33,7 +33,7 @@ public GuiElectricPump(MekanismTileContainer container, @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 54, 23, 80, 41, () -> { + addRenderableWidget(new GuiInnerScreen(this, 54, 23, 80, 42, () -> { List list = new ArrayList<>(); list.add(EnergyDisplay.of(tile.getEnergyContainer()).getTextComponent()); FluidStack fluidStack = tile.fluidTank.getFluid(); @@ -64,7 +64,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiFactory.java b/src/main/java/mekanism/client/gui/machine/GuiFactory.java index a7d11ea958a..af071f52098 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiFactory.java +++ b/src/main/java/mekanism/client/gui/machine/GuiFactory.java @@ -72,7 +72,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java b/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java index e0555a37d7c..3d3e0761391 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java +++ b/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java @@ -34,7 +34,7 @@ public GuiFluidicPlenisher(MekanismTileContainer con @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 54, 23, 80, 41, () -> { + addRenderableWidget(new GuiInnerScreen(this, 54, 23, 80, 42, () -> { List list = new ArrayList<>(); list.add(EnergyDisplay.of(tile.getEnergyContainer()).getTextComponent()); list.add(MekanismLang.FINISHED.translate(YesNo.of(tile.finishedCalc))); @@ -59,7 +59,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiFormulaicAssemblicator.java b/src/main/java/mekanism/client/gui/machine/GuiFormulaicAssemblicator.java index 2f57dcaa238..dc549ad1d60 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiFormulaicAssemblicator.java +++ b/src/main/java/mekanism/client/gui/machine/GuiFormulaicAssemblicator.java @@ -103,7 +103,7 @@ private void updateEnabledButtons() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiFuelwoodHeater.java b/src/main/java/mekanism/client/gui/machine/GuiFuelwoodHeater.java index 41d3be47009..7cceed9853c 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiFuelwoodHeater.java +++ b/src/main/java/mekanism/client/gui/machine/GuiFuelwoodHeater.java @@ -52,7 +52,7 @@ public boolean isActive() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiIsotopicCentrifuge.java b/src/main/java/mekanism/client/gui/machine/GuiIsotopicCentrifuge.java index 21f508aebe8..a756b87dcc2 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiIsotopicCentrifuge.java +++ b/src/main/java/mekanism/client/gui/machine/GuiIsotopicCentrifuge.java @@ -43,7 +43,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } diff --git a/src/main/java/mekanism/client/gui/machine/GuiMetallurgicInfuser.java b/src/main/java/mekanism/client/gui/machine/GuiMetallurgicInfuser.java index b17b1f03132..973cf70cf1f 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiMetallurgicInfuser.java +++ b/src/main/java/mekanism/client/gui/machine/GuiMetallurgicInfuser.java @@ -39,7 +39,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiNutritionalLiquifier.java b/src/main/java/mekanism/client/gui/machine/GuiNutritionalLiquifier.java index 6bc4441752b..78ecda57061 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiNutritionalLiquifier.java +++ b/src/main/java/mekanism/client/gui/machine/GuiNutritionalLiquifier.java @@ -40,7 +40,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } diff --git a/src/main/java/mekanism/client/gui/machine/GuiOredictionificator.java b/src/main/java/mekanism/client/gui/machine/GuiOredictionificator.java index 543b55efeb5..e7ed5f5b6bd 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiOredictionificator.java +++ b/src/main/java/mekanism/client/gui/machine/GuiOredictionificator.java @@ -84,7 +84,7 @@ protected void onClick(IFilter filter, int index) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiPRC.java b/src/main/java/mekanism/client/gui/machine/GuiPRC.java index 3bebbc87510..17738cc33d3 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPRC.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPRC.java @@ -2,6 +2,7 @@ import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiVerticalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; @@ -19,6 +20,8 @@ public class GuiPRC extends GuiConfigurableTile> { + private GuiElement secondGauge; + public GuiPRC(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; @@ -30,7 +33,7 @@ protected void addGuiElements() { addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getActive)); addRenderableWidget(new GuiFluidGauge(() -> tile.inputFluidTank, () -> tile.getFluidTanks(null), GaugeType.STANDARD, this, 5, 10) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(TileEntityPressurizedReactionChamber.NOT_ENOUGH_FLUID_INPUT_ERROR))); - addRenderableWidget(new GuiChemicalGauge(() -> tile.inputGasTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 28, 10) + secondGauge = addRenderableWidget(new GuiChemicalGauge(() -> tile.inputGasTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 28, 10) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(TileEntityPressurizedReactionChamber.NOT_ENOUGH_CHEMICAL_INPUT_ERROR))); addRenderableWidget(new GuiChemicalGauge(() -> tile.outputGasTank, () -> tile.getChemicalTanks(null), GaugeType.SMALL, this, 140, 40) .warning(WarningType.NO_SPACE_IN_OUTPUT, tile.getWarningCheck(TileEntityPressurizedReactionChamber.NOT_ENOUGH_SPACE_GAS_OUTPUT_ERROR))); @@ -42,9 +45,8 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - float widthThird = imageWidth / 3F; - drawTextScaledBound(guiGraphics, title, widthThird - 7, titleLabelY, titleTextColor(), 2 * widthThird); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderTitleTextWithOffset(guiGraphics, secondGauge.getRelativeX() + secondGauge.getWidth(), 2, 3, TextAlignment.LEFT); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiPaintingMachine.java b/src/main/java/mekanism/client/gui/machine/GuiPaintingMachine.java index f6186e55e49..cac6e67100d 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPaintingMachine.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPaintingMachine.java @@ -41,7 +41,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiPigmentExtractor.java b/src/main/java/mekanism/client/gui/machine/GuiPigmentExtractor.java index 1aa92a6f74f..2d221595560 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPigmentExtractor.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPigmentExtractor.java @@ -43,7 +43,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java b/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java index a443786b6d6..7c298d00d43 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java @@ -8,6 +8,7 @@ import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; +import mekanism.client.gui.element.gauge.GuiGauge; import mekanism.client.gui.element.progress.GuiProgress; import mekanism.client.gui.element.progress.GuiProgress.ColorDetails; import mekanism.client.gui.element.progress.ProgressType; @@ -22,10 +23,11 @@ public class GuiPigmentMixer extends GuiConfigurableTile> { + private GuiGauge centerGauge; + public GuiPigmentMixer(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); inventoryLabelY += 2; - titleLabelX = 5; titleLabelY = 5; dynamicSlots = true; } @@ -39,7 +41,7 @@ protected void addGuiElements() { addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getEnergyUsed)); addRenderableWidget(new GuiChemicalGauge(() -> tile.leftInputTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 25, 13)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_LEFT_INPUT)); - addRenderableWidget(new GuiChemicalGauge(() -> tile.outputTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 79, 4)) + centerGauge = addRenderableWidget(new GuiChemicalGauge(() -> tile.outputTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 79, 4)) .warning(WarningType.NO_SPACE_IN_OUTPUT, tile.getWarningCheck(RecipeError.NOT_ENOUGH_OUTPUT_SPACE)); addRenderableWidget(new GuiChemicalGauge(() -> tile.rightInputTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 133, 13)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_RIGHT_INPUT)); @@ -51,8 +53,8 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - drawString(guiGraphics, title, titleLabelX, titleLabelY, titleTextColor()); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderTitleTextWithOffset(guiGraphics, 2, getXSize() - centerGauge.getRelativeX(), 3, TextAlignment.LEFT); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiPrecisionSawmill.java b/src/main/java/mekanism/client/gui/machine/GuiPrecisionSawmill.java index 9fe6c9d0d9d..200686f4ebd 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPrecisionSawmill.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPrecisionSawmill.java @@ -42,7 +42,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiResistiveHeater.java b/src/main/java/mekanism/client/gui/machine/GuiResistiveHeater.java index a2cb20fed26..a6a4ed8c2c2 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiResistiveHeater.java +++ b/src/main/java/mekanism/client/gui/machine/GuiResistiveHeater.java @@ -58,7 +58,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiRotaryCondensentrator.java b/src/main/java/mekanism/client/gui/machine/GuiRotaryCondensentrator.java index d6a2ad6b3a1..fb77ee05930 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiRotaryCondensentrator.java +++ b/src/main/java/mekanism/client/gui/machine/GuiRotaryCondensentrator.java @@ -1,6 +1,7 @@ package mekanism.client.gui.machine; import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; +import mekanism.api.text.ILangEntry; import mekanism.client.gui.GuiConfigurableTile; import mekanism.client.gui.element.GuiDownArrow; import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; @@ -79,7 +80,8 @@ public boolean isActive() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, (tile.getMode() ? MekanismLang.DECONDENSENTRATING : MekanismLang.CONDENSENTRATING).translate(), 6, imageHeight - 92, titleTextColor()); + ILangEntry modeLang = tile.getMode() ? MekanismLang.DECONDENSENTRATING : MekanismLang.CONDENSENTRATING; + drawScrollingString(guiGraphics, modeLang.translate(), 4, imageHeight - 92, TextAlignment.LEFT, titleTextColor(), 111, 2, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiSeismicVibrator.java b/src/main/java/mekanism/client/gui/machine/GuiSeismicVibrator.java index a7807cf2ca4..fce08cdca02 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiSeismicVibrator.java +++ b/src/main/java/mekanism/client/gui/machine/GuiSeismicVibrator.java @@ -41,7 +41,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiSolarNeutronActivator.java b/src/main/java/mekanism/client/gui/machine/GuiSolarNeutronActivator.java index 58ab63be09d..8adefb4eafe 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiSolarNeutronActivator.java +++ b/src/main/java/mekanism/client/gui/machine/GuiSolarNeutronActivator.java @@ -37,7 +37,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIODriveArray.java b/src/main/java/mekanism/client/gui/qio/GuiQIODriveArray.java index 946bc639419..b7f9d849eb4 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIODriveArray.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIODriveArray.java @@ -29,7 +29,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIOFilterHandler.java b/src/main/java/mekanism/client/gui/qio/GuiQIOFilterHandler.java index 6d24ef3551a..6d301df49e9 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIOFilterHandler.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIOFilterHandler.java @@ -143,7 +143,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double xDelta, double @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIOItemFrequencySelect.java b/src/main/java/mekanism/client/gui/qio/GuiQIOItemFrequencySelect.java index 85f8b6e0673..41ad7f933b2 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIOItemFrequencySelect.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIOItemFrequencySelect.java @@ -52,13 +52,8 @@ public QIOFrequencySelectItemContainer getFrequencyContainer() { } @Override - public void drawTitleText(GuiGraphics guiGraphics, Component text, float y) { + public void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { //Adjust spacing for back button - int leftShift = 15; - int xSize = getXSize() - leftShift; - int maxLength = xSize - 12; - float textWidth = getStringWidth(text); - float scale = Math.min(1, maxLength / textWidth); - drawScaledCenteredText(guiGraphics, text, leftShift + xSize / 2F, y, titleTextColor(), scale); + drawTitleTextTextWithOffset(guiGraphics, text, 0, y, 15, 0); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIOItemViewer.java b/src/main/java/mekanism/client/gui/qio/GuiQIOItemViewer.java index 327eae4e965..9e1eef9c562 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIOItemViewer.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIOItemViewer.java @@ -48,6 +48,7 @@ public abstract class GuiQIOItemViewer protected final Inventory inv; private GuiTextField searchField; private GuiCraftingWindowTab craftingWindowTab; + private GuiDropdown searchDropdown; private boolean loadPinned = true; protected GuiQIOItemViewer(CONTAINER container, Inventory inv, Component title) { @@ -55,7 +56,7 @@ protected GuiQIOItemViewer(CONTAINER container, Inventory inv, Component title) this.inv = inv; imageWidth = 16 + MekanismConfig.client.qioItemViewerSlotsX.get() * 18 + 18; imageHeight = QIOItemViewerContainer.SLOTS_START_Y + MekanismConfig.client.qioItemViewerSlotsY.get() * 18 + 96; - inventoryLabelY = imageHeight - 94; + inventoryLabelY = imageHeight - 93; titleLabelY = 5; dynamicSlots = true; } @@ -94,7 +95,7 @@ protected void addGuiElements() { } addRenderableWidget(new GuiSlotScroll(this, 7, QIOItemViewerContainer.SLOTS_START_Y, MekanismConfig.client.qioItemViewerSlotsX.get(), slotsY, menu::getQIOItemList, menu)); - addRenderableWidget(new GuiDropdown<>(this, imageWidth - 9 - 54, QIOItemViewerContainer.SLOTS_START_Y + slotsY * 18 + 1, + searchDropdown = addRenderableWidget(new GuiDropdown<>(this, imageWidth - 9 - 54, QIOItemViewerContainer.SLOTS_START_Y + slotsY * 18 + 1, 41, ListSortType.class, menu::getSortType, menu::setSortType)); addRenderableWidget(new GuiDigitalIconToggle<>(this, imageWidth - 9 - 12, QIOItemViewerContainer.SLOTS_START_Y + slotsY * 18 + 1, 12, 12, SortDirection.class, menu::getSortDirection, menu::setSortDirection)); @@ -112,10 +113,8 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryTextAndOther(guiGraphics, MekanismLang.LIST_SORT.translate(), imageWidth - searchDropdown.getRelativeX() - 5); drawTextScaledBound(guiGraphics, MekanismLang.LIST_SEARCH.translate(), 7, 31, titleTextColor(), 41); - Component text = MekanismLang.LIST_SORT.translate(); - drawString(guiGraphics, text, imageWidth - 66 - getStringWidth(text), imageHeight - 92, titleTextColor()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIORedstoneAdapter.java b/src/main/java/mekanism/client/gui/qio/GuiQIORedstoneAdapter.java index e3bea34362e..477f5ffccab 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIORedstoneAdapter.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIORedstoneAdapter.java @@ -101,7 +101,7 @@ private void setCount() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); renderItem(guiGraphics, tile.getItemType(), 8, 31); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIOTileFrequencySelect.java b/src/main/java/mekanism/client/gui/qio/GuiQIOTileFrequencySelect.java index 9d99e45cac2..24ef3dd57ac 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIOTileFrequencySelect.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIOTileFrequencySelect.java @@ -58,13 +58,8 @@ public TileEntityQIOComponent getTileEntity() { } @Override - public void drawTitleText(GuiGraphics guiGraphics, Component text, float y) { + public void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { //Adjust spacing for back button - int leftShift = 15; - int xSize = getXSize() - leftShift; - int maxLength = xSize - 12; - float textWidth = getStringWidth(text); - float scale = Math.min(1, maxLength / textWidth); - drawScaledCenteredText(guiGraphics, text, leftShift + xSize / 2F, y, titleTextColor(), scale); + drawTitleTextTextWithOffset(guiGraphics, text, 0, y, 15, 0); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitCrafting.java b/src/main/java/mekanism/client/gui/robit/GuiRobitCrafting.java index 11ee287b647..7a100fb6ae1 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitCrafting.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitCrafting.java @@ -23,8 +23,8 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - drawString(guiGraphics, title, titleLabelX, titleLabelY, titleTextColor()); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderTitleText(guiGraphics); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitInventory.java b/src/main/java/mekanism/client/gui/robit/GuiRobitInventory.java index c3a3453a6d7..31aba4bf49a 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitInventory.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitInventory.java @@ -16,8 +16,8 @@ public GuiRobitInventory(RobitContainer container, Inventory inv, Component titl @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - drawString(guiGraphics, title, titleLabelX, titleLabelY, titleTextColor()); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderTitleText(guiGraphics); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java index ca2dc904f5d..ec48c63013c 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java @@ -46,7 +46,6 @@ public GuiRobitMain(MainRobitContainer container, Inventory inv, Component title super(container, inv, title); robit = container.getEntity(); dynamicSlots = true; - titleLabelX = 76; } private void openWindow(GuiWindow window, Supplier elementSupplier) { @@ -103,7 +102,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - drawString(guiGraphics, title, titleLabelX, titleLabelY, titleTextColor()); + renderTitleText(guiGraphics); drawTextScaledBound(guiGraphics, MekanismLang.ROBIT_GREETING.translate(robit.getName()), 29, 18, screenTextColor(), 119); drawTextScaledBound(guiGraphics, MekanismLang.ENERGY.translate(EnergyDisplay.of(robit.getEnergyContainer())), 29, 36 - 4, screenTextColor(), 119); drawTextScaledBound(guiGraphics, MekanismLang.ROBIT_FOLLOWING.translate(robit.getFollowing()), 29, 45 - 4, screenTextColor(), 119); diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java b/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java index 169a79ae94d..3cf263a7e08 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java @@ -32,7 +32,6 @@ public GuiRobitRepair(RepairRobitContainer container, Inventory inv, Component t super(container, inv, title); this.player = inv.player; inventoryLabelY += 1; - titleLabelX = 60; } @Override @@ -78,30 +77,29 @@ public void removed() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - drawString(guiGraphics, title, titleLabelX, titleLabelY, titleTextColor()); + renderTitleTextWithOffset(guiGraphics, 60, 9, 0, TextAlignment.CENTER); int maximumCost = menu.getCost(); if (maximumCost > 0) { - int k = 0x80FF20; + int textColor = 0x80FF20; Component component = MekanismLang.REPAIR_COST.translate(maximumCost); if (maximumCost >= 40 && !getMinecraft().player.getAbilities().instabuild) { component = MekanismLang.REPAIR_EXPENSIVE.translate(); - k = 0xFF6060; + textColor = 0xFF6060; } else { Slot slot = menu.getSlot(2); if (!slot.hasItem()) { component = null; } else if (!slot.mayPickup(player)) { - k = 0xFF6060; + textColor = 0xFF6060; } } if (component != null) { - int width = imageWidth - 8 - getStringWidth(component) - 2; - guiGraphics.fill(width - 2, 67, imageWidth - 8, 79, 0x4F000000); - guiGraphics.drawString(getFont(), component, width, 69, k); + guiGraphics.fill(Math.max(54 + 8, imageWidth - getStringWidth(component) - 10), 67, imageWidth - 8, 79, 0x4F000000); + drawScrollingString(guiGraphics, component, 54, 69, TextAlignment.RIGHT, textColor, getXSize() - 54, 9, true); } } - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitSmelting.java b/src/main/java/mekanism/client/gui/robit/GuiRobitSmelting.java index 5382a8831fd..eac8eb030db 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitSmelting.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitSmelting.java @@ -29,8 +29,8 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - drawString(guiGraphics, title, titleLabelX, titleLabelY, titleTextColor()); - drawString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, titleTextColor()); + renderTitleText(guiGraphics); + renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java index aabc84dc30f..8ad86d8fb5e 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java @@ -32,7 +32,7 @@ public void addWidgets(WidgetHolder widgetHolder) { MekanismLang.MULTIBLOCK_FORMED.translate(), MekanismLang.EVAPORATION_HEIGHT.translate(EvaporationMultiblockData.MAX_HEIGHT), MekanismLang.TEMPERATURE.translate(MekanismUtils.getTemperatureDisplay(HeatAPI.AMBIENT_TEMP, TemperatureUnit.KELVIN, true)), MekanismLang.FLUID_PRODUCTION.translate(0.0)) - ).spacing(1)); + ).clearSpacing()); addElement(widgetHolder, new GuiDownArrow(this, 32, 39)); addElement(widgetHolder, new GuiDownArrow(this, 136, 39)); addElement(widgetHolder, new GuiHorizontalRateBar(this, RecipeViewerUtils.FULL_BAR, 48, 63)); diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/MekanismEmiRecipe.java b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/MekanismEmiRecipe.java index 00974a54946..fe541c3e41a 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/MekanismEmiRecipe.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/MekanismEmiRecipe.java @@ -189,7 +189,7 @@ public RecipeHolder getBackingRecipe() { } @Override - public Font getFont() { + public Font font() { return Minecraft.getInstance().font; } diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java index 009668fe460..62ae2556e34 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java @@ -195,7 +195,7 @@ protected void renderElements(RECIPE recipe, IRecipeSlotsView recipeSlotsView, G } @Override - public Font getFont() { + public Font font() { return Minecraft.getInstance().font; } diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java index ecd0d13d24f..544a62f4142 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java @@ -35,7 +35,7 @@ public FluidToFluidRecipeCategory(IGuiHelper helper, IRecipeViewerRecipeType recipeHolder, IRecipeSlotsView reci super.draw(recipeHolder, recipeSlotView, guiGraphics, mouseX, mouseY); double secondaryChance = recipeHolder.value().getSecondaryChance(); if (secondaryChance > 0) { - guiGraphics.drawString(getFont(), TextUtils.getPercent(secondaryChance), 104, 41, SpecialColors.TEXT_TITLE.argb(), false); + //Perform the same translations as super does + //TODO: Figure out how to replace this with using JEI's newer widget system + PoseStack pose = guiGraphics.pose(); + pose.pushPose(); + pose.translate(getGuiLeft(), getGuiTop(), 0); + drawScrollingString(guiGraphics, TextUtils.getPercent(secondaryChance), output.getRelativeX(), output.getRelativeY() + output.getHeight() + 1, + TextAlignment.RIGHT, titleTextColor(), output.getWidth(), 1, false); + pose.popPose(); } } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 534ccc34859..631ed48b6ed 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -5,16 +5,22 @@ import java.util.List; import mekanism.api.text.TextComponentUtil; import mekanism.client.SpecialColors; +import net.minecraft.Util; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; +import org.joml.Matrix4f; +import org.joml.Vector3f; +//TODO - 1.21: Document this class public interface IFancyFontRenderer { int getXSize(); - Font getFont(); + Font font(); default int titleTextColor() { return SpecialColors.TEXT_TITLE.argb(); @@ -40,108 +46,162 @@ default int inactiveButtonTextColor() { return SpecialColors.TEXT_INACTIVE_BUTTON.argb(); } - default int drawString(GuiGraphics guiGraphics, Component component, int x, int y, int color) { - return guiGraphics.drawString(getFont(), component, x, y, color, false); + default int drawString(GuiGraphics guiGraphics, Component component, float x, float y, int color, boolean shadow) { + return guiGraphics.drawString(font(), component.getVisualOrderText(), x, y, color, shadow); } default int getStringWidth(Component component) { - return getFont().width(component); + return font().width(component); } - default void drawCenteredText(GuiGraphics guiGraphics, Component component, float x, float y, int color) { - drawCenteredText(guiGraphics, component, x, 0, y, color); + default int getLineHeight() { + return font().lineHeight; } - default void drawCenteredText(GuiGraphics guiGraphics, Component component, float xStart, float areaWidth, float y, int color) { - int textWidth = getStringWidth(component); - float centerX = xStart + (areaWidth / 2F) - (textWidth / 2F); - drawTextExact(guiGraphics, component, centerX, y, color); + default void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { + drawScrollingString(guiGraphics, text, 0, y, TextAlignment.CENTER, titleTextColor(), 4, false); } - default void drawTitleText(GuiGraphics guiGraphics, Component text, float y) { - drawCenteredTextScaledBound(guiGraphics, text, getXSize() - 8, y, titleTextColor()); + default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y, int startPad, int endPad) { + drawTitleTextTextWithOffset(guiGraphics, text, x, y, startPad, endPad, 4, TextAlignment.CENTER); } - default void drawScaledCenteredTextScaledBound(GuiGraphics guiGraphics, Component text, float left, float y, int color, float maxX, float textScale) { - float width = getStringWidth(text) * textScale; - float scale = Math.min(1, maxX / width) * textScale; - drawScaledCenteredText(guiGraphics, text, left, y, color, scale); + default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y, int startPad, int endPad, int maxLengthPad, TextAlignment alignment) { + drawScrollingString(guiGraphics, text, x + maxLengthPad + startPad, y, x + getXSize() - maxLengthPad - endPad, y + getLineHeight(), + alignment, titleTextColor(), false); } - default void drawScaledCenteredText(GuiGraphics guiGraphics, Component text, float left, float y, int color, float scale) { - int textWidth = getStringWidth(text); - float centerX = left - (textWidth / 2F) * scale; - drawTextWithScale(guiGraphics, text, centerX, y, color, scale); + default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow) { + drawScrollingString(guiGraphics, text, x, y, alignment, color, getXSize(), maxLengthPad, shadow); } - default void drawCenteredTextScaledBound(GuiGraphics guiGraphics, Component text, float maxLength, float y, int color) { - drawCenteredTextScaledBound(guiGraphics, text, maxLength, 0, y, color); + default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow) { + drawScrollingString(guiGraphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + getLineHeight(), alignment, color, shadow); } - default void drawCenteredTextScaledBound(GuiGraphics guiGraphics, Component text, float maxLength, float x, float y, int color) { - float scale = Math.min(1, maxLength / getStringWidth(text)); - drawScaledCenteredText(guiGraphics, text, x + getXSize() / 2F, y, color, scale); + default void drawScrollingString(GuiGraphics guiGraphics, Component text, int minX, int minY, int maxX, int maxY, TextAlignment alignment, int color, boolean shadow) { + int textWidth = getStringWidth(text); + //Note: Instead of doing what vanilla does, we divide to float, and don't add one + // That way if min and max are not just lineHeight away they will be more accurate, and otherwise it won't render one line below where it should be + float targetY = (minY + maxY - getLineHeight()) / 2F; + int areaWidth = maxX - minX; + if (textWidth > areaWidth) { + int overflowWidth = textWidth - areaWidth; + double seconds = Util.getMillis() / 1_000D; + double scrollPeriod = Math.max(overflowWidth * AbstractWidget.PERIOD_PER_SCROLLED_PIXEL, AbstractWidget.MIN_SCROLL_PERIOD); + double scrolledSoFar = Math.sin((Math.PI / 2) * Math.cos((2 * Math.PI) * seconds / scrollPeriod)) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; + double overflowedBy = scrolledSoFar * overflowWidth;//Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); But that is equivalent to just multiplying performing the multiplication + //Note: We are drawing in relative coordinates, but GuiGraphics#enableScissor, is expecting absolute coordinates, + // so we need to get the translations from our pose stack + int left = getTranslationX(guiGraphics); + int top = getTranslationY(guiGraphics); + guiGraphics.enableScissor(left + minX, top + minY, left + maxX, top + maxY); + //TODO: Float? + drawString(guiGraphics, text, minX - (int) overflowedBy, targetY, color, shadow); + guiGraphics.disableScissor(); + } else { + float targetX = switch (alignment) { + case LEFT -> minX; + case CENTER -> minX + (areaWidth - textWidth) / 2F; + case RIGHT -> maxX - textWidth; + }; + drawString(guiGraphics, text, targetX, targetY, color, shadow); + } } - default void drawTextExact(GuiGraphics guiGraphics, Component text, float x, float y, int color) { - PoseStack pose = guiGraphics.pose(); - pose.pushPose(); - pose.translate(x, y, 0); - drawString(guiGraphics, text, 0, 0, color); - pose.popPose(); + default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow, float scale) { + drawScaledScrollingString(guiGraphics, text, x, y, alignment, color, getXSize(), maxLengthPad, shadow, scale); } - default float getNeededScale(Component text, float maxLength) { - int length = getStringWidth(text); - return length <= maxLength ? 1 : maxLength / length; + default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow, float scale) { + drawScaledScrollingString(guiGraphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + getLineHeight(), alignment, color, shadow, scale); } - default void drawTextScaledBound(GuiGraphics guiGraphics, String text, float x, float y, int color, float maxLength) { - drawTextScaledBound(guiGraphics, TextComponentUtil.getString(text), x, y, color, maxLength); + default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int minX, int minY, int maxX, int maxY, TextAlignment alignment, int color, boolean shadow, + float scale) { + if (scale == 1.0F) { + drawScrollingString(guiGraphics, text, minX, minY, maxX, maxY, alignment, color, shadow); + return; + } + float textWidth = getStringWidth(text) * scale; + //Note: Instead of doing what vanilla does, we divide to float, and don't add one + // That way if min and max are not just lineHeight away they will be more accurate, and otherwise it won't render one line below where it should be + float targetY = (minY + maxY - getLineHeight()) / 2F; + int areaWidth = maxX - minX; + if (textWidth > areaWidth) { + float overflowWidth = textWidth - areaWidth; + double seconds = Util.getMillis() / 1_000D; + double scrollPeriod = Math.max(overflowWidth * AbstractWidget.PERIOD_PER_SCROLLED_PIXEL, AbstractWidget.MIN_SCROLL_PERIOD); + double scrolledSoFar = Math.sin((Math.PI / 2) * Math.cos((2 * Math.PI) * seconds / scrollPeriod)) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; + double overflowedBy = scrolledSoFar * overflowWidth;//Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); But that is equivalent to just multiplying performing the multiplication + //Note: We are drawing in relative coordinates, but GuiGraphics#enableScissor, is expecting absolute coordinates, + // so we need to get the translations from our pose stack + int left = getTranslationX(guiGraphics); + int top = getTranslationY(guiGraphics); + guiGraphics.enableScissor(left + minX, top + minY, left + maxX, top + maxY); + //TODO: Should this cast to float? I believe this makes it less choppy, but a bit blurry? + // So we probably don't want to cast overflowedBy to float + drawTextWithScale(guiGraphics, text, minX - (int) overflowedBy, targetY, color, shadow, scale); + guiGraphics.disableScissor(); + } else { + float targetX = switch (alignment) { + case LEFT -> minX; + case CENTER -> minX + (areaWidth - textWidth) / 2F; + case RIGHT -> maxX - textWidth; + }; + drawTextWithScale(guiGraphics, text, targetX, targetY, color, shadow, scale); + } } - default void drawTextScaledBound(GuiGraphics guiGraphics, Component component, float x, float y, int color, float maxLength) { + //TODO: Call drawScrollingString directly + @Deprecated(forRemoval = true) + default void drawTextScaledBound(GuiGraphics guiGraphics, Component component, int x, int y, int color, int maxLength) { int length = getStringWidth(component); if (length <= maxLength) { - drawTextExact(guiGraphics, component, x, y, color); + drawString(guiGraphics, component, x, y, color, false); } else { - drawTextWithScale(guiGraphics, component, x, y, color, maxLength / length); + drawScrollingString(guiGraphics, component, x, y, x + maxLength, y + getLineHeight(), TextAlignment.LEFT, color, false); } } - default void drawScaledTextScaledBound(GuiGraphics guiGraphics, Component text, float x, float y, int color, float maxX, float textScale) { - float width = getStringWidth(text) * textScale; - float scale = Math.min(1, maxX / width) * textScale; - drawTextWithScale(guiGraphics, text, x, y, color, scale); - } - - default void drawTextWithScale(GuiGraphics guiGraphics, Component text, float x, float y, int color, float scale) { + private void drawTextWithScale(GuiGraphics guiGraphics, Component text, float x, float y, int color, boolean shadow, float scale) { PoseStack pose = prepTextScale(guiGraphics, x, y, scale); - drawString(guiGraphics, text, 0, 0, color); + drawString(guiGraphics, text, 0, 0, color, shadow); pose.popPose(); } - private PoseStack prepTextScale(GuiGraphics guiGraphics, float x, float y, float scale) { - float yAdd = 4 - (scale * 8) / 2F; + //Note: As translate will implicitly cast x and y to being floats, we might as well pass these in as floats to reduce duplicate code + private static PoseStack prepTextScale(GuiGraphics guiGraphics, float x, float y, float scale) { PoseStack pose = guiGraphics.pose(); pose.pushPose(); + return prepTextScale(pose, x, y, scale); + } + + static PoseStack prepTextScale(PoseStack pose, float x, float y, float scale) { + float yAdd = 4 - 4 * scale; pose.translate(x, y + yAdd, 0); pose.scale(scale, scale, scale); return pose; } /** - * @apiNote Consider caching the {@link WrappedTextRenderer} instead of using this method. + * Equivalent to what {@link Matrix4f#getTranslation(Vector3f)} would do, without the extra allocations. */ - default int drawWrappedTextWithScale(GuiGraphics guiGraphics, Component text, float x, float y, int color, float maxLength, float scale) { - return new WrappedTextRenderer(this, text).renderWithScale(guiGraphics, x, y, color, maxLength, scale); + private static int getTranslationX(GuiGraphics guiGraphics) { + return (int) guiGraphics.pose().last().pose().m30(); } /** - * @apiNote Consider caching the {@link WrappedTextRenderer} instead of using this method. + * Equivalent to what {@link Matrix4f#getTranslation(Vector3f)} would do, without the extra allocations. */ - default void drawWrappedCenteredText(GuiGraphics guiGraphics, Component text, float x, float y, int color, float maxLength) { - new WrappedTextRenderer(this, text).renderCentered(guiGraphics, x, y, color, maxLength); + private static int getTranslationY(GuiGraphics guiGraphics) { + return (int) guiGraphics.pose().last().pose().m31(); + } + + enum TextAlignment { + LEFT, + CENTER, + RIGHT } // efficient tool to draw word-by-word wrapped text based on a horizontal bound. looks intimidating but runs in O(n) @@ -152,8 +212,8 @@ class WrappedTextRenderer { private final String text; @Nullable private Font lastFont; - private float lastMaxLength = -1; - private float lineLength = 0; + private int lastMaxLength = -1; + private int lineLength = 0; public WrappedTextRenderer(IFancyFontRenderer font, Component text) { this(font, text.getString()); @@ -164,38 +224,41 @@ public WrappedTextRenderer(IFancyFontRenderer font, String text) { this.text = text; } - public void renderCentered(GuiGraphics guiGraphics, float x, float y, int color, float maxLength) { + public void renderCentered(GuiGraphics guiGraphics, int x, int y, int color, int maxLength) { calculateLines(maxLength); - float startY = y; + int startY = y; + int lineHeight = font.getLineHeight(); + int width = font.getXSize(); for (LineData line : linesToDraw) { - font.drawTextExact(guiGraphics, line.component(), x - line.length() / 2, startY, color); - startY += 9; + font.drawString(guiGraphics, line.component(), x + (width - line.length()) / 2F, startY, color, false); + startY += lineHeight; } } - public int renderWithScale(GuiGraphics guiGraphics, float x, float y, int color, float maxLength, float scale) { + public int renderWithScale(GuiGraphics guiGraphics, int x, int y, int color, int maxLength, float scale) { //Divide by scale for calculating actual max length so that when the text is scaled it has the proper total space available - calculateLines(maxLength / scale); - PoseStack pose = font.prepTextScale(guiGraphics, x, y, scale); + calculateLines(Mth.floor(maxLength / scale)); + PoseStack pose = prepTextScale(guiGraphics, x, y, scale); int startY = 0; + int lineHeight = font.getLineHeight(); for (LineData line : linesToDraw) { - font.drawString(guiGraphics, line.component(), 0, startY, color); - startY += 9; + font.drawString(guiGraphics, line.component(), 0, startY, color, false); + startY += lineHeight; } pose.popPose(); return linesToDraw.size(); } - void calculateLines(float maxLength) { + void calculateLines(int maxLength) { //If something changed since the last time we calculated it - Font font = this.font.getFont(); + Font font = this.font.font(); if (font != null && (lastFont != font || lastMaxLength != maxLength)) { lastFont = font; lastMaxLength = maxLength; linesToDraw.clear(); StringBuilder lineBuilder = new StringBuilder(); StringBuilder wordBuilder = new StringBuilder(); - int spaceLength = lastFont.width(" "); + int spaceLength = font.width(" "); int wordLength = 0; for (char c : text.toCharArray()) { if (c == ' ') { @@ -205,22 +268,22 @@ void calculateLines(float maxLength) { continue; } wordBuilder.append(c); - wordLength += lastFont.width(Character.toString(c)); + wordLength += font.width(Character.toString(c)); } if (!wordBuilder.isEmpty()) { lineBuilder = addWord(lineBuilder, wordBuilder, maxLength, spaceLength, wordLength); } if (!lineBuilder.isEmpty()) { - linesToDraw.add(new LineData(TextComponentUtil.getString(lineBuilder.toString()), lineLength)); + linesToDraw.add(new LineData(lineBuilder, lineLength)); } } } - StringBuilder addWord(StringBuilder lineBuilder, StringBuilder wordBuilder, float maxLength, int spaceLength, int wordLength) { + StringBuilder addWord(StringBuilder lineBuilder, StringBuilder wordBuilder, int maxLength, int spaceLength, int wordLength) { // ignore spacing if this is the first word of the line - float spacingLength = lineBuilder.isEmpty() ? 0 : spaceLength; + int spacingLength = lineBuilder.isEmpty() ? 0 : spaceLength; if (lineLength + spacingLength + wordLength > maxLength) { - linesToDraw.add(new LineData(TextComponentUtil.getString(lineBuilder.toString()), lineLength)); + linesToDraw.add(new LineData(lineBuilder, lineLength)); lineBuilder = new StringBuilder(wordBuilder); lineLength = wordLength; } else { @@ -233,28 +296,24 @@ StringBuilder addWord(StringBuilder lineBuilder, StringBuilder wordBuilder, floa return lineBuilder; } - public static int calculateHeightRequired(Font font, Component text, int width, float maxLength) { - return calculateHeightRequired(font, text.getString(), width, maxLength); + public static int calculateHeightRequired(Font font, Component text, int width, int maxLength) { + //TODO: Come up with a better way of doing this (maybe allow it to somehow replace what the stored font is + // that way we can calculate, and then use the calculated values in our actual renderer without having to calculate once more + WrappedTextRenderer wrappedTextRenderer = new WrappedTextRenderer(new SimpleFancyFontRenderer(font, width), text); + wrappedTextRenderer.calculateLines(maxLength); + return font.lineHeight * wrappedTextRenderer.linesToDraw.size(); } - public static int calculateHeightRequired(Font font, String text, int width, float maxLength) { - //TODO: Come up with a better way of doing this - WrappedTextRenderer wrappedTextRenderer = new WrappedTextRenderer(new IFancyFontRenderer() { - @Override - public int getXSize() { - return width; - } + private record LineData(Component component, int length) { - @Override - public Font getFont() { - return font; - } - }, text); - wrappedTextRenderer.calculateLines(maxLength); - return 9 * wrappedTextRenderer.linesToDraw.size(); + private LineData(StringBuilder lineBuilder, int length) { + //TODO - 1.21: Make use of the style of the passed in parent component that we split during? + // Similar to StringSplitter$LineBreakFinder + this(TextComponentUtil.getString(lineBuilder.toString()), length); + } } - private record LineData(Component component, float length) { + private record SimpleFancyFontRenderer(Font font, int getXSize) implements IFancyFontRenderer { } } } diff --git a/src/main/java/mekanism/common/integration/lookingat/LookingAtElement.java b/src/main/java/mekanism/common/integration/lookingat/LookingAtElement.java index 22960a36134..96ee4f53141 100644 --- a/src/main/java/mekanism/common/integration/lookingat/LookingAtElement.java +++ b/src/main/java/mekanism/common/integration/lookingat/LookingAtElement.java @@ -1,17 +1,18 @@ package mekanism.common.integration.lookingat; -import com.mojang.blaze3d.vertex.PoseStack; import mekanism.client.gui.GuiUtils; import mekanism.client.gui.GuiUtils.TilingDirection; +import mekanism.client.render.IFancyFontRenderer; import mekanism.client.render.MekanismRenderer; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public abstract class LookingAtElement implements ILookingAtElement { +public abstract class LookingAtElement implements ILookingAtElement, IFancyFontRenderer { private final int borderColor; private final int textColor; @@ -40,17 +41,27 @@ public void render(@NotNull GuiGraphics guiGraphics, int x, int y) { } } } - renderScaledText(Minecraft.getInstance(), guiGraphics, x + 4, y + 3, textColor, width - 8, getText()); + drawScrollingString(guiGraphics, getText(), x, y + 3, TextAlignment.LEFT, textColor, 4, false); } public int getWidth() { return 100; } + @Override + public int getXSize() { + return getWidth(); + } + public int getHeight() { return 13; } + @Override + public Font font() { + return Minecraft.getInstance().font; + } + public abstract int getScaledLevel(int level); @Nullable @@ -61,20 +72,4 @@ public int getHeight() { protected boolean applyRenderColor(GuiGraphics guiGraphics) { return false; } - - public static void renderScaledText(Minecraft mc, @NotNull GuiGraphics guiGraphics, float x, float y, int color, float maxWidth, Component component) { - int length = mc.font.width(component); - if (length <= maxWidth) { - GuiUtils.drawString(guiGraphics, mc.font, component, x, y, color, false); - } else { - float scale = maxWidth / length; - float reverse = 1 / scale; - float yAdd = 4 - (scale * 8) / 2F; - PoseStack pose = guiGraphics.pose(); - pose.pushPose(); - pose.scale(scale, scale, scale); - guiGraphics.drawString(mc.font, component, (int) (x * reverse), (int) ((y * reverse) + yAdd), color, false); - pose.popPose(); - } - } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/lookingat/jade/JadeTooltipRenderer.java b/src/main/java/mekanism/common/integration/lookingat/jade/JadeTooltipRenderer.java index 0a498357bce..b7d79fa0003 100644 --- a/src/main/java/mekanism/common/integration/lookingat/jade/JadeTooltipRenderer.java +++ b/src/main/java/mekanism/common/integration/lookingat/jade/JadeTooltipRenderer.java @@ -1,6 +1,5 @@ package mekanism.common.integration.lookingat.jade; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; @@ -8,13 +7,13 @@ import java.util.Optional; import java.util.function.Function; import mekanism.api.SerializationConstants; +import mekanism.client.render.IFancyFontRenderer.TextAlignment; import mekanism.common.integration.lookingat.ChemicalElement; import mekanism.common.integration.lookingat.EnergyElement; import mekanism.common.integration.lookingat.FluidElement; import mekanism.common.integration.lookingat.ILookingAtElement; import mekanism.common.integration.lookingat.LookingAtElement; import mekanism.common.integration.lookingat.TextElement; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -23,6 +22,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import net.minecraft.world.phys.Vec2; import net.neoforged.neoforge.common.util.NeoForgeExtraCodecs; import org.jetbrains.annotations.Nullable; @@ -125,16 +125,14 @@ public Vec2 getSize() { } @Override - public void render(GuiGraphics guiGraphics, float x, float y, float maxX, float maxY) { + public void render(GuiGraphics guiGraphics, float rawX, float rawY, float maxX, float maxY) { + int x = Mth.floor(rawX); + int y = Mth.floor(rawY); if (text != null) { - LookingAtElement.renderScaledText(Minecraft.getInstance(), guiGraphics, x + 4, y + 3, 0xFFFFFF, 92, text); + element.drawScrollingString(guiGraphics, text, x,y + 3, TextAlignment.LEFT, 0xFFFFFF, 4, false); y += 13; } - PoseStack pose = guiGraphics.pose(); - pose.pushPose(); - pose.translate(x, y, 0); - element.render(guiGraphics, 0, 1); - pose.popPose(); + element.render(guiGraphics, x, y + 1); } } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/integration/lookingat/wthit/WTHITTooltipRenderer.java b/src/main/java/mekanism/common/integration/lookingat/wthit/WTHITTooltipRenderer.java index 9c8c84d436c..ab4931d9a72 100644 --- a/src/main/java/mekanism/common/integration/lookingat/wthit/WTHITTooltipRenderer.java +++ b/src/main/java/mekanism/common/integration/lookingat/wthit/WTHITTooltipRenderer.java @@ -1,6 +1,5 @@ package mekanism.common.integration.lookingat.wthit; -import com.mojang.blaze3d.vertex.PoseStack; import mcp.mobius.waila.api.IBlockAccessor; import mcp.mobius.waila.api.IBlockComponentProvider; import mcp.mobius.waila.api.IDataReader; @@ -9,11 +8,11 @@ import mcp.mobius.waila.api.IPluginConfig; import mcp.mobius.waila.api.ITooltip; import mcp.mobius.waila.api.ITooltipComponent; +import mekanism.client.render.IFancyFontRenderer.TextAlignment; import mekanism.common.integration.lookingat.ILookingAtElement; import mekanism.common.integration.lookingat.LookingAtElement; import mekanism.common.integration.lookingat.TextElement; import net.minecraft.client.DeltaTracker; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; @@ -80,14 +79,10 @@ public int getHeight() { @Override public void render(GuiGraphics guiGraphics, int x, int y, DeltaTracker delta) { if (text != null) { - LookingAtElement.renderScaledText(Minecraft.getInstance(), guiGraphics, x + 4, y + 3, 0xFFFFFF, 92, text); + element.drawScrollingString(guiGraphics, text, x, y + 3, TextAlignment.LEFT, 0xFFFFFF, 4, false); y += 13; } - PoseStack pose = guiGraphics.pose(); - pose.pushPose(); - pose.translate(x, y, 0); - element.render(guiGraphics, 0, 1); - pose.popPose(); + element.render(guiGraphics, x, y + 1); } } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/util/UnitDisplayUtils.java b/src/main/java/mekanism/common/util/UnitDisplayUtils.java index fdd7634ecad..b89278353f9 100644 --- a/src/main/java/mekanism/common/util/UnitDisplayUtils.java +++ b/src/main/java/mekanism/common/util/UnitDisplayUtils.java @@ -31,6 +31,24 @@ public class UnitDisplayUtils { //TODO: Maybe at some point improve on the ITextComponents the two getDisplay methods build, and have them have better translation keys with formats // That would improve how well this handles en_ud as currently the order of the number and the unit is not reversed and the unit is not upside down + private static final Unit IGNORED_UNIT = new Unit() { + + @Override + public Component appendTo(Object existing, boolean isShort, boolean spaceBetweenSymbol, boolean singular) { + return TextComponentUtil.build(existing); + } + + @Override + public Object getSymbol(boolean singular) { + return null; + } + + @Override + public ILangEntry getLabel(boolean singular) { + return null; + } + }; + public static Component getDisplayShort(double value, EnergyUnit unit) { return getDisplayBase(value, unit, 2, true, true); } @@ -39,15 +57,13 @@ public static Component getDisplay(double temp, TemperatureUnit unit, int decima return getDisplayBase(unit.convertFromK(temp, shift), unit, decimalPlaces, isShort, spaceBetweenSymbol); } + public static Component getDisplay(double value, int decimalPlaces) { + return getDisplayBase(value, IGNORED_UNIT, decimalPlaces, true, false); + } + private static Component getDisplayBase(double value, Unit unit, int decimalPlaces, boolean isShort, boolean spaceBetweenSymbol) { if (value == 0) { - if (isShort) { - if (spaceBetweenSymbol) { - return TextComponentUtil.build(value + " ", unit.getSymbol(false)); - } - return TextComponentUtil.build(value, unit.getSymbol(false)); - } - return TextComponentUtil.build(value, unit.getLabel(false)); + return unit.appendTo(value, isShort, spaceBetweenSymbol, false); } boolean singular = Mth.equal(value, 1); boolean negative = value < 0; @@ -101,6 +117,16 @@ public static double roundDecimals(double d) { private interface Unit { + default Component appendTo(Object existing, boolean isShort, boolean spaceBetweenSymbol, boolean singular) { + if (isShort) { + if (spaceBetweenSymbol) { + return TextComponentUtil.build(existing + " ", getSymbol(singular)); + } + return TextComponentUtil.build(existing, getSymbol(singular)); + } + return TextComponentUtil.build(existing, getLabel(singular)); + } + Object getSymbol(boolean singular); ILangEntry getLabel(boolean singular); @@ -357,10 +383,8 @@ private Component getDisplay(double value, Unit unit, int decimalPlaces, boolean if (spaceBetweenSymbol || !isShort) { name = " " + name; } - if (isShort) { - return TextComponentUtil.build(rounded + name, unit.getSymbol(singular)); - } - return TextComponentUtil.build(rounded + name, unit.getLabel(singular)); + //Note: We handle the space between symbols above + return unit.appendTo(rounded + name, isShort, false, singular); } } } \ No newline at end of file diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 12154e9c524..741effb3c85 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -7,6 +7,9 @@ public-f net.minecraft.client.gui.components.AbstractWidget render(Lnet/minecraf public net.minecraft.client.gui.components.events.ContainerEventHandler handleArrowNavigation(Lnet/minecraft/client/gui/navigation/FocusNavigationEvent$ArrowNavigation;)Lnet/minecraft/client/gui/ComponentPath; public net.minecraft.client.gui.components.events.ContainerEventHandler handleTabNavigation(Lnet/minecraft/client/gui/navigation/FocusNavigationEvent$TabNavigation;)Lnet/minecraft/client/gui/ComponentPath; +public net.minecraft.client.gui.components.AbstractWidget MIN_SCROLL_PERIOD +public net.minecraft.client.gui.components.AbstractWidget PERIOD_PER_SCROLLED_PIXEL + public net.minecraft.client.gui.components.EditBox canLoseFocus public net.minecraft.client.gui.components.EditBox maxLength public net.minecraft.client.gui.components.EditBox highlightPos From 05aad4d2740be3ea6b36d78ee575f6172161534e Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Sun, 22 Sep 2024 13:30:37 -0500 Subject: [PATCH 02/17] Continued work on unifying all our gui string rendering to supporting scrolling if it ends up going out of bounds --- .../client/gui/GuiFissionReactorStats.java | 19 ++--- .../gui/GuiFusionReactorLogicAdapter.java | 3 +- .../client/gui/GuiFusionReactorStats.java | 49 +++++++------ .../client/gui/GuiLaserAmplifier.java | 14 ++-- .../java/mekanism/client/gui/GuiMekanism.java | 13 +++- .../mekanism/client/gui/GuiSecurityDesk.java | 2 +- .../java/mekanism/client/gui/GuiUtils.java | 2 +- .../client/gui/element/GuiArrowSelection.java | 13 +++- .../client/gui/element/GuiElement.java | 15 ++-- .../client/gui/element/GuiInnerScreen.java | 4 ++ .../gui/element/button/FilterButton.java | 25 +++---- .../client/gui/element/button/GuiGasMode.java | 13 ++-- .../element/button/MovableFilterButton.java | 5 -- .../element/custom/GuiFrequencySelector.java | 32 +++++---- .../element/custom/GuiSupportedUpgrades.java | 38 +++++++--- .../element/scroll/GuiUpgradeScrollList.java | 4 +- .../client/gui/element/tab/GuiSortingTab.java | 2 +- .../gui/element/window/GuiColorWindow.java | 3 +- .../gui/element/window/GuiUpgradeWindow.java | 2 +- .../client/gui/element/window/GuiWindow.java | 2 +- .../client/gui/item/GuiSeismicReader.java | 70 ++++++++++++------- .../GuiAntiprotonicNucleosynthesizer.java | 6 +- .../gui/machine/GuiChemicalInfuser.java | 2 +- .../gui/machine/GuiDigitalMinerConfig.java | 8 +-- .../mekanism/client/gui/machine/GuiPRC.java | 2 +- .../client/gui/machine/GuiPigmentMixer.java | 2 +- .../gui/qio/GuiQIOItemFrequencySelect.java | 8 +-- .../client/gui/qio/GuiQIOItemViewer.java | 2 +- .../gui/qio/GuiQIOTileFrequencySelect.java | 8 +-- .../client/gui/robit/GuiRobitMain.java | 16 +++-- .../client/gui/robit/GuiRobitRepair.java | 2 +- .../client/render/IFancyFontRenderer.java | 62 ++++++++-------- .../mekanism/common/entity/EntityRobit.java | 1 + 33 files changed, 243 insertions(+), 206 deletions(-) diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorStats.java b/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorStats.java index 7593479c3bc..d5e0eeb603e 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorStats.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorStats.java @@ -84,16 +84,17 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, renderTitleText(guiGraphics); FissionReactorMultiblockData multiblock = tile.getMultiblock(); // heat stats - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_HEAT_STATISTICS.translate(), 6, 20, headingTextColor(), imageWidth - 12); - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_HEAT_CAPACITY.translate(TextUtils.format((long) multiblock.heatCapacitor.getHeatCapacity())), 6, 32, titleTextColor(), imageWidth - 12); - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_SURFACE_AREA.translate(TextUtils.format(multiblock.surfaceArea)), 6, 42, titleTextColor(), imageWidth - 12); - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_BOIL_EFFICIENCY.translate(tile.getBoilEfficiency()), 6, 52, titleTextColor(), imageWidth - 12); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_HEAT_STATISTICS.translate(), 0, 20, TextAlignment.LEFT, headingTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_HEAT_CAPACITY.translate(TextUtils.format((long) multiblock.heatCapacitor.getHeatCapacity())), 0, 32, TextAlignment.LEFT, titleTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_SURFACE_AREA.translate(TextUtils.format(multiblock.surfaceArea)), 0, 42, TextAlignment.LEFT, titleTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_BOIL_EFFICIENCY.translate(tile.getBoilEfficiency()), 0, 52, TextAlignment.LEFT, titleTextColor(), 6, false); // fuel stats - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_FUEL_STATISTICS.translate(), 6, 68, headingTextColor(), imageWidth - 12); - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_MAX_BURN_RATE.translate(TextUtils.format(multiblock.getMaxBurnRate())), 6, 80, titleTextColor(), imageWidth - 12); - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_RATE_LIMIT.translate(multiblock.rateLimit), 6, 90, titleTextColor(), imageWidth - 12); - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_CURRENT_BURN_RATE.translate(), 6, 104, titleTextColor(), imageWidth - 12); - drawTextScaledBound(guiGraphics, GeneratorsLang.FISSION_SET_RATE_LIMIT.translate(), 6, 130, titleTextColor(), 69); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_FUEL_STATISTICS.translate(), 0, 68, TextAlignment.LEFT, headingTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_MAX_BURN_RATE.translate(TextUtils.format(multiblock.getMaxBurnRate())), 0, 80, TextAlignment.LEFT, titleTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_RATE_LIMIT.translate(multiblock.rateLimit), 0, 90, TextAlignment.LEFT, titleTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_CURRENT_BURN_RATE.translate(), 0, 104, TextAlignment.LEFT, titleTextColor(), 6, false); + + drawScrollingString(guiGraphics, GeneratorsLang.FISSION_SET_RATE_LIMIT.translate(), 3, 130, TextAlignment.RIGHT, titleTextColor(), rateLimitField.getRelativeX() - 2, 3, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java index a2aed8db7f1..784d594d13c 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java @@ -55,7 +55,8 @@ private void changeLogic(FusionReactorLogic type) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_LOGIC_ACTIVE_COOLING.translate(EnumColor.RED, OnOff.of(tile.isActiveCooled())), 29, 20, titleTextColor(), 117); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_ACTIVE_COOLING.translate(EnumColor.RED, OnOff.of(tile.isActiveCooled())), 13, 20, TextAlignment.LEFT, + titleTextColor(), getXSize() - 13, 16, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(EnumColor.RED, tile.logicType), 0, 123, TextAlignment.CENTER, titleTextColor(), 16, false); drawScrollingString(guiGraphics, MekanismLang.STATUS.translate(EnumColor.RED, tile.checkMode() ? GeneratorsLang.REACTOR_LOGIC_OUTPUTTING : MekanismLang.IDLE), 0, 136, TextAlignment.CENTER, titleTextColor(), 16, false); diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java index 6f79977f557..8e7183b9347 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java @@ -34,29 +34,34 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, renderTitleText(guiGraphics); FusionReactorMultiblockData multiblock = tile.getMultiblock(); if (multiblock.isFormed()) { - drawScrollingString(guiGraphics,GeneratorsLang.REACTOR_PASSIVE.translateColored(EnumColor.DARK_GREEN), 0, 26, TextAlignment.LEFT, titleTextColor(), 6, false); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_MIN_INJECTION.translate(multiblock.getMinInjectionRate(false)), 16, 36, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_IGNITION.translate(MekanismUtils.getTemperatureDisplay(multiblock.getIgnitionTemperature(false), - TemperatureUnit.KELVIN, true)), 16, 46, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_MAX_PLASMA.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxPlasmaTemperature(false), - TemperatureUnit.KELVIN, true)), 16, 56, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_MAX_CASING.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxCasingTemperature(false), - TemperatureUnit.KELVIN, true)), 16, 66, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_PASSIVE_RATE.translate(EnergyDisplay.of(multiblock.getPassiveGeneration(false, false))), - 16, 76, titleTextColor(), 156); + int textArea = getXSize() - 8; + drawScrollingString(guiGraphics,GeneratorsLang.REACTOR_PASSIVE.translateColored(EnumColor.DARK_GREEN), + 0, 26, TextAlignment.LEFT, titleTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MIN_INJECTION.translate(multiblock.getMinInjectionRate(false)), + 8, 36, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_IGNITION.translate(MekanismUtils.getTemperatureDisplay(multiblock.getIgnitionTemperature(false), TemperatureUnit.KELVIN, true)), + 8, 46, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MAX_PLASMA.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxPlasmaTemperature(false), TemperatureUnit.KELVIN, true)), + 8, 56, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MAX_CASING.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxCasingTemperature(false), TemperatureUnit.KELVIN, true)), + 8, 66, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_PASSIVE_RATE.translate(EnergyDisplay.of(multiblock.getPassiveGeneration(false, false))), + 8, 76, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); - drawScrollingString(guiGraphics,GeneratorsLang.REACTOR_ACTIVE.translateColored(EnumColor.DARK_BLUE), 0, 92, TextAlignment.LEFT, titleTextColor(), 6, false); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_MIN_INJECTION.translate(multiblock.getMinInjectionRate(true)), 16, 102, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_IGNITION.translate(MekanismUtils.getTemperatureDisplay(multiblock.getIgnitionTemperature(true), - TemperatureUnit.KELVIN, true)), 16, 112, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_MAX_PLASMA.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxPlasmaTemperature(true), - TemperatureUnit.KELVIN, true)), 16, 122, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_MAX_CASING.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxCasingTemperature(true), - TemperatureUnit.KELVIN, true)), 16, 132, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_PASSIVE_RATE.translate(EnergyDisplay.of(multiblock.getPassiveGeneration(true, false))), - 16, 142, titleTextColor(), 156); - drawTextScaledBound(guiGraphics, GeneratorsLang.REACTOR_STEAM_PRODUCTION.translate(TextUtils.format(multiblock.getSteamPerTick(false))), - 16, 152, titleTextColor(), 156); + drawScrollingString(guiGraphics,GeneratorsLang.REACTOR_ACTIVE.translateColored(EnumColor.DARK_BLUE), + 0, 92, TextAlignment.LEFT, titleTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MIN_INJECTION.translate(multiblock.getMinInjectionRate(true)), + 8, 102, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_IGNITION.translate(MekanismUtils.getTemperatureDisplay(multiblock.getIgnitionTemperature(true), TemperatureUnit.KELVIN, true)), + 8, 112, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MAX_PLASMA.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxPlasmaTemperature(true), TemperatureUnit.KELVIN, true)), + 8, 122, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MAX_CASING.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxCasingTemperature(true), TemperatureUnit.KELVIN, true)), + 8, 132, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_PASSIVE_RATE.translate(EnergyDisplay.of(multiblock.getPassiveGeneration(true, false))), + 8, 142, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_STEAM_PRODUCTION.translate(TextUtils.format(multiblock.getSteamPerTick(false))), + 8, 152, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); } super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java b/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java index fa1073d0206..4ce45533b12 100644 --- a/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java +++ b/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java @@ -26,6 +26,7 @@ public class GuiLaserAmplifier extends GuiMekanismTile> { private GuiTextField minField, maxField, timerField; + private GuiEnergyGauge energyGauge; public GuiLaserAmplifier(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); @@ -35,7 +36,7 @@ public GuiLaserAmplifier(MekanismTileContainer contain @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiEnergyGauge(tile.getEnergyContainer(), GaugeType.STANDARD, this, 6, 10)); + energyGauge = addRenderableWidget(new GuiEnergyGauge(tile.getEnergyContainer(), GaugeType.STANDARD, this, 6, 10)); addRenderableWidget(new GuiEnergyTab(this, () -> List.of(MekanismLang.STORING.translate(EnergyDisplay.of(tile.getEnergyContainer()))))); addRenderableWidget(new GuiAmplifierTab(this, tile)); timerField = addRenderableWidget(new GuiTextField(this, 96, 28, 36, 11)); @@ -56,13 +57,16 @@ protected void addGuiElements() { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); renderInventoryText(guiGraphics); + int start = energyGauge.getRelativeX() + energyGauge.getWidth(); + Component delay; if (tile.getDelay() > 0) { - drawTextScaledBound(guiGraphics, MekanismLang.DELAY.translate(tile.getDelay()), 26, 30, titleTextColor(), 68); + delay = MekanismLang.DELAY.translate(tile.getDelay()); } else { - drawTextScaledBound(guiGraphics, MekanismLang.NO_DELAY.translate(), 26, 30, titleTextColor(), 68); + delay = MekanismLang.NO_DELAY.translate(); } - drawTextScaledBound(guiGraphics, MekanismLang.MIN.translate(EnergyDisplay.of(tile.getMinThreshold())), 26, 45, titleTextColor(), 68); - drawTextScaledBound(guiGraphics, MekanismLang.MAX.translate(EnergyDisplay.of(tile.getMaxThreshold())), 26, 60, titleTextColor(), 68); + drawScrollingString(guiGraphics, delay, start, 30, TextAlignment.LEFT, titleTextColor(), timerField.getRelativeX() - start, 2, false); + drawScrollingString(guiGraphics, MekanismLang.MIN.translate(EnergyDisplay.of(tile.getMinThreshold())), start, 45, TextAlignment.LEFT, titleTextColor(), minField.getRelativeX() - start, 2, false); + drawScrollingString(guiGraphics, MekanismLang.MAX.translate(EnergyDisplay.of(tile.getMaxThreshold())), start, 60, TextAlignment.LEFT, titleTextColor(), maxField.getRelativeX() - start, 2, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/GuiMekanism.java b/src/main/java/mekanism/client/gui/GuiMekanism.java index 27635bc9fc9..4f5f8d23452 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanism.java +++ b/src/main/java/mekanism/client/gui/GuiMekanism.java @@ -168,11 +168,20 @@ public void containerTick() { } protected void renderTitleText(GuiGraphics guiGraphics) { + //TODO - 1.21: Evaluate what other ones should be moved to rendering with offset. For example the electrolytic separator drawTitleText(guiGraphics, title, titleLabelY); } - protected void renderTitleTextWithOffset(GuiGraphics guiGraphics, int startPad, int endPad, int maxLengthPad, TextAlignment alignment) { - drawTitleTextTextWithOffset(guiGraphics, title, 0, titleLabelY, startPad, endPad, maxLengthPad, alignment); + protected void renderTitleTextWithOffset(GuiGraphics guiGraphics, int x) { + drawTitleTextTextWithOffset(guiGraphics, title, x, titleLabelY); + } + + protected void renderTitleTextWithOffset(GuiGraphics guiGraphics, int x, int end) { + drawTitleTextTextWithOffset(guiGraphics, title, x, titleLabelY, end); + } + + protected void renderTitleTextWithOffset(GuiGraphics guiGraphics, int x, int end, int maxLengthPad, TextAlignment alignment) { + drawTitleTextTextWithOffset(guiGraphics, title, x, titleLabelY, end, maxLengthPad, alignment); } protected void renderInventoryText(GuiGraphics guiGraphics) { diff --git a/src/main/java/mekanism/client/gui/GuiSecurityDesk.java b/src/main/java/mekanism/client/gui/GuiSecurityDesk.java index 952d100f711..1fb8707596e 100644 --- a/src/main/java/mekanism/client/gui/GuiSecurityDesk.java +++ b/src/main/java/mekanism/client/gui/GuiSecurityDesk.java @@ -189,7 +189,7 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, frequencyText = MekanismLang.SECURITY.translate(frequency.getSecurity()); } drawScrollingString(guiGraphics, frequencyText, 13, 103, TextAlignment.LEFT, titleTextColor(), 122, 0, false); - drawTextScaledBound(guiGraphics, MekanismLang.SECURITY_ADD.translate(), 13, 70, titleTextColor(), 20); + drawScrollingString(guiGraphics, MekanismLang.SECURITY_ADD.translate(), 1, 70, TextAlignment.RIGHT, titleTextColor(), trustedField.getRelativeX() - 1, 3, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiUtils.java b/src/main/java/mekanism/client/gui/GuiUtils.java index 5de91d77ce9..ab1e6099f7f 100644 --- a/src/main/java/mekanism/client/gui/GuiUtils.java +++ b/src/main/java/mekanism/client/gui/GuiUtils.java @@ -73,7 +73,7 @@ public static void fill(GuiGraphics guiGraphics, int x, int y, int width, int he } public static void drawBackdrop(GuiGraphics guiGraphics, Minecraft minecraft, int x, int y, int width, int alpha) { - drawBackdrop(guiGraphics, minecraft, x, y, width, 9, alpha); + drawBackdrop(guiGraphics, minecraft, x, y, width, minecraft.font.lineHeight, alpha); } public static void drawBackdrop(GuiGraphics guiGraphics, Minecraft minecraft, int x, int y, int width, int height, int alpha) { diff --git a/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java b/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java index 2846f8bb98e..599c524d0a7 100644 --- a/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java +++ b/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java @@ -16,10 +16,12 @@ public class GuiArrowSelection extends GuiTexturedElement { private static final ResourceLocation ARROW = MekanismUtils.getResource(ResourceType.GUI, "arrow_selection.png"); private final Supplier textComponentSupplier; + private final Supplier targetText; - public GuiArrowSelection(IGuiWrapper gui, int x, int y, Supplier textComponentSupplier) { + public GuiArrowSelection(IGuiWrapper gui, int x, int y, Supplier textComponentSupplier, Supplier targetText) { super(ARROW, gui, x, y, 33, 19); this.textComponentSupplier = textComponentSupplier; + this.targetText = targetText; } @Override @@ -46,6 +48,15 @@ public void renderToolTip(@NotNull GuiGraphics guiGraphics, int mouseX, int mous } } + @Override + public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { + super.renderForeground(guiGraphics, mouseX, mouseY); + Component component = targetText.get(); + if (component != null) { + drawScrollingString(guiGraphics, component, getWidth(), 6, TextAlignment.LEFT, screenTextColor(), 15, 1, false); + } + } + @Override public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks); diff --git a/src/main/java/mekanism/client/gui/element/GuiElement.java b/src/main/java/mekanism/client/gui/element/GuiElement.java index adc0d93d50a..bc127c8fcc9 100644 --- a/src/main/java/mekanism/client/gui/element/GuiElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiElement.java @@ -616,11 +616,10 @@ protected void drawButtonText(GuiGraphics guiGraphics, int mouseX, int mouseY) { //Only attempt to draw the message if we have a message to draw if (!text.getString().isEmpty()) { int color = getButtonTextColor(mouseX, mouseY) | Mth.ceil(alpha * 255.0F) << 24; - int buttonX = getButtonX(); - int buttonY = getButtonY(); //TODO - 1.21: Do we want to be passing false to this so that it has no shadow? I believe previously we didn't render the shadow - //TODO - 1.21: Aka do we want to use the one in IFancyFontRenderer? - renderScrollingString(guiGraphics, font(), text, buttonX + 2, buttonY, buttonX + getButtonWidth() - 2, buttonY + getButtonHeight(), color); + // but vanilla does render the shadow for buttons, so I think we may want to be rendering it? + //Note: We call super as currently getButtonX and getButtonY already factor in the relative positioning + IFancyFontRenderer.super.drawScrollingString(guiGraphics, text, getButtonX(), getButtonY(), TextAlignment.CENTER, color, getButtonWidth(), getButtonHeight(), 2, true); } } @@ -680,13 +679,13 @@ protected void drawTiledSprite(GuiGraphics guiGraphics, int xPosition, int yPosi } @Override - public void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow) { - IFancyFontRenderer.super.drawScrollingString(guiGraphics, text, relativeX + x, relativeY + y, alignment, color, width, maxLengthPad, shadow); + public final void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, boolean shadow) { + IFancyFontRenderer.super.drawScrollingString(guiGraphics, text, relativeX + x, relativeY + y, alignment, color, width, height, maxLengthPad, shadow); } @Override - public void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow, float scale) { - IFancyFontRenderer.super.drawScaledScrollingString(guiGraphics, text, relativeX + x, relativeY + y, alignment, color, width, maxLengthPad, shadow, scale); + public final void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, boolean shadow, float scale) { + IFancyFontRenderer.super.drawScaledScrollingString(guiGraphics, text, relativeX + x, relativeY + y, alignment, color, width, height, maxLengthPad, shadow, scale); } public enum ButtonBackground { diff --git a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java index be0362a7ea5..14fd8824cd1 100644 --- a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java +++ b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java @@ -65,6 +65,10 @@ public GuiInnerScreen padding(int padding) { return this; } + public GuiInnerScreen clearScale() { + return textScale(1); + } + public GuiInnerScreen textScale(float textScale) { this.textScale = textScale; return this; diff --git a/src/main/java/mekanism/client/gui/element/button/FilterButton.java b/src/main/java/mekanism/client/gui/element/button/FilterButton.java index f516696085d..fb528a3b151 100644 --- a/src/main/java/mekanism/client/gui/element/button/FilterButton.java +++ b/src/main/java/mekanism/client/gui/element/button/FilterButton.java @@ -136,9 +136,12 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { case ITagFilter tag -> Component.literal(tag.getTagName()); case IModIDFilter modId -> Component.literal(modId.getModID()); case OredictionificatorFilter oredictionificatorFilter -> Component.literal(oredictionificatorFilter.getFilterText()); - case null, default -> Component.empty(); + case null, default -> null; }; - drawFilterDescriptor(guiGraphics, filterDescriptor, relativeX, relativeY); + int textWidth = toggleButton.getRelativeX() - relativeX - 20; + if (filterDescriptor != null) { + drawScrollingString(guiGraphics, filterDescriptor, 19, 3, TextAlignment.LEFT, titleTextColor(), textWidth, 3, false); + } if (filter instanceof SorterFilter sorterFilter) { int colorX = relativeX + 22; @@ -149,27 +152,15 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { } Component color = sorterFilter.color == null ? MekanismLang.NO_COLOR.translate() : sorterFilter.color.getName(); - drawScaledScrollingString(guiGraphics, color, 27, 12, TextAlignment.LEFT, titleTextColor(), getSmallTextWidth() - 8, 3, false, 0.7F); + drawScaledScrollingString(guiGraphics, color, 27, 12, TextAlignment.LEFT, titleTextColor(), textWidth - 8, 3, false, 0.7F); } else if (filter instanceof OredictionificatorItemFilter oreDictFilter) { ItemStack result = oreDictFilter.getResult(); Component text = TextComponentUtil.build(result, " (", BuiltInRegistries.ITEM.getKey(result.getItem()).getNamespace(), ")"); - drawScaledScrollingString(guiGraphics, text, 19, 12, TextAlignment.LEFT, titleTextColor(), getSmallTextWidth(), 3, false, 0.7F); + drawScaledScrollingString(guiGraphics, text, 19, 12, TextAlignment.LEFT, titleTextColor(), textWidth, 3, false, 0.7F); } else if (filter instanceof QIOItemStackFilter itemFilter) { if (itemFilter.fuzzyMode) { - drawScaledScrollingString(guiGraphics, MekanismLang.FUZZY_MODE.translate(), 19, 12, TextAlignment.LEFT, titleTextColor(), getSmallTextWidth(), 3, false, 0.7F); + drawScaledScrollingString(guiGraphics, MekanismLang.FUZZY_MODE.translate(), 19, 12, TextAlignment.LEFT, titleTextColor(), textWidth, 3, false, 0.7F); } } } - - private int getSmallTextWidth() { - return this.width - RadioButton.RADIO_SIZE - getToggleXShift() - 19; - } - - private void drawFilterDescriptor(GuiGraphics guiGraphics, Component component, int x, int y) { - drawTextScaledBound(guiGraphics, component, x + 22, y + 3, titleTextColor(), getMaxLength()); - } - - protected int getMaxLength() { - return width - 22 - RadioButton.RADIO_SIZE - 11; - } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/button/GuiGasMode.java b/src/main/java/mekanism/client/gui/element/button/GuiGasMode.java index 543433e590f..2dc834fccec 100644 --- a/src/main/java/mekanism/client/gui/element/button/GuiGasMode.java +++ b/src/main/java/mekanism/client/gui/element/button/GuiGasMode.java @@ -11,7 +11,6 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.core.BlockPos; -import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; public class GuiGasMode extends MekanismImageButton { @@ -22,7 +21,7 @@ public class GuiGasMode extends MekanismImageButton { private final Tooltip dumpExcess; private final Tooltip dump; - private final boolean left; + private final TextAlignment textSide; private final Supplier gasModeSupplier; public GuiGasMode(IGuiWrapper gui, int x, int y, boolean left, Supplier gasModeSupplier, BlockPos pos, int tank) { @@ -31,7 +30,7 @@ public GuiGasMode(IGuiWrapper gui, int x, int y, boolean left, Supplier public GuiGasMode(IGuiWrapper gui, int x, int y, boolean left, Supplier gasModeSupplier, BlockPos pos, int tank, Tooltip dumpExcess, Tooltip dump) { super(gui, x, y, 10, IDLE, (element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.GAS_MODE_BUTTON, pos, tank))); - this.left = left; + this.textSide = left ? TextAlignment.RIGHT : TextAlignment.LEFT; this.gasModeSupplier = gasModeSupplier; this.dumpExcess = dumpExcess; this.dump = dump; @@ -49,12 +48,8 @@ protected ResourceLocation getResource() { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { //Draw the text next to the button - Component component = gasModeSupplier.get().getTextComponent(); - if (left) { - drawTextScaledBound(guiGraphics, component, relativeX - 3 - Math.min(getStringWidth(component), 66), relativeY + 1, titleTextColor(), 66); - } else { - drawTextScaledBound(guiGraphics, component, relativeX + width + 5, relativeY + 1, titleTextColor(), 66); - } + int start = textSide == TextAlignment.RIGHT ? -69 : getWidth(); + drawScrollingString(guiGraphics, gasModeSupplier.get().getTextComponent(), start, 1, textSide, titleTextColor(), 69, 2, false); super.renderForeground(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/element/button/MovableFilterButton.java b/src/main/java/mekanism/client/gui/element/button/MovableFilterButton.java index 0efd44e8e90..e0fdcccceba 100644 --- a/src/main/java/mekanism/client/gui/element/button/MovableFilterButton.java +++ b/src/main/java/mekanism/client/gui/element/button/MovableFilterButton.java @@ -90,9 +90,4 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou } updateButtonVisibility(filter); } - - @Override - protected int getMaxLength() { - return super.getMaxLength() - 12; - } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java b/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java index 4918b524b49..d912a627b00 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java @@ -51,7 +51,6 @@ public class GuiFrequencySelector extends GuiElement { private final MekanismButton deleteButton; private final GuiTextScrollList scrollList; private final GuiTextField frequencyField; - private final int yStart; //Used to keep track of the last list of frequencies, by taking advantage of container sync providing a new list object // each time things are synced currently so that we can just do an identity compare private List lastFrequencies = Collections.emptyList(); @@ -61,24 +60,23 @@ public class GuiFrequencySelector extends GuiElement { public > GuiFrequencySelector(SELECTOR frequencySelector, int yStart) { super(frequencySelector, 27, yStart, 132, 121); this.frequencySelector = frequencySelector; - this.yStart = yStart; boolean hasColor = frequencySelector instanceof IGuiColorFrequencySelector; - scrollList = addChild(new GuiTextScrollList(frequencySelector, 27, yStart + 22, 122, 42)); - publicButton = addChild(new MekanismImageButton(frequencySelector, 27, yStart, 38, 20, 38, 20, getButtonLocation("public"), + scrollList = addChild(new GuiTextScrollList(frequencySelector, relativeX, relativeY + 22, 122, 42)); + publicButton = addChild(new MekanismImageButton(frequencySelector, relativeX, relativeY, 38, 20, 38, 20, getButtonLocation("public"), (element, mouseX, mouseY) -> { this.securityMode = SecurityMode.PUBLIC; this.scrollList.clearSelection(); updateButtons(); return true; })).setTooltip(MekanismLang.PUBLIC_MODE); - trustedButton = addChild(new MekanismImageButton(frequencySelector, 69, yStart, 38, 20, 38, 20, getButtonLocation("trusted"), + trustedButton = addChild(new MekanismImageButton(frequencySelector, relativeX + 42, relativeY, 38, 20, 38, 20, getButtonLocation("trusted"), (element, mouseX, mouseY) -> { this.securityMode = SecurityMode.TRUSTED; this.scrollList.clearSelection(); updateButtons(); return true; })).setTooltip(MekanismLang.TRUSTED_MODE); - privateButton = addChild(new MekanismImageButton(frequencySelector, 111, yStart, 38, 20, 38, 20, getButtonLocation("private"), + privateButton = addChild(new MekanismImageButton(frequencySelector, relativeX + 84, relativeY, 38, 20, 38, 20, getButtonLocation("private"), (element, mouseX, mouseY) -> { this.securityMode = SecurityMode.PRIVATE; this.scrollList.clearSelection(); @@ -86,7 +84,7 @@ public > GuiFrequency return true; })).setTooltip(MekanismLang.PRIVATE_MODE); int buttonWidth = hasColor ? 50 : 60; - setButton = addChild(new TranslationButton(frequencySelector, 27, yStart + 113, buttonWidth, 18, MekanismLang.BUTTON_SET, (element, mouseX, mouseY) -> { + setButton = addChild(new TranslationButton(frequencySelector, relativeX, relativeY + 113, buttonWidth, 18, MekanismLang.BUTTON_SET, (element, mouseX, mouseY) -> { int selection = this.scrollList.getSelection(); if (selection != -1) { Frequency frequency = getFrequencies().get(selection); @@ -97,7 +95,7 @@ public > GuiFrequency updateButtons(); return true; })); - deleteButton = addChild(new TranslationButton(frequencySelector, 29 + buttonWidth, yStart + 113, buttonWidth, 18, MekanismLang.BUTTON_DELETE, (element, mouseX, mouseY) -> { + deleteButton = addChild(new TranslationButton(frequencySelector, relativeX + 2 + buttonWidth, relativeY + 113, buttonWidth, 18, MekanismLang.BUTTON_DELETE, (element, mouseX, mouseY) -> { GuiConfirmationDialog.show(gui(), MekanismLang.FREQUENCY_DELETE_CONFIRM.translate(), () -> { int selection = this.scrollList.getSelection(); if (selection != -1) { @@ -112,9 +110,9 @@ public > GuiFrequency return true; })); if (hasColor) { - addChild(new GuiSlot(SlotType.NORMAL, frequencySelector, 131, yStart + 113).setRenderAboveSlots()); + addChild(new GuiSlot(SlotType.NORMAL, frequencySelector, relativeX + 104, relativeY + 113).setRenderAboveSlots()); IGuiColorFrequencySelector colorFrequencySelector = (IGuiColorFrequencySelector) frequencySelector; - addChild(new ColorButton(frequencySelector, 132, yStart + 114, 16, 16, () -> { + addChild(new ColorButton(frequencySelector, relativeX + 105, relativeY + 114, 16, 16, () -> { IColorableFrequency frequency = colorFrequencySelector.getFrequency(); return frequency == null ? null : frequency.getColor(); }, (element, mouseX, mouseY) -> { @@ -125,7 +123,7 @@ public > GuiFrequency return true; })); } - frequencyField = addChild(new GuiTextField(frequencySelector, this, 50, yStart + 99, 98, 11)); + frequencyField = addChild(new GuiTextField(frequencySelector, this, relativeX + 23, relativeY + 99, 98, 11)); frequencyField.setMaxLength(FrequencyManager.MAX_FREQ_LENGTH); frequencyField.setBackground(BackgroundType.INNER_SCREEN); frequencyField.setEnterHandler(this::setFrequency); @@ -227,10 +225,14 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { ownerComponent = OwnerDisplay.of(Minecraft.getInstance().player, frequency.getOwner(), frequency.getOwnerName(), false).getTextComponent(); frequencySecurity = frequency.getSecurity(); } - drawTextScaledBound(guiGraphics, MekanismLang.FREQUENCY.translate(frequencyName), 27, yStart + 67, titleTextColor(), getGuiWidth() - 36); - drawTextScaledBound(guiGraphics, ownerComponent, 27, yStart + 77, titleTextColor(), getGuiWidth() - 36); - drawTextScaledBound(guiGraphics, MekanismLang.SECURITY.translate(frequencySecurity), 27, yStart + 87, titleTextColor(), getGuiWidth() - 36); - drawTextScaledBound(guiGraphics, MekanismLang.SET.translate(), 27, yStart + 100, titleTextColor(), 20); + int textEnd = getGuiWidth() - relativeX - 10; + drawScrollingString(guiGraphics, MekanismLang.FREQUENCY.translate(frequencyName), 0, 67, TextAlignment.LEFT, titleTextColor(), textEnd, 0, false); + drawScrollingString(guiGraphics, ownerComponent, 0, 77, TextAlignment.LEFT, titleTextColor(), textEnd, 0, false); + drawScrollingString(guiGraphics, MekanismLang.SECURITY.translate(frequencySecurity), 0, 87, TextAlignment.LEFT, titleTextColor(), textEnd, 0, false); + + //If it gets to wide, allow it to go to the left of the area + //TODO: Re-evaluate this behavior, and if we should define some min bound in a different way + drawScrollingString(guiGraphics, MekanismLang.SET.translate(), -relativeX, 100, TextAlignment.RIGHT, titleTextColor(), frequencyField.getRelativeX(), 5, false); } public interface IGuiFrequencySelector { diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java b/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java index 4132b6135de..d874f9d773f 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java @@ -9,6 +9,7 @@ import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.GuiElementHolder; import mekanism.client.gui.tooltip.TooltipUtils; +import mekanism.client.render.IFancyFontRenderer; import mekanism.common.MekanismLang; import mekanism.common.lib.Color; import mekanism.common.util.EnumUtils; @@ -23,20 +24,33 @@ public class GuiSupportedUpgrades extends GuiElement { + private static final Component SUPPORTED = MekanismLang.UPGRADES_SUPPORTED.translate(); + private static final int ELEMENT_WIDTH = 125; + private static final int PADDED_ELEMENT_WIDTH = ELEMENT_WIDTH - 2; private static final int ELEMENT_SIZE = 12; - private static final int FIRST_ROW_ROOM = (123 - 55) / ELEMENT_SIZE; - private static final int ROW_ROOM = 123 / ELEMENT_SIZE; + private static final int ROW_ROOM = PADDED_ELEMENT_WIDTH / ELEMENT_SIZE; - public static int calculateNeededRows() { + private static int getFirstRowStart(IFancyFontRenderer fontRenderer) { + return Math.min(fontRenderer.getStringWidth(SUPPORTED) + 1, PADDED_ELEMENT_WIDTH); + } + + private static int getFirstRowRoom(int firstRowStart) { + return (PADDED_ELEMENT_WIDTH - firstRowStart) / ELEMENT_SIZE; + } + + public static int calculateNeededRows(IFancyFontRenderer fontRenderer) { int count = EnumUtils.UPGRADES.length; - if (count <= FIRST_ROW_ROOM) { + int firstRowRoom = getFirstRowRoom(getFirstRowStart(fontRenderer)); + if (count <= firstRowRoom) { return 1; } - count -= FIRST_ROW_ROOM; + count -= firstRowRoom; return 2 + count / ROW_ROOM; } private final Set supportedUpgrades; + private final int firstRowRoom; + private final int firstRowStart; private List lastInfo = Collections.emptyList(); @Nullable @@ -45,8 +59,10 @@ public static int calculateNeededRows() { private ScreenRectangle cachedTooltipRect; public GuiSupportedUpgrades(IGuiWrapper gui, int x, int y, Set supportedUpgrades) { - super(gui, x, y, 125, ELEMENT_SIZE * calculateNeededRows() + 2); + super(gui, x, y, ELEMENT_WIDTH, ELEMENT_SIZE * calculateNeededRows(gui) + 2); this.supportedUpgrades = supportedUpgrades; + this.firstRowStart = getFirstRowStart(this); + this.firstRowRoom = getFirstRowRoom(this.firstRowStart); } @Override @@ -71,7 +87,9 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - drawTextScaledBound(guiGraphics, MekanismLang.UPGRADES_SUPPORTED.translate(), relativeX + 2, relativeY + 3, titleTextColor(), 54); + //Note: We don't have to specify where the upgrades start, because the upgrades get moved out of the way. This is only a scrolling string + // in case the translation needs more space than the entire width of the first row + drawScrollingString(guiGraphics, SUPPORTED, 0, 3, TextAlignment.LEFT, titleTextColor(), 2, false); } @NotNull @@ -111,13 +129,13 @@ public void updateTooltip(int mouseX, int mouseY) { } private UpgradePos getUpgradePos(int index) { - int row = index < FIRST_ROW_ROOM ? 0 : 1 + (index - FIRST_ROW_ROOM) / ROW_ROOM; + int row = index < firstRowRoom ? 0 : 1 + (index - firstRowRoom) / ROW_ROOM; if (row == 0) { //First row has x start a lot further in - return new UpgradePos(55 + (index % FIRST_ROW_ROOM) * ELEMENT_SIZE, 0); + return new UpgradePos(firstRowStart + (index % firstRowRoom) * ELEMENT_SIZE, 0); } //Shift the index so that we don't have to deal with the weird first row in terms of counting - index -= FIRST_ROW_ROOM; + index -= firstRowRoom; return new UpgradePos((index % ROW_ROOM) * ELEMENT_SIZE, row * ELEMENT_SIZE); } diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java b/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java index f459bc30fa4..3235ba49f16 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java @@ -84,8 +84,8 @@ public void clearSelection() { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - forEachUpgrade((upgrade, multipliedElement) -> drawTextScaledBound(guiGraphics, TextComponentUtil.build(upgrade), relativeX + 13, relativeY + 3 + multipliedElement, - titleTextColor(), 44)); + forEachUpgrade((upgrade, multipliedElement) -> drawScrollingString(guiGraphics, TextComponentUtil.build(upgrade), 12, 3 + multipliedElement, + TextAlignment.LEFT, titleTextColor(), barXShift - 14, 2, false)); } @NotNull diff --git a/src/main/java/mekanism/client/gui/element/tab/GuiSortingTab.java b/src/main/java/mekanism/client/gui/element/tab/GuiSortingTab.java index 915a0fad07b..d73319f1881 100644 --- a/src/main/java/mekanism/client/gui/element/tab/GuiSortingTab.java +++ b/src/main/java/mekanism/client/gui/element/tab/GuiSortingTab.java @@ -25,7 +25,7 @@ public GuiSortingTab(IGuiWrapper gui, TileEntityFactory tile) { @Override public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks); - drawTextScaledBound(guiGraphics, OnOff.of(dataSource.isSorting()).getTextComponent(), relativeX + 3, relativeY + 24, titleTextColor(), 21); + drawScrollingString(guiGraphics, OnOff.of(dataSource.isSorting()).getTextComponent(), 0, 24, TextAlignment.CENTER, titleTextColor(), 3, false); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java index 770030e561b..11d2b4bb7de 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiColorWindow.java @@ -124,8 +124,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); drawTitleText(guiGraphics, MekanismLang.COLOR_PICKER.translate(), 6); ILangEntry entry = handlesAlpha ? MekanismLang.RGBA : MekanismLang.RGB; - int textOffset = handlesAlpha ? 6 : 0; - drawTextScaledBound(guiGraphics, entry.translate(), relativeX + 7, relativeY + height - 18, titleTextColor(), 20 + textOffset); + drawScrollingString(guiGraphics, entry.translate(), 2, height - 18, TextAlignment.RIGHT, titleTextColor(), textField.getRelativeX() - relativeX - 2, 2, false); } private void drawTiledGradient(GuiGraphics guiGraphics, int x, int y, int width, int height) { diff --git a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java index fb47396fd79..83cc3d27a30 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java @@ -38,7 +38,7 @@ public class GuiUpgradeWindow extends GuiWindow { private final GuiInnerScreen rightScreen; public GuiUpgradeWindow(IGuiWrapper gui, int x, int y, TileEntityMekanism tile, SelectedWindowData windowData) { - super(gui, x, y, 156, 76 + 12 * GuiSupportedUpgrades.calculateNeededRows(), windowData); + super(gui, x, y, 156, 76 + 12 * GuiSupportedUpgrades.calculateNeededRows(gui), windowData); if (windowData.type != WindowType.UPGRADE) { throw new IllegalArgumentException("Upgrade windows must have an upgrade window type"); } diff --git a/src/main/java/mekanism/client/gui/element/window/GuiWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiWindow.java index ee50786aeca..4f74279b881 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiWindow.java @@ -233,7 +233,7 @@ public void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { super.drawTitleText(guiGraphics, text, y); } else { //Adjust spacing for close button and any other buttons like side config's auto eject - drawTitleTextTextWithOffset(guiGraphics, text, relativeX, relativeY + y, getTitlePadStart(), getTitlePadEnd()); + drawTitleTextTextWithOffset(guiGraphics, text, getTitlePadStart(), y, getXSize() - getTitlePadEnd()); } } diff --git a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java index c0c2b381885..9a1477b2af9 100644 --- a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java +++ b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java @@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.objects.Reference2IntMap; import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import mekanism.api.text.TextComponentUtil; import mekanism.client.gui.GuiMekanism; @@ -27,10 +28,12 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.BubbleColumnBlock; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.BlockHitResult; import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; @@ -39,7 +42,8 @@ public class GuiSeismicReader extends GuiMekanism { private final List> blockList = new ArrayList<>(); - private final Reference2IntMap frequencies = new Reference2IntOpenHashMap<>(); + private final Reference2IntMap blockFrequencies = new Reference2IntOpenHashMap<>(); + private final Reference2IntMap fluidFrequencies = new Reference2IntOpenHashMap<>(); private final int minHeight; private MekanismButton upButton; private MekanismButton downButton; @@ -56,13 +60,18 @@ public GuiSeismicReader(SeismicReaderContainer container, Inventory inv, Compone //Calculate all the blocks in the column for (BlockPos p : BlockPos.betweenClosed(new BlockPos(pos.getX(), minHeight, pos.getZ()), pos)) { BlockState state = level.getBlockState(p); + if (state.isAir()) {//Ensure all types of air are treated as air for calculations + state = Blocks.AIR.defaultBlockState(); + } + Block block = state.getBlock(); + blockFrequencies.mergeInt(block, 1, Integer::sum); //Try to get the clone item stack as maybe it has one, though it might not have a corresponding block ItemStack stack = state.getCloneItemStack(new BlockHitResult(p.getCenter().relative(Direction.UP, 0.5), Direction.UP, p, false), level, p, player); if (stack.isEmpty()) { Fluid fluid = Fluids.EMPTY; - if (state.getBlock() instanceof LiquidBlock liquidBlock) { + if (block instanceof LiquidBlock liquidBlock) { fluid = liquidBlock.fluid; - } else if (state.getBlock() instanceof BubbleColumnBlock) { + } else if (block instanceof BubbleColumnBlock) { fluid = level.getFluidState(p).getType(); } if (fluid == Fluids.EMPTY) { @@ -75,9 +84,15 @@ public GuiSeismicReader(SeismicReaderContainer container, Inventory inv, Compone graphics.blit(x, y, 0, 16, 16, texture); MekanismRenderer.resetColor(graphics); })); + fluidFrequencies.mergeInt(fluid, 1, Integer::sum); } } else { blockList.add(new BlockInfo<>(state, stack, this::renderItem)); + FluidState fluid = state.getFluidState(); + if (!fluid.isEmpty()) {//Take the fluid into account for frequency count + //TODO: Do we want to render the fact that it is fluid logged in some way? + fluidFrequencies.mergeInt(fluid.getType(), 1, Integer::sum); + } } } } @@ -85,7 +100,25 @@ public GuiSeismicReader(SeismicReaderContainer container, Inventory inv, Compone @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 7, 11, 63, 50)); + addRenderableWidget(new GuiInnerScreen(this, 7, 11, 63, 50, () -> { + // Get the name from the stack and render it + int currentLayer = getCurrentLayer(); + if (currentLayer >= 0) { + List text = new ArrayList<>(4); + BlockInfo blockInfo = blockList.get(currentLayer); + Block block = blockInfo.block(); + if (!(block instanceof LiquidBlock)) {//If the block is a liquid, let the fluid handling display and calculate the quantity + text.add(block.getName()); + text.add(MekanismLang.ABUNDANCY.translate(blockFrequencies.getInt(block))); + } + if (blockInfo.type() instanceof Fluid fluid) {//TODO: Improve this so it actually displays for fluid logged blocks + text.add(fluid.getFluidType().getDescription()); + text.add(MekanismLang.ABUNDANCY.translate(fluidFrequencies.getInt(fluid))); + } + return text; + } + return Collections.emptyList(); + })); addRenderableWidget(new GuiInnerScreen(this, 74, 11, 51, 160)); scrollBar = addRenderableWidget(new GuiScrollBar(this, 126, 25, 132, blockList::size, () -> 1)); addRenderableWidget(new GuiArrowSelection(this, 76, 81, () -> { @@ -94,7 +127,7 @@ protected void addGuiElements() { return blockList.get(blockList.size() - 1 - currentLayer).block().getName(); } return null; - })); + }, () -> TextComponentUtil.build(minHeight + getCurrentLayer()))); upButton = addRenderableWidget(new MekanismImageButton(this, 126, 11, 14, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "up.png"), (element, mouseX, mouseY) -> scrollBar.adjustScroll(1))); downButton = addRenderableWidget(new MekanismImageButton(this, 126, 157, 14, @@ -114,14 +147,15 @@ private void updateEnabledButtons() { downButton.active = currentLayer + 1 < blockList.size(); } + private int getCurrentLayer() { + return blockList.size() - scrollBar.getCurrentSelection() - 1; + } + @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - int currentLayer = blockList.size() - scrollBar.getCurrentSelection() - 1; - //Render the layer text scaled, so that it does not start overlapping past 100 - drawTextScaledBound(guiGraphics, TextComponentUtil.build(minHeight + currentLayer), 111, 87, screenTextColor(), 13); - //TODO - V11: Eventually instead of just rendering the item stacks, it would be nice to be able to render the actual vertical column of blocks //Render the item stacks or fluids + int currentLayer = getCurrentLayer(); for (int i = 0; i < 9; i++) { int layer = currentLayer + (i - 4); if (0 <= layer && layer < blockList.size()) { @@ -148,24 +182,6 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, } } } - int frequency = 0; - // Get the name from the stack and render it - if (currentLayer >= 0) { - Block block = blockList.get(currentLayer).block(); - Component displayName = block.getName(); - drawTextScaledBound(guiGraphics, displayName, 10, 16, screenTextColor(), 57); - if (frequencies.containsKey(block)) { - frequency = frequencies.getInt(block); - } else { - for (BlockInfo info : blockList) { - if (info.state().is(block)) { - frequency++; - } - } - frequencies.put(block, frequency); - } - } - drawTextScaledBound(guiGraphics, MekanismLang.ABUNDANCY.translate(frequency), 10, 26, screenTextColor(), 57); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java b/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java index 5d94c960840..ae7225011a8 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java @@ -46,6 +46,7 @@ public class GuiAntiprotonicNucleosynthesizer extends GuiConfigurableTile container, Inventory inv, Component title) { super(container, inv, title); @@ -58,7 +59,7 @@ public GuiAntiprotonicNucleosynthesizer(MekanismTileContainer tile.gasTank, () -> tile.getChemicalTanks(null), GaugeType.SMALL_MED, this, 5, 18)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_SECONDARY_INPUT)); @@ -82,7 +83,8 @@ public double getLevel() { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); renderInventoryText(guiGraphics); - drawTextScaledBound(guiGraphics, MekanismLang.PROCESS_RATE.translate(TextUtils.getPercent(tile.getProcessRate())), 48, 76, screenTextColor(), 100); + screen.drawScrollingString(guiGraphics, MekanismLang.PROCESS_RATE.translate(TextUtils.getPercent(tile.getProcessRate())), 0, + screen.getHeight() - getLineHeight() - 2, TextAlignment.LEFT, screenTextColor(), 2, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); PoseStack pose = guiGraphics.pose(); pose.pushPose(); diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java index 10e29f8bb11..7e3e0bc8d06 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java @@ -49,7 +49,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleTextWithOffset(guiGraphics, 2, getXSize() - centerGauge.getRelativeX(), 3, TextAlignment.LEFT); + renderTitleTextWithOffset(guiGraphics, 1, centerGauge.getRelativeX(), 4, TextAlignment.LEFT); renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java b/src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java index 1c4482c166d..3eb20136cc5 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java +++ b/src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java @@ -133,19 +133,13 @@ protected void addGenericTabs() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { super.drawForegroundText(guiGraphics, mouseX, mouseY); - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, 14);//Adjust spacing for back button drawScreenText(guiGraphics, MekanismLang.FILTER_COUNT.translate(getFilterManager().count()), 5); drawScreenText(guiGraphics, MekanismLang.MINER_RADIUS.translate(tile.getRadius()), 18); drawScreenText(guiGraphics, MekanismLang.MIN_DIGITAL_MINER.translate(tile.getMinY()), 44); drawScreenText(guiGraphics, MekanismLang.MAX_DIGITAL_MINER.translate(tile.getMaxY()), 71); } - @Override - public void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { - //Adjust spacing for back button - drawTitleTextTextWithOffset(guiGraphics, text, 0, y, 11, 0); - } - @Override protected void onClick(IFilter filter, int index) { if (filter instanceof IItemStackFilter) { diff --git a/src/main/java/mekanism/client/gui/machine/GuiPRC.java b/src/main/java/mekanism/client/gui/machine/GuiPRC.java index 17738cc33d3..7531685d1e4 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPRC.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPRC.java @@ -45,7 +45,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleTextWithOffset(guiGraphics, secondGauge.getRelativeX() + secondGauge.getWidth(), 2, 3, TextAlignment.LEFT); + renderTitleTextWithOffset(guiGraphics, secondGauge.getRelativeX() + secondGauge.getWidth(), getXSize(), 4, TextAlignment.LEFT); renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java b/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java index 7c298d00d43..3db32f3434b 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java @@ -53,7 +53,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleTextWithOffset(guiGraphics, 2, getXSize() - centerGauge.getRelativeX(), 3, TextAlignment.LEFT); + renderTitleTextWithOffset(guiGraphics, 1, centerGauge.getRelativeX(), 4, TextAlignment.LEFT); renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIOItemFrequencySelect.java b/src/main/java/mekanism/client/gui/qio/GuiQIOItemFrequencySelect.java index 41ad7f933b2..9a1f193e4c8 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIOItemFrequencySelect.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIOItemFrequencySelect.java @@ -37,7 +37,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, 17);//Adjust spacing for back button super.drawForegroundText(guiGraphics, mouseX, mouseY); } @@ -50,10 +50,4 @@ public FrequencyType getFrequencyType() { public QIOFrequencySelectItemContainer getFrequencyContainer() { return menu; } - - @Override - public void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { - //Adjust spacing for back button - drawTitleTextTextWithOffset(guiGraphics, text, 0, y, 15, 0); - } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIOItemViewer.java b/src/main/java/mekanism/client/gui/qio/GuiQIOItemViewer.java index 9e1eef9c562..c84d81f6ef0 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIOItemViewer.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIOItemViewer.java @@ -114,7 +114,7 @@ protected void addGuiElements() { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); renderInventoryTextAndOther(guiGraphics, MekanismLang.LIST_SORT.translate(), imageWidth - searchDropdown.getRelativeX() - 5); - drawTextScaledBound(guiGraphics, MekanismLang.LIST_SEARCH.translate(), 7, 31, titleTextColor(), 41); + drawScrollingString(guiGraphics, MekanismLang.LIST_SEARCH.translate(), 4, 31, TextAlignment.RIGHT, titleTextColor(), searchField.getRelativeX() - 4, 3, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/qio/GuiQIOTileFrequencySelect.java b/src/main/java/mekanism/client/gui/qio/GuiQIOTileFrequencySelect.java index 24ef3dd57ac..6df6ba069e9 100644 --- a/src/main/java/mekanism/client/gui/qio/GuiQIOTileFrequencySelect.java +++ b/src/main/java/mekanism/client/gui/qio/GuiQIOTileFrequencySelect.java @@ -43,7 +43,7 @@ protected void addGenericTabs() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, 17);//Adjust spacing for back button super.drawForegroundText(guiGraphics, mouseX, mouseY); } @@ -56,10 +56,4 @@ public FrequencyType getFrequencyType() { public TileEntityQIOComponent getTileEntity() { return tile; } - - @Override - public void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { - //Adjust spacing for back button - drawTitleTextTextWithOffset(guiGraphics, text, 0, y, 15, 0); - } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java index ec48c63013c..82692326b26 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java @@ -1,5 +1,6 @@ package mekanism.client.gui.robit; +import java.util.List; import java.util.function.Supplier; import mekanism.client.SpecialColors; import mekanism.client.gui.GuiMekanism; @@ -59,7 +60,14 @@ protected void addGuiElements() { super.addGuiElements(); addRenderableWidget(new GuiSecurityTab(this, robit, 120)); addRenderableWidget(GuiSideHolder.create(this, imageWidth, 6, 106, false, false, SpecialColors.TAB_ROBIT_MENU)); - addRenderableWidget(new GuiInnerScreen(this, 27, 16, 122, 56)); + addRenderableWidget(new GuiInnerScreen(this, 27, 16, 122, 56, () -> List.of( + MekanismLang.ROBIT_GREETING.translate(robit.getName()), + Component.empty(), + MekanismLang.ENERGY.translate(EnergyDisplay.of(robit.getEnergyContainer())), + MekanismLang.ROBIT_FOLLOWING.translate(robit.getFollowing()), + MekanismLang.ROBIT_DROP_PICKUP.translate(robit.getDropPickup()), + MekanismLang.ROBIT_OWNER.translate(robit.getOwnerName()) + ))).clearFormat().clearSpacing().clearScale().padding(2); addRenderableWidget(new GuiHorizontalPowerBar(this, robit.getEnergyContainer(), 27, 74, 120)); addRenderableWidget(new MekanismImageButton(this, 6, 16, 18, getButtonLocation("home"), (element, mouseX, mouseY) -> { PacketUtils.sendToServer(new PacketGuiInteract(GuiInteractionEntity.GO_HOME, ((GuiRobitMain) element.gui()).robit)); @@ -103,12 +111,6 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawTextScaledBound(guiGraphics, MekanismLang.ROBIT_GREETING.translate(robit.getName()), 29, 18, screenTextColor(), 119); - drawTextScaledBound(guiGraphics, MekanismLang.ENERGY.translate(EnergyDisplay.of(robit.getEnergyContainer())), 29, 36 - 4, screenTextColor(), 119); - drawTextScaledBound(guiGraphics, MekanismLang.ROBIT_FOLLOWING.translate(robit.getFollowing()), 29, 45 - 4, screenTextColor(), 119); - drawTextScaledBound(guiGraphics, MekanismLang.ROBIT_DROP_PICKUP.translate(robit.getDropPickup()), 29, 54 - 4, screenTextColor(), 119); - CharSequence owner = robit.getOwnerName().length() > 14 ? robit.getOwnerName().subSequence(0, 14) : robit.getOwnerName(); - drawTextScaledBound(guiGraphics, MekanismLang.ROBIT_OWNER.translate(owner), 29, 63 - 4, screenTextColor(), 119); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java b/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java index 3cf263a7e08..d55393922e1 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java @@ -77,7 +77,7 @@ public void removed() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleTextWithOffset(guiGraphics, 60, 9, 0, TextAlignment.CENTER); + renderTitleTextWithOffset(guiGraphics, itemNameField.getRelativeX(), itemNameField.getRelativeX() + itemNameField.getWidth() + 4, 0, TextAlignment.CENTER); int maximumCost = menu.getCost(); if (maximumCost > 0) { int textColor = 0x80FF20; diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 631ed48b6ed..0d238b212e8 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -62,13 +62,16 @@ default void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { drawScrollingString(guiGraphics, text, 0, y, TextAlignment.CENTER, titleTextColor(), 4, false); } - default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y, int startPad, int endPad) { - drawTitleTextTextWithOffset(guiGraphics, text, x, y, startPad, endPad, 4, TextAlignment.CENTER); + default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y) { + drawTitleTextTextWithOffset(guiGraphics, text, x, y, getXSize()); } - default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y, int startPad, int endPad, int maxLengthPad, TextAlignment alignment) { - drawScrollingString(guiGraphics, text, x + maxLengthPad + startPad, y, x + getXSize() - maxLengthPad - endPad, y + getLineHeight(), - alignment, titleTextColor(), false); + default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y, int end) { + drawTitleTextTextWithOffset(guiGraphics, text, x, y, end, 4, TextAlignment.CENTER); + } + + default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y, int end, int maxLengthPad, TextAlignment alignment) { + drawScrollingString(guiGraphics, text, x, y, alignment, titleTextColor(), end - x, maxLengthPad, false); } default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow) { @@ -76,7 +79,11 @@ default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, } default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow) { - drawScrollingString(guiGraphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + getLineHeight(), alignment, color, shadow); + drawScrollingString(guiGraphics, text, x, y, alignment, color, width, getLineHeight(), maxLengthPad, shadow); + } + + default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, boolean shadow) { + drawScrollingString(guiGraphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + height, alignment, color, shadow); } default void drawScrollingString(GuiGraphics guiGraphics, Component text, int minX, int minY, int maxX, int maxY, TextAlignment alignment, int color, boolean shadow) { @@ -100,12 +107,7 @@ default void drawScrollingString(GuiGraphics guiGraphics, Component text, int mi drawString(guiGraphics, text, minX - (int) overflowedBy, targetY, color, shadow); guiGraphics.disableScissor(); } else { - float targetX = switch (alignment) { - case LEFT -> minX; - case CENTER -> minX + (areaWidth - textWidth) / 2F; - case RIGHT -> maxX - textWidth; - }; - drawString(guiGraphics, text, targetX, targetY, color, shadow); + drawString(guiGraphics, text, alignment.getTarget(minX, maxX, areaWidth, textWidth), targetY, color, shadow); } } @@ -113,7 +115,13 @@ default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, drawScaledScrollingString(guiGraphics, text, x, y, alignment, color, getXSize(), maxLengthPad, shadow, scale); } - default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow, float scale) { + default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, + boolean shadow, float scale) { + drawScaledScrollingString(guiGraphics, text, x, y, alignment, color, width, getLineHeight(), maxLengthPad, shadow, scale); + } + + default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, + boolean shadow, float scale) { drawScaledScrollingString(guiGraphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + getLineHeight(), alignment, color, shadow, scale); } @@ -144,23 +152,7 @@ default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, drawTextWithScale(guiGraphics, text, minX - (int) overflowedBy, targetY, color, shadow, scale); guiGraphics.disableScissor(); } else { - float targetX = switch (alignment) { - case LEFT -> minX; - case CENTER -> minX + (areaWidth - textWidth) / 2F; - case RIGHT -> maxX - textWidth; - }; - drawTextWithScale(guiGraphics, text, targetX, targetY, color, shadow, scale); - } - } - - //TODO: Call drawScrollingString directly - @Deprecated(forRemoval = true) - default void drawTextScaledBound(GuiGraphics guiGraphics, Component component, int x, int y, int color, int maxLength) { - int length = getStringWidth(component); - if (length <= maxLength) { - drawString(guiGraphics, component, x, y, color, false); - } else { - drawScrollingString(guiGraphics, component, x, y, x + maxLength, y + getLineHeight(), TextAlignment.LEFT, color, false); + drawTextWithScale(guiGraphics, text, alignment.getTarget(minX, maxX, areaWidth, textWidth), targetY, color, shadow, scale); } } @@ -201,7 +193,15 @@ private static int getTranslationY(GuiGraphics guiGraphics) { enum TextAlignment { LEFT, CENTER, - RIGHT + RIGHT; + + public float getTarget(int minX, int maxX, float areaWidth, float textWidth) { + return switch (this) { + case LEFT -> minX; + case CENTER -> minX + (areaWidth - textWidth) / 2F; + case RIGHT -> maxX - textWidth; + }; + } } // efficient tool to draw word-by-word wrapped text based on a horizontal bound. looks intimidating but runs in O(n) diff --git a/src/main/java/mekanism/common/entity/EntityRobit.java b/src/main/java/mekanism/common/entity/EntityRobit.java index ec9fdde488b..61ed54b8c46 100644 --- a/src/main/java/mekanism/common/entity/EntityRobit.java +++ b/src/main/java/mekanism/common/entity/EntityRobit.java @@ -143,6 +143,7 @@ private static EntityDataAccessor define(EntityDataSerializer dataSeri private static final TicketType ROBIT_CHUNK_UNLOAD = TicketType.create("robit_chunk_unload", Integer::compareTo, SharedConstants.TICKS_PER_SECOND); private static final EntityDataAccessor OWNER_UUID = define(MekanismDataSerializers.UUID.value()); + //TODO: Ensure this properly updates if the user's name changes but uuid is the same private static final EntityDataAccessor OWNER_NAME = define(EntityDataSerializers.STRING); private static final EntityDataAccessor SECURITY = define(MekanismDataSerializers.SECURITY.value()); private static final EntityDataAccessor FOLLOW = define(EntityDataSerializers.BOOLEAN); From 154861626b5a0b1fcd9e27a5d4dbc990354b85ed Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Sun, 22 Sep 2024 13:31:51 -0500 Subject: [PATCH 03/17] Remove unnecessary tooltip rendering from seismic vibrator as we already display the information in the neighboring screen and the tooltip feels clunky --- .../client/gui/element/GuiArrowSelection.java | 24 +------------------ .../client/gui/item/GuiSeismicReader.java | 8 +------ 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java b/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java index 599c524d0a7..e0c50a1f31b 100644 --- a/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java +++ b/src/main/java/mekanism/client/gui/element/GuiArrowSelection.java @@ -1,8 +1,6 @@ package mekanism.client.gui.element; -import com.mojang.blaze3d.vertex.PoseStack; import java.util.function.Supplier; -import mekanism.client.gui.GuiUtils; import mekanism.client.gui.IGuiWrapper; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; @@ -15,12 +13,10 @@ public class GuiArrowSelection extends GuiTexturedElement { private static final ResourceLocation ARROW = MekanismUtils.getResource(ResourceType.GUI, "arrow_selection.png"); - private final Supplier textComponentSupplier; private final Supplier targetText; - public GuiArrowSelection(IGuiWrapper gui, int x, int y, Supplier textComponentSupplier, Supplier targetText) { + public GuiArrowSelection(IGuiWrapper gui, int x, int y, Supplier targetText) { super(ARROW, gui, x, y, 33, 19); - this.textComponentSupplier = textComponentSupplier; this.targetText = targetText; } @@ -30,24 +26,6 @@ public boolean isMouseOver(double xAxis, double yAxis) { return this.active && this.visible && xAxis >= getX() + 16 && xAxis < getRight() - 1 && yAxis >= getY() + 1 && yAxis < getBottom() - 1; } - @Override - public void renderToolTip(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - super.renderToolTip(guiGraphics, mouseX, mouseY); - Component component = textComponentSupplier.get(); - if (component != null) { - int tooltipX = mouseX + 5; - int tooltipY = mouseY - 5; - PoseStack pose = guiGraphics.pose(); - pose.pushPose(); - //Mirror vanilla's tooltip rendering offset - pose.translate(0, 0, 400); - GuiUtils.renderBackgroundTexture(guiGraphics, GuiInnerScreen.SCREEN, GuiInnerScreen.SCREEN_SIZE, GuiInnerScreen.SCREEN_SIZE, tooltipX - 3, tooltipY - 4, getStringWidth(component) + 6, 16, 256, 256); - //Note: This doesn't need to be a scrolling string as the background is resized to fit it - drawString(guiGraphics, component, tooltipX, tooltipY, screenTextColor(), false); - pose.popPose(); - } - } - @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); diff --git a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java index 9a1477b2af9..e6c3e7c1485 100644 --- a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java +++ b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java @@ -121,13 +121,7 @@ protected void addGuiElements() { })); addRenderableWidget(new GuiInnerScreen(this, 74, 11, 51, 160)); scrollBar = addRenderableWidget(new GuiScrollBar(this, 126, 25, 132, blockList::size, () -> 1)); - addRenderableWidget(new GuiArrowSelection(this, 76, 81, () -> { - int currentLayer = scrollBar.getCurrentSelection(); - if (currentLayer >= 0) { - return blockList.get(blockList.size() - 1 - currentLayer).block().getName(); - } - return null; - }, () -> TextComponentUtil.build(minHeight + getCurrentLayer()))); + addRenderableWidget(new GuiArrowSelection(this, 76, 81, () -> TextComponentUtil.build(minHeight + getCurrentLayer()))); upButton = addRenderableWidget(new MekanismImageButton(this, 126, 11, 14, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "up.png"), (element, mouseX, mouseY) -> scrollBar.adjustScroll(1))); downButton = addRenderableWidget(new MekanismImageButton(this, 126, 157, 14, From 91a46c5ce3f21fb9060fee52843e4c53d643ca95 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Mon, 23 Sep 2024 23:01:22 -0500 Subject: [PATCH 04/17] Fix the majority of GUIs where certain text didn't declare proper bounds --- .../client/gui/GuiFusionReactorFuel.java | 1 - .../client/gui/GuiFusionReactorHeat.java | 8 ------- .../client/gui/GuiFusionReactorInfo.java | 8 +++++++ .../client/gui/GuiFusionReactorStats.java | 1 - .../client/gui/GuiIndustrialTurbine.java | 2 +- .../mekanism/client/gui/GuiChemicalTank.java | 2 +- .../client/gui/GuiDimensionalStabilizer.java | 9 ++++---- .../client/gui/GuiLaserAmplifier.java | 4 ++-- .../mekanism/client/gui/GuiMatrixStats.java | 1 + .../java/mekanism/client/gui/GuiMekanism.java | 7 ++++-- .../client/gui/GuiModificationStation.java | 2 +- .../mekanism/client/gui/GuiModuleTweaker.java | 2 +- .../mekanism/client/gui/GuiTeleporter.java | 6 +++-- .../client/gui/element/GuiElement.java | 8 +++++++ .../client/gui/element/GuiInnerScreen.java | 9 ++++---- .../client/gui/element/GuiScreenSwitch.java | 4 ++-- .../gui/element/button/FilterButton.java | 6 ++--- .../client/gui/element/text/ButtonType.java | 4 ++-- .../element/window/GuiSideConfiguration.java | 2 +- .../element/window/GuiTransporterConfig.java | 2 +- .../filter/qio/GuiQIOItemStackFilter.java | 2 +- .../transporter/GuiSorterFilterHelper.java | 9 ++++---- .../client/gui/item/GuiDictionary.java | 2 +- .../gui/item/GuiPortableTeleporter.java | 5 +++-- .../gui/machine/GuiChemicalCrystallizer.java | 22 ++++++++++++++----- .../GuiChemicalDissolutionChamber.java | 7 ++++-- .../gui/machine/GuiChemicalInfuser.java | 2 +- .../gui/machine/GuiChemicalOxidizer.java | 8 +++++-- .../client/gui/machine/GuiDigitalMiner.java | 13 +++++++++-- .../client/gui/machine/GuiElectricPump.java | 1 + .../gui/machine/GuiElectrolyticSeparator.java | 7 ++++-- .../client/gui/machine/GuiFactory.java | 8 +++++-- .../gui/machine/GuiFluidicPlenisher.java | 1 + .../gui/machine/GuiIsotopicCentrifuge.java | 7 ++++-- .../gui/machine/GuiNutritionalLiquifier.java | 7 ++++-- .../mekanism/client/gui/machine/GuiPRC.java | 2 +- .../gui/machine/GuiPigmentExtractor.java | 7 ++++-- .../client/gui/machine/GuiPigmentMixer.java | 2 +- .../gui/machine/GuiRotaryCondensentrator.java | 7 ++++-- .../client/gui/robit/GuiRobitRepair.java | 10 +++++---- .../recipe/ChemicalCrystallizerEmiRecipe.java | 15 ++++++++++--- .../ChemicalCrystallizerRecipeCategory.java | 15 ++++++++++--- .../jei/machine/SawmillRecipeCategory.java | 4 ++-- .../type/VanillaRVRecipeType.java | 3 ++- .../inventory/slot/BasicInventorySlot.java | 4 ++++ .../common/tile/TileEntityTeleporter.java | 4 ++++ .../TileEntityChemicalCrystallizer.java | 4 ++++ 47 files changed, 182 insertions(+), 84 deletions(-) diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java index 160b8211472..fdbfa559537 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java @@ -46,7 +46,6 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_INJECTION_RATE.translate(tile.getMultiblock().getInjectionRate()), 0, 35, TextAlignment.CENTER, titleTextColor(), 16, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_EDIT_RATE.translate(), 4, 117, TextAlignment.RIGHT, titleTextColor(), 94, 2, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorHeat.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorHeat.java index 4d6ae4f24bf..34d2c742cb4 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorHeat.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorHeat.java @@ -18,12 +18,10 @@ import mekanism.generators.common.GeneratorsLang; import mekanism.generators.common.content.fusion.FusionReactorMultiblockData; import mekanism.generators.common.tile.fusion.TileEntityFusionReactorController; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.level.material.Fluids; -import org.jetbrains.annotations.NotNull; public class GuiFusionReactorHeat extends GuiFusionReactorInfo { @@ -93,10 +91,4 @@ public Component getText() { addRenderableWidget(new GuiFusionReactorTab(this, tile, FusionReactorTab.FUEL)); addRenderableWidget(new GuiFusionReactorTab(this, tile, FusionReactorTab.STAT)); } - - @Override - protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); - super.drawForegroundText(guiGraphics, mouseX, mouseY); - } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorInfo.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorInfo.java index 7e28d4832e5..d65b7db1fcc 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorInfo.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorInfo.java @@ -17,8 +17,10 @@ import mekanism.generators.common.GeneratorsLang; import mekanism.generators.common.content.fusion.FusionReactorMultiblockData; import mekanism.generators.common.tile.fusion.TileEntityFusionReactorController; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; +import org.jetbrains.annotations.NotNull; public abstract class GuiFusionReactorInfo extends GuiMekanismTile> { @@ -45,4 +47,10 @@ protected void addGuiElements() { return List.of(MekanismLang.TRANSFERRED_RATE.translate(transfer), MekanismLang.DISSIPATED_RATE.translate(environment)); })); } + + @Override + protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { + renderTitleTextWithOffset(guiGraphics, 18);//Adjust spacing for back button + super.drawForegroundText(guiGraphics, mouseX, mouseY); + } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java index 8e7183b9347..701d926f222 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java @@ -31,7 +31,6 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); FusionReactorMultiblockData multiblock = tile.getMultiblock(); if (multiblock.isFormed()) { int textArea = getXSize() - 8; diff --git a/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java b/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java index 5fb7fdf36a4..3e54980046a 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java @@ -120,7 +120,7 @@ public double getLevel() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, 85); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiChemicalTank.java b/src/main/java/mekanism/client/gui/GuiChemicalTank.java index ccccafd063e..7d5f5b14e7b 100644 --- a/src/main/java/mekanism/client/gui/GuiChemicalTank.java +++ b/src/main/java/mekanism/client/gui/GuiChemicalTank.java @@ -54,7 +54,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, 85); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/GuiDimensionalStabilizer.java b/src/main/java/mekanism/client/gui/GuiDimensionalStabilizer.java index d31ad38a530..b6880fdcc18 100644 --- a/src/main/java/mekanism/client/gui/GuiDimensionalStabilizer.java +++ b/src/main/java/mekanism/client/gui/GuiDimensionalStabilizer.java @@ -30,6 +30,9 @@ public class GuiDimensionalStabilizer extends GuiMekanismTile> { + //Note: We need a component that is a space so that the line doesn't get trimmed out when splitting to fit within the screen space + private static final Component BLANK_LINE = Component.literal(" "); + public GuiDimensionalStabilizer(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); inventoryLabelY += 2; @@ -83,16 +86,14 @@ public void updateTooltip(int mouseX, int mouseY) { // for now it doesn't really matter as given we only support a radius of two it only checks at most the inner radius (8 extra boolean lookups) for (int i = 1; i <= TileEntityDimensionalStabilizer.MAX_LOAD_RADIUS; i++) { if (hasAtRadius(i, false)) { - //Add an empty line for readability. Must be done by adding a string that just renders a space - tooltips.add(Component.literal(" ")); + tooltips.add(BLANK_LINE);//Add an empty line for readability tooltips.add(MekanismLang.STABILIZER_ENABLE_RADIUS.translate(EnumColor.INDIGO, i, EnumColor.INDIGO, chunkX, EnumColor.INDIGO, chunkZ)); break; } } for (int i = TileEntityDimensionalStabilizer.MAX_LOAD_RADIUS; i > 0; i--) { if (hasAtRadius(i, true)) { - //Add an empty line for readability. Must be done by adding a string that just renders a space - tooltips.add(Component.literal(" ")); + tooltips.add(BLANK_LINE);//Add an empty line for readability tooltips.add(MekanismLang.STABILIZER_DISABLE_RADIUS.translate(EnumColor.INDIGO, i, EnumColor.INDIGO, chunkX, EnumColor.INDIGO, chunkZ)); break; } diff --git a/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java b/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java index 4ce45533b12..0cffd8bed11 100644 --- a/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java +++ b/src/main/java/mekanism/client/gui/GuiLaserAmplifier.java @@ -55,9 +55,9 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, energyGauge.getRelativeRight()); renderInventoryText(guiGraphics); - int start = energyGauge.getRelativeX() + energyGauge.getWidth(); + int start = energyGauge.getRelativeRight(); Component delay; if (tile.getDelay() > 0) { delay = MekanismLang.DELAY.translate(tile.getDelay()); diff --git a/src/main/java/mekanism/client/gui/GuiMatrixStats.java b/src/main/java/mekanism/client/gui/GuiMatrixStats.java index c82494410da..0d9190af6d6 100644 --- a/src/main/java/mekanism/client/gui/GuiMatrixStats.java +++ b/src/main/java/mekanism/client/gui/GuiMatrixStats.java @@ -24,6 +24,7 @@ public class GuiMatrixStats extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); + titleLabelY -= 1; } @Override diff --git a/src/main/java/mekanism/client/gui/GuiMekanism.java b/src/main/java/mekanism/client/gui/GuiMekanism.java index 4f5f8d23452..9d30da07e6d 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanism.java +++ b/src/main/java/mekanism/client/gui/GuiMekanism.java @@ -168,7 +168,6 @@ public void containerTick() { } protected void renderTitleText(GuiGraphics guiGraphics) { - //TODO - 1.21: Evaluate what other ones should be moved to rendering with offset. For example the electrolytic separator drawTitleText(guiGraphics, title, titleLabelY); } @@ -185,7 +184,11 @@ protected void renderTitleTextWithOffset(GuiGraphics guiGraphics, int x, int end } protected void renderInventoryText(GuiGraphics guiGraphics) { - drawScrollingString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, TextAlignment.LEFT, titleTextColor(), getXSize() - inventoryLabelX - 6, 0, false); + renderInventoryText(guiGraphics, getXSize()); + } + + protected void renderInventoryText(GuiGraphics guiGraphics, int end) { + drawScrollingString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, TextAlignment.LEFT, titleTextColor(), end - inventoryLabelX - 6, 0, false); } protected void renderInventoryTextAndOther(GuiGraphics guiGraphics, Component rightAlignedText) { diff --git a/src/main/java/mekanism/client/gui/GuiModificationStation.java b/src/main/java/mekanism/client/gui/GuiModificationStation.java index 96d535b4165..95237c20e2e 100644 --- a/src/main/java/mekanism/client/gui/GuiModificationStation.java +++ b/src/main/java/mekanism/client/gui/GuiModificationStation.java @@ -54,7 +54,7 @@ private void onModuleSelected(@Nullable IModule module) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, 24); renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/GuiModuleTweaker.java b/src/main/java/mekanism/client/gui/GuiModuleTweaker.java index 86b70e6d48b..33dc8c4fa13 100644 --- a/src/main/java/mekanism/client/gui/GuiModuleTweaker.java +++ b/src/main/java/mekanism/client/gui/GuiModuleTweaker.java @@ -145,7 +145,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, 24); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/GuiTeleporter.java b/src/main/java/mekanism/client/gui/GuiTeleporter.java index eec15c5570e..81559b36931 100644 --- a/src/main/java/mekanism/client/gui/GuiTeleporter.java +++ b/src/main/java/mekanism/client/gui/GuiTeleporter.java @@ -17,6 +17,8 @@ public class GuiTeleporter extends GuiMekanismTile> implements ITileGuiFrequencySelector, IGuiColorFrequencySelector { + private GuiTeleporterStatus status; + public GuiTeleporter(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); imageHeight += 74; @@ -28,14 +30,14 @@ public GuiTeleporter(MekanismTileContainer container, Inve @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiTeleporterStatus(this, () -> getFrequency() != null, () -> tile.status)); + status = addRenderableWidget(new GuiTeleporterStatus(this, () -> getFrequency() != null, () -> tile.status)); addRenderableWidget(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 158, 26)); addRenderableWidget(new GuiFrequencySelector<>(this, 14)); } @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, status.getRelativeRight(), tile.getEnergySlotX()); renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/element/GuiElement.java b/src/main/java/mekanism/client/gui/element/GuiElement.java index bc127c8fcc9..cba0909ff9d 100644 --- a/src/main/java/mekanism/client/gui/element/GuiElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiElement.java @@ -110,6 +110,14 @@ public int getRelativeY() { return relativeY; } + public int getRelativeRight() { + return getRelativeX() + getWidth(); + } + + public int getRelativeBottom() { + return getRelativeY() + getHeight(); + } + /** * Transfers this {@link GuiElement} to a new parent {@link IGuiWrapper}, and moves elements as needed. */ diff --git a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java index 14fd8824cd1..fe9046d40a0 100644 --- a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java +++ b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java @@ -105,11 +105,12 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { minY = relativeY + Mth.floor(center); maxY = relativeY + lineHeight + Mth.ceil(center); } - int maxTextWidth = getMaxTextWidth(); int minX = relativeX + padding; - int maxX = relativeX + maxTextWidth - padding; int screenTextColor = screenTextColor(); - for (Component text : renderStrings.get()) { + renderStrings.get(); + for (int i = 0, size = list.size(); i < size; i++) { + Component text = list.get(i); + int maxX = relativeX + getMaxTextWidth(i) - padding; drawScaledScrollingString(guiGraphics, text, minX, minY, maxX, maxY, TextAlignment.LEFT, screenTextColor, false, textScale); minY += heightToNextLine; maxY += heightToNextLine; @@ -132,7 +133,7 @@ public void updateTooltip(int mouseX, int mouseY) { setTooltip(lastTooltip); } - protected int getMaxTextWidth() { + protected int getMaxTextWidth(int row) { return getWidth(); } diff --git a/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java b/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java index 9a7f3cebaea..dde31010867 100644 --- a/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java +++ b/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java @@ -48,7 +48,7 @@ public void onClick(double mouseX, double mouseY, int button) { } @Override - protected int getMaxTextWidth() { - return super.getMaxTextWidth() - 2 - GuiDigitalSwitch.BUTTON_SIZE_X; + protected int getMaxTextWidth(int row) { + return super.getMaxTextWidth(row) - 2 - GuiDigitalSwitch.BUTTON_SIZE_X; } } diff --git a/src/main/java/mekanism/client/gui/element/button/FilterButton.java b/src/main/java/mekanism/client/gui/element/button/FilterButton.java index fb528a3b151..a0ae1d7206d 100644 --- a/src/main/java/mekanism/client/gui/element/button/FilterButton.java +++ b/src/main/java/mekanism/client/gui/element/button/FilterButton.java @@ -133,9 +133,9 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { } Component filterDescriptor = switch (filter) { case IItemStackFilter item -> item.getItemStack().getHoverName(); - case ITagFilter tag -> Component.literal(tag.getTagName()); - case IModIDFilter modId -> Component.literal(modId.getModID()); - case OredictionificatorFilter oredictionificatorFilter -> Component.literal(oredictionificatorFilter.getFilterText()); + case ITagFilter tag -> TextComponentUtil.getString(tag.getTagName()); + case IModIDFilter modId -> TextComponentUtil.getString(modId.getModID()); + case OredictionificatorFilter oredictionificatorFilter -> TextComponentUtil.getString(oredictionificatorFilter.getFilterText()); case null, default -> null; }; int textWidth = toggleButton.getRelativeX() - relativeX - 20; diff --git a/src/main/java/mekanism/client/gui/element/text/ButtonType.java b/src/main/java/mekanism/client/gui/element/text/ButtonType.java index 70f372e06ae..0b59b66f1cc 100644 --- a/src/main/java/mekanism/client/gui/element/text/ButtonType.java +++ b/src/main/java/mekanism/client/gui/element/text/ButtonType.java @@ -8,10 +8,10 @@ import mekanism.common.util.MekanismUtils.ResourceType; public enum ButtonType { - NORMAL((field, callback) -> new MekanismImageButton(field.gui(), field.getRelativeX() + field.getWidth() - field.getHeight(), field.getRelativeY(), + NORMAL((field, callback) -> new MekanismImageButton(field.gui(), field.getRelativeRight() - field.getHeight(), field.getRelativeY(), field.getHeight(), 12, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "checkmark.png"), callback)), DIGITAL((field, callback) -> { - MekanismImageButton ret = new MekanismImageButton(field.gui(), field.getRelativeX() + field.getWidth() - field.getHeight(), field.getRelativeY(), + MekanismImageButton ret = new MekanismImageButton(field.gui(), field.getRelativeRight() - field.getHeight(), field.getRelativeY(), field.getHeight(), 12, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "checkmark_digital.png"), callback); ret.setButtonBackground(ButtonBackground.DIGITAL); return ret; diff --git a/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java b/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java index d12c280530c..cf1cd94507e 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java @@ -176,6 +176,6 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { @Override protected int getTitlePadEnd() { - return super.getTitlePadEnd() + 15; + return super.getTitlePadEnd() + 18; } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java b/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java index f4809cb73a7..0fc4c773cdf 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java @@ -82,6 +82,6 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { @Override protected int getTitlePadEnd() { - return super.getTitlePadEnd() + 15; + return super.getTitlePadEnd() + 18; } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/window/filter/qio/GuiQIOItemStackFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/qio/GuiQIOItemStackFilter.java index 5d7c3a2950b..11d6d1d77dc 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/qio/GuiQIOItemStackFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/qio/GuiQIOItemStackFilter.java @@ -46,6 +46,6 @@ protected QIOItemStackFilter createNewFilter() { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - drawScrollingString(guiGraphics, OnOff.of(filter.fuzzyMode).getTextComponent(), 159, 20, TextAlignment.LEFT, titleTextColor(), width - 159, 2, false); + drawScrollingString(guiGraphics, OnOff.of(filter.fuzzyMode).getTextComponent(), 159, 20, TextAlignment.LEFT, titleTextColor(), width - 161, 2, false); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java index 029ac253987..9eebd0c4c2b 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java @@ -81,15 +81,16 @@ default GuiSorterFilerSelect getFilterSelect(IGuiWrapper gui, TileEntityLogistic default void renderSorterForeground(GuiGraphics guiGraphics) { SorterFilter filter = getFilter(); int screenEnd = 29 + getScreenWidth(); - drawScrollingString(guiGraphics, OnOff.of(filter.allowDefault).getTextComponent(), 159, 20, TextAlignment.LEFT, titleTextColor(), getXSize() - 159, 2, false); + drawScrollingString(guiGraphics, OnOff.of(filter.allowDefault).getTextComponent(), 159, 20, TextAlignment.LEFT, titleTextColor(), getXSize() - 161, 2, false); //Note: We add two to the length, as min and max have two spaces at the end given we aren't actually providing a parameter //TODO: Do we want to adjust this, and just have separate lang keys for them? - drawScrollingString(guiGraphics, MekanismLang.MIN.translate(""), screenEnd, 32, TextAlignment.LEFT, titleTextColor(), 169 - screenEnd + 2, 1, false); - drawScrollingString(guiGraphics, MekanismLang.MAX.translate(""), screenEnd, 44, TextAlignment.LEFT, titleTextColor(), 169 - screenEnd + 2, 1, false); + drawScrollingString(guiGraphics, MekanismLang.MIN.translate(""), screenEnd, 32, TextAlignment.LEFT, titleTextColor(), 168 - screenEnd, 1, false); + //TODO - 1.21: Make the gui slightly wider so that we can have it so max isn't scrolling ever so slightly be default? + drawScrollingString(guiGraphics, MekanismLang.MAX.translate(""), screenEnd, 44, TextAlignment.LEFT, titleTextColor(), 168 - screenEnd, 1, false); if (isSingleItem() && filter.sizeMode) { drawScrollingString(guiGraphics, MekanismLang.SORTER_FILTER_SIZE_MODE.translateColored(EnumColor.RED, OnOff.ON), 159, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 159, 2, false); } else { - drawScrollingString(guiGraphics, OnOff.of(filter.sizeMode).getTextComponent(), 159, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 159, 2, false); + drawScrollingString(guiGraphics, OnOff.of(filter.sizeMode).getTextComponent(), 159, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 161, 2, false); } } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/item/GuiDictionary.java b/src/main/java/mekanism/client/gui/item/GuiDictionary.java index c4ed6db4a46..4a2c2961387 100644 --- a/src/main/java/mekanism/client/gui/item/GuiDictionary.java +++ b/src/main/java/mekanism/client/gui/item/GuiDictionary.java @@ -60,7 +60,7 @@ private void updateScrollList(Set supportedTypes) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, target.getRelativeRight()); renderInventoryTextAndOther(guiGraphics, MekanismLang.DICTIONARY_TAG_TYPE.translate(), imageWidth - dropdown.getRelativeX() - 5); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/item/GuiPortableTeleporter.java b/src/main/java/mekanism/client/gui/item/GuiPortableTeleporter.java index 63c72e7bce0..057dd32b975 100644 --- a/src/main/java/mekanism/client/gui/item/GuiPortableTeleporter.java +++ b/src/main/java/mekanism/client/gui/item/GuiPortableTeleporter.java @@ -28,6 +28,7 @@ public class GuiPortableTeleporter extends GuiMekanism implements IItemGuiFrequencySelector, IGuiColorFrequencySelector { + private GuiTeleporterStatus status; private MekanismButton teleportButton; public GuiPortableTeleporter(PortableTeleporterContainer container, Inventory inv, Component title) { @@ -39,7 +40,7 @@ public GuiPortableTeleporter(PortableTeleporterContainer container, Inventory in @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiTeleporterStatus(this, () -> getFrequency() != null, menu::getStatus)); + status = addRenderableWidget(new GuiTeleporterStatus(this, () -> getFrequency() != null, menu::getStatus)); addRenderableWidget(new GuiVerticalPowerBar(this, new IBarInfoHandler() { @Override public Component getTooltip() { @@ -82,7 +83,7 @@ public void buttonsUpdated() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, status.getRelativeRight()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalCrystallizer.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalCrystallizer.java index 6bbfd7a932d..df526d618e5 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalCrystallizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalCrystallizer.java @@ -11,6 +11,7 @@ import mekanism.api.recipes.ChemicalCrystallizerRecipe; import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.GuiInnerScreen; import mekanism.client.gui.element.bar.GuiVerticalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; @@ -41,6 +42,7 @@ public class GuiChemicalCrystallizer extends GuiConfigurableTile iterStacks = new ArrayList<>(); private final IOreInfo oreInfo = new OreInfo(); private GuiSequencedSlotDisplay slotDisplay; + private GuiElement inputGauge; @NotNull private Chemical prevSlurry = MekanismAPI.EMPTY_CHEMICAL; @@ -56,21 +58,31 @@ protected void addGuiElements() { addRenderableWidget(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 157, 23)) .warning(WarningType.NOT_ENOUGH_ENERGY, tile.getWarningCheck(RecipeError.NOT_ENOUGH_ENERGY)); addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getActive)); - addRenderableWidget(new GuiChemicalGauge(() -> tile.inputTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 7, 4)) + inputGauge = addRenderableWidget(new GuiChemicalGauge(() -> tile.inputTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 7, 4)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_INPUT)); addRenderableWidget(new GuiProgress(tile::getScaledProgress, ProgressType.LARGE_RIGHT, this, 53, 61).recipeViewerCategory(tile)) .warning(WarningType.INPUT_DOESNT_PRODUCE_OUTPUT, tile.getWarningCheck(RecipeError.INPUT_DOESNT_PRODUCE_OUTPUT)); + //TODO - 1.21: Move this to being a custom gui element so that we don't have to copy this and the overrides to the recipe viewers //Init slot display before gui screen, so it can reference it, but add it after, so it renders above it - slotDisplay = new GuiSequencedSlotDisplay(this, 129, 14, () -> iterStacks); + int slotX = 128; + slotDisplay = new GuiSequencedSlotDisplay(this, slotX + 1, 14, () -> iterStacks); updateSlotContents(); - addRenderableWidget(new GuiInnerScreen(this, 31, 13, 115, 42, () -> getScreenRenderStrings(this.oreInfo))); - addRenderableWidget(new GuiSlot(SlotType.ORE, this, 128, 13).setRenderAboveSlots()); + addRenderableWidget(new GuiInnerScreen(this, 31, 13, 115, 42, () -> getScreenRenderStrings(this.oreInfo)) { + @Override + protected int getMaxTextWidth(int row) { + if (row == 0) { + return slotX - relativeX; + } + return super.getMaxTextWidth(row); + } + }); + addRenderableWidget(new GuiSlot(SlotType.ORE, this, slotX, 13).setRenderAboveSlots()); addRenderableWidget(slotDisplay); } @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, inputGauge.getRelativeRight(), tile.getEnergySlotX()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalDissolutionChamber.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalDissolutionChamber.java index 7abd8c91c59..0456f5af2bf 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalDissolutionChamber.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalDissolutionChamber.java @@ -2,6 +2,7 @@ import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; @@ -18,6 +19,8 @@ public class GuiChemicalDissolutionChamber extends GuiConfigurableTile> { + private GuiElement inputGauge; + public GuiChemicalDissolutionChamber(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; @@ -31,7 +34,7 @@ protected void addGuiElements() { .warning(WarningType.NOT_ENOUGH_ENERGY, tile.getWarningCheck(RecipeError.NOT_ENOUGH_ENERGY)) .warning(WarningType.NOT_ENOUGH_ENERGY_REDUCED_RATE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_ENERGY_REDUCED_RATE)); addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getActive)); - addRenderableWidget(new GuiChemicalGauge(() -> tile.injectTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 7, 4)) + inputGauge = addRenderableWidget(new GuiChemicalGauge(() -> tile.injectTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 7, 4)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_SECONDARY_INPUT)); addRenderableWidget(new GuiChemicalGauge(() -> tile.outputTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 131, 13)) .warning(WarningType.NO_SPACE_IN_OUTPUT, tile.getWarningCheck(RecipeError.NOT_ENOUGH_OUTPUT_SPACE)); @@ -41,7 +44,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, inputGauge.getRelativeRight()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java index 7e3e0bc8d06..30262ebfe57 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalInfuser.java @@ -50,7 +50,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleTextWithOffset(guiGraphics, 1, centerGauge.getRelativeX(), 4, TextAlignment.LEFT); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, centerGauge.getRelativeX()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java index f6444fa0820..14a4f357f29 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java @@ -2,6 +2,7 @@ import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; @@ -18,15 +19,18 @@ public class GuiChemicalOxidizer extends GuiConfigurableTile> { + private GuiElement energyBar; + public GuiChemicalOxidizer(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; + titleLabelY -= 1; } @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiHorizontalPowerBar(this, tile.getEnergyContainer(), 115, 75)) + energyBar = addRenderableWidget(new GuiHorizontalPowerBar(this, tile.getEnergyContainer(), 115, 75)) .warning(WarningType.NOT_ENOUGH_ENERGY, tile.getWarningCheck(RecipeError.NOT_ENOUGH_ENERGY)); addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getActive)); addRenderableWidget(new GuiChemicalGauge(() -> tile.gasTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 131, 13)) @@ -38,7 +42,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, energyBar.getRelativeX()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiDigitalMiner.java b/src/main/java/mekanism/client/gui/machine/GuiDigitalMiner.java index a890e98aff5..a16c6511069 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiDigitalMiner.java +++ b/src/main/java/mekanism/client/gui/machine/GuiDigitalMiner.java @@ -57,6 +57,7 @@ public GuiDigitalMiner(MekanismTileContainer container, @Override protected void addGuiElements() { super.addGuiElements(); + int missingStackX = 64; addRenderableWidget(new GuiInnerScreen(this, 7, 19, 77, 69, () -> { List list = new ArrayList<>(); ILangEntry runningType; @@ -71,7 +72,15 @@ protected void addGuiElements() { list.add(tile.searcher.state.getTextComponent()); list.add(MekanismLang.MINER_TO_MINE.translate(TextUtils.format(tile.getToMine()))); return list; - }).clearSpacing().clearFormat()); + }) { + @Override + protected int getMaxTextWidth(int row) { + if (row < 2) { + return missingStackX - relativeX + 4; + } + return super.getMaxTextWidth(row); + } + }).clearSpacing().clearFormat(); addRenderableWidget(new GuiDigitalSwitch(this, 19, 56, EJECT, tile::getDoEject, (element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.AUTO_EJECT_BUTTON, ((GuiDigitalMiner) element.gui()).tile)), SwitchType.LOWER_ICON)) .setTooltip(MekanismLang.AUTO_EJECT); @@ -87,7 +96,7 @@ protected void addGuiElements() { return energyContainer.getEnergyPerTick() > energyContainer.getEnergy(); }); addRenderableWidget(new GuiVisualsTab(this, tile)); - addRenderableWidget(new GuiSlot(SlotType.DIGITAL, this, 64, 21).setRenderAboveSlots().validity(() -> tile.missingStack) + addRenderableWidget(new GuiSlot(SlotType.DIGITAL, this, missingStackX, 21).setRenderAboveSlots().validity(() -> tile.missingStack) .with(() -> tile.missingStack.isEmpty() ? SlotOverlay.CHECK : null) .hover(element -> ((GuiDigitalMiner) element.gui()).tile.missingStack.isEmpty() ? List.of(MekanismLang.MINER_WELL.translate()) : List.of(MekanismLang.MINER_MISSING_BLOCK.translate()))); addRenderableWidget(new GuiEnergyTab(this, () -> { diff --git a/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java b/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java index 3cd6b95fd03..a98838b9c33 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java +++ b/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java @@ -26,6 +26,7 @@ public class GuiElectricPump extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); + titleLabelY -= 1; inventoryLabelY += 2; dynamicSlots = true; } diff --git a/src/main/java/mekanism/client/gui/machine/GuiElectrolyticSeparator.java b/src/main/java/mekanism/client/gui/machine/GuiElectrolyticSeparator.java index 2f7a03c13a0..190e81886b8 100755 --- a/src/main/java/mekanism/client/gui/machine/GuiElectrolyticSeparator.java +++ b/src/main/java/mekanism/client/gui/machine/GuiElectrolyticSeparator.java @@ -2,6 +2,7 @@ import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiVerticalPowerBar; import mekanism.client.gui.element.button.GuiGasMode; import mekanism.client.gui.element.gauge.GaugeType; @@ -20,6 +21,8 @@ public class GuiElectrolyticSeparator extends GuiConfigurableTile> { + private GuiElement fluidGauge; + public GuiElectrolyticSeparator(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; @@ -29,7 +32,7 @@ public GuiElectrolyticSeparator(MekanismTileContainer tile.fluidTank, () -> tile.getFluidTanks(null), GaugeType.STANDARD, this, 5, 10)) + fluidGauge = addRenderableWidget(new GuiFluidGauge(() -> tile.fluidTank, () -> tile.getFluidTanks(null), GaugeType.STANDARD, this, 5, 10)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_INPUT)); addRenderableWidget(new GuiChemicalGauge(() -> tile.leftTank, () -> tile.getChemicalTanks(null), GaugeType.SMALL, this, 58, 18)) .warning(WarningType.NO_SPACE_IN_OUTPUT, tile.getWarningCheck(TileEntityElectrolyticSeparator.NOT_ENOUGH_SPACE_LEFT_OUTPUT_ERROR)); @@ -46,7 +49,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, fluidGauge.getRelativeRight()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiFactory.java b/src/main/java/mekanism/client/gui/machine/GuiFactory.java index af071f52098..a408b4db6d2 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiFactory.java +++ b/src/main/java/mekanism/client/gui/machine/GuiFactory.java @@ -20,9 +20,13 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class GuiFactory extends GuiConfigurableTile, MekanismTileContainer>> { + @Nullable + private GuiDumpButton dumpButton; + public GuiFactory(MekanismTileContainer> container, Inventory inv, Component title) { super(container, inv, title); if (tile.hasSecondaryResourceBar()) { @@ -54,7 +58,7 @@ protected void addGuiElements() { addRenderableWidget(new GuiChemicalBar(this, GuiChemicalBar.getProvider(factory.getChemicalTank(), tile.getChemicalTanks(null)), 7, 76, tile.tier == FactoryTier.ULTIMATE ? 172 : 138, 4, true)) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_SECONDARY_INPUT, 0)); - addRenderableWidget(new GuiDumpButton<>(this, (TileEntityFactory & IHasDumpButton) tile, tile.tier == FactoryTier.ULTIMATE ? 182 : 148, 76)); + dumpButton = addRenderableWidget(new GuiDumpButton<>(this, (TileEntityFactory & IHasDumpButton) tile, tile.tier == FactoryTier.ULTIMATE ? 182 : 148, 76)); } } @@ -72,7 +76,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, dumpButton == null ? getXSize() : dumpButton.getRelativeX()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java b/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java index 3d3e0761391..7668ee9d435 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java +++ b/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java @@ -27,6 +27,7 @@ public class GuiFluidicPlenisher extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); + titleLabelY -= 1; inventoryLabelY += 2; dynamicSlots = true; } diff --git a/src/main/java/mekanism/client/gui/machine/GuiIsotopicCentrifuge.java b/src/main/java/mekanism/client/gui/machine/GuiIsotopicCentrifuge.java index a756b87dcc2..fd4f843cc54 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiIsotopicCentrifuge.java +++ b/src/main/java/mekanism/client/gui/machine/GuiIsotopicCentrifuge.java @@ -2,6 +2,7 @@ import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; @@ -18,6 +19,8 @@ public class GuiIsotopicCentrifuge extends GuiConfigurableTile> { + private GuiElement energyBar; + public GuiIsotopicCentrifuge(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); inventoryLabelY += 2; @@ -28,7 +31,7 @@ public GuiIsotopicCentrifuge(MekanismTileContainer @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiHorizontalPowerBar(this, tile.getEnergyContainer(), 115, 75)) + energyBar = addRenderableWidget(new GuiHorizontalPowerBar(this, tile.getEnergyContainer(), 115, 75)) .warning(WarningType.NOT_ENOUGH_ENERGY, tile.getWarningCheck(RecipeError.NOT_ENOUGH_ENERGY)) .warning(WarningType.NOT_ENOUGH_ENERGY_REDUCED_RATE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_ENERGY_REDUCED_RATE)); addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getEnergyUsed)); @@ -43,7 +46,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, energyBar.getRelativeX()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } diff --git a/src/main/java/mekanism/client/gui/machine/GuiNutritionalLiquifier.java b/src/main/java/mekanism/client/gui/machine/GuiNutritionalLiquifier.java index 78ecda57061..ecde8106e70 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiNutritionalLiquifier.java +++ b/src/main/java/mekanism/client/gui/machine/GuiNutritionalLiquifier.java @@ -3,6 +3,7 @@ import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; import mekanism.client.gui.element.GuiDownArrow; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiFluidGauge; @@ -19,6 +20,8 @@ public class GuiNutritionalLiquifier extends GuiConfigurableTile> { + private GuiElement energyBar; + public GuiNutritionalLiquifier(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; @@ -27,7 +30,7 @@ public GuiNutritionalLiquifier(MekanismTileContainer tile.fluidTank, () -> tile.getFluidTanks(null), GaugeType.STANDARD, this, 133, 13)) @@ -40,7 +43,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, energyBar.getRelativeX()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } diff --git a/src/main/java/mekanism/client/gui/machine/GuiPRC.java b/src/main/java/mekanism/client/gui/machine/GuiPRC.java index 7531685d1e4..1dc93ab5a78 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPRC.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPRC.java @@ -45,7 +45,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleTextWithOffset(guiGraphics, secondGauge.getRelativeX() + secondGauge.getWidth(), getXSize(), 4, TextAlignment.LEFT); + renderTitleTextWithOffset(guiGraphics, secondGauge.getRelativeRight(), getXSize(), 4, TextAlignment.LEFT); renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiPigmentExtractor.java b/src/main/java/mekanism/client/gui/machine/GuiPigmentExtractor.java index 2d221595560..8e140bb8c7b 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPigmentExtractor.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPigmentExtractor.java @@ -5,6 +5,7 @@ import mekanism.api.recipes.ItemStackToChemicalRecipe; import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; @@ -23,6 +24,8 @@ public class GuiPigmentExtractor extends GuiConfigurableTile> { + private GuiElement energyBar; + public GuiPigmentExtractor(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; @@ -31,7 +34,7 @@ public GuiPigmentExtractor(MekanismTileContainer con @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiHorizontalPowerBar(this, tile.getEnergyContainer(), 115, 75)) + energyBar = addRenderableWidget(new GuiHorizontalPowerBar(this, tile.getEnergyContainer(), 115, 75)) .warning(WarningType.NOT_ENOUGH_ENERGY, tile.getWarningCheck(RecipeError.NOT_ENOUGH_ENERGY)); addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getActive)); addRenderableWidget(new GuiChemicalGauge(() -> tile.pigmentTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 131, 13)) @@ -43,7 +46,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, energyBar.getRelativeX()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java b/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java index 3db32f3434b..9d414864202 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPigmentMixer.java @@ -54,7 +54,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleTextWithOffset(guiGraphics, 1, centerGauge.getRelativeX(), 4, TextAlignment.LEFT); - renderInventoryText(guiGraphics); + renderInventoryText(guiGraphics, centerGauge.getRelativeX()); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/machine/GuiRotaryCondensentrator.java b/src/main/java/mekanism/client/gui/machine/GuiRotaryCondensentrator.java index fb77ee05930..a854c5088cd 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiRotaryCondensentrator.java +++ b/src/main/java/mekanism/client/gui/machine/GuiRotaryCondensentrator.java @@ -4,6 +4,7 @@ import mekanism.api.text.ILangEntry; import mekanism.client.gui.GuiConfigurableTile; import mekanism.client.gui.element.GuiDownArrow; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiHorizontalPowerBar; import mekanism.client.gui.element.button.ToggleButton; import mekanism.client.gui.element.gauge.GaugeType; @@ -28,6 +29,8 @@ public class GuiRotaryCondensentrator extends GuiConfigurableTile> { + private GuiElement energyBar; + public GuiRotaryCondensentrator(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; @@ -38,7 +41,7 @@ public GuiRotaryCondensentrator(MekanismTileContainer 0) { int textColor = 0x80FF20; @@ -95,11 +96,12 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, } if (component != null) { - guiGraphics.fill(Math.max(54 + 8, imageWidth - getStringWidth(component) - 10), 67, imageWidth - 8, 79, 0x4F000000); - drawScrollingString(guiGraphics, component, 54, 69, TextAlignment.RIGHT, textColor, getXSize() - 54, 9, true); + int min = Math.max(itemNameField.getRelativeX(), imageWidth - getStringWidth(component) - 10); + int max = imageWidth - 8; + guiGraphics.fill(min, 67, max, 79, 0x4F000000); + drawScrollingString(guiGraphics, component, min, 69, TextAlignment.RIGHT, textColor, max - min, 1, true); } } - renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/ChemicalCrystallizerEmiRecipe.java b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/ChemicalCrystallizerEmiRecipe.java index 7836b199b61..4b1e3860cac 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/ChemicalCrystallizerEmiRecipe.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/ChemicalCrystallizerEmiRecipe.java @@ -58,10 +58,19 @@ public void addWidgets(WidgetHolder widgetHolder) { GaugeType type = GaugeType.STANDARD.with(DataType.INPUT); initTank(widgetHolder, GuiChemicalGauge.getDummy(type, this, 7, 4), input(0)); addSlot(widgetHolder, SlotType.INPUT, 8, 65).with(SlotOverlay.PLUS); - addSlot(widgetHolder, SlotType.OUTPUT, 129, 57, output(0)).recipeContext(this); + int slotX = 128; + addSlot(widgetHolder, SlotType.OUTPUT, slotX + 1, 57, output(0)).recipeContext(this); addSimpleProgress(widgetHolder, ProgressType.LARGE_RIGHT, 53, 61, TileEntityChemicalCrystallizer.BASE_TICKS_REQUIRED); - addElement(widgetHolder, new GuiInnerScreen(this, 31, 13, 115, 42, () -> GuiChemicalCrystallizer.getScreenRenderStrings(this.oreInfo))); - GuiSlot slurryOreSlot = addElement(widgetHolder, new GuiSlot(SlotType.ORE, this, 128, 13).setRenderAboveSlots()); + addElement(widgetHolder, new GuiInnerScreen(this, 31, 13, 115, 42, () -> GuiChemicalCrystallizer.getScreenRenderStrings(this.oreInfo)) { + @Override + protected int getMaxTextWidth(int row) { + if (row == 0) { + return slotX - relativeX; + } + return super.getMaxTextWidth(row); + } + }); + GuiSlot slurryOreSlot = addElement(widgetHolder, new GuiSlot(SlotType.ORE, this, slotX, 13).setRenderAboveSlots()); initItem(widgetHolder, slurryOreSlot.getX(), slurryOreSlot.getY(), ingredient(displayItems)); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java index d784de72f84..96dd252d87b 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java @@ -47,10 +47,19 @@ public ChemicalCrystallizerRecipeCategory(IGuiHelper helper, IRecipeViewerRecipe GaugeType type = GaugeType.STANDARD.with(DataType.INPUT); gauge = addElement(GuiChemicalGauge.getDummy(type, this, 7, 4)); addSlot(SlotType.INPUT, 8, 65).with(SlotOverlay.PLUS); - output = addSlot(SlotType.OUTPUT, 129, 57); + int slotX = 128; + output = addSlot(SlotType.OUTPUT, slotX + 1, 57); addSimpleProgress(ProgressType.LARGE_RIGHT, 53, 61); - addElement(new GuiInnerScreen(this, 31, 13, 115, 42, () -> GuiChemicalCrystallizer.getScreenRenderStrings(this.oreInfo))); - slurryOreSlot = addElement(new GuiSlot(SlotType.ORE, this, 128, 13).setRenderAboveSlots()); + addElement(new GuiInnerScreen(this, 31, 13, 115, 42, () -> GuiChemicalCrystallizer.getScreenRenderStrings(this.oreInfo)) { + @Override + protected int getMaxTextWidth(int row) { + if (row == 0) { + return slotX - relativeX; + } + return super.getMaxTextWidth(row); + } + }); + slurryOreSlot = addElement(new GuiSlot(SlotType.ORE, this, slotX, 13).setRenderAboveSlots()); } @Override diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/machine/SawmillRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/machine/SawmillRecipeCategory.java index cd21886317e..c3abffdb365 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/machine/SawmillRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/machine/SawmillRecipeCategory.java @@ -54,8 +54,8 @@ public void draw(RecipeHolder recipeHolder, IRecipeSlotsView reci PoseStack pose = guiGraphics.pose(); pose.pushPose(); pose.translate(getGuiLeft(), getGuiTop(), 0); - drawScrollingString(guiGraphics, TextUtils.getPercent(secondaryChance), output.getRelativeX(), output.getRelativeY() + output.getHeight() + 1, - TextAlignment.RIGHT, titleTextColor(), output.getWidth(), 1, false); + drawScrollingString(guiGraphics, TextUtils.getPercent(secondaryChance), output.getRelativeX(), output.getRelativeBottom() + 1, TextAlignment.RIGHT, + titleTextColor(), output.getWidth(), 1, false); pose.popPose(); } } diff --git a/src/main/java/mekanism/client/recipe_viewer/type/VanillaRVRecipeType.java b/src/main/java/mekanism/client/recipe_viewer/type/VanillaRVRecipeType.java index 6037757a4cb..3b99054ef39 100644 --- a/src/main/java/mekanism/client/recipe_viewer/type/VanillaRVRecipeType.java +++ b/src/main/java/mekanism/client/recipe_viewer/type/VanillaRVRecipeType.java @@ -4,6 +4,7 @@ import java.util.Objects; import mekanism.api.annotations.NothingNullByDefault; import mekanism.api.providers.IItemProvider; +import mekanism.api.text.TextComponentUtil; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -25,7 +26,7 @@ public VanillaRVRecipeType(RecipeType vanillaType, Class getEnergyContainer() { return energyContainer; } + public int getEnergySlotX() { + return energySlot.getGuiX(); + } + public EnumColor getColor() { return color; } diff --git a/src/main/java/mekanism/common/tile/machine/TileEntityChemicalCrystallizer.java b/src/main/java/mekanism/common/tile/machine/TileEntityChemicalCrystallizer.java index c39ec438eb6..b42782069b9 100644 --- a/src/main/java/mekanism/common/tile/machine/TileEntityChemicalCrystallizer.java +++ b/src/main/java/mekanism/common/tile/machine/TileEntityChemicalCrystallizer.java @@ -124,6 +124,10 @@ protected boolean onUpdateServer() { return sendUpdatePacket; } + public int getEnergySlotX() { + return energySlot.getGuiX(); + } + @Override public @NotNull IMekanismRecipeTypeProvider> getRecipeType() { return MekanismRecipeType.CRYSTALLIZING; From 284c31365ab760fc37bc99bd387ff628f0bf7355 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Tue, 24 Sep 2024 11:20:46 -0500 Subject: [PATCH 05/17] Reduce duplicate code between crystallizer gui and recipe categories so that we only have to define the max text bounds in one place --- .../client/gui/element/GuiInnerScreen.java | 9 +- .../element/custom/GuiFrequencySelector.java | 2 +- .../custom/GuiQIOCrystallizerScreen.java | 140 ++++++++++++++++++ .../gui/machine/GuiChemicalCrystallizer.java | 110 +------------- .../recipe/ChemicalCrystallizerEmiRecipe.java | 30 ++-- .../recipe_viewer/jei/BaseRecipeCategory.java | 4 +- .../ChemicalCrystallizerRecipeCategory.java | 31 ++-- 7 files changed, 180 insertions(+), 146 deletions(-) create mode 100644 src/main/java/mekanism/client/gui/element/custom/GuiQIOCrystallizerScreen.java diff --git a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java index fe9046d40a0..9942d0cb196 100644 --- a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java +++ b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java @@ -88,11 +88,15 @@ public GuiInnerScreen defaultFormat() { return padding(5).spacing(2).textScale(0.8F).centerY(); } + protected List getRenderStrings() { + return renderStrings == null ? Collections.emptyList() : renderStrings.get(); + } + @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - if (renderStrings != null) { - List list = renderStrings.get(); + List list = getRenderStrings(); + if (!list.isEmpty()) { int lineHeight = getLineHeight(); int minY = relativeY + padding; int maxY = minY + lineHeight; @@ -107,7 +111,6 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { } int minX = relativeX + padding; int screenTextColor = screenTextColor(); - renderStrings.get(); for (int i = 0, size = list.size(); i < size; i++) { Component text = list.get(i); int maxX = relativeX + getMaxTextWidth(i) - padding; diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java b/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java index d912a627b00..10db3d03006 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiFrequencySelector.java @@ -110,7 +110,7 @@ public > GuiFrequency return true; })); if (hasColor) { - addChild(new GuiSlot(SlotType.NORMAL, frequencySelector, relativeX + 104, relativeY + 113).setRenderAboveSlots()); + addChild(new GuiSlot(SlotType.NORMAL, frequencySelector, relativeX + 104, relativeY + 113)); IGuiColorFrequencySelector colorFrequencySelector = (IGuiColorFrequencySelector) frequencySelector; addChild(new ColorButton(frequencySelector, relativeX + 105, relativeY + 114, 16, 16, () -> { IColorableFrequency frequency = colorFrequencySelector.getFrequency(); diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiQIOCrystallizerScreen.java b/src/main/java/mekanism/client/gui/element/custom/GuiQIOCrystallizerScreen.java new file mode 100644 index 00000000000..378b9ff3efa --- /dev/null +++ b/src/main/java/mekanism/client/gui/element/custom/GuiQIOCrystallizerScreen.java @@ -0,0 +1,140 @@ +package mekanism.client.gui.element.custom; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import mekanism.api.MekanismAPI; +import mekanism.api.MekanismAPITags; +import mekanism.api.chemical.Chemical; +import mekanism.api.chemical.ChemicalStack; +import mekanism.api.recipes.ChemicalCrystallizerRecipe; +import mekanism.client.gui.IGuiWrapper; +import mekanism.client.gui.element.GuiInnerScreen; +import mekanism.client.gui.element.slot.GuiSequencedSlotDisplay; +import mekanism.client.gui.element.slot.GuiSlot; +import mekanism.client.gui.element.slot.SlotType; +import mekanism.common.MekanismLang; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class GuiQIOCrystallizerScreen extends GuiInnerScreen { + + @Nullable + private final GuiSequencedSlotDisplay slotDisplay; + private final List iterStacks; + private final IOreInfo oreInfo; + private final GuiSlot slot; + + @NotNull + private Chemical prevSlurry = MekanismAPI.EMPTY_CHEMICAL; + + public GuiQIOCrystallizerScreen(IGuiWrapper gui, int x, int y, int width, int height, IOreInfo oreInfo) { + super(gui, x, y, width, height); + this.oreInfo = oreInfo; + int slotX = relativeX + this.width - SlotType.ORE.getWidth(); + this.slot = addChild(new GuiSlot(SlotType.ORE, gui, slotX, 13)); + if (this.oreInfo.usesSequencedDisplay()) { + this.iterStacks = new ArrayList<>(); + this.slotDisplay = addChild(new GuiSequencedSlotDisplay(gui, slotX + 1, 14, () -> this.iterStacks)); + updateSlotContents(); + } else { + this.iterStacks = Collections.emptyList(); + this.slotDisplay = null; + } + defaultFormat(); + } + + public int getSlotX() { + return this.slot.getX(); + } + + public int getSlotY() { + return this.slot.getY(); + } + + @Override + public void tick() { + updateSlotContents(); + super.tick(); + } + + private void updateSlotContents() { + if (oreInfo.usesSequencedDisplay() && slotDisplay != null) {//Note: If we use the sequenced display, slotDisplay should never be null + ChemicalStack chemical = oreInfo.getInputChemical(); + if (!chemical.isEmpty()) { + Chemical inputSlurry = chemical.getChemical(); + if (prevSlurry != inputSlurry) { + prevSlurry = inputSlurry; + iterStacks.clear(); + if (!prevSlurry.isEmptyType() && !prevSlurry.is(MekanismAPITags.Chemicals.DIRTY)) { + TagKey oreTag = prevSlurry.getOreTag(); + if (oreTag != null) { + for (Holder ore : BuiltInRegistries.ITEM.getTagOrEmpty(oreTag)) { + iterStacks.add(new ItemStack(ore)); + } + } + } + slotDisplay.updateStackList(); + } + } else if (!prevSlurry.isEmptyType()) { + prevSlurry = MekanismAPI.EMPTY_CHEMICAL; + iterStacks.clear(); + slotDisplay.updateStackList(); + } + } + } + + @Override + protected List getRenderStrings() { + ChemicalStack chemical = oreInfo.getInputChemical(); + if (!chemical.isEmpty()) { + Component recipeComponent; + //Note: If we use the sequenced display, slotDisplay should never be null + ItemStack renderStack = oreInfo.usesSequencedDisplay() && slotDisplay != null ? slotDisplay.getRenderStack() : oreInfo.getRenderStack(); + if (!renderStack.isEmpty()) { + recipeComponent = MekanismLang.GENERIC_PARENTHESIS.translate(renderStack); + } else { + ChemicalCrystallizerRecipe recipe = oreInfo.getRecipe(); + if (recipe == null) { + recipeComponent = MekanismLang.NO_RECIPE.translate(); + } else { + recipeComponent = MekanismLang.GENERIC_PARENTHESIS.translate(recipe.getOutput(chemical)); + } + } + return List.of(chemical.getTextComponent(), recipeComponent); + } + return Collections.emptyList(); + } + + @Override + protected int getMaxTextWidth(int row) { + if (row == 0) {//Don't allow the first line of text to intersect with the slot we draw + return width - slot.getWidth(); + } + return super.getMaxTextWidth(row); + } + + public interface IOreInfo { + + @NotNull + ChemicalStack getInputChemical(); + + @Nullable + ChemicalCrystallizerRecipe getRecipe(); + + @NotNull + default ItemStack getRenderStack() { + return ItemStack.EMPTY; + } + + default boolean usesSequencedDisplay() { + return true; + } + } +} diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalCrystallizer.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalCrystallizer.java index df526d618e5..0c1f738f557 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalCrystallizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalCrystallizer.java @@ -1,50 +1,32 @@ package mekanism.client.gui.machine; import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import mekanism.api.MekanismAPI; -import mekanism.api.MekanismAPITags; import mekanism.api.chemical.ChemicalStack; -import mekanism.api.chemical.Chemical; import mekanism.api.recipes.ChemicalCrystallizerRecipe; import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; import mekanism.client.gui.element.GuiElement; -import mekanism.client.gui.element.GuiInnerScreen; import mekanism.client.gui.element.bar.GuiVerticalPowerBar; +import mekanism.client.gui.element.custom.GuiQIOCrystallizerScreen; +import mekanism.client.gui.element.custom.GuiQIOCrystallizerScreen.IOreInfo; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; import mekanism.client.gui.element.progress.GuiProgress; import mekanism.client.gui.element.progress.ProgressType; -import mekanism.client.gui.element.slot.GuiSequencedSlotDisplay; -import mekanism.client.gui.element.slot.GuiSlot; -import mekanism.client.gui.element.slot.SlotType; import mekanism.client.gui.element.tab.GuiEnergyTab; -import mekanism.common.MekanismLang; import mekanism.common.inventory.container.tile.MekanismTileContainer; import mekanism.common.inventory.warning.WarningTracker.WarningType; import mekanism.common.tile.machine.TileEntityChemicalCrystallizer; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.core.Holder; -import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; -import net.minecraft.tags.TagKey; import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class GuiChemicalCrystallizer extends GuiConfigurableTile> { - private final List iterStacks = new ArrayList<>(); private final IOreInfo oreInfo = new OreInfo(); - private GuiSequencedSlotDisplay slotDisplay; private GuiElement inputGauge; - @NotNull - private Chemical prevSlurry = MekanismAPI.EMPTY_CHEMICAL; public GuiChemicalCrystallizer(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); @@ -62,22 +44,7 @@ protected void addGuiElements() { .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(RecipeError.NOT_ENOUGH_INPUT)); addRenderableWidget(new GuiProgress(tile::getScaledProgress, ProgressType.LARGE_RIGHT, this, 53, 61).recipeViewerCategory(tile)) .warning(WarningType.INPUT_DOESNT_PRODUCE_OUTPUT, tile.getWarningCheck(RecipeError.INPUT_DOESNT_PRODUCE_OUTPUT)); - //TODO - 1.21: Move this to being a custom gui element so that we don't have to copy this and the overrides to the recipe viewers - //Init slot display before gui screen, so it can reference it, but add it after, so it renders above it - int slotX = 128; - slotDisplay = new GuiSequencedSlotDisplay(this, slotX + 1, 14, () -> iterStacks); - updateSlotContents(); - addRenderableWidget(new GuiInnerScreen(this, 31, 13, 115, 42, () -> getScreenRenderStrings(this.oreInfo)) { - @Override - protected int getMaxTextWidth(int row) { - if (row == 0) { - return slotX - relativeX; - } - return super.getMaxTextWidth(row); - } - }); - addRenderableWidget(new GuiSlot(SlotType.ORE, this, slotX, 13).setRenderAboveSlots()); - addRenderableWidget(slotDisplay); + addRenderableWidget(new GuiQIOCrystallizerScreen(this, 31, 13, 115, 42, oreInfo)); } @Override @@ -86,74 +53,13 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, super.drawForegroundText(guiGraphics, mouseX, mouseY); } - @Override - public void containerTick() { - updateSlotContents(); - super.containerTick(); - } - - private void updateSlotContents() { - ChemicalStack chemical = oreInfo.getInputChemical(); - if (!chemical.isEmpty()) { - Chemical inputSlurry = chemical.getChemical(); - if (prevSlurry != inputSlurry) { - prevSlurry = inputSlurry; - iterStacks.clear(); - if (!prevSlurry.isEmptyType() && !prevSlurry.is(MekanismAPITags.Chemicals.DIRTY)) { - TagKey oreTag = prevSlurry.getOreTag(); - if (oreTag != null) { - for (Holder ore : BuiltInRegistries.ITEM.getTagOrEmpty(oreTag)) { - iterStacks.add(new ItemStack(ore)); - } - } - } - slotDisplay.updateStackList(); - } - } else if (!prevSlurry.isEmptyType()) { - prevSlurry = MekanismAPI.EMPTY_CHEMICAL; - iterStacks.clear(); - slotDisplay.updateStackList(); - } - } - - public static List getScreenRenderStrings(IOreInfo oreInfo) { - ChemicalStack chemical = oreInfo.getInputChemical(); - if (!chemical.isEmpty()) { - List ret = new ArrayList<>(); - ret.add(chemical.getTextComponent()); - if (!oreInfo.getRenderStack().isEmpty()) { - ret.add(MekanismLang.GENERIC_PARENTHESIS.translate(oreInfo.getRenderStack())); - } else { - ChemicalCrystallizerRecipe recipe = oreInfo.getRecipe(); - if (recipe == null) { - ret.add(MekanismLang.NO_RECIPE.translate()); - } else { - ret.add(MekanismLang.GENERIC_PARENTHESIS.translate(recipe.getOutput(chemical))); - } - } - return ret; - } - return Collections.emptyList(); - } - - public interface IOreInfo { - - @NotNull - ChemicalStack getInputChemical(); - - @Nullable - ChemicalCrystallizerRecipe getRecipe(); - - @NotNull - ItemStack getRenderStack(); - } - private class OreInfo implements IOreInfo { private WeakReference cachedRecipe; + @NotNull @Override - public @NotNull ChemicalStack getInputChemical() { + public ChemicalStack getInputChemical() { return tile.inputTank.getStack(); } @@ -176,12 +82,6 @@ public ChemicalCrystallizerRecipe getRecipe() { return recipe; } - @NotNull - @Override - public ItemStack getRenderStack() { - return slotDisplay == null ? ItemStack.EMPTY : slotDisplay.getRenderStack(); - } - private ChemicalCrystallizerRecipe getRecipeAndCache() { ChemicalCrystallizerRecipe recipe = tile.getRecipe(0); if (recipe == null) { diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/ChemicalCrystallizerEmiRecipe.java b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/ChemicalCrystallizerEmiRecipe.java index 4b1e3860cac..c91356fc753 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/ChemicalCrystallizerEmiRecipe.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/ChemicalCrystallizerEmiRecipe.java @@ -5,14 +5,12 @@ import mekanism.api.chemical.ChemicalStack; import mekanism.api.recipes.ChemicalCrystallizerRecipe; import mekanism.api.recipes.ingredients.ChemicalStackIngredient; -import mekanism.client.gui.element.GuiInnerScreen; +import mekanism.client.gui.element.custom.GuiQIOCrystallizerScreen; +import mekanism.client.gui.element.custom.GuiQIOCrystallizerScreen.IOreInfo; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; import mekanism.client.gui.element.progress.ProgressType; -import mekanism.client.gui.element.slot.GuiSlot; import mekanism.client.gui.element.slot.SlotType; -import mekanism.client.gui.machine.GuiChemicalCrystallizer; -import mekanism.client.gui.machine.GuiChemicalCrystallizer.IOreInfo; import mekanism.client.recipe_viewer.RecipeViewerUtils; import mekanism.client.recipe_viewer.emi.MekanismEmiRecipeCategory; import mekanism.common.inventory.container.slot.SlotOverlay; @@ -35,8 +33,9 @@ public ChemicalCrystallizerEmiRecipe(MekanismEmiRecipeCategory category, RecipeH List inputRepresentations = input.getRepresentations(); displayItems = RecipeViewerUtils.getDisplayItems(input); oreInfo = new IOreInfo() { + @NotNull @Override - public @NotNull ChemicalStack getInputChemical() { + public ChemicalStack getInputChemical() { return inputRepresentations.isEmpty() ? ChemicalStack.EMPTY : RecipeViewerUtils.getCurrent(inputRepresentations); } @@ -50,6 +49,11 @@ public ChemicalCrystallizerRecipe getRecipe() { public ItemStack getRenderStack() { return displayItems.isEmpty() ? ItemStack.EMPTY : RecipeViewerUtils.getCurrent(displayItems); } + + @Override + public boolean usesSequencedDisplay() { + return false; + } }; } @@ -58,19 +62,9 @@ public void addWidgets(WidgetHolder widgetHolder) { GaugeType type = GaugeType.STANDARD.with(DataType.INPUT); initTank(widgetHolder, GuiChemicalGauge.getDummy(type, this, 7, 4), input(0)); addSlot(widgetHolder, SlotType.INPUT, 8, 65).with(SlotOverlay.PLUS); - int slotX = 128; - addSlot(widgetHolder, SlotType.OUTPUT, slotX + 1, 57, output(0)).recipeContext(this); + addSlot(widgetHolder, SlotType.OUTPUT, 129, 57, output(0)).recipeContext(this); addSimpleProgress(widgetHolder, ProgressType.LARGE_RIGHT, 53, 61, TileEntityChemicalCrystallizer.BASE_TICKS_REQUIRED); - addElement(widgetHolder, new GuiInnerScreen(this, 31, 13, 115, 42, () -> GuiChemicalCrystallizer.getScreenRenderStrings(this.oreInfo)) { - @Override - protected int getMaxTextWidth(int row) { - if (row == 0) { - return slotX - relativeX; - } - return super.getMaxTextWidth(row); - } - }); - GuiSlot slurryOreSlot = addElement(widgetHolder, new GuiSlot(SlotType.ORE, this, slotX, 13).setRenderAboveSlots()); - initItem(widgetHolder, slurryOreSlot.getX(), slurryOreSlot.getY(), ingredient(displayItems)); + GuiQIOCrystallizerScreen screen = addElement(widgetHolder, new GuiQIOCrystallizerScreen(this, 31, 13, 115, 42, oreInfo)); + initItem(widgetHolder, screen.getSlotX(), screen.getSlotY(), ingredient(displayItems)); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java index 62ae2556e34..9eaf794d981 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java @@ -186,7 +186,9 @@ protected void renderElements(RECIPE recipe, IRecipeSlotsView recipeSlotsView, G } //Note: We don't care that onRenderForeground updates the maxZOffset in the mekanism gui as that is just used for rendering windows // and as our categories don't support windows we don't need to worry about that - int zOffset = 200; + //TODO: Re-evaluate this zOffset. We use 200 in GuiMekanism, but at least in JEI everything seems to render fine using zero. + // When using 200 the crystallizer screen's ore type slot ends up rendering in front of JEI's item rendering, so for now we are just setting this to zero + int zOffset = 0;//200; for (GuiElement element : guiElements) { pose.pushPose(); element.onRenderForeground(guiGraphics, x, y, zOffset, zOffset); diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java index 96dd252d87b..10e3dbc20c4 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/machine/ChemicalCrystallizerRecipeCategory.java @@ -4,15 +4,14 @@ import mekanism.api.chemical.ChemicalStack; import mekanism.api.recipes.ChemicalCrystallizerRecipe; import mekanism.api.recipes.ingredients.ChemicalStackIngredient; -import mekanism.client.gui.element.GuiInnerScreen; +import mekanism.client.gui.element.custom.GuiQIOCrystallizerScreen; +import mekanism.client.gui.element.custom.GuiQIOCrystallizerScreen.IOreInfo; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; import mekanism.client.gui.element.gauge.GuiGauge; import mekanism.client.gui.element.progress.ProgressType; import mekanism.client.gui.element.slot.GuiSlot; import mekanism.client.gui.element.slot.SlotType; -import mekanism.client.gui.machine.GuiChemicalCrystallizer; -import mekanism.client.gui.machine.GuiChemicalCrystallizer.IOreInfo; import mekanism.client.recipe_viewer.RecipeViewerUtils; import mekanism.client.recipe_viewer.jei.HolderRecipeCategory; import mekanism.client.recipe_viewer.type.IRecipeViewerRecipeType; @@ -40,26 +39,16 @@ public class ChemicalCrystallizerRecipeCategory extends HolderRecipeCategory gauge; private final GuiSlot output; - private final GuiSlot slurryOreSlot; + private final GuiQIOCrystallizerScreen screen; public ChemicalCrystallizerRecipeCategory(IGuiHelper helper, IRecipeViewerRecipeType recipeType) { super(helper, recipeType); GaugeType type = GaugeType.STANDARD.with(DataType.INPUT); gauge = addElement(GuiChemicalGauge.getDummy(type, this, 7, 4)); addSlot(SlotType.INPUT, 8, 65).with(SlotOverlay.PLUS); - int slotX = 128; - output = addSlot(SlotType.OUTPUT, slotX + 1, 57); + output = addSlot(SlotType.OUTPUT, 129, 57); addSimpleProgress(ProgressType.LARGE_RIGHT, 53, 61); - addElement(new GuiInnerScreen(this, 31, 13, 115, 42, () -> GuiChemicalCrystallizer.getScreenRenderStrings(this.oreInfo)) { - @Override - protected int getMaxTextWidth(int row) { - if (row == 0) { - return slotX - relativeX; - } - return super.getMaxTextWidth(row); - } - }); - slurryOreSlot = addElement(new GuiSlot(SlotType.ORE, this, slotX, 13).setRenderAboveSlots()); + screen = addElement(new GuiQIOCrystallizerScreen(this, 31, 13, 115, 42, oreInfo)); } @Override @@ -87,7 +76,7 @@ public void setRecipe(@NotNull IRecipeLayoutBuilder builder, RecipeHolder displayItems = RecipeViewerUtils.getDisplayItems(input); if (!displayItems.isEmpty()) { - initItem(builder, RecipeIngredientRole.RENDER_ONLY, slurryOreSlot, displayItems).setSlotName(DISPLAYED_ITEM); + initItem(builder, RecipeIngredientRole.RENDER_ONLY, screen.getSlotX(), screen.getSlotY(), displayItems).setSlotName(DISPLAYED_ITEM); } } @@ -99,8 +88,9 @@ private static class OreInfo implements IOreInfo { private ChemicalStack ingredient; private ItemStack itemIngredient = ItemStack.EMPTY; + @NotNull @Override - public @NotNull ChemicalStack getInputChemical() { + public ChemicalStack getInputChemical() { if (ingredient == null || ingredient.isEmpty()) { return ChemicalStack.EMPTY; } @@ -118,5 +108,10 @@ public ChemicalCrystallizerRecipe getRecipe() { public ItemStack getRenderStack() { return itemIngredient; } + + @Override + public boolean usesSequencedDisplay() { + return false; + } } } \ No newline at end of file From cb1a182c7dc2aa20f1d816f5498cb5cd15d2903d Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Tue, 24 Sep 2024 12:56:31 -0500 Subject: [PATCH 06/17] Work on adjusting various GUIs so that they don't have to make use of scrolling text for default configs when set to english --- .../gui/GuiFissionReactorLogicAdapter.java | 11 ++++++----- .../gui/GuiFusionReactorLogicAdapter.java | 17 +++++++++-------- .../client/gui/GuiSolarGenerator.java | 2 +- .../client/gui/element/GuiScreenSwitch.java | 1 + .../custom/GuiQIOCrystallizerScreen.java | 4 ++-- .../element/window/GuiSideConfiguration.java | 2 +- .../element/window/GuiTransporterConfig.java | 2 +- .../filter/GuiOredictionificatorFilter.java | 17 +++++++---------- .../filter/miner/GuiMinerFilterHelper.java | 2 ++ .../filter/miner/GuiMinerItemStackFilter.java | 6 +++--- .../filter/miner/GuiMinerModIDFilter.java | 6 +++--- .../window/filter/miner/GuiMinerTagFilter.java | 6 +++--- .../transporter/GuiSorterFilterHelper.java | 13 +++++++------ .../transporter/GuiSorterItemStackFilter.java | 6 +++--- .../transporter/GuiSorterModIDFilter.java | 6 +++--- .../filter/transporter/GuiSorterTagFilter.java | 6 +++--- .../mekanism/client/gui/robit/GuiRobitMain.java | 2 +- .../client/render/IFancyFontRenderer.java | 3 +++ 18 files changed, 59 insertions(+), 53 deletions(-) diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorLogicAdapter.java b/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorLogicAdapter.java index f48ccb33c4b..7faeb75f2ad 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorLogicAdapter.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFissionReactorLogicAdapter.java @@ -26,16 +26,17 @@ public class GuiFissionReactorLogicAdapter extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); + imageWidth += 20; } @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiElementHolder(this, 16, 31, 130, 90)); - scrollBar = addRenderableWidget(new GuiScrollBar(this, 146, 31, 90, () -> tile.getModes().length, () -> DISPLAY_COUNT)); + addRenderableWidget(new GuiElementHolder(this, 26, 31, 130, 90)); + scrollBar = addRenderableWidget(new GuiScrollBar(this, 156, 31, 90, () -> tile.getModes().length, () -> DISPLAY_COUNT)); for (int i = 0; i < DISPLAY_COUNT; i++) { int typeShift = 22 * i; - addRenderableWidget(new ReactorLogicButton<>(this, 17, 32 + typeShift, i, tile, FissionReactorLogic.class, scrollBar::getCurrentSelection, tile::getModes, this::changeLogic)); + addRenderableWidget(new ReactorLogicButton<>(this, 27, 32 + typeShift, i, tile, FissionReactorLogic.class, scrollBar::getCurrentSelection, tile::getModes, this::changeLogic)); } } @@ -48,8 +49,8 @@ private void changeLogic(FissionReactorLogic type) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(tile.logicType.getColor(), tile.logicType), 0, 123, TextAlignment.CENTER, titleTextColor(), 16, false); - drawScrollingString(guiGraphics, MekanismLang.STATUS.translate(EnumColor.RED, tile.getStatus()), 0, 136, TextAlignment.CENTER, titleTextColor(), 16, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(tile.logicType.getColor(), tile.logicType), 0, 123, TextAlignment.CENTER, titleTextColor(), 4, false); + drawScrollingString(guiGraphics, MekanismLang.STATUS.translate(EnumColor.RED, tile.getStatus()), 0, 136, TextAlignment.CENTER, titleTextColor(), 4, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java index 784d594d13c..f1d7dee8507 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorLogicAdapter.java @@ -30,19 +30,20 @@ public class GuiFusionReactorLogicAdapter extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); + imageWidth += 20; } @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiElementHolder(this, 16, 31, 130, 90)); - addRenderableWidget(new ToggleButton(this, 16, 19, 11, tile::isActiveCooled, + addRenderableWidget(new GuiElementHolder(this, 26, 31, 130, 90)); + addRenderableWidget(new ToggleButton(this, 26, 19, 11, tile::isActiveCooled, (element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.NEXT_MODE, ((GuiFusionReactorLogicAdapter) element.gui()).tile)))) .setTooltip(GeneratorsLang.REACTOR_LOGIC_TOGGLE_COOLING); - scrollBar = addRenderableWidget(new GuiScrollBar(this, 146, 31, 90, () -> tile.getModes().length, () -> DISPLAY_COUNT)); + scrollBar = addRenderableWidget(new GuiScrollBar(this, 156, 31, 90, () -> tile.getModes().length, () -> DISPLAY_COUNT)); for (int i = 0; i < DISPLAY_COUNT; i++) { int typeShift = 22 * i; - addRenderableWidget(new ReactorLogicButton<>(this, 17, 32 + typeShift, i, tile, FusionReactorLogic.class, scrollBar::getCurrentSelection, tile::getModes, this::changeLogic)); + addRenderableWidget(new ReactorLogicButton<>(this, 27, 32 + typeShift, i, tile, FusionReactorLogic.class, scrollBar::getCurrentSelection, tile::getModes, this::changeLogic)); } } @@ -55,11 +56,11 @@ private void changeLogic(FusionReactorLogic type) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_ACTIVE_COOLING.translate(EnumColor.RED, OnOff.of(tile.isActiveCooled())), 13, 20, TextAlignment.LEFT, - titleTextColor(), getXSize() - 13, 16, false); - drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(EnumColor.RED, tile.logicType), 0, 123, TextAlignment.CENTER, titleTextColor(), 16, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_ACTIVE_COOLING.translate(EnumColor.RED, OnOff.of(tile.isActiveCooled())), 23, 20, TextAlignment.LEFT, + titleTextColor(), getXSize() - 23, 16, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_LOGIC_REDSTONE_MODE.translate(EnumColor.RED, tile.logicType), 0, 123, TextAlignment.CENTER, titleTextColor(), 4, false); drawScrollingString(guiGraphics, MekanismLang.STATUS.translate(EnumColor.RED, tile.checkMode() ? GeneratorsLang.REACTOR_LOGIC_OUTPUTTING : MekanismLang.IDLE), - 0, 136, TextAlignment.CENTER, titleTextColor(), 16, false); + 0, 136, TextAlignment.CENTER, titleTextColor(), 4, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiSolarGenerator.java b/src/generators/java/mekanism/generators/client/gui/GuiSolarGenerator.java index 235b350ce30..befcbd98c34 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiSolarGenerator.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiSolarGenerator.java @@ -32,7 +32,7 @@ protected void addGuiElements() { //Add the side holder before the slots, as it holds a couple of the slots addRenderableWidget(GuiSideHolder.create(this, -26, 6, 98, true, true, SpecialColors.TAB_ARMOR_SLOTS)); super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 48, 23, 80, 40, () -> List.of( + addRenderableWidget(new GuiInnerScreen(this, 40, 23, 96, 40, () -> List.of( EnergyDisplay.of(tile.getEnergyContainer()).getTextComponent(), GeneratorsLang.PRODUCING_AMOUNT.translate(EnergyDisplay.of(tile.getProductionRate())), GeneratorsLang.OUTPUT_RATE_SHORT.translate(EnergyDisplay.of(tile.getMaxOutput())) diff --git a/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java b/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java index dde31010867..d68bcd3fd52 100644 --- a/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java +++ b/src/main/java/mekanism/client/gui/element/GuiScreenSwitch.java @@ -21,6 +21,7 @@ public GuiScreenSwitch(IGuiWrapper gui, int x, int y, int width, Component butto this.active = true; this.clickSound = () -> this.stateSupplier.getAsBoolean() ? MekanismSounds.BEEP_OFF.get() : MekanismSounds.BEEP_ON.get(); this.clickVolume = 1.0F; + padding(4); } @Override diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiQIOCrystallizerScreen.java b/src/main/java/mekanism/client/gui/element/custom/GuiQIOCrystallizerScreen.java index 378b9ff3efa..66859d2412e 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiQIOCrystallizerScreen.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiQIOCrystallizerScreen.java @@ -38,10 +38,10 @@ public GuiQIOCrystallizerScreen(IGuiWrapper gui, int x, int y, int width, int he super(gui, x, y, width, height); this.oreInfo = oreInfo; int slotX = relativeX + this.width - SlotType.ORE.getWidth(); - this.slot = addChild(new GuiSlot(SlotType.ORE, gui, slotX, 13)); + this.slot = addChild(new GuiSlot(SlotType.ORE, gui, slotX, relativeY)); if (this.oreInfo.usesSequencedDisplay()) { this.iterStacks = new ArrayList<>(); - this.slotDisplay = addChild(new GuiSequencedSlotDisplay(gui, slotX + 1, 14, () -> this.iterStacks)); + this.slotDisplay = addChild(new GuiSequencedSlotDisplay(gui, slotX + 1, relativeY + 1, () -> this.iterStacks)); updateSlotContents(); } else { this.iterStacks = Collections.emptyList(); diff --git a/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java b/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java index cf1cd94507e..bb78ca5faea 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiSideConfiguration.java @@ -59,7 +59,7 @@ public GuiSideConfiguration(IGuiWrapper gui, int x, int y, TILE tile, SelectedWi setCurrentType(transmissions.getFirst()); //TODO: Try to make the GUI look a bit better as it still seems a bit off with the scales and such // Maybe we want to eventually add some sort of "in world preview" type thing - addChild(new GuiInnerScreen(gui, relativeX + 41, relativeY + 25, 74, 12, () -> { + addChild(new GuiInnerScreen(gui, relativeX + 38, relativeY + 25, 80, 12, () -> { ConfigInfo config = getCurrentConfig(); if (config == null || !config.canEject()) { return Collections.singletonList(MekanismLang.NO_EJECT.translate()); diff --git a/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java b/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java index 0fc4c773cdf..917e9fbbfdf 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiTransporterConfig.java @@ -38,7 +38,7 @@ public GuiTransporterConfig(IGuiWrapper gui, int x, int y, TILE tile, SelectedWi } this.tile = tile; interactionStrategy = InteractionStrategy.ALL; - addChild(new GuiInnerScreen(gui, relativeX + 41, relativeY + 15, 74, 12, + addChild(new GuiInnerScreen(gui, relativeX + 38, relativeY + 15, 80, 12, () -> Collections.singletonList(MekanismLang.STRICT_INPUT_ENABLED.translate(OnOff.of(tile.getEjector().hasStrictInput()))))); addChild(new GuiSlot(SlotType.NORMAL, gui, relativeX + 111, relativeY + 48)); addChild(new MekanismImageButton(gui, relativeX + 136, relativeY + 6, 14, 16, getButtonLocation("exclamation"), diff --git a/src/main/java/mekanism/client/gui/element/window/filter/GuiOredictionificatorFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/GuiOredictionificatorFilter.java index 9f97c8d7bea..dfcc5e48212 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/GuiOredictionificatorFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/GuiOredictionificatorFilter.java @@ -21,16 +21,18 @@ public class GuiOredictionificatorFilter extends GuiTextFilter { + private static final int WIDTH = 162; + public static GuiOredictionificatorFilter create(IGuiWrapper gui, TileEntityOredictionificator tile) { - return new GuiOredictionificatorFilter(gui, (gui.getXSize() - 152) / 2, 15, tile, null); + return new GuiOredictionificatorFilter(gui, (gui.getXSize() - WIDTH) / 2, 15, tile, null); } public static GuiOredictionificatorFilter edit(IGuiWrapper gui, TileEntityOredictionificator tile, OredictionificatorItemFilter filter) { - return new GuiOredictionificatorFilter(gui, (gui.getXSize() - 152) / 2, 15, tile, filter); + return new GuiOredictionificatorFilter(gui, (gui.getXSize() - WIDTH) / 2, 15, tile, filter); } private GuiOredictionificatorFilter(IGuiWrapper gui, int x, int y, TileEntityOredictionificator tile, @Nullable OredictionificatorItemFilter origFilter) { - super(gui, x, y, 152, 100, MekanismLang.OREDICTIONIFICATOR_FILTER.translate(), tile, origFilter); + super(gui, x, y, WIDTH, 100, MekanismLang.OREDICTIONIFICATOR_FILTER.translate(), tile, origFilter); } @Override @@ -38,15 +40,10 @@ protected int getScreenHeight() { return 52; } - @Override - protected int getSlotOffset() { - return 32; - } - @Override protected void init() { super.init(); - addChild(new MekanismImageButton(gui(), relativeX + 10, relativeY + 18, 12, getButtonLocation("left"), (element, mouseX, mouseY) -> { + addChild(new MekanismImageButton(gui(), relativeX + 3, relativeY + 38, 12, getButtonLocation("left"), (element, mouseX, mouseY) -> { if (filter.hasFilter()) { filter.previous(); slotDisplay.updateStackList(); @@ -54,7 +51,7 @@ protected void init() { } return false; })).setTooltip(MekanismLang.LAST_ITEM); - addChild(new MekanismImageButton(gui(), relativeX + 10, relativeY + 52, 12, getButtonLocation("right"), (element, mouseX, mouseY) -> { + addChild(new MekanismImageButton(gui(), relativeX + 16, relativeY + 38, 12, getButtonLocation("right"), (element, mouseX, mouseY) -> { if (filter.hasFilter()) { filter.next(); slotDisplay.updateStackList(); diff --git a/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerFilterHelper.java b/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerFilterHelper.java index 64bb8d5616c..18878ca23fc 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerFilterHelper.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerFilterHelper.java @@ -22,6 +22,8 @@ public interface GuiMinerFilterHelper extends GuiFilterHelper { + int MINER_FILTER_WIDTH = 173; + @Override MinerFilter getFilter(); diff --git a/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerItemStackFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerItemStackFilter.java index f0c5072acc1..35380d85416 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerItemStackFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerItemStackFilter.java @@ -12,15 +12,15 @@ public class GuiMinerItemStackFilter extends GuiItemStackFilter implements GuiMinerFilterHelper { public static GuiMinerItemStackFilter create(IGuiWrapper gui, TileEntityDigitalMiner tile) { - return new GuiMinerItemStackFilter(gui, (gui.getXSize() - 173) / 2, 30, tile, null); + return new GuiMinerItemStackFilter(gui, (gui.getXSize() - MINER_FILTER_WIDTH) / 2, 30, tile, null); } public static GuiMinerItemStackFilter edit(IGuiWrapper gui, TileEntityDigitalMiner tile, MinerItemStackFilter filter) { - return new GuiMinerItemStackFilter(gui, (gui.getXSize() - 173) / 2, 30, tile, filter); + return new GuiMinerItemStackFilter(gui, (gui.getXSize() - MINER_FILTER_WIDTH) / 2, 30, tile, filter); } private GuiMinerItemStackFilter(IGuiWrapper gui, int x, int y, TileEntityDigitalMiner tile, @Nullable MinerItemStackFilter origFilter) { - super(gui, x, y, 173, 90, tile, origFilter); + super(gui, x, y, MINER_FILTER_WIDTH, 90, tile, origFilter); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerModIDFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerModIDFilter.java index 1e8a9987485..ca8e30d61d6 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerModIDFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerModIDFilter.java @@ -14,15 +14,15 @@ public class GuiMinerModIDFilter extends GuiModIDFilter implements GuiMinerFilterHelper { public static GuiMinerModIDFilter create(IGuiWrapper gui, TileEntityDigitalMiner tile) { - return new GuiMinerModIDFilter(gui, (gui.getXSize() - 173) / 2, 30, tile, null); + return new GuiMinerModIDFilter(gui, (gui.getXSize() - MINER_FILTER_WIDTH) / 2, 30, tile, null); } public static GuiMinerModIDFilter edit(IGuiWrapper gui, TileEntityDigitalMiner tile, MinerModIDFilter filter) { - return new GuiMinerModIDFilter(gui, (gui.getXSize() - 173) / 2, 30, tile, filter); + return new GuiMinerModIDFilter(gui, (gui.getXSize() - MINER_FILTER_WIDTH) / 2, 30, tile, filter); } private GuiMinerModIDFilter(IGuiWrapper gui, int x, int y, TileEntityDigitalMiner tile, @Nullable MinerModIDFilter origFilter) { - super(gui, x, y, 173, 90, tile, origFilter); + super(gui, x, y, MINER_FILTER_WIDTH, 90, tile, origFilter); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerTagFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerTagFilter.java index 780e0afc88e..4367b41cd51 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerTagFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerTagFilter.java @@ -14,15 +14,15 @@ public class GuiMinerTagFilter extends GuiTagFilter implements GuiMinerFilterHelper { public static GuiMinerTagFilter create(IGuiWrapper gui, TileEntityDigitalMiner tile) { - return new GuiMinerTagFilter(gui, (gui.getXSize() - 173) / 2, 30, tile, null); + return new GuiMinerTagFilter(gui, (gui.getXSize() - MINER_FILTER_WIDTH) / 2, 30, tile, null); } public static GuiMinerTagFilter edit(IGuiWrapper gui, TileEntityDigitalMiner tile, MinerTagFilter filter) { - return new GuiMinerTagFilter(gui, (gui.getXSize() - 173) / 2, 30, tile, filter); + return new GuiMinerTagFilter(gui, (gui.getXSize() - MINER_FILTER_WIDTH) / 2, 30, tile, filter); } private GuiMinerTagFilter(IGuiWrapper gui, int x, int y, TileEntityDigitalMiner tile, @Nullable MinerTagFilter origFilter) { - super(gui, x, y, 173, 90, tile, origFilter); + super(gui, x, y, MINER_FILTER_WIDTH, 90, tile, origFilter); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java index 9eebd0c4c2b..2f6a77339d0 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java @@ -28,6 +28,8 @@ public interface GuiSorterFilterHelper extends GuiFilterHelper, IFancyFontRenderer, ContainerEventHandler { + int SORTER_FILTER_WIDTH = 200; + @Override SorterFilter getFilter(); @@ -54,12 +56,12 @@ default void addSorterDefaults(IGuiWrapper gui, int slotOffset, UnaryOperator filter = getFilter(); - int screenEnd = 29 + getScreenWidth(); + int screenEnd = 30 + getScreenWidth(); drawScrollingString(guiGraphics, OnOff.of(filter.allowDefault).getTextComponent(), 159, 20, TextAlignment.LEFT, titleTextColor(), getXSize() - 161, 2, false); //Note: We add two to the length, as min and max have two spaces at the end given we aren't actually providing a parameter //TODO: Do we want to adjust this, and just have separate lang keys for them? - drawScrollingString(guiGraphics, MekanismLang.MIN.translate(""), screenEnd, 32, TextAlignment.LEFT, titleTextColor(), 168 - screenEnd, 1, false); - //TODO - 1.21: Make the gui slightly wider so that we can have it so max isn't scrolling ever so slightly be default? - drawScrollingString(guiGraphics, MekanismLang.MAX.translate(""), screenEnd, 44, TextAlignment.LEFT, titleTextColor(), 168 - screenEnd, 1, false); + drawScrollingString(guiGraphics, MekanismLang.MIN.translate(""), screenEnd, 32, TextAlignment.LEFT, titleTextColor(), 173 - screenEnd, 2, false); + drawScrollingString(guiGraphics, MekanismLang.MAX.translate(""), screenEnd, 44, TextAlignment.LEFT, titleTextColor(), 173 - screenEnd, 2, false); if (isSingleItem() && filter.sizeMode) { drawScrollingString(guiGraphics, MekanismLang.SORTER_FILTER_SIZE_MODE.translateColored(EnumColor.RED, OnOff.ON), 159, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 159, 2, false); } else { diff --git a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterItemStackFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterItemStackFilter.java index 91191a72b1d..b879cf24f01 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterItemStackFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterItemStackFilter.java @@ -14,18 +14,18 @@ public class GuiSorterItemStackFilter extends GuiItemStackFilter implements GuiSorterFilterHelper { public static GuiSorterItemStackFilter create(IGuiWrapper gui, TileEntityLogisticalSorter tile) { - return new GuiSorterItemStackFilter(gui, (gui.getXSize() - 195) / 2, 30, tile, null); + return new GuiSorterItemStackFilter(gui, (gui.getXSize() - SORTER_FILTER_WIDTH) / 2, 30, tile, null); } public static GuiSorterItemStackFilter edit(IGuiWrapper gui, TileEntityLogisticalSorter tile, SorterItemStackFilter filter) { - return new GuiSorterItemStackFilter(gui, (gui.getXSize() - 195) / 2, 30, tile, filter); + return new GuiSorterItemStackFilter(gui, (gui.getXSize() - SORTER_FILTER_WIDTH) / 2, 30, tile, filter); } private GuiTextField minField; private GuiTextField maxField; private GuiSorterItemStackFilter(IGuiWrapper gui, int x, int y, TileEntityLogisticalSorter tile, @Nullable SorterItemStackFilter origFilter) { - super(gui, x, y, 195, 90, tile, origFilter); + super(gui, x, y, SORTER_FILTER_WIDTH, 90, tile, origFilter); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterModIDFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterModIDFilter.java index 506aad2dbe9..0d4301f5209 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterModIDFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterModIDFilter.java @@ -11,18 +11,18 @@ public class GuiSorterModIDFilter extends GuiModIDFilter implements GuiSorterFilterHelper { public static GuiSorterModIDFilter create(IGuiWrapper gui, TileEntityLogisticalSorter tile) { - return new GuiSorterModIDFilter(gui, (gui.getXSize() - 182) / 2, 30, tile, null); + return new GuiSorterModIDFilter(gui, (gui.getXSize() - SORTER_FILTER_WIDTH) / 2, 30, tile, null); } public static GuiSorterModIDFilter edit(IGuiWrapper gui, TileEntityLogisticalSorter tile, SorterModIDFilter filter) { - return new GuiSorterModIDFilter(gui, (gui.getXSize() - 182) / 2, 30, tile, filter); + return new GuiSorterModIDFilter(gui, (gui.getXSize() - SORTER_FILTER_WIDTH) / 2, 30, tile, filter); } private GuiTextField minField; private GuiTextField maxField; private GuiSorterModIDFilter(IGuiWrapper gui, int x, int y, TileEntityLogisticalSorter tile, @Nullable SorterModIDFilter origFilter) { - super(gui, x, y, 195, 90, tile, origFilter); + super(gui, x, y, SORTER_FILTER_WIDTH, 90, tile, origFilter); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterTagFilter.java b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterTagFilter.java index 18851b914cd..19f04580728 100644 --- a/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterTagFilter.java +++ b/src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterTagFilter.java @@ -11,18 +11,18 @@ public class GuiSorterTagFilter extends GuiTagFilter implements GuiSorterFilterHelper { public static GuiSorterTagFilter create(IGuiWrapper gui, TileEntityLogisticalSorter tile) { - return new GuiSorterTagFilter(gui, (gui.getXSize() - 182) / 2, 30, tile, null); + return new GuiSorterTagFilter(gui, (gui.getXSize() - SORTER_FILTER_WIDTH) / 2, 30, tile, null); } public static GuiSorterTagFilter edit(IGuiWrapper gui, TileEntityLogisticalSorter tile, SorterTagFilter filter) { - return new GuiSorterTagFilter(gui, (gui.getXSize() - 182) / 2, 30, tile, filter); + return new GuiSorterTagFilter(gui, (gui.getXSize() - SORTER_FILTER_WIDTH) / 2, 30, tile, filter); } private GuiTextField minField; private GuiTextField maxField; private GuiSorterTagFilter(IGuiWrapper gui, int x, int y, TileEntityLogisticalSorter tile, @Nullable SorterTagFilter origFilter) { - super(gui, x, y, 195, 90, tile, origFilter); + super(gui, x, y, SORTER_FILTER_WIDTH, 90, tile, origFilter); } @Override diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java index 82692326b26..05dcd430d7e 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java @@ -63,7 +63,7 @@ protected void addGuiElements() { addRenderableWidget(new GuiInnerScreen(this, 27, 16, 122, 56, () -> List.of( MekanismLang.ROBIT_GREETING.translate(robit.getName()), Component.empty(), - MekanismLang.ENERGY.translate(EnergyDisplay.of(robit.getEnergyContainer())), + MekanismLang.ENERGY.translate(EnergyDisplay.of(robit.getEnergyContainer().getEnergy())), MekanismLang.ROBIT_FOLLOWING.translate(robit.getFollowing()), MekanismLang.ROBIT_DROP_PICKUP.translate(robit.getDropPickup()), MekanismLang.ROBIT_OWNER.translate(robit.getOwnerName()) diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 0d238b212e8..7116c60c11b 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -196,6 +196,9 @@ enum TextAlignment { RIGHT; public float getTarget(int minX, int maxX, float areaWidth, float textWidth) { + //TODO: Do we want to swap left and right when Font#isBidirectional is true? + // I believe in right to left languages text is meant to be aligned to the right + // but it likely would look odd in various GUIs return switch (this) { case LEFT -> minX; case CENTER -> minX + (areaWidth - textWidth) / 2F; From 070f29335188a0522e8676918220eb097231028d Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Tue, 24 Sep 2024 15:11:45 -0500 Subject: [PATCH 07/17] Slightly resize a handful of multiblock guis so that they don't have to make use of scrolling text for default configs when set to english --- .../gui/GuiFusionReactorController.java | 5 +++- .../client/gui/GuiFusionReactorFuel.java | 14 +++++------ .../client/gui/GuiFusionReactorHeat.java | 16 ++++++------ .../client/gui/GuiFusionReactorInfo.java | 1 + .../client/gui/GuiFusionReactorStats.java | 25 ++++++++++--------- .../client/gui/GuiIndustrialTurbine.java | 10 +++++--- .../client/gui/GuiTurbineStats.java | 19 +++++++------- .../fusion/FusionReactorMultiblockData.java | 2 +- .../registries/GeneratorsContainerTypes.java | 4 +-- .../mekanism/client/gui/GuiMatrixStats.java | 2 +- .../gui/GuiThermalEvaporationController.java | 2 +- .../client/gui/GuiThermoelectricBoiler.java | 13 +++++----- .../gui/machine/GuiChemicalOxidizer.java | 2 +- .../client/gui/machine/GuiElectricPump.java | 2 +- .../gui/machine/GuiFluidicPlenisher.java | 2 +- .../emi/recipe/FluidToFluidEmiRecipe.java | 2 +- .../machine/FluidToFluidRecipeCategory.java | 2 +- .../registries/MekanismContainerTypes.java | 2 +- 18 files changed, 67 insertions(+), 58 deletions(-) diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorController.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorController.java index 8e66d25e483..1d0803b38ea 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorController.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorController.java @@ -24,6 +24,8 @@ public class GuiFusionReactorController extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; + imageWidth += 10; + inventoryLabelX += 5; titleLabelY = 5; } @@ -52,7 +54,8 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - drawScrollingString(guiGraphics, MekanismLang.MULTIBLOCK_FORMED.translate(), 0, 16, TextAlignment.LEFT, titleTextColor(), 8, false); + renderInventoryText(guiGraphics); + drawScrollingString(guiGraphics, MekanismLang.MULTIBLOCK_FORMED.translate(), 0, 16, TextAlignment.LEFT, titleTextColor(), 13, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java index fdbfa559537..3cc09a321f5 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorFuel.java @@ -30,14 +30,14 @@ public GuiFusionReactorFuel(EmptyTileContainer tile.getMultiblock().deuteriumTank, () -> tile.getMultiblock().getChemicalTanks(null), GaugeType.SMALL, this, 25, 64)); - addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().fuelTank, () -> tile.getMultiblock().getChemicalTanks(null), GaugeType.STANDARD, this, 79, 50)); - addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().tritiumTank, () -> tile.getMultiblock().getChemicalTanks(null), GaugeType.SMALL, this, 133, 64)); - addRenderableWidget(new GuiProgress(() -> tile.getMultiblock().isBurning(), ProgressType.SMALL_RIGHT, this, 47, 76)); - addRenderableWidget(new GuiProgress(() -> tile.getMultiblock().isBurning(), ProgressType.SMALL_LEFT, this, 101, 76)); + addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().deuteriumTank, () -> tile.getMultiblock().getChemicalTanks(null), GaugeType.SMALL, this, 30, 64)); + addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().fuelTank, () -> tile.getMultiblock().getChemicalTanks(null), GaugeType.STANDARD, this, 84, 50)); + addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().tritiumTank, () -> tile.getMultiblock().getChemicalTanks(null), GaugeType.SMALL, this, 138, 64)); + addRenderableWidget(new GuiProgress(() -> tile.getMultiblock().isBurning(), ProgressType.SMALL_RIGHT, this, 52, 76)); + addRenderableWidget(new GuiProgress(() -> tile.getMultiblock().isBurning(), ProgressType.SMALL_LEFT, this, 106, 76)); addRenderableWidget(new GuiFusionReactorTab(this, tile, FusionReactorTab.HEAT)); addRenderableWidget(new GuiFusionReactorTab(this, tile, FusionReactorTab.STAT)); - injectionRateField = addRenderableWidget(new GuiTextField(this, 98, 115, 26, 11)); + injectionRateField = addRenderableWidget(new GuiTextField(this, 103, 115, 26, 11)); injectionRateField.setInputValidator(InputValidator.DIGIT) .setEnterHandler(this::setInjection) .setMaxLength(2); @@ -47,7 +47,7 @@ protected void addGuiElements() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_INJECTION_RATE.translate(tile.getMultiblock().getInjectionRate()), 0, 35, TextAlignment.CENTER, titleTextColor(), 16, false); - drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_EDIT_RATE.translate(), 4, 117, TextAlignment.RIGHT, titleTextColor(), 94, 2, false); + drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_EDIT_RATE.translate(), 4, 117, TextAlignment.RIGHT, titleTextColor(), 99, 2, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorHeat.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorHeat.java index 34d2c742cb4..fe9a8a4138c 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorHeat.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorHeat.java @@ -54,11 +54,11 @@ public double getScaledLevel() { public Component getText() { return GeneratorsLang.REACTOR_PLASMA.translate(MekanismUtils.getTemperatureDisplay(getLevel(), TemperatureUnit.KELVIN, true)); } - }, GaugeType.STANDARD, this, 7, 50)); + }, GaugeType.STANDARD, this, 12, 50)); addRenderableWidget(new GuiProgress(() -> { FusionReactorMultiblockData multiblock = tile.getMultiblock(); return multiblock.getLastPlasmaTemp() > multiblock.getLastCaseTemp(); - }, ProgressType.SMALL_RIGHT, this, 29, 76)); + }, ProgressType.SMALL_RIGHT, this, 34, 76)); addRenderableWidget(new GuiNumberGauge(new INumberInfoHandler() { @Override public TextureAtlasSprite getIcon() { @@ -79,15 +79,15 @@ public double getScaledLevel() { public Component getText() { return GeneratorsLang.REACTOR_CASE.translate(MekanismUtils.getTemperatureDisplay(getLevel(), TemperatureUnit.KELVIN, true)); } - }, GaugeType.STANDARD, this, 61, 50)); - addRenderableWidget(new GuiProgress(() -> tile.getMultiblock().getCaseTemp() > 0, ProgressType.SMALL_RIGHT, this, 83, 61)); + }, GaugeType.STANDARD, this, 66, 50)); + addRenderableWidget(new GuiProgress(() -> tile.getMultiblock().getCaseTemp() > 0, ProgressType.SMALL_RIGHT, this, 88, 61)); addRenderableWidget(new GuiProgress(() -> { FusionReactorMultiblockData multiblock = tile.getMultiblock(); return multiblock.getCaseTemp() > 0 && !multiblock.waterTank.isEmpty() && multiblock.steamTank.getStored() < multiblock.steamTank.getCapacity(); - }, ProgressType.SMALL_RIGHT, this, 83, 91)); - addRenderableWidget(new GuiFluidGauge(() -> tile.getMultiblock().waterTank, () -> tile.getFluidTanks(null), GaugeType.SMALL, this, 115, 84)); - addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().steamTank, () -> tile.getChemicalTanks(null), GaugeType.SMALL, this, 151, 84)); - addRenderableWidget(new GuiEnergyGauge(tile.getMultiblock().energyContainer, GaugeType.SMALL, this, 115, 46)); + }, ProgressType.SMALL_RIGHT, this, 88, 91)); + addRenderableWidget(new GuiFluidGauge(() -> tile.getMultiblock().waterTank, () -> tile.getFluidTanks(null), GaugeType.SMALL, this, 120, 84)); + addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().steamTank, () -> tile.getChemicalTanks(null), GaugeType.SMALL, this, 156, 84)); + addRenderableWidget(new GuiEnergyGauge(tile.getMultiblock().energyContainer, GaugeType.SMALL, this, 120, 46)); addRenderableWidget(new GuiFusionReactorTab(this, tile, FusionReactorTab.FUEL)); addRenderableWidget(new GuiFusionReactorTab(this, tile, FusionReactorTab.STAT)); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorInfo.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorInfo.java index d65b7db1fcc..49acc15fb27 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorInfo.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorInfo.java @@ -26,6 +26,7 @@ public abstract class GuiFusionReactorInfo extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); + imageWidth += 10; titleLabelY = 5; } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java index 701d926f222..34273405268 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiFusionReactorStats.java @@ -33,34 +33,35 @@ protected void addGuiElements() { protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { FusionReactorMultiblockData multiblock = tile.getMultiblock(); if (multiblock.isFormed()) { - int textArea = getXSize() - 8; + int indentation = 4; + int textArea = getXSize() - indentation; drawScrollingString(guiGraphics,GeneratorsLang.REACTOR_PASSIVE.translateColored(EnumColor.DARK_GREEN), 0, 26, TextAlignment.LEFT, titleTextColor(), 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MIN_INJECTION.translate(multiblock.getMinInjectionRate(false)), - 8, 36, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 36, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_IGNITION.translate(MekanismUtils.getTemperatureDisplay(multiblock.getIgnitionTemperature(false), TemperatureUnit.KELVIN, true)), - 8, 46, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 46, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MAX_PLASMA.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxPlasmaTemperature(false), TemperatureUnit.KELVIN, true)), - 8, 56, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 56, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MAX_CASING.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxCasingTemperature(false), TemperatureUnit.KELVIN, true)), - 8, 66, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 66, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_PASSIVE_RATE.translate(EnergyDisplay.of(multiblock.getPassiveGeneration(false, false))), - 8, 76, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 76, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics,GeneratorsLang.REACTOR_ACTIVE.translateColored(EnumColor.DARK_BLUE), 0, 92, TextAlignment.LEFT, titleTextColor(), 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MIN_INJECTION.translate(multiblock.getMinInjectionRate(true)), - 8, 102, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 102, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_IGNITION.translate(MekanismUtils.getTemperatureDisplay(multiblock.getIgnitionTemperature(true), TemperatureUnit.KELVIN, true)), - 8, 112, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 112, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MAX_PLASMA.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxPlasmaTemperature(true), TemperatureUnit.KELVIN, true)), - 8, 122, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 122, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_MAX_CASING.translate(MekanismUtils.getTemperatureDisplay(multiblock.getMaxCasingTemperature(true), TemperatureUnit.KELVIN, true)), - 8, 132, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 132, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_PASSIVE_RATE.translate(EnergyDisplay.of(multiblock.getPassiveGeneration(true, false))), - 8, 142, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 142, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); drawScrollingString(guiGraphics, GeneratorsLang.REACTOR_STEAM_PRODUCTION.translate(TextUtils.format(multiblock.getSteamPerTick(false))), - 8, 152, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); + indentation, 152, TextAlignment.LEFT, titleTextColor(), textArea, 6, false); } super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java b/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java index 3e54980046a..4866f6b869d 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiIndustrialTurbine.java @@ -35,6 +35,8 @@ public class GuiIndustrialTurbine extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); + imageWidth += 14; + inventoryLabelX += 7; inventoryLabelY += 2; titleLabelY = 5; dynamicSlots = true; @@ -43,7 +45,7 @@ public GuiIndustrialTurbine(MekanismTileContainer conta @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 50, 18, 112, 50, () -> { + addRenderableWidget(new GuiInnerScreen(this, 50, 18, 126, 50, () -> { List list = new ArrayList<>(); TurbineMultiblockData multiblock = tile.getMultiblock(); if (multiblock.isFormed()) { @@ -73,7 +75,7 @@ public double getLevel() { } return 1; } - }, 164, 16)); + }, 178, 16)); addRenderableWidget(new GuiVerticalRateBar(this, new IBarInfoHandler() { @Override public Component getTooltip() { @@ -112,7 +114,7 @@ public double getLevel() { return List.of(MekanismLang.STORING.translate(storing), GeneratorsLang.PRODUCING_AMOUNT.translate(producing)); })); Component warning = GeneratorsLang.TURBINE_DUMPING_STEAM_WARNING.translateColored(EnumColor.RED); - addRenderableWidget(new GuiGasMode(this, 159, 72, true, () -> tile.getMultiblock().dumpMode, tile.getBlockPos(), 0, + addRenderableWidget(new GuiGasMode(this, 173, 72, true, () -> tile.getMultiblock().dumpMode, tile.getBlockPos(), 0, TooltipUtils.create(GeneratorsLang.TURBINE_DUMPING_EXCESS_STEAM.translate(), warning), TooltipUtils.create(GeneratorsLang.TURBINE_DUMPING_STEAM.translate(), warning))); } @@ -120,7 +122,7 @@ public double getLevel() { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { renderTitleText(guiGraphics); - renderInventoryText(guiGraphics, 85); + renderInventoryText(guiGraphics, 99); super.drawForegroundText(guiGraphics, mouseX, mouseY); } } \ No newline at end of file diff --git a/src/generators/java/mekanism/generators/client/gui/GuiTurbineStats.java b/src/generators/java/mekanism/generators/client/gui/GuiTurbineStats.java index 2813a093137..3a34d982f45 100644 --- a/src/generators/java/mekanism/generators/client/gui/GuiTurbineStats.java +++ b/src/generators/java/mekanism/generators/client/gui/GuiTurbineStats.java @@ -26,6 +26,7 @@ public class GuiTurbineStats extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); + imageWidth += 14; } @Override @@ -60,21 +61,21 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int lowerVolume = multiblock.lowerVolume; int dispersers = multiblock.getDispersers(); int vents = multiblock.vents; - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_TANK_VOLUME.translate(lowerVolume), 0, 26, TextAlignment.LEFT, titleTextColor(), 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_TANK_VOLUME.translate(lowerVolume), 0, 26, TextAlignment.LEFT, titleTextColor(), 6, false); boolean dispersersLimiting = lowerVolume * dispersers * MekanismGeneratorsConfig.generators.turbineDisperserChemicalFlow.get() < vents * MekanismGeneratorsConfig.generators.turbineVentChemicalFlow.get(); boolean ventsLimiting = lowerVolume * dispersers * MekanismGeneratorsConfig.generators.turbineDisperserChemicalFlow.get() > vents * MekanismGeneratorsConfig.generators.turbineVentChemicalFlow.get(); - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_STEAM_FLOW.translate(), 0, 40, TextAlignment.LEFT, subheadingTextColor(), 8, false); - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_DISPERSERS.translate(dispersers, dispersersLimiting ? limiting : ""), 6, 49, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_VENTS.translate(vents, ventsLimiting ? limiting : ""), 6, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_STEAM_FLOW.translate(), 0, 40, TextAlignment.LEFT, subheadingTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_DISPERSERS.translate(dispersers, dispersersLimiting ? limiting : ""), 4, 49, TextAlignment.LEFT, titleTextColor(), getXSize() - 4, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_VENTS.translate(vents, ventsLimiting ? limiting : ""), 4, 58, TextAlignment.LEFT, titleTextColor(), getXSize() - 4, 6, false); int coils = multiblock.coils; int blades = multiblock.blades; - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_PRODUCTION.translate(), 0, 72, TextAlignment.LEFT, subheadingTextColor(), 8, false); - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_BLADES.translate(blades, coils * 4 > blades ? limiting : ""), 6, 81, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_COILS.translate(coils, coils * 4 < blades ? limiting : ""), 6, 90, TextAlignment.LEFT, titleTextColor(), getXSize() - 6, 8, false); - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_MAX_PRODUCTION.translate(EnergyDisplay.of(multiblock.getMaxProduction())), 0, 104, TextAlignment.LEFT, titleTextColor(), 8, false); - drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_MAX_WATER_OUTPUT.translate(TextUtils.format(multiblock.getMaxWaterOutput())), 0, 113, TextAlignment.LEFT, titleTextColor(), 8, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_PRODUCTION.translate(), 0, 72, TextAlignment.LEFT, subheadingTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_BLADES.translate(blades, coils * 4 > blades ? limiting : ""), 4, 81, TextAlignment.LEFT, titleTextColor(), getXSize() - 4, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_COILS.translate(coils, coils * 4 < blades ? limiting : ""), 4, 90, TextAlignment.LEFT, titleTextColor(), getXSize() - 4, 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_MAX_PRODUCTION.translate(EnergyDisplay.of(multiblock.getMaxProduction())), 0, 104, TextAlignment.LEFT, titleTextColor(), 6, false); + drawScrollingString(guiGraphics, GeneratorsLang.TURBINE_MAX_WATER_OUTPUT.translate(TextUtils.format(multiblock.getMaxWaterOutput())), 0, 113, TextAlignment.LEFT, titleTextColor(), 6, false); } super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/generators/java/mekanism/generators/common/content/fusion/FusionReactorMultiblockData.java b/src/generators/java/mekanism/generators/common/content/fusion/FusionReactorMultiblockData.java index 044ee0b0d23..6582d6054e8 100644 --- a/src/generators/java/mekanism/generators/common/content/fusion/FusionReactorMultiblockData.java +++ b/src/generators/java/mekanism/generators/common/content/fusion/FusionReactorMultiblockData.java @@ -155,7 +155,7 @@ public FusionReactorMultiblockData(TileEntityFusionReactorBlock tile) { energyContainers.add(energyContainer = VariableCapacityEnergyContainer.output(MekanismGeneratorsConfig.generators.fusionEnergyCapacity, this)); heatCapacitors.add(heatCapacitor = VariableHeatCapacitor.create(caseHeatCapacity, FusionReactorMultiblockData::getInverseConductionCoefficient, () -> inverseInsulation, () -> biomeAmbientTemp, this)); - inventorySlots.add(reactorSlot = ReactorInventorySlot.at(stack -> stack.getItem() instanceof ItemHohlraum, this, 80, 39)); + inventorySlots.add(reactorSlot = ReactorInventorySlot.at(stack -> stack.getItem() instanceof ItemHohlraum, this, 85, 39)); } @Override diff --git a/src/generators/java/mekanism/generators/common/registries/GeneratorsContainerTypes.java b/src/generators/java/mekanism/generators/common/registries/GeneratorsContainerTypes.java index d061353f3e3..07590e69b95 100644 --- a/src/generators/java/mekanism/generators/common/registries/GeneratorsContainerTypes.java +++ b/src/generators/java/mekanism/generators/common/registries/GeneratorsContainerTypes.java @@ -27,11 +27,11 @@ private GeneratorsContainerTypes() { public static final ContainerTypeRegistryObject> BIO_GENERATOR = CONTAINER_TYPES.custom(GeneratorsBlocks.BIO_GENERATOR, TileEntityBioGenerator.class).armorSideBar(-20, 11, 0).build(); public static final ContainerTypeRegistryObject> GAS_BURNING_GENERATOR = CONTAINER_TYPES.custom(GeneratorsBlocks.GAS_BURNING_GENERATOR, TileEntityGasGenerator.class).armorSideBar(-20, 11, 0).build(); public static final ContainerTypeRegistryObject> HEAT_GENERATOR = CONTAINER_TYPES.custom(GeneratorsBlocks.HEAT_GENERATOR, TileEntityHeatGenerator.class).armorSideBar(-20, 11, 0).build(); - public static final ContainerTypeRegistryObject> INDUSTRIAL_TURBINE = CONTAINER_TYPES.register("industrial_turbine", TileEntityTurbineCasing.class); + public static final ContainerTypeRegistryObject> INDUSTRIAL_TURBINE = CONTAINER_TYPES.custom("industrial_turbine", TileEntityTurbineCasing.class).offset(7, 0).build(); public static final ContainerTypeRegistryObject> FISSION_REACTOR = CONTAINER_TYPES.custom("fission_reactor", TileEntityFissionReactorCasing.class).offset(10, 91).build(); public static final ContainerTypeRegistryObject> FISSION_REACTOR_STATS = CONTAINER_TYPES.registerEmpty("fission_reactor_stats", TileEntityFissionReactorCasing.class); public static final ContainerTypeRegistryObject> FISSION_REACTOR_LOGIC_ADAPTER = CONTAINER_TYPES.registerEmpty(GeneratorsBlocks.FISSION_REACTOR_LOGIC_ADAPTER, TileEntityFissionReactorLogicAdapter.class); - public static final ContainerTypeRegistryObject> FUSION_REACTOR_CONTROLLER = CONTAINER_TYPES.register(GeneratorsBlocks.FUSION_REACTOR_CONTROLLER, TileEntityFusionReactorController.class); + public static final ContainerTypeRegistryObject> FUSION_REACTOR_CONTROLLER = CONTAINER_TYPES.custom(GeneratorsBlocks.FUSION_REACTOR_CONTROLLER, TileEntityFusionReactorController.class).offset(5, 0).build(); public static final ContainerTypeRegistryObject> FUSION_REACTOR_FUEL = CONTAINER_TYPES.registerEmpty("fusion_reactor_fuel", TileEntityFusionReactorController.class); public static final ContainerTypeRegistryObject> FUSION_REACTOR_HEAT = CONTAINER_TYPES.registerEmpty("fusion_reactor_heat", TileEntityFusionReactorController.class); public static final ContainerTypeRegistryObject> FUSION_REACTOR_LOGIC_ADAPTER = CONTAINER_TYPES.registerEmpty(GeneratorsBlocks.FUSION_REACTOR_LOGIC_ADAPTER, TileEntityFusionReactorLogicAdapter.class); diff --git a/src/main/java/mekanism/client/gui/GuiMatrixStats.java b/src/main/java/mekanism/client/gui/GuiMatrixStats.java index 0d9190af6d6..6e9a601f715 100644 --- a/src/main/java/mekanism/client/gui/GuiMatrixStats.java +++ b/src/main/java/mekanism/client/gui/GuiMatrixStats.java @@ -24,7 +24,7 @@ public class GuiMatrixStats extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); - titleLabelY -= 1; + titleLabelY = 5; } @Override diff --git a/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java b/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java index 972b4c85349..c4ccbb16e9e 100644 --- a/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java +++ b/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java @@ -43,7 +43,7 @@ protected void addGuiElements() { return List.of(MekanismLang.MULTIBLOCK_FORMED.translate(), MekanismLang.EVAPORATION_HEIGHT.translate(multiblock.height()), MekanismLang.TEMPERATURE.translate(MekanismUtils.getTemperatureDisplay(multiblock.getTemperature(), TemperatureUnit.KELVIN, true)), MekanismLang.FLUID_PRODUCTION.translate(Math.round(multiblock.lastGain * 100D) / 100D)); - }).clearSpacing().recipeViewerCategories(RecipeViewerRecipeType.EVAPORATING)); + }).padding(3).clearSpacing().recipeViewerCategories(RecipeViewerRecipeType.EVAPORATING)); addRenderableWidget(new GuiDownArrow(this, 32, 39)); addRenderableWidget(new GuiDownArrow(this, 136, 39)); addRenderableWidget(new GuiHorizontalRateBar(this, new IBarInfoHandler() { diff --git a/src/main/java/mekanism/client/gui/GuiThermoelectricBoiler.java b/src/main/java/mekanism/client/gui/GuiThermoelectricBoiler.java index 14cc9daa77f..0de135543a0 100644 --- a/src/main/java/mekanism/client/gui/GuiThermoelectricBoiler.java +++ b/src/main/java/mekanism/client/gui/GuiThermoelectricBoiler.java @@ -33,7 +33,8 @@ public class GuiThermoelectricBoiler extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; - imageWidth += 40; + imageWidth += 42; + inventoryLabelX += 21; inventoryLabelY += 2; titleLabelY = 5; } @@ -41,11 +42,11 @@ public GuiThermoelectricBoiler(MekanismTileContainer con @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 60, 23, 96, 40, () -> { + addRenderableWidget(new GuiInnerScreen(this, 54, 23, 110, 40, () -> { BoilerMultiblockData multiblock = tile.getMultiblock(); return List.of(MekanismLang.TEMPERATURE.translate(MekanismUtils.getTemperatureDisplay(multiblock.getTotalTemperature(), TemperatureUnit.KELVIN, true)), MekanismLang.BOIL_RATE.translate(TextUtils.format(multiblock.lastBoilRate)), MekanismLang.MAX_BOIL_RATE.translate(TextUtils.format(multiblock.lastMaxBoil))); - }).recipeViewerCategories(RecipeViewerRecipeType.BOILER)); + }).padding(3).recipeViewerCategories(RecipeViewerRecipeType.BOILER)); addRenderableWidget(new GuiBoilerTab(this, tile, BoilerTab.STAT)); addRenderableWidget(new GuiVerticalRateBar(this, new IBarInfoHandler() { @Override @@ -71,14 +72,14 @@ public double getLevel() { return Math.min(1, multiblock.lastMaxBoil * HeatUtils.getWaterThermalEnthalpy() / (multiblock.superheatingElements * MekanismConfig.general.superheatingHeatTransfer.get())); } - }, 164, 13)); + }, 166, 13)); addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().superheatedCoolantTank, () -> tile.getMultiblock().getChemicalTanks((Direction) null), GaugeType.STANDARD, this, 6, 13) .setLabel(MekanismLang.BOILER_HEATED_COOLANT_TANK.translateColored(EnumColor.ORANGE))); addRenderableWidget(new GuiFluidGauge(() -> tile.getMultiblock().waterTank, () -> tile.getMultiblock().getFluidTanks(null), GaugeType.STANDARD, this, 26, 13) .setLabel(MekanismLang.BOILER_WATER_TANK.translateColored(EnumColor.INDIGO))); - addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().steamTank, () -> tile.getMultiblock().getChemicalTanks((Direction) null), GaugeType.STANDARD, this, 172, 13) + addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().steamTank, () -> tile.getMultiblock().getChemicalTanks((Direction) null), GaugeType.STANDARD, this, 174, 13) .setLabel(MekanismLang.BOILER_STEAM_TANK.translateColored(EnumColor.GRAY))); - addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().cooledCoolantTank, () -> tile.getMultiblock().getChemicalTanks((Direction) null), GaugeType.STANDARD, this, 192, 13) + addRenderableWidget(new GuiChemicalGauge(() -> tile.getMultiblock().cooledCoolantTank, () -> tile.getMultiblock().getChemicalTanks((Direction) null), GaugeType.STANDARD, this, 194, 13) .setLabel(MekanismLang.BOILER_COOLANT_TANK.translateColored(EnumColor.AQUA))); addRenderableWidget(new GuiHeatTab(this, () -> { Component environment = MekanismUtils.getTemperatureDisplay(tile.getMultiblock().lastEnvironmentLoss, TemperatureUnit.KELVIN, false); diff --git a/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java b/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java index 14a4f357f29..8f01adc036f 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiChemicalOxidizer.java @@ -24,7 +24,7 @@ public class GuiChemicalOxidizer extends GuiConfigurableTile container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; - titleLabelY -= 1; + titleLabelY = 5; } @Override diff --git a/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java b/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java index a98838b9c33..747b471504e 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java +++ b/src/main/java/mekanism/client/gui/machine/GuiElectricPump.java @@ -26,7 +26,7 @@ public class GuiElectricPump extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); - titleLabelY -= 1; + titleLabelY = 5; inventoryLabelY += 2; dynamicSlots = true; } diff --git a/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java b/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java index 7668ee9d435..7b73cca9463 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java +++ b/src/main/java/mekanism/client/gui/machine/GuiFluidicPlenisher.java @@ -27,7 +27,7 @@ public class GuiFluidicPlenisher extends GuiMekanismTile container, Inventory inv, Component title) { super(container, inv, title); - titleLabelY -= 1; + titleLabelY = 5; inventoryLabelY += 2; dynamicSlots = true; } diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java index 8ad86d8fb5e..cdd8259215e 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java @@ -32,7 +32,7 @@ public void addWidgets(WidgetHolder widgetHolder) { MekanismLang.MULTIBLOCK_FORMED.translate(), MekanismLang.EVAPORATION_HEIGHT.translate(EvaporationMultiblockData.MAX_HEIGHT), MekanismLang.TEMPERATURE.translate(MekanismUtils.getTemperatureDisplay(HeatAPI.AMBIENT_TEMP, TemperatureUnit.KELVIN, true)), MekanismLang.FLUID_PRODUCTION.translate(0.0)) - ).clearSpacing()); + ).padding(3).clearSpacing()); addElement(widgetHolder, new GuiDownArrow(this, 32, 39)); addElement(widgetHolder, new GuiDownArrow(this, 136, 39)); addElement(widgetHolder, new GuiHorizontalRateBar(this, RecipeViewerUtils.FULL_BAR, 48, 63)); diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java index 544a62f4142..cb22fd4660b 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java @@ -35,7 +35,7 @@ public FluidToFluidRecipeCategory(IGuiHelper helper, IRecipeViewerRecipeType> FLUID_TANK = CONTAINER_TYPES.custom("fluid_tank", TileEntityFluidTank.class).armorSideBar().build(); public static final ContainerTypeRegistryObject> ENERGY_CUBE = CONTAINER_TYPES.custom("energy_cube", TileEntityEnergyCube.class).armorSideBar(180, 41, 0).build(); public static final ContainerTypeRegistryObject> INDUCTION_MATRIX = CONTAINER_TYPES.custom("induction_matrix", TileEntityInductionCasing.class).armorSideBar(-20, 41, 0).build(); - public static final ContainerTypeRegistryObject> THERMOELECTRIC_BOILER = CONTAINER_TYPES.custom("thermoelectric_boiler", TileEntityBoilerCasing.class).offset(20, 0).build(); + public static final ContainerTypeRegistryObject> THERMOELECTRIC_BOILER = CONTAINER_TYPES.custom("thermoelectric_boiler", TileEntityBoilerCasing.class).offset(21, 0).build(); public static final ContainerTypeRegistryObject PERSONAL_STORAGE_ITEM = CONTAINER_TYPES.registerMenu("personal_storage_item", () -> MekanismItemContainerType.item(ItemBlockPersonalStorage.class, PersonalStorageItemContainer::new)); public static final ContainerTypeRegistryObject> PERSONAL_STORAGE_BLOCK = CONTAINER_TYPES.custom("personal_storage_block", TileEntityPersonalStorage.class).offset(0, 56).build(); public static final ContainerTypeRegistryObject> QIO_FREQUENCY_SELECT_TILE = CONTAINER_TYPES.registerEmpty("qio_frequency_select_tile", TileEntityQIOComponent.class); From cfcba1fb4917771c2451f8631cc514b5cf36fa4a Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Tue, 24 Sep 2024 16:35:14 -0500 Subject: [PATCH 08/17] Fix dropdowns not respecting icons for max text width, and make it so that the dictionary's dropdown doesn't have to have scrolling text in english (currently still does for BE Types) --- .../java/mekanism/client/gui/GuiMekanism.java | 4 +- .../client/gui/element/GuiDropdown.java | 37 +++++++++++++------ .../client/gui/item/GuiDictionary.java | 2 +- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/java/mekanism/client/gui/GuiMekanism.java b/src/main/java/mekanism/client/gui/GuiMekanism.java index 9d30da07e6d..5dd6cb6e365 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanism.java +++ b/src/main/java/mekanism/client/gui/GuiMekanism.java @@ -196,8 +196,8 @@ protected void renderInventoryTextAndOther(GuiGraphics guiGraphics, Component ri } protected void renderInventoryTextAndOther(GuiGraphics guiGraphics, Component rightAlignedText, int rightEndPad) { - drawScrollingString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, TextAlignment.LEFT, titleTextColor(), 56, 0, false); - int rightStart = inventoryLabelX + 54; + drawScrollingString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, TextAlignment.LEFT, titleTextColor(), 54, 0, false); + int rightStart = inventoryLabelX + 52; drawScrollingString(guiGraphics, rightAlignedText, rightStart, inventoryLabelY, TextAlignment.RIGHT, titleTextColor(), getXSize() - rightStart - rightEndPad, 6, false); } diff --git a/src/main/java/mekanism/client/gui/element/GuiDropdown.java b/src/main/java/mekanism/client/gui/element/GuiDropdown.java index c626b7e4acf..a8174c84734 100644 --- a/src/main/java/mekanism/client/gui/element/GuiDropdown.java +++ b/src/main/java/mekanism/client/gui/element/GuiDropdown.java @@ -18,6 +18,11 @@ public class GuiDropdown & IDropdownEnum> extends GuiTexturedElement { + private static final int ELEMENT_HEIGHT = 12; + private static final int ICON_SIZE = 6; + //one for the screen border, one for the hover border, and one more to have a spot between the hover border and the icon + private static final int ICON_OFFSET = ICON_SIZE + 3; + private final Map typeTooltips; private final Consumer handler; private final Supplier curType; @@ -29,7 +34,7 @@ public class GuiDropdown & IDropdownEnum> extends private boolean isOpen; public GuiDropdown(IGuiWrapper gui, int x, int y, int width, Class enumClass, Supplier curType, Consumer handler) { - super(GuiInnerScreen.SCREEN, gui, x, y, width, 12); + super(GuiInnerScreen.SCREEN, gui, x, y, width, ELEMENT_HEIGHT); this.curType = curType; this.handler = handler; this.options = enumClass.getEnumConstants(); @@ -51,7 +56,10 @@ public void onRelease(double mouseX, double mouseY) { boolean wasDragging = isDragging(); super.onRelease(mouseX, mouseY); if (wasDragging && isOpen && mouseY > getY() + 11) { - handler.accept(options[getHoveredIndex(mouseX, mouseY)]); + int hoveredIndex = getHoveredIndex(mouseX, mouseY); + if (hoveredIndex != -1) { + handler.accept(options[hoveredIndex]); + } setOpen(false); } } @@ -59,15 +67,20 @@ public void onRelease(double mouseX, double mouseY) { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - TYPE current = curType.get(); - drawScaledScrollingString(guiGraphics, current.getShortName(), 0, 2, TextAlignment.LEFT, screenTextColor(), 4, false, 0.8F); + drawOptionName(guiGraphics, curType.get(), 2); if (isOpen) { for (int i = 0; i < options.length; i++) { - drawScaledScrollingString(guiGraphics, options[i].getShortName(), 0, 11 + 2 + 10 * i, TextAlignment.LEFT, screenTextColor(), 4, false, 0.8F); + drawOptionName(guiGraphics, options[i], ELEMENT_HEIGHT + 1 + 10 * i); } } } + private void drawOptionName(GuiGraphics guiGraphics, TYPE option, int y) { + //Note: We add one for if we are rendering with an icon so that we allow going closer to the icon + int maxWidth = option.getIcon() == null ? getWidth() : getWidth() - ICON_OFFSET + 1; + drawScaledScrollingString(guiGraphics, option.getShortName(), 0, y, TextAlignment.LEFT, screenTextColor(), maxWidth, 10, 3, false, 0.8F); + } + @Override public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks); @@ -75,19 +88,19 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou int index = getHoveredIndex(mouseX, mouseY); if (index != -1) { - GuiUtils.drawOutline(guiGraphics, relativeX + 1, relativeY + 12 + index * 10, width - 2, 10, screenTextColor()); + GuiUtils.drawOutline(guiGraphics, relativeX + 1, relativeY + ELEMENT_HEIGHT + index * 10, width - 2, 10, screenTextColor()); } TYPE current = curType.get(); if (current.getIcon() != null) { - guiGraphics.blit(current.getIcon(), relativeX + width - 9, relativeY + 3, 0, 0, 6, 6, 6, 6); + guiGraphics.blit(current.getIcon(), relativeX + width - ICON_OFFSET, relativeY + 3, 0, 0, ICON_SIZE, ICON_SIZE, ICON_SIZE, ICON_SIZE); } if (isOpen) { for (int i = 0; i < options.length; i++) { ResourceLocation icon = options[i].getIcon(); if (icon != null) { - guiGraphics.blit(icon, relativeX + width - 9, relativeY + 12 + 2 + 10 * i, 0, 0, 6, 6, 6, 6); + guiGraphics.blit(icon, relativeX + width - ICON_OFFSET, relativeY + ELEMENT_HEIGHT + 2 + 10 * i, 0, 0, ICON_SIZE, ICON_SIZE, ICON_SIZE, ICON_SIZE); } } } @@ -104,7 +117,7 @@ public void updateTooltip(int mouseX, int mouseY) { int index = getHoveredIndex(mouseX, mouseY); if (index != -1) { Tooltip text = typeTooltips.computeIfAbsent(options[index], t -> TooltipUtils.create(t.getTooltip())); - cachedTooltipRect = new ScreenRectangle(getX() + 1, getY() + 12 + index * 10, width - 2, 10); + cachedTooltipRect = new ScreenRectangle(getX() + 1, getY() + ELEMENT_HEIGHT + index * 10, width - 2, 10); setTooltip(text); } else { clearTooltip(); @@ -121,12 +134,12 @@ private int getHoveredIndex(double mouseX, double mouseY) { private void setOpen(boolean open) { if (isOpen != open) { - if (open) { + isOpen = open; + if (isOpen) { height += options.length * 10 + 1; } else { - height -= options.length * 10 + 1; + height = ELEMENT_HEIGHT; } } - isOpen = open; } } diff --git a/src/main/java/mekanism/client/gui/item/GuiDictionary.java b/src/main/java/mekanism/client/gui/item/GuiDictionary.java index 4a2c2961387..bcc4dfad56f 100644 --- a/src/main/java/mekanism/client/gui/item/GuiDictionary.java +++ b/src/main/java/mekanism/client/gui/item/GuiDictionary.java @@ -42,7 +42,7 @@ protected void addGuiElements() { scrollList = addRenderableWidget(new GuiTextScrollList(this, 7, 29, 162, 42)); //TODO: Ideally we would eventually replace this with some sort of tab system as it would probably look better // and could then be limited to just the tags the target supports - dropdown = addRenderableWidget(new GuiDropdown<>(this, 124, 73, 45, DictionaryTagType.class, () -> currentType, this::setCurrentType)); + dropdown = addRenderableWidget(new GuiDropdown<>(this, 114, 73, 55, DictionaryTagType.class, () -> currentType, this::setCurrentType)); target = addRenderableWidget(new GuiDictionaryTarget(this, 6, 6, this::updateScrollList)); } From dad6311865ca4f6ec13128ca7cc610a0585a780a Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Tue, 24 Sep 2024 17:37:01 -0500 Subject: [PATCH 09/17] Continued work on making it so our GUIs don't have to use scrolling text for default configs in english --- .../client/gui/GuiModificationStation.java | 6 +++--- .../mekanism/client/gui/GuiModuleTweaker.java | 12 ++++++------ .../custom/module/GuiModuleScreen.java | 2 +- .../element/scroll/GuiModuleScrollList.java | 8 ++++---- .../client/gui/item/GuiSeismicReader.java | 18 +++++++++--------- .../mekanism/client/gui/machine/GuiPRC.java | 17 ++++++++--------- .../recipe/PressurizedReactionEmiRecipe.java | 16 ++++++++-------- .../PressurizedReactionRecipeCategory.java | 16 ++++++++-------- .../type/RecipeViewerRecipeType.java | 2 +- .../container/ModuleTweakerContainer.java | 2 +- .../registries/MekanismContainerTypes.java | 2 +- .../tile/TileEntityModificationStation.java | 2 +- .../TileEntityPressurizedReactionChamber.java | 6 +++--- .../assets/mekanism/gui/module_selection.png | Bin 223 -> 224 bytes 14 files changed, 54 insertions(+), 55 deletions(-) diff --git a/src/main/java/mekanism/client/gui/GuiModificationStation.java b/src/main/java/mekanism/client/gui/GuiModificationStation.java index 95237c20e2e..6ac89868d8d 100644 --- a/src/main/java/mekanism/client/gui/GuiModificationStation.java +++ b/src/main/java/mekanism/client/gui/GuiModificationStation.java @@ -35,16 +35,16 @@ public GuiModificationStation(MekanismTileContainer { + removeButton = addRenderableWidget(new TranslationButton(this, 28, 96, 120, 17, MekanismLang.BUTTON_REMOVE, (element, mouseX, mouseY) -> { GuiModificationStation gui = (GuiModificationStation) element.gui(); return PacketUtils.sendToServer(new PacketRemoveModule(gui.tile.getBlockPos(), gui.selectedModule.getData(), Screen.hasShiftDown())); })).setTooltip(MekanismLang.REMOVE_ALL_MODULES_TOOLTIP); removeButton.active = selectedModule != null; - addRenderableWidget(new GuiModuleScrollList(this, 34, 20, 108, 74, () -> tile.containerSlot.getStack().copy(), this::onModuleSelected)); + addRenderableWidget(new GuiModuleScrollList(this, 28, 20, 74, () -> tile.containerSlot.getStack().copy(), this::onModuleSelected)); } private void onModuleSelected(@Nullable IModule module) { diff --git a/src/main/java/mekanism/client/gui/GuiModuleTweaker.java b/src/main/java/mekanism/client/gui/GuiModuleTweaker.java index 33dc8c4fa13..c63abe2bba6 100644 --- a/src/main/java/mekanism/client/gui/GuiModuleTweaker.java +++ b/src/main/java/mekanism/client/gui/GuiModuleTweaker.java @@ -61,7 +61,7 @@ public GuiModuleTweaker(ModuleTweakerContainer container, Inventory inv, Compone } } }; - imageWidth = 248; + imageWidth = 266; imageHeight += 20; } @@ -69,10 +69,10 @@ public GuiModuleTweaker(ModuleTweakerContainer container, Inventory inv, Compone protected void addGuiElements() { super.addGuiElements(); Supplier itemSupplier = () -> getStack(selected); - moduleScreen = addRenderableWidget(new GuiModuleScreen(this, 138, 20, itemSupplier, saveCallback, armorPreview)); - scrollList = addRenderableWidget(new GuiModuleScrollList(this, 30, 20, 108, 116, itemSupplier, this::onModuleSelected)); - addRenderableWidget(new GuiElementHolder(this, 30, 136, 108, 18)); - optionsButton = addRenderableWidget(new TranslationButton(this, 31, 137, 106, 16, MekanismLang.BUTTON_OPTIONS, (element, mouseX, mouseY) -> { + addRenderableWidget(new GuiElementHolder(this, 30, 136, 120, 18)); + moduleScreen = addRenderableWidget(new GuiModuleScreen(this, 150, 20, itemSupplier, saveCallback, armorPreview)); + scrollList = addRenderableWidget(new GuiModuleScrollList(this, 30, 20, 116, itemSupplier, this::onModuleSelected)); + optionsButton = addRenderableWidget(new TranslationButton(this, 31, 137, 118, 16, MekanismLang.BUTTON_OPTIONS, (element, mouseX, mouseY) -> { ((GuiModuleTweaker) element.gui()).openOptions(); return true; })); @@ -97,7 +97,7 @@ private void onModuleSelected(Module module) { } private void openOptions() { - addWindow(new GuiMekaSuitHelmetOptions(this, imageWidth / 2 - 140 / 2, imageHeight / 2 - 90 / 2)); + addWindow(new GuiMekaSuitHelmetOptions(this, (imageWidth - 140) / 2, (imageHeight - 140) / 2)); } @Override diff --git a/src/main/java/mekanism/client/gui/element/custom/module/GuiModuleScreen.java b/src/main/java/mekanism/client/gui/element/custom/module/GuiModuleScreen.java index 59fc3ef1ef5..5e3ab085866 100644 --- a/src/main/java/mekanism/client/gui/element/custom/module/GuiModuleScreen.java +++ b/src/main/java/mekanism/client/gui/element/custom/module/GuiModuleScreen.java @@ -43,7 +43,7 @@ public class GuiModuleScreen extends GuiScrollableElement { private int maxElements; public GuiModuleScreen(IGuiWrapper gui, int x, int y, Supplier itemSupplier, Consumer> saveCallback, ArmorPreview armorPreview) { - this(gui, x, y, 102, 134, itemSupplier, saveCallback, armorPreview); + this(gui, x, y, 108, 134, itemSupplier, saveCallback, armorPreview); } private GuiModuleScreen(IGuiWrapper gui, int x, int y, int width, int height, Supplier itemSupplier, Consumer> saveCallback, ArmorPreview armorPreview) { diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java b/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java index 95061846d12..d4b93413949 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java @@ -32,7 +32,7 @@ public class GuiModuleScrollList extends GuiScrollList { private static final ResourceLocation MODULE_SELECTION = MekanismUtils.getResource(ResourceType.GUI, "module_selection.png"); - private static final int TEXTURE_WIDTH = 100; + private static final int TEXTURE_WIDTH = 112; private static final int TEXTURE_HEIGHT = 36; private final Consumer> callback; @@ -51,8 +51,8 @@ public class GuiModuleScrollList extends GuiScrollList { @Nullable private ScreenRectangle cachedTooltipRect; - public GuiModuleScrollList(IGuiWrapper gui, int x, int y, int width, int height, Supplier itemSupplier, Consumer> callback) { - super(gui, x, y, width, height, TEXTURE_HEIGHT / 3, GuiElementHolder.HOLDER, GuiElementHolder.HOLDER_SIZE); + public GuiModuleScrollList(IGuiWrapper gui, int x, int y, int height, Supplier itemSupplier, Consumer> callback) { + super(gui, x, y, TEXTURE_WIDTH + 8, height, TEXTURE_HEIGHT / 3, GuiElementHolder.HOLDER, GuiElementHolder.HOLDER_SIZE); this.itemSupplier = itemSupplier; this.callback = callback; updateItemAndList(itemSupplier.get()); @@ -136,7 +136,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { if (instance != null) { boolean enabled = instance.isEnabled(); int color = module.isExclusive(ExclusiveFlag.ANY) ? (enabled ? 0x635BD4 : 0x2E2A69) : (enabled ? titleTextColor() : 0x5E1D1D); - drawScaledScrollingString(guiGraphics, TextComponentUtil.build(module), 12, 3 + multipliedElement, TextAlignment.LEFT, color, barXShift - 14, 2, false, 0.7F); + drawScaledScrollingString(guiGraphics, TextComponentUtil.build(module), 11, 3 + multipliedElement, TextAlignment.LEFT, color, barXShift - 12, 2, false, 0.7F); } } }); diff --git a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java index e6c3e7c1485..89d03d4e1a3 100644 --- a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java +++ b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java @@ -51,7 +51,7 @@ public class GuiSeismicReader extends GuiMekanism { public GuiSeismicReader(SeismicReaderContainer container, Inventory inv, Component title) { super(container, inv, title); - imageWidth = 147; + imageWidth = 150; imageHeight = 182; Player player = inv.player; Level level = player.level(); @@ -100,7 +100,7 @@ public GuiSeismicReader(SeismicReaderContainer container, Inventory inv, Compone @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 7, 11, 63, 50, () -> { + addRenderableWidget(new GuiInnerScreen(this, 5, 11, 69, 50, () -> { // Get the name from the stack and render it int currentLayer = getCurrentLayer(); if (currentLayer >= 0) { @@ -118,13 +118,13 @@ protected void addGuiElements() { return text; } return Collections.emptyList(); - })); - addRenderableWidget(new GuiInnerScreen(this, 74, 11, 51, 160)); - scrollBar = addRenderableWidget(new GuiScrollBar(this, 126, 25, 132, blockList::size, () -> 1)); - addRenderableWidget(new GuiArrowSelection(this, 76, 81, () -> TextComponentUtil.build(minHeight + getCurrentLayer()))); - upButton = addRenderableWidget(new MekanismImageButton(this, 126, 11, 14, + }).padding(3)); + addRenderableWidget(new GuiInnerScreen(this, 77, 11, 51, 160)); + scrollBar = addRenderableWidget(new GuiScrollBar(this, 129, 25, 132, blockList::size, () -> 1)); + addRenderableWidget(new GuiArrowSelection(this, 79, 81, () -> TextComponentUtil.build(minHeight + getCurrentLayer()))); + upButton = addRenderableWidget(new MekanismImageButton(this, 129, 11, 14, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "up.png"), (element, mouseX, mouseY) -> scrollBar.adjustScroll(1))); - downButton = addRenderableWidget(new MekanismImageButton(this, 126, 157, 14, + downButton = addRenderableWidget(new MekanismImageButton(this, 129, 157, 14, MekanismUtils.getResource(ResourceType.GUI_BUTTON, "down.png"), (element, mouseX, mouseY) -> scrollBar.adjustScroll(-1))); updateEnabledButtons(); } @@ -157,7 +157,7 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, if (info.renderTarget == null) { continue; } - int renderX = 92; + int renderX = 95; int renderY = 146 - 16 * i; if (i == 4) { info.render(guiGraphics, renderX, renderY); diff --git a/src/main/java/mekanism/client/gui/machine/GuiPRC.java b/src/main/java/mekanism/client/gui/machine/GuiPRC.java index 1dc93ab5a78..3e31e769d04 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiPRC.java +++ b/src/main/java/mekanism/client/gui/machine/GuiPRC.java @@ -2,7 +2,6 @@ import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.GuiConfigurableTile; -import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.bar.GuiVerticalPowerBar; import mekanism.client.gui.element.gauge.GaugeType; import mekanism.client.gui.element.gauge.GuiChemicalGauge; @@ -20,32 +19,32 @@ public class GuiPRC extends GuiConfigurableTile> { - private GuiElement secondGauge; - public GuiPRC(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); dynamicSlots = true; + imageHeight += 5; + inventoryLabelY += 5; } @Override protected void addGuiElements() { super.addGuiElements(); addRenderableWidget(new GuiEnergyTab(this, tile.getEnergyContainer(), tile::getActive)); - addRenderableWidget(new GuiFluidGauge(() -> tile.inputFluidTank, () -> tile.getFluidTanks(null), GaugeType.STANDARD, this, 5, 10) + addRenderableWidget(new GuiFluidGauge(() -> tile.inputFluidTank, () -> tile.getFluidTanks(null), GaugeType.STANDARD, this, 5, 15) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(TileEntityPressurizedReactionChamber.NOT_ENOUGH_FLUID_INPUT_ERROR))); - secondGauge = addRenderableWidget(new GuiChemicalGauge(() -> tile.inputGasTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 28, 10) + addRenderableWidget(new GuiChemicalGauge(() -> tile.inputGasTank, () -> tile.getChemicalTanks(null), GaugeType.STANDARD, this, 28, 15) .warning(WarningType.NO_MATCHING_RECIPE, tile.getWarningCheck(TileEntityPressurizedReactionChamber.NOT_ENOUGH_CHEMICAL_INPUT_ERROR))); - addRenderableWidget(new GuiChemicalGauge(() -> tile.outputGasTank, () -> tile.getChemicalTanks(null), GaugeType.SMALL, this, 140, 40) + addRenderableWidget(new GuiChemicalGauge(() -> tile.outputGasTank, () -> tile.getChemicalTanks(null), GaugeType.SMALL, this, 140, 45) .warning(WarningType.NO_SPACE_IN_OUTPUT, tile.getWarningCheck(TileEntityPressurizedReactionChamber.NOT_ENOUGH_SPACE_GAS_OUTPUT_ERROR))); - addRenderableWidget(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 163, 16) + addRenderableWidget(new GuiVerticalPowerBar(this, tile.getEnergyContainer(), 163, 21) .warning(WarningType.NOT_ENOUGH_ENERGY, tile.getWarningCheck(RecipeError.NOT_ENOUGH_ENERGY))); - addRenderableWidget(new GuiProgress(tile::getScaledProgress, ProgressType.RIGHT, this, 77, 38).recipeViewerCategory(tile)) + addRenderableWidget(new GuiProgress(tile::getScaledProgress, ProgressType.RIGHT, this, 77, 43).recipeViewerCategory(tile)) .warning(WarningType.INPUT_DOESNT_PRODUCE_OUTPUT, tile.getWarningCheck(RecipeError.INPUT_DOESNT_PRODUCE_OUTPUT)); } @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleTextWithOffset(guiGraphics, secondGauge.getRelativeRight(), getXSize(), 4, TextAlignment.LEFT); + renderTitleText(guiGraphics); renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/PressurizedReactionEmiRecipe.java b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/PressurizedReactionEmiRecipe.java index 90e3514abca..230e8ed7a59 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/PressurizedReactionEmiRecipe.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/PressurizedReactionEmiRecipe.java @@ -48,15 +48,15 @@ public PressurizedReactionEmiRecipe(MekanismEmiRecipeCategory category, RecipeHo @Override public void addWidgets(WidgetHolder widgetHolder) { - addSlot(widgetHolder, SlotType.INPUT, 54, 35, input(0)); - addSlot(widgetHolder, SlotType.OUTPUT, 116, 35, output(0)).recipeContext(this); - addSlot(widgetHolder, SlotType.POWER, 141, 17).with(SlotOverlay.POWER); - initTank(widgetHolder, GuiFluidGauge.getDummy(GaugeType.STANDARD.with(DataType.INPUT), this, 5, 10), input(1)); + addSlot(widgetHolder, SlotType.INPUT, 54, 40, input(0)); + addSlot(widgetHolder, SlotType.OUTPUT, 116, 40, output(0)).recipeContext(this); + addSlot(widgetHolder, SlotType.POWER, 141, 22).with(SlotOverlay.POWER); + initTank(widgetHolder, GuiFluidGauge.getDummy(GaugeType.STANDARD.with(DataType.INPUT), this, 5, 15), input(1)); GaugeType type1 = GaugeType.STANDARD.with(DataType.INPUT); - initTank(widgetHolder, GuiChemicalGauge.getDummy(type1, this, 28, 10), input(2)); + initTank(widgetHolder, GuiChemicalGauge.getDummy(type1, this, 28, 15), input(2)); GaugeType type = GaugeType.SMALL.with(DataType.OUTPUT); - initTank(widgetHolder, GuiChemicalGauge.getDummy(type, this, 140, 40), output(1)).recipeContext(this); - addElement(widgetHolder, new GuiVerticalPowerBar(this, RecipeViewerUtils.FULL_BAR, 164, 15)); - addSimpleProgress(widgetHolder, ProgressType.RIGHT, 77, 38, recipe.getDuration()); + initTank(widgetHolder, GuiChemicalGauge.getDummy(type, this, 140, 45), output(1)).recipeContext(this); + addElement(widgetHolder, new GuiVerticalPowerBar(this, RecipeViewerUtils.FULL_BAR, 164, 21)); + addSimpleProgress(widgetHolder, ProgressType.RIGHT, 77, 43, recipe.getDuration()); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/machine/PressurizedReactionRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/machine/PressurizedReactionRecipeCategory.java index 65d816aab7e..b003bd72dd3 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/machine/PressurizedReactionRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/machine/PressurizedReactionRecipeCategory.java @@ -41,16 +41,16 @@ public class PressurizedReactionRecipeCategory extends HolderRecipeCategory recipeType) { super(helper, recipeType); - inputItem = addSlot(SlotType.INPUT, 54, 35); - outputItem = addSlot(SlotType.OUTPUT, 116, 35); - addSlot(SlotType.POWER, 141, 17).with(SlotOverlay.POWER); - inputFluid = addElement(GuiFluidGauge.getDummy(GaugeType.STANDARD.with(DataType.INPUT), this, 5, 10)); + inputItem = addSlot(SlotType.INPUT, 54, 40); + outputItem = addSlot(SlotType.OUTPUT, 116, 40); + addSlot(SlotType.POWER, 141, 22).with(SlotOverlay.POWER); + inputFluid = addElement(GuiFluidGauge.getDummy(GaugeType.STANDARD.with(DataType.INPUT), this, 5, 15)); GaugeType type1 = GaugeType.STANDARD.with(DataType.INPUT); - inputChemical = addElement(GuiChemicalGauge.getDummy(type1, this, 28, 10)); + inputChemical = addElement(GuiChemicalGauge.getDummy(type1, this, 28, 15)); GaugeType type = GaugeType.SMALL.with(DataType.OUTPUT); - outputChemical = addElement(GuiChemicalGauge.getDummy(type, this, 140, 40)); - addElement(new GuiVerticalPowerBar(this, RecipeViewerUtils.FULL_BAR, 164, 15)); - addSimpleProgress(ProgressType.RIGHT, 77, 38); + outputChemical = addElement(GuiChemicalGauge.getDummy(type, this, 140, 45)); + addElement(new GuiVerticalPowerBar(this, RecipeViewerUtils.FULL_BAR, 164, 21)); + addSimpleProgress(ProgressType.RIGHT, 77, 43); } @Override diff --git a/src/main/java/mekanism/client/recipe_viewer/type/RecipeViewerRecipeType.java b/src/main/java/mekanism/client/recipe_viewer/type/RecipeViewerRecipeType.java index c397d3c71cc..d588f8e6362 100644 --- a/src/main/java/mekanism/client/recipe_viewer/type/RecipeViewerRecipeType.java +++ b/src/main/java/mekanism/client/recipe_viewer/type/RecipeViewerRecipeType.java @@ -88,7 +88,7 @@ private RecipeViewerRecipeType() { //Note: This previously had a lang key for a shorter string. Though ideally especially due to translations we will eventually instead just make the text scale //TODO - 1.20.4: Re-evaluate ^^ - public static final RVRecipeTypeWrapper REACTION = new RVRecipeTypeWrapper<>(MekanismRecipeType.REACTION, PressurizedReactionRecipe.class, -3, -10, 170, 60, MekanismBlocks.PRESSURIZED_REACTION_CHAMBER); + public static final RVRecipeTypeWrapper REACTION = new RVRecipeTypeWrapper<>(MekanismRecipeType.REACTION, PressurizedReactionRecipe.class, -3, -15, 170, 60, MekanismBlocks.PRESSURIZED_REACTION_CHAMBER); public static final RotaryRVRecipeType CONDENSENTRATING = new RotaryRVRecipeType(Mekanism.rl("condensentrating"), MekanismLang.CONDENSENTRATING); public static final RotaryRVRecipeType DECONDENSENTRATING = new RotaryRVRecipeType(Mekanism.rl("decondensentrating"), MekanismLang.DECONDENSENTRATING); diff --git a/src/main/java/mekanism/common/inventory/container/ModuleTweakerContainer.java b/src/main/java/mekanism/common/inventory/container/ModuleTweakerContainer.java index 6c89eee404a..d76bb68801d 100644 --- a/src/main/java/mekanism/common/inventory/container/ModuleTweakerContainer.java +++ b/src/main/java/mekanism/common/inventory/container/ModuleTweakerContainer.java @@ -37,7 +37,7 @@ public boolean mayPlace(@NotNull ItemStack stack) { }); } for (int slotY = 0; slotY < Inventory.getSelectionSize(); slotY++) { - addSlot(new HotBarSlot(inv, slotY, 43 + slotY * 18, 161) { + addSlot(new HotBarSlot(inv, slotY, 58 + slotY * 18, 161) { @Override public boolean mayPickup(@NotNull Player player) { return false; diff --git a/src/main/java/mekanism/common/registries/MekanismContainerTypes.java b/src/main/java/mekanism/common/registries/MekanismContainerTypes.java index ddde3baafc0..cb31871c457 100644 --- a/src/main/java/mekanism/common/registries/MekanismContainerTypes.java +++ b/src/main/java/mekanism/common/registries/MekanismContainerTypes.java @@ -133,7 +133,7 @@ private MekanismContainerTypes() { public static final ContainerTypeRegistryObject> OREDICTIONIFICATOR = CONTAINER_TYPES.custom(MekanismBlocks.OREDICTIONIFICATOR, TileEntityOredictionificator.class).offset(30, 64).build(); public static final ContainerTypeRegistryObject> OSMIUM_COMPRESSOR = CONTAINER_TYPES.register(MekanismBlocks.OSMIUM_COMPRESSOR, TileEntityOsmiumCompressor.class); public static final ContainerTypeRegistryObject> PRECISION_SAWMILL = CONTAINER_TYPES.register(MekanismBlocks.PRECISION_SAWMILL, TileEntityPrecisionSawmill.class); - public static final ContainerTypeRegistryObject> PRESSURIZED_REACTION_CHAMBER = CONTAINER_TYPES.register(MekanismBlocks.PRESSURIZED_REACTION_CHAMBER, TileEntityPressurizedReactionChamber.class); + public static final ContainerTypeRegistryObject> PRESSURIZED_REACTION_CHAMBER = CONTAINER_TYPES.custom(MekanismBlocks.PRESSURIZED_REACTION_CHAMBER, TileEntityPressurizedReactionChamber.class).offset(0, 5).build(); public static final ContainerTypeRegistryObject> PURIFICATION_CHAMBER = CONTAINER_TYPES.register(MekanismBlocks.PURIFICATION_CHAMBER, TileEntityPurificationChamber.class); public static final ContainerTypeRegistryObject> QUANTUM_ENTANGLOPORTER = CONTAINER_TYPES.custom(MekanismBlocks.QUANTUM_ENTANGLOPORTER, TileEntityQuantumEntangloporter.class).offset(0, 74).build(); public static final ContainerTypeRegistryObject> RESISTIVE_HEATER = CONTAINER_TYPES.register(MekanismBlocks.RESISTIVE_HEATER, TileEntityResistiveHeater.class); diff --git a/src/main/java/mekanism/common/tile/TileEntityModificationStation.java b/src/main/java/mekanism/common/tile/TileEntityModificationStation.java index ef82c468ef5..57066cb0894 100644 --- a/src/main/java/mekanism/common/tile/TileEntityModificationStation.java +++ b/src/main/java/mekanism/common/tile/TileEntityModificationStation.java @@ -76,7 +76,7 @@ protected IInventorySlotHolder getInitialInventory(IContentsListener listener) { moduleSlot.setSlotType(ContainerSlotType.NORMAL); moduleSlot.setSlotOverlay(SlotOverlay.MODULE); containerSlot.setSlotType(ContainerSlotType.NORMAL); - builder.addSlot(energySlot = EnergyInventorySlot.fillOrConvert(energyContainer, this::getLevel, listener, 149, 21)); + builder.addSlot(energySlot = EnergyInventorySlot.fillOrConvert(energyContainer, this::getLevel, listener, 151, 21)); return builder.build(); } diff --git a/src/main/java/mekanism/common/tile/machine/TileEntityPressurizedReactionChamber.java b/src/main/java/mekanism/common/tile/machine/TileEntityPressurizedReactionChamber.java index 207d58c9ba6..66877f2cef8 100644 --- a/src/main/java/mekanism/common/tile/machine/TileEntityPressurizedReactionChamber.java +++ b/src/main/java/mekanism/common/tile/machine/TileEntityPressurizedReactionChamber.java @@ -153,11 +153,11 @@ protected IEnergyContainerHolder getInitialEnergyContainers(IContentsListener li protected IInventorySlotHolder getInitialInventory(IContentsListener listener, IContentsListener recipeCacheListener, IContentsListener recipeCacheUnpauseListener) { InventorySlotHelper builder = InventorySlotHelper.forSideWithConfig(this); builder.addSlot(inputSlot = InputInventorySlot.at(item -> containsRecipeABC(item, inputFluidTank.getFluid(), inputGasTank.getStack()), this::containsRecipeA, - recipeCacheListener, 54, 35)) + recipeCacheListener, 54, 40)) .tracksWarnings(slot -> slot.warning(WarningType.NO_MATCHING_RECIPE, getWarningCheck(NOT_ENOUGH_ITEM_INPUT_ERROR))); - builder.addSlot(outputSlot = OutputInventorySlot.at(recipeCacheUnpauseListener, 116, 35)) + builder.addSlot(outputSlot = OutputInventorySlot.at(recipeCacheUnpauseListener, 116, 40)) .tracksWarnings(slot -> slot.warning(WarningType.NO_SPACE_IN_OUTPUT, getWarningCheck(NOT_ENOUGH_SPACE_ITEM_OUTPUT_ERROR))); - builder.addSlot(energySlot = EnergyInventorySlot.fillOrConvert(energyContainer, this::getLevel, listener, 141, 17)); + builder.addSlot(energySlot = EnergyInventorySlot.fillOrConvert(energyContainer, this::getLevel, listener, 141, 22)); return builder.build(); } diff --git a/src/main/resources/assets/mekanism/gui/module_selection.png b/src/main/resources/assets/mekanism/gui/module_selection.png index 58a624373f93016774e91b5316d81243db04a0e4..f979bbe020fc24ff9a831c1a9bae8ce01b04e08f 100644 GIT binary patch delta 177 zcmcc5_<&KdGr-TCmrII^fq{Y7)59eQNEZOH3JWukTzqly%!!JY^@W};jv*eM$veE| zb{s7T6yVqsHjyjLAf|+|DR{9|`>tc!=?x7sz1mhMn0a=eWVV(tGhk?BKPk4&Fo%Kl zTwh?XbL?ZW0xJdQw zj-v&E0vvn71o^`ZVoDgBf)_`z&7P*6-q2v8t8L}M%Cp;()mp;LfT59{bJ`Ze9EQsJ z<13~eT$ajh;pTbi(lj@%ga9Sc6-F8jmu6&Yd{mg@cu<04Sznf9PSliiCdSODL#I7i a8Im;`qObi;{{eIZgQqK-pUXO@geCxu>^MRI From d500167aa4cf0d2d8a410760ff3700978ad71087 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Tue, 24 Sep 2024 19:58:40 -0500 Subject: [PATCH 10/17] Make it so TEP production display doesn't have to use scrolling text in english --- .../java/mekanism/client/gui/GuiMekanism.java | 4 ++-- .../gui/GuiThermalEvaporationController.java | 18 +++++++++++------- .../gui/element/custom/GuiResizeControls.java | 2 +- .../client/gui/item/GuiDictionary.java | 2 +- .../emi/recipe/FluidToFluidEmiRecipe.java | 13 +++++++------ .../machine/FluidToFluidRecipeCategory.java | 13 +++++++------ .../type/RecipeViewerRecipeType.java | 2 +- .../evaporation/EvaporationMultiblockData.java | 4 ++-- .../registries/MekanismContainerTypes.java | 2 +- 9 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/main/java/mekanism/client/gui/GuiMekanism.java b/src/main/java/mekanism/client/gui/GuiMekanism.java index 5dd6cb6e365..7f55dbe1db1 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanism.java +++ b/src/main/java/mekanism/client/gui/GuiMekanism.java @@ -196,8 +196,8 @@ protected void renderInventoryTextAndOther(GuiGraphics guiGraphics, Component ri } protected void renderInventoryTextAndOther(GuiGraphics guiGraphics, Component rightAlignedText, int rightEndPad) { - drawScrollingString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, TextAlignment.LEFT, titleTextColor(), 54, 0, false); - int rightStart = inventoryLabelX + 52; + drawScrollingString(guiGraphics, playerInventoryTitle, inventoryLabelX, inventoryLabelY, TextAlignment.LEFT, titleTextColor(), 53, 0, false); + int rightStart = inventoryLabelX + 51; drawScrollingString(guiGraphics, rightAlignedText, rightStart, inventoryLabelY, TextAlignment.RIGHT, titleTextColor(), getXSize() - rightStart - rightEndPad, 6, false); } diff --git a/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java b/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java index c4ccbb16e9e..50b00f54df9 100644 --- a/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java +++ b/src/main/java/mekanism/client/gui/GuiThermalEvaporationController.java @@ -5,6 +5,7 @@ import java.util.function.BooleanSupplier; import mekanism.api.recipes.cache.CachedRecipe.OperationTracker.RecipeError; import mekanism.client.gui.element.GuiDownArrow; +import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.GuiInnerScreen; import mekanism.client.gui.element.bar.GuiBar.IBarInfoHandler; import mekanism.client.gui.element.bar.GuiHorizontalRateBar; @@ -28,24 +29,27 @@ public class GuiThermalEvaporationController extends GuiMekanismTile> { + private GuiElement inputGauge, outputGauge; + public GuiThermalEvaporationController(MekanismTileContainer container, Inventory inv, Component title) { super(container, inv, title); + imageWidth += 20; + inventoryLabelX += 10; inventoryLabelY += 2; - titleLabelY = 4; dynamicSlots = true; } @Override protected void addGuiElements() { super.addGuiElements(); - addRenderableWidget(new GuiInnerScreen(this, 48, 19, 80, 40, () -> { + addRenderableWidget(new GuiInnerScreen(this, 48, 19, 100, 40, () -> { EvaporationMultiblockData multiblock = tile.getMultiblock(); return List.of(MekanismLang.MULTIBLOCK_FORMED.translate(), MekanismLang.EVAPORATION_HEIGHT.translate(multiblock.height()), MekanismLang.TEMPERATURE.translate(MekanismUtils.getTemperatureDisplay(multiblock.getTemperature(), TemperatureUnit.KELVIN, true)), MekanismLang.FLUID_PRODUCTION.translate(Math.round(multiblock.lastGain * 100D) / 100D)); }).padding(3).clearSpacing().recipeViewerCategories(RecipeViewerRecipeType.EVAPORATING)); addRenderableWidget(new GuiDownArrow(this, 32, 39)); - addRenderableWidget(new GuiDownArrow(this, 136, 39)); + addRenderableWidget(new GuiDownArrow(this, 156, 39)); addRenderableWidget(new GuiHorizontalRateBar(this, new IBarInfoHandler() { @Override public Component getTooltip() { @@ -56,12 +60,12 @@ public Component getTooltip() { public double getLevel() { return Math.min(1, tile.getMultiblock().getTemperature() / EvaporationMultiblockData.MAX_MULTIPLIER_TEMP); } - }, 48, 63)) + }, 58, 62)) //Note: We just apply this warning to the bar as we don't have an arrow or anything here .warning(WarningType.INPUT_DOESNT_PRODUCE_OUTPUT, getWarningCheck(RecipeError.INPUT_DOESNT_PRODUCE_OUTPUT)); - addRenderableWidget(new GuiFluidGauge(() -> tile.getMultiblock().inputTank, () -> tile.getMultiblock().getFluidTanks(null), GaugeType.STANDARD, this, 6, 13)) + inputGauge = addRenderableWidget(new GuiFluidGauge(() -> tile.getMultiblock().inputTank, () -> tile.getMultiblock().getFluidTanks(null), GaugeType.STANDARD, this, 6, 13)) .warning(WarningType.NO_MATCHING_RECIPE, getWarningCheck(RecipeError.NOT_ENOUGH_INPUT)); - addRenderableWidget(new GuiFluidGauge(() -> tile.getMultiblock().outputTank, () -> tile.getMultiblock().getFluidTanks(null), GaugeType.STANDARD, this, 152, 13)) + outputGauge = addRenderableWidget(new GuiFluidGauge(() -> tile.getMultiblock().outputTank, () -> tile.getMultiblock().getFluidTanks(null), GaugeType.STANDARD, this, 172, 13)) .warning(WarningType.NO_SPACE_IN_OUTPUT, getWarningCheck(RecipeError.NOT_ENOUGH_OUTPUT_SPACE)); addRenderableWidget(new GuiHeatTab(this, () -> { Component environment = MekanismUtils.getTemperatureDisplay(tile.getMultiblock().lastEnvironmentLoss, TemperatureUnit.KELVIN, false); @@ -81,7 +85,7 @@ protected void addWarningTab(IWarningTracker warningTracker) { @Override protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { - renderTitleText(guiGraphics); + renderTitleTextWithOffset(guiGraphics, inputGauge.getRelativeRight(), outputGauge.getRelativeX()); renderInventoryText(guiGraphics); super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java b/src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java index ce2d863b7cd..cfbd8cc1a1e 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiResizeControls.java @@ -56,7 +56,7 @@ public void updateTooltip(int mouseX, int mouseY) { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - drawScaledScrollingString(guiGraphics, MekanismLang.HEIGHT.translate(), 0, 16, TextAlignment.CENTER, titleTextColor(), 4, false, 0.60F); + drawScaledScrollingString(guiGraphics, MekanismLang.HEIGHT.translate(), 0, 16, TextAlignment.CENTER, titleTextColor(), 4, false, 0.6F); } @Override diff --git a/src/main/java/mekanism/client/gui/item/GuiDictionary.java b/src/main/java/mekanism/client/gui/item/GuiDictionary.java index bcc4dfad56f..466e7ed2075 100644 --- a/src/main/java/mekanism/client/gui/item/GuiDictionary.java +++ b/src/main/java/mekanism/client/gui/item/GuiDictionary.java @@ -42,7 +42,7 @@ protected void addGuiElements() { scrollList = addRenderableWidget(new GuiTextScrollList(this, 7, 29, 162, 42)); //TODO: Ideally we would eventually replace this with some sort of tab system as it would probably look better // and could then be limited to just the tags the target supports - dropdown = addRenderableWidget(new GuiDropdown<>(this, 114, 73, 55, DictionaryTagType.class, () -> currentType, this::setCurrentType)); + dropdown = addRenderableWidget(new GuiDropdown<>(this, 113, 73, 56, DictionaryTagType.class, () -> currentType, this::setCurrentType)); target = addRenderableWidget(new GuiDictionaryTarget(this, 6, 6, this::updateScrollList)); } diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java index cdd8259215e..8e959fd0632 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/FluidToFluidEmiRecipe.java @@ -28,19 +28,20 @@ public FluidToFluidEmiRecipe(MekanismEmiRecipeCategory category, RecipeHolder List.of( + //Note: All these elements except for the inputs are in slightly different x positions than in the normal GUI so that they fit properly in emi + addElement(widgetHolder, new GuiInnerScreen(this, 48, 19, 86, 40, () -> List.of( MekanismLang.MULTIBLOCK_FORMED.translate(), MekanismLang.EVAPORATION_HEIGHT.translate(EvaporationMultiblockData.MAX_HEIGHT), MekanismLang.TEMPERATURE.translate(MekanismUtils.getTemperatureDisplay(HeatAPI.AMBIENT_TEMP, TemperatureUnit.KELVIN, true)), MekanismLang.FLUID_PRODUCTION.translate(0.0)) ).padding(3).clearSpacing()); addElement(widgetHolder, new GuiDownArrow(this, 32, 39)); - addElement(widgetHolder, new GuiDownArrow(this, 136, 39)); - addElement(widgetHolder, new GuiHorizontalRateBar(this, RecipeViewerUtils.FULL_BAR, 48, 63)); + addElement(widgetHolder, new GuiDownArrow(this, 142, 39)); + addElement(widgetHolder, new GuiHorizontalRateBar(this, RecipeViewerUtils.FULL_BAR, 51, 63)); addSlot(widgetHolder, SlotType.INPUT, 28, 20); addSlot(widgetHolder, SlotType.OUTPUT, 28, 51); - addSlot(widgetHolder, SlotType.INPUT, 132, 20); - addSlot(widgetHolder, SlotType.OUTPUT, 132, 51); + addSlot(widgetHolder, SlotType.INPUT, 138, 20); + addSlot(widgetHolder, SlotType.OUTPUT, 138, 51); initTank(widgetHolder, GuiFluidGauge.getDummy(GaugeType.STANDARD, this, 6, 13), input(0)); - initTank(widgetHolder, GuiFluidGauge.getDummy(GaugeType.STANDARD, this, 152, 13), output(0)).recipeContext(this); + initTank(widgetHolder, GuiFluidGauge.getDummy(GaugeType.STANDARD, this, 158, 13), output(0)).recipeContext(this); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java index cb22fd4660b..564be9b99e1 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/machine/FluidToFluidRecipeCategory.java @@ -31,20 +31,21 @@ public class FluidToFluidRecipeCategory extends HolderRecipeCategory recipeType) { super(helper, recipeType); - addElement(new GuiInnerScreen(this, 48, 19, 80, 40, () -> List.of( + //Note: All these elements except for the inputs are in slightly different x positions than in the normal GUI so that they fit properly in JEI + addElement(new GuiInnerScreen(this, 48, 19, 86, 40, () -> List.of( MekanismLang.MULTIBLOCK_FORMED.translate(), MekanismLang.EVAPORATION_HEIGHT.translate(EvaporationMultiblockData.MAX_HEIGHT), MekanismLang.TEMPERATURE.translate(MekanismUtils.getTemperatureDisplay(HeatAPI.AMBIENT_TEMP, TemperatureUnit.KELVIN, true)), MekanismLang.FLUID_PRODUCTION.translate(0.0)) ).padding(3).clearSpacing()); addElement(new GuiDownArrow(this, 32, 39)); - addElement(new GuiDownArrow(this, 136, 39)); - addElement(new GuiHorizontalRateBar(this, RecipeViewerUtils.FULL_BAR, 48, 63)); + addElement(new GuiDownArrow(this, 142, 39)); + addElement(new GuiHorizontalRateBar(this, RecipeViewerUtils.FULL_BAR, 51, 63)); addSlot(SlotType.INPUT, 28, 20); addSlot(SlotType.OUTPUT, 28, 51); - addSlot(SlotType.INPUT, 132, 20); - addSlot(SlotType.OUTPUT, 132, 51); + addSlot(SlotType.INPUT, 138, 20); + addSlot(SlotType.OUTPUT, 138, 51); input = addElement(GuiFluidGauge.getDummy(GaugeType.STANDARD, this, 6, 13)); - output = addElement(GuiFluidGauge.getDummy(GaugeType.STANDARD, this, 152, 13)); + output = addElement(GuiFluidGauge.getDummy(GaugeType.STANDARD, this, 158, 13)); } @Override diff --git a/src/main/java/mekanism/client/recipe_viewer/type/RecipeViewerRecipeType.java b/src/main/java/mekanism/client/recipe_viewer/type/RecipeViewerRecipeType.java index d588f8e6362..9908cbe1aa6 100644 --- a/src/main/java/mekanism/client/recipe_viewer/type/RecipeViewerRecipeType.java +++ b/src/main/java/mekanism/client/recipe_viewer/type/RecipeViewerRecipeType.java @@ -54,7 +54,7 @@ private RecipeViewerRecipeType() { public static final RVRecipeTypeWrapper WASHING = new RVRecipeTypeWrapper<>(MekanismRecipeType.WASHING, FluidChemicalToChemicalRecipe.class, -7, -13, 162, 60, MekanismBlocks.CHEMICAL_WASHER); - public static final RVRecipeTypeWrapper EVAPORATING = new RVRecipeTypeWrapper<>(MekanismRecipeType.EVAPORATING, FluidToFluidRecipe.class, -3, -12, 170, 62, MekanismBlocks.THERMAL_EVAPORATION_CONTROLLER, MekanismBlocks.THERMAL_EVAPORATION_VALVE, MekanismBlocks.THERMAL_EVAPORATION_BLOCK); + public static final RVRecipeTypeWrapper EVAPORATING = new RVRecipeTypeWrapper<>(MekanismRecipeType.EVAPORATING, FluidToFluidRecipe.class, -3, -12, 176, 62, MekanismBlocks.THERMAL_EVAPORATION_CONTROLLER, MekanismBlocks.THERMAL_EVAPORATION_VALVE, MekanismBlocks.THERMAL_EVAPORATION_BLOCK); public static final RVRecipeTypeWrapper ACTIVATING = new RVRecipeTypeWrapper<>(MekanismRecipeType.ACTIVATING, ChemicalToChemicalRecipe.class, -4, -13, 168, 60, MekanismBlocks.SOLAR_NEUTRON_ACTIVATOR); public static final RVRecipeTypeWrapper CENTRIFUGING = new RVRecipeTypeWrapper<>(MekanismRecipeType.CENTRIFUGING, ChemicalToChemicalRecipe.class, -4, -13, 168, 60, MekanismBlocks.ISOTOPIC_CENTRIFUGE); diff --git a/src/main/java/mekanism/common/content/evaporation/EvaporationMultiblockData.java b/src/main/java/mekanism/common/content/evaporation/EvaporationMultiblockData.java index 34bb8bf6b23..40baa2b1687 100644 --- a/src/main/java/mekanism/common/content/evaporation/EvaporationMultiblockData.java +++ b/src/main/java/mekanism/common/content/evaporation/EvaporationMultiblockData.java @@ -121,8 +121,8 @@ public EvaporationMultiblockData(TileEntityThermalEvaporationBlock tile) { outputHandler = OutputHelper.getOutputHandler(outputTank, RecipeError.NOT_ENOUGH_OUTPUT_SPACE); inventorySlots.add(inputInputSlot = FluidInventorySlot.fill(inputTank, this, 28, 20)); inventorySlots.add(outputInputSlot = OutputInventorySlot.at(this, 28, 51)); - inventorySlots.add(inputOutputSlot = FluidInventorySlot.drain(outputTank, this, 132, 20)); - inventorySlots.add(outputOutputSlot = OutputInventorySlot.at(this, 132, 51)); + inventorySlots.add(inputOutputSlot = FluidInventorySlot.drain(outputTank, this, 152, 20)); + inventorySlots.add(outputOutputSlot = OutputInventorySlot.at(this, 152, 51)); inputInputSlot.setSlotType(ContainerSlotType.INPUT); inputOutputSlot.setSlotType(ContainerSlotType.INPUT); heatCapacitors.add(heatCapacitor = VariableHeatCapacitor.create(MekanismConfig.general.evaporationHeatCapacity.get() * 3, () -> biomeAmbientTemp, this)); diff --git a/src/main/java/mekanism/common/registries/MekanismContainerTypes.java b/src/main/java/mekanism/common/registries/MekanismContainerTypes.java index cb31871c457..c566bef674b 100644 --- a/src/main/java/mekanism/common/registries/MekanismContainerTypes.java +++ b/src/main/java/mekanism/common/registries/MekanismContainerTypes.java @@ -145,7 +145,7 @@ private MekanismContainerTypes() { public static final ContainerTypeRegistryObject> SEISMIC_VIBRATOR = CONTAINER_TYPES.register(MekanismBlocks.SEISMIC_VIBRATOR, TileEntitySeismicVibrator.class); public static final ContainerTypeRegistryObject> SOLAR_NEUTRON_ACTIVATOR = CONTAINER_TYPES.register(MekanismBlocks.SOLAR_NEUTRON_ACTIVATOR, TileEntitySolarNeutronActivator.class); public static final ContainerTypeRegistryObject> TELEPORTER = CONTAINER_TYPES.custom(MekanismBlocks.TELEPORTER, TileEntityTeleporter.class).offset(0, 74).build(); - public static final ContainerTypeRegistryObject> THERMAL_EVAPORATION_CONTROLLER = CONTAINER_TYPES.register(MekanismBlocks.THERMAL_EVAPORATION_CONTROLLER, TileEntityThermalEvaporationController.class); + public static final ContainerTypeRegistryObject> THERMAL_EVAPORATION_CONTROLLER = CONTAINER_TYPES.custom(MekanismBlocks.THERMAL_EVAPORATION_CONTROLLER, TileEntityThermalEvaporationController.class).offset(10, 0).build(); public static final ContainerTypeRegistryObject> ANTIPROTONIC_NUCLEOSYNTHESIZER = CONTAINER_TYPES.custom(MekanismBlocks.ANTIPROTONIC_NUCLEOSYNTHESIZER, TileEntityAntiprotonicNucleosynthesizer.class).offset(10, 27).build(); public static final ContainerTypeRegistryObject> PIGMENT_EXTRACTOR = CONTAINER_TYPES.register(MekanismBlocks.PIGMENT_EXTRACTOR, TileEntityPigmentExtractor.class); public static final ContainerTypeRegistryObject> PIGMENT_MIXER = CONTAINER_TYPES.register(MekanismBlocks.PIGMENT_MIXER, TileEntityPigmentMixer.class); From 0d1d299719b73e25bbfb35c93a7d6ff45f9f6d61 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Thu, 26 Sep 2024 10:18:38 -0500 Subject: [PATCH 11/17] Deduplicate a bit of code for scrolling strings, and fix scaled text not quite translating to the correct spot (seems to make it slightly more readable) --- .../gui/element/GuiColorPickerSlot.java | 2 +- .../element/custom/module/ColorSelection.java | 2 +- .../tab/window/GuiCraftingWindowTab.java | 2 +- .../tab/window/GuiSideConfigurationTab.java | 2 +- .../tab/window/GuiTransporterConfigTab.java | 2 +- .../tab/window/GuiUpgradeWindowTab.java | 2 +- .../client/render/IFancyFontRenderer.java | 78 ++++++++----------- 7 files changed, 40 insertions(+), 50 deletions(-) diff --git a/src/main/java/mekanism/client/gui/element/GuiColorPickerSlot.java b/src/main/java/mekanism/client/gui/element/GuiColorPickerSlot.java index da795830fba..2c02ceb560b 100644 --- a/src/main/java/mekanism/client/gui/element/GuiColorPickerSlot.java +++ b/src/main/java/mekanism/client/gui/element/GuiColorPickerSlot.java @@ -52,6 +52,6 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { @Override public void onClick(double mouseX, double mouseY, int button) { - gui().addWindow(new GuiColorWindow(gui(), getGuiWidth() / 2 - 160 / 2, getGuiHeight() / 2 - 120 / 2, handlesAlpha, supplier.get(), consumer)); + gui().addWindow(new GuiColorWindow(gui(), (getGuiWidth() - 160) / 2, (getGuiHeight() - 120) / 2, handlesAlpha, supplier.get(), consumer)); } } diff --git a/src/main/java/mekanism/client/gui/element/custom/module/ColorSelection.java b/src/main/java/mekanism/client/gui/element/custom/module/ColorSelection.java index a76557f53ce..c467c6ce2f1 100644 --- a/src/main/java/mekanism/client/gui/element/custom/module/ColorSelection.java +++ b/src/main/java/mekanism/client/gui/element/custom/module/ColorSelection.java @@ -99,7 +99,7 @@ protected void click(double mouseX, double mouseY) { previewReset = () -> armorPreview.resetToDefault(slot); } } - parent.gui().addWindow(new GuiColorWindow(parent.gui(), parent.getGuiWidth() / 2 - 160 / 2, parent.getGuiHeight() / 2 - 120 / 2, supportsAlpha, + parent.gui().addWindow(new GuiColorWindow(parent.gui(), (parent.getGuiWidth() - 160) / 2, (parent.getGuiHeight() - 120) / 2, supportsAlpha, getColor(), color -> setData(color.argb()), armorPreview, updatePreviewColor, previewReset)); } } diff --git a/src/main/java/mekanism/client/gui/element/tab/window/GuiCraftingWindowTab.java b/src/main/java/mekanism/client/gui/element/tab/window/GuiCraftingWindowTab.java index d2042990633..26e8640d196 100644 --- a/src/main/java/mekanism/client/gui/element/tab/window/GuiCraftingWindowTab.java +++ b/src/main/java/mekanism/client/gui/element/tab/window/GuiCraftingWindowTab.java @@ -108,6 +108,6 @@ protected List getValidWindows() { @Override protected GuiWindow createWindow(SelectedWindowData windowData) { openWindows[windowData.extraData] = true; - return new GuiCraftingWindow(gui(), getGuiWidth() / 2 - 156 / 2, 15, container, windowData); + return new GuiCraftingWindow(gui(), (getGuiWidth() - 124) / 2, 15, container, windowData); } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/tab/window/GuiSideConfigurationTab.java b/src/main/java/mekanism/client/gui/element/tab/window/GuiSideConfigurationTab.java index 89855ea2caf..6d9aee6b97a 100644 --- a/src/main/java/mekanism/client/gui/element/tab/window/GuiSideConfigurationTab.java +++ b/src/main/java/mekanism/client/gui/element/tab/window/GuiSideConfigurationTab.java @@ -31,7 +31,7 @@ protected void colorTab(GuiGraphics guiGraphics) { @Override protected GuiWindow createWindow(SelectedWindowData windowData) { - return new GuiSideConfiguration<>(gui(), getGuiWidth() / 2 - 156 / 2, 15, dataSource, windowData); + return new GuiSideConfiguration<>(gui(), (getGuiWidth() - 156) / 2, 15, dataSource, windowData); } @Override diff --git a/src/main/java/mekanism/client/gui/element/tab/window/GuiTransporterConfigTab.java b/src/main/java/mekanism/client/gui/element/tab/window/GuiTransporterConfigTab.java index 05a71a8c173..483ab7c0cfc 100644 --- a/src/main/java/mekanism/client/gui/element/tab/window/GuiTransporterConfigTab.java +++ b/src/main/java/mekanism/client/gui/element/tab/window/GuiTransporterConfigTab.java @@ -31,7 +31,7 @@ protected void colorTab(GuiGraphics guiGraphics) { @Override protected GuiWindow createWindow(SelectedWindowData windowData) { - return new GuiTransporterConfig<>(gui(), getGuiWidth() / 2 - 156 / 2, 15, dataSource, windowData); + return new GuiTransporterConfig<>(gui(), (getGuiWidth() - 156) / 2, 15, dataSource, windowData); } @Override diff --git a/src/main/java/mekanism/client/gui/element/tab/window/GuiUpgradeWindowTab.java b/src/main/java/mekanism/client/gui/element/tab/window/GuiUpgradeWindowTab.java index bb9743614f7..477d55c8546 100644 --- a/src/main/java/mekanism/client/gui/element/tab/window/GuiUpgradeWindowTab.java +++ b/src/main/java/mekanism/client/gui/element/tab/window/GuiUpgradeWindowTab.java @@ -30,7 +30,7 @@ protected void colorTab(GuiGraphics guiGraphics) { @Override protected GuiWindow createWindow(SelectedWindowData windowData) { - return new GuiUpgradeWindow(gui(), getGuiWidth() / 2 - 156 / 2, 15, dataSource, windowData); + return new GuiUpgradeWindow(gui(), (getGuiWidth() - 156) / 2, 15, dataSource, windowData); } @Override diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 7116c60c11b..e7c2d93417e 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -13,7 +13,6 @@ import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; import org.joml.Matrix4f; -import org.joml.Vector3f; //TODO - 1.21: Document this class public interface IFancyFontRenderer { @@ -93,18 +92,8 @@ default void drawScrollingString(GuiGraphics guiGraphics, Component text, int mi float targetY = (minY + maxY - getLineHeight()) / 2F; int areaWidth = maxX - minX; if (textWidth > areaWidth) { - int overflowWidth = textWidth - areaWidth; - double seconds = Util.getMillis() / 1_000D; - double scrollPeriod = Math.max(overflowWidth * AbstractWidget.PERIOD_PER_SCROLLED_PIXEL, AbstractWidget.MIN_SCROLL_PERIOD); - double scrolledSoFar = Math.sin((Math.PI / 2) * Math.cos((2 * Math.PI) * seconds / scrollPeriod)) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; - double overflowedBy = scrolledSoFar * overflowWidth;//Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); But that is equivalent to just multiplying performing the multiplication - //Note: We are drawing in relative coordinates, but GuiGraphics#enableScissor, is expecting absolute coordinates, - // so we need to get the translations from our pose stack - int left = getTranslationX(guiGraphics); - int top = getTranslationY(guiGraphics); - guiGraphics.enableScissor(left + minX, top + minY, left + maxX, top + maxY); - //TODO: Float? - drawString(guiGraphics, text, minX - (int) overflowedBy, targetY, color, shadow); + float targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); + drawString(guiGraphics, text, targetX, targetY, color, shadow); guiGraphics.disableScissor(); } else { drawString(guiGraphics, text, alignment.getTarget(minX, maxX, areaWidth, textWidth), targetY, color, shadow); @@ -137,25 +126,39 @@ default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, float targetY = (minY + maxY - getLineHeight()) / 2F; int areaWidth = maxX - minX; if (textWidth > areaWidth) { - float overflowWidth = textWidth - areaWidth; - double seconds = Util.getMillis() / 1_000D; - double scrollPeriod = Math.max(overflowWidth * AbstractWidget.PERIOD_PER_SCROLLED_PIXEL, AbstractWidget.MIN_SCROLL_PERIOD); - double scrolledSoFar = Math.sin((Math.PI / 2) * Math.cos((2 * Math.PI) * seconds / scrollPeriod)) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; - double overflowedBy = scrolledSoFar * overflowWidth;//Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); But that is equivalent to just multiplying performing the multiplication - //Note: We are drawing in relative coordinates, but GuiGraphics#enableScissor, is expecting absolute coordinates, - // so we need to get the translations from our pose stack - int left = getTranslationX(guiGraphics); - int top = getTranslationY(guiGraphics); - guiGraphics.enableScissor(left + minX, top + minY, left + maxX, top + maxY); - //TODO: Should this cast to float? I believe this makes it less choppy, but a bit blurry? - // So we probably don't want to cast overflowedBy to float - drawTextWithScale(guiGraphics, text, minX - (int) overflowedBy, targetY, color, shadow, scale); + float targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); + drawTextWithScale(guiGraphics, text, targetX, targetY, color, shadow, scale); guiGraphics.disableScissor(); } else { drawTextWithScale(guiGraphics, text, alignment.getTarget(minX, maxX, areaWidth, textWidth), targetY, color, shadow, scale); } } + /** + * Based off the logic for calculating the scissor area and draw target that vanilla does in + * {@link AbstractWidget#renderScrollingString(GuiGraphics, Font, Component, int, int, int, int, int, int)} + * + * @apiNote Call {@link GuiGraphics#disableScissor()} after using this method + */ + private static float prepScrollingString(GuiGraphics guiGraphics, double textWidth, int areaWidth, int minX, int minY, int maxX, int maxY) { + double overflowWidth = textWidth - areaWidth; + double seconds = Util.getMillis() / 1_000D; + double scrollPeriod = Math.max(overflowWidth * AbstractWidget.PERIOD_PER_SCROLLED_PIXEL, AbstractWidget.MIN_SCROLL_PERIOD); + double scrolledSoFar = Math.sin((Math.PI / 2) * Math.cos((2 * Math.PI) * seconds / scrollPeriod)) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; + //Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); to calculate overflowedBy. But that is equivalent to just multiplying performing the multiplication + double overflowedBy = scrolledSoFar * overflowWidth; + //Note: We are drawing in relative coordinates, but GuiGraphics#enableScissor, is expecting absolute coordinates, + // so we need to get the translations from our pose stack + //Note: This is equivalent to what Matrix4f#getTranslation(Vector3f) would do, without the extra allocations. + Matrix4f matrix4f = guiGraphics.pose().last().pose(); + int left = (int) matrix4f.m30(); + int top = (int) matrix4f.m31(); + guiGraphics.enableScissor(left + minX, top + minY, left + maxX, top + maxY); + //TODO: Should this cast to float? I believe this makes it less choppy, but a bit blurry? + // So we probably don't want to cast overflowedBy to float + return minX - (int) overflowedBy; + } + private void drawTextWithScale(GuiGraphics guiGraphics, Component text, float x, float y, int color, boolean shadow, float scale) { PoseStack pose = prepTextScale(guiGraphics, x, y, scale); drawString(guiGraphics, text, 0, 0, color, shadow); @@ -163,33 +166,20 @@ private void drawTextWithScale(GuiGraphics guiGraphics, Component text, float x, } //Note: As translate will implicitly cast x and y to being floats, we might as well pass these in as floats to reduce duplicate code - private static PoseStack prepTextScale(GuiGraphics guiGraphics, float x, float y, float scale) { + private PoseStack prepTextScale(GuiGraphics guiGraphics, float x, float y, float scale) { PoseStack pose = guiGraphics.pose(); pose.pushPose(); return prepTextScale(pose, x, y, scale); } - static PoseStack prepTextScale(PoseStack pose, float x, float y, float scale) { - float yAdd = 4 - 4 * scale; + private PoseStack prepTextScale(PoseStack pose, float x, float y, float scale) { + float halfLineHeight = getLineHeight() / 2F; + float yAdd = halfLineHeight - halfLineHeight * scale; pose.translate(x, y + yAdd, 0); pose.scale(scale, scale, scale); return pose; } - /** - * Equivalent to what {@link Matrix4f#getTranslation(Vector3f)} would do, without the extra allocations. - */ - private static int getTranslationX(GuiGraphics guiGraphics) { - return (int) guiGraphics.pose().last().pose().m30(); - } - - /** - * Equivalent to what {@link Matrix4f#getTranslation(Vector3f)} would do, without the extra allocations. - */ - private static int getTranslationY(GuiGraphics guiGraphics) { - return (int) guiGraphics.pose().last().pose().m31(); - } - enum TextAlignment { LEFT, CENTER, @@ -241,7 +231,7 @@ public void renderCentered(GuiGraphics guiGraphics, int x, int y, int color, int public int renderWithScale(GuiGraphics guiGraphics, int x, int y, int color, int maxLength, float scale) { //Divide by scale for calculating actual max length so that when the text is scaled it has the proper total space available calculateLines(Mth.floor(maxLength / scale)); - PoseStack pose = prepTextScale(guiGraphics, x, y, scale); + PoseStack pose = font.prepTextScale(guiGraphics, x, y, scale); int startY = 0; int lineHeight = font.getLineHeight(); for (LineData line : linesToDraw) { From 50a38e8cf9eaa479a34c658ec695cf01f14e2db4 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Sat, 28 Sep 2024 12:18:57 -0500 Subject: [PATCH 12/17] Make it so that installed stone generator upgrades and remaining dictionary dropdowns fit within the gui in english without resorting to having to scroll --- .../2ca94f3a6e22cb9eec299788405fc6e4ad158c09 | 4 +- .../c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 | 6 +- .../mekanism/assets/mekanism/lang/en_ud.json | 2 +- .../mekanism/assets/mekanism/lang/en_us.json | 2 +- .../data/mekanism/computer_help/jekyll.md | 2 +- .../client/lang/MekanismLangProvider.java | 2 +- .../CrTExampleRecipeComponentBuilder.java | 4 +- .../element/custom/GuiSupportedUpgrades.java | 2 +- .../scroll/GuiInstallableScrollList.java | 130 ++++++++++++++++++ .../element/scroll/GuiModuleScrollList.java | 116 +++++----------- .../element/scroll/GuiUpgradeScrollList.java | 102 ++++---------- .../tab/window/GuiUpgradeWindowTab.java | 2 +- .../gui/element/window/GuiUpgradeWindow.java | 21 +-- .../client/gui/item/GuiSeismicReader.java | 29 ++-- .../client/render/IFancyFontRenderer.java | 2 +- .../assets/mekanism/gui/upgrade_selection.png | Bin 214 -> 223 bytes 16 files changed, 231 insertions(+), 195 deletions(-) create mode 100644 src/main/java/mekanism/client/gui/element/scroll/GuiInstallableScrollList.java diff --git a/src/datagen/generated/mekanism/.cache/2ca94f3a6e22cb9eec299788405fc6e4ad158c09 b/src/datagen/generated/mekanism/.cache/2ca94f3a6e22cb9eec299788405fc6e4ad158c09 index c2c464f3ea9..2459bef7e61 100644 --- a/src/datagen/generated/mekanism/.cache/2ca94f3a6e22cb9eec299788405fc6e4ad158c09 +++ b/src/datagen/generated/mekanism/.cache/2ca94f3a6e22cb9eec299788405fc6e4ad158c09 @@ -1,6 +1,6 @@ -// 1.21.1 2024-08-26T11:19:54.2186095 ComputerHelp: mekanism +// 1.21.1 2024-09-28T11:00:15.3012517 ComputerHelp: mekanism 740491ca25c3ff0efd50f10d2427e4ceccb0c1e1 data/mekanism/computer_help/enums.csv e43ab1d9e5ae68f834035609a85af3c6ce4161a4 data/mekanism/computer_help/enums.json -7af50c5e4ca7a140661622533860cafbed24c64d data/mekanism/computer_help/jekyll.md +a61020bfab0b0525339f1b49417d2f7e17dbc7df data/mekanism/computer_help/jekyll.md 0442f235be0f36db5728aaf942c99e9c8638f662 data/mekanism/computer_help/methods.csv 366f1717990ae1860dc4739af4a8f441cd0acad5 data/mekanism/computer_help/methods.json diff --git a/src/datagen/generated/mekanism/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 b/src/datagen/generated/mekanism/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 index 0787aa9ffec..00b567bbc28 100644 --- a/src/datagen/generated/mekanism/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 +++ b/src/datagen/generated/mekanism/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 @@ -1,5 +1,5 @@ -// 1.21.1 2024-08-24T23:59:23.1423828 Languages: en_us for mod: mekanism +// 1.21.1 2024-09-28T11:00:15.3042814 Languages: en_us for mod: mekanism 8d915354d84b3a4d60c65f9280fdd7ceca016c35 assets/mekanism/lang/en_au.json 8d915354d84b3a4d60c65f9280fdd7ceca016c35 assets/mekanism/lang/en_gb.json -28d2fb3189f404bc44f12679cf7835e080185937 assets/mekanism/lang/en_ud.json -52699badc3d935f327983b454e5299e066efd880 assets/mekanism/lang/en_us.json +2cd403d1dc72293441a4c86b1b1ddc05978130e8 assets/mekanism/lang/en_ud.json +525157cafd0048a56223755ff5b66a357d3008b4 assets/mekanism/lang/en_us.json diff --git a/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json b/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json index bd296e74c3c..0d8f56e1208 100644 --- a/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json +++ b/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json @@ -2131,7 +2131,7 @@ "dictionary.mekanism.attribute.desc": "sᵷɐ⟘ ǝʇnqᴉɹʇʇⱯ ʎɐꞁdsᴉᗡ", "dictionary.mekanism.block": "ʞɔoꞁᗺ", "dictionary.mekanism.block.desc": "sᵷɐ⟘ ʞɔoꞁᗺ ʎɐꞁdsᴉᗡ", - "dictionary.mekanism.block_entity_type": "ǝdʎ⟘ ʎʇᴉʇuƎ ʞɔoꞁᗺ", + "dictionary.mekanism.block_entity_type": "ǝdʎ⟘ Ǝᗺ", "dictionary.mekanism.block_entity_type.desc": "sᵷɐ⟘ ǝdʎ⟘ ʎʇᴉʇuƎ ʞɔoꞁᗺ ʎɐꞁdsᴉᗡ", "dictionary.mekanism.chemical": "ꞁɐɔᴉɯǝɥƆ", "dictionary.mekanism.chemical.desc": "sᵷɐ⟘ ꞁɐɔᴉɯǝɥƆ ʎɐꞁdsᴉᗡ", diff --git a/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json b/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json index 3c10ae75f97..d78477a49c4 100644 --- a/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json +++ b/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json @@ -2132,7 +2132,7 @@ "dictionary.mekanism.attribute.desc": "Display Attribute Tags", "dictionary.mekanism.block": "Block", "dictionary.mekanism.block.desc": "Display Block Tags", - "dictionary.mekanism.block_entity_type": "Block Entity Type", + "dictionary.mekanism.block_entity_type": "BE Type", "dictionary.mekanism.block_entity_type.desc": "Display Block Entity Type Tags", "dictionary.mekanism.chemical": "Chemical", "dictionary.mekanism.chemical.desc": "Display Chemical Tags", diff --git a/src/datagen/generated/mekanism/data/mekanism/computer_help/jekyll.md b/src/datagen/generated/mekanism/data/mekanism/computer_help/jekyll.md index 910ba5bb439..8816e3b2faf 100644 --- a/src/datagen/generated/mekanism/data/mekanism/computer_help/jekyll.md +++ b/src/datagen/generated/mekanism/data/mekanism/computer_help/jekyll.md @@ -4495,5 +4495,5 @@ methods: returns: java_type: boolean type: boolean -version: 10.7.5 +version: 10.7.7 --- diff --git a/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java b/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java index 1d8dd9cf477..4cec72f0704 100644 --- a/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java +++ b/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java @@ -1244,7 +1244,7 @@ private void addMisc() { add(MekanismLang.DICTIONARY_MOB_EFFECT_DESC, "Display Mob Effect Tags"); add(MekanismLang.DICTIONARY_ENCHANTMENT, "Enchantment"); add(MekanismLang.DICTIONARY_ENCHANTMENT_DESC, "Display Enchantment Tags"); - add(MekanismLang.DICTIONARY_BLOCK_ENTITY_TYPE, "Block Entity Type"); + add(MekanismLang.DICTIONARY_BLOCK_ENTITY_TYPE, "BE Type"); add(MekanismLang.DICTIONARY_BLOCK_ENTITY_TYPE_DESC, "Display Block Entity Type Tags"); add(MekanismLang.DICTIONARY_CHEMICAL, "Chemical"); add(MekanismLang.DICTIONARY_CHEMICAL_DESC, "Display Chemical Tags"); diff --git a/src/datagen/main/java/mekanism/common/integration/crafttweaker/example/component/CrTExampleRecipeComponentBuilder.java b/src/datagen/main/java/mekanism/common/integration/crafttweaker/example/component/CrTExampleRecipeComponentBuilder.java index 0ccd56d16ca..58350e82404 100644 --- a/src/datagen/main/java/mekanism/common/integration/crafttweaker/example/component/CrTExampleRecipeComponentBuilder.java +++ b/src/datagen/main/java/mekanism/common/integration/crafttweaker/example/component/CrTExampleRecipeComponentBuilder.java @@ -274,7 +274,7 @@ private void validate() { for (RecipeMethod method : methods) { if (!method.hasExample) { StringBuilder signature = new StringBuilder(method.methodName); - signature.append("("); + signature.append('('); method.appendParameters(signature, (sb, name, type, generic) -> { sb.append(type.getSimpleName()) .append(' ') @@ -285,7 +285,7 @@ private void validate() { .append('>'); } }); - signature.append(")"); + signature.append(')'); throw new RuntimeException("Recipe method: '" + signature + "' has no example usage declared."); } } diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java b/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java index d874f9d773f..b28c2a4a0be 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java @@ -25,7 +25,7 @@ public class GuiSupportedUpgrades extends GuiElement { private static final Component SUPPORTED = MekanismLang.UPGRADES_SUPPORTED.translate(); - private static final int ELEMENT_WIDTH = 125; + private static final int ELEMENT_WIDTH = 167; private static final int PADDED_ELEMENT_WIDTH = ELEMENT_WIDTH - 2; private static final int ELEMENT_SIZE = 12; private static final int ROW_ROOM = PADDED_ELEMENT_WIDTH / ELEMENT_SIZE; diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiInstallableScrollList.java b/src/main/java/mekanism/client/gui/element/scroll/GuiInstallableScrollList.java new file mode 100644 index 00000000000..f2acd66975f --- /dev/null +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiInstallableScrollList.java @@ -0,0 +1,130 @@ +package mekanism.client.gui.element.scroll; + +import java.util.List; +import mekanism.api.text.EnumColor; +import mekanism.client.gui.IGuiWrapper; +import mekanism.client.render.MekanismRenderer; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.navigation.ScreenRectangle; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public abstract class GuiInstallableScrollList extends GuiScrollList { + + private final ResourceLocation texture; + private final int textureWidth; + private final int textureHeight; + @Nullable + protected TYPE selectedType; + @Nullable + protected ScreenRectangle cachedTooltipRect; + + protected GuiInstallableScrollList(IGuiWrapper gui, int x, int y, int height, ResourceLocation background, int backgroundSideSize, + ResourceLocation texture, int textureWidth, int textureHeight) { + super(gui, x, y, textureWidth + 8, height, textureHeight / 3, background, backgroundSideSize); + this.texture = texture; + this.textureWidth = textureWidth; + this.textureHeight = textureHeight; + } + + protected abstract List getCurrentInstalled(); + + protected abstract void drawName(GuiGraphics guiGraphics, TYPE type, int multipliedElement); + + protected abstract ItemStack getRenderStack(TYPE type); + + @Nullable + public TYPE getSelection() { + return selectedType; + } + + @Override + public boolean hasSelection() { + return selectedType != null; + } + + @Override + protected int getMaxElements() { + return getCurrentInstalled().size(); + } + + @Override + protected void setSelected(int index) { + if (index >= 0) { + List currentInstalled = getCurrentInstalled(); + if (index < currentInstalled.size()) { + setSelected(currentInstalled.get(index)); + } + } + } + + protected abstract void setSelected(TYPE newType); + + @Override + public void clearSelection() { + setSelected(null); + } + + @Override + public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { + super.renderForeground(guiGraphics, mouseX, mouseY); + int currentSelection = getCurrentSelection(); + List currentInstalled = getCurrentInstalled(); + int max = Math.min(getFocusedElements(), currentInstalled.size()); + for (int i = 0; i < max; i++) { + drawName(guiGraphics, currentInstalled.get(currentSelection + i), 3 + i * elementHeight); + } + } + + protected void drawNameText(GuiGraphics guiGraphics, int y, Component name, int color, float scale) { + drawScaledScrollingString(guiGraphics, name, 13, y, TextAlignment.LEFT, color, barXShift - 16, 0, false, scale); + } + + @NotNull + @Override + protected ScreenRectangle getTooltipRectangle(int mouseX, int mouseY) { + return cachedTooltipRect == null ? super.getTooltipRectangle(mouseX, mouseY) : cachedTooltipRect; + } + + @Nullable + protected EnumColor getColor(TYPE type) { + return null; + } + + @Override + public void renderElements(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { + //Draw elements + List currentInstalled = getCurrentInstalled(); + int currentSelection = getCurrentSelection(); + int max = Math.min(getFocusedElements(), currentInstalled.size()); + for (int i = 0; i < max; i++) { + TYPE type = currentInstalled.get(currentSelection + i); + int multipliedElement = i * elementHeight; + int shiftedY = getY() + 1 + multipliedElement; + int j = 1; + if (type == getSelection()) { + j = 2; + } else if (mouseX >= getX() + 1 && mouseX < getX() + barXShift - 1 && mouseY >= shiftedY && mouseY < shiftedY + elementHeight) { + j = 0; + } + EnumColor color = getColor(type); + if (color != null) { + MekanismRenderer.color(guiGraphics, color); + } + guiGraphics.blit(texture, relativeX + 1, relativeY + 1 + multipliedElement, 0, elementHeight * j, textureWidth, + elementHeight, textureWidth, textureHeight); + if (color != null) { + MekanismRenderer.resetColor(guiGraphics); + } + } + //Note: This needs to be in its own loop as rendering the items is likely to cause the texture manager to be bound to a different texture + // and thus would make the selection area background get all screwed up + for (int i = 0; i < max; i++) { + TYPE type = currentInstalled.get(currentSelection + i); + gui().renderItem(guiGraphics, getRenderStack(type), relativeX + 3, relativeY + 3 + i * elementHeight, 0.5F); + } + } +} \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java b/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java index d4b93413949..ca653a49553 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiModuleScrollList.java @@ -3,13 +3,11 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import java.util.function.ObjIntConsumer; import java.util.function.Supplier; import mekanism.api.gear.IModule; import mekanism.api.gear.ModuleData; import mekanism.api.gear.ModuleData.ExclusiveFlag; import mekanism.api.text.EnumColor; -import mekanism.api.text.TextComponentUtil; import mekanism.client.gui.IGuiWrapper; import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.GuiElementHolder; @@ -26,14 +24,11 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class GuiModuleScrollList extends GuiScrollList { +public class GuiModuleScrollList extends GuiInstallableScrollList> { private static final ResourceLocation MODULE_SELECTION = MekanismUtils.getResource(ResourceType.GUI, "module_selection.png"); - private static final int TEXTURE_WIDTH = 112; - private static final int TEXTURE_HEIGHT = 36; private final Consumer> callback; private final List> currentList = new ArrayList<>(); @@ -41,18 +36,14 @@ public class GuiModuleScrollList extends GuiScrollList { private ItemStack currentItem; @Nullable private ModuleContainer currentContainer; - @Nullable - private ModuleData selected; @Nullable private Component lastInfo = null; @Nullable private Tooltip lastTooltip; - @Nullable - private ScreenRectangle cachedTooltipRect; public GuiModuleScrollList(IGuiWrapper gui, int x, int y, int height, Supplier itemSupplier, Consumer> callback) { - super(gui, x, y, TEXTURE_WIDTH + 8, height, TEXTURE_HEIGHT / 3, GuiElementHolder.HOLDER, GuiElementHolder.HOLDER_SIZE); + super(gui, x, y, height, GuiElementHolder.HOLDER, GuiElementHolder.HOLDER_SIZE, MODULE_SELECTION, 112, 36); this.itemSupplier = itemSupplier; this.callback = callback; updateItemAndList(itemSupplier.get()); @@ -85,74 +76,55 @@ private void recheckItem() { } @Override - protected int getMaxElements() { - return currentList.size(); - } - - @Override - public boolean hasSelection() { - return selected != null; - } - - @Override - protected void setSelected(int index) { - if (index >= 0 && index < currentList.size()) { - setSelected(currentList.get(index)); - } - } - - private void setSelected(@Nullable ModuleData newData) { - if (selected != newData) { - selected = newData; + protected void setSelected(@Nullable ModuleData newData) { + if (selectedType != newData) { + selectedType = newData; onSelectedChange(); } } private void onSelectedChange() { - if (selected == null || currentContainer == null) { + if (selectedType == null || currentContainer == null) { callback.accept(null); } else { - callback.accept(currentContainer.get(selected)); + callback.accept(currentContainer.get(selectedType)); } } - @Nullable - public ModuleData getSelection() { - return selected; + @Override + protected List> getCurrentInstalled() { + return currentList; } @Override - public void clearSelection() { - setSelected(null); + protected void drawName(GuiGraphics guiGraphics, ModuleData module, int y) { + if (currentContainer != null) { + IModule instance = currentContainer.get(module); + if (instance != null) { + boolean enabled = instance.isEnabled(); + int color = module.isExclusive(ExclusiveFlag.ANY) ? (enabled ? 0x635BD4 : 0x2E2A69) : (enabled ? titleTextColor() : 0x5E1D1D); + drawNameText(guiGraphics, y, module.getTextComponent(), color, 0.7F); + } + } } @Override - public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { - super.renderForeground(guiGraphics, mouseX, mouseY); - recheckItem(); - forEachModule((module, multipliedElement) -> { - if (currentContainer != null) { - IModule instance = currentContainer.get(module); - if (instance != null) { - boolean enabled = instance.isEnabled(); - int color = module.isExclusive(ExclusiveFlag.ANY) ? (enabled ? 0x635BD4 : 0x2E2A69) : (enabled ? titleTextColor() : 0x5E1D1D); - drawScaledScrollingString(guiGraphics, TextComponentUtil.build(module), 11, 3 + multipliedElement, TextAlignment.LEFT, color, barXShift - 12, 2, false, 0.7F); - } - } - }); + protected ItemStack getRenderStack(ModuleData moduleData) { + return moduleData.getItemProvider().getItemStack(); } - @NotNull @Override - protected ScreenRectangle getTooltipRectangle(int mouseX, int mouseY) { - return cachedTooltipRect == null ? super.getTooltipRectangle(mouseX, mouseY) : cachedTooltipRect; + public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { + recheckItem(); + super.renderForeground(guiGraphics, mouseX, mouseY); } @Override public void updateTooltip(int mouseX, int mouseY) { if (currentContainer != null && mouseX >= getX() + 1 && mouseX < getX() + barXShift - 1) { - for (int i = 0; i < getFocusedElements(); i++) { - int index = getCurrentSelection() + i; + int currentSelection = getCurrentSelection(); + for (int i = 0, focused = getFocusedElements(); i < focused; i++) { + int index = currentSelection + i; if (index > currentList.size() - 1) { break; } @@ -176,32 +148,6 @@ public void updateTooltip(int mouseX, int mouseY) { setTooltip(lastTooltip = null); } - @Override - public void renderElements(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { - //Draw elements - forEachModule((module, multipliedElement) -> { - int shiftedY = getY() + 1 + multipliedElement; - int j = 1; - if (module == getSelection()) { - j = 2; - } else if (mouseX >= getX() + 1 && mouseX < getX() + barXShift - 1 && mouseY >= shiftedY && mouseY < shiftedY + elementHeight) { - j = 0; - } - guiGraphics.blit(MODULE_SELECTION, relativeX + 1, relativeY + 1 + multipliedElement, 0, elementHeight * j, TEXTURE_WIDTH, elementHeight, TEXTURE_WIDTH, TEXTURE_HEIGHT); - }); - //Note: This needs to be in its own loop as rendering the items is likely to cause the texture manager to be bound to a different texture - // and thus would make the selection area background get all screwed up - forEachModule((module, multipliedElement) -> gui().renderItem(guiGraphics, module.getItemProvider().getItemStack(), relativeX + 3, relativeY + 3 + multipliedElement, 0.5F)); - } - - private void forEachModule(ObjIntConsumer> consumer) { - int currentSelection = getCurrentSelection(); - int max = Math.min(getFocusedElements(), currentList.size()); - for (int i = 0; i < max; i++) { - consumer.accept(currentList.get(currentSelection + i), elementHeight * i); - } - } - @Override public void syncFrom(GuiElement element) { super.syncFrom(element); @@ -210,12 +156,12 @@ public void syncFrom(GuiElement element) { //If the item is the same just change what module data we have as our selected // and don't notify the callback with a fresh read of the module data as it // should have the data it expects already - selected = old.selected; - } else if (old.selected != null) { - if (currentList.contains(old.selected)) { + selectedType = old.selectedType; + } else if (old.selectedType != null) { + if (currentList.contains(old.selectedType)) { //If the item doesn't match (in general it will) and it still has the corresponding module, // we need to update the selected value and fire the corresponding callbacks - setSelected(old.selected); + setSelected(old.selectedType); } else { //If the data is no longer present we need to fire the callbacks to ensure we propagate the clear to the current selection onSelectedChange(); diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java b/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java index 3235ba49f16..fd6aae07287 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiUpgradeScrollList.java @@ -1,16 +1,15 @@ package mekanism.client.gui.element.scroll; +import java.util.ArrayList; import java.util.EnumMap; +import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.function.ObjIntConsumer; import mekanism.api.Upgrade; -import mekanism.api.text.TextComponentUtil; +import mekanism.api.text.EnumColor; import mekanism.client.gui.IGuiWrapper; import mekanism.client.gui.element.GuiElement; import mekanism.client.gui.element.GuiElementHolder; import mekanism.client.gui.tooltip.TooltipUtils; -import mekanism.client.render.MekanismRenderer; import mekanism.common.tile.component.TileComponentUpgrade; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; @@ -19,92 +18,68 @@ import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.NotNull; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; -public class GuiUpgradeScrollList extends GuiScrollList { +public class GuiUpgradeScrollList extends GuiInstallableScrollList { private static final ResourceLocation UPGRADE_SELECTION = MekanismUtils.getResource(ResourceType.GUI, "upgrade_selection.png"); - private static final int TEXTURE_WIDTH = 58; - private static final int TEXTURE_HEIGHT = 36; private final Map tooltips = new EnumMap<>(Upgrade.class); private final TileComponentUpgrade component; private final Runnable onSelectionChange; - @Nullable - private Upgrade selectedType; - @Nullable - private ScreenRectangle cachedTooltipRect; - public GuiUpgradeScrollList(IGuiWrapper gui, int x, int y, int width, int height, TileComponentUpgrade component, Runnable onSelectionChange) { - super(gui, x, y, width, height, TEXTURE_HEIGHT / 3, GuiElementHolder.HOLDER, GuiElementHolder.HOLDER_SIZE); + public GuiUpgradeScrollList(IGuiWrapper gui, int x, int y, int height, TileComponentUpgrade component, Runnable onSelectionChange) { + super(gui, x, y, height, GuiElementHolder.HOLDER, GuiElementHolder.HOLDER_SIZE, UPGRADE_SELECTION, 100, 36); this.component = component; this.onSelectionChange = onSelectionChange; } - private Set getCurrentUpgrades() { - return component.getInstalledTypes(); - } - @Override protected int getMaxElements() { - return getCurrentUpgrades().size(); + return component.getInstalledTypes().size(); } @Override - public boolean hasSelection() { - return selectedType != null; - } - - @Override - protected void setSelected(int index) { - Set currentUpgrades = getCurrentUpgrades(); - if (index >= 0 && index < currentUpgrades.size()) { - Upgrade newSelection = currentUpgrades.toArray(new Upgrade[0])[index]; - if (selectedType != newSelection) { - selectedType = newSelection; - onSelectionChange.run(); - } + protected void setSelected(Upgrade newSelection) { + if (selectedType != newSelection) { + selectedType = newSelection; + onSelectionChange.run(); } } - @Nullable - public Upgrade getSelection() { - return selectedType; + @Override + protected List getCurrentInstalled() { + return new ArrayList<>(component.getInstalledTypes()); } @Override - public void clearSelection() { - if (selectedType != null) { - selectedType = null; - onSelectionChange.run(); - } + protected void drawName(GuiGraphics guiGraphics, Upgrade upgrade, int y) { + drawNameText(guiGraphics, y, upgrade.getTranslatedName(), titleTextColor(), 1F); } @Override - public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { - super.renderForeground(guiGraphics, mouseX, mouseY); - forEachUpgrade((upgrade, multipliedElement) -> drawScrollingString(guiGraphics, TextComponentUtil.build(upgrade), 12, 3 + multipliedElement, - TextAlignment.LEFT, titleTextColor(), barXShift - 14, 2, false)); + protected ItemStack getRenderStack(Upgrade upgrade) { + return UpgradeUtils.getStack(upgrade); } - @NotNull + @Nullable @Override - protected ScreenRectangle getTooltipRectangle(int mouseX, int mouseY) { - return cachedTooltipRect == null ? super.getTooltipRectangle(mouseX, mouseY) : cachedTooltipRect; + protected EnumColor getColor(Upgrade upgrade) { + return upgrade.getColor(); } @Override public void updateTooltip(int mouseX, int mouseY) { if (mouseX >= getX() + 1 && mouseX < getX() + barXShift - 1) { - Upgrade[] upgrades = getCurrentUpgrades().toArray(new Upgrade[0]); + List currentInstalled = getCurrentInstalled(); int currentSelection = getCurrentSelection(); - for (int i = 0; i < getFocusedElements(); i++) { + for (int i = 0, focused = getFocusedElements(); i < focused; i++) { int index = currentSelection + i; - if (index > upgrades.length - 1) { + if (index > currentInstalled.size() - 1) { break; } - Upgrade upgrade = upgrades[index]; + Upgrade upgrade = currentInstalled.get(index); int multipliedElement = elementHeight * i; if (mouseY >= getY() + 1 + multipliedElement && mouseY < getY() + 1 + multipliedElement + elementHeight) { cachedTooltipRect = new ScreenRectangle(getX() + 1, getY() + 1 + multipliedElement, barXShift - 2, elementHeight); @@ -123,30 +98,7 @@ public void renderElements(GuiGraphics guiGraphics, int mouseX, int mouseY, floa if (hasSelection() && component.getUpgrades(getSelection()) == 0) { clearSelection(); } - forEachUpgrade((upgrade, multipliedElement) -> { - int shiftedY = getY() + 1 + multipliedElement; - int j = 1; - if (upgrade == getSelection()) { - j = 2; - } else if (mouseX >= getX() + 1 && mouseX < getX() + barXShift - 1 && mouseY >= shiftedY && mouseY < shiftedY + elementHeight) { - j = 0; - } - MekanismRenderer.color(guiGraphics, upgrade.getColor()); - guiGraphics.blit(UPGRADE_SELECTION, relativeX + 1, relativeY + 1 + multipliedElement, 0, elementHeight * j, TEXTURE_WIDTH, elementHeight, TEXTURE_WIDTH, TEXTURE_HEIGHT); - MekanismRenderer.resetColor(guiGraphics); - }); - //Note: This needs to be in its own loop as rendering the items is likely to cause the texture manager to be bound to a different texture - // and thus would make the selection area background get all screwed up - forEachUpgrade((upgrade, multipliedElement) -> gui().renderItem(guiGraphics, UpgradeUtils.getStack(upgrade), relativeX + 3, relativeY + 3 + multipliedElement, 0.5F)); - } - - private void forEachUpgrade(ObjIntConsumer consumer) { - Upgrade[] upgrades = getCurrentUpgrades().toArray(new Upgrade[0]); - int currentSelection = getCurrentSelection(); - int max = Math.min(getFocusedElements(), upgrades.length); - for (int i = 0; i < max; i++) { - consumer.accept(upgrades[currentSelection + i], elementHeight * i); - } + super.renderElements(guiGraphics, mouseX, mouseY, partialTicks); } @Override diff --git a/src/main/java/mekanism/client/gui/element/tab/window/GuiUpgradeWindowTab.java b/src/main/java/mekanism/client/gui/element/tab/window/GuiUpgradeWindowTab.java index 477d55c8546..229b733d42a 100644 --- a/src/main/java/mekanism/client/gui/element/tab/window/GuiUpgradeWindowTab.java +++ b/src/main/java/mekanism/client/gui/element/tab/window/GuiUpgradeWindowTab.java @@ -30,7 +30,7 @@ protected void colorTab(GuiGraphics guiGraphics) { @Override protected GuiWindow createWindow(SelectedWindowData windowData) { - return new GuiUpgradeWindow(gui(), (getGuiWidth() - 156) / 2, 15, dataSource, windowData); + return new GuiUpgradeWindow(gui(), (getGuiWidth() - 198) / 2, 15, dataSource, windowData); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java index 83cc3d27a30..597f8c1a362 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java @@ -38,18 +38,18 @@ public class GuiUpgradeWindow extends GuiWindow { private final GuiInnerScreen rightScreen; public GuiUpgradeWindow(IGuiWrapper gui, int x, int y, TileEntityMekanism tile, SelectedWindowData windowData) { - super(gui, x, y, 156, 76 + 12 * GuiSupportedUpgrades.calculateNeededRows(gui), windowData); + super(gui, x, y, 198, 76 + Math.max(18, 12 * GuiSupportedUpgrades.calculateNeededRows(gui)), windowData); if (windowData.type != WindowType.UPGRADE) { throw new IllegalArgumentException("Upgrade windows must have an upgrade window type"); } this.tile = tile; interactionStrategy = InteractionStrategy.ALL; - scrollList = addChild(new GuiUpgradeScrollList(gui, relativeX + 6, relativeY + 18, 66, 50, tile.getComponent(), this::updateEnabledButtons)); + scrollList = addChild(new GuiUpgradeScrollList(gui, relativeX + 6, relativeY + 18, 50, tile.getComponent(), this::updateEnabledButtons)); addChild(new GuiSupportedUpgrades(gui, relativeX + 6, relativeY + 68, tile.getComponent().getSupportedTypes())); - rightScreen = addChild(new GuiInnerScreen(gui, relativeX + 72, relativeY + 18, 59, 50)); - addChild(new GuiProgress(() -> this.tile.getComponent().getScaledUpgradeProgress(), ProgressType.INSTALLING, gui, relativeX + 134, relativeY + 37)); - addChild(new GuiProgress(() -> 0, ProgressType.UNINSTALLING, gui, relativeX + 134, relativeY + 59)); - removeButton = addChild(new DigitalButton(gui, relativeX + 73, relativeY + 54, 56, 12, MekanismLang.UPGRADE_UNINSTALL, (element, mouseX, mouseY) -> { + rightScreen = addChild(new GuiInnerScreen(gui, scrollList.getRelativeRight(), relativeY + 18, 59, 50)); + addChild(new GuiProgress(() -> this.tile.getComponent().getScaledUpgradeProgress(), ProgressType.INSTALLING, gui, rightScreen.getRelativeRight() + 3, relativeY + 37)); + addChild(new GuiProgress(() -> 0, ProgressType.UNINSTALLING, gui, rightScreen.getRelativeRight() + 3, relativeY + 58)); + removeButton = addChild(new DigitalButton(gui, scrollList.getRelativeRight() + 1, relativeY + 54, 56, 12, MekanismLang.UPGRADE_UNINSTALL, (element, mouseX, mouseY) -> { if (scrollList.hasSelection()) { return PacketUtils.sendToServer(new PacketGuiInteract(Screen.hasShiftDown() ? GuiInteraction.REMOVE_ALL_UPGRADE : GuiInteraction.REMOVE_UPGRADE, this.tile, scrollList.getSelection().ordinal())); @@ -57,8 +57,8 @@ public GuiUpgradeWindow(IGuiWrapper gui, int x, int y, TileEntityMekanism tile, return false; })).setTooltip(MekanismLang.UPGRADE_UNINSTALL_TOOLTIP); MekanismTileContainer container = (MekanismTileContainer) ((GuiMekanism) gui()).getMenu(); - addChild(new GuiVirtualSlot(this, SlotType.NORMAL, gui, relativeX + 133, relativeY + 18, container.getUpgradeSlot())); - addChild(new GuiVirtualSlot(this, SlotType.NORMAL, gui, relativeX + 133, relativeY + 73, container.getUpgradeOutputSlot())); + addChild(new GuiVirtualSlot(this, SlotType.NORMAL, gui, rightScreen.getRelativeRight() + 2, relativeY + 18, container.getUpgradeSlot())); + addChild(new GuiVirtualSlot(this, SlotType.NORMAL, gui, rightScreen.getRelativeRight() + 2, relativeY + 72, container.getUpgradeOutputSlot())); updateEnabledButtons(); container.startTracking(MekanismContainer.UPGRADE_WINDOW, tile.getComponent()); PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.CONTAINER_TRACK_UPGRADES, tile, MekanismContainer.UPGRADE_WINDOW)); @@ -102,4 +102,9 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { noSelection.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, screenTextColor(), 56, 0.8F); } } + + /*@Override + protected int getTitlePadEnd() { + return super.getTitlePadEnd() + 22; + }*/ } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java index 89d03d4e1a3..70ced1c9fe3 100644 --- a/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java +++ b/src/main/java/mekanism/client/gui/item/GuiSeismicReader.java @@ -37,13 +37,14 @@ import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.BlockHitResult; import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; +import net.neoforged.neoforge.fluids.FluidType; import org.jetbrains.annotations.NotNull; public class GuiSeismicReader extends GuiMekanism { private final List> blockList = new ArrayList<>(); private final Reference2IntMap blockFrequencies = new Reference2IntOpenHashMap<>(); - private final Reference2IntMap fluidFrequencies = new Reference2IntOpenHashMap<>(); + private final Reference2IntMap fluidFrequencies = new Reference2IntOpenHashMap<>(); private final int minHeight; private MekanismButton upButton; private MekanismButton downButton; @@ -77,21 +78,22 @@ public GuiSeismicReader(SeismicReaderContainer container, Inventory inv, Compone if (fluid == Fluids.EMPTY) { blockList.add(new BlockInfo<>(state, state, null)); } else { - blockList.add(new BlockInfo<>(state, fluid, (graphics, f, x, y) -> { + FluidType fluidType = fluid.getFluidType(); + blockList.add(new BlockInfo<>(state, fluidType, (graphics, f, x, y) -> { IClientFluidTypeExtensions properties = IClientFluidTypeExtensions.of(f); MekanismRenderer.color(graphics, properties.getTintColor()); TextureAtlasSprite texture = MekanismRenderer.getSprite(properties.getStillTexture()); graphics.blit(x, y, 0, 16, 16, texture); MekanismRenderer.resetColor(graphics); })); - fluidFrequencies.mergeInt(fluid, 1, Integer::sum); + fluidFrequencies.mergeInt(fluidType, 1, Integer::sum); } } else { blockList.add(new BlockInfo<>(state, stack, this::renderItem)); FluidState fluid = state.getFluidState(); if (!fluid.isEmpty()) {//Take the fluid into account for frequency count //TODO: Do we want to render the fact that it is fluid logged in some way? - fluidFrequencies.mergeInt(fluid.getType(), 1, Integer::sum); + fluidFrequencies.mergeInt(fluid.getFluidType(), 1, Integer::sum); } } } @@ -106,14 +108,19 @@ protected void addGuiElements() { if (currentLayer >= 0) { List text = new ArrayList<>(4); BlockInfo blockInfo = blockList.get(currentLayer); - Block block = blockInfo.block(); - if (!(block instanceof LiquidBlock)) {//If the block is a liquid, let the fluid handling display and calculate the quantity + BlockState state = blockInfo.state(); + Block block = state.getBlock(); + if (!(block instanceof LiquidBlock)) { + //If the block is a liquid, let the fluid handling display and calculate the quantity + //Note: Bubble columns, still get counted so that we display it is a bubble column, and how many there are + //TODO: Do we want to try and make it so that the first few lines of the block's name wraps instead of scrolls + // for very long names like waxed oxidized copper stairs? text.add(block.getName()); text.add(MekanismLang.ABUNDANCY.translate(blockFrequencies.getInt(block))); } - if (blockInfo.type() instanceof Fluid fluid) {//TODO: Improve this so it actually displays for fluid logged blocks - text.add(fluid.getFluidType().getDescription()); - text.add(MekanismLang.ABUNDANCY.translate(fluidFrequencies.getInt(fluid))); + if (blockInfo.type() instanceof FluidType fluidType) {//TODO: Improve this so it actually displays for fluid logged blocks + text.add(fluidType.getDescription()); + text.add(MekanismLang.ABUNDANCY.translate(fluidFrequencies.getInt(fluidType))); } return text; } @@ -186,10 +193,6 @@ public boolean mouseScrolled(double mouseX, double mouseY, double xDelta, double private record BlockInfo(BlockState state, TYPE type, RenderTarget renderTarget) { - public Block block() { - return state.getBlock(); - } - public void render(GuiGraphics guiGraphics, int x, int y) { renderTarget.render(guiGraphics, type, x, y); } diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index e7c2d93417e..78959011a5c 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -281,7 +281,7 @@ StringBuilder addWord(StringBuilder lineBuilder, StringBuilder wordBuilder, int lineLength = wordLength; } else { if (spacingLength > 0) { - lineBuilder.append(" "); + lineBuilder.append(' '); } lineBuilder.append(wordBuilder); lineLength += spacingLength + wordLength; diff --git a/src/main/resources/assets/mekanism/gui/upgrade_selection.png b/src/main/resources/assets/mekanism/gui/upgrade_selection.png index 25409664de4ec47180c5c065a591a0535c48a4eb..58a624373f93016774e91b5316d81243db04a0e4 100644 GIT binary patch delta 176 zcmcb{c%Mw zj-v&E0vvn71o^`ZVoDgBf)_`z&7P*6-q2v8t8L}M%Cp;()mp;LfT59{bJ`Ze9EQsJ z<13~eT$ajh;pTbi(lj@%ga9Sc6-F8jmu6&Yd{mg@cu<04Sznf9PSliiCdSODL#I7i a8Im;`qObi;{{eIZgQqK-pUXO@geCxo3^+Id delta 166 zcmcc5c#To9Gr-TCmrII^fq{Y7)59eQNLvB13JWuk)bcd>Fj3L6Cf(D;F~q_@c}F+< zounNa94v9GH#CXzh{rZOxN>6R-Xb=Rf>Y~W9AK6xd(3DpVP?S4$X>QKmq*%R-7UkS zlzopr09R}`WB>pF From 089628395c88c34b93a6046a8b128604ae669311 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Sun, 6 Oct 2024 10:31:40 -0500 Subject: [PATCH 13/17] Don't draw the shadow behind text for digital buttons, and fix button text y value being slightly off --- .../element/button/ReactorLogicButton.java | 4 +- .../client/gui/element/GuiElement.java | 13 +++-- .../gui/element/button/BasicColorButton.java | 4 +- .../gui/element/button/ColorButton.java | 4 +- .../gui/element/button/DigitalButton.java | 5 ++ .../gui/element/button/FilterButton.java | 3 +- .../element/button/FilterSelectButton.java | 4 +- .../element/button/MekanismImageButton.java | 4 +- .../gui/element/button/RadioButton.java | 3 +- .../client/gui/element/text/GuiTextField.java | 4 +- .../gui/element/window/GuiUpgradeWindow.java | 5 -- .../client/gui/robit/GuiRobitMain.java | 3 +- .../client/render/IFancyFontRenderer.java | 51 ++++++++++--------- 13 files changed, 60 insertions(+), 47 deletions(-) diff --git a/src/generators/java/mekanism/generators/client/gui/element/button/ReactorLogicButton.java b/src/generators/java/mekanism/generators/client/gui/element/button/ReactorLogicButton.java index 75aa3e8d698..d88f799db47 100644 --- a/src/generators/java/mekanism/generators/client/gui/element/button/ReactorLogicButton.java +++ b/src/generators/java/mekanism/generators/client/gui/element/button/ReactorLogicButton.java @@ -17,7 +17,7 @@ import mekanism.generators.common.base.IReactorLogicMode; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,7 +42,7 @@ public ReactorLogicButton(IGuiWrapper gui, int x, int y, int index, @NotNull IRe } private ReactorLogicButton(IGuiWrapper gui, int x, int y, @NotNull IReactorLogic tile, Class clazz, Consumer onPress, Supplier<@Nullable TYPE> modeSupplier) { - super(gui, x, y, 128, 22, Component.empty(), (element, mouseX, mouseY) -> ((ReactorLogicButton) element).click()); + super(gui, x, y, 128, 22, CommonComponents.EMPTY, (element, mouseX, mouseY) -> ((ReactorLogicButton) element).click()); this.onPress = onPress; this.modeSupplier = modeSupplier; this.tile = tile; diff --git a/src/main/java/mekanism/client/gui/element/GuiElement.java b/src/main/java/mekanism/client/gui/element/GuiElement.java index cba0909ff9d..0b794b52a88 100644 --- a/src/main/java/mekanism/client/gui/element/GuiElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiElement.java @@ -36,6 +36,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.client.sounds.SoundManager; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; @@ -77,7 +78,7 @@ public abstract class GuiElement extends AbstractWidget implements IFancyFontRen private boolean isDragging; public GuiElement(IGuiWrapper gui, int x, int y, int width, int height) { - this(gui, x, y, width, height, Component.empty()); + this(gui, x, y, width, height, CommonComponents.EMPTY); } public GuiElement(IGuiWrapper gui, int x, int y, int width, int height, Component text) { @@ -619,15 +620,19 @@ protected int getButtonTextColor(int mouseX, int mouseY) { return getFGColor(); } + protected boolean displayButtonTextShadow() { + return true; + } + protected void drawButtonText(GuiGraphics guiGraphics, int mouseX, int mouseY) { Component text = getMessage(); //Only attempt to draw the message if we have a message to draw if (!text.getString().isEmpty()) { int color = getButtonTextColor(mouseX, mouseY) | Mth.ceil(alpha * 255.0F) << 24; - //TODO - 1.21: Do we want to be passing false to this so that it has no shadow? I believe previously we didn't render the shadow - // but vanilla does render the shadow for buttons, so I think we may want to be rendering it? + //Note: We add one to the button height as it is considered bounds, and we want to include the bottom pixel of the button in our calculations of where the text should land //Note: We call super as currently getButtonX and getButtonY already factor in the relative positioning - IFancyFontRenderer.super.drawScrollingString(guiGraphics, text, getButtonX(), getButtonY(), TextAlignment.CENTER, color, getButtonWidth(), getButtonHeight(), 2, true); + IFancyFontRenderer.super.drawScrollingString(guiGraphics, text, getButtonX(), getButtonY(), TextAlignment.CENTER, color, getButtonWidth(), + getButtonHeight() + 1, 2, displayButtonTextShadow()); } } diff --git a/src/main/java/mekanism/client/gui/element/button/BasicColorButton.java b/src/main/java/mekanism/client/gui/element/button/BasicColorButton.java index d1217737c82..9fb13751122 100644 --- a/src/main/java/mekanism/client/gui/element/button/BasicColorButton.java +++ b/src/main/java/mekanism/client/gui/element/button/BasicColorButton.java @@ -7,7 +7,7 @@ import mekanism.client.render.MekanismRenderer; import mekanism.common.lib.Color; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.CommonComponents; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,7 +20,7 @@ public static BasicColorButton toggle(IGuiWrapper gui, int x, int y, int size, E private final Supplier colorSupplier; public BasicColorButton(IGuiWrapper gui, int x, int y, int size, Supplier color, @NotNull IClickable onLeftClick, @Nullable IClickable onRightClick) { - super(gui, x, y, size, size, Component.empty(), onLeftClick, onRightClick); + super(gui, x, y, size, size, CommonComponents.EMPTY, onLeftClick, onRightClick); this.colorSupplier = color; } diff --git a/src/main/java/mekanism/client/gui/element/button/ColorButton.java b/src/main/java/mekanism/client/gui/element/button/ColorButton.java index 030dade289a..595929389f3 100644 --- a/src/main/java/mekanism/client/gui/element/button/ColorButton.java +++ b/src/main/java/mekanism/client/gui/element/button/ColorButton.java @@ -9,7 +9,7 @@ import mekanism.common.MekanismLang; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.CommonComponents; import org.jetbrains.annotations.NotNull; public class ColorButton extends MekanismButton { @@ -20,7 +20,7 @@ public class ColorButton extends MekanismButton { private final Supplier colorSupplier; public ColorButton(IGuiWrapper gui, int x, int y, int width, int height, Supplier colorSupplier, @NotNull IClickable onPress, @NotNull IClickable onRightClick) { - super(gui, x, y, width, height, Component.empty(), onPress, onRightClick); + super(gui, x, y, width, height, CommonComponents.EMPTY, onPress, onRightClick); this.colorSupplier = colorSupplier; } diff --git a/src/main/java/mekanism/client/gui/element/button/DigitalButton.java b/src/main/java/mekanism/client/gui/element/button/DigitalButton.java index 0ea1fc5e474..eb6e00b7207 100644 --- a/src/main/java/mekanism/client/gui/element/button/DigitalButton.java +++ b/src/main/java/mekanism/client/gui/element/button/DigitalButton.java @@ -22,4 +22,9 @@ protected int getButtonTextColor(int mouseX, int mouseY) { } return Color.argb(screenTextColor()).darken(0.4).argb(); } + + @Override + protected boolean displayButtonTextShadow() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/element/button/FilterButton.java b/src/main/java/mekanism/client/gui/element/button/FilterButton.java index a0ae1d7206d..88450ee6b16 100644 --- a/src/main/java/mekanism/client/gui/element/button/FilterButton.java +++ b/src/main/java/mekanism/client/gui/element/button/FilterButton.java @@ -28,6 +28,7 @@ import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -59,7 +60,7 @@ private static IFilter getFilter(FilterManager filterManager, int index) { public FilterButton(IGuiWrapper gui, int x, int y, int width, int height, int index, IntSupplier filterIndex, FilterManager filterManager, ObjIntConsumer> onPress, IntConsumer toggleButtonPress, Function, List> renderStackSupplier) { - super(gui, x, y, width, height, Component.empty(), (element, mouseX, mouseY) -> { + super(gui, x, y, width, height, CommonComponents.EMPTY, (element, mouseX, mouseY) -> { FilterButton button = (FilterButton) element; int actualIndex = button.filterIndex.getAsInt() + button.index; button.onPress.accept(getFilter(button.filterManager, actualIndex), actualIndex); diff --git a/src/main/java/mekanism/client/gui/element/button/FilterSelectButton.java b/src/main/java/mekanism/client/gui/element/button/FilterSelectButton.java index 5426b1d1730..b9f4ea71f60 100644 --- a/src/main/java/mekanism/client/gui/element/button/FilterSelectButton.java +++ b/src/main/java/mekanism/client/gui/element/button/FilterSelectButton.java @@ -6,7 +6,7 @@ import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; @@ -19,7 +19,7 @@ public class FilterSelectButton extends MekanismButton { private final boolean down; public FilterSelectButton(IGuiWrapper gui, int x, int y, boolean down, @NotNull IClickable onPress) { - super(gui, x, y, 11, 7, Component.empty(), onPress); + super(gui, x, y, 11, 7, CommonComponents.EMPTY, onPress); this.down = down; } diff --git a/src/main/java/mekanism/client/gui/element/button/MekanismImageButton.java b/src/main/java/mekanism/client/gui/element/button/MekanismImageButton.java index 1da39c4cfe1..e6c986c7ba4 100644 --- a/src/main/java/mekanism/client/gui/element/button/MekanismImageButton.java +++ b/src/main/java/mekanism/client/gui/element/button/MekanismImageButton.java @@ -2,7 +2,7 @@ import mekanism.client.gui.IGuiWrapper; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; @@ -28,7 +28,7 @@ public MekanismImageButton(IGuiWrapper gui, int x, int y, int width, int height, public MekanismImageButton(IGuiWrapper gui, int x, int y, int width, int height, int textureWidth, int textureHeight, ResourceLocation resource, @NotNull IClickable onLeftClick, @NotNull IClickable onRightClick) { - super(gui, x, y, width, height, Component.empty(), onLeftClick, onRightClick); + super(gui, x, y, width, height, CommonComponents.EMPTY, onLeftClick, onRightClick); this.resourceLocation = resource; this.textureWidth = textureWidth; this.textureHeight = textureHeight; diff --git a/src/main/java/mekanism/client/gui/element/button/RadioButton.java b/src/main/java/mekanism/client/gui/element/button/RadioButton.java index f45f999db2d..5f24989b6de 100644 --- a/src/main/java/mekanism/client/gui/element/button/RadioButton.java +++ b/src/main/java/mekanism/client/gui/element/button/RadioButton.java @@ -8,6 +8,7 @@ import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; @@ -22,7 +23,7 @@ public class RadioButton extends MekanismButton { private final BooleanSupplier toggled; public RadioButton(IGuiWrapper gui, int x, int y, BooleanSupplier toggled, @NotNull IClickable onPress, Component toggledComponent, Component altComponent) { - super(gui, x, y, RADIO_SIZE, RADIO_SIZE, Component.empty(), onPress); + super(gui, x, y, RADIO_SIZE, RADIO_SIZE, CommonComponents.EMPTY, onPress); this.toggled = toggled; this.toggledComponent = TooltipUtils.create(toggledComponent); this.altComponent = TooltipUtils.create(altComponent); diff --git a/src/main/java/mekanism/client/gui/element/text/GuiTextField.java b/src/main/java/mekanism/client/gui/element/text/GuiTextField.java index e9d0ce33053..3730a31b57f 100644 --- a/src/main/java/mekanism/client/gui/element/text/GuiTextField.java +++ b/src/main/java/mekanism/client/gui/element/text/GuiTextField.java @@ -17,6 +17,7 @@ import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.events.ContainerEventHandler; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import net.minecraft.util.StringUtil; @@ -60,7 +61,7 @@ public GuiTextField(IGuiWrapper gui, ContainerEventHandler parent, int x, int y, super(gui, x, y, width, height); this.parent = parent; - textField = new ClearingEditBox(font(), getX(), getY(), width, height, Component.empty()); + textField = new ClearingEditBox(font(), getX(), getY(), width, height, CommonComponents.EMPTY); textField.setBordered(false); textField.setResponder(s -> { if (responder != null) { @@ -216,6 +217,7 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou // hacky. we should write our own renderer at some point. float reverse = (1 - textScale) / textScale; pose.scale(textScale, textScale, textScale); + //Note: We use 4 instead of half line height (4.5) as text fields use 8 for calculating text positioning pose.translate(textField.getX() * reverse, (textField.getY() + 4) * reverse, 0); textField.render(guiGraphics, mouseX, mouseY, partialTicks); } diff --git a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java index 597f8c1a362..5b40963e7eb 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java @@ -102,9 +102,4 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { noSelection.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, screenTextColor(), 56, 0.8F); } } - - /*@Override - protected int getTitlePadEnd() { - return super.getTitlePadEnd() + 22; - }*/ } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java index 05dcd430d7e..6d31e75fab6 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitMain.java @@ -27,6 +27,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; import org.jetbrains.annotations.NotNull; @@ -62,7 +63,7 @@ protected void addGuiElements() { addRenderableWidget(GuiSideHolder.create(this, imageWidth, 6, 106, false, false, SpecialColors.TAB_ROBIT_MENU)); addRenderableWidget(new GuiInnerScreen(this, 27, 16, 122, 56, () -> List.of( MekanismLang.ROBIT_GREETING.translate(robit.getName()), - Component.empty(), + CommonComponents.EMPTY, MekanismLang.ENERGY.translate(EnergyDisplay.of(robit.getEnergyContainer().getEnergy())), MekanismLang.ROBIT_FOLLOWING.translate(robit.getFollowing()), MekanismLang.ROBIT_DROP_PICKUP.translate(robit.getDropPickup()), diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 78959011a5c..79c73b792c9 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -45,7 +45,7 @@ default int inactiveButtonTextColor() { return SpecialColors.TEXT_INACTIVE_BUTTON.argb(); } - default int drawString(GuiGraphics guiGraphics, Component component, float x, float y, int color, boolean shadow) { + private int drawString(GuiGraphics guiGraphics, Component component, float x, float y, int color, boolean shadow) { return guiGraphics.drawString(font(), component.getVisualOrderText(), x, y, color, shadow); } @@ -87,16 +87,20 @@ default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, default void drawScrollingString(GuiGraphics guiGraphics, Component text, int minX, int minY, int maxX, int maxY, TextAlignment alignment, int color, boolean shadow) { int textWidth = getStringWidth(text); + int areaWidth = maxX - minX; + boolean isScrolling = textWidth > areaWidth; //Note: Instead of doing what vanilla does, we divide to float, and don't add one // That way if min and max are not just lineHeight away they will be more accurate, and otherwise it won't render one line below where it should be float targetY = (minY + maxY - getLineHeight()) / 2F; - int areaWidth = maxX - minX; - if (textWidth > areaWidth) { - float targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); - drawString(guiGraphics, text, targetX, targetY, color, shadow); - guiGraphics.disableScissor(); + float targetX; + if (isScrolling) { + targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); } else { - drawString(guiGraphics, text, alignment.getTarget(minX, maxX, areaWidth, textWidth), targetY, color, shadow); + targetX = alignment.getTarget(minX, maxX, areaWidth, textWidth); + } + drawString(guiGraphics, text, targetX, targetY, color, shadow); + if (isScrolling) { + guiGraphics.disableScissor(); } } @@ -121,16 +125,22 @@ default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, return; } float textWidth = getStringWidth(text) * scale; + int areaWidth = maxX - minX; + boolean isScrolling = textWidth > areaWidth; //Note: Instead of doing what vanilla does, we divide to float, and don't add one // That way if min and max are not just lineHeight away they will be more accurate, and otherwise it won't render one line below where it should be float targetY = (minY + maxY - getLineHeight()) / 2F; - int areaWidth = maxX - minX; - if (textWidth > areaWidth) { - float targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); - drawTextWithScale(guiGraphics, text, targetX, targetY, color, shadow, scale); - guiGraphics.disableScissor(); + float targetX; + if (isScrolling) { + targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); } else { - drawTextWithScale(guiGraphics, text, alignment.getTarget(minX, maxX, areaWidth, textWidth), targetY, color, shadow, scale); + targetX = alignment.getTarget(minX, maxX, areaWidth, textWidth); + } + PoseStack pose = prepTextScale(guiGraphics, targetX, targetY, scale); + drawString(guiGraphics, text, 0, 0, color, shadow); + pose.popPose(); + if (isScrolling) { + guiGraphics.disableScissor(); } } @@ -142,10 +152,13 @@ default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, */ private static float prepScrollingString(GuiGraphics guiGraphics, double textWidth, int areaWidth, int minX, int minY, int maxX, int maxY) { double overflowWidth = textWidth - areaWidth; + //TODO: Some variable that keeps track of when the gui was initialized (init method called?) so that we can ensure it always starts + // the text all the way at the left. (For right to left languages we should probably start it all the way at the right) double seconds = Util.getMillis() / 1_000D; double scrollPeriod = Math.max(overflowWidth * AbstractWidget.PERIOD_PER_SCROLLED_PIXEL, AbstractWidget.MIN_SCROLL_PERIOD); + //TODO: Improve this, as it moves very slowly at the edges, and much quicker in the middle double scrolledSoFar = Math.sin((Math.PI / 2) * Math.cos((2 * Math.PI) * seconds / scrollPeriod)) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; - //Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); to calculate overflowedBy. But that is equivalent to just multiplying performing the multiplication + //Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); to calculate overflowedBy. But that is equivalent to just performing the following multiplication double overflowedBy = scrolledSoFar * overflowWidth; //Note: We are drawing in relative coordinates, but GuiGraphics#enableScissor, is expecting absolute coordinates, // so we need to get the translations from our pose stack @@ -159,20 +172,10 @@ private static float prepScrollingString(GuiGraphics guiGraphics, double textWid return minX - (int) overflowedBy; } - private void drawTextWithScale(GuiGraphics guiGraphics, Component text, float x, float y, int color, boolean shadow, float scale) { - PoseStack pose = prepTextScale(guiGraphics, x, y, scale); - drawString(guiGraphics, text, 0, 0, color, shadow); - pose.popPose(); - } - //Note: As translate will implicitly cast x and y to being floats, we might as well pass these in as floats to reduce duplicate code private PoseStack prepTextScale(GuiGraphics guiGraphics, float x, float y, float scale) { PoseStack pose = guiGraphics.pose(); pose.pushPose(); - return prepTextScale(pose, x, y, scale); - } - - private PoseStack prepTextScale(PoseStack pose, float x, float y, float scale) { float halfLineHeight = getLineHeight() / 2F; float yAdd = halfLineHeight - halfLineHeight * scale; pose.translate(x, y + yAdd, 0); From 69de805f44b72002ba43b553d55755602da22d34 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Sat, 12 Oct 2024 11:48:28 -0500 Subject: [PATCH 14/17] Make use of vanilla's line splitter to ensure we properly maintain any styles the component might have --- .../element/window/GuiConfirmationDialog.java | 9 +- .../client/render/IFancyFontRenderer.java | 125 ++++++------------ 2 files changed, 46 insertions(+), 88 deletions(-) diff --git a/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java b/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java index 384f94f1c19..42a15858a35 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java @@ -13,9 +13,9 @@ public class GuiConfirmationDialog extends GuiWindow { private final WrappedTextRenderer wrappedTextRenderer; - private GuiConfirmationDialog(IGuiWrapper gui, int x, int y, int width, int height, Component title, Runnable onConfirm, DialogType type) { + private GuiConfirmationDialog(IGuiWrapper gui, int x, int y, int width, int height, ReplaceableWrappedTextRenderer renderer, Runnable onConfirm, DialogType type) { super(gui, x, y, width, height, WindowType.CONFIRMATION); - this.wrappedTextRenderer = new WrappedTextRenderer(this, title); + this.wrappedTextRenderer = renderer.replaceFont(this); active = true; addChild(new TranslationButton(gui, relativeX + width / 2 - 51, relativeY + height - 24, 50, 18, MekanismLang.BUTTON_CANCEL, this::close)); @@ -27,8 +27,9 @@ private GuiConfirmationDialog(IGuiWrapper gui, int x, int y, int width, int heig public static void show(IGuiWrapper gui, Component title, Runnable onConfirm, DialogType type) { int width = 140; - int height = 33 + WrappedTextRenderer.calculateHeightRequired(gui.font(), title, width, width - 10); - gui.addWindow(new GuiConfirmationDialog(gui, (gui.getXSize() - width) / 2, (gui.getYSize() - height) / 2, width, height, title, onConfirm, type)); + ReplaceableWrappedTextRenderer renderer = new ReplaceableWrappedTextRenderer(gui, width, title); + int height = 33 + renderer.getRequiredHeight(width - 10); + gui.addWindow(new GuiConfirmationDialog(gui, (gui.getXSize() - width) / 2, (gui.getYSize() - height) / 2, width, height, renderer, onConfirm, type)); } @Override diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 79c73b792c9..0c061ce3959 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -1,15 +1,15 @@ package mekanism.client.render; import com.mojang.blaze3d.vertex.PoseStack; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import mekanism.api.text.TextComponentUtil; import mekanism.client.SpecialColors; import net.minecraft.Util; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.network.chat.Component; +import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; import org.joml.Matrix4f; @@ -45,10 +45,6 @@ default int inactiveButtonTextColor() { return SpecialColors.TEXT_INACTIVE_BUTTON.argb(); } - private int drawString(GuiGraphics guiGraphics, Component component, float x, float y, int color, boolean shadow) { - return guiGraphics.drawString(font(), component.getVisualOrderText(), x, y, color, shadow); - } - default int getStringWidth(Component component) { return font().width(component); } @@ -98,7 +94,7 @@ default void drawScrollingString(GuiGraphics guiGraphics, Component text, int mi } else { targetX = alignment.getTarget(minX, maxX, areaWidth, textWidth); } - drawString(guiGraphics, text, targetX, targetY, color, shadow); + guiGraphics.drawString(font(), text.getVisualOrderText(), targetX, targetY, color, shadow); if (isScrolling) { guiGraphics.disableScissor(); } @@ -137,7 +133,7 @@ default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, targetX = alignment.getTarget(minX, maxX, areaWidth, textWidth); } PoseStack pose = prepTextScale(guiGraphics, targetX, targetY, scale); - drawString(guiGraphics, text, 0, 0, color, shadow); + guiGraphics.drawString(font(), text, 0, 0, color, shadow); pose.popPose(); if (isScrolling) { guiGraphics.disableScissor(); @@ -200,113 +196,74 @@ public float getTarget(int minX, int maxX, float areaWidth, float textWidth) { } } - // efficient tool to draw word-by-word wrapped text based on a horizontal bound. looks intimidating but runs in O(n) class WrappedTextRenderer { - private final List linesToDraw = new ArrayList<>(); - private final IFancyFontRenderer font; - private final String text; + private final Component text; + private List linesToDraw = Collections.emptyList(); + + IFancyFontRenderer fontRenderer; @Nullable private Font lastFont; private int lastMaxLength = -1; - private int lineLength = 0; - public WrappedTextRenderer(IFancyFontRenderer font, Component text) { - this(font, text.getString()); - } - - public WrappedTextRenderer(IFancyFontRenderer font, String text) { - this.font = font; + public WrappedTextRenderer(IFancyFontRenderer fontRenderer, Component text) { + this.fontRenderer = fontRenderer; this.text = text; } public void renderCentered(GuiGraphics guiGraphics, int x, int y, int color, int maxLength) { calculateLines(maxLength); - int startY = y; - int lineHeight = font.getLineHeight(); - int width = font.getXSize(); - for (LineData line : linesToDraw) { - font.drawString(guiGraphics, line.component(), x + (width - line.length()) / 2F, startY, color, false); - startY += lineHeight; - } + drawLines(guiGraphics, x, y, color, true); } public int renderWithScale(GuiGraphics guiGraphics, int x, int y, int color, int maxLength, float scale) { //Divide by scale for calculating actual max length so that when the text is scaled it has the proper total space available calculateLines(Mth.floor(maxLength / scale)); - PoseStack pose = font.prepTextScale(guiGraphics, x, y, scale); - int startY = 0; - int lineHeight = font.getLineHeight(); - for (LineData line : linesToDraw) { - font.drawString(guiGraphics, line.component(), 0, startY, color, false); - startY += lineHeight; - } + PoseStack pose = fontRenderer.prepTextScale(guiGraphics, x, y, scale); + drawLines(guiGraphics, 0, 0, color, false); pose.popPose(); return linesToDraw.size(); } - void calculateLines(int maxLength) { + private void drawLines(GuiGraphics guiGraphics, int x, int startY, int color, boolean center) { + Font font = fontRenderer.font(); + for (FormattedCharSequence line : linesToDraw) { + float targetX; + if (center) { + targetX = x + (fontRenderer.getXSize() - font.width(line)) / 2F; + } else { + targetX = x; + } + guiGraphics.drawString(font, line, targetX, startY, color, false); + startY += font.lineHeight; + } + } + + private void calculateLines(int maxLength) { //If something changed since the last time we calculated it - Font font = this.font.font(); + Font font = fontRenderer.font(); if (font != null && (lastFont != font || lastMaxLength != maxLength)) { lastFont = font; lastMaxLength = maxLength; - linesToDraw.clear(); - StringBuilder lineBuilder = new StringBuilder(); - StringBuilder wordBuilder = new StringBuilder(); - int spaceLength = font.width(" "); - int wordLength = 0; - for (char c : text.toCharArray()) { - if (c == ' ') { - lineBuilder = addWord(lineBuilder, wordBuilder, maxLength, spaceLength, wordLength); - wordBuilder = new StringBuilder(); - wordLength = 0; - continue; - } - wordBuilder.append(c); - wordLength += font.width(Character.toString(c)); - } - if (!wordBuilder.isEmpty()) { - lineBuilder = addWord(lineBuilder, wordBuilder, maxLength, spaceLength, wordLength); - } - if (!lineBuilder.isEmpty()) { - linesToDraw.add(new LineData(lineBuilder, lineLength)); - } + linesToDraw = font.split(text, maxLength); } } - StringBuilder addWord(StringBuilder lineBuilder, StringBuilder wordBuilder, int maxLength, int spaceLength, int wordLength) { - // ignore spacing if this is the first word of the line - int spacingLength = lineBuilder.isEmpty() ? 0 : spaceLength; - if (lineLength + spacingLength + wordLength > maxLength) { - linesToDraw.add(new LineData(lineBuilder, lineLength)); - lineBuilder = new StringBuilder(wordBuilder); - lineLength = wordLength; - } else { - if (spacingLength > 0) { - lineBuilder.append(' '); - } - lineBuilder.append(wordBuilder); - lineLength += spacingLength + wordLength; - } - return lineBuilder; + public int getRequiredHeight(int maxLength) { + calculateLines(maxLength); + return fontRenderer.getLineHeight() * linesToDraw.size(); } + } - public static int calculateHeightRequired(Font font, Component text, int width, int maxLength) { - //TODO: Come up with a better way of doing this (maybe allow it to somehow replace what the stored font is - // that way we can calculate, and then use the calculated values in our actual renderer without having to calculate once more - WrappedTextRenderer wrappedTextRenderer = new WrappedTextRenderer(new SimpleFancyFontRenderer(font, width), text); - wrappedTextRenderer.calculateLines(maxLength); - return font.lineHeight * wrappedTextRenderer.linesToDraw.size(); - } + class ReplaceableWrappedTextRenderer extends WrappedTextRenderer { - private record LineData(Component component, int length) { + public ReplaceableWrappedTextRenderer(IFancyFontRenderer parent, int width, Component text) { + super(new SimpleFancyFontRenderer(parent.font(), width), text); + } - private LineData(StringBuilder lineBuilder, int length) { - //TODO - 1.21: Make use of the style of the passed in parent component that we split during? - // Similar to StringSplitter$LineBreakFinder - this(TextComponentUtil.getString(lineBuilder.toString()), length); - } + public WrappedTextRenderer replaceFont(IFancyFontRenderer font) { + this.fontRenderer = font; + return this; } private record SimpleFancyFontRenderer(Font font, int getXSize) implements IFancyFontRenderer { From ecb736815caacc689755254ed13402f5a588d7f6 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Sat, 12 Oct 2024 12:28:58 -0500 Subject: [PATCH 15/17] Add support for specifying text alignment to our wrapped text renderer --- .../element/window/GuiConfirmationDialog.java | 6 ++-- .../gui/element/window/GuiUpgradeWindow.java | 4 +-- .../GuiAntiprotonicNucleosynthesizer.java | 2 +- .../client/render/IFancyFontRenderer.java | 36 +++++++++---------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java b/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java index 42a15858a35..93fcd98575c 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java @@ -11,6 +11,8 @@ public class GuiConfirmationDialog extends GuiWindow { + private static final int PADDING = 5; + private final WrappedTextRenderer wrappedTextRenderer; private GuiConfirmationDialog(IGuiWrapper gui, int x, int y, int width, int height, ReplaceableWrappedTextRenderer renderer, Runnable onConfirm, DialogType type) { @@ -28,14 +30,14 @@ private GuiConfirmationDialog(IGuiWrapper gui, int x, int y, int width, int heig public static void show(IGuiWrapper gui, Component title, Runnable onConfirm, DialogType type) { int width = 140; ReplaceableWrappedTextRenderer renderer = new ReplaceableWrappedTextRenderer(gui, width, title); - int height = 33 + renderer.getRequiredHeight(width - 10); + int height = 33 + renderer.getRequiredHeight(width - 2 * PADDING); gui.addWindow(new GuiConfirmationDialog(gui, (gui.getXSize() - width) / 2, (gui.getYSize() - height) / 2, width, height, renderer, onConfirm, type)); } @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - wrappedTextRenderer.renderCentered(guiGraphics, relativeX, relativeY + 6, titleTextColor(), width - 10); + wrappedTextRenderer.render(guiGraphics, relativeX + PADDING, relativeY + 6, TextAlignment.CENTER, titleTextColor(), width - 2 * PADDING); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java index 5b40963e7eb..b04854f3b50 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java @@ -88,7 +88,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { upgradeTypeData.put(selectedType, textRenderer); } int screenWidth = rightScreen.getWidth() - 2; - int lines = textRenderer.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, screenTextColor(), + int lines = textRenderer.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, TextAlignment.LEFT, screenTextColor(), screenWidth - 2, 0.6F); int textY = 4 + 6 * lines; rightScreen.drawScaledScrollingString(guiGraphics, MekanismLang.UPGRADE_COUNT.translate(amount, selectedType.getMax()), 0, textY, TextAlignment.LEFT, @@ -99,7 +99,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { rightScreen.drawScaledScrollingString(guiGraphics, component, 0, textY, TextAlignment.LEFT, screenTextColor(), screenWidth, 2, false, 0.6F); } } else { - noSelection.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, screenTextColor(), 56, 0.8F); + noSelection.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, TextAlignment.LEFT, screenTextColor(), 56, 0.8F); } } } \ No newline at end of file diff --git a/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java b/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java index ae7225011a8..6efbacacf33 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java @@ -84,7 +84,7 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, renderTitleText(guiGraphics); renderInventoryText(guiGraphics); screen.drawScrollingString(guiGraphics, MekanismLang.PROCESS_RATE.translate(TextUtils.getPercent(tile.getProcessRate())), 0, - screen.getHeight() - getLineHeight() - 2, TextAlignment.LEFT, screenTextColor(), 2, false); + screen.getHeight() - getLineHeight() - 2, TextAlignment.CENTER, screenTextColor(), 2, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); PoseStack pose = guiGraphics.pose(); pose.pushPose(); diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 0c061ce3959..66d6c6f72eb 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -92,7 +92,7 @@ default void drawScrollingString(GuiGraphics guiGraphics, Component text, int mi if (isScrolling) { targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); } else { - targetX = alignment.getTarget(minX, maxX, areaWidth, textWidth); + targetX = alignment.getTarget(font(), minX, maxX, textWidth); } guiGraphics.drawString(font(), text.getVisualOrderText(), targetX, targetY, color, shadow); if (isScrolling) { @@ -130,7 +130,7 @@ default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, if (isScrolling) { targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); } else { - targetX = alignment.getTarget(minX, maxX, areaWidth, textWidth); + targetX = alignment.getTarget(font(), minX, maxX, textWidth); } PoseStack pose = prepTextScale(guiGraphics, targetX, targetY, scale); guiGraphics.drawString(font(), text, 0, 0, color, shadow); @@ -182,16 +182,18 @@ private PoseStack prepTextScale(GuiGraphics guiGraphics, float x, float y, float enum TextAlignment { LEFT, CENTER, - RIGHT; + RIGHT, + /** + * Represents that for left to right languages this will be left aligned, and for right to left it will be right aligned. + */ + RELATIVE;//TODO: Make use of this in various spots that make sense - public float getTarget(int minX, int maxX, float areaWidth, float textWidth) { - //TODO: Do we want to swap left and right when Font#isBidirectional is true? - // I believe in right to left languages text is meant to be aligned to the right - // but it likely would look odd in various GUIs + public float getTarget(Font font, int minX, int maxX, float textWidth) { return switch (this) { case LEFT -> minX; - case CENTER -> minX + (areaWidth - textWidth) / 2F; + case CENTER -> minX + ((maxX - minX) - textWidth) / 2F; case RIGHT -> maxX - textWidth; + case RELATIVE -> font.isBidirectional() ? maxX - textWidth : minX; }; } } @@ -211,30 +213,24 @@ public WrappedTextRenderer(IFancyFontRenderer fontRenderer, Component text) { this.text = text; } - public void renderCentered(GuiGraphics guiGraphics, int x, int y, int color, int maxLength) { + public void render(GuiGraphics guiGraphics, int x, int y, TextAlignment alignment, int color, int maxLength) { calculateLines(maxLength); - drawLines(guiGraphics, x, y, color, true); + drawLines(guiGraphics, x, y, maxLength, alignment, color, 1); } - public int renderWithScale(GuiGraphics guiGraphics, int x, int y, int color, int maxLength, float scale) { + public int renderWithScale(GuiGraphics guiGraphics, int x, int y, TextAlignment alignment, int color, int maxLength, float scale) { //Divide by scale for calculating actual max length so that when the text is scaled it has the proper total space available calculateLines(Mth.floor(maxLength / scale)); PoseStack pose = fontRenderer.prepTextScale(guiGraphics, x, y, scale); - drawLines(guiGraphics, 0, 0, color, false); + drawLines(guiGraphics, 0, 0, maxLength, alignment, color, scale); pose.popPose(); return linesToDraw.size(); } - private void drawLines(GuiGraphics guiGraphics, int x, int startY, int color, boolean center) { + private void drawLines(GuiGraphics guiGraphics, int x, int startY, int maxLength, TextAlignment alignment, int color, float scale) { Font font = fontRenderer.font(); for (FormattedCharSequence line : linesToDraw) { - float targetX; - if (center) { - targetX = x + (fontRenderer.getXSize() - font.width(line)) / 2F; - } else { - targetX = x; - } - guiGraphics.drawString(font, line, targetX, startY, color, false); + guiGraphics.drawString(font, line, alignment.getTarget(font, x, x + maxLength, font.width(line) * scale), startY, color, false); startY += font.lineHeight; } } From 5e507acb6625c842787d14b5f156bdd389bad6ef Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Wed, 16 Oct 2024 15:16:33 -0500 Subject: [PATCH 16/17] Improve scrolling text so that it starts at the left or right of the string depending on LTR or RTL language instead of starting at a random position --- .../java/mekanism/client/gui/GuiMekanism.java | 10 +- .../java/mekanism/client/gui/IGuiWrapper.java | 6 +- .../client/gui/element/GuiDropdown.java | 12 +- .../client/gui/element/GuiElement.java | 17 +- .../client/gui/element/GuiInnerScreen.java | 4 +- .../element/custom/GuiDictionaryTarget.java | 2 +- .../element/custom/GuiSupportedUpgrades.java | 2 +- .../gui/element/custom/module/EnumToggle.java | 2 +- .../gui/element/scroll/GuiSlotScroll.java | 4 +- .../element/window/GuiConfirmationDialog.java | 2 +- .../gui/element/window/GuiUpgradeWindow.java | 13 +- .../client/gui/element/window/GuiWindow.java | 8 + .../GuiAntiprotonicNucleosynthesizer.java | 2 +- .../client/gui/robit/GuiRobitRepair.java | 12 +- .../emi/recipe/MekanismEmiRecipe.java | 8 - .../recipe_viewer/jei/BaseRecipeCategory.java | 7 - .../client/render/IFancyFontRenderer.java | 197 +++++++++++------- .../lookingat/LookingAtElement.java | 7 - 18 files changed, 186 insertions(+), 129 deletions(-) diff --git a/src/main/java/mekanism/client/gui/GuiMekanism.java b/src/main/java/mekanism/client/gui/GuiMekanism.java index 7f55dbe1db1..6d658349d53 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanism.java +++ b/src/main/java/mekanism/client/gui/GuiMekanism.java @@ -30,6 +30,7 @@ import mekanism.common.tile.interfaces.ISideConfiguration; import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils.ResourceType; +import net.minecraft.Util; import net.minecraft.client.gui.ComponentPath; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; @@ -59,6 +60,7 @@ public abstract class GuiMekanism exten public boolean switchingToRecipeViewer; @Nullable private IWarningTracker warningTracker; + private long lastMSInitialized; private boolean hasClicked = false; @@ -98,6 +100,7 @@ protected void init() { // clear out any tracked warnings, so we don't have duplicates being tracked when we add our elements again warningTracker.clearTrackedWarnings(); } + lastMSInitialized = Util.getMillis(); addGuiElements(); if (warningTracker != null) { //If we have a warning tracker add it as a button, we do so via a method in case any of the sub GUIs need to reposition where it ends up @@ -167,12 +170,17 @@ public void containerTick() { windows.forEach(GuiWindow::tick); } + @Override + public long getTimeOpened() { + return lastMSInitialized; + } + protected void renderTitleText(GuiGraphics guiGraphics) { drawTitleText(guiGraphics, title, titleLabelY); } protected void renderTitleTextWithOffset(GuiGraphics guiGraphics, int x) { - drawTitleTextTextWithOffset(guiGraphics, title, x, titleLabelY); + renderTitleTextWithOffset(guiGraphics, x, getXSize()); } protected void renderTitleTextWithOffset(GuiGraphics guiGraphics, int x, int end) { diff --git a/src/main/java/mekanism/client/gui/IGuiWrapper.java b/src/main/java/mekanism/client/gui/IGuiWrapper.java index e20184ac6ca..70aba332464 100644 --- a/src/main/java/mekanism/client/gui/IGuiWrapper.java +++ b/src/main/java/mekanism/client/gui/IGuiWrapper.java @@ -64,13 +64,9 @@ default void renderItem(GuiGraphics guiGraphics, @NotNull ItemStack stack, int x GuiUtils.renderItem(guiGraphics, stack, xAxis, yAxis, scale, font(), null, false); } - default void renderItemTooltip(GuiGraphics guiGraphics, @NotNull ItemStack stack, int xAxis, int yAxis) { - guiGraphics.renderTooltip(font(), stack, xAxis, yAxis); - } - default void renderItemTooltipWithExtra(GuiGraphics guiGraphics, @NotNull ItemStack stack, int xAxis, int yAxis, List toAppend) { if (toAppend.isEmpty()) { - renderItemTooltip(guiGraphics, stack, xAxis, yAxis); + guiGraphics.renderTooltip(font(), stack, xAxis, yAxis); } else { List tooltip = new ArrayList<>(Screen.getTooltipFromItem(Minecraft.getInstance(), stack)); tooltip.addAll(toAppend); diff --git a/src/main/java/mekanism/client/gui/element/GuiDropdown.java b/src/main/java/mekanism/client/gui/element/GuiDropdown.java index a8174c84734..235ae05c684 100644 --- a/src/main/java/mekanism/client/gui/element/GuiDropdown.java +++ b/src/main/java/mekanism/client/gui/element/GuiDropdown.java @@ -9,6 +9,7 @@ import mekanism.client.gui.tooltip.TooltipUtils; import mekanism.common.inventory.GuiComponents.IDropdownEnum; import mekanism.common.registries.MekanismSounds; +import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.navigation.ScreenRectangle; @@ -31,6 +32,7 @@ public class GuiDropdown & IDropdownEnum> extends @Nullable private ScreenRectangle cachedTooltipRect; + private long msOpened; private boolean isOpen; public GuiDropdown(IGuiWrapper gui, int x, int y, int width, Class enumClass, Supplier curType, Consumer handler) { @@ -67,18 +69,19 @@ public void onRelease(double mouseX, double mouseY) { @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - drawOptionName(guiGraphics, curType.get(), 2); + drawOptionName(guiGraphics, curType.get(), 2, true); if (isOpen) { for (int i = 0; i < options.length; i++) { - drawOptionName(guiGraphics, options[i], ELEMENT_HEIGHT + 1 + 10 * i); + drawOptionName(guiGraphics, options[i], ELEMENT_HEIGHT + 1 + 10 * i, false); } } } - private void drawOptionName(GuiGraphics guiGraphics, TYPE option, int y) { + private void drawOptionName(GuiGraphics guiGraphics, TYPE option, int y, boolean alwaysDisplayed) { //Note: We add one for if we are rendering with an icon so that we allow going closer to the icon int maxWidth = option.getIcon() == null ? getWidth() : getWidth() - ICON_OFFSET + 1; - drawScaledScrollingString(guiGraphics, option.getShortName(), 0, y, TextAlignment.LEFT, screenTextColor(), maxWidth, 10, 3, false, 0.8F); + drawScaledScrollingString(guiGraphics, option.getShortName(), 0, y, TextAlignment.LEFT, screenTextColor(), maxWidth, 10, 3, false, + 0.8F, alwaysDisplayed ? getTimeOpened() : msOpened); } @Override @@ -137,6 +140,7 @@ private void setOpen(boolean open) { isOpen = open; if (isOpen) { height += options.length * 10 + 1; + msOpened = Util.getMillis(); } else { height = ELEMENT_HEIGHT; } diff --git a/src/main/java/mekanism/client/gui/element/GuiElement.java b/src/main/java/mekanism/client/gui/element/GuiElement.java index 0b794b52a88..470c8523796 100644 --- a/src/main/java/mekanism/client/gui/element/GuiElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiElement.java @@ -632,7 +632,7 @@ protected void drawButtonText(GuiGraphics guiGraphics, int mouseX, int mouseY) { //Note: We add one to the button height as it is considered bounds, and we want to include the bottom pixel of the button in our calculations of where the text should land //Note: We call super as currently getButtonX and getButtonY already factor in the relative positioning IFancyFontRenderer.super.drawScrollingString(guiGraphics, text, getButtonX(), getButtonY(), TextAlignment.CENTER, color, getButtonWidth(), - getButtonHeight() + 1, 2, displayButtonTextShadow()); + getButtonHeight() + 1, 2, displayButtonTextShadow(), getTimeOpened()); } } @@ -692,13 +692,20 @@ protected void drawTiledSprite(GuiGraphics guiGraphics, int xPosition, int yPosi } @Override - public final void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, boolean shadow) { - IFancyFontRenderer.super.drawScrollingString(guiGraphics, text, relativeX + x, relativeY + y, alignment, color, width, height, maxLengthPad, shadow); + public long getTimeOpened() { + return guiObj.getTimeOpened(); } @Override - public final void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, boolean shadow, float scale) { - IFancyFontRenderer.super.drawScaledScrollingString(guiGraphics, text, relativeX + x, relativeY + y, alignment, color, width, height, maxLengthPad, shadow, scale); + public final void drawScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, + boolean shadow, long msVisible) { + IFancyFontRenderer.super.drawScrollingString(graphics, text, relativeX + x, relativeY + y, alignment, color, width, height, maxLengthPad, shadow, msVisible); + } + + @Override + public final void drawScaledScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, + boolean shadow, float scale, long msVisible) { + IFancyFontRenderer.super.drawScaledScrollingString(graphics, text, relativeX + x, relativeY + y, alignment, color, width, height, maxLengthPad, shadow, scale, msVisible); } public enum ButtonBackground { diff --git a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java index 9942d0cb196..c1d2f122903 100644 --- a/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java +++ b/src/main/java/mekanism/client/gui/element/GuiInnerScreen.java @@ -97,7 +97,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); List list = getRenderStrings(); if (!list.isEmpty()) { - int lineHeight = getLineHeight(); + int lineHeight = font().lineHeight; int minY = relativeY + padding; int maxY = minY + lineHeight; int heightToNextLine = lineHeight + spacing; @@ -114,7 +114,7 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { for (int i = 0, size = list.size(); i < size; i++) { Component text = list.get(i); int maxX = relativeX + getMaxTextWidth(i) - padding; - drawScaledScrollingString(guiGraphics, text, minX, minY, maxX, maxY, TextAlignment.LEFT, screenTextColor, false, textScale); + drawScaledScrollingString(guiGraphics, text, minX, minY, maxX, maxY, TextAlignment.LEFT, screenTextColor, false, textScale, getTimeOpened()); minY += heightToNextLine; maxY += heightToNextLine; } diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiDictionaryTarget.java b/src/main/java/mekanism/client/gui/element/custom/GuiDictionaryTarget.java index 57fb1ef423b..bf509d03aa6 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiDictionaryTarget.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiDictionaryTarget.java @@ -92,7 +92,7 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou public void renderToolTip(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderToolTip(guiGraphics, mouseX, mouseY); if (target instanceof ItemStack stack) { - gui().renderItemTooltip(guiGraphics, stack, mouseX, mouseY); + guiGraphics.renderTooltip(font(), stack, mouseX, mouseY); } } diff --git a/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java b/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java index b28c2a4a0be..311b4a31436 100644 --- a/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java +++ b/src/main/java/mekanism/client/gui/element/custom/GuiSupportedUpgrades.java @@ -31,7 +31,7 @@ public class GuiSupportedUpgrades extends GuiElement { private static final int ROW_ROOM = PADDED_ELEMENT_WIDTH / ELEMENT_SIZE; private static int getFirstRowStart(IFancyFontRenderer fontRenderer) { - return Math.min(fontRenderer.getStringWidth(SUPPORTED) + 1, PADDED_ELEMENT_WIDTH); + return Math.min(fontRenderer.font().width(SUPPORTED) + 1, PADDED_ELEMENT_WIDTH); } private static int getFirstRowRoom(int firstRowStart) { diff --git a/src/main/java/mekanism/client/gui/element/custom/module/EnumToggle.java b/src/main/java/mekanism/client/gui/element/custom/module/EnumToggle.java index 90b3c55b49c..bdc46d42324 100644 --- a/src/main/java/mekanism/client/gui/element/custom/module/EnumToggle.java +++ b/src/main/java/mekanism/client/gui/element/custom/module/EnumToggle.java @@ -69,7 +69,7 @@ protected void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) guiGraphics.blit(hasModeIcon.getModeIcon(), getRelativeX() + optionCenter - 8, getRelativeY() + 19, 0, 0, 16, 16, 16, 16); } else { //Similar to logic for drawScaledCenteredText except shifts values slightly if they go past the max length - int textWidth = parent.getStringWidth(text); + int textWidth = parent.font().width(text); float objectWidth = textWidth * TEXT_SCALE; if (optionCenter < objectWidth / 2) { //Note: We know it will overflow, so it doesn't actually matter if we center it here or not diff --git a/src/main/java/mekanism/client/gui/element/scroll/GuiSlotScroll.java b/src/main/java/mekanism/client/gui/element/scroll/GuiSlotScroll.java index 9057b034414..4acbf7565f6 100644 --- a/src/main/java/mekanism/client/gui/element/scroll/GuiSlotScroll.java +++ b/src/main/java/mekanism/client/gui/element/scroll/GuiSlotScroll.java @@ -160,7 +160,7 @@ private void renderSlotTooltip(GuiGraphics guiGraphics, IScrollableSlot slot, in ItemStack stack = slot.item().getInternalStack(); long count = slot.count(); if (count < 10_000) { - gui().renderItemTooltip(guiGraphics, stack, slotX, slotY); + guiGraphics.renderTooltip(font(), stack, slotX, slotY); } else { //If the slot's displayed count is truncated, make sure we also add the actual amount to the tooltip gui().renderItemTooltipWithExtra(guiGraphics, stack, slotX, slotY, Collections.singletonList(MekanismLang.QIO_STORED_COUNT.translateColored(EnumColor.GRAY, @@ -181,7 +181,7 @@ private boolean isSlotEmpty(IScrollableSlot slot) { private void renderSlotText(GuiGraphics guiGraphics, Component text, int x, int y) { float scale = 0.6F; - float scaledWidth = getStringWidth(text) * scale; + float scaledWidth = font().width(text) * scale; if (scaledWidth >= 16) { //If we need a lower scale slightly due to having a lot of text, calculate it //Note: If it would still overflow, then we just let the scrolling text handle it diff --git a/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java b/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java index 93fcd98575c..f079a3c8044 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiConfirmationDialog.java @@ -37,7 +37,7 @@ public static void show(IGuiWrapper gui, Component title, Runnable onConfirm, Di @Override public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { super.renderForeground(guiGraphics, mouseX, mouseY); - wrappedTextRenderer.render(guiGraphics, relativeX + PADDING, relativeY + 6, TextAlignment.CENTER, titleTextColor(), width - 2 * PADDING); + wrappedTextRenderer.render(guiGraphics, relativeX + PADDING, relativeY + 6, width - 2 * PADDING, TextAlignment.CENTER, titleTextColor()); } @Override diff --git a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java index b04854f3b50..749d01ef038 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiUpgradeWindow.java @@ -24,6 +24,7 @@ import mekanism.common.network.to_server.PacketGuiInteract.GuiInteraction; import mekanism.common.tile.base.TileEntityMekanism; import mekanism.common.util.UpgradeUtils; +import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -37,6 +38,8 @@ public class GuiUpgradeWindow extends GuiWindow { private final GuiUpgradeScrollList scrollList; private final GuiInnerScreen rightScreen; + private long msSelected; + public GuiUpgradeWindow(IGuiWrapper gui, int x, int y, TileEntityMekanism tile, SelectedWindowData windowData) { super(gui, x, y, 198, 76 + Math.max(18, 12 * GuiSupportedUpgrades.calculateNeededRows(gui)), windowData); if (windowData.type != WindowType.UPGRADE) { @@ -44,7 +47,10 @@ public GuiUpgradeWindow(IGuiWrapper gui, int x, int y, TileEntityMekanism tile, } this.tile = tile; interactionStrategy = InteractionStrategy.ALL; - scrollList = addChild(new GuiUpgradeScrollList(gui, relativeX + 6, relativeY + 18, 50, tile.getComponent(), this::updateEnabledButtons)); + scrollList = addChild(new GuiUpgradeScrollList(gui, relativeX + 6, relativeY + 18, 50, tile.getComponent(), () -> { + updateEnabledButtons(); + msSelected = Util.getMillis(); + })); addChild(new GuiSupportedUpgrades(gui, relativeX + 6, relativeY + 68, tile.getComponent().getSupportedTypes())); rightScreen = addChild(new GuiInnerScreen(gui, scrollList.getRelativeRight(), relativeY + 18, 59, 50)); addChild(new GuiProgress(() -> this.tile.getComponent().getScaledUpgradeProgress(), ProgressType.INSTALLING, gui, rightScreen.getRelativeRight() + 3, relativeY + 37)); @@ -92,11 +98,12 @@ public void renderForeground(GuiGraphics guiGraphics, int mouseX, int mouseY) { screenWidth - 2, 0.6F); int textY = 4 + 6 * lines; rightScreen.drawScaledScrollingString(guiGraphics, MekanismLang.UPGRADE_COUNT.translate(amount, selectedType.getMax()), 0, textY, TextAlignment.LEFT, - screenTextColor(), screenWidth, 2, false, 0.6F); + screenTextColor(), screenWidth, 2, false, 0.6F, msSelected); for (Component component : UpgradeUtils.getInfo(tile, selectedType)) { //Note: We add the six here instead of after to account for the line above this for loop that draws the upgrade count textY += 6; - rightScreen.drawScaledScrollingString(guiGraphics, component, 0, textY, TextAlignment.LEFT, screenTextColor(), screenWidth, 2, false, 0.6F); + rightScreen.drawScaledScrollingString(guiGraphics, component, 0, textY, TextAlignment.LEFT, screenTextColor(), screenWidth, 2, + false, 0.6F, msSelected); } } else { noSelection.renderWithScale(guiGraphics, rightScreen.getRelativeX() + 2, rightScreen.getRelativeY() + 2, TextAlignment.LEFT, screenTextColor(), 56, 0.8F); diff --git a/src/main/java/mekanism/client/gui/element/window/GuiWindow.java b/src/main/java/mekanism/client/gui/element/window/GuiWindow.java index 4f74279b881..fbb2763e32e 100644 --- a/src/main/java/mekanism/client/gui/element/window/GuiWindow.java +++ b/src/main/java/mekanism/client/gui/element/window/GuiWindow.java @@ -17,6 +17,7 @@ import mekanism.common.inventory.container.SelectedWindowData.WindowPosition; import mekanism.common.inventory.container.SelectedWindowData.WindowType; import mekanism.common.lib.Color; +import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; @@ -34,6 +35,7 @@ public class GuiWindow extends GuiTexturedElement implements IGUIWindow { private Consumer closeListener; private Consumer reattachListener; + private final long msOpened; protected InteractionStrategy interactionStrategy = InteractionStrategy.CONTAINER; @@ -79,6 +81,7 @@ private GuiWindow(IGuiWrapper gui, WindowPosition calculatedPosition, int width, this.pinned = calculatedPosition.pinned(); isOverlay = true; active = true; + msOpened = Util.getMillis(); if (!isFocusOverlay()) { addCloseButton(); if (this.windowData.type.canPin()) { @@ -87,6 +90,11 @@ private GuiWindow(IGuiWrapper gui, WindowPosition calculatedPosition, int width, } } + @Override + public long getTimeOpened() { + return msOpened; + } + public void onFocusLost() { } diff --git a/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java b/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java index 6efbacacf33..4952d87510b 100644 --- a/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java +++ b/src/main/java/mekanism/client/gui/machine/GuiAntiprotonicNucleosynthesizer.java @@ -84,7 +84,7 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, renderTitleText(guiGraphics); renderInventoryText(guiGraphics); screen.drawScrollingString(guiGraphics, MekanismLang.PROCESS_RATE.translate(TextUtils.getPercent(tile.getProcessRate())), 0, - screen.getHeight() - getLineHeight() - 2, TextAlignment.CENTER, screenTextColor(), 2, false); + screen.getHeight() - font().lineHeight - 2, TextAlignment.CENTER, screenTextColor(), 2, false); super.drawForegroundText(guiGraphics, mouseX, mouseY); PoseStack pose = guiGraphics.pose(); pose.pushPose(); diff --git a/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java b/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java index 00958a4f1ec..3c53914b9c4 100644 --- a/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java +++ b/src/main/java/mekanism/client/gui/robit/GuiRobitRepair.java @@ -4,6 +4,7 @@ import mekanism.client.gui.element.text.GuiTextField; import mekanism.common.MekanismLang; import mekanism.common.inventory.container.entity.robit.RepairRobitContainer; +import net.minecraft.Util; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.core.component.DataComponents; @@ -27,6 +28,7 @@ public class GuiRobitRepair extends GuiRobit implements Co private static final ResourceLocation ANVIL_LOCATION = ResourceLocation.withDefaultNamespace("textures/gui/container/anvil.png"); private final Player player; private GuiTextField itemNameField; + private long msDisplayCost; public GuiRobitRepair(RepairRobitContainer container, Inventory inv, Component title) { super(container, inv, title); @@ -81,6 +83,9 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, renderInventoryText(guiGraphics, 60); int maximumCost = menu.getCost(); if (maximumCost > 0) { + if (msDisplayCost == 0) { + msDisplayCost = Util.getMillis(); + } int textColor = 0x80FF20; Component component = MekanismLang.REPAIR_COST.translate(maximumCost); if (maximumCost >= 40 && !getMinecraft().player.getAbilities().instabuild) { @@ -90,17 +95,20 @@ protected void drawForegroundText(@NotNull GuiGraphics guiGraphics, int mouseX, Slot slot = menu.getSlot(2); if (!slot.hasItem()) { component = null; + msDisplayCost = 0; } else if (!slot.mayPickup(player)) { textColor = 0xFF6060; } } if (component != null) { - int min = Math.max(itemNameField.getRelativeX(), imageWidth - getStringWidth(component) - 10); + int min = Math.max(itemNameField.getRelativeX(), imageWidth - font().width(component) - 10); int max = imageWidth - 8; guiGraphics.fill(min, 67, max, 79, 0x4F000000); - drawScrollingString(guiGraphics, component, min, 69, TextAlignment.RIGHT, textColor, max - min, 1, true); + drawScrollingString(guiGraphics, component, min, 69, TextAlignment.RIGHT, textColor, max - min, 1, true, msDisplayCost); } + } else { + msDisplayCost = 0; } super.drawForegroundText(guiGraphics, mouseX, mouseY); } diff --git a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/MekanismEmiRecipe.java b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/MekanismEmiRecipe.java index fe541c3e41a..1224b148c3c 100644 --- a/src/main/java/mekanism/client/recipe_viewer/emi/recipe/MekanismEmiRecipe.java +++ b/src/main/java/mekanism/client/recipe_viewer/emi/recipe/MekanismEmiRecipe.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.function.Supplier; import mekanism.api.annotations.NothingNullByDefault; -import mekanism.api.chemical.Chemical; import mekanism.api.chemical.ChemicalStack; import mekanism.api.recipes.ingredients.ChemicalStackIngredient; import mekanism.api.recipes.ingredients.FluidStackIngredient; @@ -28,8 +27,6 @@ import mekanism.client.recipe_viewer.emi.MekanismEmiRecipeCategory; import mekanism.client.recipe_viewer.emi.widget.MekanismEmiWidget; import mekanism.client.recipe_viewer.emi.widget.MekanismTankEmiWidget; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.events.AbstractContainerEventHandler; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.resources.ResourceLocation; @@ -188,11 +185,6 @@ public RecipeHolder getBackingRecipe() { return null; } - @Override - public Font font() { - return Minecraft.getInstance().font; - } - @Override public List children() { //TODO: I believe returning empty for this is fine for now, though we could potentially gather the children and then diff --git a/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java b/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java index 9eaf794d981..93a4f2b8412 100644 --- a/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java +++ b/src/main/java/mekanism/client/recipe_viewer/jei/BaseRecipeCategory.java @@ -37,8 +37,6 @@ import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.SharedConstants; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.events.AbstractContainerEventHandler; import net.minecraft.client.gui.navigation.ScreenRectangle; @@ -196,11 +194,6 @@ protected void renderElements(RECIPE recipe, IRecipeSlotsView recipeSlotsView, G } } - @Override - public Font font() { - return Minecraft.getInstance().font; - } - @Override public IDrawable getBackground() { return background; diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 66d6c6f72eb..3f2c5d9c9f0 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -5,6 +5,7 @@ import java.util.List; import mekanism.client.SpecialColors; import net.minecraft.Util; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; @@ -19,7 +20,20 @@ public interface IFancyFontRenderer { int getXSize(); - Font font(); + default Font font() { + return Minecraft.getInstance().font; + } + + /** + * Time the gui was opened in ms, or zero if the time is unknown (scrolling text will just use the current time then) + */ + default long getTimeOpened() { + //TODO: Try and improve how we handle the time opened concept for test in scrollable elements + //TODO: Gui elements that are part of a GuiWindow, should use the window's time instead of the gui's time + //TODO: When resizing/re-init of a GUI, do we want to reset this? I think we currently do, but we probably don't want to be doing so + // we also then will need to make gui elements copy the value. Also when switchingToRecipeViewer is true, we want to reset it + return 0; + } default int titleTextColor() { return SpecialColors.TEXT_TITLE.argb(); @@ -45,98 +59,110 @@ default int inactiveButtonTextColor() { return SpecialColors.TEXT_INACTIVE_BUTTON.argb(); } - default int getStringWidth(Component component) { - return font().width(component); - } - - default int getLineHeight() { - return font().lineHeight; + default void drawTitleText(GuiGraphics graphics, Component text, int y) { + drawScrollingString(graphics, text, 0, y, TextAlignment.CENTER, titleTextColor(), 4, false); } - default void drawTitleText(GuiGraphics guiGraphics, Component text, int y) { - drawScrollingString(guiGraphics, text, 0, y, TextAlignment.CENTER, titleTextColor(), 4, false); + default void drawTitleTextTextWithOffset(GuiGraphics graphics, Component text, int x, int y, int end) { + drawTitleTextTextWithOffset(graphics, text, x, y, end, 4, TextAlignment.CENTER); } - default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y) { - drawTitleTextTextWithOffset(guiGraphics, text, x, y, getXSize()); + default void drawTitleTextTextWithOffset(GuiGraphics graphics, Component text, int x, int y, int end, int maxLengthPad, TextAlignment alignment) { + drawScrollingString(graphics, text, x, y, alignment, titleTextColor(), end - x, maxLengthPad, false); } - default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y, int end) { - drawTitleTextTextWithOffset(guiGraphics, text, x, y, end, 4, TextAlignment.CENTER); + default void drawScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow) { + drawScrollingString(graphics, text, x, y, alignment, color, maxLengthPad, shadow, getTimeOpened()); } - default void drawTitleTextTextWithOffset(GuiGraphics guiGraphics, Component text, int x, int y, int end, int maxLengthPad, TextAlignment alignment) { - drawScrollingString(guiGraphics, text, x, y, alignment, titleTextColor(), end - x, maxLengthPad, false); + default void drawScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow, long msVisible) { + drawScrollingString(graphics, text, x, y, alignment, color, getXSize(), maxLengthPad, shadow, msVisible); } - default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow) { - drawScrollingString(guiGraphics, text, x, y, alignment, color, getXSize(), maxLengthPad, shadow); + default void drawScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow) { + drawScrollingString(graphics, text, x, y, alignment, color, width, maxLengthPad, shadow, getTimeOpened()); } - default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow) { - drawScrollingString(guiGraphics, text, x, y, alignment, color, width, getLineHeight(), maxLengthPad, shadow); + default void drawScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow, + long msVisible) { + drawScrollingString(graphics, text, x, y, alignment, color, width, font().lineHeight, maxLengthPad, shadow, msVisible); } - default void drawScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, boolean shadow) { - drawScrollingString(guiGraphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + height, alignment, color, shadow); + default void drawScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, + boolean shadow, long msVisible) { + drawScrollingString(graphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + height, alignment, color, shadow, msVisible); } - default void drawScrollingString(GuiGraphics guiGraphics, Component text, int minX, int minY, int maxX, int maxY, TextAlignment alignment, int color, boolean shadow) { - int textWidth = getStringWidth(text); + default void drawScrollingString(GuiGraphics graphics, Component text, int minX, int minY, int maxX, int maxY, TextAlignment alignment, int color, boolean shadow, + long msVisible) { + Font font = font(); + int textWidth = font.width(text); int areaWidth = maxX - minX; boolean isScrolling = textWidth > areaWidth; //Note: Instead of doing what vanilla does, we divide to float, and don't add one // That way if min and max are not just lineHeight away they will be more accurate, and otherwise it won't render one line below where it should be - float targetY = (minY + maxY - getLineHeight()) / 2F; + float targetY = (minY + maxY - font.lineHeight) / 2F; float targetX; if (isScrolling) { - targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); + targetX = prepScrollingString(graphics, font, textWidth, areaWidth, minX, minY, maxX, maxY, Util.getMillis() - msVisible); } else { - targetX = alignment.getTarget(font(), minX, maxX, textWidth); + targetX = alignment.getTarget(font, minX, maxX, textWidth); } - guiGraphics.drawString(font(), text.getVisualOrderText(), targetX, targetY, color, shadow); + graphics.drawString(font, text.getVisualOrderText(), targetX, targetY, color, shadow); if (isScrolling) { - guiGraphics.disableScissor(); + graphics.disableScissor(); } } - default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow, float scale) { - drawScaledScrollingString(guiGraphics, text, x, y, alignment, color, getXSize(), maxLengthPad, shadow, scale); + default void drawScaledScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow, + float scale) { + drawScaledScrollingString(graphics, text, x, y, alignment, color, maxLengthPad, shadow, scale, getTimeOpened()); } - default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, - boolean shadow, float scale) { - drawScaledScrollingString(guiGraphics, text, x, y, alignment, color, width, getLineHeight(), maxLengthPad, shadow, scale); + default void drawScaledScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int maxLengthPad, boolean shadow, + float scale, long msVisible) { + drawScaledScrollingString(graphics, text, x, y, alignment, color, getXSize(), maxLengthPad, shadow, scale, msVisible); } - default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, + default void drawScaledScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, boolean shadow, float scale) { - drawScaledScrollingString(guiGraphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + getLineHeight(), alignment, color, shadow, scale); + drawScaledScrollingString(graphics, text, x, y, alignment, color, width, maxLengthPad, shadow, scale, getTimeOpened()); } - default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, int minX, int minY, int maxX, int maxY, TextAlignment alignment, int color, boolean shadow, - float scale) { + default void drawScaledScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int maxLengthPad, + boolean shadow, float scale, long msVisible) { + drawScaledScrollingString(graphics, text, x, y, alignment, color, width, font().lineHeight, maxLengthPad, shadow, scale, msVisible); + } + + default void drawScaledScrollingString(GuiGraphics graphics, Component text, int x, int y, TextAlignment alignment, int color, int width, int height, int maxLengthPad, + boolean shadow, float scale, long msVisible) { + drawScaledScrollingString(graphics, text, x + maxLengthPad, y, x + width - maxLengthPad, y + height, alignment, color, shadow, scale, msVisible); + } + + default void drawScaledScrollingString(GuiGraphics graphics, Component text, int minX, int minY, int maxX, int maxY, TextAlignment alignment, int color, boolean shadow, + float scale, long msVisible) { if (scale == 1.0F) { - drawScrollingString(guiGraphics, text, minX, minY, maxX, maxY, alignment, color, shadow); + drawScrollingString(graphics, text, minX, minY, maxX, maxY, alignment, color, shadow, msVisible); return; } - float textWidth = getStringWidth(text) * scale; + Font font = font(); + float textWidth = font.width(text) * scale; int areaWidth = maxX - minX; boolean isScrolling = textWidth > areaWidth; //Note: Instead of doing what vanilla does, we divide to float, and don't add one // That way if min and max are not just lineHeight away they will be more accurate, and otherwise it won't render one line below where it should be - float targetY = (minY + maxY - getLineHeight()) / 2F; + float targetY = (minY + maxY - font.lineHeight) / 2F; float targetX; if (isScrolling) { - targetX = prepScrollingString(guiGraphics, textWidth, areaWidth, minX, minY, maxX, maxY); + targetX = prepScrollingString(graphics, font, textWidth, areaWidth, minX, minY, maxX, maxY, Util.getMillis() - msVisible); } else { - targetX = alignment.getTarget(font(), minX, maxX, textWidth); + targetX = alignment.getTarget(font, minX, maxX, textWidth); } - PoseStack pose = prepTextScale(guiGraphics, targetX, targetY, scale); - guiGraphics.drawString(font(), text, 0, 0, color, shadow); + PoseStack pose = prepTextScale(graphics, font, targetX, targetY, scale); + graphics.drawString(font, text, 0, 0, color, shadow); pose.popPose(); if (isScrolling) { - guiGraphics.disableScissor(); + graphics.disableScissor(); } } @@ -144,35 +170,50 @@ default void drawScaledScrollingString(GuiGraphics guiGraphics, Component text, * Based off the logic for calculating the scissor area and draw target that vanilla does in * {@link AbstractWidget#renderScrollingString(GuiGraphics, Font, Component, int, int, int, int, int, int)} * + * @param visibleDuration Time in ms that this string has been visible for. + * * @apiNote Call {@link GuiGraphics#disableScissor()} after using this method */ - private static float prepScrollingString(GuiGraphics guiGraphics, double textWidth, int areaWidth, int minX, int minY, int maxX, int maxY) { - double overflowWidth = textWidth - areaWidth; - //TODO: Some variable that keeps track of when the gui was initialized (init method called?) so that we can ensure it always starts - // the text all the way at the left. (For right to left languages we should probably start it all the way at the right) - double seconds = Util.getMillis() / 1_000D; - double scrollPeriod = Math.max(overflowWidth * AbstractWidget.PERIOD_PER_SCROLLED_PIXEL, AbstractWidget.MIN_SCROLL_PERIOD); - //TODO: Improve this, as it moves very slowly at the edges, and much quicker in the middle - double scrolledSoFar = Math.sin((Math.PI / 2) * Math.cos((2 * Math.PI) * seconds / scrollPeriod)) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; - //Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); to calculate overflowedBy. But that is equivalent to just performing the following multiplication - double overflowedBy = scrolledSoFar * overflowWidth; + private static float prepScrollingString(GuiGraphics graphics, Font font, double textWidth, int areaWidth, int minX, int minY, int maxX, int maxY, long visibleDuration) { //Note: We are drawing in relative coordinates, but GuiGraphics#enableScissor, is expecting absolute coordinates, // so we need to get the translations from our pose stack - //Note: This is equivalent to what Matrix4f#getTranslation(Vector3f) would do, without the extra allocations. - Matrix4f matrix4f = guiGraphics.pose().last().pose(); + //Note: This is equivalent to what Matrix4f#getTranslation(Vector3f) would do, without all the extra allocations. + Matrix4f matrix4f = graphics.pose().last().pose(); int left = (int) matrix4f.m30(); int top = (int) matrix4f.m31(); - guiGraphics.enableScissor(left + minX, top + minY, left + maxX, top + maxY); - //TODO: Should this cast to float? I believe this makes it less choppy, but a bit blurry? - // So we probably don't want to cast overflowedBy to float - return minX - (int) overflowedBy; + graphics.enableScissor(left + minX, top + minY, left + maxX, top + maxY); + //TODO: Re-evaluate this, as for text (especially scaled text) when moving very slowly near the edges, it makes the text a bit blurry + // Though maybe it is better to just make it not move so insanely slowly near the edges + //Note: Vanilla casts overflowedBy to an int, as it only bothers drawing based on int pixels. + // As we already handle and calculates with floats, casting to a float here provides a much smoother looking scroll + return minX - (float) getOverflowedBy(font, textWidth - areaWidth, visibleDuration); + } + + private static double getOverflowedBy(Font font, double overflowWidth, long visibleDuration) { + //Seconds since the gui was opened + double seconds = visibleDuration / 1_000D; + double scrollPeriod = Math.max(overflowWidth * AbstractWidget.PERIOD_PER_SCROLLED_PIXEL, AbstractWidget.MIN_SCROLL_PERIOD); + //Controls the speed at which we go between the start of the scroll and the end + double scrollSpeedModifier = Math.cos((2 * Math.PI) * seconds / scrollPeriod); + if (!font.isBidirectional()) { + //If the text is left to right (such as english). We need to start the modifier at the opposite peak so that it starts + // at the beginning of the string + //Note: Mojang doesn't include this negative for rendering text in english, but that is because they just use the current ms + // for the seconds calculation, which means that they don't care where in the wave they start + scrollSpeedModifier = -scrollSpeedModifier; + } + //TODO: Do we want to improve this in some way or another, as it moves very slowly at the edges, and much quicker in the middle + // Potentially replace this with a sigmoid function? + double scrolledSoFar = Math.sin((Math.PI / 2) * scrollSpeedModifier) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; + //Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); to calculate overflowedBy. But that is equivalent to just performing the following multiplication + return scrolledSoFar * overflowWidth; } //Note: As translate will implicitly cast x and y to being floats, we might as well pass these in as floats to reduce duplicate code - private PoseStack prepTextScale(GuiGraphics guiGraphics, float x, float y, float scale) { - PoseStack pose = guiGraphics.pose(); + private static PoseStack prepTextScale(GuiGraphics graphics, Font font, float x, float y, float scale) { + PoseStack pose = graphics.pose(); pose.pushPose(); - float halfLineHeight = getLineHeight() / 2F; + float halfLineHeight = font.lineHeight / 2F; float yAdd = halfLineHeight - halfLineHeight * scale; pose.translate(x, y + yAdd, 0); pose.scale(scale, scale, scale); @@ -213,31 +254,30 @@ public WrappedTextRenderer(IFancyFontRenderer fontRenderer, Component text) { this.text = text; } - public void render(GuiGraphics guiGraphics, int x, int y, TextAlignment alignment, int color, int maxLength) { - calculateLines(maxLength); - drawLines(guiGraphics, x, y, maxLength, alignment, color, 1); + public void render(GuiGraphics graphics, int x, int y, int maxLength, TextAlignment alignment, int color) { + render(graphics, x, y, maxLength, alignment, color, 1); } - public int renderWithScale(GuiGraphics guiGraphics, int x, int y, TextAlignment alignment, int color, int maxLength, float scale) { - //Divide by scale for calculating actual max length so that when the text is scaled it has the proper total space available - calculateLines(Mth.floor(maxLength / scale)); - PoseStack pose = fontRenderer.prepTextScale(guiGraphics, x, y, scale); - drawLines(guiGraphics, 0, 0, maxLength, alignment, color, scale); + public int renderWithScale(GuiGraphics graphics, int x, int y, TextAlignment alignment, int color, int maxLength, float scale) { + PoseStack pose = prepTextScale(graphics, fontRenderer.font(), x, y, scale); + render(graphics, 0, 0, maxLength, alignment, color, scale); pose.popPose(); return linesToDraw.size(); } - private void drawLines(GuiGraphics guiGraphics, int x, int startY, int maxLength, TextAlignment alignment, int color, float scale) { + private void render(GuiGraphics graphics, int x, int startY, int maxLength, TextAlignment alignment, int color, float scale) { Font font = fontRenderer.font(); + //Divide by scale for calculating actual max length so that when the text is scaled it has the proper total space available + calculateLines(font, scale == 1 ? maxLength : Mth.floor(maxLength / scale)); + int maxX = x + maxLength; for (FormattedCharSequence line : linesToDraw) { - guiGraphics.drawString(font, line, alignment.getTarget(font, x, x + maxLength, font.width(line) * scale), startY, color, false); + graphics.drawString(font, line, alignment.getTarget(font, x, maxX, scale * font.width(line)), startY, color, false); startY += font.lineHeight; } } - private void calculateLines(int maxLength) { + private void calculateLines(Font font, int maxLength) { //If something changed since the last time we calculated it - Font font = fontRenderer.font(); if (font != null && (lastFont != font || lastMaxLength != maxLength)) { lastFont = font; lastMaxLength = maxLength; @@ -246,8 +286,9 @@ private void calculateLines(int maxLength) { } public int getRequiredHeight(int maxLength) { - calculateLines(maxLength); - return fontRenderer.getLineHeight() * linesToDraw.size(); + Font font = fontRenderer.font(); + calculateLines(font, maxLength); + return font.lineHeight * linesToDraw.size(); } } diff --git a/src/main/java/mekanism/common/integration/lookingat/LookingAtElement.java b/src/main/java/mekanism/common/integration/lookingat/LookingAtElement.java index 96ee4f53141..390a8a46ad7 100644 --- a/src/main/java/mekanism/common/integration/lookingat/LookingAtElement.java +++ b/src/main/java/mekanism/common/integration/lookingat/LookingAtElement.java @@ -4,8 +4,6 @@ import mekanism.client.gui.GuiUtils.TilingDirection; import mekanism.client.render.IFancyFontRenderer; import mekanism.client.render.MekanismRenderer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.network.chat.Component; @@ -57,11 +55,6 @@ public int getHeight() { return 13; } - @Override - public Font font() { - return Minecraft.getInstance().font; - } - public abstract int getScaledLevel(int level); @Nullable From abce9e933c0c8d3bb850b7889807d0a934de3a5d Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Thu, 24 Oct 2024 10:53:12 -0500 Subject: [PATCH 17/17] Persist how long dropdown menus have been opened for when resizing MC, and further improve when scrolling text gets reset in relation to switching to recipe viewers and resizing MC --- .../java/mekanism/client/gui/GuiMekanism.java | 20 ++++++++++++------- .../client/gui/element/GuiDropdown.java | 12 +++++++++++ .../client/render/IFancyFontRenderer.java | 8 ++++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/mekanism/client/gui/GuiMekanism.java b/src/main/java/mekanism/client/gui/GuiMekanism.java index 6d658349d53..a4712100c09 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanism.java +++ b/src/main/java/mekanism/client/gui/GuiMekanism.java @@ -99,8 +99,10 @@ protected void init() { //If our warning tracker isn't null (so this isn't the first time we are initializing, such as after resizing) // clear out any tracked warnings, so we don't have duplicates being tracked when we add our elements again warningTracker.clearTrackedWarnings(); + } else { + //If we haven't been initialized yet, we can initialize it here + lastMSInitialized = Util.getMillis(); } - lastMSInitialized = Util.getMillis(); addGuiElements(); if (warningTracker != null) { //If we have a warning tracker add it as a button, we do so via a method in case any of the sub GUIs need to reposition where it ends up @@ -305,12 +307,16 @@ protected boolean hasClickedOutside(double mouseX, double mouseY, int guiLeftIn, @Override protected void repositionElements() { - //Mark that we are not switching to JEI if we start being initialized again - // Note: We can do this here as the screen will always have initialized as true, so we don't need to definalize init(mc, width, height) - // as it will never potentially have init() with no params be the call path - // Additionally, as the screen is not actively being used we shouldn't have cases this is called from resize while we are not present - // and setting this to false when it is already false does nothing - switchingToRecipeViewer = false; + if (switchingToRecipeViewer) { + //Mark that we are not switching to JEI if we start being initialized again + // Note: We can do this here as the screen will always have initialized as true, so we don't need to definalize init(mc, width, height) + // as it will never potentially have init() with no params be the call path + // Additionally, as the screen is not actively being used we shouldn't have cases this is called from resize while we are not present + // and setting this to false when it is already false does nothing + switchingToRecipeViewer = false; + //If we were switching to a recipe viewer, then we also want to restart the time the scrolling text is using + lastMSInitialized = Util.getMillis(); + } super.repositionElements(); } diff --git a/src/main/java/mekanism/client/gui/element/GuiDropdown.java b/src/main/java/mekanism/client/gui/element/GuiDropdown.java index 235ae05c684..35bb862fc9d 100644 --- a/src/main/java/mekanism/client/gui/element/GuiDropdown.java +++ b/src/main/java/mekanism/client/gui/element/GuiDropdown.java @@ -146,4 +146,16 @@ private void setOpen(boolean open) { } } } + + @Override + public void syncFrom(GuiElement element) { + super.syncFrom(element); + GuiDropdown old = (GuiDropdown) element; + if (old.isOpen) { + //Sync the fact it is open, and how long it has been open for + isOpen = true; + height += options.length * 10 + 1; + msOpened = old.msOpened; + } + } } diff --git a/src/main/java/mekanism/client/render/IFancyFontRenderer.java b/src/main/java/mekanism/client/render/IFancyFontRenderer.java index 3f2c5d9c9f0..4910b28e4e9 100644 --- a/src/main/java/mekanism/client/render/IFancyFontRenderer.java +++ b/src/main/java/mekanism/client/render/IFancyFontRenderer.java @@ -30,8 +30,6 @@ default Font font() { default long getTimeOpened() { //TODO: Try and improve how we handle the time opened concept for test in scrollable elements //TODO: Gui elements that are part of a GuiWindow, should use the window's time instead of the gui's time - //TODO: When resizing/re-init of a GUI, do we want to reset this? I think we currently do, but we probably don't want to be doing so - // we also then will need to make gui elements copy the value. Also when switchingToRecipeViewer is true, we want to reset it return 0; } @@ -204,8 +202,10 @@ private static double getOverflowedBy(Font font, double overflowWidth, long visi } //TODO: Do we want to improve this in some way or another, as it moves very slowly at the edges, and much quicker in the middle // Potentially replace this with a sigmoid function? - double scrolledSoFar = Math.sin((Math.PI / 2) * scrollSpeedModifier) / 2.0 + AbstractWidget.PERIOD_PER_SCROLLED_PIXEL; - //Vanilla uses: Mth.lerp(d2, 0.0, overflowWidth); to calculate overflowedBy. But that is equivalent to just performing the following multiplication + // It is particularly slow when there is a large amount of overflow + //Shift it so that the range is from [0, 1] + double scrolledSoFar = Math.sin((Math.PI / 2) * scrollSpeedModifier) / 2.0 + 0.5; + //Vanilla uses: Mth.lerp(scrolledSoFar, 0.0, overflowWidth); to calculate overflowedBy. But that is equivalent to just performing the following multiplication return scrolledSoFar * overflowWidth; }