Implement settings menu

This commit is contained in:
Downforce Agent 2024-06-30 09:51:03 -05:00
parent d839687040
commit 81350dd06b
3 changed files with 180 additions and 2 deletions

View File

@ -410,8 +410,8 @@ public class MissPiggy implements ActionListener {
}
public void optionsGUI() {
// todo settings page w/ reset switch
throwUnimplemented();
new Waldorf().Action(this);
frame.setEnabled(false);
}
public void deleteSelected() {

74
src/Waldorf.form Normal file
View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Waldorf">
<grid id="27dc6" binding="frameContainer" layout-manager="GridLayoutManager" row-count="5" column-count="3" 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>
<maximumSize width="50" height="100"/>
<minimumSize width="50" height="100"/>
<preferredSize width="50" height="100"/>
</properties>
<border type="none"/>
<children>
<component id="3d88f" class="javax.swing.JButton" binding="okbtn">
<constraints>
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Save"/>
</properties>
</component>
<component id="86775" class="javax.swing.JTextField" binding="fOutpath">
<constraints>
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="db731" 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="Mod Export Path"/>
</properties>
</component>
<component id="50d13" class="javax.swing.JButton" binding="cancelbtn">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Cancel"/>
</properties>
</component>
<component id="252b3" class="javax.swing.JButton" binding="resetbtn">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Restore Defaults"/>
</properties>
</component>
<component id="e2cd7" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=".firestar Folder"/>
</properties>
</component>
<component id="c68f2" class="javax.swing.JButton" binding="bOpenFolder">
<constraints>
<grid row="0" column="1" row-span="3" col-span="2" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<label value="Browse"/>
<text value="Browse"/>
</properties>
</component>
</children>
</grid>
</form>

104
src/Waldorf.java Normal file
View File

@ -0,0 +1,104 @@
/*
* 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 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 java.io.IOException;
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
public class Waldorf implements ActionListener {
private JFrame frame = new JFrame();
private JPanel frameContainer;
private JButton okbtn;
private JButton cancelbtn;
private JTextField fOutpath;
private JButton resetbtn;
private JButton bOpenFolder;
MissPiggy invoker;
public void Action(MissPiggy inv) {
invoker = inv;
frame.add(frameContainer);
frame.setSize(600, 200); // 1280 800
frame.setMinimumSize(new Dimension(200,100));
frame.setTitle("Options");
frame.setResizable(false);
frame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
frame.setLayout(new GridLayout());
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
cancelbtn.addActionListener(this);
okbtn.addActionListener(this);
resetbtn.addActionListener(this);
bOpenFolder.addActionListener(this);
fOutpath.setText(Main.outpath);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e)
{
invoker.frame.setEnabled(true);
e.getWindow().dispose();
}
});
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (actionEvent.getSource() == cancelbtn) {
invoker.frame.setEnabled(true);
frame.dispose();
} else
if (actionEvent.getSource() == okbtn) {
Main.outpath = fOutpath.getText();
Main.writeConf();
invoker.frame.setEnabled(true);
frame.dispose();
} else
if (actionEvent.getSource() == resetbtn) {
int result = JOptionPane.showConfirmDialog(frame,"Are you sure you want to redo the initial setup?", "Restore Default Settings", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
new File(System.getProperty("user.home") + "/.firestar/firestar.conf").delete();
int result2 = JOptionPane.showConfirmDialog(frame,"Firestar will now close.", "Restore Default Settings", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
if (result2 == JOptionPane.OK_OPTION) {
System.exit(0);
}
}
} else
if (actionEvent.getSource() == bOpenFolder) {
try {
Desktop.getDesktop().open(new File(Main.inpath));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}