Skip to content

Commit

Permalink
Merge pull request #46 from ImBonana/master
Browse files Browse the repository at this point in the history
Added option to enable / disable all resources from a specific folder
  • Loading branch information
enjarai authored Aug 21, 2024
2 parents da7f4b1 + e416e30 commit ea08dba
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void init() {
// Also make the selected packs title clickable to unload them
((FolderedPackListWidget) customSelectedPacks).recursiveresources$setTitleClickable(SELECTED_PACKS_TITLE_HOVER, null, () -> {
for (ResourcePackEntry entry : List.copyOf(customSelectedPacks.children())) {
if (entry.pack.canBeDisabled()) {
if ((this.currentFolderMeta.containsEntry(entry, this.currentFolder) || currentFolder.equals(ROOT_FOLDER)) && entry.pack.canBeDisabled()) {
entry.pack.disable();
}
}
Expand Down Expand Up @@ -173,10 +173,10 @@ private void onFiltersUpdated() {

// add a ".." entry when not in the root folder
if (notInRoot()) {
var folder = getParentFileSafe(currentFolder);
var meta = FolderMeta.loadMetaFile(roots, folder);
folders.add(new ResourcePackFolderEntry(client, customAvailablePacks,
this, folder, true, meta));
var rootFolder = getParentFileSafe(currentFolder);
var meta = FolderMeta.loadMetaFile(roots, currentFolder);
folders.add(new ResourcePackFolderEntry(client, customAvailablePacks, customSelectedPacks,
this, currentFolder, rootFolder, true, meta));
}

// create entries for all the folders that aren't packs
Expand All @@ -193,8 +193,8 @@ private void onFiltersUpdated() {
}

var meta = FolderMeta.loadMetaFile(roots, relative);
var entry = new ResourcePackFolderEntry(client, customAvailablePacks,
this, relative, false, meta);
var entry = new ResourcePackFolderEntry(client, customAvailablePacks, customSelectedPacks,
this, relative, null, false, meta);

if (((FolderPack) entry.pack).isVisible()) {
folders.add(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import nl.enjarai.recursiveresources.RecursiveResources;
import nl.enjarai.recursiveresources.pack.FolderMeta;
import nl.enjarai.recursiveresources.pack.FolderPack;
import org.jetbrains.annotations.Nullable;

import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -28,9 +29,12 @@ public class ResourcePackFolderEntry extends ResourcePackEntry {

private final FolderedResourcePackScreen ownerScreen;
public final Path folder;
@Nullable
public final Path rootFolder;
public final boolean isUp;
public final List<ResourcePackEntry> children;
public final FolderMeta meta;
private final PackListWidget selectedList;

private static Function<Path, Path> getIconFileResolver(List<Path> roots, Path folder) {
return iconPath -> {
Expand All @@ -49,32 +53,38 @@ private static Function<Path, Path> getIconFileResolver(List<Path> roots, Path f
};
}

public ResourcePackFolderEntry(MinecraftClient client, PackListWidget list, FolderedResourcePackScreen ownerScreen, Path folder, boolean isUp, FolderMeta meta) {
public ResourcePackFolderEntry(MinecraftClient client, PackListWidget availablePacks, PackListWidget selectedList, FolderedResourcePackScreen ownerScreen, Path folder, @Nullable Path rootFolder, boolean isUp, FolderMeta meta) {
super(
client, list,
client, availablePacks,
new FolderPack(
meta.errored() ? ERRORED_NAME : Text.of(isUp ? UP_TEXT : String.valueOf(folder.getFileName())),
isUp ? BACK_DESCRIPTION : meta.errored() ? ERRORED_DESCRIPTION : FOLDER_DESCRIPTION,
getIconFileResolver(ownerScreen.roots, folder),
folder, meta
)
);
this.selectedList = selectedList;
this.ownerScreen = ownerScreen;
this.folder = folder;
this.rootFolder = rootFolder;
this.isUp = isUp;
this.meta = meta;
this.children = isUp ? List.of() : resolveChildren();
this.children = resolveChildren();
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
double relativeMouseX = mouseX - (double) widget.getRowLeft();
if (!getChildren().isEmpty() && relativeMouseX <= 32.0D) {
enableChildren();
if (relativeMouseX <= 32.0D) {
if(getChildren().isEmpty()) {
disableChildren();
} else {
enableChildren();
}
return true;
}

ownerScreen.moveToFolder(folder);
ownerScreen.moveToFolder(this.isUp ? this.rootFolder : this.folder);
return true;
}

Expand All @@ -91,13 +101,7 @@ public void render(DrawContext context, int index, int y, int x, int entryWidth,

int relativeMouseX = mouseX - x;

if (getChildren().size() > 0) {
if (relativeMouseX < 32) {
context.drawTexture(WIDGETS_TEXTURE, x, y, 0.0F, 32.0F, 32, 32, 256, 256);
} else {
context.drawTexture(WIDGETS_TEXTURE, x, y, 0.0F, 0.0F, 32, 32, 256, 256);
}
}
context.drawTexture(WIDGETS_TEXTURE, x, y, getChildren().isEmpty() ? 32.0F : 0.0F, relativeMouseX < 32 ? 32.0F : 0.0F, 32, 32, 256, 256);
}
}

Expand All @@ -109,6 +113,14 @@ public void enableChildren() {
}
}

public void disableChildren() {
for (ResourcePackEntry entry : List.copyOf(this.selectedList.children())) {
if (this.meta.containsEntry(entry, this.folder) && entry.pack.canBeDisabled()) {
entry.pack.disable();
}
}
}

public List<ResourcePackEntry> getChildren() {
return children;
}
Expand Down

0 comments on commit ea08dba

Please sign in to comment.