Feature: Auto-Assign Controllers #706

Open
uncavo-hdmi wants to merge 31 commits from uncavo-hdmi/auto-assign-controller into master
uncavo-hdmi commented 2025-02-22 18:07:10 +00:00 (Migrated from github.com)

Feature: Auto-Assign Controllers

This PR introduces an auto-assigning controllers feature to Ryujinx, enhancing user experience by automatically detecting and assigning connected controllers to player slots. This streamlines the setup process, allowing users to start playing without manual configuration.

Changes & Enhancements:

  • When the feature is enabled, controllers are automatically assigned to players when connected and removed when disconnected.
  • When the feature is enabled, the Input settings page now automatically refreshes when a controller is connected.
  • Added an option in the Input settings page to enable or disable the feature.

Auto-Assign Controllers Feature

  • When enabled, this feature assigns predefined colors to each player's controller (e.g., Player 1's controller will have a blue LED, Player 2's will have red, etc.).
  • Manual customization remains available, even when the feature is enabled.

Implementation Details:

  • Assignment Logic: Controllers are assigned sequentially, starting from Player 1.

    • When two controllers are connected, they are assigned to Player 1 and Player 2, respectively.
    • If three controllers are connected and the one assigned to Player 2 disconnects, the remaining controllers will automatically shift to ensure each player slot is filled, with Player 1 retaining their controller and Player 3 becoming Player 2.
  • Enable feature: The feature can be toggled on or off using a checkbox in the Input settings page. By default, it is disabled.

  • No Conflicts: This feature does not interfere with manual controller assignments, profile selection logic, or controller binding settings. It only modifies the configuration file when new controllers are connected.

  • No configuration loss: When controllers are disconnected, no controller configuration will be erased (unless manually deassigned using "Disabled").

  • Initial controller config: Since a configuration is necessary to successfully use a controller, this feature provides default controller configurations:

    • Joycon Left Controller: Uses a custom horizontal configuration.
    • Joycon Right Controller: Uses a custom horizontal configuration.
    • Any other controller: Use the default configuration of the Switch Pro Controller.
  • Ignore Applet: When the feature is enabled, it automatically enables the Ignore Applet setting and disables the checkbox, preventing it from being toggled on or off. This ensures seamless controller detection without applet interference.


Why add this feature?

Manually assigning controllers can be cumbersome, especially in scenarios where users have multiple controllers or frequently connect/disconnect devices. This feature aims to simplify the setup process by automatically assigning controllers, saving time and reducing the hassle of manual configuration.


Known issues

  1. File Organization

    • Currently, AutoAssignController.cs (main class) and ControllerAssignmentManager.cs (helper class) are placed in Ryujinx/Input.
    • I'm unsure if this aligns with the existing project architecture and would appreciate suggestions on the best location for these files.
  2. Issues with Joy-Con Configurations

    During testing to create default configurations for each controller, I encountered several issues with the Joy-Con controllers:

    • The right Joy-Con can be easily configured to be used horizontally (by rotating 90° clockwise), but there is no simple way to achieve this with the left Joy-Con.
    • When using the left Joy-Con alone, I noticed that the Minus button is incorrectly mapped to the Plus button.
    • When using the right Joy-Con alone, I noticed that the Right Stick is incorrectly mapped to the Left Stick.
    • The motion controls have issues with the axes. As far as I remember, the default configuration for single Joy-Cons has the controller oriented incorrectly.
  3. Controller Reassignment Bug (Unrelated to This PR)

    This issue was encountered while testing, but I confirmed that it also occurs in the main Ryujinx repository. This is not caused by changes in this PR, but I am documenting it here in case anyone else encounters it (the same applies to the next issue).

    Steps to Reproduce:

     1. Start Ryujinx.
     2. Launch any game (tested with Super Mario Bros. Wonder).
     3. Go to Settings > Input, set your controller for Player 1, and click "Ok."
     4. Open Settings > Input again, set Player 1 to "Disabled," and click "Ok."
     5. Go back to Settings > Input, set your controller for Player 1, and click "Ok."
    

    Expected Behavior: The controller should function normally after being reassigned.

    Actual Behavior: The controller stops working after switching from “Disabled” back to an assigned controller.

    Additional note: It appears to happen only when switching from 'Disabled' back to a controller

  4. Crash on Game Relaunch (Unrelated to This PR)

    Steps to Reproduce:

     1. Start any game.
     2. Once the game has loaded, press "Esc" to return to the menu.
     3. Attempt to relaunch the game.
    

    Expected Behavior: The game should start normally.

    Actual Behavior: The emulator crashes on the "Loading" screen when attempting to restart the game.


