forked from Clones/Controlify
compound joysticks, button guide in screens, improve API
This commit is contained in:
@ -1,8 +0,0 @@
|
||||
package dev.isxander.controlify.api.buttonguide;
|
||||
|
||||
/**
|
||||
* Whether the action should be on the left or right list.
|
||||
*/
|
||||
public enum ActionLocation {
|
||||
LEFT, RIGHT
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package dev.isxander.controlify.api.buttonguide;
|
||||
|
||||
/**
|
||||
* Defines how the action is sorted in the list. All default Controlify actions are {@link #NORMAL}.
|
||||
*/
|
||||
public enum ActionPriority {
|
||||
LOWEST,
|
||||
LOW,
|
||||
NORMAL,
|
||||
HIGH,
|
||||
HIGHEST
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package dev.isxander.controlify.api.buttonguide;
|
||||
|
||||
import dev.isxander.controlify.bindings.ControllerBinding;
|
||||
import dev.isxander.controlify.bindings.ControllerBindings;
|
||||
import dev.isxander.controlify.gui.ButtonGuideRenderer;
|
||||
import net.minecraft.client.gui.components.AbstractButton;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Adds a guide to a button. This does not invoke the button press on binding trigger, only renders the guide.
|
||||
* This should be called every time a button is initialised, like in {@link Screen#init()}
|
||||
*/
|
||||
public interface ButtonGuideApi {
|
||||
/**
|
||||
* Makes the button render the image of the binding specified.
|
||||
* This does not invoke the button press on binding trigger, only renders the guide.
|
||||
* Custom behaviour should be handled inside a {@link dev.isxander.controlify.screenop.ScreenProcessor} or {@link dev.isxander.controlify.screenop.ComponentProcessor}
|
||||
*
|
||||
* @param button button to render the guide for
|
||||
* @param binding gets the binding to render
|
||||
* @param position where the guide should be rendered relative to the button
|
||||
* @param renderPredicate whether the guide should be rendered
|
||||
*/
|
||||
static <T extends AbstractButton> void addGuideToButton(
|
||||
T button,
|
||||
Function<ControllerBindings<?>, ControllerBinding<?>> binding,
|
||||
ButtonRenderPosition position,
|
||||
ButtonGuidePredicate<T> renderPredicate) {
|
||||
ButtonGuideRenderer.registerBindingForButton(button, binding, position, renderPredicate);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package dev.isxander.controlify.api.buttonguide;
|
||||
|
||||
import net.minecraft.client.gui.components.AbstractButton;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ButtonGuidePredicate<T extends AbstractButton> {
|
||||
boolean shouldDisplay(T button);
|
||||
|
||||
ButtonGuidePredicate<AbstractButton> FOCUS_ONLY = AbstractWidget::isFocused;
|
||||
ButtonGuidePredicate<AbstractButton> ALWAYS = btn -> true;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package dev.isxander.controlify.api.buttonguide;
|
||||
|
||||
import dev.isxander.controlify.bindings.ControllerBinding;
|
||||
|
||||
/**
|
||||
* Allows you to register your own actions to the button guide.
|
||||
* This should be called through {@link dev.isxander.controlify.api.event.ControlifyEvents#BUTTON_GUIDE_REGISTRY} as
|
||||
* these should be called every time the guide is initialised.
|
||||
*/
|
||||
public interface ButtonGuideRegistry {
|
||||
/**
|
||||
* Registers a new action to the button guide.
|
||||
*
|
||||
* @param binding the binding for the action, if unbound, the action is hidden.
|
||||
* @param location the location of the action, left or right.
|
||||
* @param priority the priority of the action, used to sort the list.
|
||||
* @param supplier the supplier for the name of the action. can be empty to hide the action.
|
||||
*/
|
||||
void registerGuideAction(ControllerBinding<?> binding, ActionLocation location, ActionPriority priority, GuideActionNameSupplier supplier);
|
||||
|
||||
/**
|
||||
* Registers a new action to the button guide.
|
||||
*
|
||||
* @param binding the binding for the action, if unbound, the action is hidden.
|
||||
* @param location the location of the action, left or right.
|
||||
* @param supplier the supplier for the name of the action. can be empty to hide the action.
|
||||
*/
|
||||
void registerGuideAction(ControllerBinding<?> binding, ActionLocation location, GuideActionNameSupplier supplier);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package dev.isxander.controlify.api.buttonguide;
|
||||
|
||||
/**
|
||||
* Where the guide should be rendered relative to the button.
|
||||
*/
|
||||
public enum ButtonRenderPosition {
|
||||
/**
|
||||
* Renders outside the button the left.
|
||||
*/
|
||||
LEFT,
|
||||
/**
|
||||
* Renders outside the button the right.
|
||||
*/
|
||||
RIGHT,
|
||||
/**
|
||||
* Renders inside the button on the left of the button text.
|
||||
*/
|
||||
TEXT
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package dev.isxander.controlify.api.buttonguide;
|
||||
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Supplies the text to display for a guide action based on the current context.
|
||||
* If return is empty, the action will not be displayed.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface GuideActionNameSupplier {
|
||||
Optional<Component> supply(
|
||||
Minecraft client,
|
||||
LocalPlayer player,
|
||||
ClientLevel level,
|
||||
HitResult hitResult,
|
||||
Controller<?, ?> controller
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user