Skip to content

Commit

Permalink
add search support for resource/data packs screens
Browse files Browse the repository at this point in the history
  • Loading branch information
Antikyth committed Sep 17, 2023
1 parent 229dd08 commit 6c3ce22
Show file tree
Hide file tree
Showing 23 changed files with 323 additions and 55 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
# Mod Properties
version=0.1.1
version=0.2.0
maven_group=io.github.antikyth
archives_base_name=searchable
# Dependencies are managed at gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.1 2023-09-14T12:39:06.073621692 Searchable/Language (en_us)
37d4d7775d43b425d020574f6d397748e2093ed2 assets/searchable/lang/en_us.json
// 1.20.1 2023-09-17T16:26:09.415058591 Searchable/Language (en_us)
46fba4b4e11e5664b2bdbb8be156734b474b0951 assets/searchable/lang/en_us.json
7 changes: 7 additions & 0 deletions src/main/generated/assets/searchable/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"config.searchable.category.keybinds_screen": "Key Binds Screen",
"config.searchable.category.language_screen": "Languages Screen",
"config.searchable.category.searchable_config_screen": "Searchable Options Screen",
"config.searchable.category.select_packs_screen": "Select Packs Screens",
"config.searchable.category.select_packs_screen.description": "The select resource packs and select data packs screens.",
"config.searchable.category.select_server_screen": "Select Server Screen",
"config.searchable.category.select_server_screen.description": "The multiplayer server selection screen.",
"config.searchable.category.select_world_screen": "Select World Screen",
Expand Down Expand Up @@ -37,6 +39,9 @@
"config.searchable.option.searchable_config_screen.match_technical_names.description": "Whether config option technical names should be searched for matching text during a search.",
"config.searchable.option.searchable_config_screen.show_technical_names": "Show Technical Names",
"config.searchable.option.searchable_config_screen.show_technical_names.description": "Whether config option technical names should be shown under their titles.",
"config.searchable.option.select_packs_screen.add_search": "Add Search Box",
"config.searchable.option.select_packs_screen.match_descriptions": "Match Descriptions",
"config.searchable.option.select_packs_screen.match_descriptions.description": "Whether resource pack and data pack descriptions should be searched for matching text during a search.",
"config.searchable.option.select_server_screen.add_search": "Add Search Box",
"config.searchable.option.select_server_screen.match_motds": "Match MOTDs",
"config.searchable.option.select_server_screen.match_motds.description": "Whether server descriptions should be searched for matching text during a search.",
Expand All @@ -57,6 +62,8 @@
"modmenu.summaryTranslation.searchable": "Improves the singleplayer select world screen search and adds it to other GUIs.",
"option.language.search": "search for languages",
"option.language.search.hint": "Search...",
"pack.search": "search for packs",
"pack.search.hint": "Search...",
"selectServer.search": "search for multiplayer servers",
"selectServer.search.hint": "Search...",
"selectWorld.search.hint": "Search..."
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/github/antikyth/searchable/Searchable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class Searchable implements PreLaunchEntrypoint, ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger(NAME);

public static final int SEARCH_BOX_WIDTH = 200;
public static final int SEARCH_BOX_Y = 22;

public static final int CONFIG_BUTTON_OFFSET = 3;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@

