Skip to content

Commit

Permalink
Close #1505
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Oct 23, 2023
1 parent f216d7d commit 032a0ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ReloadPluginsEntry extends AbstractConfigListEntry<Unit> {
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
if (PluginManager.areAnyReloading()) {
Screen screen = Minecraft.getInstance().screen;
Minecraft.getInstance().setScreen(new ConfigReloadingScreen(Component.translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen)));
Minecraft.getInstance().setScreen(new ConfigReloadingScreen(Component.translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen), null));
} else {
super.render(matrices, mouseX, mouseY, delta);
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public Optional<Unit> getDefaultValue() {

@Override
public void save() {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.Util;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
Expand All @@ -39,12 +41,14 @@ public class ConfigReloadingScreen extends Screen {
private final BooleanSupplier predicate;
private Supplier<@Nullable Component> subtitle = () -> null;
private final Runnable parent;
private final Runnable cancel;

public ConfigReloadingScreen(Component title, BooleanSupplier predicate, Runnable parent) {
public ConfigReloadingScreen(Component title, BooleanSupplier predicate, Runnable parent, Runnable cancel) {
super(Component.empty());
this.title = title;
this.predicate = predicate;
this.parent = parent;
this.cancel = cancel;
}

public void setSubtitle(Supplier<@Nullable Component> subtitle) {
Expand All @@ -56,6 +60,15 @@ public boolean shouldCloseOnEsc() {
return false;
}

@Override
public void init() {
super.init();
if (cancel == null) return;
this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120 + 12, 200, 20, CommonComponents.GUI_CANCEL, button -> {
cancel.run();
}));
}

@Override
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
this.renderDirtBackground(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package me.shedaniel.rei.impl.client.gui.widget;

import com.mojang.math.Vector4f;
import dev.architectury.platform.Platform;
import dev.architectury.utils.value.BooleanValue;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
Expand Down Expand Up @@ -150,15 +151,22 @@ public static List<FavoriteMenuEntry> createInputMethodEntries(MenuAccess access
ConfigReloadingScreen reloadingScreen = new ConfigReloadingScreen(Component.translatable("text.rei.input.methods.initializing"),
() -> !future.isDone(), () -> {
Minecraft.getInstance().setScreen(screen);
}, () -> {
Minecraft.getInstance().setScreen(screen);
InternalLogger.getInstance().error("Failed to prepare input method: cancelled");
ConfigManagerImpl.getInstance().getConfig().setInputMethodId(new ResourceLocation("rei:default"));
future.cancel(Platform.isFabric());
service.shutdown();
});
reloadingScreen.setSubtitle(() -> Component.translatable("text.rei.input.methods.reload.progress", String.format("%.2f", progress[0] * 100)));
Minecraft.getInstance().setScreen(reloadingScreen);
access.close();
future.whenComplete((unused, throwable) -> {
service.shutdown();
if (throwable != null) return;
ScreenOverlayImpl.getInstance().getHintsContainer().addHint(12, () -> new Point(getCraftableFilterBounds().getCenterX(), getCraftableFilterBounds().getCenterY()),
"text.rei.hint.input.methods", List.of(Component.translatable("text.rei.hint.input.methods")));
});
ScreenOverlayImpl.getInstance().getHintsContainer().addHint(12, () -> new Point(getCraftableFilterBounds().getCenterX(), getCraftableFilterBounds().getCenterY()),
"text.rei.hint.input.methods", List.of(Component.translatable("text.rei.hint.input.methods")));
})
.withActive(() -> !Objects.equals(config.getInputMethodId(), pair.getKey()))
.withTooltip(() -> Tooltip.create(Widget.mouse(), pair.getValue().getDescription()))
Expand Down

0 comments on commit 032a0ff

Please sign in to comment.