forked from Clones/Controlify
joystick axis rendering (no textures), improve config error handling and fix joystick deadzones being unordered
This commit is contained in:
@ -125,7 +125,10 @@ public class ControllerBindings<T extends ControllerState> {
|
||||
public void fromJson(JsonObject json) {
|
||||
for (var binding : registry().values()) {
|
||||
var bind = json.get(binding.id().toString()).getAsJsonObject();
|
||||
if (bind == null) continue;
|
||||
if (bind == null) {
|
||||
Controlify.LOGGER.warn("Unknown control: " + binding.id() + " in config file. Skipping!");
|
||||
continue;
|
||||
}
|
||||
binding.setCurrentBind(IBind.fromJson(bind, controller));
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public enum GamepadBind implements IBind<GamepadState> {
|
||||
public void draw(PoseStack matrices, int x, int centerY, Controller<GamepadState, ?> controller) {
|
||||
ResourceLocation texture;
|
||||
if (((GamepadConfig)controller.config()).theme == BuiltinGamepadTheme.DEFAULT) {
|
||||
texture = new ResourceLocation("controlify", "textures/gui/gamepad_buttons/" + controller.type().identifier() + "/" + identifier + ".png");
|
||||
texture = new ResourceLocation("controlify", "textures/gui/gamepad/" + controller.type().identifier() + "/" + identifier + ".png");
|
||||
} else {
|
||||
texture = textureLocations.get(((GamepadConfig)controller.config()).theme);
|
||||
}
|
||||
|
@ -32,14 +32,10 @@ public interface IBind<S extends ControllerState> {
|
||||
case JoystickButtonBind.BIND_ID -> JoystickButtonBind.fromJson(json, joystick);
|
||||
case JoystickHatBind.BIND_ID -> JoystickHatBind.fromJson(json, joystick);
|
||||
case JoystickAxisBind.BIND_ID -> JoystickAxisBind.fromJson(json, joystick);
|
||||
default -> {
|
||||
Controlify.LOGGER.error("Unknown bind type: " + type);
|
||||
yield new EmptyBind<>();
|
||||
}
|
||||
default -> throw new IllegalStateException("Unknown bind type for joystick: " + type);
|
||||
};
|
||||
}
|
||||
|
||||
Controlify.LOGGER.error("Could not parse bind for controller: " + controller.name());
|
||||
return new EmptyBind<>();
|
||||
throw new IllegalStateException("Unknown controller type: " + controller.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
package dev.isxander.controlify.bindings;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.controller.joystick.JoystickController;
|
||||
import dev.isxander.controlify.controller.joystick.JoystickState;
|
||||
import dev.isxander.controlify.controller.joystick.mapping.JoystickMapping;
|
||||
import dev.isxander.controlify.controller.joystick.mapping.UnmappedJoystickMapping;
|
||||
import dev.isxander.controlify.gui.DrawSize;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -35,22 +40,32 @@ public class JoystickAxisBind implements IBind<JoystickState> {
|
||||
|
||||
@Override
|
||||
public void draw(PoseStack matrices, int x, int centerY, Controller<JoystickState, ?> controller) {
|
||||
var font = Minecraft.getInstance().font;
|
||||
font.drawShadow(matrices, getTempButtonName(), x + 1.5f, centerY - font.lineHeight / 2f, 0xFFFFFF);
|
||||
if (controller != joystick) return;
|
||||
JoystickMapping mapping = joystick.mapping();
|
||||
|
||||
String type = joystick.type().identifier();
|
||||
String axis = mapping.axis(axisIndex).identifier();
|
||||
String direction = mapping.axis(axisIndex).getDirectionIdentifier(axisIndex, this.direction);
|
||||
var texture = new ResourceLocation("controlify", "textures/gui/joystick/" + type + "/axis_" + axis + "_" + direction + ".png");
|
||||
|
||||
RenderSystem.setShaderTexture(0, texture);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
GuiComponent.blit(matrices, x, centerY - 11, 0, 0, 22, 22, 22, 22);
|
||||
|
||||
if (mapping instanceof UnmappedJoystickMapping) {
|
||||
var text = Integer.toString(axisIndex + 1);
|
||||
var font = Minecraft.getInstance().font;
|
||||
GuiComponent.drawCenteredString(matrices, font, text, x + 11, centerY - font.lineHeight / 2, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DrawSize drawSize() {
|
||||
var font = Minecraft.getInstance().font;
|
||||
return new DrawSize(font.width(getTempButtonName()) + 3, font.lineHeight);
|
||||
}
|
||||
int width = 22;
|
||||
if (joystick.mapping() instanceof UnmappedJoystickMapping)
|
||||
width = Math.max(width, Minecraft.getInstance().font.width(Integer.toString(axisIndex + 1)));
|
||||
|
||||
private Component getTempButtonName() {
|
||||
var axis = joystick.mapping().axis(axisIndex);
|
||||
return Component.empty()
|
||||
.append(axis.name())
|
||||
.append(" ")
|
||||
.append(axis.getDirectionName(axisIndex, direction));
|
||||
return new DrawSize(width, 22);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,16 @@
|
||||
package dev.isxander.controlify.bindings;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.controller.joystick.JoystickController;
|
||||
import dev.isxander.controlify.controller.joystick.JoystickState;
|
||||
import dev.isxander.controlify.gui.DrawSize;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -29,19 +32,20 @@ public class JoystickButtonBind implements IBind<JoystickState> {
|
||||
|
||||
@Override
|
||||
public void draw(PoseStack matrices, int x, int centerY, Controller<JoystickState, ?> controller) {
|
||||
var font = Minecraft.getInstance().font;
|
||||
if (controller != joystick) return;
|
||||
|
||||
font.drawShadow(matrices, getTempButtonName(), x + 1.5f, centerY - font.lineHeight / 2f, 0xFFFFFF);
|
||||
String type = joystick.type().identifier();
|
||||
String button = joystick.mapping().button(buttonIndex).identifier();
|
||||
var texture = new ResourceLocation("controlify", "textures/gui/joystick/" + type + "/button_" + button + ".png");
|
||||
|
||||
RenderSystem.setShaderTexture(0, texture);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
GuiComponent.blit(matrices, x, centerY - 11, 0, 0, 22, 22, 22, 22);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DrawSize drawSize() {
|
||||
var font = Minecraft.getInstance().font;
|
||||
return new DrawSize(font.width(getTempButtonName()) + 3, font.lineHeight);
|
||||
}
|
||||
|
||||
private Component getTempButtonName() {
|
||||
return joystick.mapping().button(buttonIndex).name();
|
||||
return new DrawSize(22, 22);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,16 @@
|
||||
package dev.isxander.controlify.bindings;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.controller.joystick.JoystickController;
|
||||
import dev.isxander.controlify.controller.joystick.JoystickState;
|
||||
import dev.isxander.controlify.gui.DrawSize;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -31,21 +34,30 @@ public class JoystickHatBind implements IBind<JoystickState> {
|
||||
|
||||
@Override
|
||||
public void draw(PoseStack matrices, int x, int centerY, Controller<JoystickState, ?> controller) {
|
||||
var font = Minecraft.getInstance().font;
|
||||
font.drawShadow(matrices, getTempButtonName(), x + 1.5f, centerY - font.lineHeight / 2f, 0xFFFFFF);
|
||||
if (controller != joystick) return;
|
||||
|
||||
String type = joystick.type().identifier();
|
||||
String button = joystick.mapping().button(hatIndex).identifier();
|
||||
String direction = "centered";
|
||||
if (hatState.isUp())
|
||||
direction = "up";
|
||||
else if (hatState.isDown())
|
||||
direction = "down";
|
||||
else if (hatState.isLeft())
|
||||
direction = "left";
|
||||
else if (hatState.isRight())
|
||||
direction = "right";
|
||||
|
||||
var texture = new ResourceLocation("controlify", "textures/gui/joystick/" + type + "/hat" + button + "_" + direction + ".png");
|
||||
|
||||
RenderSystem.setShaderTexture(0, texture);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
GuiComponent.blit(matrices, x, centerY - 11, 0, 0, 22, 22, 22, 22);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DrawSize drawSize() {
|
||||
var font = Minecraft.getInstance().font;
|
||||
return new DrawSize(font.width(getTempButtonName()) + 3, font.lineHeight);
|
||||
}
|
||||
|
||||
private Component getTempButtonName() {
|
||||
return Component.empty()
|
||||
.append(joystick.mapping().hat(hatIndex).name())
|
||||
.append(" ")
|
||||
.append(hatState.getDisplayName());
|
||||
return new DrawSize(22, 22);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user