Skip to content

Commit

Permalink
Merge pull request #8 from Minenash/prefix-concept3
Browse files Browse the repository at this point in the history
Concept for prefix system
  • Loading branch information
BasiqueEvangelist authored Sep 10, 2024
2 parents e71f783 + 4b1c8bc commit 669358a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/client/java/io/wispforest/limelight/api/entry/ResultEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = extension().baseTranslationKey() + ".prefix";
if (Language.getInstance().hasTranslation(key))
return Text.translatable(key);
return extension().name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -55,7 +62,7 @@ default List<Text> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
);
Expand Down

0 comments on commit 669358a

Please sign in to comment.