Skip to content

Commit

Permalink
Tidy up VFPScreen#showErrorScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Jan 26, 2024
1 parent bcb3c57 commit a4f837f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,13 @@ public static void playClickSound() {
*
* @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)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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);
Expand All @@ -37,7 +37,7 @@ public AuthenticationSettings() {
}

public static AuthenticationSettings global() {
return instance;
return INSTANCE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -39,16 +40,18 @@

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);
Expand All @@ -58,11 +61,12 @@ public BedrockSettings() {
}

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 {
Expand All @@ -73,15 +77,15 @@ private void openBedrockAccountLogin() {
}
})));

RenderSystem.recordRenderCall(() -> MinecraftClient.getInstance().setScreen(prevScreen));
RenderSystem.recordRenderCall(() -> client.setScreen(prevScreen));
} catch (Throwable e) {
Thread.currentThread().interrupt();
VFPScreen.showErrorScreen("Microsoft Bedrock Login", e, prevScreen);
}
}

public static BedrockSettings global() {
return instance;
return INSTANCE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

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);

Expand Down Expand Up @@ -63,7 +63,7 @@ public DebugSettings() {
}

public static DebugSettings global() {
return instance;
return INSTANCE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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"),
Expand Down Expand Up @@ -63,10 +63,6 @@ public GeneralSettings() {
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);
Expand All @@ -77,4 +73,8 @@ public static ButtonWidget.Builder withOrientation(final ButtonWidget.Builder bu
};
}

public static GeneralSettings global() {
return INSTANCE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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));
Expand Down Expand Up @@ -66,7 +66,7 @@ public VisualSettings() {
}

public static VisualSettings global() {
return instance;
return INSTANCE;
}

}

0 comments on commit a4f837f

Please sign in to comment.