Ejemplo n.º 1
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() instanceof JMenuItem) {
     JMenuItem item = (JMenuItem) e.getSource();
     String name = item.getText();
     Profile profile = profiles.getProfile(name);
     Component[] components = selectorPanel.getComponents();
     for (int i = 0; i < components.length; i++) {
       Component comp = components[i];
       if (comp instanceof CPCheckBox) {
         CPCheckBox scb = (CPCheckBox) comp;
         String id = scb.element.id;
         boolean enb = profile.has(id);
         scb.setState(enb);
       }
     }
   }
 }
  /**
   * Launches factorio with the current mods selected.
   *
   * @param lastSelected The last selected TreeNode.
   */
  public boolean launchFactorio(DefaultMutableTreeNode lastSelected) {
    if (this.model.getFactorioExecutablePath().isEmpty()) {
      System.out.println("Couldn't launch factorio, invalid executable path.");
      return false;
    }

    if (lastSelected == null) return false;

    // Get the file for the mod directory.
    File modDir = new File(this.model.getFactorioModPath());
    FileUtils.deleteAllFiles(modDir);

    // We get the dir of the profile of mods and get the list of files inside the dir.
    // We get the selected node. If it's a leaf, try to get the parent (which is most likely the
    // profile)
    if (lastSelected.isLeaf() && !((DefaultMutableTreeNode) lastSelected.getParent()).isRoot())
      lastSelected = (DefaultMutableTreeNode) lastSelected.getParent();

    File profileDir = null;
    if (!lastSelected.isRoot()) {
      profileDir = new File(this.model.getFactorioModManagerPath() + lastSelected);
      copyAllEnabledMods(profileDir, modDir, lastSelected);

      // Run the factorio executable.
      try {
        Process p = Runtime.getRuntime().exec(this.model.getFactorioExecutablePath());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    // TODO Deal with not having the right thing selected.
    if (profileDir == null) {
      System.out.println("Invalid profile selected, can't execute.");
      return false;
    }

    // writeModsToJson(FileUtils.findFileWithPartName(profileDir, "mod-list.json"),
    // modListMap.get(profileDir.getName()));
    Profile selectedProfile = this.model.getModProfileMap().get(profileDir.getName());
    selectedProfile.writeModListToJson(lastSelected.children());

    return true;
  }
Ejemplo n.º 3
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() instanceof JMenuItem) {
     JMenuItem item = (JMenuItem) e.getSource();
     String name = item.getText();
     if (name.equals("New...")) {
       name = JOptionPane.showInputDialog(selectorPanel, "Enter a name for the new profile.");
     }
     if ((name == null) || name.trim().equals("")) return;
     Profile profile = new Profile(name);
     Component[] components = selectorPanel.getComponents();
     for (int i = 0; i < components.length; i++) {
       Component comp = components[i];
       if (comp instanceof CPCheckBox) {
         CPCheckBox scb = (CPCheckBox) comp;
         String id = scb.element.id;
         if (scb.isSelected()) profile.add(id);
       }
     }
     profiles.add(profile);
   }
 }
  /**
   * Sets the mod information for the selected mod. Also will attempt to display any recent versions
   * of the mod from the factorio mod website.
   *
   * @param node The selected node that contains the mod name and such.
   * @param modInfoList The JList to modify with mod information.
   */
  public void setModInformation(DefaultMutableTreeNode node, JList modInfoList) {
    // Get the checkbox (for its value) and the profile name. Get the actual mod with this.
    ModManagerWindow.CheckBoxNode checkBox = (ModManagerWindow.CheckBoxNode) node.getUserObject();
    String profileName = node.getParent().toString();
    Profile.Mod mod = Profile.getModByNameForProfile(profileName, checkBox.getText());
    this.model.setCurrentlySelectedModName(checkBox.getText());
    this.model.setCurrentlySelectedProfile(profileName);

    // Set up the initial mod information.
    Object[] modInfo = {
      "Mod Name: " + mod.name, "Author: " + mod.info.author, "Version: " + mod.info.version,
    };

    // Set the list model.
    DefaultListModel listModel = new DefaultListModel();
    for (Object obj : modInfo) listModel.addElement(obj);

    modInfoList.setModel(listModel);

    this.getRecentVersionsOfModAsync(mod, modInfoList);
  }
  public TreeModel initModList() {
    File modManagerDir = new File(this.model.getFactorioModManagerPath()); // The actual file.

    /*
       Here we will go into the mod directory (/fm/) and load all folders inside the directory to
       become their own profiles. Each profile will handle loading their own files (mods) and we will use
       those mod files to build a modTree with checkboxes.
    */

    TreeModel model = null;

    if (!modManagerDir.exists()) modManagerDir.mkdir();
    else {
      HashMap<String, Boolean> enabledMods = new HashMap<>();

      // Get the list of folder (files) in this dir. Also, make a modTree model.
      File[] files = modManagerDir.listFiles();
      DefaultMutableTreeNode root = new DefaultMutableTreeNode("profiles");
      model = new DefaultTreeModel(root);

      if (files != null && files.length > 0) {

        // For each dir under the 'fm' dir, we want to add a modTree node to the modTree (with a
        // checkbox)
        for (File profileDir : files) {
          DefaultMutableTreeNode profileNode =
              new DefaultMutableTreeNode(profileDir.getName()); // Add the name to the modTree.
          root.add(profileNode); // Add it.

          // This gets the modList from the mod-list.json and dictates which mods are
          // selected/unselected.
          Profile.ModListJson modList =
              FileUtils.getJsonObject(
                  FileUtils.findFileWithPartName(profileDir, "mod-list"),
                  Profile.ModListJson.class);
          for (Profile.Mod mod : modList.mods) enabledMods.put(mod.name, mod.enabled);
          this.model
              .getModListMap()
              .put(profileDir.getName(), modList); // Add a modName - modList link.

          // Then we want to load a new profile, get the mods, and add a modTree node to the modTree
          // for each one.
          Profile profile = new Profile(profileDir); // Make a profile object.
          ArrayList<Profile.Mod> mods = profile.getMods().mods; // Get the list of Mods it detected.
          this.model
              .getModProfileMap()
              .put(profileDir.getName(), profile); // Put the profile into the map.

          for (Profile.Mod mod : mods) { // For each mod, add the name to the modTree.
            if (mod.name.equals("base")) continue;
            profileNode.add(
                new DefaultMutableTreeNode(
                    new ModManagerWindow.CheckBoxNode(mod.name, mod.enabled)));
          }
        }
      } else {
        root.add(new DefaultMutableTreeNode("Something went wrong, no files in the fm dir?"));
      }
    }

    return model;
  }
 public void menuSelected(MenuEvent e) {
   Profile profilePage = new Profile("staff", docID, type);
   profilePage.setVisible(true);
   dispose();
 }