Mercurial > fife-parpg
comparison tools/editor/scripts/mapcontroller.py @ 423:04029ebc5670
This fixes an editor bug when you place an instance and select another layer then undo that placement. Same with deleting an instance. [t:443]
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 12 Feb 2010 20:54:45 +0000 |
parents | 9d94f4676d17 |
children | e29fbf84cb41 |
comparison
equal
deleted
inserted
replaced
422:9d94f4676d17 | 423:04029ebc5670 |
---|---|
172 for loc in self._selection: | 172 for loc in self._selection: |
173 instances.extend(self.getInstancesFromPosition(loc.getLayerCoordinates())) | 173 instances.extend(self.getInstancesFromPosition(loc.getLayerCoordinates())) |
174 | 174 |
175 return instances | 175 return instances |
176 | 176 |
177 def getInstancesFromPosition(self, position): | 177 def getInstancesFromPosition(self, position, layer=None): |
178 """ Returns all instances on a specified position """ | 178 """ Returns all instances on a specified position """ |
179 if not self._layer: | 179 if not self._layer and not layer: |
180 if self.debug: print 'No layer assigned in getInstancesFromPosition' | 180 if self.debug: print 'No layer assigned in getInstancesFromPosition' |
181 return | 181 return |
182 if not position: | 182 if not position: |
183 if self.debug: print 'No position assigned in getInstancesFromPosition' | 183 if self.debug: print 'No position assigned in getInstancesFromPosition' |
184 return | 184 return |
185 | 185 |
186 loc = fife.Location(self._layer) | 186 if layer: |
187 loc = fife.Location(layer) | |
188 else: | |
189 loc = fife.Location(self._layer) | |
187 if type(position) == fife.ExactModelCoordinate: | 190 if type(position) == fife.ExactModelCoordinate: |
188 loc.setExactLayerCoordinates(position) | 191 loc.setExactLayerCoordinates(position) |
189 else: | 192 else: |
190 loc.setLayerCoordinates(position) | 193 loc.setLayerCoordinates(position) |
191 | 194 |
192 instances = self._layer.getInstancesAt(loc) | 195 if layer: |
196 instances = layer.getInstancesAt(loc) | |
197 else: | |
198 instances = self._layer.getInstancesAt(loc) | |
193 | 199 |
194 return instances | 200 return instances |
195 | 201 |
196 def getUndoManager(self): | 202 def getUndoManager(self): |
197 """ Returns undo manager """ | 203 """ Returns undo manager """ |
211 | 217 |
212 def _endUndo(self): | 218 def _endUndo(self): |
213 """ Called when a undo operation is done """ | 219 """ Called when a undo operation is done """ |
214 self._undo = False | 220 self._undo = False |
215 | 221 |
216 def placeInstance(self, position, object): | 222 def placeInstance(self, position, object, layer=None): |
217 """ Places an instance of object at position. Any existing instances on position are removed. """ | 223 """ Places an instance of object at position. Any existing instances on position are removed. """ |
218 mname = 'placeInstance' | 224 mname = 'placeInstance' |
219 if not object: | 225 if not object: |
220 if self.debug: print 'No object assigned in %s' % mname | 226 if self.debug: print 'No object assigned in %s' % mname |
221 return | 227 return |
240 return | 246 return |
241 | 247 |
242 self._undomanager.startGroup("Placed instance") | 248 self._undomanager.startGroup("Placed instance") |
243 self.removeInstances(instances) | 249 self.removeInstances(instances) |
244 | 250 |
245 inst = self._layer.createInstance(object, position) | 251 if layer: |
252 inst = layer.createInstance(object, position) | |
253 else: | |
254 inst = self._layer.createInstance(object, position) | |
246 fife.InstanceVisual.create(inst) | 255 fife.InstanceVisual.create(inst) |
247 | 256 |
248 if not self._undo: | 257 if not self._undo: |
249 redocall = cbwa(self.placeInstance, position, object) | 258 redocall = cbwa(self.placeInstance, position, object, inst.getLocation().getLayer()) |
250 undocall = cbwa(self.removeInstanceOfObjectAt, position, object) | 259 undocall = cbwa(self.removeInstanceOfObjectAt, position, object, inst.getLocation().getLayer()) |
251 undoobject = undomanager.UndoObject(undocall, redocall, "Placed instance") | 260 undoobject = undomanager.UndoObject(undocall, redocall, "Placed instance") |
252 self._undomanager.addAction(undoobject) | 261 self._undomanager.addAction(undoobject) |
253 self._undomanager.endGroup() | 262 self._undomanager.endGroup() |
254 | 263 |
255 def removeInstanceOfObjectAt(self, position, object): | 264 def removeInstanceOfObjectAt(self, position, object, layer=None): |
256 """ Removes the first instance of object it can find on position """ | 265 """ Removes the first instance of object it can find on position """ |
257 instances = self.getInstancesFromPosition(position) | 266 instances = self.getInstancesFromPosition(position, layer) |
258 for i in instances: | 267 for i in instances: |
259 if i.getObject().getId() == object.getId() and i.getObject().getNamespace() == object.getNamespace(): | 268 if i.getObject().getId() == object.getId() and i.getObject().getNamespace() == object.getNamespace(): |
260 self.removeInstances([i]) | 269 self.removeInstances([i],layer) |
261 return | 270 return |
262 | 271 |
263 def removeInstances(self, instances): | 272 def removeInstances(self, instances, layer=None): |
264 """ Removes all provided instances """ | 273 """ Removes all provided instances """ |
265 mname = 'removeInstances' | 274 mname = 'removeInstances' |
266 if not instances: | 275 if not instances: |
267 if self.debug: print 'No instances assigned in %s' % mname | 276 if self.debug: print 'No instances assigned in %s' % mname |
268 return | 277 return |
271 if self.debug: print 'Deleting instance ' + i.getObject().getId() + ' at ' + str(i.getLocation().getExactLayerCoordinates()) | 280 if self.debug: print 'Deleting instance ' + i.getObject().getId() + ' at ' + str(i.getLocation().getExactLayerCoordinates()) |
272 | 281 |
273 if not self._undo: | 282 if not self._undo: |
274 object = i.getObject() | 283 object = i.getObject() |
275 position = i.getLocation().getExactLayerCoordinates() | 284 position = i.getLocation().getExactLayerCoordinates() |
276 undocall = cbwa(self.placeInstance, position, object) | 285 undocall = cbwa(self.placeInstance, position, object, i.getLocation().getLayer()) |
277 redocall = cbwa(self.removeInstanceOfObjectAt, position, object) | 286 redocall = cbwa(self.removeInstanceOfObjectAt, position, object, i.getLocation().getLayer()) |
278 undoobject = undomanager.UndoObject(undocall, redocall, "Removed instance") | 287 undoobject = undomanager.UndoObject(undocall, redocall, "Removed instance") |
279 self._undomanager.addAction(undoobject) | 288 self._undomanager.addAction(undoobject) |
280 | 289 |
281 self._layer.deleteInstance(i) | 290 if layer: |
291 layer.deleteInstance(i) | |
292 else: | |
293 self._layer.deleteInstance(i) | |
282 | 294 |
283 def moveInstances(self, instances, moveBy, exact=False): | 295 def moveInstances(self, instances, moveBy, exact=False): |
284 """ Moves provided instances by moveBy. If exact is false, the instances are | 296 """ Moves provided instances by moveBy. If exact is false, the instances are |
285 snapped to closest cell. """ | 297 snapped to closest cell. """ |
286 mname = 'moveInstances' | 298 mname = 'moveInstances' |