forked from Clones/Controlify
compatibility for tab nav bars in every screen
This commit is contained in:
@ -72,6 +72,10 @@ public class Controlify implements ControlifyApi {
|
||||
}
|
||||
}
|
||||
|
||||
if (Controller.CONTROLLERS.isEmpty()) {
|
||||
LOGGER.info("No controllers found.");
|
||||
}
|
||||
|
||||
if (currentController() == Controller.DUMMY && config().isFirstLaunch()) {
|
||||
this.setCurrentController(Controller.CONTROLLERS.values().stream().findFirst().orElse(null));
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
package dev.isxander.controlify.mixins.feature.screenop.vanilla;
|
||||
|
||||
import dev.isxander.controlify.screenop.ScreenProcessor;
|
||||
import dev.isxander.controlify.screenop.ScreenProcessorProvider;
|
||||
import dev.isxander.controlify.screenop.compat.vanilla.CreateWorldScreenProcessor;
|
||||
import net.minecraft.client.gui.components.tabs.Tab;
|
||||
import net.minecraft.client.gui.components.tabs.TabManager;
|
||||
import net.minecraft.client.gui.components.tabs.TabNavigationBar;
|
||||
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(CreateWorldScreen.class)
|
||||
public class CreateWorldScreenMixin implements ScreenProcessorProvider {
|
||||
@Shadow private @Nullable TabNavigationBar tabNavigationBar;
|
||||
@Shadow @Final private TabManager tabManager;
|
||||
|
||||
@Unique private final CreateWorldScreenProcessor controlify$screenProcessor
|
||||
= new CreateWorldScreenProcessor((CreateWorldScreen) (Object) this, this::changeTab);
|
||||
|
||||
@Override
|
||||
public ScreenProcessor<?> screenProcessor() {
|
||||
return controlify$screenProcessor;
|
||||
}
|
||||
|
||||
private void changeTab(boolean reverse) {
|
||||
List<Tab> tabs = ((TabNavigationBarAccessor) tabNavigationBar).getTabs();
|
||||
int currentIndex = tabs.indexOf(tabManager.getCurrentTab());
|
||||
|
||||
int newIndex = currentIndex + (reverse ? -1 : 1);
|
||||
if (newIndex < 0) newIndex = tabs.size() - 1;
|
||||
if (newIndex >= tabs.size()) newIndex = 0;
|
||||
|
||||
tabNavigationBar.selectTab(newIndex, true);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package dev.isxander.controlify.mixins.feature.screenop.vanilla;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.gui.components.tabs.Tab;
|
||||
import net.minecraft.client.gui.components.tabs.TabManager;
|
||||
import net.minecraft.client.gui.components.tabs.TabNavigationBar;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
@ -10,4 +11,7 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
public interface TabNavigationBarAccessor {
|
||||
@Accessor
|
||||
ImmutableList<Tab> getTabs();
|
||||
|
||||
@Accessor
|
||||
TabManager getTabManager();
|
||||
}
|
||||
|
@ -5,8 +5,11 @@ import dev.isxander.controlify.InputMode;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.api.event.ControlifyEvents;
|
||||
import dev.isxander.controlify.mixins.feature.screenop.vanilla.ScreenAccessor;
|
||||
import dev.isxander.controlify.mixins.feature.screenop.vanilla.TabNavigationBarAccessor;
|
||||
import net.minecraft.client.gui.ComponentPath;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.components.tabs.Tab;
|
||||
import net.minecraft.client.gui.components.tabs.TabNavigationBar;
|
||||
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
|
||||
import net.minecraft.client.gui.navigation.ScreenDirection;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
@ -30,6 +33,8 @@ public class ScreenProcessor<T extends Screen> {
|
||||
} else {
|
||||
handleVMouseNavigation(controller);
|
||||
}
|
||||
|
||||
handleTabNavigation(controller);
|
||||
}
|
||||
|
||||
public void onInputModeChanged(InputMode mode) {
|
||||
@ -104,6 +109,29 @@ public class ScreenProcessor<T extends Screen> {
|
||||
|
||||
}
|
||||
|
||||
protected void handleTabNavigation(Controller<?, ?> controller) {
|
||||
var nextTab = controller.bindings().GUI_NEXT_TAB.justPressed();
|
||||
var prevTab = controller.bindings().GUI_PREV_TAB.justPressed();
|
||||
|
||||
if (nextTab || prevTab) {
|
||||
screen.children().stream()
|
||||
.filter(child -> child instanceof TabNavigationBar)
|
||||
.map(TabNavigationBar.class::cast)
|
||||
.findAny()
|
||||
.ifPresent(navBar -> {
|
||||
var accessor = (TabNavigationBarAccessor) navBar;
|
||||
List<Tab> tabs = accessor.getTabs();
|
||||
int currentIndex = tabs.indexOf(accessor.getTabManager().getCurrentTab());
|
||||
|
||||
int newIndex = currentIndex + (prevTab ? -1 : 1);
|
||||
if (newIndex < 0) newIndex = tabs.size() - 1;
|
||||
if (newIndex >= tabs.size()) newIndex = 0;
|
||||
|
||||
navBar.selectTab(newIndex, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void onWidgetRebuild() {
|
||||
setInitialFocus();
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
package dev.isxander.controlify.screenop.compat.vanilla;
|
||||
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.screenop.ScreenProcessor;
|
||||
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class CreateWorldScreenProcessor extends ScreenProcessor<CreateWorldScreen> {
|
||||
private final Consumer<Boolean> tabChangeMethod;
|
||||
|
||||
public CreateWorldScreenProcessor(CreateWorldScreen screen, Consumer<Boolean> tabChangeMethod) {
|
||||
super(screen);
|
||||
this.tabChangeMethod = tabChangeMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleButtons(Controller<?, ?> controller) {
|
||||
if (controller.bindings().GUI_NEXT_TAB.justPressed()) {
|
||||
tabChangeMethod.accept(false);
|
||||
return;
|
||||
}
|
||||
if (controller.bindings().GUI_PREV_TAB.justPressed()) {
|
||||
tabChangeMethod.accept(true);
|
||||
return;
|
||||
}
|
||||
|
||||
super.handleButtons(controller);
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@
|
||||
"feature.screenop.vanilla.AbstractSelectionListMixin",
|
||||
"feature.screenop.vanilla.AbstractSliderButtonMixin",
|
||||
"feature.screenop.vanilla.ContainerObjectSelectionListEntryMixin",
|
||||
"feature.screenop.vanilla.CreateWorldScreenMixin",
|
||||
|
||||
"feature.screenop.vanilla.CreativeModeInventoryScreenAccessor",
|
||||
"feature.screenop.vanilla.CreativeModeInventoryScreenMixin",
|
||||
"feature.screenop.vanilla.JoinMultiplayerScreenAccessor",
|
||||
|
Reference in New Issue
Block a user