forked from Clones/Controlify
✏️ Add/improve button guides for carousel screen and title screen respectively
This commit is contained in:
@ -3,8 +3,12 @@ package dev.isxander.controlify.gui.screen;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import dev.isxander.controlify.Controlify;
|
import dev.isxander.controlify.Controlify;
|
||||||
import dev.isxander.controlify.ControllerManager;
|
import dev.isxander.controlify.ControllerManager;
|
||||||
|
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.controller.Controller;
|
||||||
import dev.isxander.controlify.controller.sdl2.SDL2NativesManager;
|
import dev.isxander.controlify.controller.sdl2.SDL2NativesManager;
|
||||||
|
import dev.isxander.controlify.screenop.ScreenControllerEventListener;
|
||||||
import dev.isxander.controlify.utils.Animator;
|
import dev.isxander.controlify.utils.Animator;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.client.gui.ComponentPath;
|
import net.minecraft.client.gui.ComponentPath;
|
||||||
@ -31,7 +35,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ControllerCarouselScreen extends Screen {
|
public class ControllerCarouselScreen extends Screen implements ScreenControllerEventListener {
|
||||||
public static final ResourceLocation CHECKMARK = new ResourceLocation("textures/gui/checkmark.png");
|
public static final ResourceLocation CHECKMARK = new ResourceLocation("textures/gui/checkmark.png");
|
||||||
|
|
||||||
private final Screen parent;
|
private final Screen parent;
|
||||||
@ -40,6 +44,8 @@ public class ControllerCarouselScreen extends Screen {
|
|||||||
private int carouselIndex;
|
private int carouselIndex;
|
||||||
private Animator.AnimationInstance carouselAnimation = null;
|
private Animator.AnimationInstance carouselAnimation = null;
|
||||||
|
|
||||||
|
private Button globalSettingsButton, doneButton;
|
||||||
|
|
||||||
private ControllerCarouselScreen(Screen parent) {
|
private ControllerCarouselScreen(Screen parent) {
|
||||||
super(Component.translatable("controlify.gui.carousel.title"));
|
super(Component.translatable("controlify.gui.carousel.title"));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
@ -75,14 +81,17 @@ public class ControllerCarouselScreen extends Screen {
|
|||||||
|
|
||||||
GridLayout grid = new GridLayout().columnSpacing(10);
|
GridLayout grid = new GridLayout().columnSpacing(10);
|
||||||
GridLayout.RowHelper rowHelper = grid.createRowHelper(2);
|
GridLayout.RowHelper rowHelper = grid.createRowHelper(2);
|
||||||
rowHelper.addChild(Button.builder(Component.translatable("controlify.gui.global_settings.title"), btn -> minecraft.setScreen(GlobalSettingsScreenFactory.createGlobalSettingsScreen(this))).build());
|
globalSettingsButton = rowHelper.addChild(Button.builder(Component.translatable("controlify.gui.global_settings.title"), btn -> minecraft.setScreen(GlobalSettingsScreenFactory.createGlobalSettingsScreen(this))).build());
|
||||||
rowHelper.addChild(Button.builder(CommonComponents.GUI_DONE, btn -> this.onClose()).build());
|
doneButton = rowHelper.addChild(Button.builder(CommonComponents.GUI_DONE, btn -> this.onClose()).build());
|
||||||
grid.visitWidgets(widget -> {
|
grid.visitWidgets(widget -> {
|
||||||
widget.setTabOrderGroup(1);
|
widget.setTabOrderGroup(1);
|
||||||
this.addRenderableWidget(widget);
|
this.addRenderableWidget(widget);
|
||||||
});
|
});
|
||||||
grid.arrangeElements();
|
grid.arrangeElements();
|
||||||
FrameLayout.centerInRectangle(grid, 0, this.height - 36, this.width, 36);
|
FrameLayout.centerInRectangle(grid, 0, this.height - 36, this.width, 36);
|
||||||
|
|
||||||
|
ButtonGuideApi.addGuideToButton(globalSettingsButton, bindings -> bindings.GUI_ABSTRACT_ACTION_1, ButtonRenderPosition.TEXT, ButtonGuidePredicate.ALWAYS);
|
||||||
|
ButtonGuideApi.addGuideToButton(doneButton, bindings -> bindings.GUI_BACK, ButtonRenderPosition.TEXT, ButtonGuidePredicate.ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshControllers() {
|
public void refreshControllers() {
|
||||||
@ -160,6 +169,13 @@ public class ControllerCarouselScreen extends Screen {
|
|||||||
Animator.INSTANCE.play(carouselAnimation);
|
Animator.INSTANCE.play(carouselAnimation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onControllerInput(Controller<?, ?> controller) {
|
||||||
|
if (controller.bindings().GUI_ABSTRACT_ACTION_1.justPressed()) {
|
||||||
|
globalSettingsButton.onPress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
minecraft.setScreen(parent);
|
minecraft.setScreen(parent);
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package dev.isxander.controlify.screenop;
|
||||||
|
|
||||||
|
import dev.isxander.controlify.controller.Controller;
|
||||||
|
|
||||||
|
public interface ScreenControllerEventListener {
|
||||||
|
default void onControllerInput(Controller<?, ?> controller) {}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package dev.isxander.controlify.screenop;
|
package dev.isxander.controlify.screenop;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
|
||||||
import dev.isxander.controlify.Controlify;
|
import dev.isxander.controlify.Controlify;
|
||||||
import dev.isxander.controlify.InputMode;
|
import dev.isxander.controlify.InputMode;
|
||||||
import dev.isxander.controlify.controller.Controller;
|
import dev.isxander.controlify.controller.Controller;
|
||||||
@ -50,6 +49,10 @@ public class ScreenProcessor<T extends Screen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleTabNavigation(controller);
|
handleTabNavigation(controller);
|
||||||
|
|
||||||
|
if (screen instanceof ScreenControllerEventListener eventListener) {
|
||||||
|
eventListener.onControllerInput(controller);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Controller<?, ?> controller, GuiGraphics graphics, float tickDelta) {
|
public void render(Controller<?, ?> controller, GuiGraphics graphics, float tickDelta) {
|
||||||
@ -125,7 +128,7 @@ public class ScreenProcessor<T extends Screen> {
|
|||||||
if (controller.bindings().GUI_PRESS.justPressed()) {
|
if (controller.bindings().GUI_PRESS.justPressed()) {
|
||||||
screen.keyPressed(GLFW.GLFW_KEY_ENTER, 0, 0);
|
screen.keyPressed(GLFW.GLFW_KEY_ENTER, 0, 0);
|
||||||
}
|
}
|
||||||
if (controller.bindings().GUI_BACK.justPressed()) {
|
if (screen.shouldCloseOnEsc() && controller.bindings().GUI_BACK.justPressed()) {
|
||||||
playClackSound();
|
playClackSound();
|
||||||
screen.onClose();
|
screen.onClose();
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,10 @@ public class TitleScreenProcessor extends ScreenProcessor<TitleScreen> {
|
|||||||
public void onWidgetRebuild() {
|
public void onWidgetRebuild() {
|
||||||
super.onWidgetRebuild();
|
super.onWidgetRebuild();
|
||||||
|
|
||||||
|
AbstractButton quitButton = (AbstractButton) getWidget("menu.quit").orElseThrow();
|
||||||
ButtonGuideApi.addGuideToButton(
|
ButtonGuideApi.addGuideToButton(
|
||||||
(AbstractButton) getWidget("menu.quit").orElseThrow(),
|
quitButton,
|
||||||
bindings -> bindings.GUI_BACK,
|
bindings -> quitButton.isFocused() ? bindings.GUI_PRESS : bindings.GUI_BACK,
|
||||||
ButtonRenderPosition.TEXT,
|
ButtonRenderPosition.TEXT,
|
||||||
ButtonGuidePredicate.ALWAYS
|
ButtonGuidePredicate.ALWAYS
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user