# HG changeset patch # User cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1250458515 0 # Node ID 7ddec4ce99b3c8911e0d64b9d914e1de0d1af7bc # Parent 2020053fffe0ef3015f1a44358ca251d99762237 Fixed a crash when removing the layer which the editor camera uses diff -r 2020053fffe0 -r 7ddec4ce99b3 clients/editor/plugins/LayerTool.py --- a/clients/editor/plugins/LayerTool.py Sun Aug 16 20:51:02 2009 +0000 +++ b/clients/editor/plugins/LayerTool.py Sun Aug 16 21:35:15 2009 +0000 @@ -123,12 +123,27 @@ def removeSelectedLayer(self): if not self._mapview: return + if self._mapview.getMap().getNumLayers() <= 1: + print "Can't remove the last layer" + return + layer = self.getActiveLayer() if not layer: return self.select_no_layer() - map = self._mapview.getMap() + map = self._mapview.getMap() + + # FIFE will crash if we try to delete the layer which is in use by a camera + # so we will set the camera to another layer instead + for cam in self._editor.getEngine().getView().getCameras(): + if cam.getLocationRef().getMap().getId() == map.getId(): + if cam.getLocation().getLayer().getId() == layer.getId(): + for l in map.getLayers(): + if l.getId() == layer.getId(): continue + cam.getLocationRef().setLayer(l) + break + map.deleteLayer(layer) self.update(self._mapview) diff -r 2020053fffe0 -r 7ddec4ce99b3 clients/editor/scripts/mapcontroller.py --- a/clients/editor/scripts/mapcontroller.py Sun Aug 16 20:51:02 2009 +0000 +++ b/clients/editor/scripts/mapcontroller.py Sun Aug 16 21:35:15 2009 +0000 @@ -294,6 +294,9 @@ def moveCamera(self, screen_x, screen_y): """ Move camera (scroll) by screen_x, screen_y """ + if not self._camera: + return + coords = self._camera.getLocationRef().getMapCoordinates() z = self._camera.getZoom() r = self._camera.getRotation() diff -r 2020053fffe0 -r 7ddec4ce99b3 clients/editor/scripts/mapview.py --- a/clients/editor/scripts/mapview.py Sun Aug 16 20:51:02 2009 +0000 +++ b/clients/editor/scripts/mapview.py Sun Aug 16 21:35:15 2009 +0000 @@ -48,6 +48,17 @@ def getCamera(self): return self._camera + + def setCamera(self, camera): + if not camera: + print "Camera can not be None" + return + + if camera.getLocation().getLayer().getMap() != self._map: + print "Camera is not associated with this map" + return + + self._camera = None def getController(self): return self._controller