diff --git a/src/tools/trackeditor/gui/TrackObjectDialog.java b/src/tools/trackeditor/gui/TrackObjectDialog.java index 183683ea8..15b709bd3 100644 --- a/src/tools/trackeditor/gui/TrackObjectDialog.java +++ b/src/tools/trackeditor/gui/TrackObjectDialog.java @@ -34,11 +34,14 @@ public class TrackObjectDialog extends JDialog private boolean isGraphicObject = false; private int rgb = 0; + + private JLabel objectMapLabel = null; + private JComboBox objectMapComboBox = null; private JCheckBox defaultCheckBox = new JCheckBox(); - private JLabel nameLabel = new JLabel(); - private JTextField nameTextField = new JTextField(); + private JLabel nameLabel = null; + private JTextField nameTextField = null; private JLabel objectLabel = new JLabel(); private JComboBox objectComboBox = null; @@ -275,6 +278,7 @@ public class TrackObjectDialog extends JDialog { setLocationRelativeTo(getParent()); } + defaultCheckBox.setText("Default Objects"); defaultCheckBox.setBounds(120, 10, 150, 23); defaultCheckBox.addActionListener(new ActionListener() @@ -339,12 +343,35 @@ public class TrackObjectDialog extends JDialog if (isGraphicObject) { - nameLabel.setText("Name"); + nameLabel = new JLabel("Name"); nameLabel.setBounds(10, 37, 120, 23); - nameTextField.setText(getObjectName()); + nameTextField = new JTextField(getObjectName()); nameTextField.setBounds(120, 37, 170, 23); } + else + { + if (editorFrame.getObjectMaps().size() > 0) + { + objectMapLabel = new JLabel("Object Map"); + objectMapLabel.setBounds(10, 37, 120, 23); + + objectMapComboBox = new JComboBox(); + objectMapComboBox.setBounds(120, 37, 170, 23); + for (int i = 0; i < editorFrame.getObjectMaps().size(); i++) + { + objectMapComboBox.addItem(editorFrame.getObjectMaps().get(i).getName()); + } + objectMapComboBox.setSelectedIndex(editorFrame.getCurrentObjectMap()); + objectMapComboBox.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + objectMapComboBoxChanged(); + } + }); + } + } colorLabel.setText("Color"); colorLabel.setBounds(10, 91, 120, 23); @@ -410,6 +437,11 @@ public class TrackObjectDialog extends JDialog add(nameLabel); add(nameTextField); } + else + { + add(objectMapLabel); + add(objectMapComboBox); + } add(objectLabel); add(objectComboBox); @@ -440,6 +472,19 @@ public class TrackObjectDialog extends JDialog objectComboBox.setSelectedIndex(objectIndex); } + private void objectMapComboBoxChanged() + { + if (ignoreActions) + return; + if (objectMapComboBox.getSelectedIndex() == -1) + { + JOptionPane.showMessageDialog(this, "No object map selected!", "Error", JOptionPane.ERROR_MESSAGE); + return; + } + editorFrame.setCurrentObjectMap(objectMapComboBox.getSelectedIndex()); + changed = true; + } + private void objectComboBoxChanged() { if (ignoreActions) @@ -518,25 +563,40 @@ public class TrackObjectDialog extends JDialog JOptionPane.showMessageDialog(this, "No object selected!", "Error", JOptionPane.ERROR_MESSAGE); return; } + + if (objectMapComboBox.getSelectedIndex() == -1) + { + JOptionPane.showMessageDialog(this, "No object map selected!", "Error", JOptionPane.ERROR_MESSAGE); + return; + } setRGB(rgb); if (objectShape != null) { - String newName = nameTextField.getText(); - - for (GraphicObject object : editorFrame.getGraphicObjects()) + if (nameTextField != null) { - if (object.getShape() != objectShape) + String newName = nameTextField.getText(); + + for (GraphicObject object : editorFrame.getGraphicObjects()) { - if (object.getName().equals(newName)) + if (object.getShape() != objectShape) { - JOptionPane.showMessageDialog(this, "Object name already used!", "Error", JOptionPane.ERROR_MESSAGE); - return; + if (object.getName().equals(newName)) + { + JOptionPane.showMessageDialog(this, "Object name already used!", "Error", JOptionPane.ERROR_MESSAGE); + return; + } } } + objectShape.setName(newName); + } + else + { + String newName = (String) objectComboBox.getSelectedItem(); + + objectShape.setName(newName); } - objectShape.setName(newName); if (graphicObject == null) { diff --git a/src/tools/trackeditor/gui/view/CircuitView.java b/src/tools/trackeditor/gui/view/CircuitView.java index dda72aadb..91d51ae62 100644 --- a/src/tools/trackeditor/gui/view/CircuitView.java +++ b/src/tools/trackeditor/gui/view/CircuitView.java @@ -2357,8 +2357,19 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene else { editorFrame.setCurrentObjectGraphic(false); - // TODO handle more than one object map - editorFrame.setCurrentObjectMap(0); + int objectMapIndex = 0; + for (ObjectMap objectMap : editorFrame.getObjectMaps()) + { + for (ObjShapeObject object : objectMap.getObjects()) + { + if (shape == object) + { + editorFrame.setCurrentObjectMap(objectMapIndex); + break; + } + } + objectMapIndex++; + } } editorFrame.setCurrentObjectColor(shape.getRGB()); editorFrame.setPasteObject(true); @@ -2994,6 +3005,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene if (option == 0) { createObjectMap(me); + editorFrame.setCurrentObjectMap(0); addToObjectMap(me); } else if (option == 1) @@ -3019,7 +3031,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene addToObjects(me); } } - else + else // no object maps { String[] options = {"Yes", "No", "Cancel"}; @@ -3032,22 +3044,8 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene } else if (option == 1) { - if (editorFrame.getObjectMaps().isEmpty()) - { - createObjectMap(me); - } - else if (editorFrame.getCurrentObjectMap() == -1) - { - if (editorFrame.getObjectMaps().size() == 1) - { - editorFrame.setCurrentObjectMap(0); - } - else - { - // TODO pick which one - editorFrame.setCurrentObjectMap(0); - } - } + createObjectMap(me); + editorFrame.setCurrentObjectMap(0); addToObjectMap(me); } } @@ -3163,7 +3161,18 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene private void addToObjectMap(MouseEvent me) { - ObjectMap objectMap = editorFrame.getObjectMaps().get(editorFrame.getCurrentObjectMap()); + ObjectMap objectMap = null; + if (editorFrame.getCurrentObjectMap() == -1) + { + if (editorFrame.getObjectMaps().isEmpty()) + { + createObjectMap(me); + } + editorFrame.setCurrentObjectMap(0); + } + + objectMap = editorFrame.getObjectMaps().get(editorFrame.getCurrentObjectMap()); + Point2D.Double real = new Point2D.Double(); screenToReal(me, real); @@ -3181,8 +3190,20 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene if (addObjectDialog.isChanged()) { - objectMap.addObject(object); - Undo.add(new UndoAddObject(objectMap, object)); + ObjectMap newObjectMap = editorFrame.getObjectMaps().get(editorFrame.getCurrentObjectMap()); + if (newObjectMap != objectMap) + { + if (objectMap.getImageWidth() != newObjectMap.getImageWidth() || + objectMap.getImageHeight() != newObjectMap.getImageHeight()) + { + // convert location to image coordinates + realToImage(real, newObjectMap.getImageWidth(), newObjectMap.getImageHeight(), imageXY); + object.setImageX(imageXY[0]); + object.setImageY(imageXY[1]); + } + } + newObjectMap.addObject(object); + Undo.add(new UndoAddObject(newObjectMap, object)); editorFrame.setCurrentObjectGraphic(false); editorFrame.setCurrentObjectColor(object.getRGB()); editorFrame.documentIsModified = true; diff --git a/src/tools/trackeditor/utils/Properties.java b/src/tools/trackeditor/utils/Properties.java index 5ecb48c12..184070580 100644 --- a/src/tools/trackeditor/utils/Properties.java +++ b/src/tools/trackeditor/utils/Properties.java @@ -34,7 +34,7 @@ public class Properties private static Properties instance = new Properties(); private Vector propertiesListeners = new Vector(); public final String title = "sd2-trackeditor"; - public final String version = "1.3.21"; + public final String version = "1.3.22"; private String path; private double imageScale = 1;