Skip to content

Commit

Permalink
Improve Obtained & Museum Item Tooltips (#417)
Browse files Browse the repository at this point in the history
Co-authored-by: alexia <[email protected]>
  • Loading branch information
AzureAaron and lunaynx authored Nov 14, 2023
1 parent cb495ea commit 7fd8afe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@ public static class ItemTooltip {
public boolean enableBazaarPrice = true;

@SerialEntry
public boolean enableMuseumDate = true;
public boolean enableObtainedDate = true;

@SerialEntry
public boolean enableMuseumInfo = true;

@SerialEntry
public boolean enableExoticTooltip = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,18 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumDate"))
.binding(defaults.general.itemTooltip.enableMuseumDate,
() -> config.general.itemTooltip.enableMuseumDate,
newValue -> config.general.itemTooltip.enableMuseumDate = newValue)
.name(Text.translatable("text.autoconfig.skyblocker.option.general.itemTooltip.enableObtainedDate"))
.binding(defaults.general.itemTooltip.enableObtainedDate,
() -> config.general.itemTooltip.enableObtainedDate,
newValue -> config.general.itemTooltip.enableObtainedDate = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumInfo"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumInfo.@Tooltip")))
.binding(defaults.general.itemTooltip.enableMuseumInfo,
() -> config.general.itemTooltip.enableMuseumInfo,
newValue -> config.general.itemTooltip.enableMuseumInfo = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static void tick(String profileId) {

public static boolean hasItemInMuseum(String id) {
String uuid = UndashedUuid.toString(MinecraftClient.getInstance().getSession().getUuidOrNull());
ObjectOpenHashSet<String> collectedItemIds = MUSEUM_ITEM_CACHE.get(uuid).get(Utils.getProfileId()).collectedItemIds();
ObjectOpenHashSet<String> collectedItemIds = (!MUSEUM_ITEM_CACHE.containsKey(uuid) || Utils.getProfileId().isBlank() || !MUSEUM_ITEM_CACHE.get(uuid).containsKey(Utils.getProfileId())) ? null : MUSEUM_ITEM_CACHE.get(uuid).get(Utils.getProfileId()).collectedItemIds();

return collectedItemIds != null && collectedItemIds.contains(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.item.MuseumItemCache;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Utils;
Expand Down Expand Up @@ -146,26 +147,41 @@ public static void getTooltip(ItemStack stack, TooltipContext context, List<Text
.append(getMotesMessage(TooltipInfoType.MOTES.getData().get(internalID).getAsInt(), count)));
}

if (TooltipInfoType.MUSEUM.isTooltipEnabled() && !bazaarOpened) {
if (TooltipInfoType.OBTAINED.isTooltipEnabled()) {
String timestamp = getTimestamp(stack);

if (TooltipInfoType.MUSEUM.hasOrNullWarning(internalID)) {
String itemCategory = TooltipInfoType.MUSEUM.getData().get(internalID).getAsString();
String format = switch (itemCategory) {
case "Weapons" -> "%-18s";
case "Armor" -> "%-19s";
default -> "%-20s";
};
lines.add(Text.literal(String.format(format, "Museum: (" + itemCategory + ")"))
.formatted(Formatting.LIGHT_PURPLE)
.append(Text.literal(timestamp).formatted(Formatting.RED)));
} else if (!timestamp.isEmpty()) {
if (!timestamp.isEmpty()) {
lines.add(Text.literal(String.format("%-21s", "Obtained: "))
.formatted(Formatting.LIGHT_PURPLE)
.append(Text.literal(timestamp).formatted(Formatting.RED)));
}
}

if (TooltipInfoType.MUSEUM.isTooltipEnabledAndHasOrNullWarning(internalID) && !bazaarOpened) {
String itemCategory = TooltipInfoType.MUSEUM.getData().get(internalID).getAsString();
String format = switch (itemCategory) {
case "Weapons" -> "%-18s";
case "Armor" -> "%-19s";
default -> "%-20s";
};

//Special case the special category so that it doesn't always display not donated
if (itemCategory.equals("Special")) {
lines.add(Text.literal(String.format(format, "Museum: (" + itemCategory + ")"))
.formatted(Formatting.LIGHT_PURPLE));
} else {
NbtCompound extraAttributes = ItemUtils.getExtraAttributes(stack);
boolean isInMuseum = (extraAttributes.contains("donated_museum") && extraAttributes.getBoolean("donated_museum")) || MuseumItemCache.hasItemInMuseum(internalID);

Formatting donatedIndicatorFormatting = isInMuseum ? Formatting.GREEN : Formatting.RED;

lines.add(Text.literal(String.format(format, "Museum (" + itemCategory + "):"))
.formatted(Formatting.LIGHT_PURPLE)
.append(Text.literal(isInMuseum ? "✔" : "✖").formatted(donatedIndicatorFormatting, Formatting.BOLD))
.append(Text.literal(isInMuseum ? " Donated" : " Not Donated").formatted(donatedIndicatorFormatting)));
}
}

if (TooltipInfoType.COLOR.isTooltipEnabledAndHasOrNullWarning(internalID) && stack.getNbt() != null) {
final NbtElement color = stack.getNbt().getCompound("display").get("color");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum TooltipInfoType implements Runnable {
ONE_DAY_AVERAGE("https://moulberry.codes/auction_averages_lbin/1day.json", itemTooltip -> itemTooltip.enableAvgBIN, false),
THREE_DAY_AVERAGE("https://moulberry.codes/auction_averages_lbin/3day.json", itemTooltip -> itemTooltip.enableAvgBIN, false),
MOTES("https://hysky.de/api/motesprice", itemTooltip -> itemTooltip.enableMotesPrice, itemTooltip -> itemTooltip.enableMotesPrice && Utils.isInTheRift(), true),
MUSEUM("https://hysky.de/api/museum", itemTooltip -> itemTooltip.enableMuseumDate, true),
OBTAINED(itemTooltip -> itemTooltip.enableObtainedDate),
MUSEUM("https://hysky.de/api/museum", itemTooltip -> itemTooltip.enableMuseumInfo, true),
COLOR("https://hysky.de/api/color", itemTooltip -> itemTooltip.enableExoticTooltip, true);

private final String address;
Expand All @@ -30,6 +31,13 @@ public enum TooltipInfoType implements Runnable {
private final boolean cacheable;
private long hash;

/**
* Use this for when you're adding tooltip info that has no data associated with it
*/
TooltipInfoType(Predicate<SkyblockerConfig.ItemTooltip> enabled) {
this(null, itemTooltip -> false, enabled, null, false);
}

/**
* @param address the address to download the data from
* @param enabled the predicate to check if the data should be downloaded and the tooltip should be shown
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
"text.autoconfig.skyblocker.option.general.itemTooltip.avg.BOTH": "Both",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableLowestBIN": "Enable Lowest BIN Price",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableBazaarPrice": "Enable Bazaar buy/sell Price",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumDate": "Enable Museum & Date",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableObtainedDate": "Enable Obtained Date",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumInfo": "Enable Museum Info",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumInfo.@Tooltip": "If this item is donatable to the museum, then the item's category in the musuem is displayed. It also displays a marker indicating whether you've donated that item to your musuem or not (freebies not yet supported).",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableExoticTooltip": "Enable Exotic Tooltip",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableExoticTooltip.@Tooltip": "Displays the type of exotic below the item's name if an armor piece is exotic.",
"text.autoconfig.skyblocker.option.general.itemInfoDisplay": "Item Info Display",
Expand Down

0 comments on commit 7fd8afe

Please sign in to comment.