Sensible screen scrolling speeds

This commit is contained in:
Martin Prokoph
2024-07-25 11:07:29 +02:00
parent dbb6e926e6
commit 333fc7f300
4 changed files with 11 additions and 17 deletions

View File

@@ -86,7 +86,7 @@ public class MidnightControlsClient extends MidnightControls {
int period = 1; // repeat every 0.001 sec. (1000 times a second)
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
public void run() { // TODO: Add a try/catch here after the alpha testing period
if (lateInitDone && client.isRunning()) {
input.tickJoysticks();
input.updateCamera();

View File

@@ -505,7 +505,7 @@ public class MidnightInput {
}
axisValue = (float) Math.min(axisValue / MidnightControlsConfig.getAxisMaxValue(storage.axis), 1);
if (AxisStorage.isLeftAxis(storage.axis) && MidnightControlsCompat.handleMovement(storage, axisValue)) return;
if (AxisStorage.isLeftAxis(storage.axis)) MidnightControlsCompat.handleMovement(storage, axisValue);
InputManager.BUTTON_VALUES.put(ButtonBinding.axisAsButton(storage.axis, true), storage.polarity == AxisStorage.Polarity.PLUS ? axisValue : 0.f);
InputManager.BUTTON_VALUES.put(ButtonBinding.axisAsButton(storage.axis, false), storage.polarity == AxisStorage.Polarity.MINUS ? axisValue : 0.f);
}
@@ -532,25 +532,22 @@ public class MidnightInput {
if (storage.axis == preferredAxis) {
var accessor = (CreativeInventoryScreenAccessor) creativeInventoryScreen;
if (accessor.midnightcontrols$hasScrollbar() && storage.absValue >= storage.deadZone) {
creativeInventoryScreen.mouseScrolled(0.0, 0.0, 0, -storage.value);
creativeInventoryScreen.mouseScrolled(0.0, 0.0, 0, -(storage.value * 0.0175f));
}
return true;
}
} else if (screen instanceof MerchantScreen || screen instanceof StonecutterScreen) {
if (storage.axis == preferredAxis) {
screen.mouseScrolled(0.0, 0.0, 0, -(storage.value * 1.5f));
return true;
}
} else if (screen instanceof AdvancementsScreen advancementsScreen) {
if (storage.axis == GLFW_GAMEPAD_AXIS_RIGHT_X || storage.axis == GLFW_GAMEPAD_AXIS_RIGHT_Y) {
var accessor = (AdvancementsScreenAccessor) advancementsScreen;
AdvancementTab tab = accessor.getSelectedTab();
tab.move(storage.axis == GLFW_GAMEPAD_AXIS_RIGHT_X ? -storage.value * 5.0 : 0.0, storage.axis == GLFW_GAMEPAD_AXIS_RIGHT_Y ? -storage.value * 5.0 : 0.0);
tab.move(storage.axis == GLFW_GAMEPAD_AXIS_RIGHT_X ? -storage.value * 1.0 : 0.0, storage.axis == GLFW_GAMEPAD_AXIS_RIGHT_Y ? -storage.value * 5.0 : 0.0);
return true;
}
} else if (screen != null) {
if (storage.axis == preferredAxis && !handleListWidgetScrolling(screen.children(), storage.value)) {
screen.mouseScrolled(0.0, 0.0, 0, -(storage.value * 1.5f));
try {
screen.mouseScrolled(0.0, 0.0, 0, -(storage.value * 0.0175f));
} catch (NullPointerException ignored) {}
} else if (isScreenInteractive(screen)) {
if (joystickCooldown == 0) {
switch (storage.axis) {

View File

@@ -55,9 +55,7 @@ public interface CompatHandler {
* @param storage the storage containing info about the current axis
* @param adjustedValue the value of the axis, adjusted for max values and non-analogue movement, recommended for player movement
*/
default boolean handleMovement(@NotNull MinecraftClient client, AxisStorage storage, float adjustedValue) {
return false;
}
default void handleMovement(@NotNull MinecraftClient client, AxisStorage storage, float adjustedValue) {}
/**
* Handles custom tab behavior

View File

@@ -191,11 +191,10 @@ public class MidnightControlsCompat {
/**
* Handles movement for players as well as vehicles
*
* @param storage the storage containing info about the current axis
* @param storage the storage containing info about the current axis
* @param adjustedValue the value of the axis, adjusted for max values and non-analogue movement, recommended for player movement
* @return true if the handle was fired and succeed, else false
*/
public static boolean handleMovement(AxisStorage storage, float adjustedValue) {
return streamCompatHandlers().anyMatch(handler -> handler.handleMovement(client, storage, adjustedValue));
public static void handleMovement(AxisStorage storage, float adjustedValue) {
streamCompatHandlers().forEach(handler -> handler.handleMovement(client, storage, adjustedValue));
}
}