Rewrite subtitle system to support dynamic subtitle changes

This commit is contained in:
FlorianMichael 2024-02-21 22:46:09 +01:00
parent 1c206b83e0
commit 27f8156c47
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
6 changed files with 17 additions and 29 deletions

View File

@ -57,11 +57,10 @@ public class VFPScreen extends Screen {
this.backButton = backButton;
}
/***
/**
* Sets the subtitle and the subtitle press action to the default values
* The default value of the subtitle is the url to the GitHub repository of VFP
* The default value of the subtitle press action is to open the url in a confirmation screen
*
*/
public void setupDefaultSubtitle() {
this.setupUrlSubtitle(MOD_URL);
@ -77,7 +76,7 @@ public class VFPScreen extends Screen {
}
/***
/**
* Sets the subtitle and the subtitle press action
*
* @param subtitle The subtitle which should be rendered
@ -86,7 +85,7 @@ public class VFPScreen extends Screen {
this.setupSubtitle(subtitle, null);
}
/***
/**
* Sets the subtitle and the subtitle press action
*
* @param subtitle The subtitle which should be rendered
@ -96,10 +95,14 @@ public class VFPScreen extends Screen {
this.subtitle = subtitle;
this.subtitlePressAction = subtitlePressAction;
if (subtitleWidget != null && subtitlePressAction == null) { // Allows to remove the subtitle when calling this method twice.
if (subtitleWidget != null) { // Allows to remove the subtitle when calling this method twice.
remove(subtitleWidget);
subtitleWidget = null;
}
if (subtitlePressAction != null) {
final int subtitleWidth = textRenderer.getWidth(subtitle);
this.addDrawableChild(subtitleWidget = new PressableTextWidget(width / 2 - (subtitleWidth / 2), (textRenderer.fontHeight + 2) * 2 + 3, subtitleWidth, textRenderer.fontHeight + 2, subtitle, subtitlePressAction, textRenderer));
}
}
/**
@ -118,11 +121,6 @@ public class VFPScreen extends Screen {
if (backButton) {
this.addDrawableChild(ButtonWidget.builder(Text.literal("<-"), button -> this.close()).position(5, 5).size(20, 20).build());
}
if (this.subtitle != null && this.subtitlePressAction != null) {
final int subtitleWidth = textRenderer.getWidth(subtitle);
this.addDrawableChild(subtitleWidget = new PressableTextWidget(width / 2 - (subtitleWidth / 2), (textRenderer.fontHeight + 2) * 2 + 3, subtitleWidth, textRenderer.fontHeight + 2, subtitle, subtitlePressAction, textRenderer));
}
}
@Override

View File

@ -48,11 +48,11 @@ public class BetaCraftScreen extends VFPScreen {
protected BetaCraftScreen() {
super("BetaCraft", true);
this.setupSubtitle(Text.of(BETA_CRAFT_SERVER_LIST_URL), ConfirmLinkScreen.opening(this, BETA_CRAFT_SERVER_LIST_URL));
}
@Override
protected void init() {
this.setupSubtitle(Text.of(BETA_CRAFT_SERVER_LIST_URL), ConfirmLinkScreen.opening(this, BETA_CRAFT_SERVER_LIST_URL));
this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, -5, (textRenderer.fontHeight + 2) * 3));
this.addDrawableChild(ButtonWidget.builder(Text.translatable("base.viafabricplus.reset"), button -> {

View File

@ -42,18 +42,13 @@ public class ClassiCubeLoginScreen extends VFPScreen {
super("ClassiCube Login", true);
}
@Override
public void open(Screen prevScreen) {
this.setupSubtitle(Text.translatable("classicube.viafabricplus.account"), ConfirmLinkScreen.opening(this, ClassiCubeHandler.CLASSICUBE_ROOT_URI.toString()));
super.open(prevScreen);
}
private TextFieldWidget nameField;
private TextFieldWidget passwordField;
@Override
protected void init() {
super.init();
this.setupSubtitle(Text.translatable("classicube.viafabricplus.account"), ConfirmLinkScreen.opening(this, ClassiCubeHandler.CLASSICUBE_ROOT_URI.toString()));
this.addDrawableChild(nameField = new TextFieldWidget(textRenderer, width / 2 - 150, 70 + 10, 300, 20, Text.empty()));
this.addDrawableChild(passwordField = new TextFieldWidget(textRenderer, width / 2 - 150, nameField.getY() + 20 + 5, 300, 20, Text.empty()));

View File

@ -40,17 +40,12 @@ public class ClassiCubeMFAScreen extends VFPScreen {
super("ClassiCube MFA", false);
}
@Override
public void open(Screen prevScreen) {
this.setupSubtitle(Text.translatable("classic4j_library.viafabricplus.error.logincode"));
super.open(prevScreen);
}
private TextFieldWidget mfaField;
@Override
protected void init() {
super.init();
this.setupSubtitle(Text.translatable("classic4j_library.viafabricplus.error.logincode"));
this.addDrawableChild(mfaField = new TextFieldWidget(textRenderer, width / 2 - 150, 70 + 10, 300, 20, Text.empty()));

View File

@ -64,15 +64,15 @@ public class ClassiCubeServerListScreen extends VFPScreen {
public ClassiCubeServerListScreen() {
super("ClassiCube", true);
final var account = ViaFabricPlus.global().getSaveManager().getAccountsSave().getClassicubeAccount();
if (account != null) {
this.setupUrlSubtitle(CLASSICUBE_SERVER_LIST_URL);
}
}
@Override
protected void init() {
final var account = ViaFabricPlus.global().getSaveManager().getAccountsSave().getClassicubeAccount();
if (account != null) {
this.setupUrlSubtitle(CLASSICUBE_SERVER_LIST_URL);
}
this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, -5, (textRenderer.fontHeight + 4) * 3));
this.addDrawableChild(ButtonWidget.builder(Text.translatable("base.viafabricplus.logout"), button -> {

View File

@ -34,11 +34,11 @@ public class SettingsScreen extends VFPScreen {
public SettingsScreen() {
super("Setting", true);
this.setupDefaultSubtitle();
}
@Override
protected void init() {
this.setupDefaultSubtitle();
this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, -5, (textRenderer.fontHeight + 2) * 2));
super.init();