## Feature: Auto-Assign Controllers This PR introduces an auto-assigning controllers feature to Ryujinx, enhancing user experience by automatically detecting and assigning connected controllers to player slots. This streamlines the setup process, allowing users to start playing without manual configuration. ### Changes & Enhancements: - When the feature is enabled, controllers are automatically assigned to players when connected and removed when disconnected. - When the feature is enabled, the `Input` settings page now automatically refreshes when a controller is connected. - Added an option in the `Input` settings page to **enable or disable** the feature. <p align="center"> <img src="https://github.com/user-attachments/assets/f9e65c87-2fa3-4bc3-b5d1-6332a776108e" alt="Auto-Assign Controllers Feature"> </p> - When enabled, this feature assigns predefined colors to each player's controller (e.g., Player 1's controller will have a blue LED, Player 2's will have red, etc.). - **Manual customization remains available, even when the feature is enabled.** --- ### Implementation Details: - **Assignment Logic**: Controllers are assigned sequentially, starting from Player 1. - When two controllers are connected, they are assigned to Player 1 and Player 2, respectively. - If three controllers are connected and the one assigned to Player 2 disconnects, the remaining controllers will automatically shift to ensure each player slot is filled, with Player 1 retaining their controller and Player 3 becoming Player 2. - **Enable feature**: The feature can be toggled on or off using a checkbox in the Input settings page. **By default, it is disabled.** - **No Conflicts**: This feature does not interfere with manual controller assignments, profile selection logic, or controller binding settings. It only modifies the configuration file when **new** controllers are **connected**. - **No configuration loss**: When controllers are disconnected, no controller configuration will be erased (unless manually deassigned using "Disabled"). - **Initial controller config**: Since a configuration is necessary to successfully use a controller, this feature provides default controller configurations: - Joycon Left Controller: Uses a custom horizontal configuration. - Joycon Right Controller: Uses a custom horizontal configuration. - Any other controller: Use the default configuration of the Switch Pro Controller. - **Ignore Applet**: When the feature is enabled, it automatically enables the `Ignore Applet` setting and disables the checkbox, preventing it from being toggled on or off. This ensures seamless controller detection without applet interference. --- ### Why add this feature? Manually assigning controllers can be cumbersome, especially in scenarios where users have multiple controllers or frequently connect/disconnect devices. This feature aims to simplify the setup process by automatically assigning controllers, saving time and reducing the hassle of manual configuration. --- ### Known issues 1. **File Organization** - Currently, `AutoAssignController.cs` (main class) and `ControllerAssignmentManager.cs` (helper class) are placed in `Ryujinx/Input`. - I'm unsure if this aligns with the existing project architecture and would appreciate suggestions on the best location for these files. 2. **Issues with Joy-Con Configurations** During testing to create default configurations for each controller, I encountered several issues with the Joy-Con controllers: - The right Joy-Con can be easily configured to be used horizontally (by rotating 90° clockwise), but there is no simple way to achieve this with the left Joy-Con. - When using the left Joy-Con alone, I noticed that the Minus button is incorrectly mapped to the Plus button. - When using the right Joy-Con alone, I noticed that the Right Stick is incorrectly mapped to the Left Stick. - The motion controls have issues with the axes. As far as I remember, the default configuration for single Joy-Cons has the controller oriented incorrectly. 3. **Controller Reassignment Bug (Unrelated to This PR)** This issue was encountered while testing, but I confirmed that it also occurs in the main Ryujinx repository. This is not caused by changes in this PR, but I am documenting it here in case anyone else encounters it (the same applies to the next issue). Steps to Reproduce: 1. Start Ryujinx. 2. Launch any game (tested with Super Mario Bros. Wonder). 3. Go to Settings > Input, set your controller for Player 1, and click "Ok." 4. Open Settings > Input again, set Player 1 to "Disabled," and click "Ok." 5. Go back to Settings > Input, set your controller for Player 1, and click "Ok." **Expected Behavior**: The controller should function normally after being reassigned. **Actual Behavior**: The controller stops working after switching from “Disabled” back to an assigned controller. **Additional note**: It appears to happen only when switching from 'Disabled' back to a controller 4. **Crash on Game Relaunch (Unrelated to This PR)** Steps to Reproduce: 1. Start any game. 2. Once the game has loaded, press "Esc" to return to the menu. 3. Attempt to relaunch the game. **Expected Behavior**: The game should start normally. **Actual Behavior**: The emulator crashes on the "Loading" screen when attempting to restart the game. ---
h3kt0rx commented 2025-02-27 23:33:53 +00:00 (Migrated from github.com)

