Skip to content

Commit

Permalink
Merge pull request #865 from viciscat/quick-nav-tooltip
Browse files Browse the repository at this point in the history
Quick nav tooltip
  • Loading branch information
kevinthegreat1 authored Aug 4, 2024
2 parents bb356d2 + 95063d2 commit 2dd2ddf
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ private static OptionGroup quickNavButton(QuickNavigationConfig.QuickNavItem def
newValue -> button.uiTitle = newValue)
.controller(StringControllerBuilder::create)
.build())
.option(Option.<String>createBuilder()
.name(Text.translatable("skyblocker.config.quickNav.button.tooltip"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.quickNav.button.tooltip.@Tooltip")))
.binding(defaultButton.tooltip,
() -> button.tooltip,
newValue -> button.tooltip = newValue)
.controller(StringControllerBuilder::create)
.build())
.option(Option.<String>createBuilder()
.name(Text.translatable("skyblocker.config.quickNav.button.clickEvent"))
.binding(defaultButton.clickEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,70 @@ public class QuickNavigationConfig {
public boolean enableQuickNav = true;

@SerialEntry
public QuickNavItem button1 = new QuickNavItem(new ItemData(Items.DIAMOND_SWORD), "Your Skills", "/skills");
public QuickNavItem button1 = new QuickNavItem(new ItemData(Items.DIAMOND_SWORD), "Your Skills", "/skills", "Skills");

@SerialEntry
public QuickNavItem button2 = new QuickNavItem(new ItemData(Items.PAINTING), "Collections", "/collection");
public QuickNavItem button2 = new QuickNavItem(new ItemData(Items.PAINTING), "Collections", "/collection", "Collections");

/* REGEX Explanation
* "Pets" : simple match on letters
* "(?: \\(\\d+/\\d+\\))?" : optional match on the non-capturing group for the page in the format " ($number/$number)"
*/
@SerialEntry
public QuickNavItem button3 = new QuickNavItem(new ItemData(Items.BONE), "Pets(?: \\(\\d+/\\d+\\))?", "/pets");
public QuickNavItem button3 = new QuickNavItem(new ItemData(Items.BONE), "Pets(?: \\(\\d+/\\d+\\))?", "/pets", "Pets");

/* REGEX Explanation
* "Wardrobe" : simple match on letters
* " \\([12]/2\\)" : match on the page either " (1/2)" or " (2/2)"
*/
@SerialEntry
public QuickNavItem button4 = new QuickNavItem(new ItemData(Items.LEATHER_CHESTPLATE, "[minecraft:dyed_color={rgb:8991416}]"), "Wardrobe \\([12]/2\\)", "/wardrobe");
public QuickNavItem button4 = new QuickNavItem(new ItemData(Items.LEATHER_CHESTPLATE, "[minecraft:dyed_color={rgb:8991416}]"), "Wardrobe \\([12]/2\\)", "/wardrobe", "Wardrobe");

@SerialEntry
public QuickNavItem button5 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={id:[I;-2081424676,-57521078,-2073572414,158072763],name:\"\",properties:[{name:\"textures\",value:\"ewogICJ0aW1lc3RhbXAiIDogMTU5MTMxMDU4NTYwOSwKICAicHJvZmlsZUlkIiA6ICI0MWQzYWJjMmQ3NDk0MDBjOTA5MGQ1NDM0ZDAzODMxYiIsCiAgInByb2ZpbGVOYW1lIiA6ICJNZWdha2xvb24iLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODBhMDc3ZTI0OGQxNDI3NzJlYTgwMDg2NGY4YzU3OGI5ZDM2ODg1YjI5ZGFmODM2YjY0YTcwNjg4MmI2ZWMxMCIKICAgIH0KICB9Cn0=\"}]}]"), "Sack of Sacks", "/sacks");
public QuickNavItem button5 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={id:[I;-2081424676,-57521078,-2073572414,158072763],name:\"\",properties:[{name:\"textures\",value:\"ewogICJ0aW1lc3RhbXAiIDogMTU5MTMxMDU4NTYwOSwKICAicHJvZmlsZUlkIiA6ICI0MWQzYWJjMmQ3NDk0MDBjOTA5MGQ1NDM0ZDAzODMxYiIsCiAgInByb2ZpbGVOYW1lIiA6ICJNZWdha2xvb24iLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODBhMDc3ZTI0OGQxNDI3NzJlYTgwMDg2NGY4YzU3OGI5ZDM2ODg1YjI5ZGFmODM2YjY0YTcwNjg4MmI2ZWMxMCIKICAgIH0KICB9Cn0=\"}]}]"), "Sack of Sacks", "/sacks", "Sacks");

@SerialEntry
public QuickNavItem button6 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={name:\"5da6bec64bd942bc\",id:[I;1571208902,1272529596,-1566400349,-679283814],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTYxYTkxOGMwYzQ5YmE4ZDA1M2U1MjJjYjkxYWJjNzQ2ODkzNjdiNGQ4YWEwNmJmYzFiYTkxNTQ3MzA5ODVmZiJ9fX0=\"}]}]"), "Accessory Bag(?: \\(\\d/\\d\\))?", "/accessories");
public QuickNavItem button6 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={name:\"5da6bec64bd942bc\",id:[I;1571208902,1272529596,-1566400349,-679283814],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTYxYTkxOGMwYzQ5YmE4ZDA1M2U1MjJjYjkxYWJjNzQ2ODkzNjdiNGQ4YWEwNmJmYzFiYTkxNTQ3MzA5ODVmZiJ9fX0=\"}]}]"), "Accessory Bag(?: \\(\\d/\\d\\))?", "/accessories", "Accessories");

/* REGEX Explanation
* "(?:Rift )?" : optional match on the non-capturing group "Rift "
* "Storage" : simple match on letters
* "(?: \\(\\d/\\d\\))?" : optional match on the non-capturing group " (1/2)" or " (2/2)"
*/
@SerialEntry
public QuickNavItem button7 = new QuickNavItem(new ItemData(Items.ENDER_CHEST), "(?:Rift )?Storage(?: \\(\\d/\\d\\))?", "/storage");
public QuickNavItem button7 = new QuickNavItem(new ItemData(Items.ENDER_CHEST), "(?:Rift )?Storage(?: \\(\\d/\\d\\))?", "/storage", "Storage");

@SerialEntry
public QuickNavItem button8 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={name:\"421a8ef40eff47f4\",id:[I;1109036788,251611124,-2126904485,-130621758],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0=\"}]}]"), "/is");
public QuickNavItem button8 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={name:\"421a8ef40eff47f4\",id:[I;1109036788,251611124,-2126904485,-130621758],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0=\"}]}]"), "/is", "Home");

