Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
修复快速关闭的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CaaMoe committed Apr 27, 2023
1 parent 24120a7 commit 7ee2781
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
public class MixinButtonWidget {
@Inject(method = "onPress", at = @At("HEAD"), cancellable = true)
private void onOnPress(CallbackInfo ci) {
if (MinecraftClient.getInstance().currentScreen instanceof ConfirmScreen) return;
if (MinecraftClient.getInstance().currentScreen instanceof ConfirmScreen){
if (((ConfirmScreen) MinecraftClient.getInstance().currentScreen).isConfirmed()) {
return;
}
}
EventResult result = ButtonPressEvent.BUTTON_PRESS.invoker().onPress((ButtonWidget) (Object) this);
if(result == EventResult.CANCEL){
ci.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public class MixinMinecraftClient {

@Inject(method = "scheduleStop", at = @At("HEAD"), cancellable = true)
private void onScheduleStop(CallbackInfo ci) {
if (currentScreen instanceof ConfirmScreen) return;
if (currentScreen instanceof ConfirmScreen) {
if (((ConfirmScreen) currentScreen).isConfirmed()) {
return;
}
ci.cancel();
return;
}
EventResult result = ClientScheduleStopEvent.CLIENT_SCHEDULE_STOP.invoker().onScheduleStop();
if (result == EventResult.CANCEL) {
GLFW.glfwSetWindowShouldClose(this.window.getHandle(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public class ConfirmScreen extends Screen {
private ButtonWidget cancel;
private ButtonWidget confirm;

private boolean confirmed = false;

public boolean isConfirmed() {
return confirmed;
}

public ConfirmScreen(Screen parentScreen, Text message, Runnable confirm) {
this(parentScreen, message, button -> confirm.run());
}
Expand All @@ -42,7 +48,11 @@ public void tick() {
}

private void initButton() {
confirm = style.generateConfirmButtons(this, onConfirm);
confirm = style.generateConfirmButtons(this, button -> {
confirmed = true;
confirm.onPress();
});

cancel = style.generateCancelButtons(this, onCancel);

confirm.active = false;
Expand Down

0 comments on commit 7ee2781

Please sign in to comment.