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
1 change: 1 addition & 0 deletions buildSrc/src/main/groovy/multiloader-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def getPackagesRepo() {
}

repositories {
mavenLocal()
mavenCentral()
exclusiveContent {
forRepository {
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
compileOnly "mezz.jei:jei-${jei_minecraft_version}-gui:${jei_version}"
compileOnly "mezz.jei:jei-${jei_minecraft_version}-lib:${jei_version}"
compileOnly "com.mrcrayfish:controllable-sdl:${controllable_sdl_version}"
compileOnly "org.hid4java:hid4java:${hid4java_version}" // gives access to hid4java to detect steam controller buttons
//compileOnly "dev.emi:emi-xplat-mojmap:${emi_version}"
compileOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${rei_version}"
compileOnly "org.spongepowered:mixin:0.8.7"
Expand Down
14 changes: 13 additions & 1 deletion common/src/main/java/com/mrcrayfish/controllable/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class Client
@ConfigProperty(name = "inputLibrary", gameRestart = true, comment = """
The library to use for game controller input. You can change this if you are having problems detecting game controllers.
Please note that changing from the default library may disable some feature in Controllable, only use this as a last resort""")
public final EnumProperty<InputLibrary> inputLibrary = EnumProperty.create(InputLibrary.SDL2);
public final EnumProperty<InputLibrary> inputLibrary = EnumProperty.create(InputLibrary.STEAM_HID);

public static class Options
{
Expand Down Expand Up @@ -142,6 +142,9 @@ remote servers (read message below).
Gyro related options. (Experimental)""")
public final Gyro gyro = new Gyro();

@ConfigProperty(name = "steamController", comment = "Steam Controller related options.")
public final SteamController steamController = new SteamController();

@ConfigProperty(name = "advanced", comment = """
Advanced related options. "advancedMode" option must be enabled""")
public final Advanced advanced = new Advanced();
Expand Down Expand Up @@ -169,6 +172,15 @@ public static class Gyro
public final BoolProperty invertY = BoolProperty.create(false);
}

public static class SteamController
{
@ConfigProperty(name = "trackpadMenuSensitivity", comment = "The Steam Controller's trackpad sensitivity when moving the cursor in menus")
public final DoubleProperty trackpadMenuSensitivity = DoubleProperty.create(1.0, 0.0, 5.0);

@ConfigProperty(name = "trackpadGameSensitivity", comment = "The Steam Controller's trackpad sensitivity when turning the camera in game")
public final DoubleProperty trackpadGameSensitivity = DoubleProperty.create(0.35, 0.0, 2.0);
}

public static class Advanced
{
@ConfigProperty(name = "advancedMode", comment = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.mrcrayfish.controllable.client.input.Controller;
import com.mrcrayfish.controllable.client.input.glfw.GLFWControllerManager;
import com.mrcrayfish.controllable.client.input.sdl2.SDL2ControllerManager;
import com.mrcrayfish.controllable.client.input.steam.SteamControllerManager;
import com.mrcrayfish.controllable.util.Utils;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -113,6 +114,7 @@ private static AdaptiveControllerManager createManager()
return switch (Config.CLIENT.inputLibrary.get()) {
case GLFW -> new GLFWControllerManager();
case SDL2 -> new SDL2ControllerManager();
case STEAM_HID -> new SteamControllerManager();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import com.mrcrayfish.controllable.Controllable;
import com.mrcrayfish.controllable.client.binding.ButtonBindings;
import com.mrcrayfish.controllable.client.input.Controller;
import com.mrcrayfish.controllable.client.input.RelativePointerController;
import com.mrcrayfish.controllable.client.util.EventHelper;
import com.mrcrayfish.controllable.client.util.InputHelper;
import com.mrcrayfish.controllable.event.Value;
import com.mrcrayfish.framework.api.event.client.FrameworkClientTickEvents;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import org.joml.Vector2f;
import org.jetbrains.annotations.ApiStatus;

/**
Expand Down Expand Up @@ -55,6 +57,20 @@ private void updateRotationDelta()
if(controller == null)
return;

// ingame trackpad motion turns the camera; menus use the same deltas in VirtualCursor
if(controller instanceof RelativePointerController relative)
{
Vector2f delta = relative.consumeRelativePointerDelta();
if(delta.lengthSquared() > 0)
{
float sensitivity = Config.CLIENT.options.steamController.trackpadGameSensitivity.get().floatValue();
this.yawDelta = delta.x * sensitivity;
this.pitchDelta = delta.y * sensitivity;
controller.updateInputTime();
return;
}
}

float thumbstickX = InputHelper.getCombinedPressedValue(controller, ButtonBindings.LOOK_LEFT, ButtonBindings.LOOK_RIGHT);
float thumbstickY = InputHelper.getCombinedPressedValue(controller, ButtonBindings.LOOK_UP, ButtonBindings.LOOK_DOWN);
if(thumbstickX * thumbstickX > 0 || thumbstickY * thumbstickY > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mrcrayfish.controllable.client.binding.ButtonBindings;
import com.mrcrayfish.controllable.client.gui.screens.ControllerLayoutScreen;
import com.mrcrayfish.controllable.client.input.Controller;
import com.mrcrayfish.controllable.client.input.RelativePointerController;
import com.mrcrayfish.controllable.client.util.InputHelper;
import com.mrcrayfish.controllable.client.util.MouseHooks;
import com.mrcrayfish.controllable.client.util.ScreenHelper;
Expand Down Expand Up @@ -204,6 +205,9 @@ private void updateMovement()
if(mc.screen == null || mc.screen instanceof ControllerLayoutScreen)
return;

if(this.applyRelativePointerInput(controller, mc))
return;

this.updateInputVector(controller);

// If the magnitude is greater than zero, input is being given
Expand Down Expand Up @@ -322,6 +326,34 @@ private void updateInputVector(Controller controller)
this.inputVector.y = InputHelper.applyDeadzone(cursorVectorY, moveThreshold);
}

// steam controller trackpad deltas should move the cursor before thumbstick cursor input is used
private boolean applyRelativePointerInput(Controller controller, Minecraft mc)
{
if(!(controller instanceof RelativePointerController relative))
return false;

Vector2f delta = relative.consumeRelativePointerDelta();
if(delta.lengthSquared() <= 0)
return false;

double cursorSpeed = Math.max(mc.getWindow().getGuiScale(), 1) * Config.CLIENT.options.steamController.trackpadMenuSensitivity.get();
this.x += delta.x * cursorSpeed;
this.y += delta.y * cursorSpeed;
this.clampCursorToWindowBounds();
this.setVisible(true);
this.snapIfNoMove = true;
this.mode = CursorMode.CONTROLLER;
controller.updateInputTime();

if(this.x != this.lastMoveX || this.y != this.lastMoveY)
{
MouseHooks.invokeMouseMoved(mc.screen, this.x, this.y, this.x - this.lastMoveX, this.y - this.lastMoveY);
this.lastMoveX = this.x;
this.lastMoveY = this.y;
}
return true;
}

/**
* Clamps the position of the cursor to the bounds of the window
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ public SettingsTab()
advancedModeOption.setChangeCallback(aBoolean -> optionsList.rebuildList(true));
optionsList.addEntry(advancedModeOption);

optionsList.addEntry(new TabOptionTitleItem(Component.translatable("controllable.gui.title.steam_controller").withStyle(ChatFormatting.BOLD, ChatFormatting.YELLOW)));
optionsList.addEntry(new TabOptionSliderItem(Config.CLIENT.options.steamController.trackpadMenuSensitivity, 0.05));
optionsList.addEntry(new TabOptionSliderItem(Config.CLIENT.options.steamController.trackpadGameSensitivity, 0.05));

this.listWidget = rootHelper.addChild(new TabListWidget(optionsList));
optionsList.finalise();
optionsList.rebuildList(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
public enum InputLibrary
{
GLFW,
SDL2 // Default
SDL2,
STEAM_HID
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mrcrayfish.controllable.client.input;

import org.joml.Vector2f;

public interface RelativePointerController
{
Vector2f consumeRelativePointerDelta();
}
Loading