Skip to content

Commit

Permalink
Fix a gui bug where an image read result wasn't checked for null, and…
Browse files Browse the repository at this point in the history
… small additions to plugin api.
  • Loading branch information
AlexIIL committed Nov 13, 2024
1 parent d7112dd commit b03fcd6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.api.Version;
import org.quiltmc.loader.api.gui.QuiltLoaderGui;
import org.quiltmc.loader.api.gui.QuiltTreeNode;
import org.quiltmc.loader.api.plugin.gui.PluginGuiManager;
import org.quiltmc.loader.api.plugin.gui.PluginGuiTreeNode;
import org.quiltmc.loader.api.plugin.solver.ModLoadOption;
Expand Down Expand Up @@ -251,10 +253,22 @@ default Path copyToReadOnlyFileSystem(String name, Path folderRoot) throws IOExc
// # Gui #
// #######

/** @return The {@link QuiltTreeNode} that will be displayed in the "Mods" tab of the plugin gui for the specific
* mod. */
QuiltTreeNode getTreeNode(ModLoadOption mod);

/** @return The {@link QuiltTreeNode} that is the root of the "Files" tab. */
QuiltTreeNode getFilesTreeNode();

/** @deprecated Use {@link #getTreeNode(ModLoadOption)} instead. */
@Deprecated
PluginGuiTreeNode getGuiNode(ModLoadOption mod);

/** @deprecated Use {@link #getFilesTreeNode()} instead. */
@Deprecated
PluginGuiTreeNode getRootGuiNode();

/** @deprecated Since {@link PluginGuiManager} is deprecated. Use {@link QuiltLoaderGui} directly instead. */
@Deprecated
PluginGuiManager getGuiManager();
}
5 changes: 3 additions & 2 deletions src/main/java/org/quiltmc/loader/impl/gui/BasicWindowUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,12 @@ BufferedImage generateIcon(PluginIconImpl.IconType info, int scale) throws IOExc
if (map.isEmpty()) {
for (byte[] src : srcImages) {
BufferedImage sub = ImageIO.read(new ByteArrayInputStream(src));
map.put(sub.getWidth(), sub);
if (sub != null) {
map.put(sub.getWidth(), sub);
}
}
}


Entry<Integer, BufferedImage> bestSource = map.ceilingEntry(scale);
if (bestSource == null) {
bestSource = map.floorEntry(scale);
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/quiltmc/loader/impl/gui/GuiManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,12 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import javax.imageio.ImageIO;

import org.quiltmc.loader.api.FasterFiles;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.api.gui.QuiltLoaderIcon;
import org.quiltmc.loader.api.plugin.gui.PluginGuiManager;
import org.quiltmc.loader.impl.util.FileUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ public class QuiltPluginManagerImpl implements QuiltPluginManager {

final Queue<MainThreadTask> mainThreadTasks;

public final GuiManagerImpl guiManager = GuiManagerImpl.MANAGER;
/** The root tree node for the "files" tab. */
public final QuiltStatusNode guiFileRoot = QuiltLoaderGuiImpl.createTreeNode();
public final QuiltStatusNode guiModsRoot = QuiltLoaderGuiImpl.createTreeNode();
Expand Down Expand Up @@ -688,18 +687,31 @@ public EnvType getEnvironment() {
// #######

@Override
public QuiltTreeNode getTreeNode(ModLoadOption mod) {
return modGuiNodes.get(mod);
}

@Override
@Deprecated
public PluginGuiTreeNode getGuiNode(ModLoadOption mod) {
return modGuiNodes.get(mod);
}

@Override
public QuiltTreeNode getFilesTreeNode() {
return guiFileRoot;
}

@Override
@Deprecated
public PluginGuiTreeNode getRootGuiNode() {
return guiFileRoot;
}

@Override
@Deprecated
public PluginGuiManager getGuiManager() {
return guiManager;
return GuiManagerImpl.MANAGER;
}

public QuiltDisplayedError reportError(BasePluginContext reporter, QuiltLoaderText title) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.quiltmc.loader.api.gui.QuiltLoaderGui;
import org.quiltmc.loader.api.gui.QuiltLoaderIcon;
import org.quiltmc.loader.api.gui.QuiltLoaderText;
import org.quiltmc.loader.api.gui.QuiltTreeNode;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.api.Version;
import org.quiltmc.loader.api.VersionRange;
Expand Down Expand Up @@ -456,9 +457,9 @@ public void onLoadOptionAdded(LoadOption option) {
Collection<? extends ProvidedMod> provides = metadata.provides();

for (ProvidedMod provided : provides) {
PluginGuiTreeNode guiNode = context().manager().getGuiNode(mod)//
QuiltTreeNode guiNode = context().manager().getTreeNode(mod)//
.addChild(QuiltLoaderText.translate("gui.text.providing", provided.id()));
guiNode.mainIcon(QuiltLoaderGui.iconUnknownFile());
guiNode.icon(QuiltLoaderGui.iconUnknownFile());
context().addModLoadOption(new ProvidedModOption(mod, provided), guiNode);
}
}
Expand Down

0 comments on commit b03fcd6

Please sign in to comment.