@SerialEntry
public QuickNavItem button9 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={name:\"e30e30d02878417c\",id:[I;-485609264,678969724,-1929747597,-718202427],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjQ4ODBkMmMxZTdiODZlODc1MjJlMjA4ODI2NTZmNDViYWZkNDJmOTQ5MzJiMmM1ZTBkNmVjYWE0OTBjYjRjIn19fQ==\"}]}]"), "/warp garden");
public QuickNavItem button9 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={name:\"e30e30d02878417c\",id:[I;-485609264,678969724,-1929747597,-718202427],properties:[{name:\"textures\",value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjQ4ODBkMmMxZTdiODZlODc1MjJlMjA4ODI2NTZmNDViYWZkNDJmOTQ5MzJiMmM1ZTBkNmVjYWE0OTBjYjRjIn19fQ==\"}]}]"), "/warp garden", "Garden");

@SerialEntry
public QuickNavItem button10 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={id:[I;-300151517,-631415889,-1193921967,-1821784279],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdjYzY2ODc0MjNkMDU3MGQ1NTZhYzUzZTA2NzZjYjU2M2JiZGQ5NzE3Y2Q4MjY5YmRlYmVkNmY2ZDRlN2JmOCJ9fX0=\"}]}]"), "/hub");
public QuickNavItem button10 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={id:[I;-300151517,-631415889,-1193921967,-1821784279],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdjYzY2ODc0MjNkMDU3MGQ1NTZhYzUzZTA2NzZjYjU2M2JiZGQ5NzE3Y2Q4MjY5YmRlYmVkNmY2ZDRlN2JmOCJ9fX0=\"}]}]"), "/hub", "Skyblock Hub");

@SerialEntry
public QuickNavItem button11 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={id:[I;1605800870,415127827,-1236127084,15358548],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg5MWQ1YjI3M2ZmMGJjNTBjOTYwYjJjZDg2ZWVmMWM0MGExYjk0MDMyYWU3MWU3NTQ3NWE1NjhhODI1NzQyMSJ9fX0=\"}]}]"), "/warp dungeon_hub");
public QuickNavItem button11 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={id:[I;1605800870,415127827,-1236127084,15358548],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg5MWQ1YjI3M2ZmMGJjNTBjOTYwYjJjZDg2ZWVmMWM0MGExYjk0MDMyYWU3MWU3NTQ3NWE1NjhhODI1NzQyMSJ9fX0=\"}]}]"), "/warp dungeon_hub", "Dungeons Hub");

@SerialEntry
public QuickNavItem button12 = new QuickNavItem(new ItemData(Items.GOLD_BLOCK), "Auction House", "/ah");
public QuickNavItem button12 = new QuickNavItem(new ItemData(Items.GOLD_BLOCK), "Auction House", "/ah", "Auction House");

