Mercurial > fife-parpg
changeset 424:e29fbf84cb41
Adding undo/redo support for moving instances.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 12 Feb 2010 22:00:58 +0000 |
parents | 04029ebc5670 |
children | ad7969d9460b |
files | tools/editor/scripts/mapcontroller.py |
diffstat | 1 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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 """