Tidy up VFPScreen#showErrorScreen

This commit is contained in:
FlorianMichael 2024-01-26 13:55:22 +01:00
parent bcb3c57832
commit a4f837fb9d
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
6 changed files with 30 additions and 31 deletions

View File

@ -169,18 +169,13 @@ public class VFPScreen extends Screen {
*
* @param title The title of the error screen
* @param throwable The throwable which should be thrown
* @param next The screen which should be opened after the error screen is closed
*/
public static void showErrorScreen(final String title, final Throwable throwable, final Screen parent) {
final MinecraftClient client = MinecraftClient.getInstance();
client.execute(() -> client.setScreen(new NoticeScreen(
() -> client.setScreen(parent),
Text.of(title),
Text.translatable("base.viafabricplus.something_went_wrong").append("\n" + throwable.getMessage()), Text.translatable("base.viafabricplus.cancel"),
false)
));
public static void showErrorScreen(final String title, final Throwable throwable, final Screen next) {
ViaFabricPlus.global().getLogger().error("Something went wrong!", throwable);
final MinecraftClient client = MinecraftClient.getInstance();
client.execute(() -> client.setScreen(new NoticeScreen(() -> client.setScreen(next), Text.of(title), Text.translatable("base.viafabricplus.something_went_wrong").append("\n" + throwable.getMessage()), Text.translatable("base.viafabricplus.cancel"), false)));
}
}

View File

@ -25,7 +25,7 @@ import net.minecraft.text.Text;
public class AuthenticationSettings extends SettingGroup {
private static final AuthenticationSettings instance = new AuthenticationSettings();
private static final AuthenticationSettings INSTANCE = new AuthenticationSettings();
public final BooleanSetting useBetaCraftAuthentication = new BooleanSetting(this, Text.translatable("authentication_settings.viafabricplus.use_beta_craft_authentication"), true);
public final BooleanSetting verifySessionForOnlineModeServers = new BooleanSetting(this, Text.translatable("authentication_settings.viafabricplus.verify_session_for_online_mode"), true);
@ -37,7 +37,7 @@ public class AuthenticationSettings extends SettingGroup {
}
public static AuthenticationSettings global() {
return instance;
return INSTANCE;
}
}

View File

@ -27,6 +27,7 @@ import de.florianmichael.viafabricplus.settings.base.ButtonSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.NoticeScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Util;
@ -39,16 +40,18 @@ import java.util.concurrent.CompletableFuture;
public class BedrockSettings extends SettingGroup {
private static final BedrockSettings instance = new BedrockSettings();
private static final BedrockSettings INSTANCE = new BedrockSettings();
public final ButtonSetting _1 = new ButtonSetting(this, Text.translatable("bedrock_settings.viafabricplus.click_to_set_bedrock_account"), () -> CompletableFuture.runAsync(this::openBedrockAccountLogin)) {
private final ButtonSetting ignored = new ButtonSetting(this, Text.translatable("bedrock_settings.viafabricplus.click_to_set_bedrock_account"), () -> CompletableFuture.runAsync(this::openBedrockAccountLogin)) {
@Override
public MutableText displayValue() {
final var account = ViaFabricPlus.global().getSaveManager().getAccountsSave().getBedrockAccount();
if (account == null) return super.displayValue();
return Text.literal("Bedrock account: " + account.getMcChain().getDisplayName());
if (account != null) {
return Text.literal("Bedrock account: " + account.getMcChain().getDisplayName());
} else {
return super.displayValue();
}
}
};
public final BooleanSetting openPromptGUIToConfirmTransfer = new BooleanSetting(this, Text.translatable("bedrock_settings.viafabricplus.confirm_transfer_server_prompt"), true);
@ -58,11 +61,12 @@ public class BedrockSettings extends SettingGroup {
}
private void openBedrockAccountLogin() {
final var prevScreen = MinecraftClient.getInstance().currentScreen;
final MinecraftClient client = MinecraftClient.getInstance();
final Screen prevScreen = client.currentScreen;
try {
ViaFabricPlus.global().getSaveManager().getAccountsSave().setBedrockAccount(MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(MinecraftAuth.createHttpClient(), new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new NoticeScreen(() -> {
MinecraftClient.getInstance().setScreen(prevScreen);
client.execute(() -> client.setScreen(new NoticeScreen(() -> {
client.setScreen(prevScreen);
Thread.currentThread().interrupt();
}, Text.literal("Microsoft Bedrock login"), Text.translatable("bedrock.viafabricplus.login"), Text.translatable("base.viafabricplus.cancel"), true)));
try {
@ -73,7 +77,7 @@ public class BedrockSettings extends SettingGroup {
}
})));
RenderSystem.recordRenderCall(() -> MinecraftClient.getInstance().setScreen(prevScreen));
RenderSystem.recordRenderCall(() -> client.setScreen(prevScreen));
} catch (Throwable e) {
Thread.currentThread().interrupt();
VFPScreen.showErrorScreen("Microsoft Bedrock Login", e, prevScreen);
@ -81,7 +85,7 @@ public class BedrockSettings extends SettingGroup {
}
public static BedrockSettings global() {
return instance;
return INSTANCE;
}
}

View File

@ -28,7 +28,7 @@ import net.raphimc.vialoader.util.VersionRange;
public class DebugSettings extends SettingGroup {
private static final DebugSettings instance = new DebugSettings();
private static final DebugSettings INSTANCE = new DebugSettings();
public final BooleanSetting queueConfigPackets = new BooleanSetting(this, Text.translatable("debug_settings.viafabricplus.queue_config_packets"), true);
@ -63,7 +63,7 @@ public class DebugSettings extends SettingGroup {
}
public static DebugSettings global() {
return instance;
return INSTANCE;
}
}

View File

@ -27,7 +27,7 @@ import net.minecraft.text.Text;
public class GeneralSettings extends SettingGroup {
private static final GeneralSettings instance = new GeneralSettings();
private static final GeneralSettings INSTANCE = new GeneralSettings();
public final ModeSetting multiplayerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general_settings.viafabricplus.multiplayer_screen_button_orientation"), 1,
Text.translatable("base.viafabricplus.left_top"),
@ -63,10 +63,6 @@ public class GeneralSettings extends SettingGroup {
emulateInventoryActionsInAlphaVersions.setTooltip(Text.translatable("base.viafabricplus.this_will_require_a_restart"));
}
public static GeneralSettings global() {
return instance;
}
public static ButtonWidget.Builder withOrientation(final ButtonWidget.Builder builder, final int orientationIndex, final int width, final int height) {
return switch (orientationIndex) {
case 0 -> builder.position(5, 5);
@ -77,4 +73,8 @@ public class GeneralSettings extends SettingGroup {
};
}
public static GeneralSettings global() {
return INSTANCE;
}
}

View File

@ -27,7 +27,7 @@ import net.raphimc.vialoader.util.VersionRange;
public class VisualSettings extends SettingGroup {
private static final VisualSettings instance = new VisualSettings();
private static final VisualSettings INSTANCE = new VisualSettings();
// 1.20.3 -> 1.20.2 and 1.16 -> 1.15.2
public final VersionedBooleanSetting removeNewerFeaturesFromJigsawScreen = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.remove_newer_features_from_jigsaw_screen"), VersionRange.andOlder(VersionEnum.r1_20_2));
@ -66,7 +66,7 @@ public class VisualSettings extends SettingGroup {
}
public static VisualSettings global() {
return instance;
return INSTANCE;
}
}