- Expose the results of addObject and deleteObject on EditorScenePanel
- Allow subclasses of EditorFrame to specify the EditorScenePanel and StageSceneWriter used git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@570 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -28,6 +28,7 @@ import java.awt.EventQueue;
|
|||||||
import java.awt.GraphicsDevice;
|
import java.awt.GraphicsDevice;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
|
||||||
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
@@ -66,6 +67,7 @@ import com.threerings.miso.tile.MisoTileManager;
|
|||||||
|
|
||||||
import com.threerings.stage.data.StageSceneModel;
|
import com.threerings.stage.data.StageSceneModel;
|
||||||
import com.threerings.stage.tools.editor.util.EditorContext;
|
import com.threerings.stage.tools.editor.util.EditorContext;
|
||||||
|
import com.threerings.stage.tools.xml.StageSceneWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A scene editor application that provides facilities for viewing,
|
* A scene editor application that provides facilities for viewing,
|
||||||
@@ -245,13 +247,14 @@ public class EditorApp implements Runnable
|
|||||||
_frame.setSize(1024, 768);
|
_frame.setSize(1024, 768);
|
||||||
SwingUtil.centerWindow(_frame);
|
SwingUtil.centerWindow(_frame);
|
||||||
_frame.setVisible(true);
|
_frame.setVisible(true);
|
||||||
|
SwingUtil.refresh((JComponent)_frame.getContentPane());
|
||||||
}
|
}
|
||||||
_framemgr.start();
|
_framemgr.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EditorFrame createEditorFrame ()
|
protected EditorFrame createEditorFrame ()
|
||||||
{
|
{
|
||||||
return new EditorFrame();
|
return new EditorFrame(new StageSceneWriter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import java.awt.event.WindowEvent;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JInternalFrame;
|
import javax.swing.JInternalFrame;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
@@ -65,8 +64,9 @@ import com.threerings.stage.tools.xml.StageSceneWriter;
|
|||||||
|
|
||||||
public class EditorFrame extends ManagedJFrame
|
public class EditorFrame extends ManagedJFrame
|
||||||
{
|
{
|
||||||
public EditorFrame ()
|
public EditorFrame (StageSceneWriter writer)
|
||||||
{
|
{
|
||||||
|
_writer = writer;
|
||||||
// treat a closing window as a request to quit
|
// treat a closing window as a request to quit
|
||||||
addWindowListener(new WindowAdapter () {
|
addWindowListener(new WindowAdapter () {
|
||||||
public void windowClosing (WindowEvent e) {
|
public void windowClosing (WindowEvent e) {
|
||||||
@@ -87,16 +87,15 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
|
|
||||||
// create the file chooser used for saving and loading scenes
|
// create the file chooser used for saving and loading scenes
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
target = EditorConfig.config.getValue(
|
target = EditorConfig.config.getValue("editor.last_dir",
|
||||||
"editor.last_dir", System.getProperty("user.dir"));
|
System.getProperty("user.dir"));
|
||||||
}
|
}
|
||||||
_chooser = (target == null) ?
|
_chooser = (target == null) ? new JFileChooser() : new JFileChooser(target);
|
||||||
new JFileChooser() : new JFileChooser(target);
|
|
||||||
_chooser.setFileFilter(new FileFilter () {
|
_chooser.setFileFilter(new FileFilter () {
|
||||||
public boolean accept (File f) {
|
@Override public boolean accept (File f) {
|
||||||
return (f.isDirectory() || f.getName().endsWith(".xml"));
|
return (f.isDirectory() || f.getName().endsWith(".xml"));
|
||||||
}
|
}
|
||||||
public String getDescription () {
|
@Override public String getDescription () {
|
||||||
return "XML Files";
|
return "XML Files";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -117,14 +116,12 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
_main = new JPanel(new BorderLayout());
|
_main = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
// set up the scene view panel with a default scene
|
// set up the scene view panel with a default scene
|
||||||
_svpanel = new EditorScenePanel(_ctx, this, _model);
|
_svpanel = createScenePanel();
|
||||||
_main.add(_svpanel, BorderLayout.CENTER);
|
_main.add(_svpanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
// create a toolbar for action selection and other options
|
// create a toolbar for action selection and other options
|
||||||
JPanel upper = new JPanel(
|
JPanel upper = new JPanel(new HGroupLayout(GroupLayout.NONE, GroupLayout.LEFT));
|
||||||
new HGroupLayout(GroupLayout.NONE, GroupLayout.LEFT));
|
upper.add(new EditorToolBarPanel(_ctx.getTileManager(), _model), GroupLayout.FIXED);
|
||||||
upper.add(new EditorToolBarPanel(_ctx.getTileManager(), _model),
|
|
||||||
GroupLayout.FIXED);
|
|
||||||
_sceneInfoPanel = new SceneInfoPanel(_ctx, _model, _svpanel);
|
_sceneInfoPanel = new SceneInfoPanel(_ctx, _model, _svpanel);
|
||||||
upper.add(_sceneInfoPanel, GroupLayout.FIXED);
|
upper.add(_sceneInfoPanel, GroupLayout.FIXED);
|
||||||
_main.add(upper, BorderLayout.NORTH);
|
_main.add(upper, BorderLayout.NORTH);
|
||||||
@@ -170,7 +167,20 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
});
|
});
|
||||||
|
|
||||||
// finally set a default scene
|
// finally set a default scene
|
||||||
newScene();
|
String lastFile = EditorConfig.config.getValue("editor.last_file", "");
|
||||||
|
if (lastFile.equals("")) {
|
||||||
|
newScene();
|
||||||
|
} else {
|
||||||
|
openScene(lastFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the EditorScenePanel to use in this frame.
|
||||||
|
*/
|
||||||
|
protected EditorScenePanel createScenePanel ()
|
||||||
|
{
|
||||||
|
return new EditorScenePanel(_ctx, this, _model);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -508,8 +518,8 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
switch (_chooser.getDialogType()) {
|
switch (_chooser.getDialogType()) {
|
||||||
case JFileChooser.OPEN_DIALOG:
|
case JFileChooser.OPEN_DIALOG:
|
||||||
openScene(filescene.getPath());
|
openScene(filescene.getPath());
|
||||||
EditorConfig.config.setValue(
|
EditorConfig.config.setValue("editor.last_dir", filescene.getParent());
|
||||||
"editor.last_dir", filescene.getParent());
|
EditorConfig.config.setValue("editor.last_file", filescene.getAbsolutePath());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JFileChooser.SAVE_DIALOG:
|
case JFileChooser.SAVE_DIALOG:
|
||||||
@@ -518,8 +528,7 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Log.warning("Wha? Weird dialog type " +
|
Log.warning("Wha? Weird dialog type " + _chooser.getDialogType() + ".");
|
||||||
_chooser.getDialogType() + ".");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -574,7 +583,7 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
protected StageSceneParser _parser = new StageSceneParser();
|
protected StageSceneParser _parser = new StageSceneParser();
|
||||||
|
|
||||||
/** We use this to save scenes. */
|
/** We use this to save scenes. */
|
||||||
protected StageSceneWriter _writer = new StageSceneWriter();
|
protected StageSceneWriter _writer;
|
||||||
|
|
||||||
/** The test tileset loader. */
|
/** The test tileset loader. */
|
||||||
protected TestTileLoader _testLoader;
|
protected TestTileLoader _testLoader;
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ import com.samskivert.swing.Controller;
|
|||||||
import com.samskivert.swing.TGraphics2D;
|
import com.samskivert.swing.TGraphics2D;
|
||||||
import com.samskivert.swing.util.SwingUtil;
|
import com.samskivert.swing.util.SwingUtil;
|
||||||
import com.samskivert.util.RandomUtil;
|
import com.samskivert.util.RandomUtil;
|
||||||
import com.samskivert.util.StringUtil;
|
|
||||||
import com.threerings.util.DirectionCodes;
|
import com.threerings.util.DirectionCodes;
|
||||||
|
|
||||||
import com.threerings.media.tile.ObjectTile;
|
import com.threerings.media.tile.ObjectTile;
|
||||||
@@ -72,7 +71,6 @@ import com.threerings.stage.client.StageScenePanel;
|
|||||||
import com.threerings.stage.data.StageLocation;
|
import com.threerings.stage.data.StageLocation;
|
||||||
import com.threerings.stage.data.StageMisoSceneModel;
|
import com.threerings.stage.data.StageMisoSceneModel;
|
||||||
|
|
||||||
import com.threerings.stage.data.StageScene;
|
|
||||||
import com.threerings.stage.tools.editor.util.EditorContext;
|
import com.threerings.stage.tools.editor.util.EditorContext;
|
||||||
import com.threerings.stage.tools.editor.util.EditorDialogUtil;
|
import com.threerings.stage.tools.editor.util.EditorDialogUtil;
|
||||||
import com.threerings.stage.tools.editor.util.ExtrasPainter;
|
import com.threerings.stage.tools.editor.util.ExtrasPainter;
|
||||||
@@ -609,47 +607,72 @@ public class EditorScenePanel extends StageScenePanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets an object tile at the specified position in the scene (in tile
|
* Sets an object tile at the specified position in the scene (in tile coordinates).
|
||||||
* coordinates).
|
*
|
||||||
|
* @return - the created object or null if an identical object was already in that spot.
|
||||||
*/
|
*/
|
||||||
public void addObject (ObjectTile tile, int fqTileId, int x, int y)
|
public ObjectInfo addObject (ObjectTile tile, int fqTileId, int x, int y)
|
||||||
{
|
{
|
||||||
Point p = new Point(x, y);
|
Point p = new Point(x, y);
|
||||||
adjustObjectCoordsAccordingToGrip(p, tile);
|
adjustObjectCoordsAccordingToGrip(p, tile);
|
||||||
|
return addObject(new ObjectInfo(fqTileId, x, y));
|
||||||
|
}
|
||||||
|
|
||||||
ObjectInfo oinfo = new ObjectInfo(fqTileId, x, y);
|
/**
|
||||||
|
* Adds the given object to the scene.
|
||||||
|
*
|
||||||
|
* @return the added object or null if an identical object was already in that spot.
|
||||||
|
*/
|
||||||
|
public ObjectInfo addObject (ObjectInfo oinfo)
|
||||||
|
{
|
||||||
// first attempt to add it to the appropriate scene block; this
|
// first attempt to add it to the appropriate scene block; this
|
||||||
// will fail if there's already a copy of the same object at this
|
// will fail if there's already a copy of the same object at this
|
||||||
// coordinate
|
// coordinate
|
||||||
if (getBlock(x, y).addObject(oinfo)) {
|
if (getBlock(oinfo.x, oinfo.y).addObject(oinfo)) {
|
||||||
// create an object info and add it to the scene model
|
// create an object info and add it to the scene model
|
||||||
_model.addObject(oinfo);
|
_model.addObject(oinfo);
|
||||||
// recompute our visible object set
|
// recompute our visible object set
|
||||||
recomputeVisible();
|
recomputeVisible();
|
||||||
|
return oinfo;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the object tile at the specified tile coordinates.
|
* Deletes the object tile at the specified tile coordinates.
|
||||||
|
*
|
||||||
|
* @return true - if a matching object was found and deleted.
|
||||||
*/
|
*/
|
||||||
public void deleteObject (SceneObject scobj)
|
public boolean deleteObject (SceneObject scobj)
|
||||||
|
{
|
||||||
|
if (deleteObject(scobj.info)) {
|
||||||
|
// make sure we clear the hover if that's what we're deleting
|
||||||
|
if (_hobject == scobj) {
|
||||||
|
_hobject = null;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Log.warning("Requested to remove unknown object " + scobj + ".");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the given object from the scene.
|
||||||
|
*
|
||||||
|
* @return true - if a matching object was found and deleted.
|
||||||
|
*/
|
||||||
|
public boolean deleteObject (ObjectInfo info)
|
||||||
{
|
{
|
||||||
// remove it from the scene model
|
// remove it from the scene model
|
||||||
if (_model.removeObject(scobj.info)) {
|
if (_model.removeObject(info)) {
|
||||||
// clear the object out of its block
|
// clear the object out of its block
|
||||||
getBlock(scobj.info.x, scobj.info.y).deleteObject(scobj.info);
|
getBlock(info.x, info.y).deleteObject(info);
|
||||||
} else {
|
|
||||||
Log.warning("Requested to remove unknown object " + scobj + ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
// recompute our visible object set
|
// recompute our visible object set
|
||||||
recomputeVisible();
|
recomputeVisible();
|
||||||
|
return true;
|
||||||
// make sure we clear the hover if that's what we're deleting
|
|
||||||
if (_hobject == scobj) {
|
|
||||||
_hobject = null;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user