I've been testing on windows, I might of encountered a bug? Player 1 and Player 2 linked to separate controllers. When controller 2 disconnects, Player 1 Controller controls both Player 1 and Player 2 after telling the game to use CPU.

Steps to possibly reproduce:

  1. Start game (only tested with Kirby Star Allies)
  2. Connect controllers for Player 1 and Player 2.
  3. Friend a character so both players are playing separate characters.
  4. Disconnect/Turn off Player 2 controller.
  5. Press A/B/X/Y button on controller 1.

This should cause the issue noted above. Endless loop of the game asking to use CPU but pressing any button will result in controlling bother players.

Edit: I tried this with more controllers on the same game, Player 1 assumes control of the rest of the players. Player 2 and Player 3 are Disabled and "Waiting for link". Taking control of the rest of the players only happens after a button is pressed (On Player 1) other than the movement.

I've been testing on windows, I might of encountered a bug? Player 1 and Player 2 linked to separate controllers. When controller 2 disconnects, Player 1 Controller controls both Player 1 and Player 2 after telling the game to use CPU. Steps to possibly reproduce: 1. Start game (only tested with Kirby Star Allies) 2. Connect controllers for Player 1 and Player 2. 3. Friend a character so both players are playing separate characters. 4. Disconnect/Turn off Player 2 controller. 5. Press A/B/X/Y button on controller 1. This should cause the issue noted above. Endless loop of the game asking to use CPU but pressing any button will result in controlling bother players. Edit: I tried this with more controllers on the same game, Player 1 assumes control of the rest of the players. Player 2 and Player 3 are Disabled and "Waiting for link". Taking control of the rest of the players only happens after a button is pressed (On Player 1) other than the movement.
uncavo-hdmi commented 2025-02-28 16:16:17 +00:00 (Migrated from github.com)

Hi @h3kt0rx, thanks for the feedback! You're absolutely right - there's an issue in the code. I'm pushing a fix right now. Let me know if it works :)

Hi @h3kt0rx, thanks for the feedback! You're absolutely right - there's an issue in the code. I'm pushing a fix right now. Let me know if it works :)
h3kt0rx commented 2025-03-01 02:55:58 +00:00 (Migrated from github.com)

Hi @h3kt0rx, thanks for the feedback! You're absolutely right - there's an issue in the code. I'm pushing a fix right now. Let me know if it works :)

