diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cafaeabd..01c39d647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Changed - The Autocrafting Monitor now has a sidebar with all tasks instead of using tabs. +- The auto-selected search box mode is now a global option used in the Autocrafter Manager as well. ## [2.0.0-milestone.4.9] - 2024-11-01 diff --git a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusTest.java b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusTest.java index a19282a9e..65e933afb 100644 --- a/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusTest.java +++ b/refinedstorage-autocrafting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test; -public class TaskStatusTest { +class TaskStatusTest { @Test void dummyTest() { new TaskStatus( diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/Config.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/Config.java index 44bf24616..9482cbb74 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/Config.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/Config.java @@ -19,6 +19,10 @@ public interface Config { boolean isSmoothScrolling(); + boolean isSearchBoxAutoSelected(); + + void setSearchBoxAutoSelected(boolean searchBoxAutoSelected); + int getMaxRowsStretch(); GridEntry getGrid(); @@ -94,10 +98,6 @@ interface GridEntry extends SimpleEnergyUsageEntry { boolean isRememberSearchQuery(); - boolean isAutoSelected(); - - void setAutoSelected(boolean autoSelected); - Optional getSynchronizer(); void setSynchronizer(ResourceLocation synchronizerId); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerScreen.java index e595859a0..9d4e345ce 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/AutocrafterManagerScreen.java @@ -4,28 +4,29 @@ import com.refinedmods.refinedstorage.common.support.Sprites; import com.refinedmods.refinedstorage.common.support.containermenu.PropertyTypes; import com.refinedmods.refinedstorage.common.support.stretching.AbstractStretchingScreen; +import com.refinedmods.refinedstorage.common.support.widget.AutoSelectedSideButtonWidget; import com.refinedmods.refinedstorage.common.support.widget.History; import com.refinedmods.refinedstorage.common.support.widget.RedstoneModeSideButtonWidget; import com.refinedmods.refinedstorage.common.support.widget.SearchFieldWidget; +import com.refinedmods.refinedstorage.common.support.widget.SearchIconWidget; import com.refinedmods.refinedstorage.common.support.widget.TextMarquee; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; +import net.minecraft.ChatFormatting; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.Slot; -import static com.refinedmods.refinedstorage.common.support.Sprites.SEARCH_SIZE; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; -// TODO: fix sonar issues -// TODO: search box autoselected mode make generic. -// TODO: tooltip on search icon public class AutocrafterManagerScreen extends AbstractStretchingScreen { private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/autocrafter_manager.png"); private static final List SEARCH_FIELD_HISTORY = new ArrayList<>(); @@ -33,6 +34,15 @@ public class AutocrafterManagerScreen extends AbstractStretchingScreen getMenu().setQuery(value)); + addRenderableWidget(new SearchIconWidget( + leftPos + 79, + topPos + 5, + () -> getSearchModeHelp().copy().withStyle(ChatFormatting.GRAY), + searchField + )); + addSideButton(new RedstoneModeSideButtonWidget(getMenu().getProperty(PropertyTypes.REDSTONE_MODE))); addSideButton(new ViewTypeSideButtonWidget(getMenu())); - addSideButton(new SearchModeSideButtonWidget(getMenu())); + addSideButton(new SearchModeSideButtonWidget(getMenu(), this::getSearchModeHelp)); + addSideButton(new AutoSelectedSideButtonWidget(searchField)); + } + + private Component getSearchModeHelp() { + return switch (menu.getSearchMode()) { + case ALL -> HELP_ALL; + case PATTERN_INPUTS -> HELP_PATTERN_INPUTS; + case PATTERN_OUTPUTS -> HELP_PATTERN_OUTPUTS; + case AUTOCRAFTER_NAMES -> HELP_AUTOCRAFTER_NAMES; + }; } private void updateScrollbar() { @@ -93,12 +120,6 @@ protected void scrollbarChanged(final int rows) { } } - @Override - protected void renderBg(final GuiGraphics graphics, final float delta, final int mouseX, final int mouseY) { - super.renderBg(graphics, delta, mouseX, mouseY); - graphics.blitSprite(Sprites.SEARCH, leftPos + 79, topPos + 5, SEARCH_SIZE, SEARCH_SIZE); - } - @Override public void render(final GuiGraphics graphics, final int mouseX, final int mouseY, final float partialTicks) { super.render(graphics, mouseX, mouseY, partialTicks); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/SearchModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/SearchModeSideButtonWidget.java index 346f56af7..2cdef6a5d 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/SearchModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/SearchModeSideButtonWidget.java @@ -2,6 +2,8 @@ import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.function.Supplier; + import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -12,20 +14,12 @@ class SearchModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "autocrafter_manager.search_mode"); private static final MutableComponent SUBTEXT_ALL = createTranslation("gui", "autocrafter_manager.search_mode.all"); - private static final MutableComponent HELP_ALL = - createTranslation("gui", "autocrafter_manager.search_mode.all.help"); private static final MutableComponent SUBTEXT_PATTERN_INPUTS = createTranslation("gui", "autocrafter_manager.search_mode.pattern_inputs"); - private static final MutableComponent HELP_PATTERN_INPUTS = - createTranslation("gui", "autocrafter_manager.search_mode.pattern_inputs.help"); private static final MutableComponent SUBTEXT_PATTERN_OUTPUTS = createTranslation("gui", "autocrafter_manager.search_mode.pattern_outputs"); - private static final MutableComponent HELP_PATTERN_OUTPUTS = - createTranslation("gui", "autocrafter_manager.search_mode.pattern_outputs.help"); private static final MutableComponent SUBTEXT_AUTOCRAFTER_NAMES = createTranslation("gui", "autocrafter_manager.search_mode.autocrafter_names"); - private static final MutableComponent HELP_AUTOCRAFTER_NAMES = - createTranslation("gui", "autocrafter_manager.search_mode.autocrafter_names.help"); private static final ResourceLocation SPRITE_ALL = createIdentifier("widget/side_button/autocrafter_manager/search_mode/all"); private static final ResourceLocation SPRITE_PATTERN_INPUTS = @@ -36,10 +30,13 @@ class SearchModeSideButtonWidget extends AbstractSideButtonWidget { createIdentifier("widget/side_button/autocrafter_manager/search_mode/autocrafter_names"); private final AutocrafterManagerContainerMenu containerMenu; + private final Supplier helpTextSupplier; - SearchModeSideButtonWidget(final AutocrafterManagerContainerMenu containerMenu) { + SearchModeSideButtonWidget(final AutocrafterManagerContainerMenu containerMenu, + final Supplier helpTextSupplier) { super(createPressAction(containerMenu)); this.containerMenu = containerMenu; + this.helpTextSupplier = helpTextSupplier; } private static OnPress createPressAction(final AutocrafterManagerContainerMenu containerMenu) { @@ -73,11 +70,6 @@ protected MutableComponent getSubText() { @Override protected Component getHelpText() { - return switch (containerMenu.getSearchMode()) { - case ALL -> HELP_ALL; - case PATTERN_INPUTS -> HELP_PATTERN_INPUTS; - case PATTERN_OUTPUTS -> HELP_PATTERN_OUTPUTS; - case AUTOCRAFTER_NAMES -> HELP_AUTOCRAFTER_NAMES; - }; + return helpTextSupplier.get(); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/TaskStatusProviderImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/TaskStatusProviderImpl.java index 23ff57450..fc96c9b99 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/TaskStatusProviderImpl.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/monitor/TaskStatusProviderImpl.java @@ -96,7 +96,7 @@ private TaskStatus generateTaskStatus() { final TaskStatus.TaskInfo taskInfo = new TaskStatus.TaskInfo( new TaskId(UUID.randomUUID()), ItemResource.ofItemStack(new ItemStack(ITEM_SET[r.nextInt(ITEM_SET.length)])), - 5 + r.nextInt(32), + 5 + r.nextLong(32), System.currentTimeMillis() ); final float pct = r.nextFloat(); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/AlternativesScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/AlternativesScreen.java index cbfeacfc6..334166aa1 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/AlternativesScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/patterngrid/AlternativesScreen.java @@ -10,6 +10,7 @@ import com.refinedmods.refinedstorage.common.support.widget.CustomCheckboxWidget; import com.refinedmods.refinedstorage.common.support.widget.HoveredImageButton; import com.refinedmods.refinedstorage.common.support.widget.ScrollbarWidget; +import com.refinedmods.refinedstorage.common.support.widget.SearchIconWidget; import java.util.ArrayList; import java.util.HashSet; @@ -17,6 +18,7 @@ import java.util.Set; import javax.annotation.Nullable; +import net.minecraft.ChatFormatting; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; @@ -30,7 +32,6 @@ import net.minecraft.world.entity.player.Inventory; import org.joml.Vector3f; -import static com.refinedmods.refinedstorage.common.support.Sprites.SEARCH_SIZE; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; @@ -42,6 +43,8 @@ public class AlternativesScreen extends AbstractAmountScreen getMenu().filter(query)); addRenderableWidget(searchField); + + addRenderableWidget(new SearchIconWidget( + leftPos + 7, + topPos + 107, + () -> SEARCH_HELP, + searchField + )); } private int getInsetY() { @@ -300,7 +310,6 @@ public void render(final GuiGraphics graphics, final int mouseX, final int mouse @Override protected void renderBg(final GuiGraphics graphics, final float delta, final int mouseX, final int mouseY) { super.renderBg(graphics, delta, mouseX, mouseY); - graphics.blitSprite(Sprites.SEARCH, leftPos + 7, topPos + 107, SEARCH_SIZE, SEARCH_SIZE); final int x = getInsetX(); final int y = getInsetY(); graphics.enableScissor(x, y, x + INSET_WIDTH, y + INSET_HEIGHT); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java index 4c1316862..47ea13859 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/AbstractGridContainerMenu.java @@ -91,10 +91,7 @@ public abstract class AbstractGridContainerMenu extends AbstractResourceContaine private GridSynchronizer synchronizer; @Nullable private ResourceType resourceTypeFilter; - private boolean autoSelected; private boolean active; - @Nullable - private GridSearchBox searchBox; protected AbstractGridContainerMenu( final MenuType menuType, @@ -126,7 +123,6 @@ protected AbstractGridContainerMenu( this.insertionStrategy = new ClientGridInsertionStrategy(); this.extractionStrategy = new ClientGridExtractionStrategy(); this.scrollingStrategy = new ClientGridScrollingStrategy(); - this.autoSelected = loadAutoSelected(); } protected AbstractGridContainerMenu( @@ -211,7 +207,6 @@ public void setViewType(final GridViewType viewType) { } public void setSearchBox(final GridSearchBox searchBox) { - this.searchBox = searchBox; registerViewUpdatingListener(searchBox); configureSearchBox(searchBox); } @@ -234,7 +229,6 @@ private boolean onSearchTextChanged(final String text) { } private void configureSearchBox(final GridSearchBox theSearchBox) { - theSearchBox.setAutoSelected(isAutoSelected()); if (Platform.INSTANCE.getConfig().getGrid().isRememberSearchQuery()) { theSearchBox.setValue(lastSearchQuery); theSearchBox.addListener(AbstractGridContainerMenu::updateLastSearchQuery); @@ -330,22 +324,6 @@ public boolean isActive() { return active; } - public void setAutoSelected(final boolean autoSelected) { - this.autoSelected = autoSelected; - Platform.INSTANCE.getConfig().getGrid().setAutoSelected(autoSelected); - if (searchBox != null) { - searchBox.setAutoSelected(autoSelected); - } - } - - private boolean loadAutoSelected() { - return Platform.INSTANCE.getConfig().getGrid().isAutoSelected(); - } - - public boolean isAutoSelected() { - return autoSelected; - } - private GridSynchronizer loadSynchronizer() { return Platform.INSTANCE .getConfig() diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/GridSearchBox.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/GridSearchBox.java index be4620b64..4bb9d4123 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/GridSearchBox.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/GridSearchBox.java @@ -3,8 +3,6 @@ import java.util.function.Consumer; public interface GridSearchBox { - void setAutoSelected(boolean autoSelected); - void setValue(String value); void setValid(boolean valid); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java index de723ef18..e9d570941 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AbstractGridScreen.java @@ -16,15 +16,16 @@ import com.refinedmods.refinedstorage.common.grid.NoopGridSynchronizer; import com.refinedmods.refinedstorage.common.grid.view.ItemGridResource; import com.refinedmods.refinedstorage.common.support.ResourceSlotRendering; -import com.refinedmods.refinedstorage.common.support.Sprites; import com.refinedmods.refinedstorage.common.support.containermenu.DisabledSlot; import com.refinedmods.refinedstorage.common.support.containermenu.PropertyTypes; import com.refinedmods.refinedstorage.common.support.containermenu.ResourceSlot; import com.refinedmods.refinedstorage.common.support.resource.ItemResource; import com.refinedmods.refinedstorage.common.support.stretching.AbstractStretchingScreen; import com.refinedmods.refinedstorage.common.support.tooltip.SmallTextClientTooltipComponent; +import com.refinedmods.refinedstorage.common.support.widget.AutoSelectedSideButtonWidget; import com.refinedmods.refinedstorage.common.support.widget.History; import com.refinedmods.refinedstorage.common.support.widget.RedstoneModeSideButtonWidget; +import com.refinedmods.refinedstorage.common.support.widget.SearchIconWidget; import com.refinedmods.refinedstorage.common.support.widget.TextMarquee; import com.refinedmods.refinedstorage.query.lexer.SyntaxHighlighter; import com.refinedmods.refinedstorage.query.lexer.SyntaxHighlighterColors; @@ -50,7 +51,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.refinedmods.refinedstorage.common.support.Sprites.SEARCH_SIZE; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslationKey; @@ -65,6 +65,13 @@ public abstract class AbstractGridScreen ex private static final int COLUMNS = 9; private static final int DISABLED_SLOT_COLOR = 0xFF5B5B5B; private static final List SEARCH_FIELD_HISTORY = new ArrayList<>(); + private static final Component SEARCH_HELP = createTranslation("gui", "grid.search_help") + .append("\n") + .append(createTranslation("gui", "grid.search_help.mod_search").withStyle(ChatFormatting.GRAY)) + .append("\n") + .append(createTranslation("gui", "grid.search_help.tag_search").withStyle(ChatFormatting.GRAY)) + .append("\n") + .append(createTranslation("gui", "grid.search_help.tooltip_search").withStyle(ChatFormatting.GRAY)); protected final int bottomHeight; @@ -113,7 +120,14 @@ protected void init(final int rows) { addSideButton(new ResourceTypeSideButtonWidget(getMenu())); addSideButton(new SortingDirectionSideButtonWidget(getMenu())); addSideButton(new SortingTypeSideButtonWidget(getMenu())); - addSideButton(new AutoSelectedSideButtonWidget(getMenu())); + addSideButton(new AutoSelectedSideButtonWidget(searchField)); + + addRenderableWidget(new SearchIconWidget( + leftPos + 79, + topPos + 5, + () -> SEARCH_HELP, + searchField + )); final boolean onlyHasNoopSynchronizer = RefinedStorageApi.INSTANCE.getGridSynchronizerRegistry() .getAll() @@ -159,12 +173,6 @@ private boolean isOverStorageArea(final int mouseX, final int mouseY) { && isInStretchedArea(relativeMouseY); } - @Override - protected void renderBg(final GuiGraphics graphics, final float delta, final int mouseX, final int mouseY) { - super.renderBg(graphics, delta, mouseX, mouseY); - graphics.blitSprite(Sprites.SEARCH, leftPos + 79, topPos + 5, SEARCH_SIZE, SEARCH_SIZE); - } - @Override protected void renderStretchingBackground(final GuiGraphics graphics, final int x, final int y, final int rows) { for (int row = 0; row < rows; ++row) { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AutoSelectedSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AutoSelectedSideButtonWidget.java deleted file mode 100644 index 43796c69a..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/AutoSelectedSideButtonWidget.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.refinedmods.refinedstorage.common.grid.screen; - -import com.refinedmods.refinedstorage.common.grid.AbstractGridContainerMenu; -import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; -import com.refinedmods.refinedstorage.common.util.IdentifierUtil; - -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; - -import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; -import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; - -class AutoSelectedSideButtonWidget extends AbstractSideButtonWidget { - private static final MutableComponent TITLE = createTranslation("gui", "grid.auto_selected"); - private static final ResourceLocation YES = createIdentifier("widget/side_button/grid/autoselected/yes"); - private static final ResourceLocation NO = createIdentifier("widget/side_button/grid/autoselected/no"); - private static final Component HELP = createTranslation("gui", "grid.auto_selected.help"); - - private final AbstractGridContainerMenu menu; - - AutoSelectedSideButtonWidget(final AbstractGridContainerMenu menu) { - super(createPressAction(menu)); - this.menu = menu; - } - - private static OnPress createPressAction(final AbstractGridContainerMenu menu) { - return btn -> menu.setAutoSelected(!menu.isAutoSelected()); - } - - @Override - protected ResourceLocation getSprite() { - return menu.isAutoSelected() ? YES : NO; - } - - @Override - protected MutableComponent getTitle() { - return TITLE; - } - - @Override - protected MutableComponent getSubText() { - return menu.isAutoSelected() ? IdentifierUtil.YES : IdentifierUtil.NO; - } - - @Override - protected Component getHelpText() { - return HELP; - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/GridSearchBoxWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/GridSearchBoxWidget.java index 46f461841..f68d07ea9 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/GridSearchBoxWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/GridSearchBoxWidget.java @@ -70,12 +70,6 @@ private Lexer createLexer(final String text) { return new Lexer(new Source("Grid search box syntax highlighting", text), LexerTokenMappings.DEFAULT_MAPPINGS); } - @Override - public void setAutoSelected(final boolean autoSelected) { - setFocused(autoSelected); - setCanLoseFocus(!autoSelected); - } - @Override public void addListener(final Consumer listener) { this.listeners.add(listener); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/Sprites.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/Sprites.java index a29fc360e..ab0897790 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/Sprites.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/Sprites.java @@ -11,8 +11,6 @@ public final class Sprites { public static final int LIGHT_ARROW_HEIGHT = 15; public static final ResourceLocation WARNING = createIdentifier("warning"); public static final int WARNING_SIZE = 10; - public static final ResourceLocation SEARCH = createIdentifier("search"); - public static final int SEARCH_SIZE = 12; public static final int ERROR_SIZE = 12; public static final ResourceLocation ERROR = createIdentifier("error"); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AutoSelectedSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AutoSelectedSideButtonWidget.java new file mode 100644 index 000000000..7a0c8dec2 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AutoSelectedSideButtonWidget.java @@ -0,0 +1,50 @@ +package com.refinedmods.refinedstorage.common.support.widget; + +import com.refinedmods.refinedstorage.common.Platform; +import com.refinedmods.refinedstorage.common.util.IdentifierUtil; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; + +public class AutoSelectedSideButtonWidget extends AbstractSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "search_box_auto_selected"); + private static final ResourceLocation YES = createIdentifier("widget/side_button/search_box_auto_selected/yes"); + private static final ResourceLocation NO = createIdentifier("widget/side_button/search_box_auto_selected/no"); + private static final Component HELP = createTranslation("gui", "search_box_auto_selected.help"); + + public AutoSelectedSideButtonWidget(final SearchFieldWidget searchFieldWidget) { + super(createPressAction(searchFieldWidget)); + } + + private static OnPress createPressAction(final SearchFieldWidget searchFieldWidget) { + return btn -> { + final boolean autoSelected = !Platform.INSTANCE.getConfig().isSearchBoxAutoSelected(); + Platform.INSTANCE.getConfig().setSearchBoxAutoSelected(autoSelected); + searchFieldWidget.setAutoSelected(autoSelected); + }; + } + + @Override + protected ResourceLocation getSprite() { + return Platform.INSTANCE.getConfig().isSearchBoxAutoSelected() ? YES : NO; + } + + @Override + protected MutableComponent getTitle() { + return TITLE; + } + + @Override + protected MutableComponent getSubText() { + return Platform.INSTANCE.getConfig().isSearchBoxAutoSelected() ? IdentifierUtil.YES : IdentifierUtil.NO; + } + + @Override + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SearchFieldWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SearchFieldWidget.java index 4d7c9603b..3646931d8 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SearchFieldWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SearchFieldWidget.java @@ -18,8 +18,9 @@ public SearchFieldWidget(final Font font, final History history) { super(font, x, y, width, font.lineHeight, Component.empty()); this.history = history; - this.setBordered(false); - this.setMaxLength(256); + setBordered(false); + setMaxLength(256); + setAutoSelected(Platform.INSTANCE.getConfig().isSearchBoxAutoSelected()); } @Override @@ -83,6 +84,11 @@ private void toggleFocus() { saveHistory(); } + public void setAutoSelected(final boolean autoSelected) { + setFocused(autoSelected); + setCanLoseFocus(!autoSelected); + } + private void saveHistory() { history.save(getValue()); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SearchIconWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SearchIconWidget.java new file mode 100644 index 000000000..802cebef6 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SearchIconWidget.java @@ -0,0 +1,57 @@ +package com.refinedmods.refinedstorage.common.support.widget; + +import java.util.function.Supplier; + +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; + +public class SearchIconWidget extends AbstractWidget { + public static final ResourceLocation SEARCH = createIdentifier("search"); + public static final int SEARCH_SIZE = 12; + + private final Supplier messageSupplier; + private final EditBox editBox; + + public SearchIconWidget(final int x, + final int y, + final Supplier messageSupplier, + final EditBox editBox) { + super(x, y, SEARCH_SIZE, SEARCH_SIZE, Component.empty()); + this.messageSupplier = messageSupplier; + this.editBox = editBox; + } + + @Override + public boolean mouseClicked(final double mouseX, final double mouseY, final int button) { + if (super.mouseClicked(mouseX, mouseY, button)) { + editBox.setFocused(true); + return true; + } + return false; + } + + @Override + protected void renderWidget(final GuiGraphics graphics, + final int mouseX, + final int mouseY, + final float partialTicks) { + graphics.blitSprite(SEARCH, getX(), getY(), SEARCH_SIZE, SEARCH_SIZE); + if (isHovered) { + setTooltip(Tooltip.create(messageSupplier.get())); + } else { + setTooltip(null); + } + } + + @Override + protected void updateWidgetNarration(final NarrationElementOutput narrationElementOutput) { + // no op + } +} diff --git a/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json b/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json index 099ce5617..ac8896191 100644 --- a/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json +++ b/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json @@ -59,8 +59,6 @@ "gui.refinedstorage.grid.sorting.type.name": "Name", "gui.refinedstorage.grid.sorting.type.id": "ID", "gui.refinedstorage.grid.sorting.type.last_modified": "Last modified", - "gui.refinedstorage.grid.auto_selected": "Auto-selected", - "gui.refinedstorage.grid.auto_selected.help": "Whether to auto-select the search box when opening the Grid.", "gui.refinedstorage.grid.synchronization_mode": "Synchronization mode", "gui.refinedstorage.grid.synchronization_mode.off": "Off", "gui.refinedstorage.grid.synchronization_mode.off.help": "Don't sync the search box text.", @@ -71,6 +69,10 @@ "gui.refinedstorage.grid.pattern_in_inventory": "This resource has a pattern in your inventory.", "gui.refinedstorage.grid.click_to_autocraft": "Click to autocraft", "gui.refinedstorage.grid.ctrl_click_to_autocraft": "CTRL + click to autocraft", + "gui.refinedstorage.grid.search_help": "Search through resources in storage.", + "gui.refinedstorage.grid.search_help.mod_search": "Use '@' to filter for resources from a specific mod", + "gui.refinedstorage.grid.search_help.tag_search": "Use '$' to filter for resources with a specific tag", + "gui.refinedstorage.grid.search_help.tooltip_search": "Use '#' to filter for resources with a specific tooltip", "gui.refinedstorage.crafting_grid.move.network": "Move items to network", "gui.refinedstorage.crafting_grid.move.inventory": "Move items to inventory", "gui.refinedstorage.crafting_grid.press_shift_ctrl_to_only_show_items_used_in_crafting": "Press SHIFT + CTRL to only show items used in the recipe.", @@ -87,12 +89,15 @@ "gui.refinedstorage.pattern_grid.processing.allowed_alternatives": "Allowed alternatives:", "gui.refinedstorage.pattern_grid.alternatives": "Alternatives", "gui.refinedstorage.pattern_grid.alternatives.expand": "Expand", + "gui.refinedstorage.pattern_grid.alternatives.search_help": "Search through tag names.", "gui.refinedstorage.screen_size": "Screen size", "gui.refinedstorage.screen_size.stretch": "Stretch", "gui.refinedstorage.screen_size.small": "Small", "gui.refinedstorage.screen_size.medium": "Medium", "gui.refinedstorage.screen_size.large": "Large", "gui.refinedstorage.screen_size.extra_large": "Extra large", + "gui.refinedstorage.search_box_auto_selected": "Search box auto-selected", + "gui.refinedstorage.search_box_auto_selected.help": "Whether to auto-select the search box.", "gui.refinedstorage.detector.mode": "Mode", "gui.refinedstorage.detector.mode.under": "Emit redstone signal when under the amount", "gui.refinedstorage.detector.mode.equal": "Emit redstone signal when on the amount", @@ -442,6 +447,8 @@ "text.autoconfig.refinedstorage.option.screenSize.tooltip": "The screen size.", "text.autoconfig.refinedstorage.option.maxRowsStretch": "Maximum amount of rows when screen size is stretched", "text.autoconfig.refinedstorage.option.maxRowsStretch.tooltip": "The maximum amount of rows that can be displayed when the screen size is stretched.", + "text.autoconfig.refinedstorage.option.searchBoxAutoSelected": "Auto-selected search box", + "text.autoconfig.refinedstorage.option.searchBoxAutoSelected.tooltip": "Whether the search box should be auto-selected.", "text.autoconfig.refinedstorage.option.grid": "Grid", "text.autoconfig.refinedstorage.option.grid.tooltip": "Configuration for the Grid.", "text.autoconfig.refinedstorage.option.grid.largeFont": "Large font", @@ -454,8 +461,6 @@ "text.autoconfig.refinedstorage.option.grid.rememberSearchQuery.tooltip": "Whether the search query should persist when closing and re-opening the Grid.", "text.autoconfig.refinedstorage.option.grid.energyUsage": "Energy usage", "text.autoconfig.refinedstorage.option.grid.energyUsage.tooltip": "The energy used by the Grid.", - "text.autoconfig.refinedstorage.option.grid.autoSelected": "Auto selected search box", - "text.autoconfig.refinedstorage.option.grid.autoSelected.tooltip": "Whether the search box should be auto-selected when opening the Grid.", "text.autoconfig.refinedstorage.option.grid.synchronizer": "Synchronizer", "text.autoconfig.refinedstorage.option.grid.synchronizer.tooltip": "The synchronization type of the Grid search box.", "text.autoconfig.refinedstorage.option.grid.resourceType": "Resource type", diff --git a/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/grid/autoselected/no.png b/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/search_box_auto_selected/no.png similarity index 100% rename from refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/grid/autoselected/no.png rename to refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/search_box_auto_selected/no.png diff --git a/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/grid/autoselected/yes.png b/refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/search_box_auto_selected/yes.png similarity index 100% rename from refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/grid/autoselected/yes.png rename to refinedstorage-common/src/main/resources/assets/refinedstorage/textures/gui/sprites/widget/side_button/search_box_auto_selected/yes.png diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ConfigImpl.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ConfigImpl.java index 1f5b809c7..1f790e368 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ConfigImpl.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/ConfigImpl.java @@ -25,6 +25,8 @@ public class ConfigImpl implements ConfigData, com.refinedmods.refinedstorage.co private boolean smoothScrolling = true; + private boolean searchBoxAutoSelected = false; + @ConfigEntry.BoundedDiscrete(min = 3L, max = 256) private int maxRowsStretch = 256; @@ -152,6 +154,17 @@ public boolean isSmoothScrolling() { return smoothScrolling; } + @Override + public boolean isSearchBoxAutoSelected() { + return searchBoxAutoSelected; + } + + @Override + public void setSearchBoxAutoSelected(final boolean searchBoxAutoSelected) { + this.searchBoxAutoSelected = searchBoxAutoSelected; + AutoConfig.getConfigHolder(ConfigImpl.class).save(); + } + @Override public int getMaxRowsStretch() { return maxRowsStretch; @@ -318,8 +331,6 @@ private static class GridEntryImpl implements GridEntry { private boolean rememberSearchQuery = false; - private boolean autoSelected = false; - private String synchronizer = ""; private String resourceType = ""; @@ -355,17 +366,6 @@ public long getEnergyUsage() { return energyUsage; } - @Override - public boolean isAutoSelected() { - return autoSelected; - } - - @Override - public void setAutoSelected(final boolean autoSelected) { - this.autoSelected = autoSelected; - save(); - } - @Override public Optional getSynchronizer() { if (synchronizer.trim().isBlank()) { diff --git a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/importer/FabricStorageImporterSource.java b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/importer/FabricStorageImporterSource.java index 9a285606c..d022db664 100644 --- a/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/importer/FabricStorageImporterSource.java +++ b/refinedstorage-fabric/src/main/java/com/refinedmods/refinedstorage/fabric/importer/FabricStorageImporterSource.java @@ -33,7 +33,7 @@ class FabricStorageImporterSource implements ImporterSource { FabricStorageImporterSource(final BlockApiLookup, Direction> lookup, final Function fromPlatformMapper, - @NullableType final Function toPlatformMapper, + final Function toPlatformMapper, final ServerLevel serverLevel, final BlockPos pos, final Direction direction, diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ConfigImpl.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ConfigImpl.java index e0a678423..d3e6dd7c2 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ConfigImpl.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/ConfigImpl.java @@ -27,6 +27,7 @@ public class ConfigImpl implements Config { private final ModConfigSpec.EnumValue screenSize; private final ModConfigSpec.BooleanValue smoothScrolling; private final ModConfigSpec.IntValue maxRowsStretch; + private final ModConfigSpec.BooleanValue searchBoxAutoSelected; private final SimpleEnergyUsageEntry cable; private final ControllerEntry controller; private final DiskDriveEntry diskDrive; @@ -68,6 +69,9 @@ public ConfigImpl() { maxRowsStretch = builder .translation(translationKey("maxRowsStretch")) .defineInRange("maxRowsStretch", 256, 3, 256); + searchBoxAutoSelected = builder + .translation(translationKey("searchBoxAutoSelected")) + .define("searchBoxAutoSelected", false); cable = new SimpleEnergyUsageEntryImpl("cable", DefaultEnergyUsage.CABLE); controller = new ControllerEntryImpl(); diskDrive = new DiskDriveEntryImpl(); @@ -137,6 +141,19 @@ public void setScreenSize(final ScreenSize screenSize) { } } + @Override + public boolean isSearchBoxAutoSelected() { + return searchBoxAutoSelected.get(); + } + + @Override + public void setSearchBoxAutoSelected(final boolean searchBoxAutoSelected) { + if (searchBoxAutoSelected != Boolean.TRUE.equals(this.searchBoxAutoSelected.get())) { + this.searchBoxAutoSelected.set(searchBoxAutoSelected); + ConfigImpl.this.spec.save(); + } + } + @Override public GridEntry getGrid() { return grid; @@ -384,7 +401,6 @@ private class GridEntryImpl implements GridEntry { private final ModConfigSpec.BooleanValue detailedTooltip; private final ModConfigSpec.BooleanValue rememberSearchQuery; private final ModConfigSpec.LongValue energyUsage; - private final ModConfigSpec.BooleanValue autoSelected; private final ModConfigSpec.ConfigValue synchronizer; private final ModConfigSpec.ConfigValue resourceType; private final ModConfigSpec.EnumValue sortingDirection; @@ -408,9 +424,6 @@ private class GridEntryImpl implements GridEntry { energyUsage = builder .translation(translationKey("grid." + ENERGY_USAGE)) .defineInRange(ENERGY_USAGE, DefaultEnergyUsage.GRID, 0, Long.MAX_VALUE); - autoSelected = builder - .translation(translationKey("grid.autoSelected")) - .define("autoSelected", false); synchronizer = builder .translation(translationKey("grid.synchronizer")) .define("synchronizer", ""); @@ -454,19 +467,6 @@ public long getEnergyUsage() { return energyUsage.get(); } - @Override - public boolean isAutoSelected() { - return autoSelected.get(); - } - - @Override - public void setAutoSelected(final boolean autoSelected) { - if (autoSelected != Boolean.TRUE.equals(this.autoSelected.get())) { - this.autoSelected.set(autoSelected); - ConfigImpl.this.spec.save(); - } - } - @Override public Optional getSynchronizer() { if (synchronizer.get().trim().isBlank()) { diff --git a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/datagen/BlockStateProviderImpl.java b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/datagen/BlockStateProviderImpl.java index 61468a71d..cb15a6510 100644 --- a/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/datagen/BlockStateProviderImpl.java +++ b/refinedstorage-neoforge/src/main/java/com/refinedmods/refinedstorage/neoforge/datagen/BlockStateProviderImpl.java @@ -68,8 +68,7 @@ private void registerCables() { final var builder = getVariantBuilder(block.get()); builder.addModels( builder.partialState(), - ConfiguredModel.builder().modelFile(modelFile(createIdentifier("block/cable/" + color.getName()))) - .build() + ConfiguredModel.builder().modelFile(getCableModel(color)).build() ); }); } @@ -79,8 +78,7 @@ private void registerCableLike(final BlockColorMap blockMap, final String blockMap.forEach((color, id, block) -> { final MultiPartBlockStateBuilder builder = getMultipartBuilder(block.get()); final var cablePart = builder.part(); - cablePart.modelFile(modelFile(createIdentifier("block/cable/" + color.getName()))) - .addModel(); + cablePart.modelFile(getCableModel(color)).addModel(); for (final Direction direction : Direction.values()) { final var part = builder.part(); addDirectionalRotation(direction, part); @@ -188,8 +186,7 @@ private void registerConstructorDestructor(final BlockColorMap blockMap, f blockMap.forEach((color, id, block) -> { final MultiPartBlockStateBuilder builder = getMultipartBuilder(block.get()); final var cablePart = builder.part(); - cablePart.modelFile(modelFile(createIdentifier("block/cable/" + color.getName()))) - .addModel(); + cablePart.modelFile(getCableModel(color)).addModel(); for (final Direction direction : Direction.values()) { final var part = builder.part(); addDirectionalRotation(direction, part); @@ -207,6 +204,10 @@ private void registerConstructorDestructor(final BlockColorMap blockMap, f }); } + private ModelFile getCableModel(final DyeColor color) { + return modelFile(createIdentifier("block/cable/" + color.getName())); + } + private ConfiguredModel[] registerDetector(final ModelFile unpowered, final DetectorBlock block, final BlockState blockState) {