Fixed Buttons in the error screen are incorrectly rendered if they are extremely long Closes #5687 (#5924)

This commit is contained in:
Gamebuster 2019-08-02 16:42:58 -04:00 committed by LexManos
parent 7acb380ba8
commit 9a50c208f0
2 changed files with 35 additions and 10 deletions

View file

@ -48,11 +48,36 @@ public class GuiButtonExt extends Button
@Override
public void renderButton(int mouseX, int mouseY, float partial)
{
super.renderButton(mouseX, mouseY, partial);
FontRenderer font = Minecraft.getInstance().fontRenderer;
int strWidth = font.getStringWidth(this.getMessage());
int ellipsisWidth = font.getStringWidth("...");
if (strWidth > width - 6 && strWidth > ellipsisWidth)
setMessage(font.trimStringToWidth(getMessage(), width - 6 - ellipsisWidth).trim() + "...");
if (this.visible)
{
Minecraft mc = Minecraft.getInstance();
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
int k = this.getYImage(this.isHovered);
GuiUtils.drawContinuousTexturedBox(WIDGETS_LOCATION, this.x, this.y, 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.blitOffset);
this.renderBg(mc, mouseX, mouseY);
int color = 14737632;
if (packedFGColor != 0)
{
color = packedFGColor;
}
else if (!this.active)
{
color = 10526880;
}
else if (this.isHovered)
{
color = 16777120;
}
String buttonText = this.getMessage();
int strWidth = mc.fontRenderer.getStringWidth(buttonText);
int ellipsisWidth = mc.fontRenderer.getStringWidth("...");
if (strWidth > width - 6 && strWidth > ellipsisWidth)
buttonText = mc.fontRenderer.trimStringToWidth(buttonText, width - 6 - ellipsisWidth).trim() + "...";
this.drawCenteredString(mc.fontRenderer, buttonText, this.x + this.width / 2, this.y + (this.height - 8) / 2, color);
}
}
}

View file

@ -23,7 +23,6 @@ import com.google.common.base.Strings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.screen.ErrorScreen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.widget.list.ExtendedList;
import net.minecraft.util.Util;
import net.minecraft.util.text.StringTextComponent;
@ -33,6 +32,7 @@ import net.minecraftforge.fml.LoadingFailedException;
import net.minecraftforge.fml.ModLoadingException;
import net.minecraftforge.fml.ModLoadingWarning;
import net.minecraftforge.fml.client.ClientHooks;
import net.minecraftforge.fml.client.config.GuiButtonExt;
import net.minecraftforge.fml.loading.FMLPaths;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -73,10 +73,10 @@ public class LoadingErrorScreen extends ErrorScreen {
this.warningHeader = TextFormatting.YELLOW + ForgeI18n.parseMessage("fml.loadingerrorscreen.warningheader", this.modLoadErrors.size()) + TextFormatting.RESET;
int yOffset = this.modLoadErrors.isEmpty() ? 46 : 38;
this.addButton(new Button(50, this.height - yOffset, this.width / 2 - 55, 20, ForgeI18n.parseMessage("fml.button.open.mods.folder"), b -> Util.getOSType().openFile(modsDir.toFile())));
this.addButton(new Button(this.width / 2 + 5, this.height - yOffset, this.width / 2 - 55, 20, ForgeI18n.parseMessage("fml.button.open.file", logFile.getFileName()), b -> Util.getOSType().openFile(logFile.toFile())));
this.addButton(new GuiButtonExt(50, this.height - yOffset, this.width / 2 - 55, 20, ForgeI18n.parseMessage("fml.button.open.mods.folder"), b -> Util.getOSType().openFile(modsDir.toFile())));
this.addButton(new GuiButtonExt(this.width / 2 + 5, this.height - yOffset, this.width / 2 - 55, 20, ForgeI18n.parseMessage("fml.button.open.file", logFile.getFileName()), b -> Util.getOSType().openFile(logFile.toFile())));
if (this.modLoadErrors.isEmpty()) {
this.addButton(new Button(this.width / 4, this.height - 24, this.width / 2, 20, ForgeI18n.parseMessage("fml.button.continue.launch"), b -> {
this.addButton(new GuiButtonExt(this.width / 4, this.height - 24, this.width / 2, 20, ForgeI18n.parseMessage("fml.button.continue.launch"), b -> {
ClientHooks.logMissingTextureErrors();
this.minecraft.displayGuiScreen(null);
}));