add lite mod description in mod panel.

This commit is contained in:
huanghongxun 2015-12-01 18:20:03 +08:00
parent 73a9fbb1c4
commit b6cb5f0bee
2 changed files with 17 additions and 8 deletions

View File

@ -26,6 +26,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.system.FileUtils; import org.jackhuang.hellominecraft.utils.system.FileUtils;
/** /**
@ -35,7 +36,7 @@ import org.jackhuang.hellominecraft.utils.system.FileUtils;
public class ModInfo implements Comparable<ModInfo> { public class ModInfo implements Comparable<ModInfo> {
public File location; public File location;
public String modid, name, description, version, mcversion, url, updateUrl, credits; public String modid, name, description, author, version, mcversion, url, updateUrl, credits;
public String[] authorList; public String[] authorList;
public boolean isActive() { public boolean isActive() {
@ -51,6 +52,14 @@ public class ModInfo implements Comparable<ModInfo> {
return name == null ? FileUtils.removeExtension(location.getName()) : name; return name == null ? FileUtils.removeExtension(location.getName()) : name;
} }
public String getAuthor() {
if (authorList != null && authorList.length > 0)
return StrUtils.parseParams("", authorList, ", ");
else if (StrUtils.isNotBlank(author))
return author;
else return "Unknown";
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj != null && obj instanceof ModInfo && (((ModInfo) obj).location == location || ((ModInfo) obj).location.equals(location)); return obj != null && obj instanceof ModInfo && (((ModInfo) obj).location == location || ((ModInfo) obj).location.equals(location));
@ -82,10 +91,13 @@ public class ModInfo implements Comparable<ModInfo> {
try { try {
ZipFile jar = new ZipFile(f); ZipFile jar = new ZipFile(f);
ZipEntry entry = jar.getEntry("mcmod.info"); ZipEntry entry = jar.getEntry("mcmod.info");
if (entry == null)
entry = jar.getEntry("litemod.json");
if (entry == null) if (entry == null)
return i; return i;
else { else {
List<ModInfo> m = C.gson.fromJson(new InputStreamReader(jar.getInputStream(entry)), new TypeToken<List<ModInfo>>() { List<ModInfo> m = C.gson.fromJson(new InputStreamReader(jar.getInputStream(entry)),
new TypeToken<List<ModInfo>>() {
}.getType()); }.getType());
if (m != null && m.size() > 0) { if (m != null && m.size() > 0) {
i = m.get(0); i = m.get(0);
@ -93,12 +105,10 @@ public class ModInfo implements Comparable<ModInfo> {
} }
} }
jar.close(); jar.close();
return i;
} catch (IOException ex) { } catch (IOException ex) {
HMCLog.warn("File " + f + " is not a jar.", ex); HMCLog.warn("File " + f + " is not a jar.", ex);
return i; } catch (JsonSyntaxException ignore) {
} catch (JsonSyntaxException e) {
return i;
} }
return i;
} }
} }

View File

@ -187,8 +187,7 @@ public class GameSettingsPanel extends javax.swing.JPanel implements DropTargetL
ModInfo m = mods.get(row); ModInfo m = mods.get(row);
boolean hasLink = m.url != null; boolean hasLink = m.url != null;
String text = "<html>" + (hasLink ? "<a href=\"" + m.url + "\">" : "") + m.getName() + (hasLink ? "</a>" : ""); String text = "<html>" + (hasLink ? "<a href=\"" + m.url + "\">" : "") + m.getName() + (hasLink ? "</a>" : "");
if (m.authorList != null && m.authorList.length > 0) text += " by " + m.getAuthor();
text += " by " + StrUtils.parseParams("", m.authorList, ", ");
text += "<br>" + (m.description == null ? "No mcmod.info found" : SwingUtils.getParsedJPanelText(lblModInfo, m.description)); text += "<br>" + (m.description == null ? "No mcmod.info found" : SwingUtils.getParsedJPanelText(lblModInfo, m.description));
lblModInfo.setText(text); lblModInfo.setText(text);
lblModInfo.setCursor(new java.awt.Cursor(hasLink ? java.awt.Cursor.HAND_CURSOR : java.awt.Cursor.DEFAULT_CURSOR)); lblModInfo.setCursor(new java.awt.Cursor(hasLink ? java.awt.Cursor.HAND_CURSOR : java.awt.Cursor.DEFAULT_CURSOR));