Thanks for all the work you're doing! The controller issue has been a pain in every switch emulator I've tried, best PR ever. I'd love to test, however, I'm a noob to compiling. I followed the instructions but running the game crashes so I'm sure I'm doing it wrong with the dotnet command or something.

> Hi @h3kt0rx, thanks for the feedback! You're absolutely right - there's an issue in the code. I'm pushing a fix right now. Let me know if it works :) Thanks for all the work you're doing! The controller issue has been a pain in every switch emulator I've tried, best PR ever. I'd love to test, however, I'm a noob to compiling. I followed the instructions but running the game crashes so I'm sure I'm doing it wrong with the dotnet command or something.
GreemDev commented 2025-03-01 02:56:42 +00:00 (Migrated from github.com)

Hi @h3kt0rx, thanks for the feedback! You're absolutely right - there's an issue in the code. I'm pushing a fix right now. Let me know if it works :)

Thanks for all the work you're doing! The controller issue has been a pain in every switch emulator I've tried, best PR ever. I'd love to test, however, I'm a noob to compiling. I followed the instructions but running the game crashes so I'm sure I'm doing it wrong with the dotnet command or something.

you do not need to compile. The first comment on this PR contains up-to-date builds containing the changes of this PR.

Edit: My bad, first time contributors need to be approved to have their builds made and I hadn't done that yet. It's below.

> > Hi @h3kt0rx, thanks for the feedback! You're absolutely right - there's an issue in the code. I'm pushing a fix right now. Let me know if it works :) > > Thanks for all the work you're doing! The controller issue has been a pain in every switch emulator I've tried, best PR ever. I'd love to test, however, I'm a noob to compiling. I followed the instructions but running the game crashes so I'm sure I'm doing it wrong with the dotnet command or something. you do not need to compile. The first comment on this PR contains up-to-date builds containing the changes of this PR. Edit: My bad, first time contributors need to be approved to have their builds made and I hadn't done that yet. It's below.
github-actions[bot] commented 2025-03-01 08:26:49 +00:00 (Migrated from github.com)
Download the artifacts for this pull request: * [ryujinx-Release-1.2.0+bf6e6c3-linux_arm64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674860873.zip) * [ryujinx-Release-1.2.0+bf6e6c3-linux_arm64-AppImage](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674860908.zip) * [ryujinx-Release-1.2.0+bf6e6c3-macos_universal](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674862921.zip) * [ryujinx-Release-1.2.0+bf6e6c3-linux_x64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674863114.zip) * [ryujinx-Release-1.2.0+bf6e6c3-linux_x64-AppImage](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674863166.zip) * [ryujinx-Release-1.2.0+bf6e6c3-win_x64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674869118.zip) <details><summary>Only for Developers</summary> * [ryujinx-Debug-1.2.0+bf6e6c3-linux_arm64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674861120.zip) * [ryujinx-Debug-1.2.0+bf6e6c3-linux_arm64-AppImage](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674861199.zip) * [ryujinx-Debug-1.2.0+bf6e6c3-linux_x64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674864038.zip) * [ryujinx-Debug-1.2.0+bf6e6c3-linux_x64-AppImage](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674864099.zip) * [ryujinx-Debug-1.2.0+bf6e6c3-macos_universal](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674864517.zip) * [ryujinx-Debug-1.2.0+bf6e6c3-win_x64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2674869179.zip) </details>
This pull request has changes conflicting with the target branch.
  • src/Ryujinx/AppHost.cs
  • src/Ryujinx/Utilities/Configuration/ConfigurationFileFormat.cs
  • src/Ryujinx/Utilities/Configuration/ConfigurationState.Migration.cs
  • src/Ryujinx/Utilities/Configuration/ConfigurationState.Model.cs
  • src/Ryujinx/Utilities/Configuration/ConfigurationState.cs

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin uncavo-hdmi/auto-assign-controller:uncavo-hdmi/auto-assign-controller
git checkout uncavo-hdmi/auto-assign-controller
Sign in to join this conversation.
No description provided.