Skip to content

Commit

Permalink
Add search tags
Browse files Browse the repository at this point in the history
Closes #20
  • Loading branch information
nea89o committed Feb 20, 2024
1 parent bbbd56b commit 6943309
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.moulberry.moulconfig.annotations

/**
* Add additional search tags to your [ConfigOption]. These search tags will not appear anywhere user facing, but
* the [io.github.moulberry.moulconfig.gui.GuiOptionEditor.fulfillsSearch] function will use them to filter
* additional elements in the search
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD)
@Repeatable
annotation class SearchTag(
val value: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package io.github.moulberry.moulconfig.gui;

import io.github.moulberry.moulconfig.annotations.SearchTag;
import io.github.moulberry.moulconfig.internal.RenderUtils;
import io.github.moulberry.moulconfig.internal.TextRenderUtils;
import io.github.moulberry.moulconfig.processor.ProcessedOption;
Expand All @@ -35,6 +36,7 @@ public abstract class GuiOptionEditor {
protected final ProcessedOption option;
public MoulConfigEditor<?> activeConfigGUI;
private String searchDescNameCache;
private String searchTags = "";

@ApiStatus.Internal
public ProcessedOption getOption() {
Expand All @@ -43,9 +45,16 @@ public ProcessedOption getOption() {

public GuiOptionEditor(ProcessedOption option) {
this.option = option;
SearchTag[] annotationsByType = option.field.getAnnotationsByType(SearchTag.class);
for (SearchTag searchTag : annotationsByType) {
if (!searchTags.isEmpty()) {
searchTags += " ";
}
searchTags += searchTag;
}
}

public void render(int x, int y, int width) {
public void render(int x, int y, int width) {
int height = getHeight();

FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
Expand Down Expand Up @@ -94,7 +103,7 @@ public void renderOverlay(int x, int y, int width) {

public boolean fulfillsSearch(String word) {
if (searchDescNameCache == null) {
searchDescNameCache = (option.name + option.desc).toLowerCase(Locale.ROOT);
searchDescNameCache = (option.name + option.desc + searchTags).toLowerCase(Locale.ROOT);
}
return searchDescNameCache.contains(word);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.moulberry.moulconfig.annotations.Category;
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
import io.github.moulberry.moulconfig.annotations.ConfigOption;
import io.github.moulberry.moulconfig.annotations.SearchTag;

public class TestCategoryParent {
@Category(name = "SubCategory", desc = "Subbier Sub description")
Expand All @@ -15,5 +16,7 @@ public class TestCategoryParent {
desc = "com111"
)
@ConfigEditorBoolean
@SearchTag("oomf")
@SearchTag("hannibal2")
public boolean w = false;
}

0 comments on commit 6943309

Please sign in to comment.