diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/VFPList.java b/src/main/java/de/florianmichael/viafabricplus/screen/VFPList.java index 224842ba..192561a7 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/VFPList.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/VFPList.java @@ -19,12 +19,25 @@ package de.florianmichael.viafabricplus.screen; +import de.florianmichael.viafabricplus.screen.base.PerServerVersionScreen; +import de.florianmichael.viafabricplus.screen.base.ProtocolSelectionScreen; import de.florianmichael.viafabricplus.settings.impl.GeneralSettings; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; -public class VFPList> extends AlwaysSelectedEntryListWidget { +/** + * Wrapper class for {@link AlwaysSelectedEntryListWidget} including the following features: + * + * + * @see ProtocolSelectionScreen + * @see PerServerVersionScreen + */ +public class VFPList extends AlwaysSelectedEntryListWidget { public VFPList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) { super(minecraftClient, width, height - top - bottom, top, entryHeight); diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/VFPListEntry.java b/src/main/java/de/florianmichael/viafabricplus/screen/VFPListEntry.java index f9195e76..054853d2 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/VFPListEntry.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/VFPListEntry.java @@ -30,8 +30,19 @@ import net.minecraft.util.math.MathHelper; import javax.annotation.Nullable; /** - * This class is a wrapper for the {@link net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget.Entry} class which provides some global - * functions and features used in all screens which are added by ViaFabricPlus + * This class is a wrapper for the {@link net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget.Entry} class. + * Features included: + *
    + *
  • Add wrapper function {@link #mappedRender(DrawContext, int, int, int, int, int, int, int, boolean, float)} for: + *
      + *
    • cross-sharing entry position/dimension between other helper functions
    • + *
    • Setting the entry position as start inside the {@link MatrixStack}
    • + *
    • rendering a default background
    • + *
    + *
  • Adds {@link #mappedMouseClicked(double, double, int)} to automatically play a click sound
  • + *
  • Adds some more utility functions, see {@link #renderScrollableText(Text, int, int)} and {@link #renderTooltip(Text, int, int)}
  • + * + *
*/ public abstract class VFPListEntry extends AlwaysSelectedEntryListWidget.Entry { diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/VFPScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/VFPScreen.java index c6a27c32..89d70977 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/VFPScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/VFPScreen.java @@ -37,7 +37,32 @@ import java.awt.*; /** * This class is a wrapper for the {@link net.minecraft.client.gui.screen.Screen} class which provides some global - * functions and features used in all screens which are added by ViaFabricPlus + * functions and features used in all screens which are added by ViaFabricPlus. + *

+ * Features: + *

    + *
  • Title and subtitle system, see: + *
      + *
    • {@link #setupDefaultSubtitle()}
    • + *
    • {@link #setupUrlSubtitle(String)}
    • + *
    • {@link #setupSubtitle(Text)}
    • + *
    • {@link #setupSubtitle(Text, ButtonWidget.PressAction)}
    • + *
    + *
  • + *
  • Automatically adds a button when set inside the constructor
  • + *
  • Helper functions: + *
      + *
    • {@link #playClickSound()}
    • + *
    • {@link #showErrorScreen(Text, Throwable, Screen)}
    • + *
    + *
  • + *
+ * + * Terminology: + *

+ * Instead of creating the screen every time it needs to be opened, the screen is created once and hold by a static + * field and later opened by calling the {@link #open(Screen)} method. + *

*/ public class VFPScreen extends Screen { @@ -131,6 +156,13 @@ public class VFPScreen extends Screen { } } + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + super.render(context, mouseX, mouseY, delta); + + this.renderTitle(context); + } + @Override public void close() { if (prevScreen instanceof VFPScreen vfpScreen) { @@ -173,6 +205,10 @@ public class VFPScreen extends Screen { return false; } + public void renderScreenTitle(final DrawContext context) { + context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 70, 16777215); + } + /** * Plays Minecraft's button click sound */ diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/base/PerServerVersionScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/base/PerServerVersionScreen.java index 2b1cb813..ddd1522f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/base/PerServerVersionScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/base/PerServerVersionScreen.java @@ -54,14 +54,7 @@ public class PerServerVersionScreen extends VFPScreen { this.addDrawableChild(new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, -5, textRenderer.fontHeight + 4)); } - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - - this.renderTitle(context); - } - - public class SlotList extends VFPList { + public class SlotList extends VFPList { public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) { super(minecraftClient, width, height, top, bottom, entryHeight); diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/base/ProtocolSelectionScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/base/ProtocolSelectionScreen.java index a3e29005..efbc551b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/base/ProtocolSelectionScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/base/ProtocolSelectionScreen.java @@ -58,14 +58,7 @@ public class ProtocolSelectionScreen extends VFPScreen { super.init(); } - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - - this.renderTitle(context); - } - - public static class SlotList extends VFPList { + public static class SlotList extends VFPList { private static double scrollAmount; public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) { diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/base/ReportIssuesScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/base/ReportIssuesScreen.java index 2fdbe04e..0d263a02 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/base/ReportIssuesScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/base/ReportIssuesScreen.java @@ -22,7 +22,6 @@ package de.florianmichael.viafabricplus.screen.base; import com.viaversion.viaversion.util.DumpUtil; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.screen.VFPScreen; -import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.text.Text; import net.minecraft.util.Util; @@ -99,9 +98,4 @@ public class ReportIssuesScreen extends VFPScreen { } } - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - this.renderTitle(context); - } } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/base/ServerListScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/base/ServerListScreen.java index 4531c636..25bda849 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/base/ServerListScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/base/ServerListScreen.java @@ -19,14 +19,12 @@ package de.florianmichael.viafabricplus.screen.base; -import de.florianmichael.classic4j.BetaCraftHandler; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.screen.VFPScreen; import de.florianmichael.viafabricplus.screen.classic4j.BetaCraftScreen; import de.florianmichael.viafabricplus.screen.classic4j.ClassiCubeLoginScreen; import de.florianmichael.viafabricplus.screen.classic4j.ClassiCubeServerListScreen; import de.florianmichael.viafabricplus.screen.realms.BedrockRealmsScreen; -import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.text.Text; @@ -82,10 +80,4 @@ public class ServerListScreen extends VFPScreen { } } - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - this.renderTitle(context); - } - } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/BetaCraftScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/BetaCraftScreen.java index 3c0c5d5c..1c72cf9e 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/BetaCraftScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/BetaCraftScreen.java @@ -73,19 +73,12 @@ public class BetaCraftScreen extends VFPScreen { }).position(width - 60 - 5, 5).size(60, 20).build()); } - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - - this.renderTitle(context); - } - @Override protected boolean subtitleCentered() { return SERVER_LIST == null; } - public static class SlotList extends VFPList { + public static class SlotList extends VFPList { private static double scrollAmount; public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) { diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeLoginScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeLoginScreen.java index 5935fdbb..367f97b1 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeLoginScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeLoginScreen.java @@ -103,9 +103,7 @@ public class ClassiCubeLoginScreen extends VFPScreen { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); - this.renderTitle(context); - - context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 70, 16777215); + this.renderScreenTitle(context); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeMFAScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeMFAScreen.java index ad53fca4..75a1255d 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeMFAScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeMFAScreen.java @@ -83,9 +83,7 @@ public class ClassiCubeMFAScreen extends VFPScreen { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); - this.renderTitle(context); - - context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 70, 16777215); + this.renderScreenTitle(context); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeServerListScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeServerListScreen.java index e6d638d0..43f4fd6d 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeServerListScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/classic4j/ClassiCubeServerListScreen.java @@ -81,9 +81,7 @@ public class ClassiCubeServerListScreen extends VFPScreen { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - this.renderBackground(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); - this.renderTitle(context); final var account = ViaFabricPlus.global().getSaveManager().getAccountsSave().getClassicubeAccount(); if (account != null) { @@ -92,7 +90,7 @@ public class ClassiCubeServerListScreen extends VFPScreen { } } - public static class SlotList extends VFPList { + public static class SlotList extends VFPList { private static double scrollAmount; public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) { @@ -113,7 +111,6 @@ public class ClassiCubeServerListScreen extends VFPScreen { } } - public static class ServerSlot extends VFPListEntry { private final CCServerInfo classiCubeServerInfo; diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/realms/AcceptInvitationCodeScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/realms/AcceptInvitationCodeScreen.java index 25bc8c94..6b99ec4e 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/realms/AcceptInvitationCodeScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/realms/AcceptInvitationCodeScreen.java @@ -20,7 +20,6 @@ package de.florianmichael.viafabricplus.screen.realms; import de.florianmichael.viafabricplus.screen.VFPScreen; -import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.text.Text; @@ -53,11 +52,4 @@ public class AcceptInvitationCodeScreen extends VFPScreen { }).position(this.width / 2 - ButtonWidget.DEFAULT_WIDTH / 2, this.height / 2 + 20).build()); } - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - - this.renderTitle(context); - } - } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/realms/BedrockRealmsScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/realms/BedrockRealmsScreen.java index e58eead3..6b488d7e 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/realms/BedrockRealmsScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/realms/BedrockRealmsScreen.java @@ -145,13 +145,6 @@ public class BedrockRealmsScreen extends VFPScreen { }).position(xPos, height - 20 - 5).size(115, 20).build()); } - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - - this.renderTitle(context); - } - @Override public void tick() { super.tick(); @@ -167,7 +160,7 @@ public class BedrockRealmsScreen extends VFPScreen { return slotList == null; } - public class SlotList extends VFPList { + public class SlotList extends VFPList { private static double scrollAmount; public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) { diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java index 7836eeb2..fa9982cc 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java @@ -45,14 +45,7 @@ public class SettingsScreen extends VFPScreen { super.init(); } - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - - this.renderTitle(context); - } - - public static class SlotList extends VFPList { + public static class SlotList extends VFPList { private static double scrollAmount; public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {