Esempio n. 1
1
 private int move(int index, int direction, boolean allTheWay) {
   Vector<Mod> visibleMods = getVisible();
   int newIndex;
   if (!allTheWay) {
     newIndex = index + direction;
   } else if (direction < 0) {
     newIndex = 0;
   } else {
     newIndex = visibleMods.size() - 1;
   }
   if (index >= 0
       && index < visibleMods.size()
       && newIndex >= 0
       && newIndex < visibleMods.size()
       && newIndex != index) {
     List<Mod> mods =
         visibleMods.subList(Math.min(index, newIndex), Math.max(index, newIndex) + 1);
     for (int i = 0; i < modsByIndex.size(); i++) {
       for (int j = 0; j < mods.size(); j++) {
         if (modsByIndex.get(i) == mods.get(j)) {
           modsByIndex.set(i, mods.get((j + direction + mods.size()) % mods.size()));
           break;
         }
       }
     }
     index = newIndex;
   }
   return index;
 }
Esempio n. 2
0
 int indexOf(Mod mod) {
   for (int i = 0; i < modsByIndex.size(); i++) {
     if (mod == modsByIndex.get(i)) {
       return i;
     }
   }
   return -1;
 }
Esempio n. 3
0
 int indexOfVisible(Mod mod) {
   Vector<Mod> visible = getVisible();
   for (int i = 0; i < visible.size(); i++) {
     if (mod == visible.get(i)) {
       return i;
     }
   }
   return -1;
 }
Esempio n. 4
0
 Vector<Mod> getVisible() {
   Vector<Mod> visibleMods = new Vector<Mod>();
   for (Mod mod : modsByIndex) {
     if (!mod.internal) {
       visibleMods.add(mod);
     }
   }
   return visibleMods;
 }
Esempio n. 5
0
 void remove(Mod mod) {
   String name = mod.getName();
   for (int i = 0; i < modsByIndex.size(); i++) {
     if (modsByIndex.get(i) == mod) {
       modsByIndex.remove(i);
       modsByName.remove(name);
     }
   }
   mod.close();
 }
Esempio n. 6
0
 void enableValidMods(boolean enableAll) {
   for (int i = modsByIndex.size() - 1; i >= 0; i--) {
     Mod mod = modsByIndex.get(i);
     boolean enabled = mod.okToApply();
     if (enabled) {
       if (enableAll) {
         selectMod(mod, true);
       }
     } else {
       selectMod(mod, false);
     }
   }
 }
Esempio n. 7
0
 int addLast(Mod mod) {
   String name = mod.getName();
   Mod oldMod = modsByName.get(name);
   if (oldMod != null) {
     remove(oldMod);
   }
   modsByIndex.add(mod);
   modsByName.put(name, mod);
   mod.setRefs();
   return indexOfVisible(mod);
 }
Esempio n. 8
0
 int replace(Mod oldMod, Mod newMod) {
   int index = indexOf(oldMod);
   if (index >= 0 && oldMod.getName().equals(newMod.getName())) {
     modsByIndex.set(index, newMod);
     modsByName.put(newMod.getName(), newMod);
     oldMod.close();
     return indexOfVisible(newMod);
   } else {
     remove(oldMod);
     return addFirst(newMod);
   }
 }
Esempio n. 9
0
 private void refreshInternalMods() {
   modsByIndex.remove(baseMod);
   modsByIndex.remove(texturePackMod);
   modsByIndex.add(0, baseMod);
   modsByIndex.add(1, texturePackMod);
   outer:
   while (true) {
     for (int i = 0; i < modsByIndex.size() - 1; i++) {
       Mod mod1 = modsByIndex.get(i);
       Mod mod2 = modsByIndex.get(i + 1);
       if (mod1.internal && !dependsOn(mod2, mod1)) {
         modsByIndex.set(i, mod2);
         modsByIndex.set(i + 1, mod1);
         continue outer;
       }
     }
     break;
   }
   for (Mod mod : modsByIndex) {
     if (mod.internal) {
       mod.setEnabled(false);
     }
   }
   HashMap<Mod, Boolean> changes = new HashMap<Mod, Boolean>();
   for (Mod mod : modsByIndex) {
     try {
       if (mod.internal) {
         // nothing
       } else if (mod.isEnabled()) {
         enableMod(changes, mod, false);
       } else {
         disableMod(changes, mod, false);
       }
     } catch (ModDependencyException e) {
       Logger.log(e);
     }
   }
   for (Map.Entry<Mod, Boolean> entry : changes.entrySet()) {
     Mod mod = entry.getKey();
     mod.setEnabled(entry.getValue());
   }
 }
Esempio n. 10
0
 private boolean addNoReplace(Mod mod) {
   if (mod == null) {
     return false;
   }
   String name = mod.getName();
   if (modsByName.containsKey(name)) {
     Logger.log(Logger.LOG_MOD, "WARNING: duplicate mod %s ignored", name);
     return false;
   }
   mod.setRefs();
   modsByName.put(name, mod);
   modsByIndex.add(mod);
   mod.setEnabled(mod.defaultEnabled);
   mod.loadOptions();
   return true;
 }
Esempio n. 11
0
 void disableAll() {
   for (int i = modsByIndex.size() - 1; i >= 0; i--) {
     Mod mod = modsByIndex.get(i);
     selectMod(mod, false);
   }
 }
Esempio n. 12
0
 int size() {
   return modsByIndex.size();
 }
Esempio n. 13
0
 Mod get(int index) {
   return modsByIndex.get(index);
 }