Skip to content

Commit

Permalink
feat: Item Filter GUI (#2417)
Browse files Browse the repository at this point in the history
* feat: Item Filter GUI

No widgets to actually edit, those will be in the next commit

* chore: spotless

* chore: Merge fixes

* feat: Add widgets

* chore: Merge fixes

* feat: Add remove button to string and numeric widgets

* feat: Add text when no widgets

* chore: Add missing @OVERRIDES

* refactor: Cleanup FontRenderer changes

* refactor: Rename FilterWidgetFactory and remove String case

* fix: Fix SkillStatProvider not providing the correct skill

* refactor: ItemProvider returns a single value

* fix: Fix RarityStatProvider sorting by name, not by enum order

* feat: Make provider name case-insensitive for filtering/sorting

* feat: Add helper for accessing the filter ui in guides

* chore: Fix profession description

---------

Co-authored-by: Kristof <49001742+kristofbolyai@users.noreply.github.com>
  • Loading branch information
ShadowCat117 and kristofbolyai committed May 5, 2024
1 parent 171a012 commit ec77450
Show file tree
Hide file tree
Showing 88 changed files with 4,813 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.wynntils.models.containers.type.SearchableContainerProperty;
import com.wynntils.models.items.WynnItem;
import com.wynntils.models.items.WynnItemData;
import com.wynntils.screens.base.widgets.ItemFilterUIButton;
import com.wynntils.screens.base.widgets.ItemSearchWidget;
import com.wynntils.screens.base.widgets.SearchWidget;
import com.wynntils.services.itemfilter.type.ItemSearchQuery;
Expand Down Expand Up @@ -255,7 +256,7 @@ private void addWidgets(AbstractContainerScreen<ChestMenu> screen, int renderX,
ItemSearchWidget searchWidget = new ItemSearchWidget(
renderX + screen.imageWidth - 175,
renderY - 20,
175,
155,
20,
currentContainer.supportedProviderTypes(),
false,
Expand All @@ -272,6 +273,14 @@ private void addWidgets(AbstractContainerScreen<ChestMenu> screen, int renderX,
lastSearchWidget = searchWidget;

screen.addRenderableWidget(lastSearchWidget);

screen.addRenderableWidget(new ItemFilterUIButton(
renderX + 157,
renderY - 20,
lastSearchWidget,
screen,
false,
currentContainer.supportedProviderTypes()));
} else {
SearchWidget searchWidget = new SearchWidget(
renderX + screen.imageWidth - 175,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,8 @@ public void resetProfiling() {
profilingTimes.clear();
profilingCounts.clear();
}

public List<ItemAnnotator> getAnnotators() {
return Collections.unmodifiableList(annotators);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright © Wynntils 2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.screens.base.widgets;

import com.wynntils.screens.itemfilter.ItemFilterScreen;
import com.wynntils.services.itemfilter.type.ItemProviderType;
import com.wynntils.utils.mc.McUtils;
import java.util.List;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;

public class ItemFilterUIButton extends WynntilsButton {
private final SearchWidget searchWidget;
private final Screen previousScreen;
private final boolean supportsSorting;
private final List<ItemProviderType> supportedProviderTypes;

public ItemFilterUIButton(
int x,
int y,
SearchWidget searchWidget,
Screen previousScreen,
boolean supportsSorting,
List<ItemProviderType> supportedProviderTypes) {
super(x, y, 20, 20, Component.literal("✎"));
this.searchWidget = searchWidget;
this.previousScreen = previousScreen;
this.supportsSorting = supportsSorting;
this.supportedProviderTypes = supportedProviderTypes;
this.setTooltip(Tooltip.create(Component.translatable("screens.wynntils.itemSearchButton.tooltip")));
}

@Override
public void onPress() {
McUtils.mc()
.setScreen(
ItemFilterScreen.create(searchWidget, previousScreen, supportsSorting, supportedProviderTypes));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © Wynntils 2022-2023.
* Copyright © Wynntils 2022-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.screens.base.widgets;
Expand Down Expand Up @@ -202,6 +202,7 @@ protected int getMaxTextWidth() {

/**
* Determines the text to render based on cursor position and maxTextWidth
*
* @return The text to render, and the starting position of the text within the entire text
*/
private Pair<String, Integer> getRenderedText(float maxTextWidth) {
Expand Down Expand Up @@ -511,6 +512,25 @@ public boolean isFocused() {
@Override
public void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {}

public void setTextBoxInput(String textBoxInput) {
this.textBoxInput = textBoxInput;
setCursorAndHighlightPositions(textBoxInput.length());

this.onUpdateConsumer.accept(this.textBoxInput);
}

/**
* Resets the text box input to an empty string.
* <p><b>
* This method does not call {@link TextInputBoxWidget#onUpdateConsumer}.
* If you want the consumer to be called, use {@link TextInputBoxWidget#setTextBoxInput(String)}.
* </b></p>
*/
public void resetTextBoxInput() {
this.textBoxInput = "";
setCursorAndHighlightPositions(0);
}

protected void drawCursor(
PoseStack poseStack, float x, float y, VerticalAlignment verticalAlignment, boolean forceUnfocusedCursor) {
if (isDragging || hasHighlighted()) return;
Expand Down Expand Up @@ -540,16 +560,10 @@ protected void removeFocus() {
textboxScreen.setFocusedTextInput(null);
}

public void setTextBoxInput(String textBoxInput) {
this.textBoxInput = textBoxInput;
setCursorAndHighlightPositions(textBoxInput.length());

this.onUpdateConsumer.accept(this.textBoxInput);
}

/**
* Sets the cursor position to the given value.
* Accepts values outside the bounds of the text box, it will clamp them.
*
* @param cursorPosition
*/
protected void setCursorPosition(int cursorPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.wynntils.utils.mc.McUtils;
import com.wynntils.utils.render.FontRenderer;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -22,7 +23,7 @@ public class WynntilsCheckbox extends Checkbox {
private final int maxTextWidth;
private final int color;

private Consumer<Integer> onClick;
private BiConsumer<WynntilsCheckbox, Integer> onClick;
private List<Component> tooltip;

public WynntilsCheckbox(
Expand All @@ -32,6 +33,21 @@ public WynntilsCheckbox(
this.color = CommonColors.WHITE.asInt();
}

public WynntilsCheckbox(
int x,
int y,
int width,
int height,
Component message,
boolean selected,
int maxTextWidth,
Consumer<Integer> onClick) {
super(x, y, width, height, message, selected);
this.maxTextWidth = maxTextWidth;
this.color = CommonColors.WHITE.asInt();
this.onClick = (checkbox, button) -> onClick.accept(button);
}

public WynntilsCheckbox(
int x,
int y,
Expand All @@ -45,6 +61,23 @@ public WynntilsCheckbox(
super(x, y, width, height, message, selected);
this.maxTextWidth = maxTextWidth;
this.color = CommonColors.WHITE.asInt();
this.onClick = (checkbox, button) -> onClick.accept(button);
this.tooltip = tooltip;
}

public WynntilsCheckbox(
int x,
int y,
int width,
int height,
Component message,
boolean selected,
int maxTextWidth,
BiConsumer<WynntilsCheckbox, Integer> onClick,
List<Component> tooltip) {
super(x, y, width, height, message, selected);
this.maxTextWidth = maxTextWidth;
this.color = CommonColors.WHITE.asInt();
this.onClick = onClick;
this.tooltip = tooltip;
}
Expand Down Expand Up @@ -103,10 +136,14 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (!isMouseOver(mouseX, mouseY)) return false;

if (onClick != null) {
onClick.accept(button);
// Do the click before the onClick so that the checkbox is updated before the consumer is called.
boolean superClicked = super.mouseClicked(mouseX, mouseY, button);

// Only trigger the onClick if the super was actually clicked
if (onClick != null && superClicked) {
onClick.accept(this, button);
}

return super.mouseClicked(mouseX, mouseY, button);
return superClicked;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.wynntils.core.WynntilsMod;
import com.wynntils.screens.base.WynntilsListScreen;
import com.wynntils.screens.base.widgets.BackButton;
import com.wynntils.screens.base.widgets.ItemFilterUIButton;
import com.wynntils.screens.base.widgets.ItemSearchWidget;
import com.wynntils.screens.base.widgets.PageSelectorButton;
import com.wynntils.screens.base.widgets.WynntilsButton;
Expand All @@ -17,14 +18,18 @@
import net.minecraft.network.chat.Component;

public abstract class WynntilsGuideScreen<E, B extends WynntilsButton> extends WynntilsListScreen<E, B> {
private List<ItemProviderType> supportedProviderTypes;

protected WynntilsGuideScreen(Component component, List<ItemProviderType> supportedProviderTypes) {
super(component);

this.supportedProviderTypes = supportedProviderTypes;

// Override the search widget with our own
this.searchWidget = new ItemSearchWidget(
0,
-22,
Texture.CONTENT_BOOK_BACKGROUND.width(),
Texture.CONTENT_BOOK_BACKGROUND.width() - 24,
20,
supportedProviderTypes,
true,
Expand All @@ -36,6 +41,9 @@ protected WynntilsGuideScreen(Component component, List<ItemProviderType> suppor
protected void doInit() {
super.doInit();

this.addRenderableWidget(new ItemFilterUIButton(
Texture.CONTENT_BOOK_BACKGROUND.width() - 20, -22, searchWidget, this, true, supportedProviderTypes));

this.addRenderableWidget(new BackButton(
(int) ((Texture.CONTENT_BOOK_BACKGROUND.width() / 2f - 16) / 2f),
65,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void doRender(GuiGraphics guiGraphics, int mouseX, int mouseY, float part

renderTitle(poseStack, I18n.get("screens.wynntils.wynntilsGuides.charmGuide.name"));

renderDescription(
poseStack,
I18n.get("screens.wynntils.wynntilsGuides.guideDescription"),
I18n.get("screens.wynntils.wynntilsGuides.filterHelper"));

renderVersion(poseStack);

renderItemsHeader(poseStack);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © Wynntils 2022-2023.
* Copyright © Wynntils 2022-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.screens.guides.emeraldpouch;
Expand Down Expand Up @@ -89,6 +89,8 @@ public void doRender(GuiGraphics guiGraphics, int mouseX, int mouseY, float part

renderTitle(poseStack, I18n.get("screens.wynntils.wynntilsGuides.emeraldPouch.name"));

renderDescription(poseStack, I18n.get("screens.wynntils.wynntilsGuides.guideDescription"), "");

renderVersion(poseStack);

renderItemsHeader(poseStack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public void doRender(GuiGraphics guiGraphics, int mouseX, int mouseY, float part

renderTitle(poseStack, I18n.get("screens.wynntils.wynntilsGuides.itemGuide.name"));

renderDescription(
poseStack,
I18n.get("screens.wynntils.wynntilsGuides.guideDescription"),
I18n.get("screens.wynntils.wynntilsGuides.filterHelper"));

renderVersion(poseStack);

renderItemsHeader(poseStack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public void doRender(GuiGraphics guiGraphics, int mouseX, int mouseY, float part

renderTitle(poseStack, I18n.get("screens.wynntils.wynntilsGuides.ingredientGuide.name"));

renderDescription(
poseStack,
I18n.get("screens.wynntils.wynntilsGuides.guideDescription"),
I18n.get("screens.wynntils.wynntilsGuides.filterHelper"));

renderVersion(poseStack);

renderItemsHeader(poseStack);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © Wynntils 2022-2023.
* Copyright © Wynntils 2022-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.screens.guides.powder;
Expand Down Expand Up @@ -86,6 +86,8 @@ public void doRender(GuiGraphics guiGraphics, int mouseX, int mouseY, float part

renderTitle(poseStack, I18n.get("screens.wynntils.wynntilsGuides.powder.name"));

renderDescription(poseStack, I18n.get("screens.wynntils.wynntilsGuides.guideDescription"), "");

renderVersion(poseStack);

renderItemsHeader(poseStack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public void doRender(GuiGraphics guiGraphics, int mouseX, int mouseY, float part

renderTitle(poseStack, I18n.get("screens.wynntils.wynntilsGuides.tomeGuide.name"));

renderDescription(
poseStack,
I18n.get("screens.wynntils.wynntilsGuides.guideDescription"),
I18n.get("screens.wynntils.wynntilsGuides.filterHelper"));

renderVersion(poseStack);

renderItemsHeader(poseStack);
Expand Down

0 comments on commit ec77450

Please sign in to comment.