Skip to content

Commit

Permalink
Move state checker of Axiom GUI to client tick event.
Browse files Browse the repository at this point in the history
  • Loading branch information
LitnhJacuzzi committed Oct 21, 2024
1 parent f9a4eaa commit 75f164f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}

Expand All @@ -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.
Expand Down Expand Up @@ -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 --;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
};
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion fabric/src/client/resources/imblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ReiTextFieldMixin",
"EmiSearchWidgetMixin",
"ReplayModTextFieldMixin",
"ImGuiMixin",
"AxiomEditorUIMixin",
"TextFieldMixin"
],
"injectors": {
Expand Down

0 comments on commit 75f164f

Please sign in to comment.