Add VFPScreen#addRefreshButton

This commit is contained in:
FlorianMichael 2024-10-11 16:36:24 +02:00
parent b076971686
commit 12bafd99f5
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 10 additions and 9 deletions

View File

@ -49,7 +49,7 @@ import java.awt.*;
* <li>{@link #setupSubtitle(Text, ButtonWidget.PressAction)}</li> * <li>{@link #setupSubtitle(Text, ButtonWidget.PressAction)}</li>
* </ul> * </ul>
* </li> * </li>
* <li>Automatically adds a button when set inside the constructor</li> * <li>Automatically adds a back button when set inside the constructor</li>
* <li>Helper functions: * <li>Helper functions:
* <ul> * <ul>
* <li>{@link #playClickSound()}</li> * <li>{@link #playClickSound()}</li>
@ -156,6 +156,13 @@ public class VFPScreen extends Screen {
} }
} }
public void addRefreshButton(final Runnable click) {
this.addDrawableChild(ButtonWidget.builder(Text.translatable("base.viafabricplus.refresh"), button -> {
click.run();
client.setScreen(this);
}).position(width - 60 - 5, 5).size(60, 20).build());
}
@Override @Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) { public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta);

View File

@ -67,10 +67,7 @@ public class BetaCraftScreen extends VFPScreen {
this.setupSubtitle(Text.of(BETA_CRAFT_SERVER_LIST_URL), ConfirmLinkScreen.opening(this, BETA_CRAFT_SERVER_LIST_URL)); 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(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.refresh"), button -> { this.addRefreshButton(() -> SERVER_LIST = null);
SERVER_LIST = null;
client.setScreen(this);
}).position(width - 60 - 5, 5).size(60, 20).build());
} }
@Override @Override

View File

@ -102,10 +102,7 @@ public class BedrockRealmsScreen extends VFPScreen {
} }
this.addDrawableChild(slotList = new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, 30, (textRenderer.fontHeight + 2) * 4)); this.addDrawableChild(slotList = new SlotList(this.client, width, height, 3 + 3 /* start offset */ + (textRenderer.fontHeight + 2) * 3 /* title is 2 */, 30, (textRenderer.fontHeight + 2) * 4));
this.addDrawableChild(ButtonWidget.builder(Text.translatable("base.viafabricplus.refresh"), button -> { this.addRefreshButton(() -> realmsWorlds = null);
realmsWorlds = null;
client.setScreen(this);
}).position(width - 60 - 5, 5).size(60, 20).build());
final int slotWidth = 360 - 4; final int slotWidth = 360 - 4;