Skip to content

Commit

Permalink
added sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed May 27, 2023
1 parent 1f65909 commit 0799acc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
39 changes: 38 additions & 1 deletion common/src/main/java/net/mca/client/gui/SkinLibraryScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class SkinLibraryScreen extends Screen implements SkinListUpdateListener
private static final float CANVAS_SCALE = 2.35f;

private String filteredString = "";
private SortingMode sortingMode = SortingMode.LIKES;

private final List<LiteContent> serverContent = new ArrayList<>();
private List<LiteContent> filteredContent = new ArrayList<>();
Expand Down Expand Up @@ -95,6 +96,8 @@ public class SkinLibraryScreen extends Screen implements SkinListUpdateListener
private double lastMouseX;
private double lastMouseY;

private int timeSinceLastRebuild;

private Text error;

private final VillagerEditorScreen previousScreen;
Expand Down Expand Up @@ -578,8 +581,19 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
return super.mouseScrolled(mouseX, mouseY, amount);
}

@Override
public void tick() {
super.tick();

timeSinceLastRebuild++;
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (timeSinceLastRebuild < 2) {
return false;
}

if (page == Page.EDITOR) {
if (button == 0 || button == 1) {
activeMouseButton = button;
Expand Down Expand Up @@ -674,6 +688,8 @@ private void pickColor() {
private void rebuild() {
clearChildren();

timeSinceLastRebuild = 0;

// filters
if (page == Page.LIBRARY || page == Page.EDITOR_LOCKED || page == Page.EDITOR_PREPARE || page == Page.EDITOR_TYPE) {
List<Page> b = new LinkedList<>();
Expand Down Expand Up @@ -711,6 +727,22 @@ private void rebuild() {
}));
setSelectionPage(selectionPage);

//sorting icons
addDrawableChild(new ToggleableTooltipIconButtonWidget(width / 2 + 150, height / 2 + 82, 6 * 16, 3 * 16,
sortingMode == SortingMode.LIKES,
Text.translatable("gui.skin_library.sort_likes"),
v -> {
sortingMode = SortingMode.LIKES;
updateSearch();
}));
addDrawableChild(new ToggleableTooltipIconButtonWidget(width / 2 + 150 + 22, height / 2 + 82, 7 * 16, 3 * 16,
sortingMode == SortingMode.NEWEST,
Text.translatable("gui.skin_library.sort_newest"),
v -> {
sortingMode = SortingMode.NEWEST;
updateSearch();
}));

//search
TextFieldWidget textFieldWidget = addDrawableChild(new TextFieldWidget(this.textRenderer, width / 2 - 200 + 65, height / 2 - 110 + 2, 110, 16,
Text.translatable("gui.skin_library.search")));
Expand Down Expand Up @@ -1174,7 +1206,6 @@ private void drawControls(LiteContent content, boolean advanced, int cx, int cy)
true,
Text.translatable("gui.skin_library.ban"),
v -> {
((ToggleableTooltipButtonWidget) v).toggle = !((ToggleableTooltipButtonWidget) v).toggle;
setBan(content.userid(), true);
reloadDatabase();
})));
Expand Down Expand Up @@ -1310,6 +1341,7 @@ private void updateSearch() {
// filter the assets by string search and asset group
filteredContent = contents.stream()
.filter(v -> (filteredString.isEmpty() || v.title().contains(filteredString) || v.username().contains(filteredString)) || v.tags().stream().anyMatch(t -> t.contains(filteredString)))
.sorted((a, b) -> sortingMode == SortingMode.LIKES ? b.likes() - a.likes() : b.contentid() - a.contentid())
.toList();

rebuild();
Expand Down Expand Up @@ -1566,6 +1598,11 @@ public enum SkinType {
HAIR
}

public enum SortingMode {
LIKES,
NEWEST
}

public enum SubscriptionFilter {
LIBRARY,
GLOBAL,
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@
"gui.skin_library.upload_duplicate": "That content already exists.",
"gui.skin_library.upload_failed": "Upload failed. Woops.",
"gui.skin_library.subscribe": "Use server wide!",
"gui.skin_library.sort_likes": "Sort by likes",
"gui.skin_library.sort_newest": "Sort by date",
"gui.skin_library.like": "Like",
"gui.skin_library.edit": "Edit",
"gui.skin_library.delete": "Delete",
Expand Down
Binary file modified common/src/main/resources/assets/mca/textures/gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0799acc

Please sign in to comment.