Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/src/main/java/com/mrcrayfish/controllable/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public static class Options
@ConfigProperty(name = "autoSelect", comment = "If enabled, controller will be automatically selected on start up or when plugged in")
public final BoolProperty autoSelect = BoolProperty.create(true);

@ConfigProperty(name = "autoSelectIndex", comment = "The index of the controller to auto-select (-1 for first available)")
public final DoubleProperty autoSelectIndex = DoubleProperty.create(-1.0, -1.0, 10.0);

@ConfigProperty(name = "renderMiniPlayer", comment = "If enabled, the player will render in the top left corner likes Bedrock Edition")
public final BoolProperty renderMiniPlayer = BoolProperty.create(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public SettingsTab()
// Controller options
optionsList.addEntry(new TabOptionTitleItem(Component.translatable("controllable.gui.title.controller").withStyle(ChatFormatting.BOLD, ChatFormatting.YELLOW)));
optionsList.addEntry(new TabOptionToggleItem(Config.CLIENT.client.options.autoSelect));
optionsList.addEntry(new TabOptionSliderItem(Config.CLIENT.client.options.autoSelectIndex, 1.0));
optionsList.addEntry(new TabOptionToggleItem(Config.CLIENT.client.options.virtualCursor));
optionsList.addEntry(new TabOptionSliderItem(Config.CLIENT.client.options.thumbstickDeadZone, 0.01));
optionsList.addEntry(new TabOptionSliderItem(Config.CLIENT.client.options.triggerDeadZone, 0.01));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,23 @@ public final void tick()

if(controller == null && Config.CLIENT.client.options.autoSelect.get())
{
controller = this.connectToFirstGameController();
double targetIndex = Config.CLIENT.client.options.autoSelectIndex.get();
if(targetIndex < 0) {
controller = this.connectToFirstGameController();
} else {
// Try to connect to the specified index
for(Map.Entry<Number, Pair<Integer, String>> entry : this.controllers.entrySet()) {
if(entry.getValue().getLeft() == (int)targetIndex) {
controller = this.createController(entry.getValue().getLeft(), entry.getKey());
if(controller != null && this.setActiveController(controller)) {
break;
}
}
}
if(controller == null) {
Constants.LOG.warn("Could not connect to controller at index {}", (int)targetIndex);
}
}
this.sendControllerToast(true, controller);
}
}
Expand Down Expand Up @@ -155,7 +171,21 @@ public final void onClientFinishedLoading()
/* Attempts to load the first game controller connected if auto select is enabled */
if(Config.CLIENT.client.options.autoSelect.get())
{
this.connectToFirstGameController();
double targetIndex = Config.CLIENT.client.options.autoSelectIndex.get();
if(targetIndex < 0) {
this.connectToFirstGameController();
} else {
// Try to connect to the specified index
for(Map.Entry<Number, Pair<Integer, String>> entry : this.controllers.entrySet()) {
if(entry.getValue().getLeft() == (int)targetIndex) {
Controller controller = this.createController(entry.getValue().getLeft(), entry.getKey());
if(controller != null && this.setActiveController(controller)) {
this.sendControllerToast(true, controller);
break;
}
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ControllerOptions
});*/

public static final ControllerSetting<Boolean> AUTO_SELECT = createToggleSetting("controllable.options.autoSelect", Config.CLIENT.client.options.autoSelect);
public static final ControllerSetting<Double> AUTO_SELECT_INDEX = createSliderSetting("controllable.options.autoSelectIndex", Config.CLIENT.client.options.autoSelectIndex, 1.0);
public static final ControllerSetting<Boolean> RENDER_MINI_PLAYER = createToggleSetting("controllable.options.renderMiniPlayer", Config.CLIENT.client.options.renderMiniPlayer);
public static final ControllerSetting<Boolean> VIRTUAL_MOUSE = createToggleSetting("controllable.options.virtualMouse", Config.CLIENT.client.options.virtualCursor);
public static final ControllerSetting<Boolean> CONSOLE_HOTBAR = createToggleSetting("controllable.options.consoleHotbar", Config.CLIENT.client.options.consoleHotbar);
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/controllable/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
"controllable.tooltip.more_recipes": "Press %s to View More",
"framework_config.controllable.client.client.options.autoSelect": "Auto Select",
"framework_config.controllable.client.client.options.autoSelect.tooltip": "If enabled, controller will be automatically selected on start up or when plugged in",
"framework_config.controllable.client.client.options.autoSelectIndex": "Controller Index",
"framework_config.controllable.client.client.options.autoSelectIndex.tooltip": "The index of the controller to auto-select (-1 for first available)",
"framework_config.controllable.client.client.options.consoleHotbar": "Console Hotbar",
"framework_config.controllable.client.client.options.consoleHotbar.tooltip": "If enabled, hotbar will render closer to the center of the screen like on console.",
"framework_config.controllable.client.client.options.controllerIcons": "Button Icons",
Expand Down