From 6b4c5e4d65e996f54157ac023180757f45a41196 Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 10 Sep 2024 15:19:26 -0400 Subject: [PATCH 1/2] concept for prefix system --- .../wispforest/limelight/api/entry/ResultEntry.java | 13 +++++++++++++ .../limelight/impl/ui/ResultEntryComponent.java | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java b/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java index c12c631..1a09df4 100644 --- a/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java +++ b/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java @@ -3,6 +3,8 @@ import io.wispforest.limelight.api.extension.LimelightExtension; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.Language; +import net.minecraft.util.Util; /** * Represents a result entry in the Limelight GUI. @@ -24,4 +26,15 @@ public sealed interface ResultEntry permits InvokeResultEntry, SetSearchTextEntr * @return the text of this entry */ Text text(); + + /** + * @return the prefix used to identify the extension in the search result. + * @apiNote By default, it'll use the translation if it exists, if it doesn't, it'll use the extension's name + * */ + default Text prefix() { + String key = Util.createTranslationKey("limelightExtension", extension().id()) + ".prefix"; + if (Language.getInstance().hasTranslation(key)) + return Text.translatable(key); + return extension().name(); + } } diff --git a/src/client/java/io/wispforest/limelight/impl/ui/ResultEntryComponent.java b/src/client/java/io/wispforest/limelight/impl/ui/ResultEntryComponent.java index 9024b0b..ca0f4cb 100644 --- a/src/client/java/io/wispforest/limelight/impl/ui/ResultEntryComponent.java +++ b/src/client/java/io/wispforest/limelight/impl/ui/ResultEntryComponent.java @@ -50,7 +50,7 @@ public ResultEntryComponent(LimelightScreen screen, ResultEntry entry, boolean i labelBuilder.append( Text.empty() - .append(entry.extension().name()) + .append(entry.prefix()) .styled(x -> x.withColor(isChild ? theme.childSourceExtensionColor() : theme.sourceExtensionColor())) .styled(x -> x.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltipText))) ); From 4b1c8bcedc72c45f6364f5c26d2d1a3e5e843f42 Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 10 Sep 2024 16:00:23 -0400 Subject: [PATCH 2/2] Added LimelightExtension.baseTranslationKey() --- .../wispforest/limelight/api/entry/ResultEntry.java | 2 +- .../limelight/api/extension/LimelightExtension.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java b/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java index 1a09df4..4368e4c 100644 --- a/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java +++ b/src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java @@ -32,7 +32,7 @@ public sealed interface ResultEntry permits InvokeResultEntry, SetSearchTextEntr * @apiNote By default, it'll use the translation if it exists, if it doesn't, it'll use the extension's name * */ default Text prefix() { - String key = Util.createTranslationKey("limelightExtension", extension().id()) + ".prefix"; + String key = extension().baseTranslationKey() + ".prefix"; if (Language.getInstance().hasTranslation(key)) return Text.translatable(key); return extension().name(); diff --git a/src/client/java/io/wispforest/limelight/api/extension/LimelightExtension.java b/src/client/java/io/wispforest/limelight/api/extension/LimelightExtension.java index 604e159..aa284c4 100644 --- a/src/client/java/io/wispforest/limelight/api/extension/LimelightExtension.java +++ b/src/client/java/io/wispforest/limelight/api/extension/LimelightExtension.java @@ -24,11 +24,18 @@ public interface LimelightExtension extends ResultEntryGatherer { */ Identifier id(); + /** + * @return the base translation key + * */ + default String baseTranslationKey() { + return Util.createTranslationKey("limelightExtension", id()); + } + /** * @return the name of this extension, to be used in the main and config screens */ default Text name() { - return Text.translatable(Util.createTranslationKey("limelightExtension", id())); + return Text.translatable(baseTranslationKey()); } /** @@ -55,7 +62,7 @@ default List tooltip() { * @return the description of this extension, to be used in the main and config screens */ default @Nullable Text description() { - String key = Util.createTranslationKey("limelightExtension", id()) + ".desc"; + String key = baseTranslationKey() + ".desc"; if (!Language.getInstance().hasTranslation(key)) return null; return Text.translatable(key); }