Skip to content

Commit

Permalink
Fix the majority of GUIs where certain text didn't declare proper bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Sep 24, 2024
1 parent 1548616 commit 91a46c5
Show file tree
Hide file tree
Showing 47 changed files with 182 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TileEntityFusionReactorController, EmptyTileContainer<TileEntityFusionReactorController>> {

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/java/mekanism/client/gui/GuiChemicalTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

public class GuiDimensionalStabilizer extends GuiMekanismTile<TileEntityDimensionalStabilizer, MekanismTileContainer<TileEntityDimensionalStabilizer>> {

//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<TileEntityDimensionalStabilizer> container, Inventory inv, Component title) {
super(container, inv, title);
inventoryLabelY += 2;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mekanism/client/gui/GuiLaserAmplifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mekanism/client/gui/GuiMatrixStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class GuiMatrixStats extends GuiMekanismTile<TileEntityInductionCasing, E

public GuiMatrixStats(EmptyTileContainer<TileEntityInductionCasing> container, Inventory inv, Component title) {
super(container, inv, title);
titleLabelY -= 1;
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/mekanism/client/gui/GuiMekanism.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mekanism/client/gui/GuiModuleTweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/mekanism/client/gui/GuiTeleporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
public class GuiTeleporter extends GuiMekanismTile<TileEntityTeleporter, MekanismTileContainer<TileEntityTeleporter>>
implements ITileGuiFrequencySelector<TeleporterFrequency, TileEntityTeleporter>, IGuiColorFrequencySelector<TeleporterFrequency> {

private GuiTeleporterStatus status;

public GuiTeleporter(MekanismTileContainer<TileEntityTeleporter> container, Inventory inv, Component title) {
super(container, inv, title);
imageHeight += 74;
Expand All @@ -28,14 +30,14 @@ public GuiTeleporter(MekanismTileContainer<TileEntityTeleporter> 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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/mekanism/client/gui/element/GuiElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/mekanism/client/gui/element/GuiInnerScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -132,7 +133,7 @@ public void updateTooltip(int mouseX, int mouseY) {
setTooltip(lastTooltip);
}

protected int getMaxTextWidth() {
protected int getMaxTextWidth(int row) {
return getWidth();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/mekanism/client/gui/item/GuiDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void updateScrollList(Set<DictionaryTagType> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class GuiPortableTeleporter extends GuiMekanism<PortableTeleporterContainer> implements IItemGuiFrequencySelector<TeleporterFrequency, PortableTeleporterContainer>,
IGuiColorFrequencySelector<TeleporterFrequency> {

private GuiTeleporterStatus status;
private MekanismButton teleportButton;

public GuiPortableTeleporter(PortableTeleporterContainer container, Inventory inv, Component title) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}

Expand Down
Loading

0 comments on commit 91a46c5

Please sign in to comment.