2024-04-10 03:35:27 -04:00
/ *
* 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/.
* /
2024-04-21 14:37:17 -04:00
import javax.imageio.ImageIO ;
2024-04-10 04:49:21 -04:00
import javax.swing.* ;
2024-04-19 19:06:52 -04:00
import javax.swing.event.ListSelectionListener ;
2024-04-12 00:26:26 -04:00
import java.awt.* ;
2024-04-12 11:21:51 -04:00
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
2024-04-21 14:37:17 -04:00
import java.awt.image.BufferedImage ;
2024-04-19 19:06:52 -04:00
import java.io.File ;
2024-04-21 14:37:17 -04:00
import java.io.IOException ;
2024-04-19 19:06:52 -04:00
import java.math.RoundingMode ;
import java.text.DecimalFormat ;
2024-04-12 11:21:51 -04:00
2024-04-12 00:26:26 -04:00
import static javax.swing.WindowConstants.EXIT_ON_CLOSE ;
2024-04-10 04:49:21 -04:00
2024-04-12 11:21:51 -04:00
public class MissPiggy implements ActionListener {
2024-04-21 14:37:17 -04:00
BufferedImage windowIcon ;
2024-04-12 00:26:26 -04:00
JFrame frame = new JFrame ( ) ;
JPanel frameContainer ;
JPanel actionsContainer ;
JPanel descriptionContainer ;
2024-04-12 11:21:51 -04:00
//JPanel menuBarContainerPanel = new JPanel();
public JMenuBar menuBar ;
public JMenu fileMenu ;
public JMenu toolsMenu ;
public JMenu helpMenu ;
//JMenuItem menuItem;
2024-04-12 00:26:26 -04:00
JScrollPane modListScrollContainer ;
2024-04-19 19:06:52 -04:00
public JList < String > modList ;
2024-04-12 00:26:26 -04:00
private JButton toggleButton ;
private JButton moveUpButton ;
private JButton deleteButton1 ;
private JButton moveDownButton ;
private JButton optionsButton ;
private JButton importButton ;
2024-04-12 11:21:51 -04:00
private JButton deployButton ;
2024-04-19 19:06:52 -04:00
private JTextPane descriptionField ;
2024-04-12 00:26:26 -04:00
private int selectedItem ;
// Initialize the main window
public void Action ( /*Main entryPoint*/ ) {
/// DEBUG ///
2024-04-19 19:06:52 -04:00
Main . Mod testModEntry = new Main ( ) . new Mod ( ) ; //this is retarded? we're making a new object of a certain type, why the fuck do you care where it comes from? static or regardless??
testModEntry . friendlyName = " Example Mod 1 " ;
2024-04-12 00:26:26 -04:00
testModEntry . game = " 2048 " ;
2024-04-19 19:06:52 -04:00
testModEntry . path = " /home/bonkyboo/madarao_sneaky2_square.png " ; //used to test file sizes
2024-04-12 00:26:26 -04:00
testModEntry . version = 1 ;
2024-04-19 19:06:52 -04:00
//testModEntry.priority = 0; //will discard this in favor of the list index for simplicity
2024-04-12 00:26:26 -04:00
Main . Mods . add ( testModEntry ) ;
2024-04-19 19:06:52 -04:00
Main . Mod testModEntry2 = new Main ( ) . new Mod ( ) ;
testModEntry2 . friendlyName = " Example Mod 2 " ;
testModEntry2 . author = " Daniel Chang " ;
testModEntry2 . game = " 2048 " ;
testModEntry2 . path = " /home/bonkyboo/chengou.mp4 " ;
testModEntry2 . version = 1 ;
testModEntry2 . loaderversion = 0 ;
Main . Mods . add ( testModEntry2 ) ;
Main . Mod testModEntry3 = new Main ( ) . new Mod ( ) ;
testModEntry3 . friendlyName = " Example Mod 3 " ;
testModEntry3 . author = " John Dekka " ;
testModEntry3 . game = " 2048 " ;
testModEntry3 . path = " /home/bonkyboo/round2.mp4 " ;
testModEntry3 . version = 1 ;
testModEntry3 . loaderversion = 0 ;
Main . Mods . add ( testModEntry3 ) ;
2024-04-12 00:26:26 -04:00
///-/////-///
2024-04-12 11:21:51 -04:00
// populate menu bar
menuBar = new JMenuBar ( ) ;
fileMenu = new JMenu ( " File " ) ;
toolsMenu = new JMenu ( " Tools " ) ;
helpMenu = new JMenu ( " Help " ) ;
fileMenu . add ( new JMenuItem ( " Deploy All Mods " ) ) ;
fileMenu . add ( new JMenuItem ( " Import Mod... " ) ) ;
fileMenu . add ( new JMenuItem ( " Remove All " ) ) ;
fileMenu . add ( new JSeparator ( ) ) ;
fileMenu . add ( new JMenuItem ( " Options " ) ) ;
fileMenu . add ( new JMenuItem ( " Quit " ) ) ;
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... " ) ) ;
helpMenu . add ( new JMenuItem ( " About Firestar " ) ) ;
menuBar . add ( fileMenu ) ;
menuBar . add ( toolsMenu ) ;
menuBar . add ( helpMenu ) ;
menuBar . setVisible ( true ) ;
frame . setJMenuBar ( menuBar ) ;
2024-04-12 00:26:26 -04:00
frame . add ( frameContainer ) ; // initialize window contents -- will be handled by IntelliJ IDEA
2024-04-12 11:21:51 -04:00
InitializeModListInGUI ( ) ; // present mod list
2024-04-12 11:31:38 -04:00
fileMenu . getItem ( 0 ) . addActionListener ( this ) ;
fileMenu . getItem ( 1 ) . addActionListener ( this ) ;
fileMenu . getItem ( 2 ) . addActionListener ( this ) ;
fileMenu . getItem ( 4 ) . addActionListener ( this ) ;
2024-04-12 11:21:51 -04:00
fileMenu . getItem ( 5 ) . addActionListener ( this ) ;
2024-04-12 11:31:38 -04:00
toolsMenu . getItem ( 0 ) . addActionListener ( this ) ;
toolsMenu . getItem ( 1 ) . addActionListener ( this ) ;
helpMenu . getItem ( 0 ) . addActionListener ( this ) ;
2024-04-12 11:21:51 -04:00
2024-04-19 19:06:52 -04:00
descriptionField . getDocument ( ) . putProperty ( " filterNewlines " , Boolean . FALSE ) ;
modList . addListSelectionListener ( e - > {
String authorDisplay ;
File pathReference = new File ( Main . Mods . get ( modList . getSelectedIndex ( ) ) . path ) ;
DecimalFormat df = new DecimalFormat ( " ##.## " ) ;
df . setRoundingMode ( RoundingMode . UP ) ;
float modFileSize = pathReference . length ( ) ; //precise units
String modFileSizeStr = String . valueOf ( modFileSize ) ;
String modFileSizeUnits = " bytes " ;
if ( pathReference . length ( ) > = 1024 ) {
modFileSizeStr = String . valueOf ( df . format ( modFileSize / 1024 ) ) ;
modFileSizeUnits = " Kilobytes " ;
}
if ( pathReference . length ( ) > = 1024 * 1024 ) {
modFileSizeStr = String . valueOf ( df . format ( modFileSize / ( 1024 * 1024 ) ) ) ;
modFileSizeUnits = " Megabytes " ;
}
if ( pathReference . length ( ) > = 1024 * 1024 * 1024 ) {
modFileSizeStr = String . valueOf ( df . format ( modFileSize / ( 1024 * 1024 * 1024 ) ) ) ;
modFileSizeUnits = " Gigabytes " ;
}
if ( Main . Mods . get ( modList . getSelectedIndex ( ) ) . author = = null ) {
authorDisplay = " an Unknown Author " ;
} else {
authorDisplay = Main . Mods . get ( modList . getSelectedIndex ( ) ) . author ;
}
descriptionField . setText (
" \" " + Main . Mods . get ( modList . getSelectedIndex ( ) ) . friendlyName + " \" \ n " +
" by " + authorDisplay + " \ n \ n " +
" Version " + Main . Mods . get ( modList . getSelectedIndex ( ) ) . version + " \ n " +
modFileSizeStr + " " + modFileSizeUnits + " in size "
) ; } ) ;
2024-04-12 11:21:51 -04:00
// display window
2024-04-21 14:37:17 -04:00
try {
windowIcon = ImageIO . read ( new File ( System . getProperty ( " user.dir " ) + " /resources/titleIcon.png " ) ) ;
frame . setIconImage ( windowIcon ) ;
} catch ( IOException e ) {
System . out . println ( " ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon. " ) ;
}
2024-04-12 00:26:26 -04:00
frame . setSize ( 800 , 600 ) ; // 1280 800
2024-04-19 19:06:52 -04:00
frame . setMinimumSize ( new Dimension ( 640 , 480 ) ) ;
2024-04-12 00:26:26 -04:00
frame . setTitle ( " Firestar Mod Manager " ) ;
frame . setResizable ( true ) ;
frame . setDefaultCloseOperation ( EXIT_ON_CLOSE ) ;
frame . setLayout ( new GridLayout ( ) ) ;
2024-04-13 11:04:35 -04:00
frame . setLocationRelativeTo ( null ) ;
2024-04-12 00:26:26 -04:00
frame . setVisible ( true ) ;
}
public void InitializeModListInGUI ( ) { // i really wanted this to be "lights, camera, action" but the code organizing kept getting stupider and stupider so i gave up
// cleanup
2024-04-19 19:06:52 -04:00
descriptionField . setText ( " Select a mod from the list on the right to view more details, or to make changes to your installation. " ) ;
2024-04-12 00:26:26 -04:00
modList . clearSelection ( ) ;
modList . removeAll ( ) ;
2024-04-19 18:00:20 -04:00
modList . setVisibleRowCount ( Main . Mods . size ( ) ) ;
modList . setSelectionMode ( ListSelectionModel . SINGLE_SELECTION ) ;
2024-04-12 00:26:26 -04:00
// add text entry for each
int i = 0 ;
2024-04-19 18:00:20 -04:00
/*JLabel[]*/ String [ ] contents = new String [ Main . Mods . size ( ) ] ;
2024-04-21 14:37:17 -04:00
System . out . println ( " Initializing modList to GUI with length of " + Main . Mods . size ( ) + " units " ) ; //debug
2024-04-12 00:26:26 -04:00
while ( i < Main . Mods . size ( ) ) {
2024-04-19 18:00:20 -04:00
contents [ i ] = Main . Mods . get ( i ) . friendlyName ;
2024-04-12 00:26:26 -04:00
//debug
2024-04-19 19:06:52 -04:00
String authorDisplay ;
if ( Main . Mods . get ( i ) . author = = null ) { authorDisplay = " Anonymous " ; } else { authorDisplay = " \" " + Main . Mods . get ( i ) . author + " \" " ; }
System . out . println ( " Added " + Main . Mods . get ( i ) . friendlyName + " by " + authorDisplay ) ;
2024-04-10 04:49:21 -04:00
2024-04-12 00:26:26 -04:00
i + + ;
}
2024-04-19 18:00:20 -04:00
modList . setListData ( contents ) ;
2024-04-10 03:35:27 -04:00
}
2024-04-12 11:21:51 -04:00
2024-04-19 19:06:52 -04:00
private ListSelectionListener whenItemSelected ( ) {
return null ;
}
2024-04-12 11:21:51 -04:00
@Override
public void actionPerformed ( ActionEvent actionEvent ) {
2024-04-12 11:31:38 -04:00
if ( actionEvent . getSource ( ) = = fileMenu . getItem ( 5 ) ) { System . exit ( 0 ) ; } else
if ( actionEvent . getSource ( ) = = fileMenu . getItem ( 0 ) ) { deployModGUI ( ) ; } else
if ( actionEvent . getSource ( ) = = fileMenu . getItem ( 1 ) ) { importModGUI ( ) ; } else
if ( actionEvent . getSource ( ) = = fileMenu . getItem ( 2 ) ) { removeAllGUI ( ) ; } else
2024-04-13 11:04:35 -04:00
if ( actionEvent . getSource ( ) = = fileMenu . getItem ( 4 ) ) { optionsGUI ( ) ; } else
if ( actionEvent . getSource ( ) = = helpMenu . getItem ( 0 ) ) { new Rowlf ( ) . displayAboutScreen ( ) ; }
2024-04-12 11:31:38 -04:00
}
// Will likely split the below functions into separate classes to work with intellij GUI designer.
public void deployModGUI ( ) {
// todo dialog that monitors psarc progress, handles file transfers, etc
// could prevent closing program during this process? (may also be unnecessary)
}
public void importModGUI ( ) {
// todo call system shell to request file picker
}
public void removeAllGUI ( ) {
// todo warning dialog that nukes list when Yes is clicked
}
public void optionsGUI ( ) {
// todo settings page w/ reset switch
}
public void generatorGUI ( ) {
// todo mod packer
}
public void metaEditorGUI ( ) {
// todo tag editor
}
public void aboutGUI ( ) {
// todo about page
2024-04-12 11:21:51 -04:00
}
2024-04-10 03:35:27 -04:00
}