1
0
forked from Clones/Controlify

Complete container guide

This commit is contained in:
isXander
2023-05-14 22:29:58 +01:00
parent f557c1ab05
commit 8dd2cd181e
3 changed files with 117 additions and 72 deletions

View File

@ -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();

View File

@ -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,24 +41,45 @@ 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));
for (var element : leftLayout.getComponent().getChildComponents()) {
element.updateName(ctx); element.updateName(ctx);
} }
for (var element : rightLayout.getComponent().getChildComponents()) { }
for (var row : rightLayout.getComponent().getChildComponents()) {
for (var element : row.getChildComponents()) {
element.updateName(ctx); element.updateName(ctx);
} }
}
leftLayout.updatePosition(); leftLayout.updatePosition();
rightLayout.updatePosition(); rightLayout.updatePosition();
@ -75,7 +97,11 @@ public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<
} }
leftLayout = new PositionedComponent<>( leftLayout = new PositionedComponent<>(
RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder() ColumnLayoutComponent.<RowLayoutComponent<GuideActionRenderer<ContainerGuideCtx>>>builder()
.spacing(2)
.elementPosition(ColumnLayoutComponent.ElementPosition.LEFT)
.colPadding(2)
.element(RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder()
.spacing(5) .spacing(5)
.rowPadding(0) .rowPadding(0)
.elementPosition(RowLayoutComponent.ElementPosition.MIDDLE) .elementPosition(RowLayoutComponent.ElementPosition.MIDDLE)
@ -104,6 +130,7 @@ public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<
}), }),
false, false false, false
)) ))
.build())
.build(), .build(),
AnchorPoint.BOTTOM_LEFT, AnchorPoint.BOTTOM_LEFT,
0, 0, 0, 0,
@ -111,7 +138,24 @@ public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<
); );
rightLayout = new PositionedComponent<>( rightLayout = new PositionedComponent<>(
RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder() ColumnLayoutComponent.<RowLayoutComponent<GuideActionRenderer<ContainerGuideCtx>>>builder()
.spacing(2)
.elementPosition(ColumnLayoutComponent.ElementPosition.RIGHT)
.colPadding(2)
.element(RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder()
.spacing(5)
.rowPadding(0)
.elementPosition(RowLayoutComponent.ElementPosition.MIDDLE)
.element(new GuideActionRenderer<>(
new GuideAction<>(bindings.DROP, ctx -> {
if (ctx.hoveredSlot() != null && ctx.hoveredSlot().hasItem())
return Optional.of(Component.translatable("controlify.guide.container.drop"));
return Optional.empty();
}),
true, false
))
.build())
.element(RowLayoutComponent.<GuideActionRenderer<ContainerGuideCtx>>builder()
.spacing(5) .spacing(5)
.rowPadding(0) .rowPadding(0)
.elementPosition(RowLayoutComponent.ElementPosition.MIDDLE) .elementPosition(RowLayoutComponent.ElementPosition.MIDDLE)
@ -127,10 +171,13 @@ public class AbstractContainerScreenProcessor<T extends AbstractContainerScreen<
)) ))
.element(new GuideActionRenderer<>( .element(new GuideActionRenderer<>(
new GuideAction<>(bindings.VMOUSE_SHIFT_CLICK, ctx -> { 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.of(Component.translatable("controlify.guide.container.quick_move"));
return Optional.empty();
}), }),
true, false true, false
)) ))
.build())
.build(), .build(),
AnchorPoint.BOTTOM_RIGHT, AnchorPoint.BOTTOM_RIGHT,
0, 0, 0, 0,

View File

@ -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;