Further cleanup

This commit is contained in:
Martin Prokoph
2024-07-17 23:43:07 +02:00
parent 45149af859
commit 241228dcde
14 changed files with 52 additions and 242 deletions

View File

@@ -12,6 +12,8 @@ package eu.midnightdust.midnightcontrols;
import net.minecraft.util.Identifier;
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
/**
* Represents the constants used by MidnightControls.
*
@@ -21,7 +23,7 @@ import net.minecraft.util.Identifier;
*/
public class MidnightControlsConstants {
public static final String NAMESPACE = "midnightcontrols";
public static final Identifier CONTROLS_MODE_CHANNEL = Identifier.of(NAMESPACE, "controls_mode");
public static final Identifier FEATURE_CHANNEL = Identifier.of(NAMESPACE, "feature");
public static final Identifier HELLO_CHANNEL = Identifier.of(NAMESPACE, "hello");
public static final Identifier CONTROLS_MODE_CHANNEL = id("controls_mode");
public static final Identifier FEATURE_CHANNEL = id("feature");
public static final Identifier HELLO_CHANNEL = id("hello");
}

View File

@@ -12,6 +12,7 @@ package eu.midnightdust.midnightcontrols.client;
import eu.midnightdust.lib.util.PlatformFunctions;
import eu.midnightdust.midnightcontrols.ControlsMode;
import eu.midnightdust.midnightcontrols.MidnightControls;
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
import eu.midnightdust.midnightcontrols.MidnightControlsFeature;
import eu.midnightdust.midnightcontrols.client.compat.MidnightControlsCompat;
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
@@ -103,7 +104,7 @@ public class MidnightControlsClient extends MidnightControls {
MidnightControlsConfig.mouseScreens.remove("net.minecraft.class_5375");
MidnightControlsConfig.mouseScreens.remove("net.minecraft.client.gui.screen.pack.PackScreen");
MidnightControlsConfig.configVersion = 2;
MidnightControlsConfig.write("midnightcontrols");
MidnightControlsConfig.write(MidnightControlsConstants.NAMESPACE);
}
hud.setVisible(MidnightControlsConfig.hudEnable);
Controller.updateMappings();
@@ -135,7 +136,7 @@ public class MidnightControlsClient extends MidnightControls {
for (int i = 0; i < KeyBindingIDAccessor.getKEYS_BY_ID().size(); ++i) {
KeyBinding keyBinding = KeyBindingIDAccessor.getKEYS_BY_ID().entrySet().stream().toList().get(i).getValue();
if (MidnightControlsConfig.excludedKeybindings.stream().noneMatch(excluded -> keyBinding.getTranslationKey().startsWith(excluded))) {
if (!keyBinding.getTranslationKey().contains("midnightcontrols") && !keyBinding.getTranslationKey().contains("ok_zoomer") && !keyBinding.getTranslationKey().contains("okzoomer")) {
if (!keyBinding.getTranslationKey().contains(MidnightControlsConstants.NAMESPACE)) {
AtomicReference<ButtonCategory> category = new AtomicReference<>();
InputManager.streamCategories().forEach(buttonCategory -> {
if (buttonCategory.getIdentifier().equals(Identifier.of("minecraft", keyBinding.getCategory())))

View File

@@ -15,6 +15,7 @@ import com.mojang.blaze3d.platform.GlDebugInfo;
import eu.midnightdust.lib.config.MidnightConfig;
import eu.midnightdust.midnightcontrols.ControlsMode;
import eu.midnightdust.midnightcontrols.MidnightControls;
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
import eu.midnightdust.midnightcontrols.MidnightControlsFeature;
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
import eu.midnightdust.midnightcontrols.client.controller.Controller;
@@ -130,7 +131,7 @@ public class MidnightControlsConfig extends MidnightConfig {
* Loads the configuration
*/
public static void load() {
MidnightControlsConfig.init("midnightcontrols", MidnightControlsConfig.class);
MidnightControlsConfig.init(MidnightControlsConstants.NAMESPACE, MidnightControlsConfig.class);
MidnightControls.log("Configuration loaded.");
// Controller controls.
InputManager.loadButtonBindings();
@@ -140,7 +141,7 @@ public class MidnightControlsConfig extends MidnightConfig {
* Saves the configuration.
*/
public static void save() {
MidnightControlsConfig.write("midnightcontrols");
MidnightControlsConfig.write(MidnightControlsConstants.NAMESPACE);
MidnightControls.log("Configuration saved.");
MidnightControlsFeature.refreshEnabled();
}
@@ -188,7 +189,7 @@ public class MidnightControlsConfig extends MidnightConfig {
*/
public static void setController(Controller controller) {
MidnightControlsConfig.controllerID = controller.id();
MidnightControlsConfig.write("midnightcontrols");
MidnightControlsConfig.write(MidnightControlsConstants.NAMESPACE);
}
/**

View File

@@ -7,9 +7,10 @@ import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
import eu.midnightdust.midnightcontrols.client.controller.ButtonCategory;
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
public class EMICompat implements CompatHandler {
public static boolean handleEmiPages(boolean direction) {
if (isEMIEnabled() && MidnightControlsClient.input.actionGuiCooldown == 0 && EmiScreenManager.getSearchPanel() != null && EmiScreenManager.getSearchPanel().pageLeft != null && EmiScreenManager.getSearchPanel().pageRight != null) {
@@ -22,7 +23,7 @@ public class EMICompat implements CompatHandler {
}
@Override
public void handle() {
ButtonCategory category = new ButtonCategory(Identifier.of("midnightcontrols","category.emi"));
ButtonCategory category = new ButtonCategory(id("category.emi"));
InputManager.registerCategory(category);
new ButtonBinding.Builder("emi_page_left")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true))

View File

@@ -11,7 +11,6 @@ package eu.midnightdust.midnightcontrols.client.compat;
import eu.midnightdust.lib.util.PlatformFunctions;
import eu.midnightdust.midnightcontrols.client.controller.InputManager;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.hit.BlockHitResult;
@@ -39,21 +38,15 @@ public class MidnightControlsCompat {
* Initializes compatibility with other mods if needed.
*/
public static void init() {
// "okzoomer" is the mod ID used by Fabric-compatible versions of Ok Zoomer. (5.0.0-beta.6 and below.)
// "ok_zoomer" is the mod ID used by Quilt-exclusive versions of Ok Zoomer. (5.0.0-beta.7 and above.)
if (FabricLoader.getInstance().isModLoaded("okzoomer") || FabricLoader.getInstance().isModLoaded("ok_zoomer")) {
log("Adding Ok Zoomer compatibility...");
registerCompatHandler(new OkZoomerCompat());
}
if (isEMIPresent()) {
log("Adding EMI compatibility...");
registerCompatHandler(new EMICompat());
}
if (FabricLoader.getInstance().isModLoaded("hardcorequesting") && LambdaReflection.doesClassExist(HQMCompat.GUI_BASE_CLASS_PATH)) {
if (PlatformFunctions.isModLoaded("hardcorequesting") && LambdaReflection.doesClassExist(HQMCompat.GUI_BASE_CLASS_PATH)) {
log("Adding HQM compatibility...");
registerCompatHandler(new HQMCompat());
}
if (FabricLoader.getInstance().isModLoaded("bedrockify")) {
if (PlatformFunctions.isModLoaded("bedrockify")) {
log("Adding Bedrockify compatibility...");
registerCompatHandler(new BedrockifyCompat());
}
@@ -208,6 +201,6 @@ public class MidnightControlsCompat {
* @return true if Emotecraft is present, else false
*/
public static boolean isEmotecraftPresent() {
return FabricLoader.getInstance().isModLoaded("emotecraft");
return PlatformFunctions.isModLoaded("emotecraft");
}
}

View File

@@ -10,13 +10,10 @@
package eu.midnightdust.midnightcontrols.client.compat;
import eu.midnightdust.lib.util.PlatformFunctions;
import net.fabricmc.loader.api.FabricLoader;
import org.jetbrains.annotations.NotNull;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

View File

@@ -1,196 +0,0 @@
/*
* Copyright © 2021-2022 Karen/あけみ <karen@akemi.ai>, LambdAurora <aurora42lambda@gmail.com>
*
* This file is part of MidnightControls.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/
package eu.midnightdust.midnightcontrols.client.compat;
import eu.midnightdust.midnightcontrols.MidnightControls;
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
import eu.midnightdust.midnightcontrols.client.controller.ButtonBinding;
import net.minecraft.client.option.KeyBinding;
import org.jetbrains.annotations.NotNull;
import org.aperlambda.lambdacommon.utils.LambdaReflection;
import org.lwjgl.glfw.GLFW;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Represents a compatibility handler for Ok Zoomer.
*
* @author Karen/あけみ, LambdAurora
* @version 1.4.3
* @since 1.1.0
*/
public class OkZoomerCompat implements CompatHandler {
private boolean didAllReflectionCallsSucceed = false;
private KeyBinding okZoomerZoomKey;
private KeyBinding okZoomerIncreaseZoomKey;
private KeyBinding okZoomerDecreaseZoomKey;
private KeyBinding okZoomerResetZoomKey;
private Method okZoomerAreExtraKeyBindsEnabledMethod;
public OkZoomerCompat() {
// These strings represent the names of the classes, fields, and methods we use from the Ok Zoomer API
String okZoomerZoomKeybindsClassString;
String okZoomerZoomKeyFieldString;
String okZoomerIncreaseZoomKeyFieldString;
String okZoomerDecreaseZoomKeyFieldString;
String okZoomerResetZoomKeyFieldString;
String okZoomerAreExtraKeyBindsEnabledMethodNameString;
// These variables represent the actual objects that we reflect to
Class<?> okZoomerZoomKeybindsClass;
Field okZoomerZoomKeyField;
Field okZoomerIncreaseZoomKeyField;
Field okZoomerDecreaseZoomKeyField;
Field okZoomerResetZoomKeyField;
// First, we need to determine which version of the Ok Zoomer API we're dealing with here.
if (LambdaReflection.doesClassExist("io.github.ennuil.okzoomer.keybinds.ZoomKeybinds")) {
// https://github.com/EnnuiL/OkZoomer/blob/5.0.0-beta.3+1.17.1/src/main/java/io/github/ennuil/okzoomer/keybinds/ZoomKeybinds.java
MidnightControls.log("Ok Zoomer version 5.0.0-beta.3 or below detected!");
okZoomerZoomKeybindsClassString = "io.github.ennuil.okzoomer.keybinds.ZoomKeybinds";
okZoomerZoomKeyFieldString = "zoomKey";
okZoomerIncreaseZoomKeyFieldString = "increaseZoomKey";
okZoomerDecreaseZoomKeyFieldString = "decreaseZoomKey";
okZoomerResetZoomKeyFieldString = "resetZoomKey";
okZoomerAreExtraKeyBindsEnabledMethodNameString = "areExtraKeybindsEnabled";
} else if (LambdaReflection.doesClassExist("io.github.ennuil.okzoomer.key_binds.ZoomKeyBinds")) {
// https://github.com/EnnuiL/OkZoomer/blob/5.0.0-beta.6+1.18.2/src/main/java/io/github/ennuil/okzoomer/key_binds/ZoomKeyBinds.java
MidnightControls.log("Ok Zoomer version 5.0.0-beta.6, 5.0.0-beta.5, or 5.0.0-beta.4 detected!");
okZoomerZoomKeybindsClassString = "io.github.ennuil.okzoomer.key_binds.ZoomKeyBinds";
okZoomerZoomKeyFieldString = "ZOOM_KEY";
okZoomerIncreaseZoomKeyFieldString = "INCREASE_ZOOM_KEY";
okZoomerDecreaseZoomKeyFieldString = "DECREASE_ZOOM_KEY";
okZoomerResetZoomKeyFieldString = "RESET_ZOOM_KEY";
okZoomerAreExtraKeyBindsEnabledMethodNameString = "areExtraKeyBindsEnabled";
} else if (LambdaReflection.doesClassExist("io.github.ennuil.ok_zoomer.key_binds.ZoomKeyBinds")) {
// https://github.com/EnnuiL/OkZoomer/blob/5.0.0-beta.7+1.18.2/src/main/java/io/github/ennuil/ok_zoomer/key_binds/ZoomKeyBinds.java
MidnightControls.log("Ok Zoomer version 5.0.0-beta.7 (Quilt) or above detected!");
okZoomerZoomKeybindsClassString = "io.github.ennuil.ok_zoomer.key_binds.ZoomKeyBinds";
okZoomerZoomKeyFieldString = "ZOOM_KEY";
okZoomerIncreaseZoomKeyFieldString = "INCREASE_ZOOM_KEY";
okZoomerDecreaseZoomKeyFieldString = "DECREASE_ZOOM_KEY";
okZoomerResetZoomKeyFieldString = "RESET_ZOOM_KEY";
okZoomerAreExtraKeyBindsEnabledMethodNameString = "areExtraKeyBindsEnabled";
} else {
// If all of the above checks fail, then the version of the Ok Zoomer API that the user is trying to use is too new.
MidnightControls.warn("The version of Ok Zoomer that you are currently using is too new, and is not yet supported by MidnightControls!");
return;
}
// Reflect to the ZoomKeyBinds (>= 5.0.0-beta.4) / ZoomKeybinds (<= 5.0.0-beta.3) class.
try {
okZoomerZoomKeybindsClass = Class.forName(okZoomerZoomKeybindsClassString);
} catch (ClassNotFoundException exception) {
// This theoretically should never happen.
MidnightControls.warn("MidnightControls failed to reflect to the Ok Zoomer keybinds class!");
exception.printStackTrace();
return;
}
// Reflect to all of the keybind fields.
try {
okZoomerZoomKeyField = okZoomerZoomKeybindsClass.getField(okZoomerZoomKeyFieldString);
okZoomerIncreaseZoomKeyField = okZoomerZoomKeybindsClass.getField(okZoomerIncreaseZoomKeyFieldString);
okZoomerDecreaseZoomKeyField = okZoomerZoomKeybindsClass.getField(okZoomerDecreaseZoomKeyFieldString);
okZoomerResetZoomKeyField = okZoomerZoomKeybindsClass.getField(okZoomerResetZoomKeyFieldString);
} catch (NoSuchFieldException exception) {
MidnightControls.warn("MidnightControls failed to reflect to the Ok Zoomer keybind fields!");
exception.printStackTrace();
return;
}
// Initialise KeyBinding objects
try {
okZoomerZoomKey = (KeyBinding) okZoomerZoomKeyField.get(null);
okZoomerIncreaseZoomKey = (KeyBinding) okZoomerIncreaseZoomKeyField.get(null);
okZoomerDecreaseZoomKey = (KeyBinding) okZoomerDecreaseZoomKeyField.get(null);
okZoomerResetZoomKey = (KeyBinding) okZoomerResetZoomKeyField.get(null);
} catch (IllegalAccessException exception) {
MidnightControls.warn("MidnightControls failed to reflect to the Ok Zoomer keybind objects!");
exception.printStackTrace();
return;
}
// Reflect to the areExtraKeyBindsEnabled (>= 5.0.0-beta.4) / areExtraKeybindsEnabled (<= 5.0.0-beta.3) method.
// TODO: Consider replacing this entirely with getExtraKeyBind (>= 5.0.0-beta.4) / getExtraKeybind (<= 5.0.0-beta.3) in the future.
try {
okZoomerAreExtraKeyBindsEnabledMethod = okZoomerZoomKeybindsClass.getDeclaredMethod(okZoomerAreExtraKeyBindsEnabledMethodNameString);
} catch (NoSuchMethodException exception) {
MidnightControls.warn("MidnightControls failed to reflect to an Ok Zoomer method (areExtraKeyBindsEnabled / areExtraKeybindsEnabled)!");
exception.printStackTrace();
return;
}
didAllReflectionCallsSucceed = true;
}
@Override
public void handle() {
if (didAllReflectionCallsSucceed) {
new ButtonBinding.Builder("zoom")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, GLFW.GLFW_GAMEPAD_BUTTON_X)
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(okZoomerZoomKey)
.register();
boolean okZoomerAreExtraKeyBindsEnabled = false;
try {
okZoomerAreExtraKeyBindsEnabled = (boolean) okZoomerAreExtraKeyBindsEnabledMethod.invoke(null);
} catch (IllegalAccessException exception) {
MidnightControls.warn("MidnightControls encountered an IllegalAccessException while attempting to invoke a reflected Ok Zoomer method (areExtraKeyBindsEnabled / areExtraKeybindsEnabled)!");
exception.printStackTrace();
} catch (InvocationTargetException exception) {
MidnightControls.warn("MidnightControls encountered an InvocationTargetException while attempting to invoke a reflected Ok Zoomer method (areExtraKeyBindsEnabled / areExtraKeybindsEnabled)!");
exception.printStackTrace();
}
if (okZoomerAreExtraKeyBindsEnabled) {
new ButtonBinding.Builder("zoom_in")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, true))
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(okZoomerIncreaseZoomKey)
.register();
new ButtonBinding.Builder("zoom_out")
.buttons(GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP, ButtonBinding.axisAsButton(GLFW.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, true))
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(okZoomerDecreaseZoomKey)
.register();
new ButtonBinding.Builder("zoom_reset")
.onlyInGame()
.cooldown(true)
.category(ButtonBinding.MISC_CATEGORY)
.linkKeybind(okZoomerResetZoomKey)
.register();
}
}
}
}

View File

@@ -38,6 +38,15 @@ public class ButtonCategory {
public ButtonCategory(@NotNull Identifier id) {
this(id, 100);
}
@Deprecated
public ButtonCategory(@NotNull org.aperlambda.lambdacommon.Identifier id, int priority) {
this(Identifier.of(id.getNamespace(), id.getName()), priority);
}
@Deprecated
public ButtonCategory(@NotNull org.aperlambda.lambdacommon.Identifier id) {
this(id, 100);
}
public void registerBinding(@NotNull ButtonBinding binding) {
if (this.bindings.contains(binding))

View File

@@ -29,6 +29,8 @@ import net.minecraft.util.hit.HitResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
/**
* Represents the midnightcontrols HUD.
*
@@ -55,7 +57,7 @@ public class MidnightControlsHud extends Hud {
private static boolean isCrammed = false;
public MidnightControlsHud() {
super(Identifier.of(MidnightControlsConstants.NAMESPACE, "hud/button_indicator"));
super(id("hud/button_indicator"));
}
@Override

View File

@@ -10,6 +10,7 @@
package eu.midnightdust.midnightcontrols.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import eu.midnightdust.midnightcontrols.MidnightControlsConstants;
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
import eu.midnightdust.midnightcontrols.client.util.platform.NetworkUtil;
import org.thinkingstudio.obsidianui.background.Background;
@@ -215,7 +216,7 @@ public class MidnightControlsSettingsScreen extends SpruceScreen {
var client = MinecraftClient.getInstance();
this.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight());
});
this.advancedConfigOption = SpruceSimpleActionOption.of("midnightcontrols.midnightconfig.title", button -> client.setScreen(MidnightControlsConfig.getScreen(this, "midnightcontrols")));
this.advancedConfigOption = SpruceSimpleActionOption.of("midnightcontrols.midnightconfig.title", button -> client.setScreen(MidnightControlsConfig.getScreen(this, MidnightControlsConstants.NAMESPACE)));
// Gameplay options
this.analogMovementOption = new SpruceToggleBooleanOption("midnightcontrols.menu.analog_movement",
() -> MidnightControlsConfig.analogMovement, value -> MidnightControlsConfig.analogMovement = value,

View File

@@ -43,6 +43,7 @@ import org.lwjgl.glfw.GLFW;
import java.util.List;
import java.util.Objects;
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.input;
import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_RIGHT_X;
import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_RIGHT_Y;
@@ -51,7 +52,7 @@ import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_RIGHT_Y;
* Represents the touchscreen overlay
*/
public class TouchscreenOverlay extends Screen {
public static final Identifier WIDGETS_LOCATION = Identifier.of("midnightcontrols", "textures/gui/widgets.png");
public static final Identifier WIDGETS_LOCATION = id("textures/gui/widgets.png");
private SilentTexturedButtonWidget inventoryButton;
private SilentTexturedButtonWidget swapHandsButton;
private SilentTexturedButtonWidget dropButton;
@@ -165,15 +166,15 @@ public class TouchscreenOverlay extends Screen {
int emoteOffset = 0;
if (PlatformFunctions.isModLoaded("emotecraft")) {
emoteOffset = 10;
TextIconButtonWidget emoteButton = TextIconButtonWidget.builder(Text.empty(), btn -> EmotecraftCompat.openEmotecraftScreen(this), true).width(20).texture(Identifier.of(MidnightControlsConstants.NAMESPACE, "touch/emote"), 20, 20).build();
TextIconButtonWidget emoteButton = TextIconButtonWidget.builder(Text.empty(), btn -> EmotecraftCompat.openEmotecraftScreen(this), true).width(20).texture(id("touch/emote"), 20, 20).build();
emoteButton.setPosition(scaledWidth / 2 - 30, 0);
this.addDrawableChild(emoteButton);
}
TextIconButtonWidget chatButton = TextIconButtonWidget.builder(Text.empty(), btn -> this.client.setScreen(new ChatScreen("")), true).width(20).texture(Identifier.of(MidnightControlsConstants.NAMESPACE, "touch/chat"), 20, 20).build();
TextIconButtonWidget chatButton = TextIconButtonWidget.builder(Text.empty(), btn -> this.client.setScreen(new ChatScreen("")), true).width(20).texture(id("touch/chat"), 20, 20).build();
chatButton.setPosition(scaledWidth / 2 - 20 + emoteOffset, 0);
this.addDrawableChild(chatButton);
TextIconButtonWidget pauseButton = TextIconButtonWidget.builder(Text.empty(), btn -> this.pauseGame(), true).width(20).texture(Identifier.of(MidnightControlsConstants.NAMESPACE, "touch/pause"), 20, 20).build();
TextIconButtonWidget pauseButton = TextIconButtonWidget.builder(Text.empty(), btn -> this.pauseGame(), true).width(20).texture(id("touch/pause"), 20, 20).build();
pauseButton.setPosition(scaledWidth / 2 + emoteOffset, 0);
this.addDrawableChild(pauseButton);
// Inventory buttons.
@@ -287,17 +288,17 @@ public class TouchscreenOverlay extends Screen {
}
private void initCustomButtons(boolean left) {
assert client != null;
Identifier emptySprite = Identifier.of(MidnightControlsConstants.NAMESPACE, "touch/empty");
Identifier emptySprite = id("touch/empty");
List<String> list = left ? MidnightControlsConfig.leftTouchBinds : MidnightControlsConfig.rightTouchBinds;
Sprite missingSprite = client.getGuiAtlasManager().getSprite(MissingSprite.getMissingSpriteId());
for (int i = 0; i < list.size(); i++) {
String bindName = list.get(i);
ButtonBinding binding = InputManager.getBinding(bindName);
if (binding == null) continue;
boolean hasTexture = client.getGuiAtlasManager().getSprite(Identifier.of(MidnightControlsConstants.NAMESPACE, "binding/"+bindName)) != missingSprite;
if (MidnightControlsConfig.debug) System.out.println(left +" "+Identifier.of(MidnightControlsConstants.NAMESPACE, "binding/"+bindName)+" "+ hasTexture);
boolean hasTexture = client.getGuiAtlasManager().getSprite(id("binding/"+bindName)) != missingSprite;
if (MidnightControlsConfig.debug) System.out.println(left +" "+id("binding/"+bindName)+" "+ hasTexture);
var button = TextIconButtonWidget.builder(Text.translatable(binding.getTranslationKey()), b -> binding.handle(client, 1, ButtonState.PRESS), hasTexture)
.texture(hasTexture ? Identifier.of(MidnightControlsConstants.NAMESPACE, "binding/"+bindName) : emptySprite, 20, 20).dimension(20, 20).build();
.texture(hasTexture ? id("binding/"+bindName) : emptySprite, 20, 20).dimension(20, 20).build();
button.setPosition(left ? (3+(i*23)) : this.width-(23+(i*23)), 3);
button.setAlpha(MidnightControlsConfig.touchTransparency / 100f);
this.addDrawableChild(button);

View File

@@ -17,7 +17,6 @@ import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.widget.OptionListWidget;
import net.minecraft.client.gui.widget.TextIconButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -26,6 +25,8 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
/**
* Injects the new controls settings button.
*/
@@ -33,7 +34,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class GameOptionsScreenMixin extends Screen {
@Shadow @Nullable protected OptionListWidget body;
@Unique TextIconButtonWidget midnightcontrols$button = TextIconButtonWidget.builder(Text.translatable("midnightcontrols.menu.title.controller"), (button -> this.client.setScreen(new MidnightControlsSettingsScreen(this, false))), true)
.dimension(20,20).texture(Identifier.of("midnightcontrols", "icon/controller"), 20, 20).build();
.dimension(20,20).texture(id("icon/controller"), 20, 20).build();
protected GameOptionsScreenMixin(Text title) {
super(title);

View File

@@ -30,26 +30,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GameRenderer.class)
public abstract class GameRendererMixin {
@Shadow
@Final
MinecraftClient client;
@Shadow @Final MinecraftClient client;
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Mouse;getX()D", shift = At.Shift.BEFORE))
private void onRender(RenderTickCounter tickCounter, boolean tick, CallbackInfo ci) {
private void midnigtcontrols$onRender(RenderTickCounter tickCounter, boolean tick, CallbackInfo ci) {
if (this.client.currentScreen != null && MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER)
MidnightControlsClient.input.onPreRenderScreen(this.client, this.client.currentScreen);
}
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;draw()V", shift = At.Shift.BEFORE))
private void renderVirtualCursor(RenderTickCounter tickCounter, boolean tick, CallbackInfo ci, @Local DrawContext drawContext) {
private void midnigtcontrols$renderVirtualCursor(RenderTickCounter tickCounter, boolean tick, CallbackInfo ci, @Local DrawContext drawContext) {
MidnightControlsRenderer.renderVirtualCursor(drawContext, client);
if (MidnightControlsClient.isWayland) MidnightControlsRenderer.renderWaylandCursor(drawContext, client);
drawContext.draw();
}
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/GameRenderer;renderHand:Z"), method = "renderWorld")
private void captureProjAndModMatrix(RenderTickCounter tickCounter, CallbackInfo ci, @Local(ordinal = 1) Matrix4f matrices) {
private void midnigtcontrols$captureMatrices(RenderTickCounter tickCounter, CallbackInfo ci, @Local(ordinal = 1) Matrix4f matrices) {
TouchUtils.lastProjMat.set(RenderSystem.getProjectionMatrix());
TouchUtils.lastModMat.set(RenderSystem.getModelViewMatrix());
TouchUtils.lastWorldSpaceMatrix.set(matrices);
}
}

View File

@@ -17,11 +17,11 @@ import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.util.Identifier;
import org.thinkingstudio.obsidianui.fabric.event.OpenScreenCallback;
import java.util.Optional;
import static eu.midnightdust.midnightcontrols.MidnightControls.id;
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.BINDING_LOOK_DOWN;
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.BINDING_LOOK_LEFT;
import static eu.midnightdust.midnightcontrols.client.MidnightControlsClient.BINDING_LOOK_RIGHT;
@@ -65,9 +65,9 @@ public class MidnightControlsClientFabric implements ClientModInitializer {
MidnightControlsClient.input.onScreenOpen(client, client.getWindow().getWidth(), client.getWindow().getHeight());
}
});
FabricLoader.getInstance().getModContainer("midnightcontrols").ifPresent(modContainer -> {
ResourceManagerHelper.registerBuiltinResourcePack(Identifier.of("midnightcontrols","bedrock"), modContainer, ResourcePackActivationType.NORMAL);
ResourceManagerHelper.registerBuiltinResourcePack(Identifier.of("midnightcontrols","legacy"), modContainer, ResourcePackActivationType.NORMAL);
FabricLoader.getInstance().getModContainer(MidnightControlsConstants.NAMESPACE).ifPresent(modContainer -> {
ResourceManagerHelper.registerBuiltinResourcePack(id("bedrock"), modContainer, ResourcePackActivationType.NORMAL);
ResourceManagerHelper.registerBuiltinResourcePack(id("legacy"), modContainer, ResourcePackActivationType.NORMAL);
});
MidnightControlsClient.initClient();
}