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 org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.StrUtils;
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 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 boolean isActive() {
@ -50,6 +51,14 @@ public class ModInfo implements Comparable<ModInfo> {
public String getName() {
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
public boolean equals(Object obj) {
@ -82,10 +91,13 @@ public class ModInfo implements Comparable<ModInfo> {
try {
ZipFile jar = new ZipFile(f);
ZipEntry entry = jar.getEntry("mcmod.info");
if (entry == null)
entry = jar.getEntry("litemod.json");
if (entry == null)
return i;
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());
if (m != null && m.size() > 0) {
i = m.get(0);
@ -93,12 +105,10 @@ public class ModInfo implements Comparable<ModInfo> {
}
}
jar.close();
return i;
} catch (IOException ex) {
HMCLog.warn("File " + f + " is not a jar.", ex);
return i;
} catch (JsonSyntaxException e) {
return i;
} catch (JsonSyntaxException ignore) {
}
return i;
}
}

View File

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