1
0
forked from Clones/Controlify

✏️ Add/improve button guides for carousel screen and title screen respectively

This commit is contained in:
isXander
2023-06-04 12:28:09 +01:00
parent 6fd6b5a221
commit b68f718901
4 changed files with 34 additions and 7 deletions

View File

@ -3,8 +3,12 @@ package dev.isxander.controlify.gui.screen;
import com.google.common.collect.ImmutableList;
import dev.isxander.controlify.Controlify;
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.sdl2.SDL2NativesManager;
import dev.isxander.controlify.screenop.ScreenControllerEventListener;
import dev.isxander.controlify.utils.Animator;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.ComponentPath;
@ -31,7 +35,7 @@ import org.jetbrains.annotations.Nullable;
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");
private final Screen parent;
@ -40,6 +44,8 @@ public class ControllerCarouselScreen extends Screen {
private int carouselIndex;
private Animator.AnimationInstance carouselAnimation = null;
private Button globalSettingsButton, doneButton;
private ControllerCarouselScreen(Screen parent) {
super(Component.translatable("controlify.gui.carousel.title"));
this.parent = parent;
@ -75,14 +81,17 @@ public class ControllerCarouselScreen extends Screen {
GridLayout grid = new GridLayout().columnSpacing(10);
GridLayout.RowHelper rowHelper = grid.createRowHelper(2);
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());
globalSettingsButton = rowHelper.addChild(Button.builder(Component.translatable("controlify.gui.global_settings.title"), btn -> minecraft.setScreen(GlobalSettingsScreenFactory.createGlobalSettingsScreen(this))).build());
doneButton = rowHelper.addChild(Button.builder(CommonComponents.GUI_DONE, btn -> this.onClose()).build());
grid.visitWidgets(widget -> {
widget.setTabOrderGroup(1);
this.addRenderableWidget(widget);
});
grid.arrangeElements();
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() {
@ -160,6 +169,13 @@ public class ControllerCarouselScreen extends Screen {
Animator.INSTANCE.play(carouselAnimation);
}
@Override
public void onControllerInput(Controller<?, ?> controller) {
if (controller.bindings().GUI_ABSTRACT_ACTION_1.justPressed()) {
globalSettingsButton.onPress();
}
}
@Override
public void onClose() {
minecraft.setScreen(parent);

View File

@ -0,0 +1,7 @@
package dev.isxander.controlify.screenop;
import dev.isxander.controlify.controller.Controller;
public interface ScreenControllerEventListener {
default void onControllerInput(Controller<?, ?> controller) {}
}

View File

@ -1,6 +1,5 @@
package dev.isxander.controlify.screenop;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.isxander.controlify.Controlify;
import dev.isxander.controlify.InputMode;
import dev.isxander.controlify.controller.Controller;
@ -50,6 +49,10 @@ public class ScreenProcessor<T extends Screen> {
}
handleTabNavigation(controller);
if (screen instanceof ScreenControllerEventListener eventListener) {
eventListener.onControllerInput(controller);
}
}
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()) {
screen.keyPressed(GLFW.GLFW_KEY_ENTER, 0, 0);
}
if (controller.bindings().GUI_BACK.justPressed()) {
if (screen.shouldCloseOnEsc() && controller.bindings().GUI_BACK.justPressed()) {
playClackSound();
screen.onClose();
}

View File

@ -33,9 +33,10 @@ public class TitleScreenProcessor extends ScreenProcessor<TitleScreen> {
public void onWidgetRebuild() {
super.onWidgetRebuild();
AbstractButton quitButton = (AbstractButton) getWidget("menu.quit").orElseThrow();
ButtonGuideApi.addGuideToButton(
(AbstractButton) getWidget("menu.quit").orElseThrow(),
bindings -> bindings.GUI_BACK,
quitButton,
bindings -> quitButton.isFocused() ? bindings.GUI_PRESS : bindings.GUI_BACK,
ButtonRenderPosition.TEXT,
ButtonGuidePredicate.ALWAYS
);