diff --git a/common/src/main/java/io/github/reserveword/imblocker/AxiomGuiAccessor.java b/common/src/main/java/io/github/reserveword/imblocker/AxiomGuiAccessor.java new file mode 100644 index 0000000..22f8bd9 --- /dev/null +++ b/common/src/main/java/io/github/reserveword/imblocker/AxiomGuiAccessor.java @@ -0,0 +1,8 @@ +package io.github.reserveword.imblocker; + +public abstract class AxiomGuiAccessor { + public static AxiomGuiAccessor instance; + + public abstract boolean isCaptureKeyboard(); + public abstract boolean isTextFieldFocused(); +} diff --git a/common/src/main/java/io/github/reserveword/imblocker/IMCheckState.java b/common/src/main/java/io/github/reserveword/imblocker/IMCheckState.java index 3fdc794..a134228 100644 --- a/common/src/main/java/io/github/reserveword/imblocker/IMCheckState.java +++ b/common/src/main/java/io/github/reserveword/imblocker/IMCheckState.java @@ -13,7 +13,8 @@ public class IMCheckState { public static FocusableWidgetAccessor focusedInputWidget = null; - public static boolean imguiFocused = false; + private static boolean axiomGuiCaptureKeyboard = false; + private static boolean axiomGuiTextFieldFocused = false; public static boolean isWhiteListScreenShowing = false; @@ -29,8 +30,14 @@ private static void syncState() { deferredOp = null; } - IMManager.makeState((focusedInputWidget != null && focusedInputWidget.isWidgetEditable()) - || isWhiteListScreenShowing || imguiFocused); + boolean state; + if(axiomGuiCaptureKeyboard) { + state = axiomGuiTextFieldFocused; + }else { + state = (focusedInputWidget != null && focusedInputWidget.isWidgetEditable()) + || isWhiteListScreenShowing; + } + IMManager.makeState(state); updateChatState(); } @@ -45,13 +52,22 @@ public static void focusLost(FocusableWidgetAccessor widget) { } private static void updateChatState() { - ChatState currentChatState = !isChatScreenShowing || imguiFocused ? ChatState.NONE : + ChatState currentChatState = !isChatScreenShowing || axiomGuiCaptureKeyboard ? ChatState.NONE : (focusedInputWidget.getText().trim().startsWith("/") ? ChatState.COMMAND : ChatState.CHAT); if(currentChatState != ChatState.NONE && chatState != currentChatState) { + //Executing at the same tick as imstate change will nullify this operation, thus move to next tick. deferredOp = () -> IMManager.makeImmOnState(currentChatState == ChatState.COMMAND); } chatState = currentChatState; } + + private static void checkAxiomGuiState() { + AxiomGuiAccessor axiomGuiAccessor = AxiomGuiAccessor.instance; + if(axiomGuiAccessor != null) { + axiomGuiCaptureKeyboard = axiomGuiAccessor.isCaptureKeyboard(); + axiomGuiTextFieldFocused = axiomGuiAccessor.isTextFieldFocused(); + } + } // process SCREEN_LIST rules // notice that nonPrintable rule triggers at screen change, here. @@ -196,11 +212,12 @@ public static void captureClick(BooleanSupplier active) { } public static void clientTick(ScreenInfo screen) { - checkScreenList(screen); + /*checkScreenList(screen); checkSpecial(); if (count == 0) checkTick(); checkNonPrintable(screen); - checkClick(); + checkClick();*/ + checkAxiomGuiState(); syncState(); // check interval if (count > 0) count --; diff --git a/fabric/src/client/java/io/github/reserveword/imblocker/mixin/AxiomEditorUIMixin.java b/fabric/src/client/java/io/github/reserveword/imblocker/mixin/AxiomEditorUIMixin.java new file mode 100644 index 0000000..c758757 --- /dev/null +++ b/fabric/src/client/java/io/github/reserveword/imblocker/mixin/AxiomEditorUIMixin.java @@ -0,0 +1,33 @@ +package io.github.reserveword.imblocker.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import imgui.ImGuiIO; +import io.github.reserveword.imblocker.AxiomGuiAccessor; + +@Pseudo +@Mixin(targets = "com.moulberry.axiom.editor.EditorUI", remap = false) +public abstract class AxiomEditorUIMixin { + @Shadow + public static ImGuiIO imGuiIO; + + @Inject(method = "init", at = @At("TAIL")) + private static void loadImGui(CallbackInfo ci) { + AxiomGuiAccessor.instance = new AxiomGuiAccessor() { + @Override + public boolean isTextFieldFocused() { + return imGuiIO.getWantTextInput(); + } + + @Override + public boolean isCaptureKeyboard() { + return imGuiIO.getWantCaptureKeyboard(); + } + }; + } +} diff --git a/fabric/src/client/java/io/github/reserveword/imblocker/mixin/ImGuiMixin.java b/fabric/src/client/java/io/github/reserveword/imblocker/mixin/ImGuiMixin.java deleted file mode 100644 index 2b80112..0000000 --- a/fabric/src/client/java/io/github/reserveword/imblocker/mixin/ImGuiMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.reserveword.imblocker.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import imgui.callback.ImGuiInputTextCallback; -import imgui.internal.ImGui; -import imgui.type.ImString; -import io.github.reserveword.imblocker.IMCheckState; - -@Pseudo -@Mixin(targets = "imgui.ImGui") -public abstract class ImGuiMixin { - private static boolean hasFocusedWidget = false; - - @Inject(method = "preInputText(ZLjava/lang/String;Ljava/lang/String;Limgui/type/ImString;" - + "FFILimgui/callback/ImGuiInputTextCallback;)Z", at = @At("HEAD")) - private static void preInputText(boolean multiline, String label, String hint, ImString text, float width, - float height, int flags, ImGuiInputTextCallback callback, CallbackInfoReturnable ci) { - boolean wantTextInput = ImGui.getIO().getWantTextInput(); - if(hasFocusedWidget != wantTextInput) { - if(wantTextInput) { - IMCheckState.imguiFocused = true; - }else { - IMCheckState.imguiFocused = false; - } - hasFocusedWidget = wantTextInput; - } - } -} diff --git a/fabric/src/client/resources/imblocker.mixins.json b/fabric/src/client/resources/imblocker.mixins.json index b37e964..b5ca8b1 100644 --- a/fabric/src/client/resources/imblocker.mixins.json +++ b/fabric/src/client/resources/imblocker.mixins.json @@ -15,7 +15,7 @@ "ReiTextFieldMixin", "EmiSearchWidgetMixin", "ReplayModTextFieldMixin", - "ImGuiMixin", + "AxiomEditorUIMixin", "TextFieldMixin" ], "injectors": {