Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per Slot Text Toggle #1043

Merged
merged 6 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import de.hysky.skyblocker.config.ConfigUtils;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.configs.GeneralConfig;
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextMode;
import de.hysky.skyblocker.skyblock.item.tooltip.adders.CraftPriceTooltip;
import de.hysky.skyblocker.skyblock.shortcut.ShortcutsConfigScreen;
import dev.isxander.yacl3.api.*;
Expand Down Expand Up @@ -269,23 +268,6 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.group(OptionGroup.createBuilder()
.name(Text.translatable("skyblocker.config.general.itemInfoDisplay"))
.collapsed(true)
.option(Option.<SlotTextMode>createBuilder()
.name(Text.translatable("skyblocker.config.general.itemInfoDisplay.slotText"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.general.itemInfoDisplay.slotText.@Tooltip")))
.binding(defaults.general.itemInfoDisplay.slotTextMode,
() -> config.general.itemInfoDisplay.slotTextMode,
newValue -> config.general.itemInfoDisplay.slotTextMode = newValue)
.controller(ConfigUtils::createEnumCyclingListController)
.build())
.option(ConfigUtils.createShortcutToKeybindsScreen())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.itemInfoDisplay.attributeShardInfo"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.general.itemInfoDisplay.attributeShardInfo.@Tooltip")))
.binding(defaults.general.itemInfoDisplay.attributeShardInfo,
() -> config.general.itemInfoDisplay.attributeShardInfo,
newValue -> config.general.itemInfoDisplay.attributeShardInfo = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.itemInfoDisplay.itemRarityBackgrounds"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.general.itemInfoDisplay.itemRarityBackgrounds.@Tooltip")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.configs.UIAndVisualsConfig;
import de.hysky.skyblocker.skyblock.fancybars.StatusBarsConfigScreen;
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextManager;
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextMode;
import de.hysky.skyblocker.skyblock.tabhud.config.WidgetsConfigurationScreen;
import de.hysky.skyblocker.skyblock.tabhud.screenbuilder.ScreenBuilder;
import de.hysky.skyblocker.skyblock.tabhud.screenbuilder.ScreenMaster;
import de.hysky.skyblocker.skyblock.waypoint.WaypointsScreen;
import de.hysky.skyblocker.utils.Location;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.container.SlotTextAdder;
import de.hysky.skyblocker.utils.render.title.TitleContainerConfigScreen;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import dev.isxander.yacl3.api.ConfigCategory;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.ColorControllerBuilder;
import dev.isxander.yacl3.api.controller.FloatFieldControllerBuilder;
Expand All @@ -23,6 +25,9 @@
import net.minecraft.util.Formatting;

import java.awt.*;
import java.util.Collection;
import java.util.Comparator;
import java.util.Objects;

public class UIAndVisualsCategory {
public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig config) {
Expand Down Expand Up @@ -133,6 +138,23 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.build())
.build())

.group(OptionGroup.createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.slotText"))
.collapsed(true)
.option(Option.<SlotTextMode>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.slotText"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.uiAndVisuals.slotText.@Tooltip")))
.binding(defaults.uiAndVisuals.slotText.slotTextMode,
() -> config.uiAndVisuals.slotText.slotTextMode,
newValue -> config.uiAndVisuals.slotText.slotTextMode = newValue)
.controller(ConfigUtils::createEnumCyclingListController)
.build())
.option(ConfigUtils.createShortcutToKeybindsScreen())
.option(LabelOption.create(Text.translatable("skyblocker.config.uiAndVisuals.slotText.separator")))
.options(createSlotTextToggles(config))
.build()
)

// Inventory Search
.group(OptionGroup.createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.inventorySearch"))
Expand Down Expand Up @@ -492,4 +514,10 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig

.build();
}

