Skip to content

Commit

Permalink
Some cleanup of the last PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 18, 2023
1 parent 63f74d5 commit 6aedfbd
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public class VFPScreen extends Screen {

private static final String MOD_URL = "https://github.com/ViaVersion/ViaFabricPlus";
private final static String MOD_URL = "https://github.com/ViaVersion/ViaFabricPlus";

private final boolean backButton;
public Screen prevScreen;
Expand All @@ -62,9 +62,19 @@ public VFPScreen(final String title, final boolean backButton) {
*
*/
public void setupDefaultSubtitle() {
this.setupSubtitle(Text.of(MOD_URL), ConfirmLinkScreen.opening(MOD_URL, this, true));
this.setupUrlSubtitle(MOD_URL);
}

/**
* Sets the subtitle and the subtitle press action to the default values
*
* @param subtitle The subtitle which should be rendered
*/
public void setupUrlSubtitle(final String subtitle) {
this.setupSubtitle(Text.of(subtitle), ConfirmLinkScreen.opening(subtitle, this, true));
}


/***
* Sets the subtitle and the subtitle press action
*
Expand All @@ -83,7 +93,8 @@ public void setupSubtitle(@Nullable final Text subtitle) {
public void setupSubtitle(@Nullable final Text subtitle, @Nullable final ButtonWidget.PressAction subtitlePressAction) {
this.subtitle = subtitle;
this.subtitlePressAction = subtitlePressAction;
if (subtitleWidget != null && subtitlePressAction == null) {

if (subtitleWidget != null && subtitlePressAction == null) { // Allows to remove the subtitle when calling this method twice.
remove(subtitleWidget);
subtitleWidget = null;
}
Expand Down Expand Up @@ -162,7 +173,7 @@ public static void playClickSound() {
/**
* Opens an error screen with a specific title and throws the given throwable
*
* @param title The title of the error screen
* @param title The title of the error screen
* @param throwable The throwable which should be thrown
*/
public void showErrorScreen(final String title, final Throwable throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.minecraft.util.Identifier;

public class BoatModel_1_8 extends CompositeEntityModel<BoatEntity> {
public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(new Identifier("viafabricplus", "boat_1_8"), "main");
public final static EntityModelLayer MODEL_LAYER = new EntityModelLayer(new Identifier("viafabricplus", "boat_1_8"), "main");
private final ImmutableList<ModelPart> parts;

public BoatModel_1_8(ModelPart root) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.minecraft.util.math.RotationAxis;

public class BoatRenderer_1_8 extends EntityRenderer<BoatEntity> {
private static final Identifier TEXTURE = new Identifier("viafabricplus", "textures/boat_1_8.png");
private final static Identifier TEXTURE = new Identifier("viafabricplus", "textures/boat_1_8.png");
private final BoatModel_1_8 model;

public BoatRenderer_1_8(EntityRendererFactory.Context ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class MixinNamedCompoundTagType {

@Unique
private static final TagLimiter viafabricplus_tag_limiter = new TagLimiter() {
private final static TagLimiter viafabricplus_tag_limiter = new TagLimiter() {
private final int maxBytes = 2097152;
private int bytes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BetaCraftScreen extends VFPScreen {
public static BCServerList SERVER_LIST;
public final static BetaCraftScreen INSTANCE = new BetaCraftScreen();

private static final String BETA_CRAFT_SERVER_LIST_URL = "https://betacraft.uk/serverlist/";
private final static String BETA_CRAFT_SERVER_LIST_URL = "https://betacraft.uk/serverlist/";

protected BetaCraftScreen() {
super("BetaCraft", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class ClassiCubeLoginScreen extends VFPScreen {
public final static ClassiCubeLoginScreen INSTANCE = new ClassiCubeLoginScreen();

private static final String CLASSI_CUBE_URL = "https://www.classicube.net/";
private final static String CLASSI_CUBE_URL = "https://www.classicube.net/";

public ClassiCubeLoginScreen() {
super("ClassiCube Login", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ public ClassiCubeMFAScreen() {

@Override
public void open(Screen prevScreen) {
status = Classic4JImpl.fromError(CCError.LOGIN_CODE);
this.setupSubtitle(Classic4JImpl.fromError(CCError.LOGIN_CODE));
super.open(prevScreen);
}

private TextFieldWidget mfaField;

private Text status;

@Override
protected void init() {
super.init();
Expand All @@ -58,7 +56,7 @@ protected void init() {
mfaField.setPlaceholder(Text.literal("MFA"));

this.addDrawableChild(ButtonWidget.builder(Text.literal("Login"), button -> {
status = Text.translatable("classicube.viafabricplus.loading");
this.setupSubtitle(Text.translatable("classicube.viafabricplus.loading"));
final CCAccount account = ClassiCubeAccountHandler.INSTANCE.getAccount();

ClassiCubeHandler.requestAuthentication(account, mfaField.getText(), new LoginProcessHandler() {
Expand All @@ -74,7 +72,7 @@ public void handleSuccessfulLogin(CCAccount account) {

@Override
public void handleException(Throwable throwable) {
status = Text.literal(throwable.getMessage());
setupSubtitle(Text.literal(throwable.getMessage()));
}
});
}).position(width / 2 - 75, mfaField.getY() + (20 * 4) + 5).size(150, 20).build());
Expand All @@ -90,7 +88,8 @@ public void close() {
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
this.renderBackground(context, mouseX, mouseY, delta);
context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 70, 16777215);
context.drawCenteredTextWithShadow(this.textRenderer, this.status, this.width / 2, 1, 16777215);

this.renderSubtitle(context);

super.render(context, mouseX, mouseY, delta);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.mojang.blaze3d.systems.RenderSystem;
import de.florianmichael.classic4j.ClassiCubeHandler;
import de.florianmichael.classic4j.api.LoginProcessHandler;
import de.florianmichael.classic4j.model.classicube.account.CCAccount;
import de.florianmichael.classic4j.model.classicube.server.CCServerInfo;
import de.florianmichael.viafabricplus.base.screen.MappedSlotEntry;
import de.florianmichael.viafabricplus.base.screen.VFPScreen;
Expand All @@ -32,7 +31,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
import net.minecraft.client.gui.screen.ConnectScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
Expand All @@ -50,7 +48,7 @@ public class ClassiCubeServerListScreen extends VFPScreen {
public final static List<CCServerInfo> SERVER_LIST = new ArrayList<>();
public final static ClassiCubeServerListScreen INSTANCE = new ClassiCubeServerListScreen();

private static final String CLASSI_CUBE_SERVER_LIST_URL = "https://www.classicube.net/server/list/";
private final static String CLASSICUBE_SERVER_LIST_URL = "https://www.classicube.net/server/list/";

public static void open(final Screen prevScreen, final LoginProcessHandler loginProcessHandler) {
ClassiCubeHandler.requestServerList(ClassiCubeAccountHandler.INSTANCE.getAccount(), ccServerList -> {
Expand All @@ -61,13 +59,10 @@ public static void open(final Screen prevScreen, final LoginProcessHandler login

public ClassiCubeServerListScreen() {
super("ClassiCube ServerList", true);
final CCAccount account = ClassiCubeAccountHandler.INSTANCE.getAccount();

final var account = ClassiCubeAccountHandler.INSTANCE.getAccount();
if (account != null) {
this.setupSubtitle(Text.of(CLASSI_CUBE_SERVER_LIST_URL), ConfirmLinkScreen.opening(
CLASSI_CUBE_SERVER_LIST_URL,
this,
true
));
this.setupUrlSubtitle(CLASSICUBE_SERVER_LIST_URL);
}
}

Expand All @@ -94,22 +89,11 @@ 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 CCAccount account = ClassiCubeAccountHandler.INSTANCE.getAccount();

final var account = ClassiCubeAccountHandler.INSTANCE.getAccount();
if (account != null) {
context.drawTextWithShadow(
textRenderer,
Text.of("ClassiCube Profile: "),
32,
6,
-1
);
context.drawTextWithShadow(
textRenderer,
Text.of(account.username()),
32,
16,
-1
);
context.drawTextWithShadow(textRenderer, Text.of("ClassiCube Profile:"), 32, 6, -1);
context.drawTextWithShadow(textRenderer, Text.of(account.username()), 32, 16, -1);
}
}

Expand Down

0 comments on commit 6aedfbd

Please sign in to comment.