forked from Clones/Controlify
✏️ Make the "edit box keeps focus" feature customizable behaviour by ComponentProcessor
This commit is contained in:
@ -0,0 +1,18 @@
|
|||||||
|
package dev.isxander.controlify.mixins.feature.screenop.vanilla;
|
||||||
|
|
||||||
|
import dev.isxander.controlify.screenop.ComponentProcessor;
|
||||||
|
import dev.isxander.controlify.screenop.ComponentProcessorProvider;
|
||||||
|
import dev.isxander.controlify.screenop.compat.vanilla.EditBoxComponentProcessor;
|
||||||
|
import net.minecraft.client.gui.components.EditBox;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
|
||||||
|
@Mixin(EditBox.class)
|
||||||
|
public class EditBoxMixin implements ComponentProcessorProvider {
|
||||||
|
@Unique private final ComponentProcessor processor = new EditBoxComponentProcessor();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ComponentProcessor componentProcessor() {
|
||||||
|
return processor;
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,10 @@ public interface ComponentProcessor extends ComponentProcessorProvider {
|
|||||||
default void onFocusGained(ScreenProcessor<?> screen, Controller<?, ?> controller) {
|
default void onFocusGained(ScreenProcessor<?> screen, Controller<?, ?> controller) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean shouldKeepFocusOnKeyboardMode(ScreenProcessor<?> screen) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default ComponentProcessor componentProcessor() {
|
default ComponentProcessor componentProcessor() {
|
||||||
return this;
|
return this;
|
||||||
|
@ -65,10 +65,10 @@ public class ScreenProcessor<T extends Screen> {
|
|||||||
public void onInputModeChanged(InputMode mode) {
|
public void onInputModeChanged(InputMode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case KEYBOARD_MOUSE -> {
|
case KEYBOARD_MOUSE -> {
|
||||||
boolean focusingEditBox = getFocusTree().stream()
|
boolean shouldKeepFocus = getFocusTree().stream()
|
||||||
.anyMatch(component -> component instanceof EditBox);
|
.anyMatch(component -> ComponentProcessorProvider.provide(component).shouldKeepFocusOnKeyboardMode(this));
|
||||||
|
|
||||||
if (!focusingEditBox) {
|
if (!shouldKeepFocus) {
|
||||||
((ScreenAccessor) screen).invokeClearFocus();
|
((ScreenAccessor) screen).invokeClearFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package dev.isxander.controlify.screenop.compat.vanilla;
|
||||||
|
|
||||||
|
import dev.isxander.controlify.screenop.ComponentProcessor;
|
||||||
|
import dev.isxander.controlify.screenop.ScreenProcessor;
|
||||||
|
|
||||||
|
public class EditBoxComponentProcessor implements ComponentProcessor {
|
||||||
|
@Override
|
||||||
|
public boolean shouldKeepFocusOnKeyboardMode(ScreenProcessor<?> screen) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -67,6 +67,7 @@
|
|||||||
"feature.screenop.vanilla.CreateWorldScreenMixin",
|
"feature.screenop.vanilla.CreateWorldScreenMixin",
|
||||||
"feature.screenop.vanilla.CreativeModeInventoryScreenAccessor",
|
"feature.screenop.vanilla.CreativeModeInventoryScreenAccessor",
|
||||||
"feature.screenop.vanilla.CreativeModeInventoryScreenMixin",
|
"feature.screenop.vanilla.CreativeModeInventoryScreenMixin",
|
||||||
|
"feature.screenop.vanilla.EditBoxMixin",
|
||||||
"feature.screenop.vanilla.JoinMultiplayerScreenAccessor",
|
"feature.screenop.vanilla.JoinMultiplayerScreenAccessor",
|
||||||
"feature.screenop.vanilla.JoinMultiplayerScreenMixin",
|
"feature.screenop.vanilla.JoinMultiplayerScreenMixin",
|
||||||
"feature.screenop.vanilla.LanguageSelectionListEntryMixin",
|
"feature.screenop.vanilla.LanguageSelectionListEntryMixin",
|
||||||
|
Reference in New Issue
Block a user