forked from Clones/Controlify
➕ Config option delegate_setup
to not discover controllers immediately.
This commit is contained in:
@ -63,6 +63,7 @@ public class Controlify implements ControlifyApi {
|
||||
private final ControlifyConfig config = new ControlifyConfig(this);
|
||||
|
||||
private final Queue<Controller<?, ?>> calibrationQueue = new ArrayDeque<>();
|
||||
private boolean canDiscoverControllers = true;
|
||||
|
||||
private int consecutiveInputSwitches = 0;
|
||||
private double lastInputSwitchTime = 0;
|
||||
@ -78,7 +79,20 @@ public class Controlify implements ControlifyApi {
|
||||
|
||||
var controllersConnected = IntStream.range(0, GLFW.GLFW_JOYSTICK_LAST + 1).anyMatch(GLFW::glfwJoystickPresent);
|
||||
if (controllersConnected) {
|
||||
askNatives().whenComplete((loaded, th) -> discoverControllers());
|
||||
if (!config().globalSettings().delegateSetup) {
|
||||
askNatives().whenComplete((loaded, th) -> discoverControllers());
|
||||
} else {
|
||||
ToastUtils.sendToast(
|
||||
Component.translatable("controlify.toast.setup_in_config.title"),
|
||||
Component.translatable(
|
||||
"controlify.toast.setup_in_config.description",
|
||||
Component.translatable("options.title"),
|
||||
Component.translatable("controls.keybinds.title"),
|
||||
Component.literal("Controlify")
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// listen for new controllers
|
||||
@ -107,7 +121,7 @@ public class Controlify implements ControlifyApi {
|
||||
nativeOnboardingFuture = new CompletableFuture<>();
|
||||
|
||||
minecraft.setScreen(new SDLOnboardingScreen(
|
||||
minecraft.screen,
|
||||
() -> minecraft.screen,
|
||||
answer -> {
|
||||
if (answer)
|
||||
SDL2NativesManager.initialise();
|
||||
@ -118,7 +132,12 @@ public class Controlify implements ControlifyApi {
|
||||
return nativeOnboardingFuture;
|
||||
}
|
||||
|
||||
private void discoverControllers() {
|
||||
public void discoverControllers() {
|
||||
if (!canDiscoverControllers) {
|
||||
throw new IllegalStateException("Cannot discover controllers!");
|
||||
}
|
||||
canDiscoverControllers = false;
|
||||
|
||||
DebugLog.log("Discovering and initializing controllers...");
|
||||
|
||||
if (config().globalSettings().loadVibrationNatives)
|
||||
@ -321,6 +340,8 @@ public class Controlify implements ControlifyApi {
|
||||
this.askToSwitchController(controller);
|
||||
config().saveIfDirty();
|
||||
}
|
||||
|
||||
canDiscoverControllers = false;
|
||||
}
|
||||
|
||||
private void onControllerDisconnect(int jid) {
|
||||
|
@ -13,6 +13,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@ -119,12 +120,16 @@ public class ControlifyConfig {
|
||||
setDirty();
|
||||
}
|
||||
|
||||
this.compoundJoysticks = object
|
||||
.getAsJsonArray("compound_joysticks")
|
||||
.asList()
|
||||
.stream()
|
||||
.map(element -> GSON.fromJson(element, CompoundJoystickInfo.class))
|
||||
.collect(Collectors.toMap(info -> info.type().mappingId(), Function.identity()));
|
||||
if (object.has("compound_joysticks")) {
|
||||
this.compoundJoysticks = object
|
||||
.getAsJsonArray("compound_joysticks")
|
||||
.asList()
|
||||
.stream()
|
||||
.map(element -> GSON.fromJson(element, CompoundJoystickInfo.class))
|
||||
.collect(Collectors.toMap(info -> info.type().mappingId(), Function.identity()));
|
||||
} else {
|
||||
this.compoundJoysticks = Map.of();
|
||||
}
|
||||
|
||||
if (object.has("current_controller")) {
|
||||
JsonElement element = object.get("current_controller");
|
||||
|
@ -20,4 +20,5 @@ public class GlobalSettings {
|
||||
public ReachAroundMode reachAround = ReachAroundMode.OFF;
|
||||
public boolean uiSounds = false;
|
||||
public boolean notifyLowBattery = true;
|
||||
public boolean delegateSetup = false;
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@ -48,14 +47,26 @@ public class YACLHelper {
|
||||
private static final Function<Float, Component> percentOrOffFormatter = v -> v == 0 ? CommonComponents.OPTION_OFF : percentFormatter.apply(v);
|
||||
|
||||
public static Screen openConfigScreen(Screen parent) {
|
||||
Screen configScreen = generateConfigScreen(parent);
|
||||
if (!Controlify.instance().config().globalSettings().vibrationOnboarded)
|
||||
configScreen = new SDLOnboardingScreen(configScreen, yes -> {
|
||||
var controlify = Controlify.instance();
|
||||
|
||||
if (!controlify.config().globalSettings().vibrationOnboarded) {
|
||||
return new SDLOnboardingScreen(() -> generateConfigScreen(parent), yes -> {
|
||||
if (yes) {
|
||||
SDL2NativesManager.initialise();
|
||||
|
||||
if (controlify.config().globalSettings().delegateSetup) {
|
||||
controlify.discoverControllers();
|
||||
controlify.config().globalSettings().delegateSetup = false;
|
||||
controlify.config().save();
|
||||
}
|
||||
}
|
||||
});
|
||||
return configScreen;
|
||||
});
|
||||
} else if (Controlify.instance().config().globalSettings().delegateSetup) {
|
||||
controlify.discoverControllers();
|
||||
controlify.config().globalSettings().delegateSetup = false;
|
||||
controlify.config().save();
|
||||
}
|
||||
return generateConfigScreen(parent);
|
||||
}
|
||||
|
||||
private static Screen generateConfigScreen(Screen parent) {
|
||||
|
@ -9,15 +9,17 @@ import net.minecraft.client.gui.screens.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SDLOnboardingScreen extends ConfirmScreen {
|
||||
public SDLOnboardingScreen(Screen lastScreen, BooleanConsumer onAnswered) {
|
||||
public SDLOnboardingScreen(Supplier<Screen> lastScreen, BooleanConsumer onAnswered) {
|
||||
super(
|
||||
yes -> {
|
||||
Controlify.instance().config().globalSettings().loadVibrationNatives = yes;
|
||||
Controlify.instance().config().globalSettings().vibrationOnboarded = true;
|
||||
Controlify.instance().config().save();
|
||||
Minecraft.getInstance().setScreen(lastScreen);
|
||||
onAnswered.accept(yes);
|
||||
Minecraft.getInstance().setScreen(lastScreen.get());
|
||||
},
|
||||
Component.translatable("controlify.sdl2_onboarding.title").withStyle(ChatFormatting.BOLD),
|
||||
Util.make(() -> {
|
||||
|
Reference in New Issue
Block a user