| 1 | package net.minecraft.client.gui.screens.options;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableList;
|
| 4 | import java.util.List;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.gui.ActiveTextCollector;
|
| 8 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 9 | import net.minecraft.client.gui.TextAlignment;
|
| 10 | import net.minecraft.client.gui.components.Button;
|
| 11 | import net.minecraft.client.gui.components.MultiLineLabel;
|
| 12 | import net.minecraft.client.gui.screens.Screen;
|
| 13 | import net.minecraft.network.chat.CommonComponents;
|
| 14 | import net.minecraft.network.chat.Component;
|
| 15 | import net.minecraft.network.chat.ComponentUtils;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class UnsupportedGraphicsWarningScreen extends Screen {
|
| 19 | private static final int BUTTON_PADDING = 20;
|
| 20 | private static final int BUTTON_MARGIN = 5;
|
| 21 | private static final int BUTTON_HEIGHT = 20;
|
| 22 | private final Component narrationMessage;
|
| 23 | private final List<Component> message;
|
| 24 | private final ImmutableList<UnsupportedGraphicsWarningScreen.ButtonOption> buttonOptions;
|
| 25 | private MultiLineLabel messageLines = MultiLineLabel.EMPTY;
|
| 26 | private int contentTop;
|
| 27 | private int buttonWidth;
|
| 28 |
|
| 29 | protected UnsupportedGraphicsWarningScreen(
|
| 30 | final Component title, final List<Component> message, final ImmutableList<UnsupportedGraphicsWarningScreen.ButtonOption> buttonOptions
|
| 31 | ) {
|
| 32 | super(title);
|
| 33 | this.message = message;
|
| 34 | this.narrationMessage = CommonComponents.joinForNarration(title, ComponentUtils.formatList(message, CommonComponents.EMPTY));
|
| 35 | this.buttonOptions = buttonOptions;
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | public Component getNarrationMessage() {
|
| 40 | return this.narrationMessage;
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public void init() {
|
| 45 | for (UnsupportedGraphicsWarningScreen.ButtonOption buttonOption : this.buttonOptions) {
|
| 46 | this.buttonWidth = Math.max(this.buttonWidth, 20 + this.font.width(buttonOption.message) + 20);
|
| 47 | }
|
| 48 |
|
| 49 | int buttonAdvance = 5 + this.buttonWidth + 5;
|
| 50 | int contentWidth = buttonAdvance * this.buttonOptions.size();
|
| 51 | this.messageLines = MultiLineLabel.create(this.font, contentWidth, this.message.toArray(new Component[0]));
|
| 52 | int messageHeight = this.messageLines.getLineCount() * 9;
|
| 53 | this.contentTop = (int)(this.height / 2.0 - messageHeight / 2.0);
|
| 54 | int buttonTop = this.contentTop + messageHeight + 9 * 2;
|
| 55 | int x = (int)(this.width / 2.0 - contentWidth / 2.0);
|
| 56 |
|
| 57 | for (UnsupportedGraphicsWarningScreen.ButtonOption buttonOption : this.buttonOptions) {
|
| 58 | this.addRenderableWidget(Button.builder(buttonOption.message, buttonOption.onPress).bounds(x, buttonTop, this.buttonWidth, 20).build());
|
| 59 | x += buttonAdvance;
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float a) {
|
| 65 | super.extractRenderState(graphics, mouseX, mouseY, a);
|
| 66 | ActiveTextCollector textRenderer = graphics.textRenderer();
|
| 67 | graphics.centeredText(this.font, this.title, this.width / 2, this.contentTop - 9 * 2, -1);
|
| 68 | this.messageLines.visitLines(TextAlignment.CENTER, this.width / 2, this.contentTop, 9, textRenderer);
|
| 69 | }
|
| 70 |
|
| 71 | @Override
|
| 72 | public boolean shouldCloseOnEsc() {
|
| 73 | return false;
|
| 74 | }
|
| 75 |
|
| 76 | @Environment(EnvType.CLIENT)
|
| 77 | public static final class ButtonOption {
|
| 78 | private final Component message;
|
| 79 | private final Button.OnPress onPress;
|
| 80 |
|
| 81 | public ButtonOption(final Component message, final Button.OnPress onPress) {
|
| 82 | this.message = message;
|
| 83 | this.onPress = onPress;
|
| 84 | }
|
| 85 | }
|
| 86 | }
|
| 87 |
|