Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for folders in the emotes folder #561

Merged
merged 14 commits into from
Mar 13, 2025
Prev Previous commit
Next Next commit
Fix search
  • Loading branch information
dima-dencep committed Mar 12, 2025
commit 0689bd6f886ca9207be4a2efd9d5a8c38a21a0d8
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.kosmx.playerAnim.core.util.MathHelper;
import dev.kosmx.playerAnim.core.util.Pair;
import io.github.kosmx.emotes.PlatformTools;
import io.github.kosmx.emotes.api.services.LoggerService;
import io.github.kosmx.emotes.arch.gui.widgets.search.ISearchEngine;
import io.github.kosmx.emotes.arch.gui.widgets.search.VanillaSearch;
import io.github.kosmx.emotes.main.EmoteHolder;
Expand All @@ -26,7 +25,6 @@
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.logging.Level;

public class EmoteListWidget extends ObjectSelectionList<EmoteListWidget.ListEntry> {
private final FolderEntry mainFolder = new FolderEntry(Component.translatable("emotecraft.folder.main"));
Expand Down Expand Up @@ -98,12 +96,12 @@ public void setEmotes(Iterable<EmoteHolder> list, boolean showInvalid) {
this.mainFolder.entries.add(new EmoteEntry(emoteHolder));
}
}
filter(VanillaSearch.INSTANCE, "");
filter(VanillaSearch.INSTANCE, false, "");
}

public void filter(ISearchEngine engine, String search) {
public void filter(ISearchEngine engine, boolean excludeFolders, String search) {
clearEntries();
engine.filter(getEmotes().stream(), search).forEach(this::addEntry);
engine.filter(getEmotes(excludeFolders).stream(), search).forEach(this::addEntry);
this.setScrollAmount(0);
}

Expand All @@ -125,8 +123,8 @@ public Iterable<EmoteHolder> getEmptyEmotes() {
return empties;
}

public List<ListEntry> getEmotes() {
return this.mainFolder.getEmotes();
public List<ListEntry> getEmotes(boolean excludeFolders) {
return this.mainFolder.getEmotes(excludeFolders);
}

@Override
Expand Down Expand Up @@ -161,7 +159,6 @@ public void setSelected(@Nullable EmoteListWidget.ListEntry selected) {

public boolean setLastFolder(FolderEntry folder) {
if (this.mainFolder.setLastFolder(folder)) {
LoggerService.INSTANCE.log(Level.INFO, appendScreenPath(this.mainFolder, Component.empty()).getString());
if (this.backButton != null) {
this.backButton.active = this.mainFolder.next != null;
}
Expand Down Expand Up @@ -203,17 +200,13 @@ public boolean matches(String string) {
return name.getString().toLowerCase().contains(string.toLowerCase());
}

public abstract List<ListEntry> getEmotes();
public abstract List<ListEntry> getEmotes(boolean excludeFolders);

@Override
public boolean equals(Object obj) {
return obj instanceof ListEntry entry && this.name.equals(entry.name);
}
public abstract boolean equals(Object obj);

@Override
public int hashCode() {
return this.name.hashCode();
}
public abstract int hashCode();
}

public class EmoteEntry extends ListEntry {
Expand Down Expand Up @@ -259,9 +252,19 @@ public boolean matches(String string) {
}

@Override
public List<ListEntry> getEmotes() {
public List<ListEntry> getEmotes(boolean excludeFolders) {
return Collections.singletonList(this);
}

@Override
public boolean equals(Object obj) {
return obj instanceof EmoteEntry entry && this.emote.equals(entry.emote);
}

@Override
public int hashCode() {
return this.emote.hashCode();
}
}

public class FolderEntry extends ListEntry {
Expand All @@ -284,18 +287,26 @@ public boolean isInvalid() {
}

@Override
public List<ListEntry> getEmotes() {
public List<ListEntry> getEmotes(boolean excludeFolders) {
List<ListEntry> emotes = new ArrayList<>();
if (this.next == null || !this.entries.contains(this.next)) {
if (excludeFolders) {
for (var entry : this.entries) {
if (entry instanceof FolderEntry) {
emotes.addAll(entry.getEmotes(true));
} else {
emotes.add(entry);
}
}
} else if (this.next == null || !this.entries.contains(this.next)) {
for (var entry : this.entries) {
if (entry instanceof FolderEntry folder && folder.isInvalid()) {
emotes.addAll(entry.getEmotes());
emotes.addAll(entry.getEmotes(false));
} else {
emotes.add(entry);
}
}
} else {
emotes.addAll(this.next.getEmotes());
emotes.addAll(this.next.getEmotes(false));
}
emotes.sort(Comparator.comparing(o -> o.name.getString().toLowerCase()));
return Collections.unmodifiableList(emotes);
Expand Down Expand Up @@ -333,6 +344,16 @@ public FolderEntry getOrCreateFolder(Component name) {
this.entries.add(folder);
return folder;
}

@Override
public boolean equals(Object obj) {
return obj instanceof FolderEntry entry && this.name.equals(entry.name);
}

@Override
public int hashCode() {
return this.name.hashCode();
}
}

public void setCompactMode(boolean compactMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
Expand Down Expand Up @@ -56,9 +57,9 @@ protected void init() {

protected void addTitle() {
this.searchBox = this.layout.addToHeader(this.searchEngine.createEditBox(this.font, SEARCH,
() -> Objects.requireNonNull(this.list).getEmotes()
() -> Objects.requireNonNull(this.list).getEmotes(this.searchBox != null && !StringUtils.isBlank(this.searchBox.getValue()))
));
this.searchBox.setResponder((string) -> Objects.requireNonNull(this.list).filter(this.searchEngine, string));
this.searchBox.setResponder((string) -> Objects.requireNonNull(this.list).filter(this.searchEngine, this.searchBox != null && !StringUtils.isBlank(this.searchBox.getValue()), string));
}

protected void addPlayerPreview() {
Expand Down
Loading