mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-16 16:45:09 +01:00
Compare commits
8 Commits
architectu
...
db7f1daa02
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db7f1daa02 | ||
|
|
e50128d75d | ||
|
|
837ead55fb | ||
|
|
c00d5893e9 | ||
|
|
af4b40e88a | ||
|
|
994cd0d155 | ||
|
|
9e4686be32 | ||
|
|
b472503ec4 |
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id "architectury-plugin" version "3.4-SNAPSHOT"
|
id "architectury-plugin" version "3.4-SNAPSHOT"
|
||||||
id "dev.architectury.loom" version "1.10-SNAPSHOT" apply false
|
id "dev.architectury.loom" version "1.11-SNAPSHOT" apply false
|
||||||
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
|
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
|
||||||
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
|
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,20 +150,20 @@ public class MidnightControlsClient extends MidnightControls {
|
|||||||
if (PlatformFunctions.isModLoaded("wynntils") && KeyBindingIDAccessor.getKEYS_BY_ID().entrySet().stream().noneMatch(b -> Objects.equals(b.getValue().getCategory(), "Wynntils"))) return;
|
if (PlatformFunctions.isModLoaded("wynntils") && KeyBindingIDAccessor.getKEYS_BY_ID().entrySet().stream().noneMatch(b -> Objects.equals(b.getValue().getCategory(), "Wynntils"))) return;
|
||||||
for (int i = 0; i < KeyBindingIDAccessor.getKEYS_BY_ID().size(); ++i) {
|
for (int i = 0; i < KeyBindingIDAccessor.getKEYS_BY_ID().size(); ++i) {
|
||||||
KeyBinding keyBinding = KeyBindingIDAccessor.getKEYS_BY_ID().entrySet().stream().toList().get(i).getValue();
|
KeyBinding keyBinding = KeyBindingIDAccessor.getKEYS_BY_ID().entrySet().stream().toList().get(i).getValue();
|
||||||
if (MidnightControlsConfig.excludedKeybindings.stream().noneMatch(excluded -> keyBinding.getTranslationKey().startsWith(excluded))) {
|
if (MidnightControlsConfig.excludedKeybindings.stream().noneMatch(excluded -> keyBinding.getId().startsWith(excluded))) {
|
||||||
if (!keyBinding.getTranslationKey().contains(MidnightControlsConstants.NAMESPACE)) {
|
if (!keyBinding.getId().contains(MidnightControlsConstants.NAMESPACE)) {
|
||||||
AtomicReference<ButtonCategory> category = new AtomicReference<>();
|
AtomicReference<ButtonCategory> category = new AtomicReference<>();
|
||||||
InputManager.streamCategories().forEach(buttonCategory -> {
|
InputManager.streamCategories().forEach(buttonCategory -> {
|
||||||
if (buttonCategory.getIdentifier().equals(validVanillaId(keyBinding.getCategory())))
|
if (buttonCategory.getIdentifier().equals(keyBinding.getCategory().id()))
|
||||||
category.set(buttonCategory);
|
category.set(buttonCategory);
|
||||||
});
|
});
|
||||||
if (category.get() == null) {
|
if (category.get() == null) {
|
||||||
category.set(new ButtonCategory(validVanillaId(keyBinding.getCategory())));
|
category.set(new ButtonCategory(keyBinding.getCategory().id()));
|
||||||
InputManager.registerCategory(category.get());
|
InputManager.registerCategory(category.get());
|
||||||
}
|
}
|
||||||
ButtonBinding buttonBinding = new ButtonBinding.Builder(keyBinding.getTranslationKey()).category(category.get()).linkKeybind(keyBinding).register();
|
ButtonBinding buttonBinding = new ButtonBinding.Builder(keyBinding.getId()).category(category.get()).linkKeybind(keyBinding).register();
|
||||||
if (MidnightControlsConfig.debug) {
|
if (MidnightControlsConfig.debug) {
|
||||||
MidnightControls.log(keyBinding.getTranslationKey());
|
MidnightControls.log(keyBinding.getId());
|
||||||
MidnightControls.log(String.valueOf(buttonBinding));
|
MidnightControls.log(String.valueOf(buttonBinding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,14 +172,6 @@ public class MidnightControlsClient extends MidnightControls {
|
|||||||
InputManager.loadButtonBindings();
|
InputManager.loadButtonBindings();
|
||||||
lateInitDone = true;
|
lateInitDone = true;
|
||||||
}
|
}
|
||||||
private static Identifier validVanillaId(String path) {
|
|
||||||
for(int i = 0; i < path.length(); ++i) {
|
|
||||||
if (!Identifier.isPathCharacterValid(path.charAt(i))) {
|
|
||||||
path = path.replace(path.charAt(i), '_');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Identifier.ofVanilla(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called every Minecraft tick.
|
* This method is called every Minecraft tick.
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ package eu.midnightdust.midnightcontrols.client;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.mojang.blaze3d.platform.GLX;
|
import com.mojang.blaze3d.platform.GLX;
|
||||||
|
import eu.midnightdust.lib.config.EntryInfo;
|
||||||
import eu.midnightdust.lib.config.MidnightConfig;
|
import eu.midnightdust.lib.config.MidnightConfig;
|
||||||
|
import eu.midnightdust.lib.config.MidnightConfigListWidget;
|
||||||
|
import eu.midnightdust.lib.config.MidnightConfigScreen;
|
||||||
import eu.midnightdust.midnightcontrols.ControlsMode;
|
import eu.midnightdust.midnightcontrols.ControlsMode;
|
||||||
import eu.midnightdust.midnightcontrols.MidnightControls;
|
import eu.midnightdust.midnightcontrols.MidnightControls;
|
||||||
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
||||||
@@ -30,6 +33,7 @@ import eu.midnightdust.midnightcontrols.client.enums.TouchMode;
|
|||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.ChatScreen;
|
import net.minecraft.client.gui.screen.ChatScreen;
|
||||||
import net.minecraft.client.gui.screen.advancement.AdvancementsScreen;
|
import net.minecraft.client.gui.screen.advancement.AdvancementsScreen;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|||||||
@@ -17,14 +17,18 @@ import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
|
|||||||
import eu.midnightdust.midnightcontrols.client.compat.YACLCompat;
|
import eu.midnightdust.midnightcontrols.client.compat.YACLCompat;
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.AdvancementsScreenAccessor;
|
import eu.midnightdust.midnightcontrols.client.mixin.AdvancementsScreenAccessor;
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.CreativeInventoryScreenAccessor;
|
import eu.midnightdust.midnightcontrols.client.mixin.CreativeInventoryScreenAccessor;
|
||||||
|
import eu.midnightdust.midnightcontrols.client.mixin.KeyboardAccessor;
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.MouseAccessor;
|
import eu.midnightdust.midnightcontrols.client.mixin.MouseAccessor;
|
||||||
import eu.midnightdust.midnightcontrols.client.util.InventoryUtil;
|
import eu.midnightdust.midnightcontrols.client.util.InventoryUtil;
|
||||||
import eu.midnightdust.midnightcontrols.client.util.storage.AxisStorage;
|
import eu.midnightdust.midnightcontrols.client.util.storage.AxisStorage;
|
||||||
import eu.midnightdust.midnightcontrols.client.util.storage.ButtonStorage;
|
import eu.midnightdust.midnightcontrols.client.util.storage.ButtonStorage;
|
||||||
|
import net.minecraft.client.gui.Click;
|
||||||
import net.minecraft.client.gui.screen.option.KeybindsScreen;
|
import net.minecraft.client.gui.screen.option.KeybindsScreen;
|
||||||
import net.minecraft.client.gui.widget.EntryListWidget;
|
import net.minecraft.client.gui.widget.EntryListWidget;
|
||||||
import net.minecraft.client.gui.widget.PressableWidget;
|
import net.minecraft.client.gui.widget.PressableWidget;
|
||||||
import net.minecraft.client.gui.widget.SliderWidget;
|
import net.minecraft.client.gui.widget.SliderWidget;
|
||||||
|
import net.minecraft.client.input.KeyInput;
|
||||||
|
import net.minecraft.client.input.MouseInput;
|
||||||
import net.minecraft.entity.vehicle.BoatEntity;
|
import net.minecraft.entity.vehicle.BoatEntity;
|
||||||
import org.thinkingstudio.obsidianui.widget.AbstractSpruceWidget;
|
import org.thinkingstudio.obsidianui.widget.AbstractSpruceWidget;
|
||||||
import org.thinkingstudio.obsidianui.widget.container.SpruceEntryListWidget;
|
import org.thinkingstudio.obsidianui.widget.container.SpruceEntryListWidget;
|
||||||
@@ -82,6 +86,7 @@ import static org.lwjgl.glfw.GLFW.*;
|
|||||||
*/
|
*/
|
||||||
public class MidnightInput {
|
public class MidnightInput {
|
||||||
public static final Map<Integer, Integer> BUTTON_COOLDOWNS = new HashMap<>();
|
public static final Map<Integer, Integer> BUTTON_COOLDOWNS = new HashMap<>();
|
||||||
|
public static final KeyInput ENTER_KEY_INPUT = new KeyInput(GLFW_KEY_ENTER, 0, 0);
|
||||||
// Cooldowns
|
// Cooldowns
|
||||||
public int actionGuiCooldown = 0;
|
public int actionGuiCooldown = 0;
|
||||||
public int joystickCooldown = 0;
|
public int joystickCooldown = 0;
|
||||||
@@ -393,9 +398,9 @@ public class MidnightInput {
|
|||||||
accessor.midnightcontrols$onCursorPos(client.getWindow().getHandle(), client.mouse.getX(), client.mouse.getY());
|
accessor.midnightcontrols$onCursorPos(client.getWindow().getHandle(), client.mouse.getX(), client.mouse.getY());
|
||||||
switch (storage.state) {
|
switch (storage.state) {
|
||||||
// Button pressed
|
// Button pressed
|
||||||
case PRESS -> accessor.midnightcontrols$onMouseButton(client.getWindow().getHandle(), GLFW_MOUSE_BUTTON_LEFT, 1, 0);
|
case PRESS -> accessor.midnightcontrols$onMouseButton(client.getWindow().getHandle(), new MouseInput(GLFW_MOUSE_BUTTON_LEFT, 1), 0);
|
||||||
case RELEASE -> { // Button released
|
case RELEASE -> { // Button released
|
||||||
accessor.midnightcontrols$onMouseButton(client.getWindow().getHandle(), GLFW_MOUSE_BUTTON_LEFT, 0, 0);
|
accessor.midnightcontrols$onMouseButton(client.getWindow().getHandle(), new MouseInput(GLFW_MOUSE_BUTTON_LEFT, 0), 0);
|
||||||
client.currentScreen.setDragging(false);
|
client.currentScreen.setDragging(false);
|
||||||
}
|
}
|
||||||
case REPEAT -> client.currentScreen.setDragging(true); // Button held down / dragging
|
case REPEAT -> client.currentScreen.setDragging(true); // Button held down / dragging
|
||||||
@@ -412,8 +417,8 @@ public class MidnightInput {
|
|||||||
if (client.currentScreen instanceof HandledScreen<?> handledScreen && ((HandledScreenAccessor) handledScreen).midnightcontrols$getSlotAt(
|
if (client.currentScreen instanceof HandledScreen<?> handledScreen && ((HandledScreenAccessor) handledScreen).midnightcontrols$getSlotAt(
|
||||||
mouseX, mouseY) != null) return;
|
mouseX, mouseY) != null) return;
|
||||||
if (!this.ignoreNextXRelease && client.currentScreen != null) {
|
if (!this.ignoreNextXRelease && client.currentScreen != null) {
|
||||||
if (storage.state == ButtonState.PRESS) client.currentScreen.mouseClicked(mouseX, mouseY, GLFW.GLFW_MOUSE_BUTTON_2);
|
if (storage.state == ButtonState.PRESS) client.currentScreen.mouseClicked(new Click(mouseX, mouseY, new MouseInput(GLFW.GLFW_MOUSE_BUTTON_2, 1)), false);
|
||||||
else if (storage.state == ButtonState.RELEASE) client.currentScreen.mouseReleased(mouseX, mouseY, GLFW.GLFW_MOUSE_BUTTON_2);
|
else if (storage.state == ButtonState.RELEASE) client.currentScreen.mouseReleased(new Click(mouseX, mouseY, new MouseInput(GLFW.GLFW_MOUSE_BUTTON_2, 0)));
|
||||||
this.screenCloseCooldown = 5;
|
this.screenCloseCooldown = 5;
|
||||||
} else {
|
} else {
|
||||||
this.ignoreNextXRelease = false;
|
this.ignoreNextXRelease = false;
|
||||||
@@ -607,7 +612,7 @@ public class MidnightInput {
|
|||||||
public boolean handleAButton(@NotNull Screen screen, @NotNull Element focused) {
|
public boolean handleAButton(@NotNull Screen screen, @NotNull Element focused) {
|
||||||
if (focused instanceof PressableWidget widget) {
|
if (focused instanceof PressableWidget widget) {
|
||||||
widget.playDownSound(MinecraftClient.getInstance().getSoundManager());
|
widget.playDownSound(MinecraftClient.getInstance().getSoundManager());
|
||||||
widget.onPress();
|
widget.onPress(ENTER_KEY_INPUT);
|
||||||
return true;
|
return true;
|
||||||
} else if (focused instanceof AbstractSprucePressableButtonWidget widget) {
|
} else if (focused instanceof AbstractSprucePressableButtonWidget widget) {
|
||||||
widget.playDownSound();
|
widget.playDownSound();
|
||||||
@@ -622,8 +627,8 @@ public class MidnightInput {
|
|||||||
} else if (focused instanceof MultiplayerServerListWidget list) {
|
} else if (focused instanceof MultiplayerServerListWidget list) {
|
||||||
var entry = list.getSelectedOrNull();
|
var entry = list.getSelectedOrNull();
|
||||||
if (entry instanceof MultiplayerServerListWidget.LanServerEntry || entry instanceof MultiplayerServerListWidget.ServerEntry) {
|
if (entry instanceof MultiplayerServerListWidget.LanServerEntry || entry instanceof MultiplayerServerListWidget.ServerEntry) {
|
||||||
((MultiplayerScreen) screen).select(entry);
|
//((MultiplayerScreen) screen).select(entry);
|
||||||
((MultiplayerScreen) screen).connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
} else if (focused instanceof SpruceParentWidget) {
|
} else if (focused instanceof SpruceParentWidget) {
|
||||||
var childFocused = ((SpruceParentWidget<?>) focused).getFocused();
|
var childFocused = ((SpruceParentWidget<?>) focused).getFocused();
|
||||||
@@ -672,7 +677,7 @@ public class MidnightInput {
|
|||||||
}
|
}
|
||||||
case SliderWidget slider -> {
|
case SliderWidget slider -> {
|
||||||
if (slider.active) {
|
if (slider.active) {
|
||||||
slider.keyPressed(right ? 262 : 263, 0, 0);
|
slider.keyPressed(new KeyInput(right ? 262 : 263, 0, 0));
|
||||||
this.actionGuiCooldown = 2; // Prevent to press too quickly the focused element, so we have to skip 5 ticks.
|
this.actionGuiCooldown = 2; // Prevent to press too quickly the focused element, so we have to skip 5 ticks.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -796,7 +801,7 @@ public class MidnightInput {
|
|||||||
.anyMatch(element -> {
|
.anyMatch(element -> {
|
||||||
if (element.getMessage().getContent() instanceof TranslatableTextContent translatableText) {
|
if (element.getMessage().getContent() instanceof TranslatableTextContent translatableText) {
|
||||||
if (set.stream().anyMatch(key -> translatableText.getKey().equals(key))) {
|
if (set.stream().anyMatch(key -> translatableText.getKey().equals(key))) {
|
||||||
element.onPress();
|
element.onPress(ENTER_KEY_INPUT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -811,9 +816,9 @@ public class MidnightInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void pressKeyboardKey(MinecraftClient client, int key) {
|
public void pressKeyboardKey(MinecraftClient client, int key) {
|
||||||
client.keyboard.onKey(client.getWindow().getHandle(), key, 0, 1, 0);
|
((KeyboardAccessor) client.keyboard).midnightcontrols$onKey(client.getWindow().getHandle(), 1, new KeyInput(key, 0, 0));
|
||||||
}
|
}
|
||||||
public void pressKeyboardKey(Screen screen, int key) {
|
public void pressKeyboardKey(Screen screen, int key) {
|
||||||
screen.keyPressed(key, 0, 1);
|
screen.keyPressed(new KeyInput(key, 0, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class MidnightReacharound {
|
|||||||
if (client.player.isRiding())
|
if (client.player.isRiding())
|
||||||
return null;
|
return null;
|
||||||
// Temporary pos, do not use
|
// Temporary pos, do not use
|
||||||
Vec3d playerPosi = client.player.getPos();
|
Vec3d playerPosi = client.player.getEntityPos();
|
||||||
|
|
||||||
// Imitates var playerPos = client.player.getBlockPos().down();
|
// Imitates var playerPos = client.player.getBlockPos().down();
|
||||||
Vec3d playerPos = new Vec3d(playerPosi.getX(), playerPosi.getY() - 1.0, playerPosi.getZ());
|
Vec3d playerPos = new Vec3d(playerPosi.getX(), playerPosi.getY() - 1.0, playerPosi.getZ());
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import dev.emi.emi.api.EmiApi;
|
|||||||
import dev.emi.emi.config.EmiConfig;
|
import dev.emi.emi.config.EmiConfig;
|
||||||
import dev.emi.emi.screen.EmiScreenManager;
|
import dev.emi.emi.screen.EmiScreenManager;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
||||||
|
import eu.midnightdust.midnightcontrols.client.MidnightInput;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.ButtonCategory;
|
import eu.midnightdust.midnightcontrols.client.controller.ButtonCategory;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
|
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
|
||||||
@@ -14,8 +15,8 @@ import static eu.midnightdust.midnightcontrols.MidnightControls.id;
|
|||||||
public class EMICompat implements CompatHandler {
|
public class EMICompat implements CompatHandler {
|
||||||
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(MidnightInput.ENTER_KEY_INPUT);
|
||||||
else EmiScreenManager.getSearchPanel().pageLeft.onPress();
|
else EmiScreenManager.getSearchPanel().pageLeft.onPress(MidnightInput.ENTER_KEY_INPUT);
|
||||||
MidnightControlsClient.input.actionGuiCooldown = 5;
|
MidnightControlsClient.input.actionGuiCooldown = 5;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import eu.midnightdust.midnightcontrols.client.mixin.MouseAccessor;
|
|||||||
import io.github.kosmx.emotes.arch.screen.ingame.FastMenuScreen;
|
import io.github.kosmx.emotes.arch.screen.ingame.FastMenuScreen;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.input.MouseInput;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ public class EmotecraftCompat {
|
|||||||
InputManager.INPUT_MANAGER.updateMousePosition(client);
|
InputManager.INPUT_MANAGER.updateMousePosition(client);
|
||||||
|
|
||||||
if (stickReleased) {
|
if (stickReleased) {
|
||||||
((MouseAccessor) client.mouse).midnightcontrols$onMouseButton(client.getWindow().getHandle(), GLFW.GLFW_MOUSE_BUTTON_LEFT, GLFW.GLFW_PRESS, 0);
|
((MouseAccessor) client.mouse).midnightcontrols$onMouseButton(client.getWindow().getHandle(), new MouseInput(GLFW.GLFW_MOUSE_BUTTON_LEFT, GLFW.GLFW_PRESS), 0);
|
||||||
prevIndex = -1;
|
prevIndex = -1;
|
||||||
}
|
}
|
||||||
else prevIndex = index;
|
else prevIndex = index;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import dev.isxander.yacl.gui.OptionListWidget;
|
|||||||
import dev.isxander.yacl.gui.YACLScreen;
|
import dev.isxander.yacl.gui.YACLScreen;
|
||||||
import dev.isxander.yacl.gui.controllers.ControllerWidget;
|
import dev.isxander.yacl.gui.controllers.ControllerWidget;
|
||||||
import dev.isxander.yacl.gui.controllers.slider.SliderControllerElement;
|
import dev.isxander.yacl.gui.controllers.slider.SliderControllerElement;
|
||||||
|
import eu.midnightdust.midnightcontrols.client.MidnightInput;
|
||||||
import net.minecraft.client.gui.Element;
|
import net.minecraft.client.gui.Element;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
@@ -13,7 +14,7 @@ public class YACLCompat implements CompatHandler {
|
|||||||
public static boolean handleAButton(Screen screen, Element element) {
|
public static boolean handleAButton(Screen screen, Element element) {
|
||||||
if (element instanceof AbstractWidget abstractWidget) {
|
if (element instanceof AbstractWidget abstractWidget) {
|
||||||
// imitate enter key press
|
// imitate enter key press
|
||||||
return abstractWidget.keyPressed(GLFW.GLFW_KEY_ENTER, 0, 0);
|
return abstractWidget.keyPressed(MidnightInput.ENTER_KEY_INPUT);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class ButtonBinding {
|
|||||||
public static final ButtonBinding SCREENSHOT = new Builder("screenshot").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW_GAMEPAD_BUTTON_A)
|
public static final ButtonBinding SCREENSHOT = new Builder("screenshot").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW_GAMEPAD_BUTTON_A)
|
||||||
.action(InputHandlers::handleScreenshot).cooldown().register();
|
.action(InputHandlers::handleScreenshot).cooldown().register();
|
||||||
public static final ButtonBinding DEBUG_SCREEN = new Builder("debug_screen").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW_GAMEPAD_BUTTON_B)
|
public static final ButtonBinding DEBUG_SCREEN = new Builder("debug_screen").buttons(GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW_GAMEPAD_BUTTON_B)
|
||||||
.action((client,binding,value,action) -> {if (action == ButtonState.PRESS) client.inGameHud.getDebugHud().toggleDebugHud(); return true;}).cooldown().register();
|
.action((client,binding,value,action) -> {if (action == ButtonState.PRESS) client.inGameHud.getDebugHud().toggleRenderingChart(); return true;}).cooldown().register();
|
||||||
public static final ButtonBinding SLOT_DOWN = new Builder("slot_down").buttons(GLFW_GAMEPAD_BUTTON_DPAD_DOWN)
|
public static final ButtonBinding SLOT_DOWN = new Builder("slot_down").buttons(GLFW_GAMEPAD_BUTTON_DPAD_DOWN)
|
||||||
.action(InputHandlers.handleInventorySlotPad(1)).onlyInInventory().cooldown().register();
|
.action(InputHandlers.handleInventorySlotPad(1)).onlyInInventory().cooldown().register();
|
||||||
public static final ButtonBinding SLOT_LEFT = new Builder("slot_left").buttons(GLFW_GAMEPAD_BUTTON_DPAD_LEFT)
|
public static final ButtonBinding SLOT_LEFT = new Builder("slot_left").buttons(GLFW_GAMEPAD_BUTTON_DPAD_LEFT)
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ public class InputHandlers {
|
|||||||
if (button.getName().equals("take_all")) {
|
if (button.getName().equals("take_all")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
slotId = accessor.midnightcontrols$isClickOutsideBounds(x, y, accessor.getX(), accessor.getY(), GLFW_MOUSE_BUTTON_1) ? -999 : -1;
|
slotId = accessor.midnightcontrols$isClickOutsideBounds(x, y, accessor.getX(), accessor.getY()) ? -999 : -1;
|
||||||
} else {
|
} else {
|
||||||
slotId = slot.id;
|
slotId = slot.id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.cli
|
|||||||
*/
|
*/
|
||||||
public class InputManager {
|
public class InputManager {
|
||||||
public static final InputManager INPUT_MANAGER = new InputManager();
|
public static final InputManager INPUT_MANAGER = new InputManager();
|
||||||
private static final List<ButtonBinding> BINDINGS = new ArrayList<>();
|
private static final List<ButtonBinding> BINDINGS = Collections.synchronizedList(new ArrayList<>());
|
||||||
private static final List<ButtonCategory> CATEGORIES = new ArrayList<>();
|
private static final List<ButtonCategory> CATEGORIES = new ArrayList<>();
|
||||||
public static final Int2ObjectMap<ButtonState> STATES = new Int2ObjectOpenHashMap<>();
|
public static final Int2ObjectMap<ButtonState> STATES = new Int2ObjectOpenHashMap<>();
|
||||||
public static final Int2FloatMap BUTTON_VALUES = new Int2FloatOpenHashMap();
|
public static final Int2FloatMap BUTTON_VALUES = new Int2FloatOpenHashMap();
|
||||||
@@ -109,8 +109,10 @@ public class InputManager {
|
|||||||
* @return true if the binding is registered, else false
|
* @return true if the binding is registered, else false
|
||||||
*/
|
*/
|
||||||
public static boolean hasBinding(@NotNull ButtonBinding binding) {
|
public static boolean hasBinding(@NotNull ButtonBinding binding) {
|
||||||
|
synchronized (BINDINGS) {
|
||||||
return BINDINGS.contains(binding);
|
return BINDINGS.contains(binding);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the specified binding is registered or not.
|
* Returns whether the specified binding is registered or not.
|
||||||
@@ -119,8 +121,10 @@ public class InputManager {
|
|||||||
* @return true if the binding is registered, else false
|
* @return true if the binding is registered, else false
|
||||||
*/
|
*/
|
||||||
public static boolean hasBinding(@NotNull String name) {
|
public static boolean hasBinding(@NotNull String name) {
|
||||||
|
synchronized (BINDINGS) {
|
||||||
return BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name));
|
return BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the specified binding is registered or not.
|
* Returns whether the specified binding is registered or not.
|
||||||
@@ -139,18 +143,22 @@ public class InputManager {
|
|||||||
* @return true if the binding is registered, else false
|
* @return true if the binding is registered, else false
|
||||||
*/
|
*/
|
||||||
public static ButtonBinding getBinding(@NotNull String name) {
|
public static ButtonBinding getBinding(@NotNull String name) {
|
||||||
|
synchronized (BINDINGS) {
|
||||||
if (BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name)))
|
if (BINDINGS.parallelStream().map(ButtonBinding::getName).anyMatch(binding -> binding.equalsIgnoreCase(name)))
|
||||||
BINDINGS.forEach(binding -> {
|
BINDINGS.forEach(binding -> {
|
||||||
if (binding.getName().equalsIgnoreCase(name)) InputManager.tempBinding = binding;
|
if (binding.getName().equalsIgnoreCase(name)) InputManager.tempBinding = binding;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return tempBinding;
|
return tempBinding;
|
||||||
}
|
}
|
||||||
private static List<ButtonBinding> unboundBindings;
|
private static List<ButtonBinding> unboundBindings;
|
||||||
public static List<ButtonBinding> getUnboundBindings() {
|
public static List<ButtonBinding> getUnboundBindings() {
|
||||||
unboundBindings = new ArrayList<>();
|
unboundBindings = new ArrayList<>();
|
||||||
|
synchronized (BINDINGS) {
|
||||||
BINDINGS.forEach(binding -> {
|
BINDINGS.forEach(binding -> {
|
||||||
if (binding.isNotBound() && !MidnightControlsConfig.ignoredUnboundKeys.contains(binding.getTranslationKey())) unboundBindings.add(binding);
|
if (binding.isNotBound() && !MidnightControlsConfig.ignoredUnboundKeys.contains(binding.getTranslationKey())) unboundBindings.add(binding);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
unboundBindings.sort(Comparator.comparing(s -> I18n.translate(s.getTranslationKey())));
|
unboundBindings.sort(Comparator.comparing(s -> I18n.translate(s.getTranslationKey())));
|
||||||
return unboundBindings;
|
return unboundBindings;
|
||||||
}
|
}
|
||||||
@@ -162,9 +170,11 @@ public class InputManager {
|
|||||||
* @return the registered binding
|
* @return the registered binding
|
||||||
*/
|
*/
|
||||||
public static @NotNull ButtonBinding registerBinding(@NotNull ButtonBinding binding) {
|
public static @NotNull ButtonBinding registerBinding(@NotNull ButtonBinding binding) {
|
||||||
if (hasBinding(binding))
|
synchronized (BINDINGS) {
|
||||||
|
if (BINDINGS.contains(binding))
|
||||||
throw new IllegalStateException("Cannot register twice a button binding in the registry.");
|
throw new IllegalStateException("Cannot register twice a button binding in the registry.");
|
||||||
BINDINGS.add(binding);
|
BINDINGS.add(binding);
|
||||||
|
}
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,8 +294,10 @@ public class InputManager {
|
|||||||
* @return true if the button has duplicated bindings, else false
|
* @return true if the button has duplicated bindings, else false
|
||||||
*/
|
*/
|
||||||
public static boolean hasDuplicatedBindings(int[] button) {
|
public static boolean hasDuplicatedBindings(int[] button) {
|
||||||
|
synchronized (BINDINGS) {
|
||||||
return BINDINGS.parallelStream().filter(binding -> areButtonsEquivalent(binding.getButton(), button)).count() > 1;
|
return BINDINGS.parallelStream().filter(binding -> areButtonsEquivalent(binding.getButton(), button)).count() > 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the button has duplicated bindings.
|
* Returns whether the button has duplicated bindings.
|
||||||
@@ -294,8 +306,10 @@ public class InputManager {
|
|||||||
* @return true if the button has duplicated bindings, else false
|
* @return true if the button has duplicated bindings, else false
|
||||||
*/
|
*/
|
||||||
public static boolean hasDuplicatedBindings(ButtonBinding binding) {
|
public static boolean hasDuplicatedBindings(ButtonBinding binding) {
|
||||||
|
synchronized (BINDINGS) {
|
||||||
return BINDINGS.parallelStream().filter(other -> areButtonsEquivalent(other.getButton(), binding.getButton()) && other.filter.equals(binding.filter)).count() > 1;
|
return BINDINGS.parallelStream().filter(other -> areButtonsEquivalent(other.getButton(), binding.getButton()) && other.filter.equals(binding.filter)).count() > 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the specified buttons are equivalent or not.
|
* Returns whether the specified buttons are equivalent or not.
|
||||||
@@ -347,6 +361,7 @@ public class InputManager {
|
|||||||
record ButtonStateValue(ButtonState state, float value) {
|
record ButtonStateValue(ButtonState state, float value) {
|
||||||
}
|
}
|
||||||
var states = new Object2ObjectOpenHashMap<ButtonBinding, ButtonStateValue>();
|
var states = new Object2ObjectOpenHashMap<ButtonBinding, ButtonStateValue>();
|
||||||
|
synchronized (BINDINGS) {
|
||||||
for (var binding : BINDINGS) {
|
for (var binding : BINDINGS) {
|
||||||
var state = binding.isAvailable() ? getBindingState(binding) : ButtonState.NONE;
|
var state = binding.isAvailable() ? getBindingState(binding) : ButtonState.NONE;
|
||||||
if (skipButtons.intStream().anyMatch(btn -> containsButton(binding.getButton(), btn))) {
|
if (skipButtons.intStream().anyMatch(btn -> containsButton(binding.getButton(), btn))) {
|
||||||
@@ -369,6 +384,7 @@ public class InputManager {
|
|||||||
|
|
||||||
states.put(binding, new ButtonStateValue(state, value));
|
states.put(binding, new ButtonStateValue(state, value));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
states.forEach((binding, state) -> {
|
states.forEach((binding, state) -> {
|
||||||
if (state.state() != ButtonState.NONE) {
|
if (state.state() != ButtonState.NONE) {
|
||||||
@@ -387,8 +403,10 @@ public class InputManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull Stream<ButtonBinding> streamBindings() {
|
public static @NotNull Stream<ButtonBinding> streamBindings() {
|
||||||
|
synchronized (BINDINGS) {
|
||||||
return BINDINGS.stream();
|
return BINDINGS.stream();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static @NotNull Stream<ButtonCategory> streamCategories() {
|
public static @NotNull Stream<ButtonCategory> streamCategories() {
|
||||||
return CATEGORIES.stream();
|
return CATEGORIES.stream();
|
||||||
@@ -405,6 +423,15 @@ public class InputManager {
|
|||||||
* @see #makeKeyBinding(Identifier, InputUtil.Type, int, String)
|
* @see #makeKeyBinding(Identifier, InputUtil.Type, int, String)
|
||||||
*/
|
*/
|
||||||
public static @NotNull KeyBinding makeKeyBinding(@NotNull Identifier id, InputUtil.Type type, int code, @NotNull String category) {
|
public static @NotNull KeyBinding makeKeyBinding(@NotNull Identifier id, InputUtil.Type type, int code, @NotNull String category) {
|
||||||
return new KeyBinding(String.format("key.%s.%s", id.getNamespace(), id.getPath()), type, code, category);
|
return new KeyBinding(String.format("key.%s.%s", id.getNamespace(), id.getPath()), type, code, new KeyBinding.Category(validVanillaId(category)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Identifier validVanillaId(String path) {
|
||||||
|
for(int i = 0; i < path.length(); ++i) {
|
||||||
|
if (!Identifier.isPathCharacterValid(path.charAt(i))) {
|
||||||
|
path = path.replace(path.charAt(i), '_');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Identifier.ofVanilla(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class MappingsStringInputWidget extends SpruceContainerWidget {
|
|||||||
@Override
|
@Override
|
||||||
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||||
super.renderWidget(context, mouseX, mouseY, delta);
|
super.renderWidget(context, mouseX, mouseY, delta);
|
||||||
context.drawCenteredTextWithShadow(this.client.textRenderer, Text.translatable("midnightcontrols.menu.multiple_mapping_tip"), this.textArea.getX() + this.textArea.getWidth() / 2, this.textArea.getY() + this.textArea.getHeight() - 12, 0x888888);
|
context.drawCenteredTextWithShadow(this.client.textRenderer, Text.translatable("midnightcontrols.menu.multiple_mapping_tip"), this.textArea.getX() + this.textArea.getWidth() / 2, this.textArea.getY() + this.textArea.getHeight() - 12, 0xFF888888);
|
||||||
context.drawCenteredTextWithShadow(this.client.textRenderer, Text.translatable("midnightcontrols.menu.current_controller_guid", MidnightControlsConfig.getController().getGuid()), this.textArea.getX() + this.textArea.getWidth() / 2, this.height - 21, 0xFFFFFF);
|
context.drawCenteredTextWithShadow(this.client.textRenderer, Text.translatable("midnightcontrols.menu.current_controller_guid", MidnightControlsConfig.getController().getGuid()), this.textArea.getX() + this.textArea.getWidth() / 2, this.height - 21, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
|||||||
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
|
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
||||||
import net.minecraft.client.render.RenderTickCounter;
|
import net.minecraft.client.render.RenderTickCounter;
|
||||||
|
import org.joml.Matrix3x2fStack;
|
||||||
import org.thinkingstudio.obsidianui.hud.Hud;
|
import org.thinkingstudio.obsidianui.hud.Hud;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.resource.language.I18n;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
@@ -83,13 +83,13 @@ public class MidnightControlsHud extends Hud {
|
|||||||
if (MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && this.client.currentScreen == null) {
|
if (MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && this.client.currentScreen == null) {
|
||||||
isCrammed = client.getWindow().getScaledWidth() < 520;
|
isCrammed = client.getWindow().getScaledWidth() < 520;
|
||||||
int y = bottom(2);
|
int y = bottom(2);
|
||||||
MatrixStack matrices = context.getMatrices();
|
Matrix3x2fStack matrices = context.getMatrices();
|
||||||
matrices.push();
|
matrices.pushMatrix();
|
||||||
this.renderFirstIcons(context, MidnightControlsConfig.hudSide == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
|
this.renderFirstIcons(context, MidnightControlsConfig.hudSide == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
|
||||||
this.renderSecondIcons(context, MidnightControlsConfig.hudSide == HudSide.RIGHT ? 2 : client.getWindow().getScaledWidth() - 2, y);
|
this.renderSecondIcons(context, MidnightControlsConfig.hudSide == HudSide.RIGHT ? 2 : client.getWindow().getScaledWidth() - 2, y);
|
||||||
this.renderFirstSection(context, MidnightControlsConfig.hudSide == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
|
this.renderFirstSection(context, MidnightControlsConfig.hudSide == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
|
||||||
this.renderSecondSection(context, MidnightControlsConfig.hudSide == HudSide.RIGHT ? 2 : client.getWindow().getScaledWidth() - 2, y);
|
this.renderSecondSection(context, MidnightControlsConfig.hudSide == HudSide.RIGHT ? 2 : client.getWindow().getScaledWidth() - 2, y);
|
||||||
matrices.pop();
|
matrices.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MidnightControlsClient.reacharound.isLastReacharoundVertical()) {
|
if (MidnightControlsClient.reacharound.isLastReacharoundVertical()) {
|
||||||
@@ -102,7 +102,7 @@ public class MidnightControlsHud extends Hud {
|
|||||||
int opacity = ((int) (255 * scale)) << 24;
|
int opacity = ((int) (255 * scale)) << 24;
|
||||||
|
|
||||||
context.drawText(client.textRenderer, text, (int) (window.getScaledWidth() / 2.f - this.client.textRenderer.getWidth(text) / 2.f),
|
context.drawText(client.textRenderer, text, (int) (window.getScaledWidth() / 2.f - this.client.textRenderer.getWidth(text) / 2.f),
|
||||||
(int) (window.getScaledHeight() / 2.f - 4), 0xCCCCCC | opacity, false);
|
(int) (window.getScaledHeight() / 2.f - 4), 0xFFCCCCCC | opacity, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,6 +298,6 @@ public class MidnightControlsHud extends Hud {
|
|||||||
return;
|
return;
|
||||||
var translatedAction = I18n.translate(action);
|
var translatedAction = I18n.translate(action);
|
||||||
int textY = (MidnightControlsRenderer.ICON_SIZE / 2 - this.client.textRenderer.fontHeight / 2) + 1;
|
int textY = (MidnightControlsRenderer.ICON_SIZE / 2 - this.client.textRenderer.fontHeight / 2) + 1;
|
||||||
context.drawText(this.client.textRenderer, translatedAction, x, (y + textY), 14737632, false);
|
context.drawText(this.client.textRenderer, translatedAction, x, (y + textY), 0xFFFFFFFF, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
package eu.midnightdust.midnightcontrols.client.gui;
|
package eu.midnightdust.midnightcontrols.client.gui;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||||
import eu.midnightdust.midnightcontrols.ControlsMode;
|
import eu.midnightdust.midnightcontrols.ControlsMode;
|
||||||
import eu.midnightdust.midnightcontrols.client.enums.ControllerType;
|
import eu.midnightdust.midnightcontrols.client.enums.ControllerType;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
||||||
@@ -18,24 +20,33 @@ import eu.midnightdust.midnightcontrols.client.MidnightInput;
|
|||||||
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
|
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
||||||
import eu.midnightdust.midnightcontrols.client.enums.VirtualMouseSkin;
|
import eu.midnightdust.midnightcontrols.client.enums.VirtualMouseSkin;
|
||||||
|
import eu.midnightdust.midnightcontrols.client.gui.render.UnalignedTexturedQuadGuiElementRenderState;
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.DrawContextAccessor;
|
import eu.midnightdust.midnightcontrols.client.mixin.DrawContextAccessor;
|
||||||
import eu.midnightdust.midnightcontrols.client.util.HandledScreenAccessor;
|
import eu.midnightdust.midnightcontrols.client.util.HandledScreenAccessor;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
|
import net.minecraft.client.gl.RenderPipelines;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.gui.render.state.TexturedQuadGuiElementRenderState;
|
||||||
import net.minecraft.client.render.*;
|
import net.minecraft.client.render.*;
|
||||||
import net.minecraft.client.resource.language.I18n;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
|
import net.minecraft.client.texture.TextureSetup;
|
||||||
|
import net.minecraft.client.util.SpriteIdentifier;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Atlases;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.ColorHelper;
|
import net.minecraft.util.math.ColorHelper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.joml.Matrix3x2f;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
|
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
|
||||||
|
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the midnightcontrols renderer.
|
* Represents the midnightcontrols renderer.
|
||||||
@@ -171,8 +182,8 @@ public class MidnightControlsRenderer {
|
|||||||
|
|
||||||
int assetSize = axis || (button >= 15 && button <= 18) ? AXIS_SIZE : BUTTON_SIZE;
|
int assetSize = axis || (button >= 15 && button <= 18) ? AXIS_SIZE : BUTTON_SIZE;
|
||||||
|
|
||||||
RenderSystem.setShaderColor(1.f, second ? 0.f : 1.f, 1.f, 1.f);
|
//RenderSystem.setShaderColor(1.f, second ? 0.f : 1.f, 1.f, 1.f);
|
||||||
context.drawTexture(RenderLayer::getGuiTextured, axis ? MidnightControlsClient.CONTROLLER_AXIS : button >= 15 && button <= 19 ? MidnightControlsClient.CONTROLLER_EXPANDED :MidnightControlsClient.CONTROLLER_BUTTONS
|
context.drawTexture(RenderPipelines.GUI_TEXTURED, axis ? MidnightControlsClient.CONTROLLER_AXIS : button >= 15 && button <= 19 ? MidnightControlsClient.CONTROLLER_EXPANDED :MidnightControlsClient.CONTROLLER_BUTTONS
|
||||||
, x + (ICON_SIZE / 2 - assetSize / 2), y + (ICON_SIZE / 2 - assetSize / 2),
|
, x + (ICON_SIZE / 2 - assetSize / 2), y + (ICON_SIZE / 2 - assetSize / 2),
|
||||||
(float) buttonOffset, (float) (controllerType * assetSize),
|
(float) buttonOffset, (float) (controllerType * assetSize),
|
||||||
assetSize, assetSize,
|
assetSize, assetSize,
|
||||||
@@ -192,7 +203,8 @@ public class MidnightControlsRenderer {
|
|||||||
var translatedAction = I18n.translate(action);
|
var translatedAction = I18n.translate(action);
|
||||||
int textY = (MidnightControlsRenderer.ICON_SIZE / 2 - client.textRenderer.fontHeight / 2) + 1;
|
int textY = (MidnightControlsRenderer.ICON_SIZE / 2 - client.textRenderer.fontHeight / 2) + 1;
|
||||||
|
|
||||||
return context.drawTextWithShadow(client.textRenderer, translatedAction, (x + buttonWidth + 2), (y + textY), 14737632);
|
context.drawTextWithShadow(client.textRenderer, translatedAction, (x + buttonWidth + 2), (y + textY), 0xFFFFFFFF);
|
||||||
|
return (x + buttonWidth + 2) + client.textRenderer.getWidth(translatedAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -10;
|
return -10;
|
||||||
@@ -211,8 +223,9 @@ public class MidnightControlsRenderer {
|
|||||||
Identifier spritePath = MidnightControlsClient.WAYLAND_CURSOR_TEXTURE_LIGHT;
|
Identifier spritePath = MidnightControlsClient.WAYLAND_CURSOR_TEXTURE_LIGHT;
|
||||||
if (MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.DEFAULT_DARK || MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.SECOND_DARK)
|
if (MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.DEFAULT_DARK || MidnightControlsConfig.virtualMouseSkin == VirtualMouseSkin.SECOND_DARK)
|
||||||
spritePath = MidnightControlsClient.WAYLAND_CURSOR_TEXTURE_DARK;
|
spritePath = MidnightControlsClient.WAYLAND_CURSOR_TEXTURE_DARK;
|
||||||
Sprite sprite = client.getGuiAtlasManager().getSprite(spritePath);
|
|
||||||
drawUnalignedTexturedQuad(RenderLayer::getGuiTextured, sprite.getAtlasId(), context, mouseX, mouseX + 8, mouseY, mouseY + 8, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
|
Sprite sprite = client.getAtlasManager().getAtlasTexture(Atlases.GUI).getSprite(spritePath);
|
||||||
|
drawUnalignedTexturedQuad(RenderPipelines.GUI_TEXTURED, sprite.getAtlasId(), context, mouseX, mouseX + 8, mouseY, mouseY + 8, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
|
||||||
} catch (IllegalStateException ignored) {}
|
} catch (IllegalStateException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,21 +268,13 @@ public class MidnightControlsRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Sprite sprite = client.getGuiAtlasManager().getSprite(id(MidnightControlsConfig.virtualMouseSkin.getSpritePath() + (hoverSlot ? "_slot" : "")));
|
Sprite sprite = client.getAtlasManager().getAtlasTexture(Atlases.GUI).getSprite(id(MidnightControlsConfig.virtualMouseSkin.getSpritePath() + (hoverSlot ? "_slot" : "")));
|
||||||
drawUnalignedTexturedQuad(RenderLayer::getGuiTextured, sprite.getAtlasId(), context, mouseX, mouseX + 16, mouseY, mouseY + 16, 999, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
|
drawUnalignedTexturedQuad(RenderPipelines.GUI_TEXTURED, sprite.getAtlasId(), context, mouseX, mouseX + 16, mouseY, mouseY + 16, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV());
|
||||||
} catch (IllegalStateException ignored) {}
|
} catch (IllegalStateException ignored) {}
|
||||||
}
|
}
|
||||||
private static void drawUnalignedTexturedQuad(Function<Identifier, RenderLayer> renderLayers, Identifier texture, DrawContext context, float x1, float x2, float y1, float y2, float z, float u1, float u2, float v1, float v2) {
|
private static void drawUnalignedTexturedQuad(RenderPipeline pipeline, Identifier texture, DrawContext context, float x1, float x2, float y1, float y2, float u1, float u2, float v1, float v2) {
|
||||||
RenderLayer renderLayer = renderLayers.apply(texture);
|
DrawContextAccessor accessor = (DrawContextAccessor) context;
|
||||||
//RenderSystem.setShaderTexture(0, texture);
|
accessor.getState().addSimpleElement(new UnalignedTexturedQuadGuiElementRenderState(pipeline, TextureSetup.withoutGlTexture(client.getTextureManager().getTexture(texture).getGlTextureView()), new Matrix3x2f(context.getMatrices()), x1, y1, x2, y2, u1, u2, v1, v2, 0xffffffff, accessor.getScissorStack().peekLast()));
|
||||||
Matrix4f matrix4f = context.getMatrices().peek().getPositionMatrix();
|
|
||||||
//BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
|
|
||||||
VertexConsumer vertexConsumer = ((DrawContextAccessor)context).getVertexConsumers().getBuffer(renderLayer);
|
|
||||||
vertexConsumer.vertex(matrix4f, x1, y1, z).texture(u1, v1).color(ColorHelper.getWhite(1.0f));
|
|
||||||
vertexConsumer.vertex(matrix4f, x1, y2, z).texture(u1, v2).color(ColorHelper.getWhite(1.0f));
|
|
||||||
vertexConsumer.vertex(matrix4f, x2, y2, z).texture(u2, v2).color(ColorHelper.getWhite(1.0f));
|
|
||||||
vertexConsumer.vertex(matrix4f, x2, y1, z).texture(u2, v1).color(ColorHelper.getWhite(1.0f));
|
|
||||||
context.draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ButtonSize(int length, int height) {
|
public record ButtonSize(int length, int height) {
|
||||||
|
|||||||
@@ -9,16 +9,13 @@
|
|||||||
|
|
||||||
package eu.midnightdust.midnightcontrols.client.gui;
|
package eu.midnightdust.midnightcontrols.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.opengl.GlStateManager;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
||||||
import eu.midnightdust.midnightcontrols.client.util.platform.NetworkUtil;
|
import eu.midnightdust.midnightcontrols.client.util.platform.NetworkUtil;
|
||||||
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.KeyboardLayoutManager;
|
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.KeyboardLayoutManager;
|
||||||
|
import net.minecraft.util.math.ColorHelper;
|
||||||
import org.thinkingstudio.obsidianui.background.Background;
|
import org.thinkingstudio.obsidianui.background.Background;
|
||||||
import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor;
|
|
||||||
import org.thinkingstudio.obsidianui.widget.SpruceWidget;
|
import org.thinkingstudio.obsidianui.widget.SpruceWidget;
|
||||||
import eu.midnightdust.lib.util.MidnightColorUtil;
|
|
||||||
import eu.midnightdust.midnightcontrols.MidnightControls;
|
import eu.midnightdust.midnightcontrols.MidnightControls;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.Controller;
|
import eu.midnightdust.midnightcontrols.client.controller.Controller;
|
||||||
@@ -37,18 +34,13 @@ import net.minecraft.client.MinecraftClient;
|
|||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
import net.minecraft.client.render.*;
|
|
||||||
import net.minecraft.client.resource.language.I18n;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.text.MutableText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import org.joml.Matrix4f;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the midnightcontrols settings screen.
|
* Represents the midnightcontrols settings screen.
|
||||||
*/
|
*/
|
||||||
@@ -507,7 +499,7 @@ public class MidnightControlsSettingsScreen extends SpruceScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderTitle(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void renderTitle(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||||
context.drawCenteredTextWithShadow(this.textRenderer, I18n.translate("midnightcontrols.menu.title"), this.width / 2, 8, 16777215);
|
context.drawCenteredTextWithShadow(this.textRenderer, I18n.translate("midnightcontrols.menu.title"), this.width / 2, 8, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MidnightControlsBackground implements Background {
|
public static class MidnightControlsBackground implements Background {
|
||||||
@@ -518,21 +510,7 @@ public class MidnightControlsSettingsScreen extends SpruceScreen {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) {
|
public void render(DrawContext context, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) {
|
||||||
fill(context, widget.getX(), widget.getY(), widget.getX() + widget.getWidth(), widget.getY() + widget.getHeight(), Color.black);
|
context.fill(widget.getX(), widget.getY(), widget.getX() + widget.getWidth(), widget.getY() + widget.getHeight(), ColorHelper.getArgb(transparency, 0, 0, 0));
|
||||||
}
|
|
||||||
private static void fill(DrawContext context, int x2, int y2, int x1, int y1, Color color) {
|
|
||||||
RenderLayer renderLayer = RenderLayer.getGui();
|
|
||||||
VertexConsumer vertexConsumer = ((DrawContextAccessor)context).getVertexConsumers().getBuffer(renderLayer);
|
|
||||||
|
|
||||||
float r = (float)(color.getRed()) / 255.0F;
|
|
||||||
float g = (float)(color.getGreen()) / 255.0F;
|
|
||||||
float b = (float)(color.getBlue()) / 255.0F;
|
|
||||||
float t = (float)(transparency) / 255.0F;
|
|
||||||
vertexConsumer.vertex((float)x1, (float)y2, 0.0F).color(r, g, b, t);
|
|
||||||
vertexConsumer.vertex((float)x2, (float)y2, 0.0F).color(r, g, b, t);
|
|
||||||
vertexConsumer.vertex((float)x2, (float)y1, 0.0F).color(r, g, b, t);
|
|
||||||
vertexConsumer.vertex((float)x1, (float)y1, 0.0F).color(r, g, b, t);
|
|
||||||
context.draw();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ package eu.midnightdust.midnightcontrols.client.gui;
|
|||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
||||||
import eu.midnightdust.midnightcontrols.client.ring.RingButtonMode;
|
import eu.midnightdust.midnightcontrols.client.ring.RingButtonMode;
|
||||||
import eu.midnightdust.midnightcontrols.client.ring.RingPage;
|
import eu.midnightdust.midnightcontrols.client.ring.RingPage;
|
||||||
|
import net.minecraft.client.gui.Click;
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
@@ -79,8 +80,8 @@ public class RingScreen extends Screen {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
public boolean mouseReleased(Click click) {
|
||||||
if (ring.getCurrentPage().onClick(width, height, (int) mouseX, (int) mouseY)) {
|
if (ring.getCurrentPage().onClick(width, height, (int) click.x(), (int) click.y())) {
|
||||||
this.close();
|
this.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package eu.midnightdust.midnightcontrols.client.gui.render;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.client.gui.ScreenRect;
|
||||||
|
import net.minecraft.client.gui.render.state.SimpleGuiElementRenderState;
|
||||||
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
|
import net.minecraft.client.texture.TextureSetup;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.joml.Matrix3x2f;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public record UnalignedTexturedQuadGuiElementRenderState(RenderPipeline pipeline, TextureSetup textureSetup, Matrix3x2f pose, float x1, float y1, float x2, float y2, float u1, float u2, float v1, float v2, int color, @Nullable ScreenRect scissorArea, @Nullable ScreenRect bounds) implements SimpleGuiElementRenderState {
|
||||||
|
public UnalignedTexturedQuadGuiElementRenderState(RenderPipeline pipeline, TextureSetup textureSetup, Matrix3x2f pose, float x1, float y1, float x2, float y2, float u1, float u2, float v1, float v2, int color, @Nullable ScreenRect scissorArea) {
|
||||||
|
this(pipeline, textureSetup, pose, x1, y1, x2, y2, u1, u2, v1, v2, color, scissorArea, createBounds(x1, y1, x2, y2, pose, scissorArea));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupVertices(VertexConsumer vertices) {
|
||||||
|
vertices.vertex(pose(), x1(), y1()).texture(u1(), v1()).color(color());
|
||||||
|
vertices.vertex(pose(), x1(), y2()).texture(u1(), v2()).color(color());
|
||||||
|
vertices.vertex(pose(), x2(), y2()).texture(u2(), v2()).color(color());
|
||||||
|
vertices.vertex(pose(), x2(), y1()).texture(u2(), v1()).color(color());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static ScreenRect createBounds(float x1, float y1, float x2, float y2, Matrix3x2f pose, @Nullable ScreenRect scissorArea) {
|
||||||
|
ScreenRect screenRect = (new ScreenRect((int) x1, (int) y1, (int) (x2 - x1), (int) (y2 - y1))).transformEachVertex(pose);
|
||||||
|
return scissorArea != null ? scissorArea.intersection(screenRect) : screenRect;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,7 +56,7 @@ public class ControllerControlsWidget extends SpruceContainerWidget {
|
|||||||
@Override
|
@Override
|
||||||
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||||
context.drawCenteredTextWithShadow(this.client.textRenderer, Text.translatable("midnightcontrols.menu.title.controller_controls"),
|
context.drawCenteredTextWithShadow(this.client.textRenderer, Text.translatable("midnightcontrols.menu.title.controller_controls"),
|
||||||
this.getX() + this.width / 2, this.getY() + 4, 16777215);
|
this.getX() + this.width / 2, this.getY() + 4, 0xFFFFFFFF);
|
||||||
this.resetButton.setActive(InputManager.streamBindings().anyMatch(Predicates.not(ButtonBinding::isDefault)));
|
this.resetButton.setActive(InputManager.streamBindings().anyMatch(Predicates.not(ButtonBinding::isDefault)));
|
||||||
super.renderWidget(context, mouseX, mouseY, delta);
|
super.renderWidget(context, mouseX, mouseY, delta);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
|||||||
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.ButtonCategory;
|
import eu.midnightdust.midnightcontrols.client.controller.ButtonCategory;
|
||||||
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
|
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
|
||||||
|
import net.minecraft.client.gl.RenderPipelines;
|
||||||
|
import net.minecraft.client.gui.Click;
|
||||||
|
import net.minecraft.client.input.KeyInput;
|
||||||
|
import net.minecraft.client.input.MouseInput;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
import net.minecraft.client.render.RenderLayer;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.thinkingstudio.obsidianui.Position;
|
import org.thinkingstudio.obsidianui.Position;
|
||||||
@@ -114,7 +118,7 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
|||||||
int size = 12;
|
int size = 12;
|
||||||
int x = this.getX() + this.getWidth() / 2 - size / 2;
|
int x = this.getX() + this.getWidth() / 2 - size / 2;
|
||||||
int y = this.getY() + this.getHeight() / 2 - size / 2;
|
int y = this.getY() + this.getHeight() / 2 - size / 2;
|
||||||
drawContext.drawGuiTexture(RenderLayer::getGuiTextured, resetTexture, x, y, size, size);
|
drawContext.drawGuiTexture(RenderPipelines.GUI_TEXTURED, resetTexture, x, y, size, size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -174,7 +178,7 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
element = it.next();
|
element = it.next();
|
||||||
} while (!element.mouseClicked(mouseX, mouseY, button));
|
} while (!element.mouseClicked(new Click(mouseX, mouseY, new MouseInput(button, 0)), false));
|
||||||
|
|
||||||
this.setFocused(element);
|
this.setFocused(element);
|
||||||
if (button == GLFW.GLFW_MOUSE_BUTTON_1)
|
if (button == GLFW.GLFW_MOUSE_BUTTON_1)
|
||||||
@@ -186,18 +190,18 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
|||||||
@Override
|
@Override
|
||||||
protected boolean onMouseRelease(double mouseX, double mouseY, int button) {
|
protected boolean onMouseRelease(double mouseX, double mouseY, int button) {
|
||||||
this.dragging = false;
|
this.dragging = false;
|
||||||
return this.hoveredElement(mouseX, mouseY).filter(element -> element.mouseReleased(mouseX, mouseY, button)).isPresent();
|
return this.hoveredElement(mouseX, mouseY).filter(element -> element.mouseReleased(new Click(mouseX, mouseY, new MouseInput(button, 0)))).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onMouseDrag(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
protected boolean onMouseDrag(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||||
return this.getFocused() != null && this.dragging && button == GLFW.GLFW_MOUSE_BUTTON_1
|
return this.getFocused() != null && this.dragging && button == GLFW.GLFW_MOUSE_BUTTON_1
|
||||||
&& this.getFocused().mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
&& this.getFocused().mouseDragged(new Click(mouseX, mouseY, new MouseInput(button, 0)), deltaX, deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onKeyPress(int keyCode, int scanCode, int modifiers) {
|
protected boolean onKeyPress(int keyCode, int scanCode, int modifiers) {
|
||||||
return this.focused != null && this.focused.keyPressed(keyCode, scanCode, modifiers);
|
return this.focused != null && this.focused.keyPressed(new KeyInput(keyCode, scanCode, modifiers));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Navigation */
|
/* Navigation */
|
||||||
@@ -247,7 +251,7 @@ public class ControlsListWidget extends SpruceEntryListWidget<ControlsListWidget
|
|||||||
int height = this.getHeight();
|
int height = this.getHeight();
|
||||||
//float textX = (float) (this.getX() + 70 - ControlsListWidget.this.maxTextLength);
|
//float textX = (float) (this.getX() + 70 - ControlsListWidget.this.maxTextLength);
|
||||||
int textY = this.getY() + height / 2;
|
int textY = this.getY() + height / 2;
|
||||||
context.drawText(textRenderer, this.bindingName, this.getX(), (textY - 9 / 2), 16777215, true);
|
context.drawText(textRenderer, this.bindingName, this.getX(), (textY - 9 / 2), 0xFFFFFFFF, true);
|
||||||
|
|
||||||
this.resetButton.setVisible(!focused);
|
this.resetButton.setVisible(!focused);
|
||||||
this.unbindButton.setVisible(focused);
|
this.unbindButton.setVisible(focused);
|
||||||
|
|||||||
@@ -1,28 +1,12 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.mixin;
|
package eu.midnightdust.midnightcontrols.client.mixin;
|
||||||
|
|
||||||
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
||||||
import net.minecraft.client.util.SelectionManager;
|
import net.minecraft.client.gui.widget.EditBoxWidget;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
|
||||||
|
|
||||||
@Mixin(BookEditScreen.class)
|
@Mixin(BookEditScreen.class)
|
||||||
public interface BookEditScreenAccessor {
|
public interface BookEditScreenAccessor {
|
||||||
@Accessor("signing")
|
@Accessor("editBox")
|
||||||
boolean midnightcontrols$isSigning();
|
EditBoxWidget midnightcontrols$getEditBox();
|
||||||
|
|
||||||
@Accessor("title")
|
|
||||||
String midnightcontrols$getTitle();
|
|
||||||
|
|
||||||
@Accessor("title")
|
|
||||||
void midnightcontrols$setTitle(String title);
|
|
||||||
|
|
||||||
@Accessor("currentPageSelectionManager")
|
|
||||||
SelectionManager midnightcontrols$getCurrentPageSelectionManager();
|
|
||||||
|
|
||||||
@Invoker("getCurrentPageContent")
|
|
||||||
String midnightcontrols$getCurrentPageContent();
|
|
||||||
|
|
||||||
@Invoker("setPageContent")
|
|
||||||
void midnightcontrols$setPageContent(String newContent);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package eu.midnightdust.midnightcontrols.client.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.screen.ingame.BookSigningScreen;
|
||||||
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(BookSigningScreen.class)
|
||||||
|
public interface BookSigningScreenAccessor {
|
||||||
|
@Accessor("bookTitleTextField")
|
||||||
|
TextFieldWidget midnightcontrols$getBookTitleTextField();
|
||||||
|
}
|
||||||
@@ -26,10 +26,10 @@ public abstract class ChatScreenMixin extends Screen {
|
|||||||
}
|
}
|
||||||
@Inject(method = "render", at = @At("HEAD"))
|
@Inject(method = "render", at = @At("HEAD"))
|
||||||
private void midnightcontrols$moveInputFieldBackground(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
private void midnightcontrols$moveInputFieldBackground(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||||
if (MidnightControlsConfig.moveChat) context.getMatrices().translate(0f, -this.height + 16, 0f);
|
if (MidnightControlsConfig.moveChat) context.getMatrices().translate(0f, -this.height + 16);
|
||||||
}
|
}
|
||||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;render(Lnet/minecraft/client/gui/DrawContext;IIF)V", shift = At.Shift.BEFORE))
|
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;fill(IIIII)V", shift = At.Shift.AFTER))
|
||||||
private void midnightcontrols$dontMoveOtherStuff(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
private void midnightcontrols$dontMoveOtherStuff(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
|
||||||
if (MidnightControlsConfig.moveChat) context.getMatrices().translate(0f, this.height - 16, 0f);
|
if (MidnightControlsConfig.moveChat) context.getMatrices().translate(0f, this.height - 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,15 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.mixin;
|
package eu.midnightdust.midnightcontrols.client.mixin;
|
||||||
|
|
||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.render.VertexConsumerProvider;
|
import net.minecraft.client.gui.render.state.GuiRenderState;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
@Mixin(DrawContext.class)
|
@Mixin(DrawContext.class)
|
||||||
public interface DrawContextAccessor {
|
public interface DrawContextAccessor {
|
||||||
@Accessor("vertexConsumers")
|
@Accessor("state")
|
||||||
VertexConsumerProvider.Immediate getVertexConsumers();
|
GuiRenderState getState();
|
||||||
|
|
||||||
|
@Accessor("scissorStack")
|
||||||
|
DrawContext.ScissorStack getScissorStack();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,16 +37,16 @@ public abstract class GameRendererMixin {
|
|||||||
if (this.client.currentScreen != null && MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER)
|
if (this.client.currentScreen != null && MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER)
|
||||||
MidnightControlsClient.input.onPreRenderScreen(this.client.currentScreen);
|
MidnightControlsClient.input.onPreRenderScreen(this.client.currentScreen);
|
||||||
}
|
}
|
||||||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;draw()V", shift = At.Shift.BEFORE))
|
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;renderWithTooltip(Lnet/minecraft/client/gui/DrawContext;IIF)V", shift = At.Shift.AFTER))
|
||||||
private void midnightcontrols$renderVirtualCursor(RenderTickCounter tickCounter, boolean tick, CallbackInfo ci, @Local DrawContext drawContext) {
|
private void midnightcontrols$renderVirtualCursor(RenderTickCounter tickCounter, boolean tick, CallbackInfo ci, @Local DrawContext drawContext) {
|
||||||
MidnightControlsRenderer.renderVirtualCursor(drawContext, client);
|
MidnightControlsRenderer.renderVirtualCursor(drawContext, client);
|
||||||
if (MidnightControlsClient.isWayland) MidnightControlsRenderer.renderWaylandCursor(drawContext, client);
|
if (MidnightControlsClient.isWayland) MidnightControlsRenderer.renderWaylandCursor(drawContext, client);
|
||||||
drawContext.draw();
|
//drawContext.draw();
|
||||||
}
|
}
|
||||||
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/GameRenderer;renderHand:Z"), method = "renderWorld")
|
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;renderHand(FZLorg/joml/Matrix4f;)V"), method = "renderWorld")
|
||||||
private void midnigtcontrols$captureMatrices(RenderTickCounter tickCounter, CallbackInfo ci, @Local(ordinal = 2) Matrix4f matrices) {
|
private void midnigtcontrols$captureMatrices(RenderTickCounter tickCounter, CallbackInfo ci, @Local(ordinal = 1) Matrix4f projectionMatrix, @Local(ordinal = 1) Matrix4f worldSpaceMatrix) {
|
||||||
TouchUtils.lastProjMat.set(RenderSystem.getProjectionMatrix());
|
TouchUtils.lastProjMat.set(projectionMatrix);
|
||||||
TouchUtils.lastModMat.set(RenderSystem.getModelViewMatrix());
|
TouchUtils.lastModMat.set(RenderSystem.getModelViewMatrix());
|
||||||
TouchUtils.lastWorldSpaceMatrix.set(matrices);
|
TouchUtils.lastWorldSpaceMatrix.set(worldSpaceMatrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public abstract class HandledScreenMixin implements HandledScreenAccessor {
|
|||||||
public abstract Slot midnightcontrols$getSlotAt(double posX, double posY);
|
public abstract Slot midnightcontrols$getSlotAt(double posX, double posY);
|
||||||
|
|
||||||
@Invoker("isClickOutsideBounds")
|
@Invoker("isClickOutsideBounds")
|
||||||
public abstract boolean midnightcontrols$isClickOutsideBounds(double mouseX, double mouseY, int x, int y, int button);
|
public abstract boolean midnightcontrols$isClickOutsideBounds(double mouseX, double mouseY, int left, int top);
|
||||||
|
|
||||||
|
|
||||||
@Invoker("onMouseClick")
|
@Invoker("onMouseClick")
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package eu.midnightdust.midnightcontrols.client.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.Keyboard;
|
||||||
|
import net.minecraft.client.input.KeyInput;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
@Mixin(Keyboard.class)
|
||||||
|
public interface KeyboardAccessor {
|
||||||
|
@Invoker("onKey")
|
||||||
|
void midnightcontrols$onKey(long window, int action, KeyInput input);
|
||||||
|
}
|
||||||
@@ -77,7 +77,7 @@ public abstract class MinecraftClientMixin {
|
|||||||
if (!MidnightControlsFeature.FAST_BLOCK_PLACING.isAvailable())
|
if (!MidnightControlsFeature.FAST_BLOCK_PLACING.isAvailable())
|
||||||
return;
|
return;
|
||||||
if (this.midnightcontrols$lastPos == null)
|
if (this.midnightcontrols$lastPos == null)
|
||||||
this.midnightcontrols$lastPos = this.player.getPos();
|
this.midnightcontrols$lastPos = this.player.getEntityPos();
|
||||||
|
|
||||||
int cooldown = this.itemUseCooldown;
|
int cooldown = this.itemUseCooldown;
|
||||||
BlockHitResult hitResult;
|
BlockHitResult hitResult;
|
||||||
@@ -106,7 +106,7 @@ public abstract class MinecraftClientMixin {
|
|||||||
// this.itemUseCooldown = 0;
|
// this.itemUseCooldown = 0;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
this.midnightcontrols$lastPos = this.player.getPos();
|
this.midnightcontrols$lastPos = this.player.getEntityPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "setScreen")
|
@Inject(at = @At("TAIL"), method = "setScreen")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.mixin;
|
package eu.midnightdust.midnightcontrols.client.mixin;
|
||||||
|
|
||||||
import net.minecraft.client.Mouse;
|
import net.minecraft.client.Mouse;
|
||||||
|
import net.minecraft.client.input.MouseInput;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
@@ -9,5 +10,5 @@ public interface MouseAccessor {
|
|||||||
@Invoker("onCursorPos")
|
@Invoker("onCursorPos")
|
||||||
void midnightcontrols$onCursorPos(long window, double x, double y);
|
void midnightcontrols$onCursorPos(long window, double x, double y);
|
||||||
@Invoker("onMouseButton")
|
@Invoker("onMouseButton")
|
||||||
void midnightcontrols$onMouseButton(long window, int button, int action, int mods);
|
void midnightcontrols$onMouseButton(long window, MouseInput input, int action);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import eu.midnightdust.midnightcontrols.client.touch.TouchInput;
|
|||||||
import eu.midnightdust.midnightcontrols.client.touch.TouchUtils;
|
import eu.midnightdust.midnightcontrols.client.touch.TouchUtils;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.Mouse;
|
import net.minecraft.client.Mouse;
|
||||||
|
import net.minecraft.client.gui.Click;
|
||||||
|
import net.minecraft.client.input.MouseInput;
|
||||||
import net.minecraft.client.util.GlfwUtil;
|
import net.minecraft.client.util.GlfwUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ThrowablePotionItem;
|
import net.minecraft.item.ThrowablePotionItem;
|
||||||
@@ -64,12 +66,12 @@ public abstract class MouseMixin implements MouseAccessor {
|
|||||||
@Shadow private boolean leftButtonClicked;
|
@Shadow private boolean leftButtonClicked;
|
||||||
|
|
||||||
@Inject(method = "onMouseButton", at = @At(value = "HEAD"), cancellable = true)
|
@Inject(method = "onMouseButton", at = @At(value = "HEAD"), cancellable = true)
|
||||||
private void midnightcontrols$onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) {
|
private void midnightcontrols$onMouseButton(long window, MouseInput input, int action, CallbackInfo ci) {
|
||||||
if (window != this.client.getWindow().getHandle()) return;
|
if (window != this.client.getWindow().getHandle()) return;
|
||||||
if (action == 1 && button == GLFW.GLFW_MOUSE_BUTTON_4 && client.currentScreen != null) {
|
if (action == 1 && input.button() == GLFW.GLFW_MOUSE_BUTTON_4 && client.currentScreen != null) {
|
||||||
MidnightControlsClient.input.tryGoBack(client.currentScreen);
|
MidnightControlsClient.input.tryGoBack(client.currentScreen);
|
||||||
}
|
}
|
||||||
else if ((client.currentScreen == null && doMixedInput() || client.currentScreen instanceof TouchscreenOverlay) && client.player != null && button == GLFW_MOUSE_BUTTON_1) {
|
else if ((client.currentScreen == null && doMixedInput() || client.currentScreen instanceof TouchscreenOverlay) && client.player != null && input.button() == GLFW_MOUSE_BUTTON_1) {
|
||||||
double mouseX = x / client.getWindow().getScaleFactor();
|
double mouseX = x / client.getWindow().getScaleFactor();
|
||||||
double mouseY = y / client.getWindow().getScaleFactor();
|
double mouseY = y / client.getWindow().getScaleFactor();
|
||||||
int centerX = client.getWindow().getScaledWidth() / 2;
|
int centerX = client.getWindow().getScaledWidth() / 2;
|
||||||
@@ -87,11 +89,11 @@ public abstract class MouseMixin implements MouseAccessor {
|
|||||||
if (action == 1) {
|
if (action == 1) {
|
||||||
TouchInput.clickStartTime = System.currentTimeMillis();
|
TouchInput.clickStartTime = System.currentTimeMillis();
|
||||||
boolean bl = false;
|
boolean bl = false;
|
||||||
if (client.currentScreen instanceof TouchscreenOverlay overlay) bl = overlay.mouseClicked(mouseX, mouseY, button);
|
if (client.currentScreen instanceof TouchscreenOverlay overlay) bl = overlay.mouseClicked(new Click(mouseX, mouseY, input), false);
|
||||||
if (!bl) TouchInput.firstHitResult = TouchUtils.getTargetedObject(mouseX, mouseY);
|
if (!bl) TouchInput.firstHitResult = TouchUtils.getTargetedObject(mouseX, mouseY);
|
||||||
if (client.currentScreen == null) ci.cancel();
|
if (client.currentScreen == null) ci.cancel();
|
||||||
}
|
}
|
||||||
else if (TouchInput.mouseReleased(mouseX, mouseY, button)) ci.cancel();
|
else if (TouchInput.mouseReleased(mouseX, mouseY, input.button())) ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +142,7 @@ public abstract class MouseMixin implements MouseAccessor {
|
|||||||
stack.getUseAction() == UseAction.SPEAR || stack.getItem() instanceof ThrowablePotionItem));
|
stack.getUseAction() == UseAction.SPEAR || stack.getItem() instanceof ThrowablePotionItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "lockCursor", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/InputUtil;setCursorParameters(JIDD)V",shift = At.Shift.BEFORE), cancellable = true)
|
@Inject(method = "lockCursor", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/InputUtil;setCursorParameters(Lnet/minecraft/client/util/Window;IDD)V",shift = At.Shift.BEFORE), cancellable = true)
|
||||||
private void midnightcontrols$lockCursor(CallbackInfo ci) {
|
private void midnightcontrols$lockCursor(CallbackInfo ci) {
|
||||||
if ((doMixedInput() || MidnightControlsConfig.eyeTrackerAsMouse)) {
|
if ((doMixedInput() || MidnightControlsConfig.eyeTrackerAsMouse)) {
|
||||||
//In eye tracking mode, we cannot have the cursor locked to the center.
|
//In eye tracking mode, we cannot have the cursor locked to the center.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import eu.midnightdust.midnightcontrols.client.util.RainbowColor;
|
|||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.*;
|
import net.minecraft.client.render.*;
|
||||||
|
import net.minecraft.client.render.state.WorldRenderState;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.client.world.ClientWorld;
|
import net.minecraft.client.world.ClientWorld;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
@@ -58,24 +59,23 @@ public abstract class WorldRendererMixin {
|
|||||||
@Final
|
@Final
|
||||||
private BufferBuilderStorage bufferBuilders;
|
private BufferBuilderStorage bufferBuilders;
|
||||||
|
|
||||||
@Redirect(method = "renderTargetBlockOutline", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/hit/BlockHitResult;getType()Lnet/minecraft/util/hit/HitResult$Type;"))
|
@Inject(method = "renderTargetBlockOutline", at = @At("HEAD"), cancellable = true)
|
||||||
private HitResult.Type dontRenderOutline(BlockHitResult instance) {
|
private void dontRenderOutline(VertexConsumerProvider.Immediate immediate, MatrixStack matrices, boolean renderBlockOutline, WorldRenderState renderStates, CallbackInfo ci) {
|
||||||
if (MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN && MidnightControlsConfig.touchMode == TouchMode.FINGER_POS) {
|
if (MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN && MidnightControlsConfig.touchMode == TouchMode.FINGER_POS) {
|
||||||
return HitResult.Type.MISS;
|
ci.cancel();
|
||||||
}
|
}
|
||||||
return instance.getType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "renderTargetBlockOutline",
|
method = "renderTargetBlockOutline",
|
||||||
at = @At("HEAD")
|
at = @At("HEAD")
|
||||||
)
|
)
|
||||||
private void onOutlineRender(Camera camera, VertexConsumerProvider.Immediate vertexConsumers, MatrixStack matrices, boolean translucent, CallbackInfo ci) {
|
private void onOutlineRender(VertexConsumerProvider.Immediate immediate, MatrixStack matrices, boolean renderBlockOutline, WorldRenderState renderStates, CallbackInfo ci) {
|
||||||
if (((MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && MidnightControlsConfig.touchInControllerMode) || MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN)
|
if (((MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && MidnightControlsConfig.touchInControllerMode) || MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN)
|
||||||
&& MidnightControlsConfig.touchMode == TouchMode.FINGER_POS) {
|
&& MidnightControlsConfig.touchMode == TouchMode.FINGER_POS) {
|
||||||
this.midnightcontrols$renderFingerOutline(matrices, camera);
|
this.midnightcontrols$renderFingerOutline(matrices, client.gameRenderer.getCamera());
|
||||||
}
|
}
|
||||||
this.midnightcontrols$renderReacharoundOutline(matrices, camera);
|
this.midnightcontrols$renderReacharoundOutline(matrices, client.gameRenderer.getCamera());
|
||||||
}
|
}
|
||||||
@Unique
|
@Unique
|
||||||
private void midnightcontrols$renderFingerOutline(MatrixStack matrices, Camera camera) {
|
private void midnightcontrols$renderFingerOutline(MatrixStack matrices, Camera camera) {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class EyeTrackerHandler {
|
|||||||
// The player entity's needs their facing rotated.
|
// The player entity's needs their facing rotated.
|
||||||
double invertY = 1.0;
|
double invertY = 1.0;
|
||||||
double moveMagnitude = Math.sqrt(normalizedX*normalizedX + normalizedY*normalizedY);
|
double moveMagnitude = Math.sqrt(normalizedX*normalizedX + normalizedY*normalizedY);
|
||||||
if (client.options.getInvertYMouse().getValue()) {
|
if (client.options.getInvertMouseY().getValue()) {
|
||||||
invertY = -1.0;
|
invertY = -1.0;
|
||||||
}
|
}
|
||||||
boolean notInDeadzone = (moveMagnitude > MidnightControlsConfig.eyeTrackerDeadzone) && !usingLongRangedTool;
|
boolean notInDeadzone = (moveMagnitude > MidnightControlsConfig.eyeTrackerDeadzone) && !usingLongRangedTool;
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
|||||||
import eu.midnightdust.midnightcontrols.client.touch.gui.TouchscreenOverlay;
|
import eu.midnightdust.midnightcontrols.client.touch.gui.TouchscreenOverlay;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.Click;
|
||||||
|
import net.minecraft.client.input.MouseInput;
|
||||||
|
import net.minecraft.client.particle.BlockDustParticle;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
@@ -46,7 +49,7 @@ public class TouchInput {
|
|||||||
if (result instanceof BlockHitResult blockHit && firstHitResult instanceof BlockHitResult firstBlock && blockHit.getBlockPos().equals(firstBlock.getBlockPos())) {
|
if (result instanceof BlockHitResult blockHit && firstHitResult instanceof BlockHitResult firstBlock && blockHit.getBlockPos().equals(firstBlock.getBlockPos())) {
|
||||||
if (MidnightControlsConfig.debug) System.out.println(blockHit.getBlockPos().toString());
|
if (MidnightControlsConfig.debug) System.out.println(blockHit.getBlockPos().toString());
|
||||||
if (client.interactionManager.updateBlockBreakingProgress(blockHit.getBlockPos(), blockHit.getSide())) {
|
if (client.interactionManager.updateBlockBreakingProgress(blockHit.getBlockPos(), blockHit.getSide())) {
|
||||||
client.particleManager.addBlockBreakingParticles(blockHit.getBlockPos(), blockHit.getSide());
|
//client.particleManager.addBlockBreakingParticles(blockHit.getBlockPos(), blockHit.getSide()); // TODO Re-implement block breaking particles!!!
|
||||||
client.player.swingHand(Hand.MAIN_HAND);
|
client.player.swingHand(Hand.MAIN_HAND);
|
||||||
} else client.interactionManager.cancelBlockBreaking();
|
} else client.interactionManager.cancelBlockBreaking();
|
||||||
firstHitResult = TouchUtils.getTargetedObject(mouseX, mouseY);
|
firstHitResult = TouchUtils.getTargetedObject(mouseX, mouseY);
|
||||||
@@ -62,7 +65,7 @@ public class TouchInput {
|
|||||||
isDragging = false;
|
isDragging = false;
|
||||||
firstHitResult = null;
|
firstHitResult = null;
|
||||||
if (client.interactionManager != null) client.interactionManager.cancelBlockBreaking();
|
if (client.interactionManager != null) client.interactionManager.cancelBlockBreaking();
|
||||||
if ((client.currentScreen == null || !client.currentScreen.mouseReleased(mouseX, mouseY, button)) && System.currentTimeMillis() - clickStartTime < MidnightControlsConfig.touchBreakDelay) {
|
if ((client.currentScreen == null || !client.currentScreen.mouseReleased(new Click(mouseX, mouseY, new MouseInput(button, 0)))) && System.currentTimeMillis() - clickStartTime < MidnightControlsConfig.touchBreakDelay) {
|
||||||
assert client.player != null;
|
assert client.player != null;
|
||||||
assert client.world != null;
|
assert client.world != null;
|
||||||
assert client.interactionManager != null;
|
assert client.interactionManager != null;
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ public class TouchUtils {
|
|||||||
Vec3d far = screenSpaceToWorldSpace(mouseX, mouseY, 1);
|
Vec3d far = screenSpaceToWorldSpace(mouseX, mouseY, 1);
|
||||||
|
|
||||||
float playerRange = getPlayerRange(client);
|
float playerRange = getPlayerRange(client);
|
||||||
EntityHitResult entityCast = ProjectileUtil.raycast(client.player, near, far, Box.from(client.player.getPos()).expand(playerRange), entity -> (!entity.isSpectator() && entity.isAttackable()), playerRange * playerRange);
|
EntityHitResult entityCast = ProjectileUtil.raycast(client.player, near, far, Box.from(client.player.getEntityPos()).expand(playerRange), entity -> (!entity.isSpectator() && entity.isAttackable()), playerRange * playerRange);
|
||||||
|
|
||||||
if (entityCast != null && entityCast.getType() == HitResult.Type.ENTITY) return entityCast;
|
if (entityCast != null && entityCast.getType() == HitResult.Type.ENTITY) return entityCast;
|
||||||
|
|
||||||
BlockHitResult result = client.world.raycast(new RaycastContext(near, far, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, client.player));
|
BlockHitResult result = client.world.raycast(new RaycastContext(near, far, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, client.player));
|
||||||
|
|
||||||
if (client.player.getPos().distanceTo(result.getPos()) > playerRange) return null;
|
if (client.player.getEntityPos().distanceTo(result.getPos()) > playerRange) return null;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,17 @@
|
|||||||
|
|
||||||
package eu.midnightdust.midnightcontrols.client.touch.gui;
|
package eu.midnightdust.midnightcontrols.client.touch.gui;
|
||||||
|
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.KeyBindingIDAccessor;
|
|
||||||
import eu.midnightdust.midnightcontrols.client.touch.TouchInput;
|
import eu.midnightdust.midnightcontrols.client.touch.TouchInput;
|
||||||
import eu.midnightdust.midnightcontrols.client.util.storage.AxisStorage;
|
import eu.midnightdust.midnightcontrols.client.util.storage.AxisStorage;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.gui.Click;
|
||||||
import net.minecraft.client.gui.screen.ChatScreen;
|
import net.minecraft.client.gui.screen.ChatScreen;
|
||||||
import net.minecraft.client.gui.screen.GameMenuScreen;
|
import net.minecraft.client.gui.screen.GameMenuScreen;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.util.SpriteIdentifier;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.item.consume.UseAction;
|
import net.minecraft.item.consume.UseAction;
|
||||||
import net.minecraft.util.Arm;
|
import net.minecraft.util.Arm;
|
||||||
|
import net.minecraft.util.Atlases;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.thinkingstudio.obsidianui.Position;
|
import org.thinkingstudio.obsidianui.Position;
|
||||||
@@ -36,10 +37,8 @@ import eu.midnightdust.midnightcontrols.client.util.KeyBindingAccessor;
|
|||||||
import net.minecraft.client.gui.DrawContext;
|
import net.minecraft.client.gui.DrawContext;
|
||||||
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
|
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
|
||||||
import net.minecraft.client.gui.widget.TextIconButtonWidget;
|
import net.minecraft.client.gui.widget.TextIconButtonWidget;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
|
||||||
import net.minecraft.client.texture.MissingSprite;
|
import net.minecraft.client.texture.MissingSprite;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.client.util.InputUtil;
|
|
||||||
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -94,7 +93,7 @@ public class TouchscreenOverlay extends Screen {
|
|||||||
assert this.client != null;
|
assert this.client != null;
|
||||||
this.client.setScreen(new GameMenuScreen(true));
|
this.client.setScreen(new GameMenuScreen(true));
|
||||||
if (this.client.isIntegratedServerRunning() && !Objects.requireNonNull(this.client.getServer()).isRemote()) {
|
if (this.client.isIntegratedServerRunning() && !Objects.requireNonNull(this.client.getServer()).isRemote()) {
|
||||||
this.client.getSoundManager().pauseAll();
|
this.client.getSoundManager().pauseAllExcept();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +173,7 @@ public class TouchscreenOverlay extends Screen {
|
|||||||
this.addDrawableChild(emoteButton);
|
this.addDrawableChild(emoteButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextIconButtonWidget chatButton = TextIconButtonWidget.builder(Text.empty(), btn -> this.client.setScreen(new ChatScreen("")), true).width(20).texture(id("touch/chat"), 20, 20).build();
|
TextIconButtonWidget chatButton = TextIconButtonWidget.builder(Text.empty(), btn -> this.client.setScreen(new ChatScreen("", true)), true).width(20).texture(id("touch/chat"), 20, 20).build();
|
||||||
chatButton.setPosition(scaledWidth / 2 - 20 + emoteOffset, 0);
|
chatButton.setPosition(scaledWidth / 2 - 20 + emoteOffset, 0);
|
||||||
this.addDrawableChild(chatButton);
|
this.addDrawableChild(chatButton);
|
||||||
TextIconButtonWidget pauseButton = TextIconButtonWidget.builder(Text.empty(), btn -> this.pauseGame(), true).width(20).texture(id("touch/pause"), 20, 20).build();
|
TextIconButtonWidget pauseButton = TextIconButtonWidget.builder(Text.empty(), btn -> this.pauseGame(), true).width(20).texture(id("touch/pause"), 20, 20).build();
|
||||||
@@ -293,12 +292,12 @@ public class TouchscreenOverlay extends Screen {
|
|||||||
assert client != null;
|
assert client != null;
|
||||||
Identifier emptySprite = id("touch/empty");
|
Identifier emptySprite = id("touch/empty");
|
||||||
List<String> list = left ? MidnightControlsConfig.leftTouchBinds : MidnightControlsConfig.rightTouchBinds;
|
List<String> list = left ? MidnightControlsConfig.leftTouchBinds : MidnightControlsConfig.rightTouchBinds;
|
||||||
Sprite missingSprite = client.getGuiAtlasManager().getSprite(MissingSprite.getMissingSpriteId());
|
Sprite missingSprite = client.getAtlasManager().getAtlasTexture(Atlases.GUI).getMissingSprite();
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
String bindName = list.get(i);
|
String bindName = list.get(i);
|
||||||
ButtonBinding binding = InputManager.getBinding(bindName);
|
ButtonBinding binding = InputManager.getBinding(bindName);
|
||||||
if (binding == null) continue;
|
if (binding == null) continue;
|
||||||
boolean hasTexture = client.getGuiAtlasManager().getSprite(id("binding/"+bindName)) != missingSprite;
|
boolean hasTexture = client.getAtlasManager().getAtlasTexture(Atlases.GUI).getSprite(id("binding/"+bindName)) != missingSprite;
|
||||||
if (MidnightControlsConfig.debug) System.out.println(left +" "+id("binding/"+bindName)+" "+ hasTexture);
|
if (MidnightControlsConfig.debug) System.out.println(left +" "+id("binding/"+bindName)+" "+ hasTexture);
|
||||||
var button = TextIconButtonWidget.builder(Text.translatable(binding.getTranslationKey()), b -> {
|
var button = TextIconButtonWidget.builder(Text.translatable(binding.getTranslationKey()), b -> {
|
||||||
binding.handle(client, 1.0f, ButtonState.PRESS);
|
binding.handle(client, 1.0f, ButtonState.PRESS);
|
||||||
@@ -353,8 +352,8 @@ public class TouchscreenOverlay extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
public boolean mouseDragged(Click click, double deltaX, double deltaY) {
|
||||||
if (button == GLFW.GLFW_MOUSE_BUTTON_1 && this.client != null) {
|
if (click.button() == GLFW.GLFW_MOUSE_BUTTON_1 && this.client != null) {
|
||||||
if (TouchInput.isDragging) {
|
if (TouchInput.isDragging) {
|
||||||
if (!MidnightControlsConfig.invertTouch) {
|
if (!MidnightControlsConfig.invertTouch) {
|
||||||
deltaX = -deltaX;
|
deltaX = -deltaX;
|
||||||
@@ -365,6 +364,6 @@ public class TouchscreenOverlay extends Screen {
|
|||||||
}
|
}
|
||||||
else TouchInput.isDragging = true;
|
else TouchInput.isDragging = true;
|
||||||
}
|
}
|
||||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
return super.mouseDragged(click, deltaX, deltaY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public interface HandledScreenAccessor {
|
|||||||
*/
|
*/
|
||||||
Slot midnightcontrols$getSlotAt(double posX, double posY);
|
Slot midnightcontrols$getSlotAt(double posX, double posY);
|
||||||
|
|
||||||
boolean midnightcontrols$isClickOutsideBounds(double mouseX, double mouseY, int x, int y, int button);
|
boolean midnightcontrols$isClickOutsideBounds(double mouseX, double mouseY, int left, int top);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a mouse click on the specified slot.
|
* Handles a mouse click on the specified slot.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.util.platform;
|
package eu.midnightdust.midnightcontrols.client.util.platform;
|
||||||
|
|
||||||
import dev.architectury.injectables.annotations.ExpectPlatform;
|
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||||
|
import eu.midnightdust.midnightcontrols.client.MidnightInput;
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.CreativeInventoryScreenAccessor;
|
import eu.midnightdust.midnightcontrols.client.mixin.CreativeInventoryScreenAccessor;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
|
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
|
||||||
@@ -11,6 +12,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static eu.midnightdust.midnightcontrols.client.MidnightInput.ENTER_KEY_INPUT;
|
||||||
|
|
||||||
public class ItemGroupUtil {
|
public class ItemGroupUtil {
|
||||||
@ExpectPlatform
|
@ExpectPlatform
|
||||||
public static List<ItemGroup> getVisibleGroups(CreativeInventoryScreen screen) {
|
public static List<ItemGroup> getVisibleGroups(CreativeInventoryScreen screen) {
|
||||||
@@ -24,10 +27,10 @@ public class ItemGroupUtil {
|
|||||||
.filter(element -> element.getMessage() != null && element.getMessage().getContent() != null)
|
.filter(element -> element.getMessage() != null && element.getMessage().getContent() != null)
|
||||||
.anyMatch(element -> {
|
.anyMatch(element -> {
|
||||||
if (next && element.getMessage().getString().equals(">")) {
|
if (next && element.getMessage().getString().equals(">")) {
|
||||||
element.onPress();
|
element.onPress(ENTER_KEY_INPUT);
|
||||||
return true;
|
return true;
|
||||||
} else if (element.getMessage().getString().equals("<")) {
|
} else if (element.getMessage().getString().equals("<")) {
|
||||||
element.onPress();
|
element.onPress(ENTER_KEY_INPUT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler.Abst
|
|||||||
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler.BookEditScreenClickHandler;
|
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler.BookEditScreenClickHandler;
|
||||||
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler.DefaultScreenClickHandler;
|
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler.DefaultScreenClickHandler;
|
||||||
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler.SignEditScreenClickHandler;
|
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler.SignEditScreenClickHandler;
|
||||||
|
import net.minecraft.client.gui.Click;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
||||||
|
import net.minecraft.client.gui.screen.ingame.BookSigningScreen;
|
||||||
import net.minecraft.client.gui.screen.ingame.SignEditScreen;
|
import net.minecraft.client.gui.screen.ingame.SignEditScreen;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -18,19 +20,20 @@ public class MouseClickInterceptor {
|
|||||||
|
|
||||||
public MouseClickInterceptor() {
|
public MouseClickInterceptor() {
|
||||||
this.clickHandlers = new HashMap<>();
|
this.clickHandlers = new HashMap<>();
|
||||||
|
this.clickHandlers.put(BookSigningScreen.class, new BookEditScreenClickHandler.Signing());
|
||||||
this.clickHandlers.put(BookEditScreen.class, new BookEditScreenClickHandler());
|
this.clickHandlers.put(BookEditScreen.class, new BookEditScreenClickHandler());
|
||||||
this.clickHandlers.put(SignEditScreen.class, new SignEditScreenClickHandler());
|
this.clickHandlers.put(SignEditScreen.class, new SignEditScreenClickHandler());
|
||||||
this.clickHandlers.put(Screen.class, new DefaultScreenClickHandler());
|
this.clickHandlers.put(Screen.class, new DefaultScreenClickHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Screen> void intercept(T screen, double mouseX, double mouseY) {
|
public <T extends Screen> void intercept(T screen, Click click) {
|
||||||
AbstractScreenClickHandler<T> handler = (AbstractScreenClickHandler<T>) clickHandlers.get(screen.getClass());
|
AbstractScreenClickHandler<T> handler = (AbstractScreenClickHandler<T>) clickHandlers.get(screen.getClass());
|
||||||
|
|
||||||
if (handler == null) {
|
if (handler == null) {
|
||||||
handler = (AbstractScreenClickHandler<T>) clickHandlers.get(Screen.class);
|
handler = (AbstractScreenClickHandler<T>) clickHandlers.get(Screen.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.handle(screen, mouseX, mouseY);
|
handler.handle(screen, click.x(), click.y());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler;
|
package eu.midnightdust.midnightcontrols.client.virtualkeyboard.clickhandler;
|
||||||
|
|
||||||
import eu.midnightdust.midnightcontrols.client.mixin.BookEditScreenAccessor;
|
import eu.midnightdust.midnightcontrols.client.mixin.BookEditScreenAccessor;
|
||||||
|
import eu.midnightdust.midnightcontrols.client.mixin.BookSigningScreenAccessor;
|
||||||
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.gui.VirtualKeyboardScreen;
|
import eu.midnightdust.midnightcontrols.client.virtualkeyboard.gui.VirtualKeyboardScreen;
|
||||||
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
|
||||||
|
import net.minecraft.client.gui.screen.ingame.BookSigningScreen;
|
||||||
|
import net.minecraft.client.gui.widget.EditBoxWidget;
|
||||||
|
|
||||||
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
|
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
|
||||||
|
|
||||||
@@ -10,27 +13,35 @@ public class BookEditScreenClickHandler extends AbstractScreenClickHandler<BookE
|
|||||||
@Override
|
@Override
|
||||||
public void handle(BookEditScreen screen, double mouseX, double mouseY) {
|
public void handle(BookEditScreen screen, double mouseX, double mouseY) {
|
||||||
// don't open the keyboard if a UI element was clicked
|
// don't open the keyboard if a UI element was clicked
|
||||||
if(screen.hoveredElement(mouseX, mouseY).isPresent()) {
|
if(screen.hoveredElement(mouseX, mouseY).isPresent() && !(screen.hoveredElement(mouseX, mouseY).get() instanceof EditBoxWidget)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var accessor = (BookEditScreenAccessor) screen;
|
var accessor = (BookEditScreenAccessor) screen;
|
||||||
|
|
||||||
VirtualKeyboardScreen virtualKeyboardScreen;
|
VirtualKeyboardScreen virtualKeyboardScreen = new VirtualKeyboardScreen(accessor.midnightcontrols$getEditBox().getText(), (text) -> {
|
||||||
if(accessor.midnightcontrols$isSigning()) {
|
|
||||||
virtualKeyboardScreen = new VirtualKeyboardScreen(accessor.midnightcontrols$getTitle(), (text) -> {
|
|
||||||
client.setScreen(screen);
|
client.setScreen(screen);
|
||||||
accessor.midnightcontrols$setTitle(text);
|
accessor.midnightcontrols$getEditBox().setText(text);
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
client.setScreen(virtualKeyboardScreen);
|
||||||
}
|
}
|
||||||
else {
|
public static class Signing extends AbstractScreenClickHandler<BookSigningScreen> {
|
||||||
virtualKeyboardScreen = new VirtualKeyboardScreen(accessor.midnightcontrols$getCurrentPageContent(), (text) -> {
|
@Override
|
||||||
|
public void handle(BookSigningScreen screen, double mouseX, double mouseY) {
|
||||||
|
// don't open the keyboard if a UI element was clicked
|
||||||
|
if(screen.hoveredElement(mouseX, mouseY).isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var accessor = (BookSigningScreenAccessor) screen;
|
||||||
|
|
||||||
|
VirtualKeyboardScreen virtualKeyboardScreen = new VirtualKeyboardScreen(accessor.midnightcontrols$getBookTitleTextField().getText(), (text) -> {
|
||||||
client.setScreen(screen);
|
client.setScreen(screen);
|
||||||
accessor.midnightcontrols$setPageContent(text);
|
accessor.midnightcontrols$getBookTitleTextField().setText(text);
|
||||||
accessor.midnightcontrols$getCurrentPageSelectionManager().putCursorAtEnd();
|
}, false);
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
client.setScreen(virtualKeyboardScreen);
|
client.setScreen(virtualKeyboardScreen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
|
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.client;
|
||||||
|
import static eu.midnightdust.midnightcontrols.client.MidnightInput.ENTER_KEY_INPUT;
|
||||||
|
|
||||||
public class DefaultScreenClickHandler extends AbstractScreenClickHandler<Screen> {
|
public class DefaultScreenClickHandler extends AbstractScreenClickHandler<Screen> {
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class DefaultScreenClickHandler extends AbstractScreenClickHandler<Screen
|
|||||||
}
|
}
|
||||||
case ChatScreen chatScreen -> {
|
case ChatScreen chatScreen -> {
|
||||||
// send the chat message
|
// send the chat message
|
||||||
chatScreen.keyPressed(GLFW.GLFW_KEY_ENTER, 0, 0);
|
chatScreen.keyPressed(ENTER_KEY_INPUT);
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,12 +74,6 @@ public class VirtualKeyboardScreen extends SpruceScreen {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
|
|
||||||
this.renderBackground(drawContext, mouseX, mouseY, delta);
|
|
||||||
super.render(drawContext, mouseX, mouseY, delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldPause() {
|
public boolean shouldPause() {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
accessWidener v1 named
|
accessWidener v1 named
|
||||||
|
|
||||||
#accessible class net/minecraft/client/gui/widget/EntryListWidget$MoveDirection
|
accessible class net/minecraft/client/gui/DrawContext$ScissorStack
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
"AbstractSignEditScreenMixin",
|
"AbstractSignEditScreenMixin",
|
||||||
"AdvancementsScreenAccessor",
|
"AdvancementsScreenAccessor",
|
||||||
"BookEditScreenAccessor",
|
"BookEditScreenAccessor",
|
||||||
|
"BookSigningScreenAccessor",
|
||||||
"ChatScreenMixin",
|
"ChatScreenMixin",
|
||||||
"ClickableWidgetAccessor",
|
"ClickableWidgetAccessor",
|
||||||
"ClientPlayerEntityMixin",
|
"ClientPlayerEntityMixin",
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ dependencies {
|
|||||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||||
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
|
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
|
||||||
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric")
|
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-fabric")
|
||||||
modImplementation include ("maven.modrinth:obsidianui:${rootProject.obsidianui_version}-fabric") {}
|
modImplementation include ("maven.modrinth:obsidianui:${rootProject.obsidianui_version}-fabric")
|
||||||
include 'org.aperlambda:lambdajcommon:1.8.1'
|
include 'org.aperlambda:lambdajcommon:1.8.1'
|
||||||
modCompileOnly "maven.modrinth:emi:${project.emi_version}"
|
modCompileOnly "maven.modrinth:emi:${project.emi_version}"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package eu.midnightdust.midnightcontrols.fabric.event;
|
package eu.midnightdust.midnightcontrols.fabric.event;
|
||||||
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
||||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents;
|
import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents;
|
||||||
|
import net.minecraft.client.gui.Click;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
|
||||||
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.clickInterceptor;
|
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.clickInterceptor;
|
||||||
@@ -13,9 +14,9 @@ public class MouseClickListener implements ScreenMouseEvents.AllowMouseClick {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowMouseClick(Screen screen, double mouseX, double mouseY, int button) {
|
public boolean allowMouseClick(Screen screen, Click click) {
|
||||||
if(MidnightControlsConfig.virtualKeyboard) {
|
if(MidnightControlsConfig.virtualKeyboard) {
|
||||||
clickInterceptor.intercept(screen, mouseX, mouseY);
|
clickInterceptor.intercept(screen, click);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -33,8 +34,4 @@ public class MouseClickListener implements ScreenMouseEvents.AllowMouseClick {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return screen.hashCode();
|
return screen.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,32 +2,32 @@
|
|||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
org.gradle.jvmargs=-Xmx2048M
|
org.gradle.jvmargs=-Xmx2048M
|
||||||
|
|
||||||
minecraft_version=1.21.5
|
minecraft_version=1.21.9-rc1
|
||||||
supported_versions=
|
supported_versions=
|
||||||
yarn_mappings=1.21.5+build.1
|
yarn_mappings=1.21.9-rc1+build.2
|
||||||
enabled_platforms=fabric,neoforge
|
enabled_platforms=fabric,neoforge
|
||||||
|
|
||||||
archives_base_name=midnightcontrols
|
archives_base_name=midnightcontrols
|
||||||
mod_version=1.11.0
|
mod_version=1.11.2
|
||||||
maven_group=eu.midnightdust
|
maven_group=eu.midnightdust
|
||||||
release_type=release
|
release_type=release
|
||||||
modrinth_id = bXX9h73M
|
modrinth_id = bXX9h73M
|
||||||
curseforge_id = 621768
|
curseforge_id = 621768
|
||||||
# Configure the IDs here after creating the projects on the websites
|
# Configure the IDs here after creating the projects on the websites
|
||||||
|
|
||||||
midnightlib_version=1.7.3+1.21.4
|
midnightlib_version=1.8.0+1.21.9-rc1
|
||||||
|
|
||||||
fabric_loader_version=0.16.10
|
fabric_loader_version=0.17.2
|
||||||
fabric_api_version=0.119.5+1.21.5
|
fabric_api_version=0.133.13+1.21.9
|
||||||
|
|
||||||
neoforge_version=21.5.2-beta
|
neoforge_version=21.6.0-beta
|
||||||
yarn_mappings_patch_neoforge_version = 1.21+build.4
|
yarn_mappings_patch_neoforge_version = 1.21+build.4
|
||||||
|
|
||||||
quilt_loader_version=0.19.0-beta.18
|
quilt_loader_version=0.19.0-beta.18
|
||||||
quilt_fabric_api_version=7.0.1+0.83.0-1.20
|
quilt_fabric_api_version=7.0.1+0.83.0-1.20
|
||||||
|
|
||||||
sodium_version=mc1.21-0.6.0-beta.1
|
sodium_version=mc1.21-0.6.0-beta.1
|
||||||
obsidianui_version=0.2.11+mc1.21.5
|
obsidianui_version=0.2.12+mc1.21.6
|
||||||
modmenu_version=10.0.0-beta.1
|
modmenu_version=10.0.0-beta.1
|
||||||
emotecraft_version=2.5.5+1.21.4-fabric
|
emotecraft_version=2.5.5+1.21.4-fabric
|
||||||
bendylib_version=2.0.+
|
bendylib_version=2.0.+
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ configurations {
|
|||||||
dependencies {
|
dependencies {
|
||||||
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
|
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
|
||||||
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-neoforge")
|
modImplementation include ("maven.modrinth:midnightlib:${rootProject.midnightlib_version}-neoforge")
|
||||||
modImplementation include ("maven.modrinth:obsidianui:${rootProject.obsidianui_version}-neoforge") {}
|
modImplementation include ("maven.modrinth:obsidianui:${rootProject.obsidianui_version}-neoforge")
|
||||||
shadowBundle('org.aperlambda:lambdajcommon:1.8.1') {
|
shadowBundle('org.aperlambda:lambdajcommon:1.8.1') {
|
||||||
exclude group: 'com.google.code.gson'
|
exclude group: 'com.google.code.gson'
|
||||||
exclude group: 'com.google.guava'
|
exclude group: 'com.google.guava'
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ pluginManagement {
|
|||||||
include("common")
|
include("common")
|
||||||
include("fabric")
|
include("fabric")
|
||||||
//include("quilt") // Native quilt support is disabled atm, as the Quilt libraries are currently in maintenance mode
|
//include("quilt") // Native quilt support is disabled atm, as the Quilt libraries are currently in maintenance mode
|
||||||
include("neoforge")
|
//include("neoforge")
|
||||||
|
|
||||||
rootProject.name = "midnightcontrols"
|
rootProject.name = "midnightcontrols"
|
||||||
|
|||||||
Reference in New Issue
Block a user