Skip to content

Commit

Permalink
Add VFPScreen#addRefreshButton
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 11, 2024
1 parent b076971 commit 12bafd9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* <li>{@link #setupSubtitle(Text, ButtonWidget.PressAction)}</li>
* </ul>
* </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:
* <ul>
* <li>{@link #playClickSound()}</li>
Expand Down Expand Up @@ -156,6 +156,13 @@ protected void init() {
}
}

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
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ private void createView() {
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.refresh"), button -> {
SERVER_LIST = null;
client.setScreen(this);
}).position(width - 60 - 5, 5).size(60, 20).build());
this.addRefreshButton(() -> SERVER_LIST = null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ private void createView() {
}
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 -> {
realmsWorlds = null;
client.setScreen(this);
}).position(width - 60 - 5, 5).size(60, 20).build());
this.addRefreshButton(() -> realmsWorlds = null);

final int slotWidth = 360 - 4;

Expand Down

0 comments on commit 12bafd9

Please sign in to comment.