trackeditor: fix editing objects when there are multiple object maps

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9191 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: d49a4ec8ba117b2adf9b86d57ddf98bf927efca9
Former-commit-id: 4c706d228d7e2e89a27c1726544700ab5b8f1877
This commit is contained in:
iobyte 2023-10-31 14:28:37 +00:00
parent 3aef0d70ef
commit 08d8a63066
3 changed files with 116 additions and 35 deletions

View file

@ -35,10 +35,13 @@ public class TrackObjectDialog extends JDialog
private int rgb = 0; private int rgb = 0;
private JLabel objectMapLabel = null;
private JComboBox<String> objectMapComboBox = null;
private JCheckBox defaultCheckBox = new JCheckBox(); private JCheckBox defaultCheckBox = new JCheckBox();
private JLabel nameLabel = new JLabel(); private JLabel nameLabel = null;
private JTextField nameTextField = new JTextField(); private JTextField nameTextField = null;
private JLabel objectLabel = new JLabel(); private JLabel objectLabel = new JLabel();
private JComboBox<String> objectComboBox = null; private JComboBox<String> objectComboBox = null;
@ -275,6 +278,7 @@ public class TrackObjectDialog extends JDialog
{ {
setLocationRelativeTo(getParent()); setLocationRelativeTo(getParent());
} }
defaultCheckBox.setText("Default Objects"); defaultCheckBox.setText("Default Objects");
defaultCheckBox.setBounds(120, 10, 150, 23); defaultCheckBox.setBounds(120, 10, 150, 23);
defaultCheckBox.addActionListener(new ActionListener() defaultCheckBox.addActionListener(new ActionListener()
@ -339,12 +343,35 @@ public class TrackObjectDialog extends JDialog
if (isGraphicObject) if (isGraphicObject)
{ {
nameLabel.setText("Name"); nameLabel = new JLabel("Name");
nameLabel.setBounds(10, 37, 120, 23); nameLabel.setBounds(10, 37, 120, 23);
nameTextField.setText(getObjectName()); nameTextField = new JTextField(getObjectName());
nameTextField.setBounds(120, 37, 170, 23); 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<String>();
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.setText("Color");
colorLabel.setBounds(10, 91, 120, 23); colorLabel.setBounds(10, 91, 120, 23);
@ -410,6 +437,11 @@ public class TrackObjectDialog extends JDialog
add(nameLabel); add(nameLabel);
add(nameTextField); add(nameTextField);
} }
else
{
add(objectMapLabel);
add(objectMapComboBox);
}
add(objectLabel); add(objectLabel);
add(objectComboBox); add(objectComboBox);
@ -440,6 +472,19 @@ public class TrackObjectDialog extends JDialog
objectComboBox.setSelectedIndex(objectIndex); 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() private void objectComboBoxChanged()
{ {
if (ignoreActions) if (ignoreActions)
@ -519,9 +564,17 @@ public class TrackObjectDialog extends JDialog
return; return;
} }
if (objectMapComboBox.getSelectedIndex() == -1)
{
JOptionPane.showMessageDialog(this, "No object map selected!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
setRGB(rgb); setRGB(rgb);
if (objectShape != null) if (objectShape != null)
{
if (nameTextField != null)
{ {
String newName = nameTextField.getText(); String newName = nameTextField.getText();
@ -537,6 +590,13 @@ public class TrackObjectDialog extends JDialog
} }
} }
objectShape.setName(newName); objectShape.setName(newName);
}
else
{
String newName = (String) objectComboBox.getSelectedItem();
objectShape.setName(newName);
}
if (graphicObject == null) if (graphicObject == null)
{ {

View file

@ -2357,8 +2357,19 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
else else
{ {
editorFrame.setCurrentObjectGraphic(false); editorFrame.setCurrentObjectGraphic(false);
// TODO handle more than one object map int objectMapIndex = 0;
editorFrame.setCurrentObjectMap(0); for (ObjectMap objectMap : editorFrame.getObjectMaps())
{
for (ObjShapeObject object : objectMap.getObjects())
{
if (shape == object)
{
editorFrame.setCurrentObjectMap(objectMapIndex);
break;
}
}
objectMapIndex++;
}
} }
editorFrame.setCurrentObjectColor(shape.getRGB()); editorFrame.setCurrentObjectColor(shape.getRGB());
editorFrame.setPasteObject(true); editorFrame.setPasteObject(true);
@ -2994,6 +3005,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
if (option == 0) if (option == 0)
{ {
createObjectMap(me); createObjectMap(me);
editorFrame.setCurrentObjectMap(0);
addToObjectMap(me); addToObjectMap(me);
} }
else if (option == 1) else if (option == 1)
@ -3019,7 +3031,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
addToObjects(me); addToObjects(me);
} }
} }
else else // no object maps
{ {
String[] options = {"Yes", "No", "Cancel"}; String[] options = {"Yes", "No", "Cancel"};
@ -3031,23 +3043,9 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
addToObjects(me); addToObjects(me);
} }
else if (option == 1) else if (option == 1)
{
if (editorFrame.getObjectMaps().isEmpty())
{ {
createObjectMap(me); createObjectMap(me);
}
else if (editorFrame.getCurrentObjectMap() == -1)
{
if (editorFrame.getObjectMaps().size() == 1)
{
editorFrame.setCurrentObjectMap(0); editorFrame.setCurrentObjectMap(0);
}
else
{
// TODO pick which one
editorFrame.setCurrentObjectMap(0);
}
}
addToObjectMap(me); addToObjectMap(me);
} }
} }
@ -3163,7 +3161,18 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
private void addToObjectMap(MouseEvent me) 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(); Point2D.Double real = new Point2D.Double();
screenToReal(me, real); screenToReal(me, real);
@ -3181,8 +3190,20 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
if (addObjectDialog.isChanged()) if (addObjectDialog.isChanged())
{ {
objectMap.addObject(object); ObjectMap newObjectMap = editorFrame.getObjectMaps().get(editorFrame.getCurrentObjectMap());
Undo.add(new UndoAddObject(objectMap, object)); 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.setCurrentObjectGraphic(false);
editorFrame.setCurrentObjectColor(object.getRGB()); editorFrame.setCurrentObjectColor(object.getRGB());
editorFrame.documentIsModified = true; editorFrame.documentIsModified = true;

View file

@ -34,7 +34,7 @@ public class Properties
private static Properties instance = new Properties(); private static Properties instance = new Properties();
private Vector<ActionListener> propertiesListeners = new Vector<ActionListener>(); private Vector<ActionListener> propertiesListeners = new Vector<ActionListener>();
public final String title = "sd2-trackeditor"; public final String title = "sd2-trackeditor";
public final String version = "1.3.21"; public final String version = "1.3.22";
private String path; private String path;
private double imageScale = 1; private double imageScale = 1;