80 lines
2 KiB
Java
80 lines
2 KiB
Java
package net.minecraft.client.gui.screens;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.GameNarrator;
|
|
import net.minecraft.client.gui.GuiGraphics;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.util.ProgressListener;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class ProgressScreen extends Screen implements ProgressListener {
|
|
@Nullable
|
|
private Component header;
|
|
@Nullable
|
|
private Component stage;
|
|
private int progress;
|
|
private boolean stop;
|
|
private final boolean clearScreenAfterStop;
|
|
|
|
public ProgressScreen(boolean clearScreenAfterStop) {
|
|
super(GameNarrator.NO_TITLE);
|
|
this.clearScreenAfterStop = clearScreenAfterStop;
|
|
}
|
|
|
|
@Override
|
|
public boolean shouldCloseOnEsc() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
protected boolean shouldNarrateNavigation() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void progressStartNoAbort(Component component) {
|
|
this.progressStart(component);
|
|
}
|
|
|
|
@Override
|
|
public void progressStart(Component header) {
|
|
this.header = header;
|
|
this.progressStage(Component.translatable("menu.working"));
|
|
}
|
|
|
|
@Override
|
|
public void progressStage(Component stage) {
|
|
this.stage = stage;
|
|
this.progressStagePercentage(0);
|
|
}
|
|
|
|
@Override
|
|
public void progressStagePercentage(int progress) {
|
|
this.progress = progress;
|
|
}
|
|
|
|
@Override
|
|
public void stop() {
|
|
this.stop = true;
|
|
}
|
|
|
|
@Override
|
|
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
|
if (this.stop) {
|
|
if (this.clearScreenAfterStop) {
|
|
this.minecraft.setScreen(null);
|
|
}
|
|
} else {
|
|
super.render(guiGraphics, mouseX, mouseY, partialTick);
|
|
if (this.header != null) {
|
|
guiGraphics.drawCenteredString(this.font, this.header, this.width / 2, 70, 16777215);
|
|
}
|
|
|
|
if (this.stage != null && this.progress != 0) {
|
|
guiGraphics.drawCenteredString(this.font, Component.empty().append(this.stage).append(" " + this.progress + "%"), this.width / 2, 90, 16777215);
|
|
}
|
|
}
|
|
}
|
|
}
|