changeset 321:7ddec4ce99b3

Fixed a crash when removing the layer which the editor camera uses
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 16 Aug 2009 21:35:15 +0000
parents 2020053fffe0
children 3853f8659598
files clients/editor/plugins/LayerTool.py clients/editor/scripts/mapcontroller.py clients/editor/scripts/mapview.py
diffstat 3 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)
 		
--- 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()
--- 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