forked from Clones/Controlify
small bits
This commit is contained in:
@ -49,7 +49,7 @@ public class YACLHelper {
|
|||||||
.name(Component.translatable("controlify.gui.current_controller"))
|
.name(Component.translatable("controlify.gui.current_controller"))
|
||||||
.tooltip(Component.translatable("controlify.gui.current_controller.tooltip"))
|
.tooltip(Component.translatable("controlify.gui.current_controller.tooltip"))
|
||||||
.binding(Controlify.instance().currentController(), () -> Controlify.instance().currentController(), v -> Controlify.instance().setCurrentController(v))
|
.binding(Controlify.instance().currentController(), () -> Controlify.instance().currentController(), v -> Controlify.instance().setCurrentController(v))
|
||||||
.controller(opt -> new CyclingListController<>(opt, Iterables.concat(List.of(Controller.DUMMY), Controller.CONTROLLERS.values()), c -> Component.literal(c == Controller.DUMMY ? "Disabled" : c.name())))
|
.controller(opt -> new CyclingListController<>(opt, Iterables.concat(List.of(Controller.DUMMY), Controller.CONTROLLERS.values().stream().filter(Controller::canBeUsed).toList()), c -> Component.literal(c == Controller.DUMMY ? "Disabled" : c.name())))
|
||||||
.instant(true)
|
.instant(true)
|
||||||
.build())
|
.build())
|
||||||
.option(Option.createBuilder(boolean.class)
|
.option(Option.createBuilder(boolean.class)
|
||||||
@ -67,14 +67,21 @@ public class YACLHelper {
|
|||||||
yacl.category(globalCategory.build());
|
yacl.category(globalCategory.build());
|
||||||
|
|
||||||
for (var controller : Controller.CONTROLLERS.values()) {
|
for (var controller : Controller.CONTROLLERS.values()) {
|
||||||
// if (controller instanceof JoystickController joystick && joystick.mapping() instanceof UnmappedJoystickMapping) {
|
yacl.category(createControllerCategory(controller));
|
||||||
// // PlaceholderCategory for onboarding
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
|
return yacl.build().generateScreen(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ConfigCategory createControllerCategory(Controller<?, ?> controller) {
|
||||||
var category = ConfigCategory.createBuilder();
|
var category = ConfigCategory.createBuilder();
|
||||||
|
|
||||||
category.name(Component.literal(controller.name()));
|
category.name(Component.literal(controller.name()));
|
||||||
|
|
||||||
|
if (!controller.canBeUsed()) {
|
||||||
|
category.tooltip(Component.translatable("controlify.gui.controller_unavailable"));
|
||||||
|
}
|
||||||
|
|
||||||
var config = controller.config();
|
var config = controller.config();
|
||||||
var def = controller.defaultConfig();
|
var def = controller.defaultConfig();
|
||||||
|
|
||||||
@ -247,9 +254,6 @@ public class YACLHelper {
|
|||||||
|
|
||||||
category.group(controlsGroup.build());
|
category.group(controlsGroup.build());
|
||||||
|
|
||||||
yacl.category(category.build());
|
return category.build();
|
||||||
}
|
|
||||||
|
|
||||||
return yacl.build().generateScreen(parent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,10 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
|
|||||||
|
|
||||||
void updateState();
|
void updateState();
|
||||||
|
|
||||||
|
default boolean canBeUsed() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Map<Integer, Controller<?, ?>> CONTROLLERS = new HashMap<>();
|
Map<Integer, Controller<?, ?>> CONTROLLERS = new HashMap<>();
|
||||||
|
|
||||||
static Controller<?, ?> createOrGet(int joystickId, @Nullable HidDevice device) {
|
static Controller<?, ?> createOrGet(int joystickId, @Nullable HidDevice device) {
|
||||||
|
@ -56,7 +56,11 @@ public class ControllerType {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeMap.getOrDefault(hid, UNKNOWN);
|
var type = typeMap.getOrDefault(hid, UNKNOWN);
|
||||||
|
if (type == UNKNOWN) {
|
||||||
|
Controlify.LOGGER.warn("Controller type unknown! Please report the make and model of your controller and give the following details: " + hid);
|
||||||
|
}
|
||||||
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readControllerIdFiles(JsonReader reader) throws IOException {
|
private static void readControllerIdFiles(JsonReader reader) throws IOException {
|
||||||
|
@ -3,8 +3,9 @@ package dev.isxander.controlify.controller.joystick;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import dev.isxander.controlify.controller.AbstractController;
|
import dev.isxander.controlify.controller.AbstractController;
|
||||||
import dev.isxander.controlify.controller.joystick.mapping.DataJoystickMapping;
|
import dev.isxander.controlify.controller.joystick.mapping.RPJoystickMapping;
|
||||||
import dev.isxander.controlify.controller.joystick.mapping.JoystickMapping;
|
import dev.isxander.controlify.controller.joystick.mapping.JoystickMapping;
|
||||||
|
import dev.isxander.controlify.controller.joystick.mapping.UnmappedJoystickMapping;
|
||||||
import org.hid4java.HidDevice;
|
import org.hid4java.HidDevice;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
@ -23,7 +24,7 @@ public class JoystickController extends AbstractController<JoystickState, Joysti
|
|||||||
this.buttonCount = GLFW.glfwGetJoystickButtons(joystickId).capacity();
|
this.buttonCount = GLFW.glfwGetJoystickButtons(joystickId).capacity();
|
||||||
this.hatCount = GLFW.glfwGetJoystickHats(joystickId).capacity();
|
this.hatCount = GLFW.glfwGetJoystickHats(joystickId).capacity();
|
||||||
|
|
||||||
this.mapping = Objects.requireNonNull(DataJoystickMapping.fromType(type()));
|
this.mapping = Objects.requireNonNull(RPJoystickMapping.fromType(type()));
|
||||||
|
|
||||||
this.config = new JoystickConfig(this);
|
this.config = new JoystickConfig(this);
|
||||||
this.defaultConfig = new JoystickConfig(this);
|
this.defaultConfig = new JoystickConfig(this);
|
||||||
@ -49,6 +50,11 @@ public class JoystickController extends AbstractController<JoystickState, Joysti
|
|||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeUsed() {
|
||||||
|
return !(mapping() instanceof UnmappedJoystickMapping);
|
||||||
|
}
|
||||||
|
|
||||||
public int axisCount() {
|
public int axisCount() {
|
||||||
return axisCount;
|
return axisCount;
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,15 @@ import net.minecraft.world.phys.Vec2;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class DataJoystickMapping implements JoystickMapping {
|
public class RPJoystickMapping implements JoystickMapping {
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
private final Map<Integer, AxisMapping> axisMappings;
|
private final Map<Integer, AxisMapping> axisMappings;
|
||||||
private final Map<Integer, ButtonMapping> buttonMappings;
|
private final Map<Integer, ButtonMapping> buttonMappings;
|
||||||
private final Map<Integer, HatMapping> hatMappings;
|
private final Map<Integer, HatMapping> hatMappings;
|
||||||
|
|
||||||
public DataJoystickMapping(JsonObject object, ControllerType type) {
|
public RPJoystickMapping(JsonObject object, ControllerType type) {
|
||||||
axisMappings = new HashMap<>();
|
axisMappings = new HashMap<>();
|
||||||
object.getAsJsonArray("axes").forEach(element -> {
|
object.getAsJsonArray("axes").forEach(element -> {
|
||||||
var axis = element.getAsJsonObject();
|
var axis = element.getAsJsonObject();
|
||||||
@ -106,7 +104,7 @@ public class DataJoystickMapping implements JoystickMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try (var reader = resource.get().openAsReader()) {
|
try (var reader = resource.get().openAsReader()) {
|
||||||
return new DataJoystickMapping(gson.fromJson(reader, JsonObject.class), type);
|
return new RPJoystickMapping(gson.fromJson(reader, JsonObject.class), type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Controlify.LOGGER.error("Failed to load joystick mapping for controller: '" + type.identifier() + "'", e);
|
Controlify.LOGGER.error("Failed to load joystick mapping for controller: '" + type.identifier() + "'", e);
|
||||||
return UnmappedJoystickMapping.INSTANCE;
|
return UnmappedJoystickMapping.INSTANCE;
|
Reference in New Issue
Block a user