diff options
Diffstat (limited to 'src/editorui')
-rw-r--r-- | src/editorui/doodads.py | 58 | ||||
-rw-r--r-- | src/editorui/editormain.py | 69 | ||||
-rw-r--r-- | src/editorui/objects.py | 2 | ||||
-rw-r--r-- | src/editorui/paths.py | 13 |
4 files changed, 75 insertions, 67 deletions
diff --git a/src/editorui/doodads.py b/src/editorui/doodads.py index 632551d..f57502a 100644 --- a/src/editorui/doodads.py +++ b/src/editorui/doodads.py @@ -159,8 +159,8 @@ class KPEditorDoodad(KPEditorItem): itemC.setData(0.0, QtCore.Qt.EditRole) self.model.appendRow([QtGui.QStandardItem("Contiguous"), QtGui.QStandardItem("Linear"), - QtGui.QStandardItem(itemA), QtGui.QStandardItem("X Position"), - QtGui.QStandardItem(itemB), QtGui.QStandardItem(itemC)]) + itemA, QtGui.QStandardItem("X Position"), + itemB, itemC]) def remAnmItem(self): @@ -223,43 +223,10 @@ class KPEditorDoodad(KPEditorItem): rowList.append(data) - - Loop = rowList[0] - Type = rowList[3] - Curve = rowList[1] - Frames = rowList[2] - StartVal = rowList[4] - EndVal = rowList[5] - - Timeline = QtCore.QTimeLine() - - # Interpolate the correct modifier - if Curve == "Linear": - Timeline.setCurveShape(3) - elif Curve == "Sinusoidial": - Timeline.setCurveShape(4) - elif Curve == "Cosinoidial": - Timeline.setCurveShape(5) - - Timeline.setFrameRange(StartVal, EndVal) - - if Loop == "Contiguous": - Timeline.setLoopCount(1) - elif Loop == "Loop": - Timeline.setLoopCount(1000000000) # Dollars *holds pinky to corner of mouth* - elif Loop == "Reversible Loop": - Timeline.setLoopCount(1) - Timeline.finished.connect(Timeline.toggleDirection) - Timeline.finished.connect(Timeline.start) - - Timeline.setDuration(Frames/60.0*1000) # Wii goes at 60 frames per second - - rowList.append(Timeline) - KP.mapScene.timeLines.append(Timeline) - anmList.append(rowList) - + doodad.animations = anmList + doodad.setupAnimations() self.update() @@ -281,13 +248,11 @@ class KPEditorDoodad(KPEditorItem): self._doodadRef = weakref.ref(doodad) self._layerRef = weakref.ref(layer) - # TODO: refactor this to store source doodad data under KP.map - sourceItem = KP.mainWindow.doodadSelector.getDoodad(doodad.index) - self._sourceRef = weakref.ref(sourceItem) - self.resizing = None self.rotating = None + self.source = doodad.source + self._updatePixmap() self._updatePosition() self._updateSize() @@ -297,14 +262,16 @@ class KPEditorDoodad(KPEditorItem): self.setAcceptHoverEvents(True) + if len(doodad.animations) > 0: + doodad.setupAnimations() + if not hasattr(KPEditorDoodad, 'SELECTION_PEN'): KPEditorDoodad.SELECTION_PEN = QtGui.QPen(Qt.red, 1, Qt.DotLine) def _updatePixmap(self): - source = self._sourceRef() - pixmap = source.icon().pixmap(source.icon().availableSizes()[0]) + pixmap = self.source[1] self.prepareGeometryChange() w, h = pixmap.width(), pixmap.height() @@ -314,11 +281,15 @@ class KPEditorDoodad(KPEditorItem): def _updatePosition(self): # NOTE: EditorDoodads originate at the centre, not the top left like the others + self.ignoreMovement = True + doodad = self._doodadRef() x,y = doodad.position w,h = doodad.size self.setPos(x+floor(w/2.0), y+floor(h/2.0)) + self.ignoreMovement = False + def _updateSize(self): self.prepareGeometryChange() @@ -514,6 +485,7 @@ class KPEditorDoodad(KPEditorItem): layer = self._layerRef() layer.objects.remove(doodad) + doodad.cleanUpAnimations() if withItem: self.scene().removeItem(self) diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py index 136eee1..5575453 100644 --- a/src/editorui/editormain.py +++ b/src/editorui/editormain.py @@ -17,7 +17,7 @@ class KPMapScene(QtGui.QGraphicsScene): self.playing = False self.timeLines = [] self.ticker = QtCore.QTimeLine(100000) - self.ticker.setLoopCount(10) + self.ticker.setLoopCount(0) self.ticker.setCurveShape(4) self.ticker.setFrameRange(0,100000) self.ticker.valueChanged.connect(self.thing) @@ -25,6 +25,23 @@ class KPMapScene(QtGui.QGraphicsScene): self.grid = False + # create an item for everything in the map + for layer in KP.map.layers: + if isinstance(layer, KPTileLayer): + for obj in layer.objects: + self.addItem(KPEditorObject(obj, layer)) + elif isinstance(layer, KPDoodadLayer): + for obj in layer.objects: + self.addItem(KPEditorDoodad(obj, layer)) + elif isinstance(layer, KPPathLayer): + for node in layer.nodes: + self.addItem(KPEditorNode(node)) + + for path in layer.paths: + self.addItem(KPEditorPath(path)) + + layer.setActivated(False) + def playPause(self): if self.playing == False: @@ -247,30 +264,30 @@ class KPMapScene(QtGui.QGraphicsScene): # Anm Interpolations are Linear, Sinusoidial, Cosinoidial # Anm Types are X Position, Y Position, Angle, X Scale, Y Scale, Opacity - for anm in animations: + if len(animations) > 0: + for anm, Timeline in zip(animations, doodad.timelines): - Type = anm[3] - Timeline = anm[6] - - modifier = Timeline.currentFrame() + Type = anm[3] + + modifier = Timeline.currentFrame() - if Type == "X Position": - posRect.adjust(modifier, 0, modifier, 0) + if Type == "X Position": + posRect.adjust(modifier, 0, modifier, 0) - elif Type == "Y Position": - posRect.adjust(0, modifier, 0, modifier) + elif Type == "Y Position": + posRect.adjust(0, modifier, 0, modifier) - elif Type == "Angle": - transform.rotate(modifier) + elif Type == "Angle": + transform.rotate(modifier) - elif Type == "X Scale": - posRect.setWidth(posRect.width()*modifier/100.0) - - elif Type == "Y Scale": - posRect.setHeight(posRect.height()*modifier/100.0) + elif Type == "X Scale": + posRect.setWidth(posRect.width()*modifier/100.0) + + elif Type == "Y Scale": + posRect.setHeight(posRect.height()*modifier/100.0) - elif Type == "Opacity": - painter.setOpacity(modifier/100.0) + elif Type == "Opacity": + painter.setOpacity(modifier/100.0) painter.setWorldTransform(transform, True) painter.drawPixmap(posRect.x(), posRect.y(), posRect.width(), posRect.height(), item.pixmap) @@ -299,11 +316,16 @@ class KPEditorWidget(QtGui.QGraphicsView): self.yScrollBar = QtGui.QScrollBar(Qt.Vertical, parent) self.setVerticalScrollBar(self.yScrollBar) + self.assignNewScene(scene) + + def assignNewScene(self, scene): + self.setScene(scene) self.centerOn(0,0) # set up stuff for painting - self.paintNext = None - self.paintNextID = None + self.objectToPaint = None + self.objectIDToPaint = None + self.doodadToPaint = None self._resetPaintVars() def _resetPaintVars(self): @@ -314,11 +336,11 @@ class KPEditorWidget(QtGui.QGraphicsView): def _tryToPaint(self, event): '''Called when a paint attempt is initiated''' - paint = self.paintNext layer = self.scene().currentLayer if not layer.visible: return if isinstance(layer, KPTileLayer): + paint = self.objectToPaint if paint is None: return clicked = self.mapToScene(event.x(), event.y()) @@ -346,6 +368,7 @@ class KPEditorWidget(QtGui.QGraphicsView): self.paintBeginPosition = (x, y) elif isinstance(layer, KPDoodadLayer): + paint = self.doodadToPaint if paint is None: return clicked = self.mapToScene(event.x(), event.y()) @@ -355,7 +378,7 @@ class KPEditorWidget(QtGui.QGraphicsView): obj = KPDoodad() obj.position = [x,y] - obj.index = self.paintNextID + obj.source = paint obj.setDefaultSize() layer.objects.append(obj) diff --git a/src/editorui/objects.py b/src/editorui/objects.py index 1ae46f7..975b365 100644 --- a/src/editorui/objects.py +++ b/src/editorui/objects.py @@ -26,8 +26,10 @@ class KPEditorObject(KPEditorItem): def _updatePosition(self): self.ignoreMovement = True + x,y = self._objRef().position self.setPos(x*24, y*24) + self.ignoreMovement = False def _updateSize(self): diff --git a/src/editorui/paths.py b/src/editorui/paths.py index c1579be..2f4388a 100644 --- a/src/editorui/paths.py +++ b/src/editorui/paths.py @@ -230,10 +230,14 @@ class KPEditorNode(KPEditorItem): def _updatePosition(self): + self.ignoreMovement = True + node = self._nodeRef() x, y = node.position self.setPos(x+12, y+12) + self.ignoreMovement = False + def _itemMoved(self, oldX, oldY, newX, newY): node = self._nodeRef() @@ -440,7 +444,13 @@ class KPEditorPath(QtGui.QGraphicsLineItem): # Connections - self.ExclusiveButtons.buttonReleased.connect(self.updatePathAnim) + # regular connect doesn't work for some reason... + #self.ExclusiveButtons.buttonReleased.connect(self.updatePathAnim) + QtCore.QObject.connect( + self.ExclusiveButtons, + QtCore.SIGNAL('buttonReleased(int)'), + self.updatePathAnim) + self.moveSpeedSpinner.valueChanged.connect(self.updateMoveSpeed) self.linkedLayer.currentIndexChanged.connect(self.updateLinkLayer) @@ -464,6 +474,7 @@ class KPEditorPath(QtGui.QGraphicsLineItem): path = self._pathRef() path.animation = buttonID + print path.animation path.qtItem.update() |