Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ public final class ControlifyBindings {
.id("controlify", "radial_axis_right")
.category(RADIAL_CATEGORY)
.allowedContexts(BindContext.RADIAL_MENU));
//? if neoforge {
public static final InputBindingSupplier RADIAL_SEND_KEY = ControlifyBindApi.get().registerBinding(builder -> builder
.id("controlify", "radial_send_key")
.category(RADIAL_CATEGORY)
.allowedContexts(BindContext.RADIAL_MENU));
//?}

public static final InputBindingSupplier VMOUSE_MOVE_UP = ControlifyBindApi.get().registerBinding(builder -> builder
.id("controlify", "vmouse_move_up")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public Config(@Nullable ControllerMapping typeProvidedMapping) {

public boolean mixedInput = false;

//? if neoforge {
public boolean setKeysDownWithRadialEvent = true;
//?}

public boolean keepDefaultBindings = false;

public ResourceLocation[] radialActions = new ResourceLocation[8];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ private ConfigCategory createAdvancedCategory(ControllerEntity controller) {
.controller(TickBoxControllerBuilder::create)
.build()));

//? if neoforge {
input.ifPresent(inputComponent -> builder.option(Option.<Boolean>createBuilder()
.name(Component.translatable("controlify.gui.set_keys_down_with_radial_event"))
.description(OptionDescription.of(Component.translatable("controlify.gui.set_keys_down_with_radial_event.tooltip")))
.binding(inputComponent.defObj().setKeysDownWithRadialEvent, () -> inputComponent.confObj().setKeysDownWithRadialEvent, v -> inputComponent.confObj().setKeysDownWithRadialEvent = v)
.controller(TickBoxControllerBuilder::create)
.build()));
//?}

makeVibrationGroup(controller).ifPresent(builder::group);
makeGyroGroup(controller).ifPresent(builder::group);
makeControllerMappingGroup(controller).ifPresent(builder::group);
Expand Down
130 changes: 118 additions & 12 deletions src/main/java/dev/isxander/controlify/gui/screen/RadialMenuScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import dev.isxander.controlify.api.bind.InputBinding;
import dev.isxander.controlify.controller.ControllerEntity;
import dev.isxander.controlify.controller.haptic.HapticEffects;
import dev.isxander.controlify.gui.layout.AnchorPoint;
import dev.isxander.controlify.gui.layout.PositionedComponent;
//import dev.isxander.controlify.gui.layout.AnchorPoint;
//import dev.isxander.controlify.gui.layout.PositionedComponent;
import dev.isxander.controlify.screenop.ComponentProcessor;
import dev.isxander.controlify.screenop.ScreenControllerEventListener;
import dev.isxander.controlify.screenop.ScreenProcessor;
Expand All @@ -32,17 +32,44 @@
import net.minecraft.client.gui.navigation.ScreenRectangle;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.CommonComponents;
//import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.Nullable;

//? if neoforge {
/*import net.minecraft.client.KeyMapping;
import org.lwjgl.glfw.GLFW;
import net.neoforged.neoforge.client.event.InputEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.api.distmarker.Dist;

//? if >= 1.21.9 {
//import net.minecraft.client.input.KeyEvent;
//?}

//? if < 1.21.4 {
//import dev.isxander.controlify.mixins.feature.bind.KeyMappingAccessor;
//?}

*///?}

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

//import java.util.Optional;

//? if neoforge {
/*//? if < 1.21.8 {
@EventBusSubscriber(modid = "controlify", bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT)
//?} else {
//@EventBusSubscriber(modid = "controlify", value = Dist.CLIENT)
//?}
*///?}
public class RadialMenuScreen extends Screen implements ScreenControllerEventListener, ScreenProcessorProvider {
public static final ResourceLocation EMPTY_ACTION = CUtil.rl("empty_action");

Expand Down Expand Up @@ -109,7 +136,7 @@ protected void init() {
}
animation.play();

if (editMode != null) {
// if (editMode != null) {
// var exitGuide = addRenderableWidget(new PositionedComponent<>(
// new GuideActionRenderer(
// new GuideAction(
Expand All @@ -126,19 +153,98 @@ protected void init() {
//
// exitGuide.getComponent().updateName(null);
// exitGuide.updatePosition(width, height);
// }
}

//? if neoforge {
/*private static KeyMapping keyToPress = null;
private static boolean setKeysDownWithRadialEvent = true;

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onKeyInputBefore(InputEvent.Key event) {
if (keyToPress != null) {
switch (event.getAction()) {
case GLFW.GLFW_PRESS:
if (setKeysDownWithRadialEvent)
keyToPress.setDown(true);
break;
case GLFW.GLFW_RELEASE:
if (setKeysDownWithRadialEvent)
keyToPress.setDown(false);
keyToPress = null;
break;
}
}
}

@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onKeyInputAfter(InputEvent.Key event) {
if (keyToPress != null) {
NeoForge.EVENT_BUS.post(
new InputEvent.Key(
//? if >= 1.21.9 {
new KeyEvent(keyToPress.getKey().getValue(), 0, 0),
GLFW.GLFW_RELEASE
//?} else {
//keyToPress.getKey().getValue(),
//0,
//GLFW.GLFW_RELEASE,
//0
//?}
)
);
}
}
*///?}

@Override
public void onControllerInput(ControllerEntity controller) {
if (this.controller != controller) return;

if (editMode == null && !openBind.digitalNow()) {
if (selectedButton != -1 && buttons[selectedButton].invoke()) {
playClickSound();
if (editMode == null) {
//? if neoforge {
/*if (ControlifyBindings.RADIAL_SEND_KEY.on(controller).justPressed()) {
onClose();

if (selectedButton != -1) {
@Nullable KeyMapping km =
//? if >= 1.21.4 {
KeyMapping
//?} else {
//KeyMappingAccessor.getAll()
//?}
.get(controller.input().orElseThrow().confObj().radialActions[selectedButton].getPath());

keyToPress = km;
setKeysDownWithRadialEvent = controller.input().orElseThrow().confObj().setKeysDownWithRadialEvent;

if (km != null) {
NeoForge.EVENT_BUS.post(
new InputEvent.Key(
//? if >= 1.21.9 {
new KeyEvent(km.getKey().getValue(), 0, 0),
GLFW.GLFW_PRESS
//?} else {
//km.getKey().getValue(),
//0,
//GLFW.GLFW_PRESS,
//0
//?}
)
);
playClickSound();
}
}
}
*///?}

onClose();
if (!openBind.digitalNow()) {
if (selectedButton != -1 && buttons[selectedButton].invoke()) {
playClickSound();
}

onClose();
}
}

if (editMode != null && ControlifyBindings.GUI_BACK.on(controller).justPressed()) {
Expand Down Expand Up @@ -376,8 +482,8 @@ public ScreenRectangle getRectangle() {
public class ActionSelectList implements Renderable, ContainerEventHandler, NarratableEntry, ComponentProcessor {
private final int radialIndex;

private int x, y;
private int width, height;
private final int x, y;
private final int width, height;
private final int itemHeight = 10;
private int scrollOffset;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.isxander.controlify.mixins.feature.bind;

import net.minecraft.client.KeyMapping;
import org.apache.commons.lang3.NotImplementedException;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Map;

@Mixin(KeyMapping.class)
public interface KeyMappingAccessor {
//? < 1.21.4 && neoforge {
@Accessor("ALL")
static Map<String, KeyMapping> getAll() {
throw new NotImplementedException("Should be overwritten by Accessor");
}
//?}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/controlify/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
"controlify.config.category.advanced": "Advanced",
"controlify.gui.mixed_input": "Mixed Input",
"controlify.gui.mixed_input.tooltip": "If enabled, Controlify will allow you to use both this controller and keyboard/mouse at the same time. This should be used when pairing with Steam Input, where certain advanced controller actions needs to be mapped to these inputs, rather than a gamepad. Be aware, this prevents you from entering normal keyboard/mouse mode whilst this controller is in use.",
"controlify.gui.set_keys_down_with_radial_event": "Set Keys Down With Radial Event",
"controlify.gui.set_keys_down_with_radial_event.tooltip": "When using 'Radial Menu Send Key', should the corresponding keybind be set down?",
"controlify.gui.controller_mapping.explanation": "Controller mapping allows you to convert your current controller inputs into something else. You can, for example, emulate a gamepad with a flightstick directly in-game.",
"controlify.gui.group.controller_mapping": "Controller Mapping",
"controlify.gui.create_gamepad_mapping": "Map to Gamepad",
Expand Down Expand Up @@ -309,6 +311,8 @@
"controlify.binding.controlify.radial_axis_down": "Radial Menu Down",
"controlify.binding.controlify.radial_axis_left": "Radial Menu Left",
"controlify.binding.controlify.radial_axis_right": "Radial Menu Right",
"controlify.binding.controlify.radial_send_key": "Radial Menu Send Key",
"controlify.binding.controlify.radial_send_key.desc": "Click this to send a physical button press instead of an event. This requires the key to be bound in your minecraft controls menu.",
"controlify.binding.controlify.game_mode_switcher": "Game Mode Switcher",
"controlify.binding.controlify.vmouse_move_up": "VMouse Move Up",
"controlify.binding.controlify.vmouse_move_down": "VMouse Move Down",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/controlify.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"core.MouseHandlerMixin",
"feature.accessibility.LocalPlayerMixin",
"feature.bind.GuiMixin",
"feature.bind.KeyMappingAccessor",
"feature.bind.KeyMappingMixin",
"feature.bind.MinecraftMixin",
"feature.bind.ToggleKeyMappingMixin",
Expand Down
Loading