-
-
Notifications
You must be signed in to change notification settings - Fork 68
Add global option to disable automatic controller switching #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adamrb
wants to merge
4
commits into
isXander:lts
Choose a base branch
from
adamrb:feature/auto-switch-controllers-toggle
base: lts
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2c442bd
Add global option to disable automatic controller switching
adamrb b447afd
Persist preferred controller and restore on startup/hotplug
adamrb f0552c4
Address PR review feedback
adamrb 3e40879
Merge remote-tracking branch 'upstream/multiversion/dev' into feature…
adamrb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import dev.isxander.controlify.Controlify; | ||
| import dev.isxander.controlify.api.ControlifyApi; | ||
| import dev.isxander.controlify.api.event.ControlifyEvents; | ||
| import dev.isxander.controlify.config.settings.GlobalSettings; | ||
| import dev.isxander.controlify.controller.ControllerEntity; | ||
| import dev.isxander.controlify.driver.steamdeck.SteamDeckUtil; | ||
|
|
@@ -21,16 +22,27 @@ | |
| import net.minecraft.network.chat.Component; | ||
| import net.minecraft.resources.Identifier; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| public class GlobalSettingsScreenFactory { | ||
| public static Screen createGlobalSettingsScreen(Screen parent) { | ||
| var globalSettings = Controlify.instance().config().getSettings().globalSettings(); | ||
| AtomicReference<ListOption<String>> whitelist = new AtomicReference<>(); | ||
| AtomicReference<Option<String>> controllerSelector = new AtomicReference<>(); | ||
|
|
||
| List<String> controllerUids = new ArrayList<>(); | ||
| controllerUids.add(""); | ||
| Controlify.instance().getControllerManager().ifPresent(cm -> { | ||
| for (ControllerEntity c : cm.getConnectedControllers()) { | ||
| controllerUids.add(c.uid()); | ||
| } | ||
| }); | ||
|
|
||
| boolean is12106OrLater = /*? if >=1.21.6 {*/ true /*?} else {*/ /*false *//*?}*/;; | ||
|
|
||
| return YetAnotherConfigLib.createBuilder() | ||
| Screen result = YetAnotherConfigLib.createBuilder() | ||
| .title(Component.translatable("controlify.gui.global_settings.title")) | ||
| .save(() -> Controlify.instance().config().saveSafely()) | ||
| .category(ConfigCategory.createBuilder() | ||
|
|
@@ -153,6 +165,56 @@ public static Screen createGlobalSettingsScreen(Screen parent) { | |
| .binding(GlobalSettings.defaults().mixedInput, () -> globalSettings.mixedInput, v -> globalSettings.mixedInput = v) | ||
| .controller(TickBoxControllerBuilder::create) | ||
| .build()) | ||
| .option(Option.<Boolean>createBuilder() | ||
| .name(Component.translatable("controlify.gui.auto_switch_controllers")) | ||
| .description(OptionDescription.createBuilder() | ||
| .text(Component.translatable("controlify.gui.auto_switch_controllers.tooltip")) | ||
| .build()) | ||
| .binding(GlobalSettings.defaults().autoSwitchControllers, () -> globalSettings.autoSwitchControllers, v -> globalSettings.autoSwitchControllers = v) | ||
| .controller(TickBoxControllerBuilder::create) | ||
| .addListener((opt, event) -> { | ||
| var selector = controllerSelector.get(); | ||
| if (selector != null) selector.setAvailable(!opt.pendingValue()); | ||
| }) | ||
| .build()) | ||
| .option(Util.make(() -> { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| var opt = Option.<String>createBuilder() | ||
| .name(Component.translatable("controlify.gui.current_controller")) | ||
| .description(OptionDescription.createBuilder() | ||
| .text(Component.translatable("controlify.gui.current_controller.tooltip")) | ||
| .build()) | ||
| .binding( | ||
| "", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a comment or two for future reference explaining what an empty string represents'd be good |
||
| () -> Controlify.instance().getCurrentController().map(ControllerEntity::uid).orElse(""), | ||
| uid -> { | ||
| if (uid.isEmpty()) { | ||
| Controlify.instance().setCurrentController(null, true); | ||
| } else { | ||
| Controlify.instance().getControllerManager().ifPresent(cm -> | ||
| cm.getConnectedControllers().stream() | ||
| .filter(c -> c.uid().equals(uid)) | ||
| .findFirst() | ||
| .ifPresent(c -> Controlify.instance().setCurrentController(c, true))); | ||
| } | ||
| } | ||
| ) | ||
| .controller(o -> CyclingListControllerBuilder.create(o) | ||
| .values(controllerUids) | ||
| .formatValue(uid -> { | ||
| if (uid.isEmpty()) return Component.translatable("controlify.gui.carousel.entry.keyboard_mouse"); | ||
| return Controlify.instance().getControllerManager() | ||
| .map(cm -> cm.getConnectedControllers().stream() | ||
| .filter(c -> c.uid().equals(uid)) | ||
| .findFirst() | ||
| .map(c -> (Component) Component.literal(c.name())) | ||
| .orElse(Component.literal(uid))) | ||
| .orElse(Component.literal(uid)); | ||
| })) | ||
| .available(!globalSettings.autoSwitchControllers) | ||
| .build(); | ||
| controllerSelector.set(opt); | ||
| return opt; | ||
| })) | ||
| .optionIf(SteamDeckUtil.IS_STEAM_DECK, Option.<Boolean>createBuilder() | ||
| .name(Component.translatable("controlify.gui.use_enhanced_steam_deck_driver")) | ||
| .description(OptionDescription.createBuilder() | ||
|
|
@@ -182,6 +244,19 @@ public static Screen createGlobalSettingsScreen(Screen parent) { | |
| .build()) | ||
| .build()) | ||
| .build().generateScreen(parent); | ||
|
|
||
| ControlifyEvents.CONTROLLER_CONNECTED.register(event -> { | ||
| if (Minecraft.getInstance().screen == result) { | ||
| Minecraft.getInstance().setScreen(createGlobalSettingsScreen(parent)); | ||
| } | ||
| }); | ||
| ControlifyEvents.CONTROLLER_DISCONNECTED.register(event -> { | ||
| if (Minecraft.getInstance().screen == result) { | ||
| Minecraft.getInstance().setScreen(createGlobalSettingsScreen(parent)); | ||
| } | ||
| }); | ||
|
|
||
adamrb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return result; | ||
| } | ||
|
|
||
| private static Identifier screenshot(String filename) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.