From 13513987c8415c6be8cf29086884cf4f27d294a8 Mon Sep 17 00:00:00 2001 From: Wirlaburla Date: Tue, 16 Jul 2024 01:01:28 -0500 Subject: [PATCH] tried to add a feature, fucked up. here, I fucked up other bits of code too. --- firestar/src/main/java/Clifford.java | 8 +- firestar/src/main/java/Main.java | 24 ++++ firestar/src/main/java/MissPiggy.java | 8 +- firestar/src/main/java/Robin.java | 23 ++++ firestar/src/main/java/Scooter.form | 44 +++++++ firestar/src/main/java/Scooter.java | 79 +++++++++++++ firestar/src/main/java/Suggs.java | 158 +++++++++++++++----------- 7 files changed, 272 insertions(+), 72 deletions(-) create mode 100644 firestar/src/main/java/Robin.java create mode 100644 firestar/src/main/java/Scooter.form create mode 100644 firestar/src/main/java/Scooter.java diff --git a/firestar/src/main/java/Clifford.java b/firestar/src/main/java/Clifford.java index 94b78fc..e9d6b6a 100644 --- a/firestar/src/main/java/Clifford.java +++ b/firestar/src/main/java/Clifford.java @@ -45,14 +45,14 @@ public class Clifford implements ActionListener { private JButton savebtn; private JButton cancelbtn; - MissPiggy invoker; + Robin invoker; Main.Mod mod; int index; File directory; boolean creating; - public void Action(MissPiggy inv, int modindex) { // Editor + public void Action(Robin inv, int modindex) { // Editor invoker = inv; mod = Main.Mods.get(modindex); index = modindex; @@ -93,7 +93,7 @@ public class Clifford implements ActionListener { }); } - public void Action(MissPiggy inv, File dir) { // Generator + public void Action(Robin inv, File dir) { // Generator invoker = inv; directory = dir; creating = true; @@ -159,7 +159,7 @@ public class Clifford implements ActionListener { Main.Mods.set(index, mod); invoker.frame.setEnabled(true); - invoker.InitializeModListInGUI(); + if (invoker instanceof MissPiggy) ((MissPiggy)invoker).InitializeModListInGUI(); frame.dispose(); } else if (actionEvent.getSource() == savebtn && creating) { if (fName.getText().isEmpty()) { diff --git a/firestar/src/main/java/Main.java b/firestar/src/main/java/Main.java index e758ece..d45e836 100644 --- a/firestar/src/main/java/Main.java +++ b/firestar/src/main/java/Main.java @@ -21,10 +21,12 @@ import net.lingala.zip4j.exception.ZipException; import org.json.*; import java.awt.*; +import java.awt.image.BufferedImage; import java.io.*; import java.nio.file.*; import java.util.*; import java.util.List; +import javax.imageio.ImageIO; import javax.swing.*; public class Main { @@ -92,6 +94,7 @@ public class Main { // UI Global Assets public static Font fExo2; + public static BufferedImage windowIcon; public static void main(String[] args) { // license string @@ -119,6 +122,13 @@ public class Main { System.out.println("Font \"Exo 2\" is missing!"); fExo2 = new Font("Arial", Font.PLAIN, 12); } + + // load global window icon + try { + windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png")); + } catch (IOException e) { + System.out.println("ERROR: Failed to find titleIcon.png. Window will not have an icon."); + } // check and load configs File fConf = new File(System.getProperty("user.home") + "/.firestar/firestar.conf"); @@ -226,4 +236,18 @@ public class Main { public static boolean callDownloaderStatically (String url, String folder, String name) { return new Fozzie().DownloadFile(url, folder, name); } + + public static Process exec(String[] cmd, String cwd) throws IOException { + Process p; + String[] pcmd; + if (!Main.windows) { + pcmd = new String[cmd.length + 1]; + pcmd[0] = "wine"; + System.arraycopy(cmd, 0, pcmd, 1, cmd.length); + p = Runtime.getRuntime().exec(pcmd, null, new File(cwd)); + } else { + p = Runtime.getRuntime().exec(cmd, null, new File(cwd.replace("/", "\\"))); + } + return p; + } } \ No newline at end of file diff --git a/firestar/src/main/java/MissPiggy.java b/firestar/src/main/java/MissPiggy.java index f271a86..66d7e56 100644 --- a/firestar/src/main/java/MissPiggy.java +++ b/firestar/src/main/java/MissPiggy.java @@ -48,7 +48,7 @@ import static java.nio.file.StandardCopyOption.*; import static javax.swing.WindowConstants.EXIT_ON_CLOSE; -public class MissPiggy implements ActionListener { +public class MissPiggy implements Robin, ActionListener { BufferedImage windowIcon; JFrame frame = new JFrame(); JPanel frameContainer; @@ -107,7 +107,7 @@ public class MissPiggy implements ActionListener { toolsMenu.add(new JMenuItem("Edit Metadata")); // disabled if a mod is not selected from the list toolsMenu.add(new JMenuItem("Generate New Mod from Folder...")); - toolsMenu.add(new JMenuItem("Create Soundtrack Mod...")); + //toolsMenu.add(new JMenuItem("Create Soundtrack Mod...")); //toolsMenu.add(new JMenuItem("Download Mod from URL")); // TODO: implement. move option to File menu. should be ez helpMenu.add(new JMenuItem("Manual")); @@ -136,7 +136,7 @@ public class MissPiggy implements ActionListener { fileMenu.getItem(5).addActionListener(this); toolsMenu.getItem(0).addActionListener(this); toolsMenu.getItem(1).addActionListener(this); - toolsMenu.getItem(2).addActionListener(this); + //toolsMenu.getItem(2).addActionListener(this); helpMenu.getItem(0).addActionListener(this); helpMenu.getItem(2).addActionListener(this); helpMenu.getItem(3).addActionListener(this); @@ -315,7 +315,7 @@ public class MissPiggy implements ActionListener { } private void StartErnie() { - new Thread(new Runnable() { + new Thread(new Runnable() { @Override public void run() { new Ernie(frame); // changed away from runnable in order to pass params to constructor -bonk diff --git a/firestar/src/main/java/Robin.java b/firestar/src/main/java/Robin.java new file mode 100644 index 0000000..4995cce --- /dev/null +++ b/firestar/src/main/java/Robin.java @@ -0,0 +1,23 @@ +/* + * Firestar Mod Manager + * Copyright (C) 2024 bonkmaykr + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + */ + +import javax.swing.JFrame; + +public interface Robin { + public JFrame frame = new JFrame(); +} \ No newline at end of file diff --git a/firestar/src/main/java/Scooter.form b/firestar/src/main/java/Scooter.form new file mode 100644 index 0000000..af7effb --- /dev/null +++ b/firestar/src/main/java/Scooter.form @@ -0,0 +1,44 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/firestar/src/main/java/Scooter.java b/firestar/src/main/java/Scooter.java new file mode 100644 index 0000000..2bba401 --- /dev/null +++ b/firestar/src/main/java/Scooter.java @@ -0,0 +1,79 @@ +/* + * Firestar Mod Manager + * Copyright (C) 2024 bonkmaykr + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + */ + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.*; + +public class Scooter { + private JFrame frame = new JFrame(); + public JProgressBar progressBar; + private JPanel frameContainer; + private JLabel label; + + public void showDialog(String title) { + frame.add(frameContainer); + frame.setSize(300, 100); + frame.setTitle(title); + frame.setResizable(false); + frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + frame.setLayout(new GridLayout()); + frame.setLocationRelativeTo(null); + frame.setAlwaysOnTop(true); + frame.setIconImage(Main.windowIcon); + + progressBar.setStringPainted(true); + + frame.setVisible(true); + } + + public void setProgressMin(int i) { + progressBar.setMinimum(i); + } + + public void setProgressValue(int i) { + progressBar.setValue(i); + } + + public void setProgressMax(int i) { + progressBar.setMaximum(i); + } + + public int getProgressMin() { + return progressBar.getMinimum(); + } + + public int getProgressValue() { + return progressBar.getValue(); + } + + public int getProgressMax() { + return progressBar.getMaximum(); + } + + public void setText(String text) { + label.setText(text); + } + + public void destroyDialog() { + frame.setVisible(false); + frame.dispose(); + } +} diff --git a/firestar/src/main/java/Suggs.java b/firestar/src/main/java/Suggs.java index 384a94f..be1ef3a 100644 --- a/firestar/src/main/java/Suggs.java +++ b/firestar/src/main/java/Suggs.java @@ -16,6 +16,12 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + import javax.imageio.ImageIO; import javax.swing.*; import javax.swing.event.ListSelectionEvent; @@ -28,15 +34,20 @@ import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.math.RoundingMode; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.filechooser.FileNameExtensionFilter; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; -public class Suggs implements ActionListener, ListSelectionListener { - private BufferedImage windowIcon; +public class Suggs implements Robin, ActionListener, ListSelectionListener { public JFrame frame = new JFrame(); private JPanel frameContainer; private JList dSongList; @@ -57,7 +68,8 @@ public class Suggs implements ActionListener, ListSelectionListener { private JLabel dSTitle; private JLabel dMTitle; private JCheckBox checkAdditive; - + private Scooter progressDialog; + JFrame parent; int curIndex = -1; @@ -77,16 +89,11 @@ public class Suggs implements ActionListener, ListSelectionListener { this.parent = parent; parent.setEnabled(false); - try { - windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png")); - frame.setIconImage(windowIcon); - } catch (IOException e) { - System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon."); - } + frame.setIconImage(Main.windowIcon); frame.add(frameContainer); // initialize window contents -- will be handled by IntelliJ IDEA frame.setSize(700, 400); - frame.setMinimumSize(new Dimension(700,400)); + frame.setMinimumSize(new Dimension(650,280)); frame.setTitle("Soundtrack Mod Generator"); frame.setResizable(true); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); @@ -249,61 +256,84 @@ public class Suggs implements ActionListener, ListSelectionListener { } } - private JFrame progressFrame = new JFrame(); - public JProgressBar progressBar; - private JPanel progressFrameContainer; - private JLabel progressLabel; - private void save() { - progressFrameContainer = new JPanel(); - - progressLabel = new JLabel("Generating audio files..."); - progressBar = new JProgressBar(); - progressBar.setMaximum(tracklist.size()); - - progressFrameContainer.add(progressLabel); - progressFrameContainer.add(progressBar); - - progressFrame.add(progressFrameContainer); - progressFrame.setSize(300, 100); - progressFrame.setTitle("Soundtrack Mod Generator"); - progressFrame.setResizable(false); - progressFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - progressFrame.setLayout(new GridLayout()); - progressFrame.setLocationRelativeTo(null); - progressFrame.setAlwaysOnTop(true); - progressFrame.setIconImage(windowIcon); - - // Lord, forgive me for this style hell - progressFrameContainer.setBackground(new Color(-15128227)); - progressFrameContainer.setForeground(new Color(-1)); - progressBar.setBackground(new Color(-1)); - progressBar.setForeground(new Color(-2271221)); - progressLabel.setBackground(new Color(-15128227)); - progressLabel.setForeground(new Color(-1)); - - progressFrame.setVisible(true); - - frame.dispose(); - - new File(System.getProperty("user.home") + "/.firestar/temp/audio/music").mkdirs(); - - int i = 0; - for (AudioTrack at : tracklist) { - Process p; - try { - System.out.println("Encoding \"" + at.title + " - " + at.artist + "\"..."); - new File(System.getProperty("user.home") + "/.firestar/temp/audio/music/" + String.format("%02d", i)).mkdirs(); - if (!Main.windows) {p = Runtime.getRuntime().exec(new String[]{"bash","-c","cd " + System.getProperty("user.home") + "/.firestar/temp/" + ";wine ../at9tool.exe -e -br 144 \"" + at.path + "\" audio/music/" + String.format("%02d", i) + "/music_stereo.at9"});} - else {p = Runtime.getRuntime().exec(new String[]{(System.getProperty("user.home") + "\\.firestar\\at9tool.exe"), "-e", "-br", "144", at.path, "audio\\music\\" + String.format("%02d", i) + "\\music_stereo.at9"}, null, new File((System.getProperty("user.home") + "/.firestar/temp/").replace("/", "\\")));} - p.waitFor(); - } catch (IOException | InterruptedException ex) { - Logger.getLogger(Suggs.class.getName()).log(Level.SEVERE, null, ex); + frame.setEnabled(false); + frame.setAlwaysOnTop(false); + Main.deleteDir(new File(System.getProperty("user.home") + "/.firestar/temp/")); // starts with clean temp + new Thread(() -> { + int progressSize = tracklist.size()+(sptrack != null?1:0)+(mptrack != null?1:0)+2; // Accounting for processes + + progressDialog = new Scooter(); + progressDialog.showDialog("Soundtrack Mod Generator"); + progressDialog.setText("Generating audio files..."); + progressDialog.setProgressMax(progressSize); + + new File(System.getProperty("user.home") + "/.firestar/temp/data/audio/music").mkdirs(); + + for (int i = 0; i < tracklist.size(); i++) { + AudioTrack at = tracklist.get(i); + String trackno = String.format("%02d", i); + progressDialog.setText("Encoding track " + (i+1) + " out of " + tracklist.size() + "..."); + try { + System.out.println("Encoding track #" + (i+1) + " \"" + at.title + " - " + at.artist + "\"..."); + new File(System.getProperty("user.home") + "/.firestar/temp/data/audio/music/" + trackno).mkdirs(); + Process p = Main.exec(new String[]{"../at9tool.exe", "-e", "-br", "144", at.path, "data/audio/music/" + trackno + "/music_stereo.at9"}, System.getProperty("user.home") + "/.firestar/temp/"); + p.waitFor(); + } catch (IOException | InterruptedException ex) { + Logger.getLogger(Suggs.class.getName()).log(Level.SEVERE, null, ex); + } + progressDialog.setProgressValue(i); } - progressBar.setValue(i++); - } - System.out.println("Finished encoding."); - progressFrame.dispose(); - parent.setEnabled(true); + if (sptrack != null) { + progressDialog.setText("Encoding singleplayer frontend track..."); + if (new File(sptrack).exists()) { + try { + System.out.println("Encoding singleplayer frontend track..."); + new File(System.getProperty("user.home") + "/.firestar/temp/data/audio/music/FEMusic").mkdirs(); + Process p = Main.exec(new String[]{"../at9tool.exe", "-e", "-br", "144", sptrack, "data/audio/music/FEMusic/frontend_stereo.at9"}, System.getProperty("user.home") + "/.firestar/temp/"); + p.waitFor(); + } catch (IOException | InterruptedException ex) { + Logger.getLogger(Suggs.class.getName()).log(Level.SEVERE, null, ex); + } + } + progressDialog.setProgressValue(progressDialog.getProgressValue()+1); + } + if (mptrack != null) { + progressDialog.setText("Encoding multiplayer frontend track..."); + try { + assert(new File(mptrack).exists()); + System.out.println("Encoding multiplayer frontend track..."); + new File(System.getProperty("user.home") + "/.firestar/temp/data/audio/music/FEDemoMusic").mkdirs(); + Process p = Main.exec(new String[]{"../at9tool.exe", "-e", "-br", "144", mptrack, "data/audio/music/FEDemoMusic/frontend_stereo.at9"}, System.getProperty("user.home") + "/.firestar/temp/"); + p.waitFor(); + } catch (IOException | InterruptedException ex) { + Logger.getLogger(Suggs.class.getName()).log(Level.SEVERE, null, ex); + } + progressDialog.setProgressValue(progressDialog.getProgressValue()+1); + } + System.out.println("Finished encoding."); + + progressDialog.setText("Generating Music Definitions..."); + /* + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + try { + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new File()); + NodeList screen = doc.getElementsByTagName("Screen"); + for (int i = 0; i < tracklist.size(); i++) { + AudioTrack at = tracklist.get(i); + Node node = screen.item(i); + } + } catch (ParserConfigurationException | SAXException | IOException e) { + e.printStackTrace(); + }*/ + progressDialog.setProgressValue(progressDialog.getProgressValue()+1); + + progressDialog.destroyDialog(); + frame.dispose(); + new Clifford().Action(this, new File(System.getProperty("user.home") + "/.firestar/temp/")); + System.out.println("Post Clifford"); + parent.setEnabled(true); + }).start(); } }