mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
Improve look of notification GUI, improve StartupQuery API
This commit is contained in:
1 parent
f0bab0fb38
commit
eb9c966095
4 files changed
+181
-48
No files matched your search
@@ -30,16 +30,16 @@ public class ConfirmationScreen extends NotificationScreen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
protected void addConfirmationButtons()
|
||||
{
|
||||
this.addButton(new Button(this.width / 2 - 104, this.height - 38, 100, 20, ForgeI18n.parseMessage("gui.yes"), b ->
|
||||
this.addButton(new Button(this.width / 2 - 104, this.height - PADDING - 20, 100, 20, ForgeI18n.parseMessage("gui.yes"), b ->
|
||||
{
|
||||
ConfirmationScreen.this.minecraft.currentScreen = null;
|
||||
query.setResult(true);
|
||||
query.finish();
|
||||
}
|
||||
));
|
||||
this.addButton(new Button(this.width / 2 + 4, this.height - 38, 100, 20, ForgeI18n.parseMessage("gui.no"), b ->
|
||||
this.addButton(new Button(this.width / 2 + 4, this.height - PADDING - 20, 100, 20, ForgeI18n.parseMessage("gui.no"), b ->
|
||||
{
|
||||
ConfirmationScreen.this.minecraft.currentScreen = null;
|
||||
query.setResult(false);
|
||||
|
||||
@@ -20,23 +20,81 @@
|
||||
package net.minecraftforge.fml.client.gui.screen;
|
||||
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.client.gui.ScrollPanel;
|
||||
import net.minecraftforge.fml.StartupQuery;
|
||||
|
||||
public class NotificationScreen extends Screen
|
||||
{
|
||||
private class TextPanel extends ScrollPanel
|
||||
{
|
||||
TextPanel(Minecraft client, int width, int height, int top, int left)
|
||||
{
|
||||
super(client, width, height, top, left);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentHeight()
|
||||
{
|
||||
int height = 0;
|
||||
height += (textLines.length * font.FONT_HEIGHT) + 4;
|
||||
if (height < this.height - 50)
|
||||
height = this.height - 50;
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawPanel(int entryRight, int relativeY, Tessellator tess, int mouseX, int mouseY)
|
||||
{
|
||||
drawCenteredLines(relativeY, textLines);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getScrollAmount()
|
||||
{
|
||||
return font.FONT_HEIGHT * 3;
|
||||
}
|
||||
}
|
||||
|
||||
protected static final int PADDING = 6;
|
||||
|
||||
protected final StartupQuery query;
|
||||
|
||||
private final String[] headerLines;
|
||||
private final String[] textLines;
|
||||
private final String action;
|
||||
|
||||
private ScrollPanel textPanel;
|
||||
|
||||
public NotificationScreen(StartupQuery query)
|
||||
{
|
||||
super(new TranslationTextComponent("fml.menu.notification.title"));
|
||||
this.query = query;
|
||||
this.headerLines = query.getHeader().isEmpty() ? new String[0] : query.getHeader().split("\n");
|
||||
this.textLines = query.getText().split("\n");
|
||||
this.action = query.getAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
this.buttons.add(new Button(this.width / 2 - 100, this.height - 38, 200, 20, I18n.format("gui.done"), b -> {
|
||||
super.init();
|
||||
int panelY = PADDING + headerLines.length * font.FONT_HEIGHT + PADDING;
|
||||
int panelHeight = this.height - PADDING - 20 - panelY;
|
||||
if (!action.isEmpty()) {
|
||||
panelHeight = panelHeight - font.FONT_HEIGHT - PADDING;
|
||||
}
|
||||
textPanel = new TextPanel(this.minecraft, this.width - (PADDING * 2), panelHeight, panelY, PADDING);
|
||||
this.children.add(textPanel);
|
||||
addConfirmationButtons();
|
||||
}
|
||||
|
||||
protected void addConfirmationButtons() {
|
||||
this.buttons.add(new Button(this.width / 2 - 100, this.height - PADDING - 20, 200, 20, I18n.format("gui.done"), b -> {
|
||||
NotificationScreen.this.minecraft.displayGuiScreen(null);
|
||||
query.finish();
|
||||
}));
|
||||
@@ -47,29 +105,28 @@ public class NotificationScreen extends Screen
|
||||
{
|
||||
this.renderBackground();
|
||||
|
||||
String[] lines = query.getText().split("\n");
|
||||
drawCenteredLines(PADDING, headerLines);
|
||||
|
||||
int spaceAvailable = this.height - 38 - 20;
|
||||
int spaceRequired = Math.min(spaceAvailable, 10 + 10 * lines.length);
|
||||
|
||||
int offset = 10 + (spaceAvailable - spaceRequired) / 2; // vertically centered
|
||||
|
||||
for (String line : lines)
|
||||
if (textPanel != null)
|
||||
{
|
||||
if (offset >= spaceAvailable)
|
||||
{
|
||||
this.drawCenteredString(this.font, "...", this.width / 2, offset, 0xFFFFFF);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!line.isEmpty()) this.drawCenteredString(this.font, line, this.width / 2, offset, 0xFFFFFF);
|
||||
offset += 10;
|
||||
}
|
||||
textPanel.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
if (!action.isEmpty())
|
||||
{
|
||||
drawCenteredString(font, action, this.width / 2, this.height - PADDING - 20 - font.FONT_HEIGHT, -1);
|
||||
}
|
||||
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
protected final StartupQuery query;
|
||||
protected void drawCenteredLines(int yStart, String... lines)
|
||||
{
|
||||
for (String line : lines)
|
||||
{
|
||||
if (!line.isEmpty())
|
||||
this.drawCenteredString(font, line, this.width / 2, yStart, 0xFFFFFF);
|
||||
yStart += font.FONT_HEIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user