mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-25 12:25:22 +01:00
Remove duplicated code in screens, improve docs
This commit is contained in:
parent
dccc75e045
commit
b076971686
@ -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<T extends AlwaysSelectedEntryListWidget.Entry<T>> extends AlwaysSelectedEntryListWidget<T> {
|
||||
/**
|
||||
* Wrapper class for {@link AlwaysSelectedEntryListWidget} including the following features:
|
||||
* <ul>
|
||||
* <li>Changing the constructor arguments to be more readable and customizable</li>
|
||||
* <li>Adds {@link #initScrollAmount(double)} to save the scroll state after closing the screen, requires static tracking by the implementation</li>
|
||||
* <li>Removes the selection box</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see ProtocolSelectionScreen
|
||||
* @see PerServerVersionScreen
|
||||
*/
|
||||
public class VFPList extends AlwaysSelectedEntryListWidget<VFPListEntry> {
|
||||
|
||||
public VFPList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {
|
||||
super(minecraftClient, width, height - top - bottom, top, entryHeight);
|
||||
|
@ -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:
|
||||
* <ul>
|
||||
* <li>Add wrapper function {@link #mappedRender(DrawContext, int, int, int, int, int, int, int, boolean, float)} for:
|
||||
* <ul>
|
||||
* <li>cross-sharing entry position/dimension between other helper functions</li>
|
||||
* <li>Setting the entry position as start inside the {@link MatrixStack}</li>
|
||||
* <li>rendering a default background</li>
|
||||
* </ul>
|
||||
* <li>Adds {@link #mappedMouseClicked(double, double, int)} to automatically play a click sound</li>
|
||||
* <li>Adds some more utility functions, see {@link #renderScrollableText(Text, int, int)} and {@link #renderTooltip(Text, int, int)}</li>
|
||||
* </li>
|
||||
* </ul>
|
||||
*/
|
||||
public abstract class VFPListEntry extends AlwaysSelectedEntryListWidget.Entry<VFPListEntry> {
|
||||
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* Features:
|
||||
* <ul>
|
||||
* <li>Title and subtitle system, see:
|
||||
* <ul>
|
||||
* <li>{@link #setupDefaultSubtitle()}</li>
|
||||
* <li>{@link #setupUrlSubtitle(String)}</li>
|
||||
* <li>{@link #setupSubtitle(Text)}</li>
|
||||
* <li>{@link #setupSubtitle(Text, ButtonWidget.PressAction)}</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>Automatically adds a button when set inside the constructor</li>
|
||||
* <li>Helper functions:
|
||||
* <ul>
|
||||
* <li>{@link #playClickSound()}</li>
|
||||
* <li>{@link #showErrorScreen(Text, Throwable, Screen)}</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* Terminology:
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
@ -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<VFPListEntry> {
|
||||
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);
|
||||
|
@ -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<VFPListEntry> {
|
||||
public static class SlotList extends VFPList {
|
||||
private static double scrollAmount;
|
||||
|
||||
public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<VFPListEntry> {
|
||||
public static class SlotList extends VFPList {
|
||||
private static double scrollAmount;
|
||||
|
||||
public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<VFPListEntry> {
|
||||
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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<VFPListEntry> {
|
||||
public class SlotList extends VFPList {
|
||||
private static double scrollAmount;
|
||||
|
||||
public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {
|
||||
|
@ -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<VFPListEntry> {
|
||||
public static class SlotList extends VFPList {
|
||||
private static double scrollAmount;
|
||||
|
||||
public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {
|
||||
|
Loading…
Reference in New Issue
Block a user