forked from Clones/Controlify
➕ Maybe later button for controller calibration
This commit is contained in:
@ -183,7 +183,12 @@ public class Controlify implements ControlifyApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getCurrentController().isEmpty()) {
|
if (getCurrentController().isEmpty()) {
|
||||||
this.setCurrentController(ControllerManager.getConnectedControllers().stream().findFirst().orElse(null));
|
var controller = ControllerManager.getConnectedControllers().stream().findFirst().orElse(null);
|
||||||
|
if (controller != null && controller.config().delayedCalibration) {
|
||||||
|
controller = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setCurrentController(controller);
|
||||||
} else {
|
} else {
|
||||||
// setCurrentController saves config
|
// setCurrentController saves config
|
||||||
config().saveIfDirty();
|
config().saveIfDirty();
|
||||||
|
@ -30,6 +30,7 @@ public abstract class ControllerConfig {
|
|||||||
public JsonObject vibrationStrengths = RumbleSource.getDefaultJson();
|
public JsonObject vibrationStrengths = RumbleSource.getDefaultJson();
|
||||||
|
|
||||||
public boolean deadzonesCalibrated = false;
|
public boolean deadzonesCalibrated = false;
|
||||||
|
public boolean delayedCalibration = false;
|
||||||
|
|
||||||
public abstract void setDeadzone(int axis, float deadzone);
|
public abstract void setDeadzone(int axis, float deadzone);
|
||||||
public abstract float getDeadzone(int axis);
|
public abstract float getDeadzone(int axis);
|
||||||
|
@ -9,6 +9,7 @@ import net.minecraft.ChatFormatting;
|
|||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.components.MultiLineLabel;
|
import net.minecraft.client.gui.components.MultiLineLabel;
|
||||||
|
import net.minecraft.client.gui.components.Tooltip;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@ -27,7 +28,7 @@ public class ControllerCalibrationScreen extends Screen {
|
|||||||
|
|
||||||
private MultiLineLabel waitLabel, infoLabel, completeLabel;
|
private MultiLineLabel waitLabel, infoLabel, completeLabel;
|
||||||
|
|
||||||
protected Button readyButton;
|
protected Button readyButton, laterButton;
|
||||||
|
|
||||||
protected boolean calibrating = false, calibrated = false;
|
protected boolean calibrating = false, calibrated = false;
|
||||||
protected int calibrationTicks = 0;
|
protected int calibrationTicks = 0;
|
||||||
@ -47,16 +48,20 @@ public class ControllerCalibrationScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
addRenderableWidget(
|
addRenderableWidget(readyButton =
|
||||||
readyButton = Button.builder(Component.translatable("controlify.calibration.ready"), btn -> {
|
Button.builder(Component.translatable("controlify.calibration.ready"), btn -> onButtonPress())
|
||||||
if (!calibrated)
|
|
||||||
startCalibration();
|
|
||||||
else
|
|
||||||
onClose();
|
|
||||||
})
|
|
||||||
.width(150)
|
.width(150)
|
||||||
.pos(this.width / 2 - 75, this.height - 8 - 20)
|
.pos(this.width / 2 - 150 - 5, this.height - 8 - 20)
|
||||||
.build());
|
.build()
|
||||||
|
);
|
||||||
|
addRenderableWidget(laterButton =
|
||||||
|
Button.builder(Component.translatable("controlify.calibration.later"), btn -> onLaterButtonPress())
|
||||||
|
.width(150)
|
||||||
|
.pos(this.width / 2 + 5, this.height - 8 - 20)
|
||||||
|
.tooltip(Tooltip.create(Component.translatable("controlify.calibration.later.tooltip")))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
this.infoLabel = MultiLineLabel.create(font, Component.translatable("controlify.calibration.info"), width - 30);
|
this.infoLabel = MultiLineLabel.create(font, Component.translatable("controlify.calibration.info"), width - 30);
|
||||||
this.waitLabel = MultiLineLabel.create(font, Component.translatable("controlify.calibration.wait"), width - 30);
|
this.waitLabel = MultiLineLabel.create(font, Component.translatable("controlify.calibration.wait"), width - 30);
|
||||||
@ -139,6 +144,7 @@ public class ControllerCalibrationScreen extends Screen {
|
|||||||
readyButton.setMessage(Component.translatable("controlify.calibration.done"));
|
readyButton.setMessage(Component.translatable("controlify.calibration.done"));
|
||||||
|
|
||||||
controller.config().deadzonesCalibrated = true;
|
controller.config().deadzonesCalibrated = true;
|
||||||
|
controller.config().delayedCalibration = false;
|
||||||
Controlify.instance().config().save();
|
Controlify.instance().config().save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,6 +184,25 @@ public class ControllerCalibrationScreen extends Screen {
|
|||||||
.anyMatch(axis -> Math.abs(axis - controller.prevState().axes().get(controller.state().axes().indexOf(axis))) > amt);
|
.anyMatch(axis -> Math.abs(axis - controller.prevState().axes().get(controller.state().axes().indexOf(axis))) > amt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onButtonPress() {
|
||||||
|
if (!calibrated) {
|
||||||
|
startCalibration();
|
||||||
|
|
||||||
|
removeWidget(laterButton);
|
||||||
|
readyButton.setX(this.width / 2 - 75);
|
||||||
|
} else
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onLaterButtonPress() {
|
||||||
|
if (!calibrated) {
|
||||||
|
controller.config().delayedCalibration = true;
|
||||||
|
Controlify.instance().config().setDirty();
|
||||||
|
Controlify.instance().setCurrentController(null);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
minecraft.setScreen(parent.get());
|
minecraft.setScreen(parent.get());
|
||||||
|
@ -274,6 +274,8 @@
|
|||||||
"controlify.calibration.ready": "Ready",
|
"controlify.calibration.ready": "Ready",
|
||||||
"controlify.calibration.done": "Done",
|
"controlify.calibration.done": "Done",
|
||||||
"controlify.calibration.calibrating": "Calibrating...",
|
"controlify.calibration.calibrating": "Calibrating...",
|
||||||
|
"controlify.calibration.later": "Maybe Later",
|
||||||
|
"controlify.calibration.later.tooltip": "You must calibrate to use the controller. Pressing this will deactivate the controller and you will have to use it again to calibrate.",
|
||||||
|
|
||||||
"controlify.beta.title": "Controlify Beta Notice",
|
"controlify.beta.title": "Controlify Beta Notice",
|
||||||
"controlify.beta.message": "You are currently using Controlify Beta.\n\nThis mod is a work in progress and will contain many bugs. Please, if you spot a bug in this mod or have a suggestion to make it even better, please create an issue on the %s!\n\nYou can always find the link to the issue tracker in Controlify's settings menu.",
|
"controlify.beta.message": "You are currently using Controlify Beta.\n\nThis mod is a work in progress and will contain many bugs. Please, if you spot a bug in this mod or have a suggestion to make it even better, please create an issue on the %s!\n\nYou can always find the link to the issue tracker in Controlify's settings menu.",
|
||||||
|
Reference in New Issue
Block a user