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

Concept for prefix system #8

Merged
merged 2 commits into from
Sep 10, 2024
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
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