diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb1b997 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.classpath +.metadata +.project +bin +libs diff --git a/src/main/java/glowredman/mmcc/Main.java b/src/main/java/glowredman/mmcc/Main.java new file mode 100644 index 0000000..77d643f --- /dev/null +++ b/src/main/java/glowredman/mmcc/Main.java @@ -0,0 +1,157 @@ +package glowredman.mmcc; + +import java.awt.Desktop; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.io.File; +import java.net.URI; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.KeyStroke; +import javax.swing.UIManager; + +import glowredman.mmcc.panels.MaterialPanel; +import glowredman.mmcc.panels.TopPanel; +import glowredman.mmcc.panels.TypePanel; +import glowredman.mmcc.panels.VariantPanel; +import glowredman.mmcc.panels.VeinPanel; +import glowredman.modularmaterials.data.object.MM_Material; +import glowredman.modularmaterials.data.object.MM_OreVariant; +import glowredman.modularmaterials.data.object.MM_OreVein; +import glowredman.modularmaterials.data.object.MM_Type; + +public class Main extends JFrame { + + private static final long serialVersionUID = -1962144914785470334L; + private File configDir; + private JButton openButton; + private JProgressBar progress; + private TopPanel materialsPanel; + private TopPanel typesPanel; + private TopPanel variantsPanel; + private TopPanel veinsPanel; + + public Main() { + //frame setup + super("Modular Materials Config Creator"); + this.setDefaultCloseOperation(EXIT_ON_CLOSE); + this.setLayout(new GridBagLayout()); + this.setResizable(false); + + GridBagConstraints cst = new GridBagConstraints(); + + // --- MATERIALS --- + materialsPanel = new MaterialPanel(); + cst.gridx = 0; + cst.gridy = 0; + this.add(materialsPanel, cst); + + // --- TYPES --- + typesPanel = new TypePanel(); + cst.gridx = 1; + this.add(typesPanel, cst); + + // --- VARIANTS --- + variantsPanel = new VariantPanel(); + cst.gridx = 2; + this.add(variantsPanel, cst); + + // --- VEINS --- + veinsPanel = new VeinPanel(); + cst.gridx = 3; + this.add(veinsPanel, cst); + + // --- BOTTOM --- + JPanel bottomPanel = new JPanel(); + + progress = new JProgressBar(0, 4); + progress.setPreferredSize(new Dimension(340, 23)); + bottomPanel.add(progress); + + JButton helpButton = new JButton("Help"); + helpButton.addActionListener(this::help); + bottomPanel.add(helpButton); + + openButton = new JButton("Open Config Folder"); + openButton.addActionListener(this::open); + bottomPanel.add(openButton); + + JButton saveButton = new JButton("Save"); + saveButton.addActionListener(this::save); + bottomPanel.add(saveButton); + + cst.gridwidth = 4; + cst.gridx = 0; + cst.gridy = 1; + this.add(bottomPanel, cst); + + //keybindings + this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) + .put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK), "save"); + this.getRootPane().getActionMap().put("save", new MethodAction(this::save)); + this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) + .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK), "open"); + this.getRootPane().getActionMap().put("open", new MethodAction(this::open)); + + //pack & show frame + this.pack(); + this.setVisible(true); + } + + private void help(ActionEvent e) { + try { + Desktop.getDesktop().browse(new URI("https://github.com/glowredman/modularmaterials/wiki/Modular-Materials-Config-Creator")); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private void open(ActionEvent e) { + JFileChooser fc = new JFileChooser(); + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + if(fc.showOpenDialog(openButton) == JFileChooser.APPROVE_OPTION) { + configDir = fc.getSelectedFile(); + new File(configDir, "mmcc_backup").mkdir(); + materialsPanel.read(configDir); + typesPanel.read(configDir); + variantsPanel.read(configDir); + veinsPanel.read(configDir); + } + } + + private void save(ActionEvent e) { + if(configDir == null) return; + String now = String.format("%1$tF_%1$tH.%1$tM.%1$tS", System.currentTimeMillis()); + progress.setValue(0); + materialsPanel.write(configDir, now); + progress.setValue(1); + typesPanel.write(configDir, now); + progress.setValue(2); + variantsPanel.write(configDir, now); + progress.setValue(3); + veinsPanel.write(configDir, now); + progress.setValue(4); + } + + public static void main(String[] args) { + EventQueue.invokeLater(() -> { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + new Main(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } + +} diff --git a/src/main/java/glowredman/mmcc/MethodAction.java b/src/main/java/glowredman/mmcc/MethodAction.java new file mode 100644 index 0000000..dfe0ba0 --- /dev/null +++ b/src/main/java/glowredman/mmcc/MethodAction.java @@ -0,0 +1,23 @@ +package glowredman.mmcc; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.AbstractAction; + +public class MethodAction extends AbstractAction { + + private ActionListener action; + + public MethodAction(ActionListener action) { + this.action = action; + } + + @Override + public void actionPerformed(ActionEvent e) { + action.actionPerformed(e); + } + + private static final long serialVersionUID = 6608068217528825813L; + +} diff --git a/src/main/java/glowredman/mmcc/frames/Editor.java b/src/main/java/glowredman/mmcc/frames/Editor.java new file mode 100644 index 0000000..11d568a --- /dev/null +++ b/src/main/java/glowredman/mmcc/frames/Editor.java @@ -0,0 +1,111 @@ +package glowredman.mmcc.frames; + +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.KeyStroke; + +import glowredman.mmcc.MethodAction; +import glowredman.mmcc.panels.TopPanel; + +public abstract class Editor extends JFrame implements WindowListener { + + private static final long serialVersionUID = 9104601877871319607L; + public String identifier; + protected T object; + private T clipboard; + protected final TopPanel parent; + + public Editor(TopPanel parent) { + this.parent = parent; + this.addWindowListener(this); + this.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK), "copy"); + this.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK), "paste"); + this.getRootPane().getActionMap().put("copy", new MethodAction(this::copy)); + this.getRootPane().getActionMap().put("paste", new MethodAction(this::paste)); + } + + @Override + public void windowClosing(WindowEvent e) { + parent.unlock(); + } + + private void copy(ActionEvent e) { + clipboard = object; + } + + private void paste(ActionEvent e) { + setObject(clipboard); + } + + protected void cancel(ActionEvent e) { + parent.unlock(); + this.setVisible(false); + } + + protected abstract void save(ActionEvent e); + + public abstract void setObject(T o); + + // --- Helper methods --- + + public static String listAsString(List l) { + if (l.size() == 0) { + return ""; + } + String s = l.get(0); + for (int i = 1; i < l.size(); i++) { + s += "\n" + l.get(i); + } + return s; + } + + public static List stringAsList(String s) { + if(s.isEmpty()) { + return new ArrayList<>(); + } else { + return Arrays.asList(s.split("\n")); + } + } + + public static String arrayAsString(String[] a) { + if (a.length == 0) { + return ""; + } + String s = a[0]; + for (int i = 1; i < a.length; i++) { + s += "\n" + a[i]; + } + return s; + } + + public static String[] stringAsArray(String s) { + return s.split("\n"); + } + + @Override + public void windowOpened(WindowEvent e) {} + + @Override + public void windowClosed(WindowEvent e) {} + + @Override + public void windowIconified(WindowEvent e) {} + + @Override + public void windowDeiconified(WindowEvent e) {} + + @Override + public void windowActivated(WindowEvent e) {} + + @Override + public void windowDeactivated(WindowEvent e) {} + +} diff --git a/src/main/java/glowredman/mmcc/frames/MaterialEditor.java b/src/main/java/glowredman/mmcc/frames/MaterialEditor.java new file mode 100644 index 0000000..d31a4f1 --- /dev/null +++ b/src/main/java/glowredman/mmcc/frames/MaterialEditor.java @@ -0,0 +1,641 @@ +package glowredman.mmcc.frames; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JColorChooser; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import glowredman.mmcc.panels.IdentifierPanel; +import glowredman.mmcc.panels.LabeledComboBox; +import glowredman.mmcc.panels.LabeledTextField; +import glowredman.mmcc.panels.TagsPanel; +import glowredman.mmcc.panels.TopPanel; +import glowredman.modularmaterials.data.object.MM_Material; +import glowredman.modularmaterials.data.object.sub.AdvRarity; +import glowredman.modularmaterials.data.object.sub.ChemicalState; + +public class MaterialEditor extends Editor { + + private static final long serialVersionUID = -9095933751519104032L; + //first column + private IdentifierPanel enabled_identifier; + private LabeledTextField name; + private LabeledTextField burnTime; + private LabeledTextField enchantPower; + private LabeledTextField fireSpread; + private LabeledTextField flammability; + private LabeledTextField jumpFactor; + private LabeledTextField lightLevel; + private LabeledTextField resistance; + private LabeledTextField speedFactor; + private LabeledTextField texture; + private LabeledComboBox state; + private JButton color; + private JTextArea tagNames; + private JTextArea enabledTypes; + //second column + private LabeledTextField oFriction; + private LabeledTextField oHardness; + private LabeledTextField oJumpFactor; + private LabeledTextField oLightLevel; + private LabeledTextField oResistance; + private LabeledTextField oSpeedFactor; + private JCheckBox oRequiresTool; + private LabeledTextField oMapColor; + private LabeledTextField oMaterial; + private LabeledTextField oSound; + private TagsPanel oTags; + private JButton tBackground; + private JButton tBorderStart; + private JButton tBorderEnd; + private JTextArea tText; + //third column + private LabeledTextField bHardness; + private LabeledTextField bFriction; + private LabeledTextField bMapColor; + private LabeledTextField bMaterial; + private LabeledTextField bSound; + private JCheckBox bRequiresTool; + private JCheckBox bSticky; + private TagsPanel bTags; + private LabeledTextField iLifespan; + private JCheckBox iFireResistant; + private JCheckBox iFoil; + private LabeledComboBox iRarity; + private TagsPanel iTags; + //Fourth column + private LabeledTextField fBoilingTemp; + private LabeledTextField fMeltingTemp; + private LabeledTextField fCurrentTemp; + private LabeledTextField gDensity; + private LabeledTextField gViscosity; + private LabeledTextField gLuminosity; + private JCheckBox gPropagatesSkylightDown; + private JCheckBox gPathfindable; + private LabeledTextField lDensity; + private LabeledTextField lViscosity; + private LabeledTextField lLuminosity; + private JCheckBox lPropagatesSkylightDown; + private JCheckBox lPathfindable; + private TagsPanel fTags; + + public MaterialEditor(TopPanel parent) { + super(parent); + this.setTitle("Edit materials.json Entry"); + this.setResizable(false); + this.setLayout(new GridBagLayout()); + + GridBagConstraints cst = new GridBagConstraints(); + + //First Column + enabled_identifier = new IdentifierPanel(); + cst.anchor = GridBagConstraints.NORTHWEST; + cst.gridx = 0; + cst.gridy = 0; + this.add(enabled_identifier, cst); + + name = new LabeledTextField("Name"); + cst.gridy = 1; + this.add(name, cst); + + burnTime = new LabeledTextField("Burn Time"); + cst.gridy = 2; + this.add(burnTime, cst); + + enchantPower = new LabeledTextField("Enchantment Power Bonus"); + cst.gridy = 3; + this.add(enchantPower, cst); + + fireSpread = new LabeledTextField("Fire Spread Speed"); + cst.gridy = 4; + this.add(fireSpread, cst); + + flammability = new LabeledTextField("Flammability"); + cst.gridy = 5; + this.add(flammability, cst); + + jumpFactor = new LabeledTextField("Jump Factor"); + cst.gridy = 6; + this.add(jumpFactor, cst); + + lightLevel = new LabeledTextField("Light Level"); + cst.gridy = 7; + this.add(lightLevel, cst); + + resistance = new LabeledTextField("Blast Resistance"); + cst.gridy = 8; + this.add(resistance, cst); + + speedFactor = new LabeledTextField("Speed Factor"); + cst.gridy = 9; + this.add(speedFactor, cst); + + texture = new LabeledTextField("Texture"); + cst.gridy = 10; + this.add(texture, cst); + + state = new LabeledComboBox<>("State", ChemicalState.values()); + cst.gridy = 11; + this.add(state, cst); + + color = new JButton("Color"); + color.addActionListener(this::color); + cst.anchor = GridBagConstraints.CENTER; + cst.gridy = 12; + this.add(color, cst); + + tagNames = new JTextArea(); + JScrollPane tagNamesPanel = new JScrollPane(tagNames); + tagNamesPanel.setBorder(BorderFactory.createTitledBorder("Tag Names")); + tagNamesPanel.setMinimumSize(new Dimension(250, 100)); + tagNamesPanel.setPreferredSize(new Dimension(250, 100)); + tagNamesPanel.setMaximumSize(new Dimension(250, 100)); + cst.anchor = GridBagConstraints.NORTHWEST; + cst.gridy = 13; + this.add(tagNamesPanel, cst); + + enabledTypes = new JTextArea(); + JScrollPane enabledTypesPanel = new JScrollPane(enabledTypes); + enabledTypesPanel.setBorder(BorderFactory.createTitledBorder("Enabled Types")); + enabledTypesPanel.setMinimumSize(new Dimension(250, 300)); + enabledTypesPanel.setPreferredSize(new Dimension(250, 300)); + enabledTypesPanel.setMaximumSize(new Dimension(250, 300)); + cst.gridy = 14; + this.add(enabledTypesPanel, cst); + + //Second column + JPanel oreProps = new JPanel(); + GridBagConstraints oCst = new GridBagConstraints(); + oreProps.setBorder(BorderFactory.createTitledBorder("Ore Properties")); + oreProps.setLayout(new GridBagLayout()); + + oFriction = new LabeledTextField("Friction"); + oCst.anchor = GridBagConstraints.NORTHWEST; + oCst.gridx = 0; + oCst.gridy = 0; + oreProps.add(oFriction, oCst); + + oHardness = new LabeledTextField("Hardness"); + oCst.gridy = 1; + oreProps.add(oHardness, oCst); + + oJumpFactor = new LabeledTextField("Jump Factor"); + oCst.gridy = 2; + oreProps.add(oJumpFactor, oCst); + + oLightLevel = new LabeledTextField("Light Level"); + oCst.gridy = 3; + oreProps.add(oLightLevel, oCst); + + oResistance = new LabeledTextField("Blast Resistance"); + oCst.gridy = 4; + oreProps.add(oResistance, oCst); + + oSpeedFactor = new LabeledTextField("Speed Factor"); + oCst.gridy = 5; + oreProps.add(oSpeedFactor, oCst); + + oMapColor = new LabeledTextField("Map Color"); + oCst.gridy = 6; + oreProps.add(oMapColor, oCst); + + oMaterial = new LabeledTextField("Material"); + oCst.gridy = 7; + oreProps.add(oMaterial, oCst); + + oSound = new LabeledTextField("Sound type"); + oCst.gridy = 8; + oreProps.add(oSound, oCst); + + oRequiresTool = new JCheckBox("Requires Tool For Drops"); + oCst.gridy = 9; + oreProps.add(oRequiresTool, oCst); + + oTags = new TagsPanel(); + oTags.setMinimumSize(new Dimension(250, 173)); + oTags.setPreferredSize(new Dimension(250, 173)); + oTags.setMaximumSize(new Dimension(250, 173)); + oCst.gridy = 10; + oreProps.add(oTags, oCst); + + cst.gridx = 1; + cst.gridy = 0; + cst.gridheight = 14; + this.add(oreProps, cst); + + JPanel ttProps = new JPanel(); + GridBagConstraints tCst = new GridBagConstraints(); + ttProps.setBorder(BorderFactory.createTitledBorder("Tooltip Properties")); + ttProps.setLayout(new GridBagLayout()); + + tBackground = new JButton("Background"); + tBackground.addActionListener(this::background); + tCst.anchor = GridBagConstraints.NORTH; + tCst.gridx = 0; + tCst.gridy = 0; + ttProps.add(tBackground, tCst); + + tBorderStart = new JButton("Border Start"); + tBorderStart.addActionListener(this::borderStart); + tCst.gridy = 1; + ttProps.add(tBorderStart, tCst); + + tBorderEnd = new JButton("Border End"); + tBorderEnd.addActionListener(this::borderEnd); + tCst.gridy = 2; + ttProps.add(tBorderEnd, tCst); + + tText = new JTextArea(); + JScrollPane textPane = new JScrollPane(tText); + textPane.setBorder(BorderFactory.createTitledBorder("Text")); + textPane.setMinimumSize(new Dimension(250, 209)); + textPane.setPreferredSize(new Dimension(250, 209)); + textPane.setMaximumSize(new Dimension(250, 209)); + tCst.gridy = 3; + ttProps.add(textPane, tCst); + + cst.gridx = 1; + cst.gridy = 14; + cst.gridheight = 1; + this.add(ttProps, cst); + + //Third column + JPanel bProps = new JPanel(); + GridBagConstraints bCst = new GridBagConstraints(); + bProps.setBorder(BorderFactory.createTitledBorder("Block Properties")); + bProps.setLayout(new GridBagLayout()); + + bHardness = new LabeledTextField("Hardness"); + bCst.anchor = GridBagConstraints.NORTHWEST; + bCst.gridx = 0; + bCst.gridy = 0; + bProps.add(bHardness, bCst); + + bFriction = new LabeledTextField("Friction"); + bCst.gridy = 1; + bProps.add(bFriction, bCst); + + bMapColor = new LabeledTextField("Map Color"); + bCst.gridy = 2; + bProps.add(bMapColor, bCst); + + bMaterial = new LabeledTextField("Material"); + bCst.gridy = 3; + bProps.add(bMaterial, bCst); + + bSound = new LabeledTextField("Sound Type"); + bCst.gridy = 4; + bProps.add(bSound, bCst); + + bRequiresTool = new JCheckBox("Requires Tool For Drops"); + bCst.gridy = 5; + bProps.add(bRequiresTool, bCst); + + bSticky = new JCheckBox("Sticky"); + bCst.gridy = 6; + bProps.add(bSticky, bCst); + + bTags = new TagsPanel(); + bTags.setMinimumSize(new Dimension(250, 170)); + bTags.setPreferredSize(new Dimension(250, 170)); + bTags.setMaximumSize(new Dimension(250, 170)); + bCst.gridy = 7; + bProps.add(bTags, bCst); + + cst.gridx = 2; + cst.gridy = 0; + cst.gridheight = 13; + this.add(bProps, cst); + + JPanel iProps = new JPanel(); + GridBagConstraints iCst = new GridBagConstraints(); + iProps.setBorder(BorderFactory.createTitledBorder("Item Properties")); + iProps.setLayout(new GridBagLayout()); + + iLifespan = new LabeledTextField("Lifespan"); + iCst.anchor = GridBagConstraints.NORTHWEST; + iCst.gridx = 0; + iCst.gridy = 0; + iProps.add(iLifespan, iCst); + + iFireResistant = new JCheckBox("Fire Resistant"); + iCst.gridy = 1; + iProps.add(iFireResistant, iCst); + + iFoil = new JCheckBox("Holographic"); + iCst.gridy = 2; + iProps.add(iFoil, iCst); + + iRarity = new LabeledComboBox<>("Rarity", AdvRarity.values()); + iCst.gridy = 3; + iProps.add(iRarity, iCst); + + iTags = new TagsPanel(); + iTags.setMinimumSize(new Dimension(250, 271)); + iTags.setPreferredSize(new Dimension(250, 271)); + iTags.setMaximumSize(new Dimension(250, 271)); + iCst.gridy = 4; + iProps.add(iTags, iCst); + + cst.gridx = 2; + cst.gridy = 13; + cst.gridheight = 2; + this.add(iProps, cst); + + //Fourth column + JPanel panel4 = new JPanel(); + GridBagConstraints cst4 = new GridBagConstraints(); + panel4.setLayout(new GridBagLayout()); + + JPanel fProps = new JPanel(); + GridBagConstraints fCst = new GridBagConstraints(); + fProps.setBorder(BorderFactory.createTitledBorder("Fluid Properties")); + fProps.setLayout(new GridBagLayout()); + + fBoilingTemp = new LabeledTextField("Boiling Temperature"); + fCst.anchor = GridBagConstraints.NORTHWEST; + fCst.gridx = 0; + fCst.gridy = 0; + fProps.add(fBoilingTemp, fCst); + + fMeltingTemp = new LabeledTextField("Melting Temperature"); + fCst.gridy = 1; + fProps.add(fMeltingTemp, fCst); + + fCurrentTemp = new LabeledTextField("Current Temperature"); + fCst.gridy = 2; + fProps.add(fCurrentTemp, fCst); + + JPanel gProps = new JPanel(); + GridBagConstraints gCst = new GridBagConstraints(); + gProps.setBorder(BorderFactory.createTitledBorder("Gas Properties")); + gProps.setLayout(new GridBagLayout()); + + gDensity = new LabeledTextField("Density"); + gCst.anchor = GridBagConstraints.NORTHWEST; + gCst.gridx = 0; + gCst.gridy = 0; + gProps.add(gDensity, gCst); + + gViscosity = new LabeledTextField("Viscosity"); + gCst.gridy = 1; + gProps.add(gViscosity, gCst); + + gLuminosity = new LabeledTextField("Light Level"); + gCst.gridy = 2; + gProps.add(gLuminosity, gCst); + + gPropagatesSkylightDown = new JCheckBox("Propagates Skylight Down"); + gCst.gridy = 3; + gProps.add(gPropagatesSkylightDown, gCst); + + gPathfindable = new JCheckBox("Pathfindable"); + gCst.gridy = 4; + gProps.add(gPathfindable, gCst); + + fCst.gridy = 3; + fProps.add(gProps, fCst); + + JPanel lProps = new JPanel(); + GridBagConstraints lCst = new GridBagConstraints(); + lProps.setBorder(BorderFactory.createTitledBorder("Liquid Properties")); + lProps.setLayout(new GridBagLayout()); + + lDensity = new LabeledTextField("Density"); + lCst.anchor = GridBagConstraints.NORTHWEST; + lCst.gridx = 0; + lCst.gridy = 0; + lProps.add(lDensity, lCst); + + lViscosity = new LabeledTextField("Viscosity"); + lCst.gridy = 1; + lProps.add(lViscosity, lCst); + + lLuminosity = new LabeledTextField("Light Level"); + lCst.gridy = 2; + lProps.add(lLuminosity, lCst); + + lPropagatesSkylightDown = new JCheckBox("Propagates Skylight Down"); + lCst.gridy = 3; + lProps.add(lPropagatesSkylightDown, lCst); + + lPathfindable = new JCheckBox("Pathfindable"); + lCst.gridy = 4; + lProps.add(lPathfindable, lCst); + + fCst.gridy = 4; + fProps.add(lProps, fCst); + + fTags = new TagsPanel(); + fTags.setMinimumSize(new Dimension(250, 325)); + fTags.setPreferredSize(new Dimension(250, 325)); + fTags.setMaximumSize(new Dimension(250, 325)); + fCst.gridy = 5; + fProps.add(fTags, fCst); + + cst4.anchor = GridBagConstraints.NORTHEAST; + cst4.gridx = 0; + cst4.gridy = 0; + panel4.add(fProps, cst4); + + JPanel buttonPanel = new JPanel(); + + JButton doneButton = new JButton("Done"); + doneButton.addActionListener(this::save); + buttonPanel.add(doneButton); + + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(this::cancel); + buttonPanel.add(cancelButton); + + cst4.gridy = 1; + panel4.add(buttonPanel, cst4); + + cst.gridx = 3; + cst.gridy = 0; + cst.gridheight = 15; + this.add(panel4, cst); + + this.pack(); + } + + private void color(ActionEvent e) { + Color c = JColorChooser.showDialog(this, "Edit Material Color", new Color(object.color.red, object.color.green, object.color.blue, object.color.alpha), true); + if(c != null) { + object.color.alpha = c.getAlpha(); + object.color.blue = c.getBlue(); + object.color.green = c.getGreen(); + object.color.red = c.getRed(); + } + } + + private void background(ActionEvent e) { + Color col; + try { + col = new Color(Integer.parseUnsignedInt(object.tooltip.background, 16), true); + } catch (Exception ex) { + ex.printStackTrace(); + col = new Color(0xF0100010, true); + } + Color c = JColorChooser.showDialog(this, "Edit Tooltip Background Color", col, true); + if(c != null) { + object.tooltip.background = Integer.toHexString(c.getRGB()); + } + } + + private void borderStart(ActionEvent e) { + Color col; + try { + col = new Color(Integer.parseUnsignedInt(object.tooltip.borderStart, 16), true); + } catch (Exception ex) { + ex.printStackTrace(); + col = new Color(0x505000FF, true); + } + Color c = JColorChooser.showDialog(this, "Edit Tooltip Border Start Color", col, true); + if(c != null) { + object.tooltip.borderStart = Integer.toHexString(c.getRGB()); + } + } + + private void borderEnd(ActionEvent e) { + Color col; + try { + col = new Color(Integer.parseUnsignedInt(object.tooltip.borderEnd, 16), true); + } catch (Exception ex) { + ex.printStackTrace(); + col = new Color(0x5028007F, true); + } + Color c = JColorChooser.showDialog(this, "Edit Tooltip Border End Color", col, true); + if(c != null) { + object.tooltip.borderEnd = Integer.toHexString(c.getRGB()); + } + } + + @Override + public void setObject(MM_Material o) { + bFriction.setText(o.block.friction); + bHardness.setText(o.block.hardness); + bMapColor.setText(o.block.mapColor); + bMaterial.setText(o.block.material); + bRequiresTool.setSelected(o.block.requiresToolForDrops); + bSound.setText(o.block.sound); + bSticky.setSelected(o.block.sticky); + bTags.setTags(o.block.tags); + burnTime.setText(o.burnTime); + enabled_identifier.setEnabledState(o.enabled); + enabled_identifier.setKey(identifier); + enabledTypes.setText(listAsString(o.enabledTypes)); + enchantPower.setText(o.enchantPowerBonus); + fBoilingTemp.setText(o.fluid.boilingTemperature); + fCurrentTemp.setText(o.fluid.currentTemperature); + fireSpread.setText(o.fireSpreadSpeed); + flammability.setText(o.flammability); + fMeltingTemp.setText(o.fluid.meltingTemperature); + fTags.setTags(o.fluid.tags); + gDensity.setText(o.fluid.gas.density); + gLuminosity.setText(o.fluid.gas.luminosity); + gPathfindable.setSelected(o.fluid.gas.isPathfindable); + gPropagatesSkylightDown.setSelected(o.fluid.gas.propagatesSkylightDown); + gViscosity.setText(o.fluid.gas.viscosity); + iFireResistant.setSelected(o.item.isFireResistant); + iFoil.setSelected(o.item.isFoil); + iLifespan.setText(o.item.lifespan); + iRarity.setSelected(o.item.rarity); + iTags.setTags(o.item.tags); + jumpFactor.setText(o.jumpFactor); + lDensity.setText(o.fluid.liquid.density); + lightLevel.setText(o.lightLevel); + lLuminosity.setText(o.fluid.liquid.luminosity); + lPathfindable.setSelected(o.fluid.liquid.isPathfindable); + lPropagatesSkylightDown.setSelected(o.fluid.liquid.propagatesSkylightDown); + lViscosity.setText(o.fluid.liquid.viscosity); + name.setText(o.name); + oFriction.setText(o.ore.friction); + oHardness.setText(o.ore.hardness); + oJumpFactor.setText(o.ore.jumpFactor); + oLightLevel.setText(o.ore.lightLevel); + oMapColor.setText(o.ore.mapColor); + oMaterial.setText(o.ore.material); + oRequiresTool.setSelected(o.ore.requiresToolForDrops); + oResistance.setText(o.ore.resistance); + oSound.setText(o.ore.sound); + oSpeedFactor.setText(o.ore.speedFactor); + oTags.setTags(o.ore.tags); + resistance.setText(o.resistance); + speedFactor.setText(o.speedFactor); + state.setSelected(o.state); + tagNames.setText(arrayAsString(o.tagNames)); + texture.setText(o.texture); + tText.setText(arrayAsString(o.tooltip.text)); + object = o; + } + + @Override + protected void save(ActionEvent e) { + object.block.friction = bFriction.getTextF(object.block.friction); + object.block.hardness = bHardness.getTextF(object.block.hardness); + object.block.mapColor = bMapColor.getText(); + object.block.material = bMaterial.getText(); + object.block.requiresToolForDrops = bRequiresTool.isSelected(); + object.block.sound = bSound.getText(); + object.block.sticky = bSticky.isSelected(); + object.block.tags = bTags.getTags(); + object.burnTime = burnTime.getTextI(object.burnTime); + object.enabled = enabled_identifier.getEnabledState(); + object.enabledTypes = stringAsList(enabledTypes.getText()); + object.enchantPowerBonus = enchantPower.getTextF(object.enchantPowerBonus); + object.fireSpreadSpeed = fireSpread.getTextI(object.fireSpreadSpeed); + object.flammability = flammability.getTextI(object.flammability); + object.fluid.boilingTemperature = fBoilingTemp.getTextI(object.fluid.boilingTemperature); + object.fluid.currentTemperature = fCurrentTemp.getTextI(object.fluid.currentTemperature); + object.fluid.gas.density = gDensity.getTextI(object.fluid.gas.density); + object.fluid.gas.isPathfindable = gPathfindable.isSelected(); + object.fluid.gas.luminosity = gLuminosity.getTextI(object.fluid.gas.luminosity); + object.fluid.gas.propagatesSkylightDown = gPropagatesSkylightDown.isSelected(); + object.fluid.gas.viscosity = gViscosity.getTextI(object.fluid.gas.viscosity); + object.fluid.liquid.density = lDensity.getTextI(object.fluid.liquid.density); + object.fluid.liquid.isPathfindable = lPathfindable.isSelected(); + object.fluid.liquid.luminosity = lLuminosity.getTextI(object.fluid.liquid.luminosity); + object.fluid.liquid.propagatesSkylightDown = lPropagatesSkylightDown.isSelected(); + object.fluid.liquid.viscosity = lViscosity.getTextI(object.fluid.liquid.viscosity); + object.fluid.meltingTemperature = fMeltingTemp.getTextI(object.fluid.meltingTemperature); + object.fluid.tags = fTags.getTags(); + object.item.isFireResistant = iFireResistant.isSelected(); + object.item.isFoil = iFoil.isSelected(); + object.item.lifespan = iLifespan.getTextI(object.item.lifespan); + object.item.rarity = iRarity.getSelected(); + object.item.tags = iTags.getTags(); + object.jumpFactor = jumpFactor.getTextF(object.jumpFactor); + object.lightLevel = lightLevel.getTextI(object.lightLevel); + object.name = name.getText(); + object.ore.friction = oFriction.getTextF(object.ore.friction); + object.ore.hardness = oHardness.getTextF(object.ore.hardness); + object.ore.jumpFactor = oJumpFactor.getTextF(object.ore.jumpFactor); + object.ore.mapColor = oMapColor.getText(); + object.ore.material = oMaterial.getText(); + object.ore.requiresToolForDrops = oRequiresTool.isSelected(); + object.ore.resistance = oResistance.getTextF(object.ore.resistance); + object.ore.sound = oSound.getText(); + object.ore.speedFactor = oSpeedFactor.getTextF(object.ore.speedFactor); + object.ore.tags = oTags.getTags(); + object.resistance = resistance.getTextF(object.resistance); + object.speedFactor = speedFactor.getTextF(object.speedFactor); + object.state = state.getSelected(); + object.tagNames = stringAsArray(tagNames.getText()); + object.texture = texture.getText(); + object.tooltip.text = stringAsArray(tText.getText()); + parent.set(enabled_identifier.getKey(), object); + parent.unlock(); + this.setVisible(false); + } + +} diff --git a/src/main/java/glowredman/mmcc/frames/TypeEditor.java b/src/main/java/glowredman/mmcc/frames/TypeEditor.java new file mode 100644 index 0000000..429ed03 --- /dev/null +++ b/src/main/java/glowredman/mmcc/frames/TypeEditor.java @@ -0,0 +1,180 @@ +package glowredman.mmcc.frames; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JPanel; + +import glowredman.mmcc.panels.IdentifierPanel; +import glowredman.mmcc.panels.LabeledComboBox; +import glowredman.mmcc.panels.LabeledTextField; +import glowredman.mmcc.panels.TagsPanel; +import glowredman.mmcc.panels.TopPanel; +import glowredman.modularmaterials.data.object.MM_Type; +import glowredman.modularmaterials.data.object.sub.Category; +import glowredman.modularmaterials.data.object.sub.ChemicalState; + +public class TypeEditor extends Editor { + + private static final long serialVersionUID = 8785693131214416569L; + private IdentifierPanel enabled_identifier; + private LabeledTextField name; + private LabeledComboBox category; + private LabeledComboBox state; + private LabeledTextField burnTime; + private LabeledTextField enchantPower; + private LabeledTextField fireSpread; + private LabeledTextField flammability; + private LabeledTextField jumpFactor; + private LabeledTextField lightLevel; + private LabeledTextField resistance; + private LabeledTextField speedFactor; + private JCheckBox hasTooltip; + private LabeledTextField syntax; + private TagsPanel tags; + + public TypeEditor(TopPanel parent) { + super(parent); + this.setTitle("Edit types.json Entry"); + this.setResizable(false); + this.setLayout(new GridBagLayout()); + + //First Column + GridBagConstraints cst = new GridBagConstraints(); + cst.anchor = GridBagConstraints.SOUTHWEST; + + enabled_identifier = new IdentifierPanel(); + cst.gridx = 0; + cst.gridy = 0; + this.add(enabled_identifier, cst); + + category = new LabeledComboBox<>("Category", Category.values()); + cst.gridy = 1; + this.add(category, cst); + + state = new LabeledComboBox<>("State", ChemicalState.values()); + cst.gridy = 2; + this.add(state, cst); + + name = new LabeledTextField("Tag Name"); + cst.gridy = 3; + this.add(name, cst); + + syntax = new LabeledTextField("Name Syntax"); + cst.gridy = 4; + this.add(syntax, cst); + + hasTooltip = new JCheckBox("Has Tooltip"); + cst.gridy = 5; + this.add(hasTooltip, cst); + + JPanel mPanel = new JPanel(new GridBagLayout()); + mPanel.setBorder(BorderFactory.createTitledBorder("Multiplier")); + + GridBagConstraints mCst = new GridBagConstraints(); + + burnTime = new LabeledTextField("Burn Time"); + mCst.gridx = 0; + mCst.gridy = 0; + mPanel.add(burnTime, mCst); + + enchantPower = new LabeledTextField("Enchantment Power Bonus"); + mCst.gridy = 1; + mPanel.add(enchantPower, mCst); + + fireSpread = new LabeledTextField("Fire Spread Speed"); + mCst.gridy = 2; + mPanel.add(fireSpread, mCst); + + flammability = new LabeledTextField("Flammability"); + mCst.gridy = 3; + mPanel.add(flammability, mCst); + + jumpFactor = new LabeledTextField("Jump Factor"); + mCst.gridy = 4; + mPanel.add(jumpFactor, mCst); + + lightLevel = new LabeledTextField("Light Level"); + mCst.gridy = 5; + mPanel.add(lightLevel, mCst); + + resistance = new LabeledTextField("Blast Resistance"); + mCst.gridy = 6; + mPanel.add(resistance, mCst); + + speedFactor = new LabeledTextField("Speed Factor"); + mCst.gridy = 7; + mPanel.add(speedFactor, mCst); + + cst.gridy = 6; + this.add(mPanel, cst); + + JButton doneButton = new JButton("Done"); + doneButton.addActionListener(this::save); + cst.anchor = GridBagConstraints.EAST; + cst.gridy = 7; + this.add(doneButton, cst); + + //Second Column + tags = new TagsPanel(); + cst.anchor = GridBagConstraints.SOUTHWEST; + cst.gridx = 1; + cst.gridy = 0; + cst.gridheight = 7; + this.add(tags, cst); + + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(this::cancel); + cst.gridy = 7; + this.add(cancelButton, cst); + + this.pack(); + } + + @Override + public void setObject(MM_Type o) { + enabled_identifier.setEnabledState(o.enabled); + enabled_identifier.setKey(identifier); + category.setSelected(o.category); + state.setSelected(o.state); + name.setText(o.tagName); + syntax.setText(o.nameSyntax); + hasTooltip.setSelected(o.hasTooltip); + burnTime.setText(o.burnTimeMultiplier); + enchantPower.setText(o.enchantPowerBonusMultiplier); + fireSpread.setText(o.fireSpreadSpeedMultiplier); + flammability.setText(o.flammabilityMultiplier); + jumpFactor.setText(o.jumpFactorMultiplier); + lightLevel.setText(o.lightLevelMultiplier); + resistance.setText(o.resistanceMultiplier); + speedFactor.setText(o.speedFactorMultiplier); + object = o; + } + + @Override + protected void save(ActionEvent e) { + object.burnTimeMultiplier = burnTime.getTextF(object.burnTimeMultiplier); + object.category = category.getSelected(); + object.enabled = enabled_identifier.getEnabledState(); + object.enchantPowerBonusMultiplier = enchantPower.getTextF(object.enchantPowerBonusMultiplier); + object.fireSpreadSpeedMultiplier = fireSpread.getTextF(object.fireSpreadSpeedMultiplier); + object.flammabilityMultiplier = flammability.getTextF(object.flammabilityMultiplier); + object.hasTooltip = hasTooltip.isSelected(); + object.jumpFactorMultiplier = jumpFactor.getTextF(object.jumpFactorMultiplier); + object.lightLevelMultiplier = lightLevel.getTextF(object.lightLevelMultiplier); + object.nameSyntax = syntax.getText(); + object.resistanceMultiplier = resistance.getTextF(object.resistanceMultiplier); + object.speedFactorMultiplier = speedFactor.getTextF(object.speedFactorMultiplier); + object.state = state.getSelected(); + object.tagName = name.getText(); + object.tags = tags.getTags(); + parent.set(enabled_identifier.getKey(), object); + parent.unlock(); + this.setVisible(false); + } + +} diff --git a/src/main/java/glowredman/mmcc/frames/VariantEditor.java b/src/main/java/glowredman/mmcc/frames/VariantEditor.java new file mode 100644 index 0000000..e99aeb5 --- /dev/null +++ b/src/main/java/glowredman/mmcc/frames/VariantEditor.java @@ -0,0 +1,107 @@ +package glowredman.mmcc.frames; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JPanel; + +import glowredman.mmcc.panels.IdentifierPanel; +import glowredman.mmcc.panels.LabeledTextField; +import glowredman.mmcc.panels.TagsPanel; +import glowredman.mmcc.panels.TopPanel; +import glowredman.modularmaterials.data.object.MM_OreVariant; + +public class VariantEditor extends Editor { + + private static final long serialVersionUID = -8604490226423285097L; + private IdentifierPanel enabled_identifier; + private JCheckBox falling; + private LabeledTextField name; + private LabeledTextField block; + private LabeledTextField texture; + private LabeledTextField syntax; + private TagsPanel tags; + + public VariantEditor(TopPanel parent) { + super(parent); + this.setTitle("Edit orevariants.json Entry"); + this.setResizable(false); + this.setLayout(new GridBagLayout()); + + GridBagConstraints cst = new GridBagConstraints(); + cst.anchor = GridBagConstraints.WEST; + + enabled_identifier = new IdentifierPanel(); + cst.gridx = 0; + cst.gridy = 0; + this.add(enabled_identifier, cst); + + falling = new JCheckBox("Obeys Gravity"); + cst.gridy = 1; + this.add(falling, cst); + + name = new LabeledTextField("Variant Name"); + cst.gridy = 2; + this.add(name, cst); + + block = new LabeledTextField("Base Block"); + cst.gridy = 3; + this.add(block, cst); + + texture = new LabeledTextField("Base Texture"); + cst.gridy = 4; + this.add(texture, cst); + + syntax = new LabeledTextField("Name Syntax"); + cst.gridy = 5; + this.add(syntax, cst); + + tags = new TagsPanel(); + cst.gridy = 6; + this.add(tags, cst); + + JPanel panel = new JPanel(); + JButton doneButton = new JButton("Done"); + doneButton.addActionListener(this::save); + panel.add(doneButton); + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(this::cancel); + panel.add(cancelButton); + cst.anchor = GridBagConstraints.CENTER; + cst.gridy = 7; + this.add(panel, cst); + + this.pack(); + } + + @Override + public void setObject(MM_OreVariant o) { + enabled_identifier.setEnabledState(o.enabled); + enabled_identifier.setKey(identifier); + falling.setSelected(o.falling); + name.setText(o.variantName); + block.setText(o.baseBlock); + texture.setText(o.baseTexture); + syntax.setText(o.nameSyntax); + tags.setTags(o.tags); + object = o; + } + + @Override + protected void save(ActionEvent e) { + object.baseBlock = block.getText(); + object.baseTexture = texture.getText(); + object.enabled = enabled_identifier.getEnabledState(); + object.falling = falling.isSelected(); + object.nameSyntax = syntax.getText(); + object.tags = tags.getTags(); + object.variantName = name.getText(); + parent.set(enabled_identifier.getKey(), object); + parent.unlock(); + this.setVisible(false); + } + +} diff --git a/src/main/java/glowredman/mmcc/frames/VeinEditor.java b/src/main/java/glowredman/mmcc/frames/VeinEditor.java new file mode 100644 index 0000000..510e6a3 --- /dev/null +++ b/src/main/java/glowredman/mmcc/frames/VeinEditor.java @@ -0,0 +1,200 @@ +package glowredman.mmcc.frames; + +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; + +import glowredman.mmcc.panels.IdentifierPanel; +import glowredman.mmcc.panels.LabeledTextField; +import glowredman.mmcc.panels.TopPanel; +import glowredman.modularmaterials.data.object.MM_OreVein; + +public class VeinEditor extends Editor { + + private static final long serialVersionUID = -1060546302330071806L; + private IdentifierPanel enabled_identifier; + private LabeledTextField primary; + private LabeledTextField secondary; + private LabeledTextField inbetween; + private LabeledTextField sporadic; + private JCheckBox invertBiomes; + private JTextArea biomes; + private LabeledTextField name; + private LabeledTextField density; + private JTextField minY; + private JTextField maxY; + private LabeledTextField size; + private LabeledTextField weight; + private JCheckBox invertDimensions; + private JTextArea dimensions; + + public VeinEditor(TopPanel parent) { + super(parent); + this.setTitle("Edit oreveins.json Entry"); + this.setResizable(false); + this.setLayout(new GridBagLayout()); + + GridBagConstraints cst = new GridBagConstraints(); + + // First Column + enabled_identifier = new IdentifierPanel(); + cst.anchor = GridBagConstraints.WEST; + cst.gridx = 0; + cst.gridy = 0; + this.add(enabled_identifier, cst); + + primary = new LabeledTextField("Primary"); + cst.gridy = 1; + this.add(primary, cst); + + secondary = new LabeledTextField("Secondary"); + cst.gridy = 2; + this.add(secondary, cst); + + inbetween = new LabeledTextField("Inbetween"); + cst.gridy = 3; + this.add(inbetween, cst); + + sporadic = new LabeledTextField("Sporadic"); + cst.gridy = 4; + this.add(sporadic, cst); + + JPanel biomesPanel = new JPanel(); + biomesPanel.setLayout(new BoxLayout(biomesPanel, BoxLayout.Y_AXIS)); + biomesPanel.setBorder(BorderFactory.createTitledBorder("Biomes")); + invertBiomes = new JCheckBox("Invert"); + biomes = new JTextArea(); + JScrollPane biomesScrollPane = new JScrollPane(biomes); + biomesScrollPane.setMinimumSize(new Dimension(250, 500)); + biomesScrollPane.setPreferredSize(new Dimension(250, 500)); + biomesScrollPane.setMaximumSize(new Dimension(250, 500)); + biomesPanel.add(invertBiomes); + biomesPanel.add(biomesScrollPane); + cst.gridy = 5; + this.add(biomesPanel, cst); + + JButton doneButton = new JButton("Done"); + doneButton.addActionListener(this::save); + cst.anchor = GridBagConstraints.EAST; + cst.gridy = 6; + this.add(doneButton, cst); + + //Second Column + name = new LabeledTextField("Name"); + cst.anchor = GridBagConstraints.WEST; + cst.gridx = 1; + cst.gridy = 0; + this.add(name, cst); + + density = new LabeledTextField("Density"); + cst.gridy = 1; + this.add(density, cst); + + JPanel yPanel = new JPanel(); + JLabel yLabel = new JLabel("Height Range"); + yLabel.setMinimumSize(new Dimension(75, 20)); + yLabel.setPreferredSize(new Dimension(75, 20)); + yLabel.setMaximumSize(new Dimension(75, 20)); + yLabel.setToolTipText("Height Range"); + minY = new JTextField(); + minY.setMinimumSize(new Dimension(30, 20)); + minY.setPreferredSize(new Dimension(30, 20)); + minY.setMaximumSize(new Dimension(30, 20)); + minY.setToolTipText("Minimum Height"); + JLabel toLabel = new JLabel("-"); + maxY = new JTextField(); + maxY.setMinimumSize(new Dimension(30, 20)); + maxY.setPreferredSize(new Dimension(30, 20)); + maxY.setMaximumSize(new Dimension(30, 20)); + maxY.setToolTipText("Maximum Height"); + yPanel.add(yLabel); + yPanel.add(minY); + yPanel.add(toLabel); + yPanel.add(maxY); + cst.gridy = 2; + this.add(yPanel, cst); + + size = new LabeledTextField("Size"); + cst.gridy = 3; + this.add(size, cst); + + weight = new LabeledTextField("Weight"); + cst.gridy = 4; + this.add(weight, cst); + + JPanel dimensionsPanel = new JPanel(); + dimensionsPanel.setLayout(new BoxLayout(dimensionsPanel, BoxLayout.Y_AXIS)); + dimensionsPanel.setBorder(BorderFactory.createTitledBorder("Dimensions")); + invertDimensions = new JCheckBox("Invert"); + dimensions = new JTextArea(); + JScrollPane dimensionsScrollPane = new JScrollPane(dimensions); + dimensionsScrollPane.setMinimumSize(new Dimension(250, 500)); + dimensionsScrollPane.setPreferredSize(new Dimension(250, 500)); + dimensionsScrollPane.setMaximumSize(new Dimension(250, 500)); + dimensionsPanel.add(invertDimensions); + dimensionsPanel.add(dimensionsScrollPane); + cst.gridy = 5; + this.add(dimensionsPanel, cst); + + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(this::cancel); + cst.gridy = 6; + this.add(cancelButton, cst); + + this.pack(); + } + + protected void save(ActionEvent e) { + object.biomes = stringAsList(biomes.getText()); + object.density = density.getTextI(object.density); + object.dimensions = stringAsList(dimensions.getText()); + object.enabled = enabled_identifier.getEnabledState(); + object.inbetween = inbetween.getText(); + object.invertBiomes = invertBiomes.isSelected(); + object.invertDimensions = invertDimensions.isSelected(); + try { object.maxY = Integer.parseInt(maxY.getText()); } catch (Exception ex) { ex.printStackTrace(); } + try { object.minY = Integer.parseInt(minY.getText()); } catch (Exception ex) { ex.printStackTrace(); } + object.name = name.getText(); + object.primary = primary.getText(); + object.secondary = secondary.getText(); + object.size = size.getTextI(object.size); + object.sporadic = sporadic.getText(); + object.weight = weight.getTextI(object.weight); + parent.set(enabled_identifier.getKey(), object); + parent.unlock(); + this.setVisible(false); + } + + @Override + public void setObject(MM_OreVein o) { + enabled_identifier.setEnabledState(o.enabled); + enabled_identifier.setKey(identifier); + primary.setText(o.primary); + secondary.setText(o.secondary); + inbetween.setText(o.inbetween); + sporadic.setText(o.sporadic); + invertBiomes.setSelected(o.invertBiomes); + biomes.setText(listAsString(o.biomes)); + name.setText(o.name); + density.setText(o.density); + minY.setText(String.valueOf(o.minY)); + maxY.setText(String.valueOf(o.maxY)); + size.setText(o.size); + weight.setText(o.weight); + invertDimensions.setSelected(o.invertDimensions); + dimensions.setText(listAsString(o.dimensions)); + object = o; + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/IdentifierPanel.java b/src/main/java/glowredman/mmcc/panels/IdentifierPanel.java new file mode 100644 index 0000000..5778cb1 --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/IdentifierPanel.java @@ -0,0 +1,48 @@ +package glowredman.mmcc.panels; + +import java.awt.Dimension; + +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +public class IdentifierPanel extends JPanel { + + private static final long serialVersionUID = -40591255661383007L; + private JTextField key; + private JCheckBox enabled; + + public IdentifierPanel() { + JLabel identLabel = new JLabel("Identifier"); + key = new JTextField(); + enabled = new JCheckBox(); + identLabel.setMinimumSize(new Dimension(75, 20)); + identLabel.setPreferredSize(new Dimension(75, 20)); + identLabel.setMaximumSize(new Dimension(75, 20)); + key.setMinimumSize(new Dimension(125, 20)); + key.setPreferredSize(new Dimension(125, 20)); + key.setMaximumSize(new Dimension(125, 20)); + enabled.setToolTipText("Enabled"); + this.add(identLabel); + this.add(key); + this.add(enabled); + } + + public boolean getEnabledState() { + return enabled.isSelected(); + } + + public void setEnabledState(boolean b) { + enabled.setSelected(b); + } + + public String getKey() { + return key.getText(); + } + + public void setKey(String t) { + key.setText(t); + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/LabeledComboBox.java b/src/main/java/glowredman/mmcc/panels/LabeledComboBox.java new file mode 100644 index 0000000..557d545 --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/LabeledComboBox.java @@ -0,0 +1,38 @@ +package glowredman.mmcc.panels; + +import java.awt.Dimension; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class LabeledComboBox extends JPanel { + + private static final long serialVersionUID = 1747551096358857336L; + private JComboBox box; + + public LabeledComboBox(String text, E[] values) { + JLabel label = new JLabel(text); + box = new JComboBox<>(values); + label.setMinimumSize(new Dimension(75, 20)); + label.setPreferredSize(new Dimension(75, 20)); + label.setMaximumSize(new Dimension(75, 20)); + label.setToolTipText(text); + box.setMinimumSize(new Dimension(150, 20)); + box.setPreferredSize(new Dimension(150, 20)); + box.setMaximumSize(new Dimension(150, 20)); + box.setToolTipText(text); + this.add(label); + this.add(box); + } + + public void setSelected(E value) { + box.setSelectedItem(value); + } + + @SuppressWarnings("unchecked") + public E getSelected() { + return (E) box.getSelectedItem(); + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/LabeledTextField.java b/src/main/java/glowredman/mmcc/panels/LabeledTextField.java new file mode 100644 index 0000000..3e17729 --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/LabeledTextField.java @@ -0,0 +1,61 @@ +package glowredman.mmcc.panels; + +import java.awt.Dimension; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +public class LabeledTextField extends JPanel { + + private static final long serialVersionUID = 3840431008411414662L; + public JTextField text; + + public LabeledTextField(String name) { + JLabel label = new JLabel(name); + text = new JTextField(); + label.setMinimumSize(new Dimension(75, 20)); + label.setPreferredSize(new Dimension(75, 20)); + label.setMaximumSize(new Dimension(75, 20)); + text.setMinimumSize(new Dimension(150, 20)); + text.setPreferredSize(new Dimension(150, 20)); + text.setMaximumSize(new Dimension(150, 20)); + this.add(label); + this.add(text); + } + + public String getText() { + return text.getText(); + } + + public int getTextI(int prev) { + try { + return Integer.parseInt(text.getText()); + } catch (Exception e) { + e.printStackTrace(); + return prev; + } + } + + public float getTextF(float prev) { + try { + return Float.parseFloat(text.getText()); + } catch (Exception e) { + e.printStackTrace(); + return prev; + } + } + + public void setText(int t) { + text.setText(String.valueOf(t)); + } + + public void setText(float t) { + text.setText(String.valueOf(t)); + } + + public void setText(String t) { + text.setText(t); + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/MaterialPanel.java b/src/main/java/glowredman/mmcc/panels/MaterialPanel.java new file mode 100644 index 0000000..63f193c --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/MaterialPanel.java @@ -0,0 +1,30 @@ +package glowredman.mmcc.panels; + +import java.lang.reflect.Type; +import java.util.LinkedHashMap; + +import com.google.gson.reflect.TypeToken; + +import glowredman.mmcc.frames.MaterialEditor; +import glowredman.modularmaterials.data.object.MM_Material; + +public class MaterialPanel extends TopPanel { + + private static final long serialVersionUID = -6408366295724301578L; + + public MaterialPanel() { + super("materials.json"); + this.editorFrame = new MaterialEditor(this); + } + + @Override + protected Type getType() { + return new TypeToken>() {}.getType(); + } + + @Override + protected MM_Material getNew() { + return new MM_Material(); + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/TagsPanel.java b/src/main/java/glowredman/mmcc/panels/TagsPanel.java new file mode 100644 index 0000000..d7db14c --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/TagsPanel.java @@ -0,0 +1,34 @@ +package glowredman.mmcc.panels; + +import java.awt.Dimension; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import glowredman.mmcc.frames.Editor; + +public class TagsPanel extends JScrollPane { + + private static final long serialVersionUID = -8193585166429016225L; + private JTextArea tags; + + public TagsPanel() { + tags = new JTextArea(); + this.setViewportView(tags); + this.setBorder(BorderFactory.createTitledBorder("Tags")); + this.setMinimumSize(new Dimension(250, 400)); + this.setPreferredSize(new Dimension(250, 400)); + this.setMaximumSize(new Dimension(250, 400)); + } + + public void setTags(List tags) { + this.tags.setText(Editor.listAsString(tags)); + } + + public List getTags() { + return Editor.stringAsList(tags.getText()); + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/TopPanel.java b/src/main/java/glowredman/mmcc/panels/TopPanel.java new file mode 100644 index 0000000..c4d5892 --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/TopPanel.java @@ -0,0 +1,200 @@ +package glowredman.mmcc.panels; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import glowredman.mmcc.MethodAction; +import glowredman.mmcc.frames.Editor; + +public abstract class TopPanel extends JPanel { + + private static final long serialVersionUID = -5275091548038115322L; + protected Editor editorFrame; + private final JScrollPane scrollPane; + protected final JList list; + private final DefaultListModel listModel; + private Map map; + private final String fileName; + protected boolean addNew; + + public TopPanel(String fileName) { + this.map = new LinkedHashMap<>(); + this.listModel = new DefaultListModel<>(); + this.list = new JList<>(listModel); + this.scrollPane = new JScrollPane(list); + this.fileName = fileName; + + lock(); + + list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + + this.setEnabled(false); + this.setBorder(BorderFactory.createTitledBorder(fileName)); + this.setPreferredSize(new Dimension(150, 400)); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + this.add(scrollPane); + + setKeyBindings(this::add, "add", KeyEvent.VK_F1, KeyEvent.VK_INSERT, KeyEvent.VK_PLUS, KeyEvent.VK_ADD); + setKeyBindings(this::edit, "edit", KeyEvent.VK_F2, KeyEvent.VK_ENTER); + setKeyBindings(this::delete, "delete", KeyEvent.VK_F3, KeyEvent.VK_DELETE, KeyEvent.VK_MINUS, KeyEvent.VK_SUBTRACT, KeyEvent.VK_BACK_SPACE); + setKeyBindings(this::up, "up", KeyEvent.VK_F4); + setKeyBindings(this::down, "down", KeyEvent.VK_F5); + } + + private void add(ActionEvent e) { + if(list.getSelectedIndices().length != 1) return; + + lock(); + addNew = true; + + editorFrame.identifier = ""; + editorFrame.setObject(this.getNew()); + editorFrame.setVisible(true); + + } + + private void edit(ActionEvent e) { + int[] selected = list.getSelectedIndices(); + if(selected.length != 1) return; + + lock(); + addNew = false; + + editorFrame.identifier = listModel.elementAt(selected[0]); + editorFrame.setObject(map.get(editorFrame.identifier)); + editorFrame.setVisible(true); + } + + private void delete(ActionEvent e) { + int min = list.getMinSelectionIndex(); + int max = list.getMaxSelectionIndex(); + if(min == -1) return; + listModel.removeRange(min, max); + if(listModel.size() > 0) { + if(min == listModel.size()) { + list.setSelectedIndex(min - 1); + } else { + list.setSelectedIndex(min); + } + } + } + + private void up(ActionEvent e) { + int[] selection = list.getSelectedIndices(); + if(selection.length == 1 && selection[0] > 0) { + int oldPos = selection[0]; + int newPos = oldPos - 1; + String selected = listModel.get(oldPos); + String other = listModel.get(newPos); + listModel.set(newPos, selected); + listModel.set(oldPos, other); + list.setSelectedIndex(newPos); + } + } + + private void down(ActionEvent e) { + int[] selection = list.getSelectedIndices(); + if(selection.length == 1 && selection[0] < listModel.size() - 1) { + int oldPos = selection[0]; + int newPos = oldPos + 1; + String selected = listModel.get(oldPos); + String other = listModel.get(newPos); + listModel.set(newPos, selected); + listModel.set(oldPos, other); + list.setSelectedIndex(newPos); + } + } + + public void unlock() { + this.list.setEnabled(true); + } + + public void lock() { + this.list.setEnabled(false); + } + + public void set(String identifier, T value) { + if(addNew) { + listModel.insertElementAt(identifier, list.getSelectedIndex() + 1); + } else { + listModel.set(list.getSelectedIndex(), identifier); + } + map.put(identifier, value); + } + + private Map getSorted() { + Map newMap = new LinkedHashMap<>(); + for(int i = 0; i < listModel.size(); i++) { + String element = listModel.get(i); + newMap.put(element, map.get(element)); + } + return newMap; + } + + protected abstract Type getType(); + + protected abstract T getNew(); + + public void read(File configDir) { + try { + Gson gson = new Gson(); + map.clear(); + listModel.clear(); + map = gson.fromJson(new BufferedReader(new FileReader(new File(configDir, fileName), StandardCharsets.UTF_8)), getType()); + if(map == null) map = new LinkedHashMap<>(); + listModel.addAll(map.keySet()); + unlock(); + this.setEnabled(true); + System.out.println("Found " + fileName + " with " + map.size() + " entries"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void write(File confFile, String dateAndTime) { + try { + File currentFile = new File(confFile, fileName); + String newFileName = "mmcc_backup/" + fileName.replace(".json", "") + "-before-" + dateAndTime + ".json"; + Files.copy(currentFile.toPath(), confFile.toPath().resolve(newFileName), StandardCopyOption.COPY_ATTRIBUTES); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + BufferedWriter w = new BufferedWriter(new FileWriter(currentFile, StandardCharsets.UTF_8)); + w.write(gson.toJson(getSorted(), getType())); + w.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void setKeyBindings(ActionListener action, String name, int... keys) { + for(int i : keys) { + this.list.getInputMap().put(KeyStroke.getKeyStroke(i, 0, true), name); + } + this.list.getActionMap().put(name, new MethodAction(action)); + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/TypePanel.java b/src/main/java/glowredman/mmcc/panels/TypePanel.java new file mode 100644 index 0000000..5ccca23 --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/TypePanel.java @@ -0,0 +1,30 @@ +package glowredman.mmcc.panels; + +import java.lang.reflect.Type; +import java.util.LinkedHashMap; + +import com.google.gson.reflect.TypeToken; + +import glowredman.mmcc.frames.TypeEditor; +import glowredman.modularmaterials.data.object.MM_Type; + +public class TypePanel extends TopPanel { + + private static final long serialVersionUID = -7774516960074130028L; + + public TypePanel() { + super("types.json"); + this.editorFrame = new TypeEditor(this); + } + + @Override + protected Type getType() { + return new TypeToken>() {}.getType(); + } + + @Override + protected MM_Type getNew() { + return new MM_Type(); + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/VariantPanel.java b/src/main/java/glowredman/mmcc/panels/VariantPanel.java new file mode 100644 index 0000000..5e5de58 --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/VariantPanel.java @@ -0,0 +1,30 @@ +package glowredman.mmcc.panels; + +import java.lang.reflect.Type; +import java.util.LinkedHashMap; + +import com.google.gson.reflect.TypeToken; + +import glowredman.mmcc.frames.VariantEditor; +import glowredman.modularmaterials.data.object.MM_OreVariant; + +public class VariantPanel extends TopPanel { + + private static final long serialVersionUID = 1834797922759218551L; + + public VariantPanel() { + super("orevariants.json"); + this.editorFrame = new VariantEditor(this); + } + + @Override + protected Type getType() { + return new TypeToken>() {}.getType(); + } + + @Override + protected MM_OreVariant getNew() { + return new MM_OreVariant(); + } + +} diff --git a/src/main/java/glowredman/mmcc/panels/VeinPanel.java b/src/main/java/glowredman/mmcc/panels/VeinPanel.java new file mode 100644 index 0000000..c69bed5 --- /dev/null +++ b/src/main/java/glowredman/mmcc/panels/VeinPanel.java @@ -0,0 +1,30 @@ +package glowredman.mmcc.panels; + +import java.lang.reflect.Type; +import java.util.LinkedHashMap; + +import com.google.gson.reflect.TypeToken; + +import glowredman.mmcc.frames.VeinEditor; +import glowredman.modularmaterials.data.object.MM_OreVein; + +public class VeinPanel extends TopPanel { + + private static final long serialVersionUID = -2342409049924673489L; + + public VeinPanel() { + super("oreveins.json"); + this.editorFrame = new VeinEditor(this); + } + + @Override + protected Type getType() { + return new TypeToken>() {}.getType(); + } + + @Override + protected MM_OreVein getNew() { + return new MM_OreVein(); + } + +} diff --git a/src/main/java/glowredman/modularmaterials/client/FormattingHandler.java b/src/main/java/glowredman/modularmaterials/client/FormattingHandler.java new file mode 100644 index 0000000..7bcaf87 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/client/FormattingHandler.java @@ -0,0 +1,47 @@ +package glowredman.modularmaterials.client; + +import java.util.List; + +public class FormattingHandler { + + public static String listToString(List list) { + + // no entries = [] + if(list == null || list.size() == 0) { + return "[]"; + } + + // one entry = ["abc"] + if(list.size() == 1) { + return "[\"" + list.get(0) + "\"]"; + } + + // multiple entries = ["abc", "def", ...] + String ret = "[\"" + list.get(0); + for(int i = 1; i < list.size(); i++) { + ret += "\", \"" + list.get(i); + } + return ret += "\"]"; + } + + public static String arrayToString(String[] array) { + + // no entries = [] + if(array == null || array.length == 0) { + return "[]"; + } + + // one entry = ["abc"] + if(array.length == 1) { + return "[\"" + array[0] + "\"]"; + } + + // multiple entries = ["abc", "def", ...] + String ret = "[\"" + array[0]; + for(int i = 1; i < array.length; i++) { + ret += "\", \"" + array[i]; + } + return ret += "\"]"; + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/TagHandler.java b/src/main/java/glowredman/modularmaterials/data/TagHandler.java new file mode 100644 index 0000000..868730d --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/TagHandler.java @@ -0,0 +1,7 @@ +package glowredman.modularmaterials.data; + +public class TagHandler { + + public static final String PARAM_MATERIAL = ""; + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/MM_Material.java b/src/main/java/glowredman/modularmaterials/data/object/MM_Material.java new file mode 100644 index 0000000..e810efd --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/MM_Material.java @@ -0,0 +1,52 @@ +package glowredman.modularmaterials.data.object; + +import java.util.ArrayList; +import java.util.List; + +import glowredman.modularmaterials.client.FormattingHandler; +import glowredman.modularmaterials.data.object.sub.BlockProperties; +import glowredman.modularmaterials.data.object.sub.ChemicalState; +import glowredman.modularmaterials.data.object.sub.ColorProperties; +import glowredman.modularmaterials.data.object.sub.FluidProperties; +import glowredman.modularmaterials.data.object.sub.ItemProperties; +import glowredman.modularmaterials.data.object.sub.OreProperties; +import glowredman.modularmaterials.data.object.sub.TooltipProperties; + +public class MM_Material { + + public String name = "material_" + this.hashCode(); + public String[] tagNames = new String[] {name}; + public boolean enabled = false; + public List enabledTypes = new ArrayList<>(); + public ColorProperties color = new ColorProperties(); + public int burnTime = 0; + public float enchantPowerBonus = 0.0f; + public int fireSpreadSpeed = 0; + public int flammability = 0; + public float jumpFactor = 1.0f; + public int lightLevel = 0; + public float resistance = 6.0f; + public float speedFactor = 1.0f; + public ChemicalState state = ChemicalState.SOLID; + public String texture = "metallic"; + public TooltipProperties tooltip = new TooltipProperties(); + public BlockProperties block = new BlockProperties(); + public FluidProperties fluid = new FluidProperties(); + public ItemProperties item = new ItemProperties(); + public OreProperties ore = new OreProperties(); + + @Override + public String toString() { + return String.format("{name: %s, tagNames: %s, enabled: %b, enabledTypes: %s, color: %s, burnTime: %d, enchantPowerBonus: %f, fireSpreadSpeed: %d, flammability: %d, jumpFactor: %f, lightLevel: %d, resistance: %f, speedFactor: %f, state: %s, texture: %s, tooltip: %s, block: %s, fluid: %s, item: %s, ore: %s}", + name, FormattingHandler.arrayToString(tagNames), enabled, FormattingHandler.listToString(enabledTypes), color, burnTime, enchantPowerBonus, fireSpreadSpeed, flammability, jumpFactor, lightLevel, resistance, speedFactor, state, texture, tooltip, block, fluid, item, ore); + } + + @Override + public boolean equals(Object obj) { + if(obj == null || !(obj instanceof MM_Material)) { + return false; + } + return this.name.equals(((MM_Material) obj).name); + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/MM_OreVariant.java b/src/main/java/glowredman/modularmaterials/data/object/MM_OreVariant.java new file mode 100644 index 0000000..fc60cb7 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/MM_OreVariant.java @@ -0,0 +1,25 @@ +package glowredman.modularmaterials.data.object; + +import java.util.ArrayList; +import java.util.List; + +import glowredman.modularmaterials.client.FormattingHandler; +import glowredman.modularmaterials.data.TagHandler; + +public class MM_OreVariant { + + public boolean enabled = true; + public boolean falling = false; + public String variantName = "variant_" + this.hashCode(); + public String baseBlock = "minecraft:stone"; + public String baseTexture = "minecraft:block/stone"; + public String nameSyntax = TagHandler.PARAM_MATERIAL + " Ore"; + public List tags = new ArrayList<>(); + + @Override + public String toString() { + return String.format("{enabled: %b, falling: %b, variantName: %s, baseBlock: %s, baseTexture: %s, nameSyntax: %s, tags: %s}", + enabled, falling, variantName, baseBlock, baseTexture, nameSyntax, FormattingHandler.listToString(tags)); + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/MM_OreVein.java b/src/main/java/glowredman/modularmaterials/data/object/MM_OreVein.java new file mode 100644 index 0000000..8207e15 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/MM_OreVein.java @@ -0,0 +1,25 @@ +package glowredman.modularmaterials.data.object; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MM_OreVein { + + public String name = "vein_" + this.hashCode(); + public boolean enabled = false; + public String primary = "example"; + public String secondary = "example"; + public String inbetween = "example"; + public String sporadic = "example"; + public int density = 2; + public int minY = 5; + public int maxY = 250; + public int size = 32; + public int weight = 100; + public boolean invertDimensions = false; + public List dimensions = Arrays.asList("minecraft:overworld"); + public boolean invertBiomes = true; + public List biomes = new ArrayList<>(); + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/MM_Type.java b/src/main/java/glowredman/modularmaterials/data/object/MM_Type.java new file mode 100644 index 0000000..2ae8195 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/MM_Type.java @@ -0,0 +1,35 @@ +package glowredman.modularmaterials.data.object; + +import java.util.ArrayList; +import java.util.List; + +import glowredman.modularmaterials.client.FormattingHandler; +import glowredman.modularmaterials.data.TagHandler; +import glowredman.modularmaterials.data.object.sub.Category; +import glowredman.modularmaterials.data.object.sub.ChemicalState; + +public class MM_Type { + + public boolean enabled = false; + public String tagName = "type_" + this.hashCode(); + public Category category = Category.ITEM; + public ChemicalState state = ChemicalState.SOLID; + public float burnTimeMultiplier = 1.0f; + public float enchantPowerBonusMultiplier = 1.0f; + public float fireSpreadSpeedMultiplier = 1.0f; + public float flammabilityMultiplier = 1.0f; + public float jumpFactorMultiplier = 1.0f; + public float lightLevelMultiplier = 1.0f; + public float resistanceMultiplier = 1.0f; + public float speedFactorMultiplier = 1.0f; + public boolean hasTooltip = true; + public String nameSyntax = TagHandler.PARAM_MATERIAL; + public List tags = new ArrayList<>(); + + @Override + public String toString() { + return String.format("{enabled: %b, tagNames: %s, category: %s, state: %s, burnTimeMultiplier: %f, enchantPowerBonusMultiplier: %f, fireSpreadSpeedMultiplier: %f, flammabilityMultiplier: %f, jumpFactorMultiplier: %f, lightLevelMultiplier: %f, resistanceMultiplier: %f, speedFactorMultiplier: %f, hasTooltip: %b, nameSyntax: %s, tags: %s}", + enabled, tagName, category, state, burnTimeMultiplier, enchantPowerBonusMultiplier, fireSpreadSpeedMultiplier, flammabilityMultiplier, jumpFactorMultiplier, lightLevelMultiplier, resistanceMultiplier, speedFactorMultiplier, hasTooltip, nameSyntax, FormattingHandler.listToString(tags)); + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/AdvRarity.java b/src/main/java/glowredman/modularmaterials/data/object/sub/AdvRarity.java new file mode 100644 index 0000000..380e8a5 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/AdvRarity.java @@ -0,0 +1,47 @@ +package glowredman.modularmaterials.data.object.sub; + +public enum AdvRarity { + COMMON(), + UNCOMMON(), + RARE(), + EPIC(), + BLACK(), + DARK_BLUE(), + DARK_GREEN(), + DARK_AQUA(), + DARK_RED(), + DARK_PURPLE(), + GOLD(), + GRAY(), + DARK_GRAY(), + BLUE(), + GREEN(), + + /**@deprecated Use {@link #RARE}*/ + @Deprecated + AQUA(), + + RED(), + + /**@deprecated Use {@link #EPIC}*/ + @Deprecated + LIGHT_PURPLE(), + + /**@deprecated Use {@link #UNCOMMON}*/ + @Deprecated + YELLOW(), + + /**@deprecated Use {@link #COMMON}*/ + @Deprecated + WHITE(), + + OBFUSCATED(), + BOLD(), + STRIKETHROUGH(), + UNDERLINE(), + ITALIC(); + + private AdvRarity() { + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/BlockProperties.java b/src/main/java/glowredman/modularmaterials/data/object/sub/BlockProperties.java new file mode 100644 index 0000000..39af031 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/BlockProperties.java @@ -0,0 +1,25 @@ +package glowredman.modularmaterials.data.object.sub; + +import java.util.ArrayList; +import java.util.List; + +import glowredman.modularmaterials.client.FormattingHandler; + +public class BlockProperties { + + public float hardness = 5.0f; + public float friction = 0.6f; + public String mapColor = "AUTO"; + public String material = "METAL"; + public boolean requiresToolForDrops = true; + public String sound = "METAL"; + public boolean sticky = false; + public List tags = new ArrayList<>(); + + @Override + public String toString() { + return String.format("{friction: %f, hardness: %f, mapColor: %s, material: %s, sound: %s, sticky: %b, tags: %s}", + friction, hardness, mapColor, material, sound, sticky, FormattingHandler.listToString(tags)); + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/Category.java b/src/main/java/glowredman/modularmaterials/data/object/sub/Category.java new file mode 100644 index 0000000..050298a --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/Category.java @@ -0,0 +1,8 @@ +package glowredman.modularmaterials.data.object.sub; + +public enum Category { + ITEM, + BLOCK, + FLUID; + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/ChemicalState.java b/src/main/java/glowredman/modularmaterials/data/object/sub/ChemicalState.java new file mode 100644 index 0000000..7e12582 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/ChemicalState.java @@ -0,0 +1,7 @@ +package glowredman.modularmaterials.data.object.sub; + +public enum ChemicalState { + SOLID, + LIQUID, + GASEOUS; +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/ColorProperties.java b/src/main/java/glowredman/modularmaterials/data/object/sub/ColorProperties.java new file mode 100644 index 0000000..6a47d56 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/ColorProperties.java @@ -0,0 +1,38 @@ +package glowredman.modularmaterials.data.object.sub; + +public class ColorProperties { + + public int red = 255; + public int green = 255; + public int blue = 255; + public int alpha = 255; + + public ColorProperties() {} + + public ColorProperties(int red, int green, int blue, int alpha) { + this.red = red; + this.green = green; + this.blue = blue; + this.alpha = alpha; + } + + public ColorProperties(int red, int green, int blue) { + this.red = red; + this.green = green; + this.blue = blue; + } + + public int getARGB() { + return alpha << 24 | red << 16 | green << 8 | blue; + } + + public int getRGB() { + return red << 16 | green << 8 | blue; + } + + @Override + public String toString() { + return String.format("{red: %d, green: %d, blue: %d, alpha: %d}", red, green, blue, alpha); + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/FluidProperties.java b/src/main/java/glowredman/modularmaterials/data/object/sub/FluidProperties.java new file mode 100644 index 0000000..12ab61f --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/FluidProperties.java @@ -0,0 +1,57 @@ +package glowredman.modularmaterials.data.object.sub; + +import java.util.ArrayList; +import java.util.List; + +import glowredman.modularmaterials.client.FormattingHandler; + +public class FluidProperties { + + public int boilingTemperature = 374; + public int meltingTemperature = 274; + public int currentTemperature = 288; + public StateBasedProperties gas = new StateBasedProperties(); + public StateBasedProperties liquid = new StateBasedProperties(); + public List tags = new ArrayList<>(); + + @Override + public String toString() { + return String.format("{boilingTemperature: %d, meltingTemperature: %d, currentTemperature: %d, gas: %s, liquid: %s, tags: %s}", + boilingTemperature, meltingTemperature, currentTemperature, gas, liquid, FormattingHandler.listToString(tags)); + } + + public int getTemperature(ChemicalState currentState, ChemicalState reqState) { + if(currentState == reqState) { + return currentTemperature; + } + else if(reqState == ChemicalState.GASEOUS) { + return boilingTemperature; + } + else if(reqState == ChemicalState.LIQUID) { + return meltingTemperature; + } + //should only be returned if either currentState xor reqState is SOLID + return currentTemperature; + } + + public StateBasedProperties propertiesOfState(ChemicalState state) { + return state == ChemicalState.GASEOUS ? gas : liquid; + } + + public static class StateBasedProperties { + + public int density = 1000; + public int viscosity = 1000; + public int luminosity; + public boolean propagatesSkylightDown; + public boolean isPathfindable; + + @Override + public String toString() { + return String.format("{density: %d, viscosity: %d, luminosity: %d, propagatesSkylightDown: %b, isPathfindable: %b}", + density, viscosity, luminosity, propagatesSkylightDown, isPathfindable); + } + + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/ItemProperties.java b/src/main/java/glowredman/modularmaterials/data/object/sub/ItemProperties.java new file mode 100644 index 0000000..8744f14 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/ItemProperties.java @@ -0,0 +1,22 @@ +package glowredman.modularmaterials.data.object.sub; + +import java.util.ArrayList; +import java.util.List; + +import glowredman.modularmaterials.client.FormattingHandler; + +public class ItemProperties { + + public boolean isFireResistant = false; + public boolean isFoil = false; + public int lifespan = 6000; + public AdvRarity rarity = AdvRarity.COMMON; + public List tags = new ArrayList<>(); + + @Override + public String toString() { + return String.format("{isFireResistant: %b, isFoil: %b, lifespan: %d, rarity: %s, tags: %s}", + isFireResistant, isFoil, lifespan, rarity, FormattingHandler.listToString(tags)); + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/OreProperties.java b/src/main/java/glowredman/modularmaterials/data/object/sub/OreProperties.java new file mode 100644 index 0000000..2b100c0 --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/OreProperties.java @@ -0,0 +1,28 @@ +package glowredman.modularmaterials.data.object.sub; + +import java.util.ArrayList; +import java.util.List; + +import glowredman.modularmaterials.client.FormattingHandler; + +public class OreProperties { + + public float friction = 0.0f; + public float hardness = 3.0f; + public float jumpFactor = 1.0f; + public int lightLevel = 0; + public float resistance = 0.0f; + public float speedFactor = 1.0f; + public boolean requiresToolForDrops = true; + public String mapColor = "AUTO"; + public String material = "STONE"; + public String sound = "STONE"; + public List tags = new ArrayList<>(); + + @Override + public String toString() { + return String.format("{friction: %f, hardness: %f, jumpFactor: %f, lightLevel: %d, resistance: %f, requiresToolForDrops: %b, mapColor: %s, material: %s, soundType: %s, tags: %s}", + friction, hardness, jumpFactor, lightLevel, resistance, requiresToolForDrops, mapColor, material, sound, FormattingHandler.listToString(tags)); + } + +} diff --git a/src/main/java/glowredman/modularmaterials/data/object/sub/TooltipProperties.java b/src/main/java/glowredman/modularmaterials/data/object/sub/TooltipProperties.java new file mode 100644 index 0000000..bb89f3a --- /dev/null +++ b/src/main/java/glowredman/modularmaterials/data/object/sub/TooltipProperties.java @@ -0,0 +1,41 @@ +package glowredman.modularmaterials.data.object.sub; + +import glowredman.modularmaterials.client.FormattingHandler; + +public class TooltipProperties { + + public String background = "F0100010"; + public String borderStart = "505000FF"; + public String borderEnd = "5028007F"; + public String[] text = new String[0]; + + @Override + public String toString() { + return String.format("[background: %s, borderStart: %s, borderEnd: %s, text: %s]", background, borderStart, borderEnd, FormattingHandler.arrayToString(text)); + } + + public int getBackground() { + try { + return Integer.parseUnsignedInt(background, 16); + } catch (Exception e) { + return 0xF0100010; + } + } + + public int getBorderStart() { + try { + return Integer.parseUnsignedInt(background, 16); + } catch (Exception e) { + return 0x505000FF; + } + } + + public int getBorderEnd() { + try { + return Integer.parseUnsignedInt(background, 16); + } catch (Exception e) { + return 0x5028007F; + } + } + +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..6ab4b54 --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module glowredman.mmcc { + exports glowredman.modularmaterials.data.object; + exports glowredman.modularmaterials.data.object.sub; + + requires transitive java.desktop; + requires com.google.gson; +} \ No newline at end of file