mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-14 07:35:10 +01:00
More code improvements
This commit is contained in:
@@ -288,7 +288,7 @@ public class MidnightInput {
|
|||||||
float rightX = polarUtil.polarX;
|
float rightX = polarUtil.polarX;
|
||||||
float rightY = polarUtil.polarY;
|
float rightY = polarUtil.polarY;
|
||||||
|
|
||||||
boolean isRadialMenu = client.currentScreen instanceof RingScreen || (EmotecraftCompat.isPresent() && EmotecraftCompat.isEmotecraftScreen(client.currentScreen));
|
boolean isRadialMenu = client.currentScreen instanceof RingScreen || (PlatformFunctions.isModLoaded("emotecraft") && EmotecraftCompat.isEmotecraftScreen(client.currentScreen));
|
||||||
|
|
||||||
if (!isRadialMenu) {
|
if (!isRadialMenu) {
|
||||||
for (int i = 0; i < GLFW_GAMEPAD_AXIS_LEFT_TRIGGER; i++) {
|
for (int i = 0; i < GLFW_GAMEPAD_AXIS_LEFT_TRIGGER; i++) {
|
||||||
@@ -427,7 +427,7 @@ public class MidnightInput {
|
|||||||
private void handleJoystickAxis(AxisStorage storage) {
|
private void handleJoystickAxis(AxisStorage storage) {
|
||||||
storage.setupButtonStates();
|
storage.setupButtonStates();
|
||||||
|
|
||||||
this.handleMovement(storage);
|
this.handleJoystickMovement(storage);
|
||||||
|
|
||||||
if (this.handleScreenScrolling(client.currentScreen, storage)) return;
|
if (this.handleScreenScrolling(client.currentScreen, storage)) return;
|
||||||
|
|
||||||
@@ -496,7 +496,7 @@ public class MidnightInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMovement(AxisStorage storage) {
|
private void handleJoystickMovement(AxisStorage storage) {
|
||||||
float axisValue = storage.absValue;
|
float axisValue = storage.absValue;
|
||||||
if (!MidnightControlsConfig.analogMovement || (client.player != null && client.player.getVehicle() instanceof BoatEntity)) {
|
if (!MidnightControlsConfig.analogMovement || (client.player != null && client.player.getVehicle() instanceof BoatEntity)) {
|
||||||
axisValue = (float) (storage.absValue - storage.deadZone);
|
axisValue = (float) (storage.absValue - storage.deadZone);
|
||||||
@@ -505,10 +505,9 @@ public class MidnightInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
axisValue = (float) Math.min(axisValue / MidnightControlsConfig.getAxisMaxValue(storage.axis), 1);
|
axisValue = (float) Math.min(axisValue / MidnightControlsConfig.getAxisMaxValue(storage.axis), 1);
|
||||||
if (!MidnightControlsCompat.handleMovement(storage, axisValue)) {
|
if (AxisStorage.isLeftAxis(storage.axis) && MidnightControlsCompat.handleMovement(storage, axisValue)) return;
|
||||||
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, 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);
|
InputManager.BUTTON_VALUES.put(ButtonBinding.axisAsButton(storage.axis, false), storage.polarity == AxisStorage.Polarity.MINUS ? axisValue : 0.f);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleScreenScrolling(Screen screen, AxisStorage storage) {
|
private boolean handleScreenScrolling(Screen screen, AxisStorage storage) {
|
||||||
@@ -587,7 +586,7 @@ public class MidnightInput {
|
|||||||
else if (y > border) index = 6;
|
else if (y > border) index = 6;
|
||||||
}
|
}
|
||||||
if (client.currentScreen instanceof RingScreen && index > -1) RingPage.selected = index;
|
if (client.currentScreen instanceof RingScreen && index > -1) RingPage.selected = index;
|
||||||
if (EmotecraftCompat.isPresent() && EmotecraftCompat.isEmotecraftScreen(client.currentScreen)) EmotecraftCompat.handleEmoteSelector(index);
|
if (PlatformFunctions.isModLoaded("emotecraft") && EmotecraftCompat.isEmotecraftScreen(client.currentScreen)) EmotecraftCompat.handleEmoteSelector(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean handleListWidgetScrolling(List<? extends Element> children, float value) {
|
public boolean handleListWidgetScrolling(List<? extends Element> children, float value) {
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import org.lwjgl.glfw.GLFW;
|
|||||||
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
|
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
|
||||||
|
|
||||||
public class EMICompat implements CompatHandler {
|
public class EMICompat implements CompatHandler {
|
||||||
protected static boolean isPresent;
|
|
||||||
|
|
||||||
public static boolean handleEmiPages(boolean direction) {
|
public static boolean handleEmiPages(boolean direction) {
|
||||||
if (isEMIEnabled() && MidnightControlsClient.input.actionGuiCooldown == 0 && EmiScreenManager.getSearchPanel() != null && EmiScreenManager.getSearchPanel().pageLeft != null && EmiScreenManager.getSearchPanel().pageRight != null) {
|
if (isEMIEnabled() && MidnightControlsClient.input.actionGuiCooldown == 0 && EmiScreenManager.getSearchPanel() != null && EmiScreenManager.getSearchPanel().pageLeft != null && EmiScreenManager.getSearchPanel().pageRight != null) {
|
||||||
if (direction) EmiScreenManager.getSearchPanel().pageRight.onPress();
|
if (direction) EmiScreenManager.getSearchPanel().pageRight.onPress();
|
||||||
@@ -40,14 +38,6 @@ public class EMICompat implements CompatHandler {
|
|||||||
.filter(((buttonBinding) -> EmiApi.getHandledScreen() != null))
|
.filter(((buttonBinding) -> EmiApi.getHandledScreen() != null))
|
||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Returns whether EMI is present.
|
|
||||||
*
|
|
||||||
* @return true if EMI is present, else false
|
|
||||||
*/
|
|
||||||
public static boolean isPresent() {
|
|
||||||
return isPresent;
|
|
||||||
}
|
|
||||||
public static boolean isEMIEnabled() {
|
public static boolean isEMIEnabled() {
|
||||||
return EmiConfig.enabled;
|
return EmiConfig.enabled;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import net.minecraft.client.MinecraftClient;
|
|||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
|
||||||
public class EmotecraftCompat {
|
public class EmotecraftCompat {
|
||||||
protected static boolean isPresent;
|
|
||||||
private static final MinecraftClient client = MinecraftClient.getInstance();
|
private static final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
|
||||||
public static void openEmotecraftScreen(Screen parent) {
|
public static void openEmotecraftScreen(Screen parent) {
|
||||||
@@ -34,13 +33,4 @@ public class EmotecraftCompat {
|
|||||||
InputManager.INPUT_MANAGER.updateMousePosition(client);
|
InputManager.INPUT_MANAGER.updateMousePosition(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether Emotecraft is present.
|
|
||||||
*
|
|
||||||
* @return true if Emotecraft is present, else false
|
|
||||||
*/
|
|
||||||
public static boolean isPresent() {
|
|
||||||
return isPresent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
|
|||||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||||
|
|
||||||
public class InventoryTabsCompat implements CompatHandler {
|
public class InventoryTabsCompat implements CompatHandler {
|
||||||
protected static boolean isPresent;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handleTabs(Screen screen, boolean next) {
|
public boolean handleTabs(Screen screen, boolean next) {
|
||||||
if (screen instanceof HandledScreen<?> && !(screen instanceof CreativeInventoryScreen)) {
|
if (screen instanceof HandledScreen<?> && !(screen instanceof CreativeInventoryScreen)) {
|
||||||
@@ -42,12 +40,4 @@ public class InventoryTabsCompat implements CompatHandler {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Returns whether InventoryTabs is present.
|
|
||||||
*
|
|
||||||
* @return true if InventoryTabs is present, else false
|
|
||||||
*/
|
|
||||||
public static boolean isPresent() {
|
|
||||||
return isPresent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ public class MidnightControlsCompat {
|
|||||||
if (PlatformFunctions.isModLoaded("emi")) {
|
if (PlatformFunctions.isModLoaded("emi")) {
|
||||||
log("Adding EMI compatibility...");
|
log("Adding EMI compatibility...");
|
||||||
registerCompatHandler(new EMICompat());
|
registerCompatHandler(new EMICompat());
|
||||||
EMICompat.isPresent = true;
|
|
||||||
}
|
}
|
||||||
if (PlatformFunctions.isModLoaded("hardcorequesting") && LambdaReflection.doesClassExist(HQMCompat.GUI_BASE_CLASS_PATH)) {
|
if (PlatformFunctions.isModLoaded("hardcorequesting") && LambdaReflection.doesClassExist(HQMCompat.GUI_BASE_CLASS_PATH)) {
|
||||||
log("Adding HQM compatibility...");
|
log("Adding HQM compatibility...");
|
||||||
@@ -64,10 +63,6 @@ public class MidnightControlsCompat {
|
|||||||
if (PlatformFunctions.isModLoaded("inventorytabs")) {
|
if (PlatformFunctions.isModLoaded("inventorytabs")) {
|
||||||
log("Adding Inventory Tabs compatibility...");
|
log("Adding Inventory Tabs compatibility...");
|
||||||
registerCompatHandler(new InventoryTabsCompat());
|
registerCompatHandler(new InventoryTabsCompat());
|
||||||
InventoryTabsCompat.isPresent = true;
|
|
||||||
}
|
|
||||||
if (PlatformFunctions.isModLoaded("emotecraft")) {
|
|
||||||
EmotecraftCompat.isPresent = true;
|
|
||||||
}
|
}
|
||||||
HANDLERS.forEach(CompatHandler::handle);
|
HANDLERS.forEach(CompatHandler::handle);
|
||||||
InputManager.loadButtonBindings();
|
InputManager.loadButtonBindings();
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public abstract class HandledScreenMixin implements HandledScreenAccessor {
|
|||||||
if (MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && MidnightControlsConfig.hudEnable) {
|
if (MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && MidnightControlsConfig.hudEnable) {
|
||||||
var client = MinecraftClient.getInstance();
|
var client = MinecraftClient.getInstance();
|
||||||
int x = 2, y = client.getWindow().getScaledHeight() - 2 - MidnightControlsRenderer.ICON_SIZE;
|
int x = 2, y = client.getWindow().getScaledHeight() - 2 - MidnightControlsRenderer.ICON_SIZE;
|
||||||
if (EMICompat.isPresent() && EMICompat.isEMIEnabled()) {
|
if (PlatformFunctions.isModLoaded("emi") && EMICompat.isEMIEnabled()) {
|
||||||
x += 42;
|
x += 42;
|
||||||
}
|
}
|
||||||
if (!ButtonBinding.TAKE_ALL.isNotBound()) x = MidnightControlsRenderer.drawButtonTip(context, x, y, ButtonBinding.TAKE_ALL,true, client) + 2;
|
if (!ButtonBinding.TAKE_ALL.isNotBound()) x = MidnightControlsRenderer.drawButtonTip(context, x, y, ButtonBinding.TAKE_ALL,true, client) + 2;
|
||||||
@@ -66,7 +66,7 @@ public abstract class HandledScreenMixin implements HandledScreenAccessor {
|
|||||||
x = 2;
|
x = 2;
|
||||||
y -= 24;
|
y -= 24;
|
||||||
}
|
}
|
||||||
if (EMICompat.isPresent() && EMICompat.isEMIEnabled() && EMICompat.isSearchBarCentered()) {
|
if (PlatformFunctions.isModLoaded("emi") && EMICompat.isEMIEnabled() && EMICompat.isSearchBarCentered()) {
|
||||||
x = client.getWindow().getScaledWidth() - 4 - client.textRenderer.getWidth(Text.translatable("midnightcontrols.action.pickup"))
|
x = client.getWindow().getScaledWidth() - 4 - client.textRenderer.getWidth(Text.translatable("midnightcontrols.action.pickup"))
|
||||||
- client.textRenderer.getWidth(Text.translatable("midnightcontrols.action.quick_move"))
|
- client.textRenderer.getWidth(Text.translatable("midnightcontrols.action.quick_move"))
|
||||||
- 2 * MidnightControlsRenderer.getBindingIconWidth(ButtonBinding.TAKE) - MidnightControlsRenderer.getBindingIconWidth(ButtonBinding.QUICK_MOVE);
|
- 2 * MidnightControlsRenderer.getBindingIconWidth(ButtonBinding.TAKE) - MidnightControlsRenderer.getBindingIconWidth(ButtonBinding.QUICK_MOVE);
|
||||||
|
|||||||
Reference in New Issue
Block a user