public interface MultiplayerServerListWidgetAccessor extends SetQueryAccessor {
MultiplayerServerListWidget.Entry searchable$getLastSelection();

String searchable$getQuery();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public class SearchableConfig extends ReflectiveConfig {
public final SelectWorldScreenOptions select_world_screen = new SelectWorldScreenOptions();
@Comment(EnglishUs.Config.EditGameRulesScreen.DESCRIPTION)
public final EditGameRulesScreenOptions edit_gamerules_screen = new EditGameRulesScreenOptions();
@Comment(EnglishUs.Config.SelectPacksScreen.DESCRIPTION)
public final SelectPackScreenOptions select_packs_screen = new SelectPackScreenOptions();

public static class SearchableConfigScreenOptions extends Section {
public static final class SearchableConfigScreenOptions extends Section {
@Comment(EnglishUs.Config.SearchableConfigScreen.SHOW_TECHNICAL_NAMES_DESCRIPTION)
public final TrackedValue<Boolean> show_technical_names = value(false);

Expand All @@ -47,7 +49,7 @@ public static class SearchableConfigScreenOptions extends Section {
public final TrackedValue<Boolean> match_technical_names = value(false);
}

public static class KeyBindScreenOptions extends Section {
public static final class KeyBindScreenOptions extends Section {
public final TrackedValue<Boolean> add_search = value(true);

@Comment(EnglishUs.Config.KeyBindsScreen.MATCH_CATEGORIES_DESCRIPTION)
Expand All @@ -56,23 +58,23 @@ public static class KeyBindScreenOptions extends Section {
public final TrackedValue<Boolean> match_bound_keys = value(true);
}

public static class LanguageScreenOptions extends Section {
public static final class LanguageScreenOptions extends Section {
public final TrackedValue<Boolean> add_search = value(true);
}

public static class SelectServerScreenOptions extends Section {
public static final class SelectServerScreenOptions extends Section {
public final TrackedValue<Boolean> add_search = value(true);

@Comment(EnglishUs.Config.SelectServerScreen.MATCH_MOTDS_DESCRIPTION)
public final TrackedValue<Boolean> match_motds = value(true);
}

public static class SelectWorldScreenOptions extends Section {
public static final class SelectWorldScreenOptions extends Section {
@Comment(EnglishUs.Config.SelectWorldScreen.MATCH_WORLD_DETAILS_DESCRIPTION)
public final TrackedValue<Boolean> match_world_details = value(false);
}

public static class EditGameRulesScreenOptions extends Section {
public static final class EditGameRulesScreenOptions extends Section {
public final TrackedValue<Boolean> add_search = value(true);

@Comment(EnglishUs.Config.EditGameRulesScreen.SHOW_TECHNICAL_NAMES_DESCRIPTION)
Expand All @@ -85,4 +87,11 @@ public static class EditGameRulesScreenOptions extends Section {
@Comment(EnglishUs.Config.EditGameRulesScreen.MATCH_TECHNICAL_NAMES_DESCRIPTION)
public final TrackedValue<Boolean> match_technical_names = value(true);
}

public static final class SelectPackScreenOptions extends Section {
public final TrackedValue<Boolean> add_search = value(true);

@Comment(EnglishUs.Config.SelectPacksScreen.MATCH_DESCRIPTIONS_DESCRIPTION)
public final TrackedValue<Boolean> match_descriptions = value(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public EnglishUs(FabricDataOutput dataGenerator) {
@Translation("option.language.search.hint")
@Translation("selectServer.search.hint")
@Translation("selectWorld.search.hint")
@Translation("pack.search.hint")
@Translation("config.%s.search.hint")
public static final String SEARCH_HINT = "Search...";
public static final String ADD_SEARCH = "Add Search Box";
Expand All @@ -43,6 +44,8 @@ public static class ModMenu {
public static final String SELECT_SERVER_SEARCH_NARRATION = "search for multiplayer servers";
@Translation("editGamerule.search")
public static final String EDIT_GAME_RULE_SEARCH_NARRATION = "search for game rules";
@Translation("pack.search")
public static final String SELECT_PACKS_SEARCH_NARRATION = "search for packs";

public static class Config {
@Translation("config.%s.title")
Expand Down Expand Up @@ -207,6 +210,23 @@ public static final class EditGameRulesScreen {
public static final String MATCH_TECHNICAL_NAMES_DESCRIPTION = """
Whether game rule technical names should be searched for matching text during a search.""";
}

@Translation.ConfigCategory("select_packs_screen")
public static final class SelectPacksScreen {
@Translation.ConfigCategory.Name
public static final String NAME = "Select Packs Screens";
@Translation.ConfigCategory.Description
public static final String DESCRIPTION = "The select resource packs and select data packs screens.";

@Translation.ConfigOption.Name("add_search")
public static final String ADD_SEARCH = EnglishUs.ADD_SEARCH;

@Translation.ConfigOption.Name("match_descriptions")
public static final String MATCH_DESCRIPTIONS = "Match Descriptions";
@Translation.ConfigOption.Description("match_descriptions")
public static final String MATCH_DESCRIPTIONS_DESCRIPTION = """
Whether resource pack and data pack descriptions should be searched for matching text during a search.""";
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public SearchableConfigScreen(Screen parent) {
@Override
protected void init() {
// Search box {{{
this.searchBox = new TextFieldWidget(this.textRenderer, (this.width - Searchable.SEARCH_BOX_WIDTH) / 2, 22, Searchable.SEARCH_BOX_WIDTH, 20, this.searchBox, SEARCH_BOX_NARRATION_MESSAGE);
this.searchBox = new TextFieldWidget(this.textRenderer, (this.width - Searchable.SEARCH_BOX_WIDTH) / 2, Searchable.SEARCH_BOX_Y, Searchable.SEARCH_BOX_WIDTH, 20, this.searchBox, SEARCH_BOX_NARRATION_MESSAGE);
this.searchBox.setHint(SEARCH_BOX_HINT);
this.searchBox.setChangedListener(query -> {
PatternSyntaxException validityError = MatchManager.matcher().validateQueryError(query);
Expand All @@ -80,11 +80,12 @@ protected void init() {
this.setInitialFocus(this.searchBox);
// }}}

// Entry list widget
// Entry list widget {{{
this.entryListWidget = new SearchableConfigEntryListWidget(48, this.height - 32, 28, this.entryListWidget);
this.addSelectableChild(this.entryListWidget);
// }}}

// Buttons
// Buttons {{{
GridWidget.AdditionHelper additionHelper = this.grid.createAdditionHelper(2);

this.doneButton = additionHelper.add(ButtonWidget.builder(CommonTexts.DONE, button -> {
Expand All @@ -93,6 +94,7 @@ protected void init() {
this.getClient().setScreen(this.parent);
}).build());
additionHelper.add(ButtonWidget.builder(CommonTexts.CANCEL, button -> this.closeScreen()).build());
// }}}

this.repositionElements();
this.grid.visitWidgets(this::addDrawableChild);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void onInit(CallbackInfo ci) {
Searchable.LOGGER.debug("adding search box to edit gamerules screen");

// Search box {{{
this.searchBox = new TextFieldWidget(this.textRenderer, (this.width - Searchable.SEARCH_BOX_WIDTH) / 2, 22, Searchable.searchBoxWidth(), 20, this.searchBox, SEARCH_BOX_NARRATION_MESSAGE);
this.searchBox = new TextFieldWidget(this.textRenderer, (this.width - Searchable.SEARCH_BOX_WIDTH) / 2, Searchable.SEARCH_BOX_Y, Searchable.searchBoxWidth(), 20, this.searchBox, SEARCH_BOX_NARRATION_MESSAGE);
this.searchBox.setHint(SEARCH_BOX_HINT);
this.searchBox.setChangedListener(query -> {
PatternSyntaxException validityError = MatchManager.matcher().validateQueryError(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onInit(CallbackInfo ci) {
Searchable.LOGGER.debug("adding search box to key binds screen");

// Search box {{{
this.searchBox = new TextFieldWidget(this.textRenderer, (this.width - Searchable.SEARCH_BOX_WIDTH) / 2, 22, Searchable.searchBoxWidth(), 20, this.searchBox, SEARCH_BOX_NARRATION_MESSAGE);
this.searchBox = new TextFieldWidget(this.textRenderer, (this.width - Searchable.SEARCH_BOX_WIDTH) / 2, Searchable.SEARCH_BOX_Y, Searchable.searchBoxWidth(), 20, this.searchBox, SEARCH_BOX_NARRATION_MESSAGE);
this.searchBox.setHint(SEARCH_BOX_HINT);
this.searchBox.setChangedListener(query -> {
PatternSyntaxException validityError = MatchManager.matcher().validateQueryError(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void onInitHead(CallbackInfo ci) {
Searchable.LOGGER.debug("adding search box to language options screen...");

// Search box {{{
this.searchBox = new TextFieldWidget(this.textRenderer, (this.width - Searchable.SEARCH_BOX_WIDTH) / 2, 22, Searchable.searchBoxWidth(), 20, this.searchBox, SEARCH_BOX_NARRATION_MESSAGE);
this.searchBox = new TextFieldWidget(this.textRenderer, (this.width - Searchable.SEARCH_BOX_WIDTH) / 2, Searchable.SEARCH_BOX_Y, Searchable.searchBoxWidth(), 20, this.searchBox, SEARCH_BOX_NARRATION_MESSAGE);
this.searchBox.setHint(SEARCH_BOX_HINT);
// Filter the language selection list when the query is changed.
this.searchBox.setChangedListener(query -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package io.github.antikyth.searchable.mixin.pack;

import io.github.antikyth.searchable.Searchable;
import io.github.antikyth.searchable.config.SearchableConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.pack.PackListWidget;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(PackListWidget.class)
public class PackListWidgetMixin extends AlwaysSelectedEntryListWidget<PackListWidget.ResourcePackEntry> {
@Unique
private static final int TITLE_Y = 8;
@Unique
private static final int TEXT_HEIGHT = 8;
@Unique
private static final int DROP_INFO_PADDING = 20 - (TITLE_Y + TEXT_HEIGHT);
@Unique
private static final int SHIFT = 16 + TEXT_HEIGHT + DROP_INFO_PADDING;

public PackListWidgetMixin(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {
super(minecraftClient, width, height, top, bottom, entryHeight);
}

@ModifyArg(method = "<init>", at = @At(
value = "INVOKE",
target = "net/minecraft/client/gui/widget/AlwaysSelectedEntryListWidget.<init> (Lnet/minecraft/client/MinecraftClient;IIIII)V",
ordinal = 0
), index = 3)
private static int adjustTopCoord(int top) {
if (!enabled()) return top;

Searchable.LOGGER.debug("moving select pack screen pack list down by " + SHIFT + "px...");

return top + SHIFT;
}

@Unique
private static boolean enabled() {
return SearchableConfig.INSTANCE.select_packs_screen.add_search.value();
}
}
Loading

0 comments on commit 6c3ce22

Please sign in to comment.