| 1 | package net.minecraft.client.gui.screens.worldselection;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.gui.GuiGraphicsExtractor;
|
| 6 | import net.minecraft.client.gui.components.Button;
|
| 7 | import net.minecraft.client.gui.screens.Screen;
|
| 8 | import net.minecraft.network.chat.CommonComponents;
|
| 9 | import net.minecraft.network.chat.Component;
|
| 10 | import net.minecraft.util.Mth;
|
| 11 | import net.minecraft.util.worldupdate.UpgradeProgress;
|
| 12 | import net.minecraft.util.worldupdate.UpgradeProgress.FileFixStats;
|
| 13 | import net.minecraft.util.worldupdate.UpgradeProgress.Type;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class FileFixerProgressScreen extends Screen {
|
| 17 | private static final int PROGRESS_BAR_WIDTH = 200;
|
| 18 | private static final int PROGRESS_BAR_HEIGHT = 2;
|
| 19 | private static final int LINE_SPACING = 3;
|
| 20 | private static final int SECTION_SPACING = 30;
|
| 21 | private static final Component SCANNING = Component.translatable("upgradeWorld.info.scanning");
|
| 22 | private final UpgradeProgress upgradeProgress;
|
| 23 | private Button cancelButton;
|
| 24 |
|
| 25 | public FileFixerProgressScreen(final UpgradeProgress upgradeProgress) {
|
| 26 | super(Component.translatable("upgradeWorld.title"));
|
| 27 | this.upgradeProgress = upgradeProgress;
|
| 28 | }
|
| 29 |
|
| 30 | @Override
|
| 31 | protected void init() {
|
| 32 | super.init();
|
| 33 | this.cancelButton = Button.builder(CommonComponents.GUI_CANCEL, button -> {
|
| 34 | this.upgradeProgress.setCanceled();
|
| 35 | button.active = false;
|
| 36 | }).bounds((this.width - 200) / 2, this.height / 2 + 100, 200, 20).build();
|
| 37 | this.addRenderableWidget(this.cancelButton);
|
| 38 | }
|
| 39 |
|
| 40 | @Override
|
| 41 | public boolean shouldCloseOnEsc() {
|
| 42 | return false;
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public void extractRenderState(final GuiGraphicsExtractor graphics, final int mouseX, final int mouseY, final float partialTick) {
|
| 47 | super.extractRenderState(graphics, mouseX, mouseY, partialTick);
|
| 48 | int xCenter = this.width / 2;
|
| 49 | int yCenter = this.height / 2;
|
| 50 | int textTop = yCenter - 50;
|
| 51 | this.extractTitle(graphics, xCenter, textTop);
|
| 52 | int totalFiles = this.upgradeProgress.getTotalFileFixStats().totalOperations();
|
| 53 | if (totalFiles > 0) {
|
| 54 | this.extractProgress(graphics, xCenter, textTop);
|
| 55 | } else {
|
| 56 | this.extractScanning(graphics, xCenter, textTop);
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | private void extractTitle(final GuiGraphicsExtractor graphics, final int xCenter, final int yTop) {
|
| 61 | graphics.centeredText(this.font, this.title, xCenter, yTop, -1);
|
| 62 | }
|
| 63 |
|
| 64 | private void extractProgress(final GuiGraphicsExtractor graphics, final int xCenter, final int textTop) {
|
| 65 | FileFixStats typeFileStats = this.upgradeProgress.getTypeFileFixStats();
|
| 66 | FileFixStats totalFileStats = this.upgradeProgress.getTotalFileFixStats();
|
| 67 | FileFixStats runningFileFixerStats = this.upgradeProgress.getRunningFileFixerStats();
|
| 68 | int y = textTop + 9 + 3;
|
| 69 | this.extractProgressBar(graphics, xCenter, y, runningFileFixerStats.getProgress());
|
| 70 | y += 7;
|
| 71 | this.extractFileStats(graphics, xCenter, y, totalFileStats.finishedOperations(), totalFileStats.totalOperations());
|
| 72 | y += 9 * 2 + 6;
|
| 73 | this.extractFileFixerCount(graphics, xCenter, y, runningFileFixerStats.finishedOperations(), runningFileFixerStats.totalOperations());
|
| 74 | y += 9 + 30 - 5;
|
| 75 | this.extractTypeText(graphics, xCenter, y);
|
| 76 | y += 9 + 3;
|
| 77 | this.extractProgressBar(graphics, xCenter, y, typeFileStats.getProgress());
|
| 78 | y += 7;
|
| 79 | this.extractTypeProgress(graphics, xCenter, y, typeFileStats.getProgress());
|
| 80 | }
|
| 81 |
|
| 82 | private void extractProgressBar(final GuiGraphicsExtractor graphics, final int xCenter, final int y, final float progress) {
|
| 83 | int barLeft = xCenter - 100;
|
| 84 | int barRight = barLeft + 200;
|
| 85 | int barBottom = y + 2;
|
| 86 | graphics.fill(barLeft, y, barRight, barBottom, -16777216);
|
| 87 | graphics.fill(barLeft, y, barLeft + Math.round(progress * 200.0F), barBottom, -16711936);
|
| 88 | }
|
| 89 |
|
| 90 | private void extractTypeText(final GuiGraphicsExtractor graphics, final int xCenter, final int y) {
|
| 91 | Type upgradeProgressType = this.upgradeProgress.getType();
|
| 92 | if (upgradeProgressType != null) {
|
| 93 | graphics.centeredText(this.font, upgradeProgressType.label(), xCenter, y, -6250336);
|
| 94 | }
|
| 95 | }
|
| 96 |
|
| 97 | private void extractTypeProgress(final GuiGraphicsExtractor graphics, final int xCenter, final int y, final float progress) {
|
| 98 | Component percentageText = Component.translatable("upgradeWorld.progress.percentage", Mth.floor(progress * 100.0F));
|
| 99 | graphics.centeredText(this.font, percentageText, xCenter, y, -6250336);
|
| 100 | }
|
| 101 |
|
| 102 | private void extractFileStats(final GuiGraphicsExtractor graphics, final int xCenter, final int yStart, final int converted, final int total) {
|
| 103 | int lineHeight = 9 + 3;
|
| 104 | graphics.centeredText(this.font, Component.translatable("upgradeWorld.info.converted", converted), xCenter, yStart, -6250336);
|
| 105 | graphics.centeredText(this.font, Component.translatable("upgradeWorld.info.total", total), xCenter, yStart + lineHeight, -6250336);
|
| 106 | }
|
| 107 |
|
| 108 | private void extractScanning(final GuiGraphicsExtractor graphics, final int xCenter, final int textTop) {
|
| 109 | graphics.centeredText(this.font, SCANNING, xCenter, textTop + 9 + 3, -6250336);
|
| 110 | }
|
| 111 |
|
| 112 | private void extractFileFixerCount(final GuiGraphicsExtractor graphics, final int xCenter, final int y, final int current, final int total) {
|
| 113 | Component percentageText = Component.translatable("upgradeWorld.info.file_fix_stage", current, total);
|
| 114 | graphics.centeredText(this.font, percentageText, xCenter, y, -6250336);
|
| 115 | }
|
| 116 | }
|
| 117 |
|