Implemented meta editor

This commit is contained in:
Downforce Agent 2024-06-30 17:52:25 -05:00
parent bfb37d74d8
commit 213b8227e1
3 changed files with 224 additions and 4 deletions

93
src/Clifford.form Normal file
View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Clifford">
<grid id="27dc6" binding="frameContainer" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="3294c" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Name"/>
</properties>
</component>
<component id="2e9e" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Author"/>
</properties>
</component>
<component id="e22ba" class="javax.swing.JTextField" binding="fName">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="9a381" class="javax.swing.JTextField" binding="fAuthor">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="c443e" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Version"/>
</properties>
</component>
<component id="d7be8" class="javax.swing.JTextField" binding="fVersion">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="e6d9e" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Description"/>
</properties>
</component>
<component id="4c6b" class="javax.swing.JTextPane" binding="fDescription">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="9d8aa" class="javax.swing.JButton" binding="savebtn">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Save"/>
</properties>
</component>
<component id="8ded9" class="javax.swing.JButton" binding="cancelbtn">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Cancel"/>
</properties>
</component>
</children>
</grid>
</form>

123
src/Clifford.java Normal file
View File

@ -0,0 +1,123 @@
/*
* 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 net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import org.json.JSONObject;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class Clifford implements ActionListener {
private JFrame frame = new JFrame();
private JPanel frameContainer;
private JTextField fName;
private JTextField fAuthor;
private JTextField fVersion;
private JTextPane fDescription;
private JButton savebtn;
private JButton cancelbtn;
MissPiggy invoker;
Main.Mod mod;
int index;
public void Action(MissPiggy inv, int modindex) {
invoker = inv;
mod = Main.Mods.get(modindex);
index = modindex;
frame.add(frameContainer);
frame.setSize(600, 200); // 1280 800
frame.setMinimumSize(new Dimension(200,100));
frame.setTitle("Options");
frame.setResizable(false);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setLayout(new GridLayout());
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
fName.setText(mod.friendlyName);
fAuthor.setText(mod.author);
fVersion.setText(String.valueOf(mod.version));
fDescription.setText(mod.description);
cancelbtn.addActionListener(this);
savebtn.addActionListener(this);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e)
{
invoker.frame.setEnabled(true);
e.getWindow().dispose();
}
});
}
public void Action(MissPiggy inv, File dir) {
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (actionEvent.getSource() == cancelbtn) {
invoker.frame.setEnabled(true);
frame.dispose();
} else
if (actionEvent.getSource() == savebtn) {
try {
mod.version = Integer.parseInt(fVersion.getText());
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(frame, "Mod version must be a valid integer.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
mod.friendlyName = fName.getText();
mod.author = fAuthor.getText();
mod.description = fDescription.getText();
JSONObject container = new JSONObject();
container.put("version", mod.version);
container.put("friendlyName", mod.friendlyName);
container.put("author", mod.author);
container.put("description", mod.description);
container.put("loaderversion", mod.loaderversion);
container.put("game", mod.game);
try {
new ZipFile(System.getProperty("user.home") + "/.firestar/mods/" + mod.path.trim()).setComment(container.toString());
} catch (ZipException e) {
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(frame, "An error has occured.\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
Main.Mods.set(index, mod);
invoker.frame.setEnabled(true);
invoker.InitializeModListInGUI();
frame.dispose();
}
}
}

View File

@ -304,7 +304,7 @@ public class MissPiggy implements ActionListener {
if (actionEvent.getSource() == toggleButton) {toggleSelected(modList.getSelectedIndex());} else if (actionEvent.getSource() == toggleButton) {toggleSelected(modList.getSelectedIndex());} else
if (actionEvent.getSource() == deleteButton1) {deleteSelected();} else if (actionEvent.getSource() == deleteButton1) {deleteSelected();} else
if (actionEvent.getSource() == toolsMenu.getItem(0)) {throwUnimplemented();} else if (actionEvent.getSource() == toolsMenu.getItem(0)) {metaEditorGUI(modList.getSelectedIndex());} else
if (actionEvent.getSource() == toolsMenu.getItem(1)) {throwUnimplemented();} else if (actionEvent.getSource() == toolsMenu.getItem(1)) {throwUnimplemented();} else
if (actionEvent.getSource() == toolsMenu.getItem(2)) {throwUnimplemented();} else if (actionEvent.getSource() == toolsMenu.getItem(2)) {throwUnimplemented();} else
@ -447,9 +447,13 @@ public class MissPiggy implements ActionListener {
throwUnimplemented(); throwUnimplemented();
} }
public void metaEditorGUI() { public void metaEditorGUI(int index) {
// todo tag editor if (index >= 0) {
throwUnimplemented(); new Clifford().Action(this, index);
frame.setEnabled(false);
} else {
JOptionPane.showMessageDialog(frame, "Please select a mod to edit first.", "Error", JOptionPane.ERROR_MESSAGE);
}
} }
private void moveUp(int index) { private void moveUp(int index) {