forked from Clones/Controlify
➕ Server selection screen controller compat
This commit is contained in:
@ -14,7 +14,7 @@ public class JoinMultiplayerScreenMixin implements ScreenProcessorProvider {
|
||||
@Shadow protected ServerSelectionList serverSelectionList;
|
||||
|
||||
@Unique private final JoinMultiplayerScreenProcessor controlify$processor
|
||||
= new JoinMultiplayerScreenProcessor((JoinMultiplayerScreen) (Object) this, serverSelectionList);
|
||||
= new JoinMultiplayerScreenProcessor((JoinMultiplayerScreen) (Object) this, () -> serverSelectionList);
|
||||
|
||||
@Override
|
||||
public ScreenProcessor<?> screenProcessor() {
|
||||
|
@ -260,8 +260,16 @@ public class ScreenProcessor<T extends Screen> {
|
||||
return tree;
|
||||
}
|
||||
|
||||
protected final Optional<AbstractWidget> getWidget(Component message) {
|
||||
return screen.children().stream()
|
||||
.filter(child -> child instanceof AbstractWidget)
|
||||
.map(AbstractWidget.class::cast)
|
||||
.filter(widget -> widget.getMessage().equals(message))
|
||||
.findAny();
|
||||
}
|
||||
|
||||
protected final Optional<AbstractWidget> getWidget(String translationKey) {
|
||||
var translatedName = Component.translatable(translationKey).getString();
|
||||
String translatedName = Component.translatable(translationKey).getString();
|
||||
|
||||
return screen.children().stream()
|
||||
.filter(child -> child instanceof AbstractWidget)
|
||||
|
@ -1,25 +1,50 @@
|
||||
package dev.isxander.controlify.screenop.compat.vanilla;
|
||||
|
||||
import dev.isxander.controlify.api.buttonguide.ButtonGuideApi;
|
||||
import dev.isxander.controlify.api.buttonguide.ButtonGuidePredicate;
|
||||
import dev.isxander.controlify.api.buttonguide.ButtonRenderPosition;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.screenop.ScreenProcessor;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.AbstractButton;
|
||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
import net.minecraft.client.gui.screens.multiplayer.ServerSelectionList;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class JoinMultiplayerScreenProcessor extends ScreenProcessor<JoinMultiplayerScreen> {
|
||||
private final ServerSelectionList list;
|
||||
private final Supplier<ServerSelectionList> listSupplier;
|
||||
|
||||
public JoinMultiplayerScreenProcessor(JoinMultiplayerScreen screen, ServerSelectionList list) {
|
||||
public JoinMultiplayerScreenProcessor(JoinMultiplayerScreen screen, Supplier<ServerSelectionList> listSupplier) {
|
||||
super(screen);
|
||||
this.list = list;
|
||||
this.listSupplier = listSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleButtons(Controller<?, ?> controller) {
|
||||
if (screen.getFocused() instanceof Button && controller.bindings().GUI_BACK.justPressed()) {
|
||||
screen.setFocused(list);
|
||||
if (controller.bindings().GUI_BACK.justPressed()) {
|
||||
this.getWidget(CommonComponents.GUI_BACK).ifPresent(back -> {
|
||||
if (!back.isFocused()) {
|
||||
ServerSelectionList list = listSupplier.get();
|
||||
list.setSelected(null);
|
||||
list.setFocused(null);
|
||||
|
||||
screen.setFocused(back);
|
||||
} else {
|
||||
((AbstractButton) back).onPress();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
super.handleButtons(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWidgetRebuild() {
|
||||
this.getWidget(CommonComponents.GUI_BACK).ifPresent(button -> {
|
||||
ButtonGuideApi.addGuideToButton((AbstractButton) button, controller -> controller.bindings().GUI_BACK, ButtonRenderPosition.TEXT, ButtonGuidePredicate.ALWAYS);
|
||||
});
|
||||
|
||||
super.onWidgetRebuild();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ public class ServerSelectionListEntryComponentProcessor implements ComponentProc
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user