Skip to content

Commit

Permalink
fix(input): fix button long press
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenira committed Dec 3, 2023
1 parent 8e3a749 commit 91f8634
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"conventionalCommits.scopes": [
"input",
"render",
"ui",
"player"
]
}
3 changes: 1 addition & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ While the mod is in a playable state, it is still in early development. Some fea
- :arrows_counterclockwise: Smooth turning

=== Missing
- Gesture support (e.g. Mining =1using pickaxe motion)
- Gesture support (e.g. Mining using pickaxe motion)
- Comfort options (e.g. Teleportation). Smooth locomotion and turning only for now.
- Model for the player's body. Currently not a priority as this requires IK.
- Default bindings for VR controllers other than the Valve Index Controllers
Expand All @@ -64,7 +64,6 @@ While the mod is in a playable state, it is still in early development. Some fea
- Some UI elements might be outside of the players field of view or scaled incorrectly.
- Button prompts are not for VR controllers.
- Haptics are played on both controllers by the game. One improvement would be to play them on the hand that is actually holding the tool.
- When gathering it goes into auto mode and won't stop until you mine something.
- Performance needs improvement

=== Cool stuff to try
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/camera/patch/target_raycast_patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static bool Postfix(PlayerFirstPersonController __instance)
var forward = right_hand_transform.forward;

// Rotate the forward vector 45 degrees down
var rotation = Quaternion.Euler(45f, 0f, 0f);
var rotation = Quaternion.Euler(60f, 0f, 0f);
forward = rotation * forward;

__instance._hasCamHit = Physics.Raycast(new Ray(right_hand_transform.position, forward), out __instance._camHit, __instance.cam.farClipPlane, __instance.aimLayer, QueryTriggerInteraction.Collide);
Expand Down
8 changes: 4 additions & 4 deletions plugin/src/input/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class Button
{
bool currentState;
bool previousState;
float lastChangeTime = UnityEngine.Time.time;
float lastDuration = 0f;
float lastChangeTime;
float lastDuration;

public Button(SteamVR_Action_Boolean action)
{
Expand Down Expand Up @@ -52,7 +52,7 @@ public bool IsReleased()

public bool IsTimedPress(float min)
{
return currentState && lastChangeTime + min >= UnityEngine.Time.time;
return currentState && UnityEngine.Time.time - lastChangeTime >= min;
}

public bool IsTimedPressUp(float min)
Expand All @@ -67,7 +67,7 @@ public bool IsTimedPressUp(float min, float max)

public bool IsTimedPressDown(float min)
{
return currentState && lastChangeTime + min >= UnityEngine.Time.time;
return currentState && UnityEngine.Time.time - lastChangeTime >= min;
}

public bool IsTimedPressDown(float min, float max)
Expand Down
16 changes: 15 additions & 1 deletion plugin/src/input/input_patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void Move(PlayerFirstPersonController __instance)
}

var delta = Time.deltaTime;
var horizontalRotation = SteamVRInputMapper.TurnAxis * delta * 64f;
var horizontalRotation = SteamVRInputMapper.TurnAxis * delta * ModConfig.smoothTurnSpeed.Value;
__instance.gameObject.transform.RotateAround(VRCameraManager.mainCamera.transform.position, Vector3.up, horizontalRotation);
}

Expand Down Expand Up @@ -130,6 +130,20 @@ static bool GetButtonTimedPress(ref bool __result, int actionId, float time)
return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Rewired.Player), nameof(Rewired.Player.GetButtonLongPressDown), [typeof(int)])]
static bool GetButtonLongPressDown(ref bool __result, int actionId)
{
var state = MapButtonState(actionId);
if (state != null)
{
__result = state.IsTimedPressDown(ModConfig.longPressTime.Value);
return false;
}

return true;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Rewired.Player), nameof(Rewired.Player.GetButtonTimedPressDown), [typeof(int), typeof(float)])]
static bool GetButtonTimedPressDown(ref bool __result, int actionId, float time)
Expand Down
12 changes: 12 additions & 0 deletions plugin/src/mod_config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ public class ModConfig
// General
public static ConfigEntry<bool> modEnabled;

// Input
public static ConfigEntry<int> smoothTurnSpeed;

// Buttons
public static ConfigEntry<float> longPressTime;

// Debug
public static ConfigEntry<bool> debugMode;
public static ConfigEntry<bool> debugLineEnabled;
Expand All @@ -16,6 +22,12 @@ public static void Init(ConfigFile config)
// General
modEnabled = config.Bind("General", "Enabled", true, "Enable mod");

// Input
smoothTurnSpeed = config.Bind("Input", "Smooth Turn Speed", 90, "Speed of smooth turning");

// Buttons
longPressTime = config.Bind("Buttons", "Long Press Time", 1f, "Time to hold button for long press");

// Debug
debugMode = config.Bind("Debug", "Debug Mode", false, "Enable debug mode");
debugLineEnabled = config.Bind("Debug", "Debug Line Enabled", false, "Enable debug lines");
Expand Down

0 comments on commit 91f8634

Please sign in to comment.