private static Collection<Option<Boolean>> createSlotTextToggles(SkyblockerConfig config) {
return SlotTextManager.getAdderStream().map(SlotTextAdder::getConfigInformation).filter(Objects::nonNull).distinct()
.map(configInfo -> configInfo.getOption(config))
.sorted(Comparator.comparing(option -> option.name().getString())).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,15 @@ public static class ItemInfoDisplay {
@SerialEntry
public boolean slotText = true;

@Deprecated
@SerialEntry
public SlotTextMode slotTextMode = SlotTextMode.ENABLED;

@Deprecated
@SerialEntry
public boolean slotTextToggled = true;

@Deprecated
@SerialEntry
public boolean attributeShardInfo = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package de.hysky.skyblocker.config.configs;

import de.hysky.skyblocker.skyblock.item.slottext.SlotTextMode;
import de.hysky.skyblocker.skyblock.tabhud.screenbuilder.ScreenBuilder;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.util.Formatting;

Expand Down Expand Up @@ -41,6 +44,9 @@ public class UIAndVisualsConfig {
@SerialEntry
public ItemCooldown itemCooldown = new ItemCooldown();

@SerialEntry
public SlotText slotText = new SlotText();

@SerialEntry
public InventorySearchConfig inventorySearch = new InventorySearchConfig();

Expand Down Expand Up @@ -90,6 +96,19 @@ public static class ItemCooldown {
public boolean enableItemCooldowns = true;
}

public static class SlotText {

@SerialEntry
public SlotTextMode slotTextMode = SlotTextMode.ENABLED;

@SerialEntry
public Object2BooleanMap<String> textEnabled = new Object2BooleanOpenHashMap<>();

@SerialEntry
public boolean slotTextToggled = true;

}

public static class InventorySearchConfig {
@SerialEntry
public EnableState enabled = EnableState.SKYBLOCK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.hysky.skyblocker.utils.container.SlotTextAdder;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.regex.Pattern;

Expand All @@ -12,28 +13,67 @@
* Extend this class and add it to {@link SlotTextManager#adders} to add text to any arbitrary slot.
*/
public abstract class SimpleSlotTextAdder extends RegexContainerMatcher implements SlotTextAdder {
protected final @Nullable ConfigInformation configInformation;

/**
* Utility constructor that will compile the given string into a pattern.
* Utility constructor that will compile the given string into a pattern with no config
*
* @see #SimpleSlotTextAdder(Pattern)
*/
protected SimpleSlotTextAdder(@NotNull @Language("RegExp") String titlePattern) {
this(titlePattern, null);
}

/**
* Creates a SlotTextAdder that will be applied to screens with titles that match the given pattern with no config
*
* @param titlePattern The pattern to match the screen title against.
*/
protected SimpleSlotTextAdder(@NotNull Pattern titlePattern) {
this(titlePattern, null);
}

/**
* Creates a SlotTextAdder that will be applied to all screens with no config
*/
protected SimpleSlotTextAdder() {
this((ConfigInformation) null);
}

/**
* Utility constructor that will compile the given string into a pattern.
* The adder will be able to be turned off/on in the config using info provided by the {@link de.hysky.skyblocker.utils.container.SlotTextAdder.ConfigInformation}
*
* @see #SimpleSlotTextAdder(Pattern)
*/
protected SimpleSlotTextAdder(@NotNull @Language("RegExp") String titlePattern, @Nullable ConfigInformation configInformation) {
super(titlePattern);
this.configInformation = configInformation;
}

/**
* Creates a SlotTextAdder that will be applied to screens with titles that match the given pattern.
* The adder will be able to be turned off/on in the config using info provided by the {@link de.hysky.skyblocker.utils.container.SlotTextAdder.ConfigInformation}
*
* @param titlePattern The pattern to match the screen title against.
*/
protected SimpleSlotTextAdder(@NotNull Pattern titlePattern) {
protected SimpleSlotTextAdder(@NotNull Pattern titlePattern, @Nullable ConfigInformation configInformation) {
super(titlePattern);
this.configInformation = configInformation;
}

/**
* Creates a SlotTextAdder that will be applied to all screens.
* The adder will be able to be turned off/on in the config using info provided by the {@link de.hysky.skyblocker.utils.container.SlotTextAdder.ConfigInformation}
*/
protected SimpleSlotTextAdder() {
protected SimpleSlotTextAdder(@Nullable ConfigInformation configInformation) {
super();
this.configInformation = configInformation;
}

@Override
@Nullable
public ConfigInformation getConfigInformation() {
return configInformation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import org.lwjgl.glfw.GLFW;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class SlotTextManager {
private static final SlotTextAdder[] adders = new SlotTextAdder[]{
Expand Down Expand Up @@ -70,7 +72,7 @@ public static void init() {
}
ScreenKeyboardEvents.afterKeyPress(screen).register((screen1, key, scancode, modifiers) -> {
if (keyBinding.matchesKey(key, scancode)) {
SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextToggled = !SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextToggled;
SkyblockerConfigManager.get().uiAndVisuals.slotText.slotTextToggled = !SkyblockerConfigManager.get().uiAndVisuals.slotText.slotTextToggled;
keyHeld = true;
}
});
Expand Down Expand Up @@ -141,11 +143,19 @@ public static void renderSlotText(DrawContext context, TextRenderer textRenderer
}
}

public static Stream<SlotTextAdder> getAdderStream() {
return Arrays.stream(adders);
}

public static boolean isEnabled(String adderId) {
return SkyblockerConfigManager.get().uiAndVisuals.slotText.textEnabled.getOrDefault(adderId, true);
}

public static boolean isEnabled() {
return switch (SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextMode) {
return switch (SkyblockerConfigManager.get().uiAndVisuals.slotText.slotTextMode) {
case ENABLED -> true;
case DISABLED -> false;
case PRESS_TO_TOGGLE -> SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextToggled;
case PRESS_TO_TOGGLE -> SkyblockerConfigManager.get().uiAndVisuals.slotText.slotTextToggled;
case HOLD_TO_HIDE -> !keyHeld;
case HOLD_TO_SHOW -> keyHeld;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public enum SlotTextMode {

@Override
public String toString() {
return I18n.translate("skyblocker.config.general.itemInfoDisplay.slotText.mode." + name());
return I18n.translate("skyblocker.config.uiAndVisuals.slotText.mode." + name());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.hysky.skyblocker.skyblock.item.slottext.adders;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder;
import de.hysky.skyblocker.utils.ItemUtils;
Expand All @@ -17,6 +16,10 @@

public class AttributeShardAdder extends SimpleSlotTextAdder {
private static final Object2ObjectMap<String, String> ID_2_SHORT_NAME = new Object2ObjectOpenHashMap<>();
private static final ConfigInformation CONFIG_INFORMATION = new ConfigInformation(
"attribute_shard",
"skyblocker.config.uiAndVisuals.slotText.attributeShard",
"skyblocker.config.uiAndVisuals.slotText.attributeShard.@Tooltip");

static {
//Weapons
Expand Down Expand Up @@ -66,7 +69,7 @@ public class AttributeShardAdder extends SimpleSlotTextAdder {
}

public AttributeShardAdder() {
super();
super(CONFIG_INFORMATION);
}

@Override
Expand All @@ -88,9 +91,4 @@ public AttributeShardAdder() {
SlotText.topLeft(Text.literal(attributeInitials).withColor(0xCFF8F8))
);
}

@Override
public boolean isEnabled() {
return SkyblockerConfigManager.get().general.itemInfoDisplay.attributeShardInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder;
import de.hysky.skyblocker.utils.RomanNumerals;
import de.hysky.skyblocker.utils.container.SlotTextAdder;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
Expand All @@ -18,13 +19,18 @@
//This class is split into 3 inner classes as there are multiple screens for showing catacombs levels, each with different slot ids or different style of showing the level.
//It's still kept in 1 main class for organization purposes.
public class CatacombsLevelAdder {

private static final SlotTextAdder.ConfigInformation CONFIG_INFORMATION = new SlotTextAdder.ConfigInformation(
"catacombs_level",
"skyblocker.config.uiAndVisuals.slotText.catacombsLevel");

private CatacombsLevelAdder() {
}

public static class Dungeoneering extends SimpleSlotTextAdder {
private static final Pattern LEVEL_PATTERN = Pattern.compile(".*?(?:(?<arabic>\\d+)|(?<roman>\\S+))? ?✯?");
public Dungeoneering() {
super("^Dungeoneering");
super("^Dungeoneering", CONFIG_INFORMATION);
}

@Override
Expand Down Expand Up @@ -57,7 +63,7 @@ public Dungeoneering() {
public static class DungeonClasses extends SimpleSlotTextAdder {

public DungeonClasses() {
super("^Dungeon Classes"); //Applies to both screens as they are same in both the placement and the style of the level text.
super("^Dungeon Classes", CONFIG_INFORMATION); //Applies to both screens as they are same in both the placement and the style of the level text.
}

@Override
Expand All @@ -78,7 +84,7 @@ public DungeonClasses() {
public static class ReadyUp extends SimpleSlotTextAdder {

public ReadyUp() {
super("^Ready Up");
super("^Ready Up", CONFIG_INFORMATION);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@

public class CollectionAdder extends SimpleSlotTextAdder {
private static final Pattern COLLECTION = Pattern.compile("^[\\w -]+ (?<level>[IVXLCDM]+)$");
private static final ConfigInformation CONFIG_INFORMATION = new ConfigInformation(
"collection",
"skyblocker.config.uiAndVisuals.slotText.collectionLevel"
);

public CollectionAdder() {
super("^\\w+ Collections");
super("^\\w+ Collections", CONFIG_INFORMATION);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
public class CommunityShopAdder extends SimpleSlotTextAdder {
private static final byte CATEGORIES_START = 10;
private static final byte CATEGORIES_END = 14; //Inclusive
private static final ConfigInformation CONFIG_INFORMATION = new ConfigInformation(
"community_shop",
"skyblocker.config.uiAndVisuals.slotText.communityShop",
"skyblocker.config.uiAndVisuals.slotText.communityShop.@Tooltip");
private static byte currentScreen = -1; // 0 = city projects, 1 = upgrades, 2 = booster cookie, 3 = bits shop, 4 = fire sales, any other number = invalid

public CommunityShopAdder() {
super("^Community Shop");
super("^Community Shop", CONFIG_INFORMATION);
}

@Override
Expand Down
Loading
Loading