@SerialEntry
public QuickNavItem button13 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={id:[I;-562285948,532499670,-1705302742,775653035],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmZlMmRjZGE0MWVjM2FmZjhhZjUwZjI3MmVjMmUwNmE4ZjUwOWUwZjgwN2YyMzU1YTFmNWEzM2MxYjY2ZTliNCJ9fX0=\"}]}]"), "Bazaar .*", "/bz");
public QuickNavItem button13 = new QuickNavItem(new ItemData(Items.PLAYER_HEAD, "[minecraft:profile={id:[I;-562285948,532499670,-1705302742,775653035],name:\"\",properties:[{name:\"textures\",value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmZlMmRjZGE0MWVjM2FmZjhhZjUwZjI3MmVjMmUwNmE4ZjUwOWUwZjgwN2YyMzU1YTFmNWEzM2MxYjY2ZTliNCJ9fX0=\"}]}]"), "Bazaar .*", "/bz", "Bazaar");

@SerialEntry
public QuickNavItem button14 = new QuickNavItem(new ItemData(Items.CRAFTING_TABLE), "Craft Item", "/craft");
public QuickNavItem button14 = new QuickNavItem(new ItemData(Items.CRAFTING_TABLE), "Craft Item", "/craft", "Crafting Table");

public static class QuickNavItem {
public QuickNavItem(ItemData itemData, @Language("RegExp") String uiTitle, String clickEvent) {
public QuickNavItem(ItemData itemData, @Language("RegExp") String uiTitle, String clickEvent, String tooltip) {
this.itemData = itemData;
this.uiTitle = uiTitle;
this.clickEvent = clickEvent;
this.tooltip = tooltip;
}

public QuickNavItem(ItemData itemData, String clickEvent) {
this(itemData, "none", clickEvent);
public QuickNavItem(ItemData itemData, String clickEvent, String tooltip) {
this(itemData, "none", clickEvent, tooltip);
}

@SerialEntry
Expand All @@ -84,6 +85,9 @@ public QuickNavItem(ItemData itemData, String clickEvent) {
@SerialEntry
public String uiTitle;

@SerialEntry
public String tooltip;

@SerialEntry
public String clickEvent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.regex.PatternSyntaxException;

public class QuickNav {
private static final Logger LOGGER = LoggerFactory.getLogger(QuickNav.class);
static final Logger LOGGER = LoggerFactory.getLogger(QuickNav.class);

public static List<QuickNavButton> init(String screenTitle) {
List<QuickNavButton> buttons = new ArrayList<>();
Expand Down Expand Up @@ -59,6 +59,6 @@ private static QuickNavButton parseButton(QuickNavigationConfig.QuickNavItem but
player.sendMessage(Constants.PREFIX.get().append(Text.literal("Invalid regex in Quick Nav Button " + (id + 1) + "!").formatted(Formatting.RED)), false);
}
}
return new QuickNavButton(id, uiTitleMatches, buttonInfo.clickEvent, stack);
return new QuickNavButton(id, uiTitleMatches, buttonInfo.clickEvent, stack, buttonInfo.tooltip);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package de.hysky.skyblocker.skyblock.quicknav;

import com.google.gson.JsonElement;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.serialization.JsonOps;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import net.fabricmc.api.EnvType;
Expand All @@ -10,11 +13,15 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;
import net.minecraft.util.Identifier;

import java.time.Duration;

@Environment(value = EnvType.CLIENT)
public class QuickNavButton extends ClickableWidget {
private final int index;
Expand Down Expand Up @@ -48,14 +55,22 @@ public boolean toggled() {
* @param toggled the toggled state of the button.
* @param command the command to execute when the button is clicked.
* @param icon the icon to display on the button.
* @param tooltip the tooltip to show when hovered
*/
public QuickNavButton(int index, boolean toggled, String command, ItemStack icon) {
public QuickNavButton(int index, boolean toggled, String command, ItemStack icon, String tooltip) {
super(0, 0, 26, 32, Text.empty());
this.index = index;
this.toggled = toggled;
this.command = command;
this.icon = icon;
this.toggleTime = 0;
if (tooltip == null || tooltip.isEmpty()) return;
try {
setTooltip(Tooltip.of(TextCodecs.CODEC.decode(JsonOps.INSTANCE, SkyblockerMod.GSON.fromJson(tooltip, JsonElement.class)).getOrThrow().getFirst()));
} catch (Exception e) {
setTooltip(Tooltip.of(Text.literal(tooltip)));
}
setTooltipDelay(Duration.ofMillis(100));
}

private void updateCoordinates() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@
"skyblocker.config.quickNav.button.item.count": "Item Count",
"skyblocker.config.quickNav.button.item.itemName": "Item",
"skyblocker.config.quickNav.button.render": "Render",
"skyblocker.config.quickNav.button.tooltip": "Tooltip",
"skyblocker.config.quickNav.button.tooltip.@Tooltip": "Tooltip shown when hovering your mouse over the button.\n\nYou can use text json format.\nPutting nothing will make the tooltip not render.",
"skyblocker.config.quickNav.button.uiTitle": "UI Title",
"skyblocker.config.quickNav.enableQuickNav": "Enable Quick Navigation",

Expand Down

0 comments on commit 2dd2ddf

Please sign in to comment.