# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1266012058 0 # Node ID e29fbf84cb419294358f0438629526f2c45ec067 # Parent 04029ebc5670cb6f78b9e39a64aeba9c4150e878 Adding undo/redo support for moving instances. diff -r 04029ebc5670 -r e29fbf84cb41 tools/editor/scripts/mapcontroller.py --- a/tools/editor/scripts/mapcontroller.py Fri Feb 12 20:54:45 2010 +0000 +++ b/tools/editor/scripts/mapcontroller.py Fri Feb 12 22:00:58 2010 +0000 @@ -292,9 +292,11 @@ else: self._layer.deleteInstance(i) - def moveInstances(self, instances, moveBy, exact=False): + def moveInstances(self, instances, moveBy, exact=False, origLoc=None, origFacing=None): """ Moves provided instances by moveBy. If exact is false, the instances are - snapped to closest cell. """ + snapped to closest cell. origLoc and origFacing are only set when an undo/redo + operation takes place and will have no effect and should not be used under normal + circumstances.""" mname = 'moveInstances' if not self._layer: if self.debug: print 'No layer assigned in %s' % mname @@ -317,8 +319,21 @@ newCoords = loc.getLayerCoordinates() + moveBy loc.setLayerCoordinates(newCoords) f.setLayerCoordinates(f.getLayerCoordinates() + moveBy) - i.setLocation(loc) - i.setFacingLocation(f) + + if not self._undo: + undocall = cbwa(self.moveInstances, [i], moveBy, exact, i.getLocation(), i.getFacingLocation()) + redocall = cbwa(self.moveInstances, [i], moveBy, exact, i.getLocation(), i.getFacingLocation()) + undoobject = undomanager.UndoObject(undocall, redocall, "Moved instance") + self._undomanager.addAction(undoobject) + i.setLocation(loc) + i.setFacingLocation(f) + + else: + assert(origLoc) + assert(origFacing) + i.setLocation(origLoc) + i.setFacingLocation(origFacing) + def rotateCounterClockwise(self): """ Rotates map counterclockwise by 90 degrees """