Skip to content

Commit

Permalink
Merge pull request #719 from refinedmods/fix/NO-ISSUE/sonar
Browse files Browse the repository at this point in the history
Misc fixes
  • Loading branch information
raoulvdberge authored Nov 16, 2024
2 parents e89b4bd + a786a35 commit 3a5b99b
Show file tree
Hide file tree
Showing 23 changed files with 236 additions and 168 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.junit.jupiter.api.Test;

public class TaskStatusTest {
class TaskStatusTest {
@Test
void dummyTest() {
new TaskStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public interface Config {

boolean isSmoothScrolling();

boolean isSearchBoxAutoSelected();

void setSearchBoxAutoSelected(boolean searchBoxAutoSelected);

int getMaxRowsStretch();

GridEntry getGrid();
Expand Down Expand Up @@ -94,10 +98,6 @@ interface GridEntry extends SimpleEnergyUsageEntry {

boolean isRememberSearchQuery();

boolean isAutoSelected();

void setAutoSelected(boolean autoSelected);

Optional<ResourceLocation> getSynchronizer();

void setSynchronizer(ResourceLocation synchronizerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@
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<AutocrafterManagerContainerMenu> {
private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/autocrafter_manager.png");
private static final List<String> SEARCH_FIELD_HISTORY = new ArrayList<>();
private static final ResourceLocation AUTOCRAFTER_NAME = createIdentifier("autocrafter_manager/autocrafter_name");
private static final int COLUMNS = 9;
private static final int INACTIVE_COLOR = 0xFF5B5B5B;

private static final MutableComponent HELP_ALL =
createTranslation("gui", "autocrafter_manager.search_mode.all.help");
private static final MutableComponent HELP_PATTERN_INPUTS =
createTranslation("gui", "autocrafter_manager.search_mode.pattern_inputs.help");
private static final MutableComponent HELP_PATTERN_OUTPUTS =
createTranslation("gui", "autocrafter_manager.search_mode.pattern_outputs.help");
private static final MutableComponent HELP_AUTOCRAFTER_NAMES =
createTranslation("gui", "autocrafter_manager.search_mode.autocrafter_names.help");

@Nullable
private SearchFieldWidget searchField;

Expand Down Expand Up @@ -70,9 +80,26 @@ protected void init(final int rows) {
addWidget(searchField);
searchField.setResponder(value -> 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() {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =
Expand All @@ -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<Component> helpTextSupplier;

SearchModeSideButtonWidget(final AutocrafterManagerContainerMenu containerMenu) {
SearchModeSideButtonWidget(final AutocrafterManagerContainerMenu containerMenu,
final Supplier<Component> helpTextSupplier) {
super(createPressAction(containerMenu));
this.containerMenu = containerMenu;
this.helpTextSupplier = helpTextSupplier;
}

private static OnPress createPressAction(final AutocrafterManagerContainerMenu containerMenu) {
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
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;
import java.util.List;
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;
Expand All @@ -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;

Expand All @@ -42,6 +43,8 @@ public class AlternativesScreen extends AbstractAmountScreen<AlternativeContaine
private static final MutableComponent TITLE = createTranslation("gui", "configure_amount");
private static final MutableComponent ALTERNATIVES = createTranslation("gui", "pattern_grid.alternatives");
private static final MutableComponent EXPAND = createTranslation("gui", "pattern_grid.alternatives.expand");
private static final Component SEARCH_HELP = createTranslation("gui", "pattern_grid.alternatives.search_help")
.withStyle(ChatFormatting.GRAY);
private static final WidgetSprites EXPAND_SPRITES = new WidgetSprites(
createIdentifier("widget/expand"),
createIdentifier("widget/expand_disabled"),
Expand Down Expand Up @@ -137,6 +140,13 @@ protected void init() {
searchField.setFocused(false);
searchField.setResponder(query -> getMenu().filter(query));
addRenderableWidget(searchField);

addRenderableWidget(new SearchIconWidget(
leftPos + 7,
topPos + 107,
() -> SEARCH_HELP,
searchField
));
}

private int getInsetY() {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends AbstractGridContainerMenu> menuType,
Expand Down Expand Up @@ -126,7 +123,6 @@ protected AbstractGridContainerMenu(
this.insertionStrategy = new ClientGridInsertionStrategy();
this.extractionStrategy = new ClientGridExtractionStrategy();
this.scrollingStrategy = new ClientGridScrollingStrategy();
this.autoSelected = loadAutoSelected();
}

protected AbstractGridContainerMenu(
Expand Down Expand Up @@ -211,7 +207,6 @@ public void setViewType(final GridViewType viewType) {
}

public void setSearchBox(final GridSearchBox searchBox) {
this.searchBox = searchBox;
registerViewUpdatingListener(searchBox);
configureSearchBox(searchBox);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.function.Consumer;

public interface GridSearchBox {
void setAutoSelected(boolean autoSelected);

void setValue(String value);

void setValid(boolean valid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -65,6 +65,13 @@ public abstract class AbstractGridScreen<T extends AbstractGridContainerMenu> ex
private static final int COLUMNS = 9;
private static final int DISABLED_SLOT_COLOR = 0xFF5B5B5B;
private static final List<String> 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;

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 3a5b99b

Please sign in to comment.