forked from Clones/Controlify
✏️ Remove jank from the controller submission screen
This commit is contained in:
@ -1,7 +0,0 @@
|
||||
package dev.isxander.controlify.gui.screen;
|
||||
|
||||
public interface CustomWarningTitlePadding {
|
||||
default int getMessageY() {
|
||||
return 70;
|
||||
}
|
||||
}
|
@ -9,12 +9,10 @@ import dev.isxander.controlify.hid.HIDDevice;
|
||||
import dev.isxander.controlify.utils.Log;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.*;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.multiplayer.WarningScreen;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
@ -24,12 +22,14 @@ import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SubmitUnknownControllerScreen extends WarningScreen implements CustomWarningTitlePadding {
|
||||
public class SubmitUnknownControllerScreen extends Screen {
|
||||
public static final String SUBMISSION_URL = "https://api-controlify.isxander.dev/api/v1/submit";
|
||||
public static final Pattern NAME_PATTERN = Pattern.compile("^[\\w\\- ]{3,32}$");
|
||||
|
||||
private final Controller<?, ?> controller;
|
||||
|
||||
private Checkbox dontShowAgain;
|
||||
|
||||
private final Screen lastScreen;
|
||||
|
||||
private int invalidNameTicks;
|
||||
@ -38,12 +38,7 @@ public class SubmitUnknownControllerScreen extends WarningScreen implements Cust
|
||||
private EditBox nameField;
|
||||
|
||||
public SubmitUnknownControllerScreen(Controller<?, ?> controller, Screen lastScreen) {
|
||||
super(
|
||||
Component.translatable("controlify.controller_submission.title").withStyle(ChatFormatting.BOLD),
|
||||
Component.translatable("controlify.controller_submission.message"),
|
||||
Component.translatable("controlify.controller_submission.dont_show_again"),
|
||||
Component.translatable("controlify.controller_submission.title")
|
||||
);
|
||||
super(Component.translatable("controlify.controller_submission.title").withStyle(ChatFormatting.BOLD));
|
||||
if (!canSubmit(controller))
|
||||
throw new IllegalArgumentException("Controller ineligible for submission!");
|
||||
this.controller = controller;
|
||||
@ -51,24 +46,65 @@ public class SubmitUnknownControllerScreen extends WarningScreen implements Cust
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initButtons(int textHeight) {
|
||||
protected void init() {
|
||||
var content = this.addRenderableWidget(
|
||||
new MultiLineTextWidget(
|
||||
Component.translatable("controlify.controller_submission.message"),
|
||||
font
|
||||
)
|
||||
);
|
||||
content.setMaxWidth(this.width - 100);
|
||||
content.setX(this.width / 2 - content.getWidth() / 2);
|
||||
|
||||
int titleBottomPadding = 11;
|
||||
int checkboxPadding = 6;
|
||||
int checkboxHeight = 20;
|
||||
int buttonHeight = 20;
|
||||
int nameFieldPaddingTop = 5;
|
||||
int nameFieldHeight = 20;
|
||||
int errorPadding = 4;
|
||||
|
||||
int allHeight = font.lineHeight + titleBottomPadding + content.getHeight() + checkboxPadding + checkboxHeight + checkboxPadding + buttonHeight + nameFieldPaddingTop + nameFieldHeight + errorPadding + font.lineHeight;
|
||||
|
||||
int y = this.height / 2 - allHeight / 2;
|
||||
this.addRenderableWidget(createStringWidget(this.getTitle(), font, 25, y));
|
||||
y += font.lineHeight + titleBottomPadding;
|
||||
|
||||
content.setY(y);
|
||||
y += content.getHeight() + checkboxPadding;
|
||||
|
||||
var dontShowAgainText = Component.translatable("controlify.controller_submission.dont_show_again");
|
||||
this.dontShowAgain = this.addRenderableWidget(
|
||||
new Checkbox(
|
||||
this.width / 2 - font.width(dontShowAgainText) / 2 - 8,
|
||||
y,
|
||||
150,
|
||||
checkboxHeight,
|
||||
Component.translatable("controlify.controller_submission.dont_show_again"),
|
||||
false
|
||||
)
|
||||
);
|
||||
y += checkboxHeight + checkboxPadding;
|
||||
|
||||
this.submitButton = this.addRenderableWidget(
|
||||
Button.builder(Component.translatable("controlify.controller_submission.submit"), this::onSubmitButton)
|
||||
.pos(this.width / 2 - 155, textHeight + 80)
|
||||
.pos(this.width / 2 - 155, y)
|
||||
.width(150)
|
||||
.build()
|
||||
);
|
||||
this.addRenderableWidget(
|
||||
Button.builder(CommonComponents.GUI_CANCEL, btn -> onClose())
|
||||
.pos(this.width / 2 + 5, textHeight + 80)
|
||||
Button.builder(Component.translatable("controlify.controller_submission.skip"), btn -> onClose())
|
||||
.pos(this.width / 2 + 5, y)
|
||||
.width(150)
|
||||
.build()
|
||||
);
|
||||
y += buttonHeight + nameFieldPaddingTop;
|
||||
|
||||
this.nameField = this.addRenderableWidget(
|
||||
new EditBox(
|
||||
font,
|
||||
this.width / 2 - 155,
|
||||
textHeight + 105,
|
||||
y,
|
||||
310, 20,
|
||||
Component.translatable("controlify.controller_submission.name_narration")
|
||||
)
|
||||
@ -109,6 +145,8 @@ public class SubmitUnknownControllerScreen extends WarningScreen implements Cust
|
||||
onClose();
|
||||
} else {
|
||||
// TODO: Show error message
|
||||
dontShowAgain();
|
||||
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
@ -162,7 +200,7 @@ public class SubmitUnknownControllerScreen extends WarningScreen implements Cust
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (stopShowing.selected()) {
|
||||
if (dontShowAgain.selected()) {
|
||||
dontShowAgain();
|
||||
}
|
||||
|
||||
@ -175,14 +213,8 @@ public class SubmitUnknownControllerScreen extends WarningScreen implements Cust
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLineHeight() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMessageY() {
|
||||
return 50;
|
||||
private static StringWidget createStringWidget(Component text, Font font, int x, int y) {
|
||||
return new StringWidget(x, y, font.width(text.getVisualOrderText()), font.lineHeight, text, font);
|
||||
}
|
||||
|
||||
public static boolean canSubmit(Controller<?, ?> controller) {
|
||||
|
@ -1,20 +0,0 @@
|
||||
package dev.isxander.controlify.mixins.feature.gui;
|
||||
|
||||
import dev.isxander.controlify.gui.screen.CustomWarningTitlePadding;
|
||||
import net.minecraft.client.gui.screens.multiplayer.WarningScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
|
||||
@Mixin(WarningScreen.class)
|
||||
public class WarningScreenMixin implements CustomWarningTitlePadding {
|
||||
@ModifyConstant(method = "render", constant = @Constant(intValue = 70))
|
||||
private int modifyMessageY(int original) {
|
||||
return this.getMessageY();
|
||||
}
|
||||
|
||||
@ModifyConstant(method = "init", constant = @Constant(intValue = 76))
|
||||
private int modifyCheckboxY(int original) {
|
||||
return this.getMessageY() + 6;
|
||||
}
|
||||
}
|
@ -280,9 +280,10 @@
|
||||
"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.controller_submission.title": "Unknown Controller Submission",
|
||||
"controlify.controller_submission.message": "Please submit some of your controller info to Controlify's database to get it added in a future update.\n\nControlify sends the following information:\n- Your controller's vendor & product IDs\n- Your controller's GUID\n- The name of your controller (in the box below)\n- The version of Controlify you are currently on\n\nThis is completely anonymous and does store any of your personal or account information.",
|
||||
"controlify.controller_submission.message": "Please submit some of your controller info to Controlify's database to get it added in a future update.\n\nControlify sends the following information:\n- Your controller's vendor & product IDs\n- Your controller's GUID\n- The name of your controller (in the box below)\n- The version of Controlify you are currently on\n\nThis is completely anonymous and doesn't store any of your personal or account information.",
|
||||
"controlify.controller_submission.dont_show_again": "Do not show for this controller again",
|
||||
"controlify.controller_submission.submit": "Submit Data",
|
||||
"controlify.controller_submission.skip": "Skip",
|
||||
"controlify.controller_submission.name_hint": "Controller name",
|
||||
"controlify.controller_submission.name_narration": "Controller name input field",
|
||||
"controlify.controller_submission.invalid_name": "Invalid controller name. Use only letters, numbers and spaces.",
|
||||
|
@ -34,7 +34,6 @@
|
||||
"feature.chatkbheight.ChatScreenMixin",
|
||||
"feature.fixes.boatfix.BoatMixin",
|
||||
"feature.fixes.boatfix.LocalPlayerMixin",
|
||||
"feature.gui.WarningScreenMixin",
|
||||
"feature.guide.ingame.ClientPacketListenerMixin",
|
||||
"feature.guide.ingame.GuiMixin",
|
||||
"feature.guide.screen.AbstractButtonMixin",
|
||||
|
Reference in New Issue
Block a user