Skip to content

Commit

Permalink
Merge pull request #752 from kevinthegreat1/more-tips
Browse files Browse the repository at this point in the history
Refactor and add more tips
  • Loading branch information
kevinthegreat1 authored Jun 30, 2024
2 parents 690f047 + 81d8171 commit 2f6aeac
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 42 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dependencies {
modCompileOnly "dev.emi:emi-fabric:${project.emi_version}:api"
//modLocalRuntime "dev.emi:emi-fabric:${project.emi_version}"

compileOnly "com.demonwav.mcdev:annotations:${project.mcdev_annotations_version}"

include modImplementation("meteordevelopment:discord-ipc:1.1")

// Occlusion Culling (https://github.com/LogisticsCraft/OcclusionCulling)
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ rei_version = 13.0.666
emi_version = 1.0.22+1.20.2

# Minecraft and Related Libraries
## McDev Annotations (https://central.sonatype.com/artifact/com.demonwav.mcdev/annotations)
mcdev_annotations_version = 2.1.0
## Occlusion Culling (https://github.com/LogisticsCraft/OcclusionCulling)
occlusionculling_version = 0.0.8-SNAPSHOT
## neu repoparser (https://repo.nea.moe/#/releases/moe/nea/neurepoparser/)
Expand Down
33 changes: 20 additions & 13 deletions src/main/java/de/hysky/skyblocker/SkyblockerScreen.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.hysky.skyblocker;

import java.time.LocalDate;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.Tips;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
Expand All @@ -11,18 +9,16 @@
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.client.gui.widget.*;
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;

import java.time.LocalDate;

public class SkyblockerScreen extends Screen {
private static final int SPACING = 8;
private static final int BUTTON_WIDTH = 210;
Expand All @@ -36,15 +32,16 @@ public class SkyblockerScreen extends Screen {
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 ThreePartsLayoutWidget layout;
private MultilineTextWidget tip;

static {
LocalDate date = LocalDate.now();

ICON = date.getMonthValue() == 4 && date.getDayOfMonth() == 1 ? Identifier.of(SkyblockerMod.NAMESPACE, "icons.png") : Identifier.of(SkyblockerMod.NAMESPACE, "icon.png");
}

private SkyblockerScreen() {
public SkyblockerScreen() {
super(TITLE);
}

Expand All @@ -57,6 +54,7 @@ public static void initClass() {

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

GridWidget gridWidget = this.layout.addBody(new GridWidget()).setSpacing(SPACING);
Expand All @@ -72,17 +70,26 @@ protected void init() {
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));
GridWidget footerGridWidget = this.layout.addFooter(new GridWidget()).setSpacing(SPACING).setRowSpacing(0);
footerGridWidget.getMainPositioner().alignHorizontalCenter();
GridWidget.Adder footerAdder = footerGridWidget.createAdder(2);
footerAdder.add(tip = new MultilineTextWidget(Tips.nextTip(), this.textRenderer).setCentered(true).setMaxWidth((int) (this.width * 0.7)), 2);
footerAdder.add(ButtonWidget.builder(Text.translatable("skyblocker.tips.previous"), button -> {
tip.setMessage(Tips.previousTip());
layout.refreshPositions();
}).build());
footerAdder.add(ButtonWidget.builder(Text.translatable("skyblocker.tips.next"), button -> {
tip.setMessage(Tips.nextTip());
layout.refreshPositions();
}).build());

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.hysky.skyblocker.config.categories;

import de.hysky.skyblocker.SkyblockerScreen;
import de.hysky.skyblocker.config.ConfigUtils;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.configs.GeneralConfig;
Expand All @@ -16,6 +17,13 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
return ConfigCategory.createBuilder()
.name(Text.translatable("skyblocker.config.general"))

//Skyblocker Screen
.option(ButtonOption.createBuilder()
.name(Text.translatable("skyblocker.skyblockerScreen"))
.text(Text.translatable("text.skyblocker.open"))
.action((screen, opt) -> MinecraftClient.getInstance().setScreen(new SkyblockerScreen()))
.build())

//Ungrouped Options
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.enableTips"))
Expand Down
102 changes: 73 additions & 29 deletions src/main/java/de/hysky/skyblocker/skyblock/Tips.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.hysky.skyblocker.skyblock;

import com.demonwav.mcdev.annotations.Translatable;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
Expand All @@ -14,16 +15,16 @@
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class Tips {
private static final Random RANDOM = new Random();
private static int previousTipIndex = -1;
private static final List<Supplier<Text>> TIPS = List.of(
private static int currentTipIndex = 0;
private static final List<Supplier<Text>> TIPS = new ArrayList<>(List.of(
getTipFactory("skyblocker.tips.customItemNames", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker custom renameItem"),
getTipFactory("skyblocker.tips.customArmorDyeColors", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker custom dyeColor"),
getTipFactory("skyblocker.tips.customArmorTrims", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker custom armorTrim"),
Expand All @@ -36,47 +37,60 @@ public class Tips {
getTipFactory("skyblocker.tips.gallery", ClickEvent.Action.OPEN_URL, "https://hysky.de/skyblocker/gallery"),
getTipFactory("skyblocker.tips.itemRarityBackground", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config"),
getTipFactory("skyblocker.tips.modMenuUpdate"),
getTipFactory("skyblocker.tips.issues", ClickEvent.Action.OPEN_URL, "https://github.com/SkyblockerMod/Skyblocker"),
getTipFactory("skyblocker.tips.issues", ClickEvent.Action.OPEN_URL, "https://github.com/SkyblockerMod/Skyblocker/issues"),
getTipFactory("skyblocker.tips.beta", ClickEvent.Action.OPEN_URL, "https://github.com/SkyblockerMod/Skyblocker/actions"),
getTipFactory("skyblocker.tips.contribute", ClickEvent.Action.OPEN_URL, "https://github.com/SkyblockerMod/Skyblocker/wiki/contribute"),
getTipFactory("skyblocker.tips.discord", ClickEvent.Action.OPEN_URL, "https://discord.gg/aNNJHQykck"),
getTipFactory("skyblocker.tips.flameOverlay", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config"),
getTipFactory("skyblocker.tips.wikiLookup", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config"),
getTipFactory("skyblocker.tips.protectItem", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker protectItem"),
getTipFactory("skyblocker.tips.fairySoulsEnigmaSoulsRelics", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker fairySouls"),
getTipFactory("skyblocker.tips.quickNav", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config")
);
getTipFactory("skyblocker.tips.quickNav", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config"),
getTipFactory("skyblocker.tips.waypoints", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker waypoint"),
getTipFactory("skyblocker.tips.orderedWaypoints", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker waypoint ordered"),
getTipFactory("skyblocker.tips.visitorHelper"),
getTipFactory("skyblocker.tips.slotText"),
getTipFactory("skyblocker.tips.profileViewer", ClickEvent.Action.SUGGEST_COMMAND, "/pv"),
getTipFactory("skyblocker.tips.configSearch", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config"),
getTipFactory("skyblocker.tips.compactDamage", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config"),
getTipFactory("skyblocker.tips.skyblockerScreen", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker"),
getTipFactory("skyblocker.tips.tipsClick", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker tips next"),
getTipFactory("skyblocker.tips.eventNotifications", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config"),
getTipFactory("skyblocker.tips.signCalculator"),
getTipFactory("skyblocker.tips.calculateCommand", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker calculate"),
getTipFactory("skyblocker.tips.fancierBars", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker bars"),
getTipFactory("skyblocker.tips.crystalWaypointsShare", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker crystalWaypoints share"),
getTipFactory("skyblocker.tips.gardenMouseLock", ClickEvent.Action.SUGGEST_COMMAND, "/skyblocker config"),
getTipFactory("skyblocker.tips.newYearCakesHelper"),
getTipFactory("skyblocker.tips.accessoryHelper"),
getTipFactory("skyblocker.tips.fancyAuctionHouseCheapHighlight")
));

private static boolean sentTip = false;

private static Supplier<Text> getTipFactory(String key) {
private static Supplier<Text> getTipFactory(@Translatable String key) {
return () -> Text.translatable(key);
}

private static Supplier<Text> getTipFactory(String key, ClickEvent.Action clickAction, String value) {
private static Supplier<Text> getTipFactory(@Translatable String key, ClickEvent.Action clickAction, String value) {
return () -> Text.translatable(key).styled(style -> style.withClickEvent(new ClickEvent(clickAction, value)));
}

public static void init() {
ClientCommandRegistrationCallback.EVENT.register(Tips::registerTipsCommand);
SkyblockEvents.JOIN.register(Tips::sendNextTip);
Collections.shuffle(TIPS);
}

private static void registerTipsCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
dispatcher.register(literal(SkyblockerMod.NAMESPACE).then(literal("tips")
.then(literal("enable").executes(Tips::enableTips))
.then(literal("disable").executes(Tips::disableTips))
.then(literal("next").executes(Tips::nextTip))
.then(literal("previous").executes(Tips::sendPreviousTipCommand))
.then(literal("next").executes(Tips::sendNextTipCommand))
));
}

private static void sendNextTip() {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player != null && SkyblockerConfigManager.get().general.enableTips && !sentTip) {
client.player.sendMessage(nextTip(), false);
sentTip = true;
}
}

private static int enableTips(CommandContext<FabricClientCommandSource> context) {
SkyblockerConfigManager.get().general.enableTips = true;
SkyblockerConfigManager.save();
Expand All @@ -91,22 +105,52 @@ private static int disableTips(CommandContext<FabricClientCommandSource> context
return Command.SINGLE_SUCCESS;
}

private static int nextTip(CommandContext<FabricClientCommandSource> context) {
context.getSource().sendFeedback(nextTip());
private static void sendNextTip() {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player != null && SkyblockerConfigManager.get().general.enableTips && !sentTip) {
client.player.sendMessage(tipMessage(nextTip()), false);
sentTip = true;
}
}

private static int sendNextTipCommand(CommandContext<FabricClientCommandSource> context) {
context.getSource().sendFeedback(tipMessage(nextTip()));
return Command.SINGLE_SUCCESS;
}

private static Text nextTip() {
return Constants.PREFIX.get().append(Text.translatable("skyblocker.tips.tip", nextTipInternal()))
public static Text nextTip() {
return Text.translatable("skyblocker.tips.tip", nextTipInternal());
}

private static Text nextTipInternal() {
currentTipIndex++;
currentTipIndex %= TIPS.size();
return TIPS.get(currentTipIndex).get();
}

private static int sendPreviousTipCommand(CommandContext<FabricClientCommandSource> context) {
context.getSource().sendFeedback(tipMessage(previousTip()));
return Command.SINGLE_SUCCESS;
}

public static Text previousTip() {
return Text.translatable("skyblocker.tips.tip", previousTipInternal());
}

private static Text previousTipInternal() {
currentTipIndex--;
currentTipIndex += TIPS.size();
currentTipIndex %= TIPS.size();
return TIPS.get(currentTipIndex).get();
}

private static Text tipMessage(Text tip) {
return Constants.PREFIX.get().append(tip)
.append(" ")
.append(Text.translatable("skyblocker.tips.clickPreviousTip").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker tips previous"))))
.append(" ")
.append(Text.translatable("skyblocker.tips.clickNextTip").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker tips next"))))
.append(" ")
.append(Text.translatable("skyblocker.tips.clickDisable").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker tips disable"))));
}

public static Text nextTipInternal() {
int randomInt = RANDOM.nextInt(TIPS.size());
while (randomInt == previousTipIndex) randomInt = RANDOM.nextInt(TIPS.size());
previousTipIndex = randomInt;
return TIPS.get(randomInt).get();
}
}
24 changes: 24 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"text.skyblocker.modrinth": "Modrinth",
"text.skyblocker.discord": "Discord",

"skyblocker.skyblockerScreen": "Skyblocker Main Screen",

"skyblocker.config.title": "Skyblocker Settings",

"skyblocker.config.crimsonIsle": "Crimson Isle",
Expand Down Expand Up @@ -813,8 +815,11 @@

"skyblocker.tips.enabled": "§aEnabled Tips.",
"skyblocker.tips.disabled": "§cDisabled Tips.",
"skyblocker.tips.previous": "Previous Tip",
"skyblocker.tips.next": "Next Tip",
"skyblocker.tips.clickEnable": "§a[Click to Enable Tips]",
"skyblocker.tips.clickDisable": "§c[Click to Disable Tips]",
"skyblocker.tips.clickPreviousTip": "§b[Click for Previous Tip]",
"skyblocker.tips.clickNextTip": "§a[Click for Next Tip]",
"skyblocker.tips.tip": "§aTip: %s\n",
"skyblocker.tips.customItemNames": "Customize the names of your items with /skyblocker custom renameItem",
Expand All @@ -831,12 +836,31 @@
"skyblocker.tips.modMenuUpdate": "ModMenu will let you know if there's an update available for Skyblocker for your game version.",
"skyblocker.tips.issues": "Submit bug reports and feature requests to https://github.com/SkyblockerMod/Skyblocker.",
"skyblocker.tips.beta": "We often have beta versions available from GitHub Actions that contain new and experimental features.",
"skyblocker.tips.contribute": "We welcome contributions to the mod! See https://github.com/SkyblockerMod/Skyblocker/wiki/contribute for more info.",
"skyblocker.tips.discord": "Join our discord at https://discord.gg/aNNJHQykck to keep up with the latest news about Skyblocker!",
"skyblocker.tips.flameOverlay": "Find that the flame overlay takes up too much screen space? Check out the config to make it smaller",
"skyblocker.tips.wikiLookup": "Press F4 while hovering over an item to open its wiki page in your web browser.",
"skyblocker.tips.protectItem": "Prevent accidentally dropping your items with /skyblocker protectItem.",
"skyblocker.tips.fairySoulsEnigmaSoulsRelics": "Don't know where to find Fairy Souls, Enigma Souls, or Relics? Enable the helpers to aid your exploration, they'll remember which souls you've already found.",
"skyblocker.tips.quickNav": "You can customize the QuickNav buttons in the config.",
"skyblocker.tips.waypoints": "You can import (including from skytils), add, remove, and toggle waypoints on any island with /skyblocker waypoints.",
"skyblocker.tips.orderedWaypoints": "You can import (including from coleweight), add, remove, and toggle ordered waypoints with /skyblocker waypoints ordered.",
"skyblocker.tips.visitorHelper": "Click on the item name in the visitor helper to buy from the bazaar or click on [Copy Amount] to copy the amount to your clipboard.",
"skyblocker.tips.slotText": "Slot text shows you the attribute shard info, catacombs level, collection level, enchantment book level, minion level, pet level, potion level, prehistoric egg blocks walked, rancher's boots speed cap, skill level, skyblock level in the slot.",
"skyblocker.tips.profileViewer": "You can view other player's profiles with /pv.",
"skyblocker.tips.configSearch": "You can search the entire config using the search bar on the bottom right of the config screen.",
"skyblocker.tips.compactDamage": "Customize your damage value with Compact Damage in the config.",
"skyblocker.tips.skyblockerScreen": "You can access the Skyblocker screen to open the config or checkout helpful links for the mod with /skyblocker.",
"skyblocker.tips.tipsClick": "Click on a tip chat message to run its suggestion!",
"skyblocker.tips.eventNotifications": "Check out the customizable event notifications in the config.",
"skyblocker.tips.signCalculator": "Type an math expression in a sign to have the mod calculate it for you.",
"skyblocker.tips.calculateCommand": "Enter an expression after /skyblocker calculate to have the mod calculate it for you.",
"skyblocker.tips.fancierBars": "Customize the look of your health, mana, defense, and experience bars with /skyblocker bars. You can snap and resize bars too!",
"skyblocker.tips.crystalWaypointsShare": "Share Crystal Hollows Waypoints with /skyblocker crystalWaypoints share.",
"skyblocker.tips.gardenMouseLock": "Lock your mouse while farming in the Skyblocker Garden config.",
"skyblocker.tips.newYearCakesHelper": "Open your New Year Cake Bag and Skyblocker will remember them and highlight duplicate cakes red and missing cakes green.",
"skyblocker.tips.accessoryHelper": "Open your accessory bag and Skyblocker will remember them. The accessory helper will tell you what accessories you have and what accessories are missing.",
"skyblocker.tips.fancyAuctionHouseCheapHighlight": "Cheap BINs are highlighted in green in the Fancy Auction House.",

"skyblocker.partyFinder.tabs.partyFinder": "Party Finder",
"skyblocker.partyFinder.tabs.searchSettings": "Search Filters",
Expand Down

0 comments on commit 2f6aeac

Please sign in to comment.