Skip to content

Commit

Permalink
Merge pull request #638 from AzureAaron/default-screen
Browse files Browse the repository at this point in the history
Info Screen
  • Loading branch information
kevinthegreat1 authored Apr 12, 2024
2 parents 8de8c71 + 85c4ec2 commit a8ab2df
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(this::tick);
Utils.init();
SkyblockerConfigManager.init();
SkyblockerScreen.initClass();
Tips.init();
NEURepoManager.init();
ImageRepoLoader.init();
Expand Down
125 changes: 125 additions & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package de.hysky.skyblocker;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.Tips;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
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.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.client.gui.widget.MultilineTextWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.client.gui.widget.ThreePartsLayoutWidget;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.OrderedText;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Language;

public class SkyblockerScreen extends Screen {
private static final int SPACING = 8;
private static final int BUTTON_WIDTH = 210;
private static final int HALF_BUTTON_WIDTH = 101; //Same as (210 - 8) / 2
private static final Text TITLE = Text.literal("Skyblocker " + SkyblockerMod.VERSION);
private static final Identifier ICON = new Identifier(SkyblockerMod.NAMESPACE, "icon.png");
private static final Text CONFIGURATION_TEXT = Text.translatable("text.skyblocker.config");
private static final Text SOURCE_TEXT = Text.translatable("text.skyblocker.source");
private static final Text REPORT_BUGS_TEXT = Text.translatable("menu.reportBugs");
private static final Text WEBSITE_TEXT = Text.translatable("text.skyblocker.website");
private static final Text TRANSLATE_TEXT = Text.translatable("text.skyblocker.translate");
private static final Text MODRINTH_TEXT = Text.translatable("text.skyblocker.modrinth");
private static final Text DISCORD_TEXT = Text.translatable("text.skyblocker.discord");
private final ThreePartsLayoutWidget layout = new ThreePartsLayoutWidget(this);

private SkyblockerScreen() {
super(TITLE);
}

public static void initClass() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
dispatcher.register(ClientCommandManager.literal(SkyblockerMod.NAMESPACE)
.executes(Scheduler.queueOpenScreenCommand(SkyblockerScreen::new)));
});
}

@Override
protected void init() {
this.layout.addHeader(new IconTextWidget(this.getTitle(), this.textRenderer, ICON));

GridWidget gridWidget = this.layout.addBody(new GridWidget()).setSpacing(SPACING);
gridWidget.getMainPositioner().alignHorizontalCenter();
GridWidget.Adder adder = gridWidget.createAdder(2);

adder.add(ButtonWidget.builder(CONFIGURATION_TEXT, button -> this.openConfig()).width(BUTTON_WIDTH).build(), 2);
adder.add(ButtonWidget.builder(SOURCE_TEXT, ConfirmLinkScreen.opening(this, "https://github.com/SkyblockerMod/Skyblocker")).width(HALF_BUTTON_WIDTH).build());
adder.add(ButtonWidget.builder(REPORT_BUGS_TEXT, ConfirmLinkScreen.opening(this, "https://github.com/SkyblockerMod/Skyblocker/issues")).width(HALF_BUTTON_WIDTH).build());
adder.add(ButtonWidget.builder(WEBSITE_TEXT, ConfirmLinkScreen.opening(this, "https://hysky.de/")).width(HALF_BUTTON_WIDTH).build());
adder.add(ButtonWidget.builder(TRANSLATE_TEXT, ConfirmLinkScreen.opening(this, "https://translate.hysky.de/")).width(HALF_BUTTON_WIDTH).build());
adder.add(ButtonWidget.builder(MODRINTH_TEXT, ConfirmLinkScreen.opening(this, "https://modrinth.com/mod/skyblocker-liap")).width(HALF_BUTTON_WIDTH).build());
adder.add(ButtonWidget.builder(DISCORD_TEXT, ConfirmLinkScreen.opening(this, "https://discord.gg/aNNJHQykck")).width(HALF_BUTTON_WIDTH).build());
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> this.close()).width(BUTTON_WIDTH).build(), 2);

MultilineTextWidget tip = new MultilineTextWidget(Text.translatable("skyblocker.tips.tip", Tips.nextTipInternal()), this.textRenderer)
.setCentered(true)
.setMaxWidth((int) (this.width * 0.7));

this.layout.addFooter(tip);
this.layout.refreshPositions();
this.layout.forEachChild(this::addDrawableChild);
}

@Override
protected void initTabNavigation() {
this.layout.refreshPositions();
}

private void openConfig() {
this.client.setScreen(SkyblockerConfigManager.createGUI(this));
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
this.renderBackground(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);
}

private static class IconTextWidget extends TextWidget {
private final Identifier icon;

IconTextWidget(Text message, TextRenderer textRenderer, Identifier icon) {
super(message, textRenderer);
this.icon = icon;
}

@Override
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
Text text = this.getMessage();
TextRenderer textRenderer = this.getTextRenderer();

int width = this.getWidth();
int textWidth = textRenderer.getWidth(text);
float horizontalAlignment = 0.5f; // default
//17 = (32 + 2) / 2 • 32 + 2 is the width of the icon + spacing between icon and text
int x = this.getX() + 17 + Math.round(horizontalAlignment * (float) (width - textWidth));
int y = this.getY() + (this.getHeight() - textRenderer.fontHeight) / 2;
OrderedText orderedText = textWidth > width ? this.trim(text, width) : text.asOrderedText();

int iconX = x - 34;
int iconY = y - 13;

context.drawTextWithShadow(textRenderer, orderedText, x, y, this.getTextColor());
context.drawTexture(this.icon, iconX, iconY, 0, 0, 32, 32, 32, 32);
}

private OrderedText trim(Text text, int width) {
TextRenderer textRenderer = this.getTextRenderer();
StringVisitable stringVisitable = textRenderer.trimToWidth(text, width - textRenderer.getWidth(ScreenTexts.ELLIPSIS));
return Language.getInstance().reorder(StringVisitable.concat(stringVisitable, ScreenTexts.ELLIPSIS));
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/de/hysky/skyblocker/skyblock/Tips.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static Text nextTip() {
.append(Text.translatable("skyblocker.tips.clickDisable").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker tips disable"))));
}

private static Text nextTipInternal() {
public static Text nextTipInternal() {
int randomInt = RANDOM.nextInt(TIPS.size());
while (randomInt == previousTipIndex) randomInt = RANDOM.nextInt(TIPS.size());
previousTipIndex = randomInt;
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"text.skyblocker.quit_config": "Changes Not Saved",
"text.skyblocker.quit_config_sure": "Are you sure you want to quit editing the config? Changes will not be saved!",
"text.skyblocker.quit_discard": "Quit & Discard Changes",
"text.skyblocker.config": "Open Config...",
"text.skyblocker.source": "Source",
"text.skyblocker.website": "Website",
"text.skyblocker.translate": "Translate",
"text.skyblocker.modrinth": "Modrinth",
"text.skyblocker.discord": "Discord",

"text.autoconfig.skyblocker.title": "Skyblocker Settings",

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"modmenu": {
"links": {
"modmenu.discord": "https://discord.com/invite/aNNJHQykck",
"modmenu.modrinth": "https://modrinth.com/mod/skyblocker-liap"
"modmenu.modrinth": "https://modrinth.com/mod/skyblocker-liap",
"text.skyblocker.translate": "https://translate.hysky.de"
}
}
}
Expand Down

0 comments on commit a8ab2df

Please sign in to comment.