This commit is contained in:
Martin Haye 2015-05-31 19:03:41 -07:00
commit 234fadabe1
4 changed files with 37 additions and 5 deletions

View File

@ -460,6 +460,11 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
}
}
public void removeScript(Script script) {
getCurrentMap().removeScriptFromMap(script);
redraw();
}
public static enum DrawMode {
Pencil1px, Pencil3px, Pencil5px, FilledRect, Eraser

View File

@ -213,4 +213,12 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
public static boolean isNullTile(String tileId) {
return tileId.equalsIgnoreCase(NULL_TILE_ID);
}
public void removeScriptFromMap(Script script) {
script.getLocationTrigger().clear();
locationScripts.values().stream().filter((scripts) -> !(scripts == null)).forEach((scripts) -> {
scripts.remove(script);
});
backingMap.getScripts().getScript().remove(script);
}
}

View File

@ -28,8 +28,14 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
protected void onScriptDeletePressed(ActionEvent event) {
Script script = globalScriptList.getSelectionModel().getSelectedItem();
if (script != null) {
getCurrentEditor().removeScript(script);
redrawGlobalScripts();
UIAction.confirm(
"Are you sure you want to delete the script "
+ script.getName()
+ "? There is no undo for this!",
() -> {
getCurrentEditor().removeScript(script);
redrawGlobalScripts();
}, null);
}
}

View File

@ -195,7 +195,18 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
@Override
public void onMapScriptDeletePressed(ActionEvent event) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
Script script = mapScriptsList.getSelectionModel().getSelectedItem();
if (script != null) {
UIAction.confirm(
"Are you sure you want to delete the script "
+ script.getName()
+ "? There is no undo for this!",
() -> {
getCurrentEditor().removeScript(script);
redrawMapScripts();
},
null);
};
}
@Override
@ -288,8 +299,10 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
bind(mapNameField.textProperty(), stringProp(m, "name"));
// bind(mapWidthField.textProperty(), intProp(m, "width"));
// bind(mapWrapAround.selectedProperty(),boolProp(m, "wrap"));
} catch (NoSuchMethodException ex) {
Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(ApplicationUIControllerImpl.class
.getName()).log(Level.SEVERE, null, ex);
}
MapEditor e = new MapEditor();
e.setEntity(m);
@ -386,7 +399,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
@Override
public ListCell<Script> call(ListView<Script> param) {
final ListCell<Script> cell = new ListCell<Script>() {
@Override
protected void updateItem(Script item, boolean empty) {
super.updateItem(item, empty);