comparison clients/editor/plugins/LayerTool.py @ 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 62ec3b530cc6
children 3853f8659598
comparison
equal deleted inserted replaced
320:2020053fffe0 321:7ddec4ce99b3
121 self.container.position = (50, 200) 121 self.container.position = (50, 200)
122 122
123 def removeSelectedLayer(self): 123 def removeSelectedLayer(self):
124 if not self._mapview: return 124 if not self._mapview: return
125 125
126 if self._mapview.getMap().getNumLayers() <= 1:
127 print "Can't remove the last layer"
128 return
129
126 layer = self.getActiveLayer() 130 layer = self.getActiveLayer()
127 if not layer: return 131 if not layer: return
128 132
129 self.select_no_layer() 133 self.select_no_layer()
130 134
131 map = self._mapview.getMap() 135 map = self._mapview.getMap()
136
137 # FIFE will crash if we try to delete the layer which is in use by a camera
138 # so we will set the camera to another layer instead
139 for cam in self._editor.getEngine().getView().getCameras():
140 if cam.getLocationRef().getMap().getId() == map.getId():
141 if cam.getLocation().getLayer().getId() == layer.getId():
142 for l in map.getLayers():
143 if l.getId() == layer.getId(): continue
144 cam.getLocationRef().setLayer(l)
145 break
146
132 map.deleteLayer(layer) 147 map.deleteLayer(layer)
133 self.update(self._mapview) 148 self.update(self._mapview)
134 149
135 def showLayerWizard(self): 150 def showLayerWizard(self):
136 if not self._mapview: return 151 if not self._mapview: return