forked from Clones/Controlify
✅ Complete container guide
This commit is contained in:
@ -9,7 +9,6 @@ import dev.isxander.controlify.controller.Controller;
|
|||||||
import dev.isxander.controlify.controller.ControllerState;
|
import dev.isxander.controlify.controller.ControllerState;
|
||||||
import dev.isxander.controlify.controller.sdl2.SDL2NativesManager;
|
import dev.isxander.controlify.controller.sdl2.SDL2NativesManager;
|
||||||
import dev.isxander.controlify.debug.DebugProperties;
|
import dev.isxander.controlify.debug.DebugProperties;
|
||||||
import dev.isxander.controlify.gui.guide.ContainerButtonGuide;
|
|
||||||
import dev.isxander.controlify.gui.screen.ControllerDeadzoneCalibrationScreen;
|
import dev.isxander.controlify.gui.screen.ControllerDeadzoneCalibrationScreen;
|
||||||
import dev.isxander.controlify.gui.screen.SDLOnboardingScreen;
|
import dev.isxander.controlify.gui.screen.SDLOnboardingScreen;
|
||||||
import dev.isxander.controlify.screenop.ScreenProcessorProvider;
|
import dev.isxander.controlify.screenop.ScreenProcessorProvider;
|
||||||
@ -184,7 +183,6 @@ public class Controlify implements ControlifyApi {
|
|||||||
|
|
||||||
this.inGameInputHandler = null;
|
this.inGameInputHandler = null;
|
||||||
this.virtualMouseHandler = new VirtualMouseHandler();
|
this.virtualMouseHandler = new VirtualMouseHandler();
|
||||||
//ContainerButtonGuide.setup();
|
|
||||||
|
|
||||||
controllerHIDService = new ControllerHIDService();
|
controllerHIDService = new ControllerHIDService();
|
||||||
controllerHIDService.start();
|
controllerHIDService.start();
|
||||||
|
@ -8,6 +8,7 @@ import dev.isxander.controlify.gui.guide.ContainerGuideCtx;
|
|||||||
import dev.isxander.controlify.gui.guide.GuideAction;
|
import dev.isxander.controlify.gui.guide.GuideAction;
|
||||||
import dev.isxander.controlify.gui.guide.GuideActionRenderer;
|
import dev.isxander.controlify.gui.guide.GuideActionRenderer;
|
||||||
import dev.isxander.controlify.gui.layout.AnchorPoint;
|
import dev.isxander.controlify.gui.layout.AnchorPoint;
|
||||||
|
import dev.isxander.controlify.gui.layout.ColumnLayoutComponent;
|
||||||
import dev.isxander.controlify.gui.layout.PositionedComponent;
|
import dev.isxander.controlify.gui.layout.PositionedComponent;
|
||||||
import dev.isxander.controlify.gui.layout.RowLayoutComponent;
|
import dev.isxander.controlify.gui.layout.RowLayoutComponent;
|
||||||
import dev.isxander.controlify.mixins.feature.guide.screen.AbstractContainerScreenAccessor;
|
import dev.isxander.controlify.mixins.feature.guide.screen.AbstractContainerScreenAccessor;
|
||||||
@ -26,8 +27,8 @@ import java.util.Optional;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<?>> extends ScreenProcessor<T> {
|
public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<?>> extends ScreenProcessor<T> {
|
||||||
private PositionedComponent<RowLayoutComponent<GuideActionRenderer<ContainerGuideCtx>>> leftLayout;
|
private PositionedComponent<ColumnLayoutComponent<RowLayoutComponent<GuideActionRenderer<ContainerGuideCtx>>>> leftLayout;
|
||||||
private PositionedComponent<RowLayoutComponent<GuideActionRenderer<ContainerGuideCtx>>> rightLayout;
|
private PositionedComponent<ColumnLayoutComponent<RowLayoutComponent<GuideActionRenderer<ContainerGuideCtx>>>> rightLayout;
|
||||||
|
|
||||||
private final Supplier<Slot> hoveredSlot;
|
private final Supplier<Slot> hoveredSlot;
|
||||||
private final ClickSlotFunction clickSlotFunction;
|
private final ClickSlotFunction clickSlotFunction;
|
||||||
@ -40,23 +41,44 @@ public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleScreenVMouse(Controller<?, ?> controller, VirtualMouseHandler vmouse) {
|
protected void handleScreenVMouse(Controller<?, ?> controller, VirtualMouseHandler vmouse) {
|
||||||
if (controller.bindings().DROP.justPressed()) {
|
var accessor = (AbstractContainerScreenAccessor) screen;
|
||||||
Slot slot = hoveredSlot.get();
|
ContainerGuideCtx ctx = new ContainerGuideCtx(hoveredSlot.get(), screen.getMenu().getCarried(), accessor.invokeHasClickedOutside(vmouse.getCurrentX(1f), vmouse.getCurrentY(1f), accessor.getLeftPos(), accessor.getTopPos(), 0));
|
||||||
if (slot != null && slot.hasItem()) {
|
|
||||||
clickSlotFunction.clickSlot(slot, slot.index, 0, ClickType.THROW);
|
Slot hoveredSlot = this.hoveredSlot.get();
|
||||||
|
if (hoveredSlot != null) {
|
||||||
|
if (controller.bindings().DROP.justPressed() && hoveredSlot.hasItem()) {
|
||||||
|
clickSlotFunction.clickSlot(hoveredSlot, hoveredSlot.index, 0, ClickType.THROW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (controller.bindings().INV_SELECT.justPressed()) {
|
||||||
|
clickSlotFunction.clickSlot(hoveredSlot, hoveredSlot.index, 0, ClickType.PICKUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (controller.bindings().INV_QUICK_MOVE.justPressed()) {
|
||||||
|
clickSlotFunction.clickSlot(hoveredSlot, hoveredSlot.index, 0, ClickType.QUICK_MOVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (controller.bindings().INV_TAKE_HALF.justPressed()) {
|
||||||
|
clickSlotFunction.clickSlot(hoveredSlot, hoveredSlot.index, 1, ClickType.PICKUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (controller.bindings().SWAP_HANDS.justPressed()) {
|
||||||
|
clickSlotFunction.clickSlot(hoveredSlot, hoveredSlot.index, 40, ClickType.SWAP);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vmouse.handleCompatibilityBinds(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leftLayout != null && rightLayout != null) {
|
if (leftLayout != null && rightLayout != null) {
|
||||||
var accessor = (AbstractContainerScreenAccessor) screen;
|
for (var row : leftLayout.getComponent().getChildComponents()) {
|
||||||
|
for (var element : row.getChildComponents()) {
|
||||||
ContainerGuideCtx ctx = new ContainerGuideCtx(hoveredSlot.get(), screen.getMenu().getCarried(), accessor.invokeHasClickedOutside(vmouse.getCurrentX(1f), vmouse.getCurrentY(1f), accessor.getLeftPos(), accessor.getTopPos(), 0));
|
element.updateName(ctx);
|
||||||
|
}
|
||||||
for (var element : leftLayout.getComponent().getChildComponents()) {
|
|
||||||
element.updateName(ctx);
|
|
||||||
}
|
}
|
||||||
for (var element : rightLayout.getComponent().getChildComponents()) {
|
for (var row : rightLayout.getComponent().getChildComponents()) {
|
||||||
element.updateName(ctx);
|
for (var element : row.getChildComponents()) {
|
||||||
|
element.updateName(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leftLayout.updatePosition();
|
leftLayout.updatePosition();
|
||||||
@ -75,35 +97,40 @@ public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<
|
|||||||
}
|
}
|
||||||
|
|
||||||
leftLayout = new PositionedComponent<>(
|
leftLayout = new PositionedComponent<>(
|
||||||
RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder()
|
ColumnLayoutComponent.<RowLayoutComponent<GuideActionRenderer<ContainerGuideCtx>>>builder()
|
||||||
.spacing(5)
|
.spacing(2)
|
||||||
.rowPadding(0)
|
.elementPosition(ColumnLayoutComponent.ElementPosition.LEFT)
|
||||||
.elementPosition(RowLayoutComponent.ElementPosition.MIDDLE)
|
.colPadding(2)
|
||||||
.element(new GuideActionRenderer<>(
|
.element(RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder()
|
||||||
new GuideAction<>(bindings.VMOUSE_LCLICK, ctx -> {
|
.spacing(5)
|
||||||
if (!ctx.holdingItem().isEmpty())
|
.rowPadding(0)
|
||||||
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().hasItem())
|
.elementPosition(RowLayoutComponent.ElementPosition.MIDDLE)
|
||||||
if (ctx.hoveredSlot().mayPlace(ctx.holdingItem()))
|
.element(new GuideActionRenderer<>(
|
||||||
if (ctx.holdingItem().getCount() > 1)
|
new GuideAction<>(bindings.VMOUSE_LCLICK, ctx -> {
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.place_all"));
|
if (!ctx.holdingItem().isEmpty())
|
||||||
else
|
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().hasItem())
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.place_one"));
|
if (ctx.hoveredSlot().mayPlace(ctx.holdingItem()))
|
||||||
else
|
if (ctx.holdingItem().getCount() > 1)
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.swap"));
|
return Optional.of(Component.translatable("controlify.guide.container.place_all"));
|
||||||
else if (ctx.cursorOutsideContainer())
|
else
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.drop"));
|
return Optional.of(Component.translatable("controlify.guide.container.place_one"));
|
||||||
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().hasItem())
|
else
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.take"));
|
return Optional.of(Component.translatable("controlify.guide.container.swap"));
|
||||||
return Optional.empty();
|
else if (ctx.cursorOutsideContainer())
|
||||||
}),
|
return Optional.of(Component.translatable("controlify.guide.container.drop"));
|
||||||
false, false
|
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().hasItem())
|
||||||
))
|
return Optional.of(Component.translatable("controlify.guide.container.take"));
|
||||||
.element(new GuideActionRenderer<>(
|
return Optional.empty();
|
||||||
new GuideAction<>(bindings.GUI_BACK, ctx -> {
|
}),
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.exit"));
|
false, false
|
||||||
}),
|
))
|
||||||
false, false
|
.element(new GuideActionRenderer<>(
|
||||||
))
|
new GuideAction<>(bindings.GUI_BACK, ctx -> {
|
||||||
|
return Optional.of(Component.translatable("controlify.guide.container.exit"));
|
||||||
|
}),
|
||||||
|
false, false
|
||||||
|
))
|
||||||
|
.build())
|
||||||
.build(),
|
.build(),
|
||||||
AnchorPoint.BOTTOM_LEFT,
|
AnchorPoint.BOTTOM_LEFT,
|
||||||
0, 0,
|
0, 0,
|
||||||
@ -111,26 +138,46 @@ public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<
|
|||||||
);
|
);
|
||||||
|
|
||||||
rightLayout = new PositionedComponent<>(
|
rightLayout = new PositionedComponent<>(
|
||||||
RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder()
|
ColumnLayoutComponent.<RowLayoutComponent<GuideActionRenderer<ContainerGuideCtx>>>builder()
|
||||||
.spacing(5)
|
.spacing(2)
|
||||||
.rowPadding(0)
|
.elementPosition(ColumnLayoutComponent.ElementPosition.RIGHT)
|
||||||
.elementPosition(RowLayoutComponent.ElementPosition.MIDDLE)
|
.colPadding(2)
|
||||||
.element(new GuideActionRenderer<>(
|
.element(RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder()
|
||||||
new GuideAction<>(bindings.VMOUSE_RCLICK, ctx -> {
|
.spacing(5)
|
||||||
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().getItem().getCount() > 1 && ctx.holdingItem().isEmpty())
|
.rowPadding(0)
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.take_half"));
|
.elementPosition(RowLayoutComponent.ElementPosition.MIDDLE)
|
||||||
if (ctx.hoveredSlot() != null && !ctx.holdingItem().isEmpty() && ctx.hoveredSlot().mayPlace(ctx.holdingItem()))
|
.element(new GuideActionRenderer<>(
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.take_one"));
|
new GuideAction<>(bindings.DROP, ctx -> {
|
||||||
return Optional.empty();
|
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().hasItem())
|
||||||
}),
|
return Optional.of(Component.translatable("controlify.guide.container.drop"));
|
||||||
true, false
|
return Optional.empty();
|
||||||
))
|
}),
|
||||||
.element(new GuideActionRenderer<>(
|
true, false
|
||||||
new GuideAction<>(bindings.VMOUSE_SHIFT_CLICK, ctx -> {
|
))
|
||||||
return Optional.of(Component.translatable("controlify.guide.container.quick_move"));
|
.build())
|
||||||
}),
|
.element(RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder()
|
||||||
true, false
|
.spacing(5)
|
||||||
))
|
.rowPadding(0)
|
||||||
|
.elementPosition(RowLayoutComponent.ElementPosition.MIDDLE)
|
||||||
|
.element(new GuideActionRenderer<>(
|
||||||
|
new GuideAction<>(bindings.VMOUSE_RCLICK, ctx -> {
|
||||||
|
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().getItem().getCount() > 1 && ctx.holdingItem().isEmpty())
|
||||||
|
return Optional.of(Component.translatable("controlify.guide.container.take_half"));
|
||||||
|
if (ctx.hoveredSlot() != null && !ctx.holdingItem().isEmpty() && ctx.hoveredSlot().mayPlace(ctx.holdingItem()))
|
||||||
|
return Optional.of(Component.translatable("controlify.guide.container.take_one"));
|
||||||
|
return Optional.empty();
|
||||||
|
}),
|
||||||
|
true, false
|
||||||
|
))
|
||||||
|
.element(new GuideActionRenderer<>(
|
||||||
|
new GuideAction<>(bindings.VMOUSE_SHIFT_CLICK, ctx -> {
|
||||||
|
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().hasItem())
|
||||||
|
return Optional.of(Component.translatable("controlify.guide.container.quick_move"));
|
||||||
|
return Optional.empty();
|
||||||
|
}),
|
||||||
|
true, false
|
||||||
|
))
|
||||||
|
.build())
|
||||||
.build(),
|
.build(),
|
||||||
AnchorPoint.BOTTOM_RIGHT,
|
AnchorPoint.BOTTOM_RIGHT,
|
||||||
0, 0,
|
0, 0,
|
||||||
|
@ -89,19 +89,19 @@ public class VirtualMouseHandler {
|
|||||||
targetX = Mth.clamp(targetX, 0, minecraft.getWindow().getWidth());
|
targetX = Mth.clamp(targetX, 0, minecraft.getWindow().getWidth());
|
||||||
targetY = Mth.clamp(targetY, 0, minecraft.getWindow().getHeight());
|
targetY = Mth.clamp(targetY, 0, minecraft.getWindow().getHeight());
|
||||||
|
|
||||||
if (controller.bindings().GUI_BACK.justPressed() && minecraft.screen != null) {
|
scrollY += controller.bindings().VMOUSE_SCROLL_UP.state() - controller.bindings().VMOUSE_SCROLL_DOWN.state();
|
||||||
ScreenProcessor.playClackSound();
|
|
||||||
minecraft.screen.onClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ScreenProcessorProvider.provide(minecraft.screen).virtualMouseBehaviour().hasCursor()) {
|
if (!ScreenProcessorProvider.provide(minecraft.screen).virtualMouseBehaviour().hasCursor()) {
|
||||||
handleCompatibilityBinds(controller);
|
handleCompatibilityBinds(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (controller.bindings().GUI_BACK.justPressed() && minecraft.screen != null) {
|
||||||
|
ScreenProcessor.playClackSound();
|
||||||
|
minecraft.screen.onClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCompatibilityBinds(Controller<?, ?> controller) {
|
public void handleCompatibilityBinds(Controller<?, ?> controller) {
|
||||||
scrollY += controller.bindings().VMOUSE_SCROLL_UP.state() - controller.bindings().VMOUSE_SCROLL_DOWN.state();
|
|
||||||
|
|
||||||
var mouseHandler = (MouseHandlerAccessor) minecraft.mouseHandler;
|
var mouseHandler = (MouseHandlerAccessor) minecraft.mouseHandler;
|
||||||
var keyboardHandler = (KeyboardHandlerAccessor) minecraft.keyboardHandler;
|
var keyboardHandler = (KeyboardHandlerAccessor) minecraft.keyboardHandler;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user