boolean skip = false;
final Mod mod = installer.getMods().get(i);
if (installer.isServer() && !mod.installOnServer()) {
continue;
}
ModsJCheckBox checkBox = null;
if ((installer.isServer() ? mod.isServerOptional() : mod.isOptional())) {
if (!mod.getCategory().isEmpty()) {
if (!categoriesDone.contains(mod.getCategory())) {
skip = true;
categoriesDone.add(mod.getCategory());
checkBox = new ModsJCheckBox(installerr.getCategoryName(mod.getCategory()));
checkBox.setBounds(0, (count1 * 20), checkBox.getPreferredSize().width, 20);
checkBox.setEnabled(false);
count1++;
}
}
if (!skip) {
checkBox = new ModsJCheckBox(mod);
checkBox.setEnabled(true);
if (mod.getLinked().isEmpty()) {
checkBox.setBounds((mod.hasCategory() ? 20 : 0), (count1 * 20),
checkBox.getPreferredSize().width, 20);
} else {
Mod linkedMod = installer.getModByName(mod.getLinked());
if (linkedMod == null) {
LogManager.error("The mod " + mod.getName() + " tried to reference a linked mod " + mod
.getLinked() + " which doesn't exist!");
installer.cancel(true);
return;
}
if ((installer.isServer() ? linkedMod.isServerOptional() : linkedMod.isOptional())) {
checkBox.setEnabled(false);
checkBox.setBounds((mod.hasCategory() ? 40 : 20), (count1 * 20),
checkBox.getPreferredSize().width, 20);
} else {
checkBox.setBounds((mod.hasCategory() ? 20 : 0), (count1 * 20),
checkBox.getPreferredSize().width, 20);
}
if (mod.isSelected()) {
checkBox.setEnabled(true);
checkBox.setSelected(true);
if (!linkedMod.isSelected()) {
boolean needToEnableChildren = false;
for (ModsJCheckBox checkbox : modCheckboxes) {
if (checkbox.getMod().getName().equalsIgnoreCase(mod.getLinked())) {
checkbox.setSelected(true); // Select the checkbox
needToEnableChildren = true;
break;
}
}
if (needToEnableChildren) {
for (ModsJCheckBox checkbox : modCheckboxes) {
if (checkbox.getMod().getLinked().equalsIgnoreCase(mod.getLinked())) {
checkbox.setEnabled(true);
}
}
}
}
} else {
if (linkedMod.isSelected()) {
checkBox.setEnabled(true);
}
}
}
if (mod.isHidden() || mod.isLibrary()) {
checkBox.setVisible(false);
} else {
count1++;
}
}
if (mod.hasWarning()) {
final ModsJCheckBox finalCheckBox = checkBox;
checkBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (finalCheckBox.isSelected()) {
String message = installer.getPack().getWarningMessage(installer.getVersion()
.getVersion(), mod.getWarning());
if (message != null) {
String[] options = {Language.INSTANCE.localize("common.yes"),
Language.INSTANCE.localize("common.no")};
int ret = JOptionPane.showOptionDialog(App.settings.getParent(),
"<html>" + message + "<br/>" +
Language.INSTANCE.localize("instance.warningsure") + "</html>",
Language.INSTANCE.localize("instance.warning"),
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options,
options[1]);
if (ret != 0) {
finalCheckBox.setSelected(false);
}
}
}
}
});
}
} else {
checkBox = new ModsJCheckBox(mod);
checkBox.setBounds(0, (count2 * 20), checkBox.getPreferredSize().width, 20);
checkBox.setSelected(true);
checkBox.setEnabled(false);
if (mod.isHidden() || mod.isLibrary()) {
checkBox.setVisible(false);
} else {
count2++;
}
}
if (!checkBox.isCategory()) {
if (installer.isReinstall()) {
if (installer.wasModInstalled(mod.getName())) {
if ((installer.isServer() ? mod.isServerOptional() : mod.isOptional())) {
checkBox.setSelected(true);
checkBox.setEnabled(true);
}
}
} else {
if ((installer.isServer() ? mod.isServerOptional() : mod.isOptional()) && mod.isSelected()) {
checkBox.setSelected(true);
checkBox.setEnabled(true);
}
}
checkBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ModsJCheckBox a = (ModsJCheckBox) e.getSource();
sortOutMods(a);
}
});
}
modCheckboxes.add(checkBox);
if (!skip) {
i++;
}
}
for (int i = 0; i < modCheckboxes.size(); i++) {
ModsJCheckBox checkBox = modCheckboxes.get(i);
if (checkBox.isCategory()) {
checkBoxPanel1.add(checkBox);
} else if ((installer.isServer() ? checkBox.getMod().isServerOptional() : checkBox.getMod().isOptional())) {
checkBoxPanel1.add(checkBox);
} else {
checkBoxPanel2.add(checkBox);
}
}