diff options
author | Colin Noga <Tempus@Spectrum-Song.local> | 2011-11-25 03:32:29 -0600 |
---|---|---|
committer | Colin Noga <Tempus@Spectrum-Song.local> | 2011-11-25 03:32:29 -0600 |
commit | b108fc94779df34fe498b8a2b5ce6a155711455c (patch) | |
tree | e57d6bbcfdbb43ddd67621c5aa999cc7a075ba19 /src | |
parent | 123ae369ff7e84f75e16c1ada8f248493b35aea6 (diff) | |
download | koopatlas-b108fc94779df34fe498b8a2b5ce6a155711455c.tar.gz koopatlas-b108fc94779df34fe498b8a2b5ce6a155711455c.zip |
ANIMATIONS AND PREVIEWING ARE WORKING. They look da bomb.
Other issues: animation ui editors don't always have proper range settings, deco charatcers, steps, etc. The animation pop up is a bit unruly, tends to move around.'
'
Diffstat (limited to 'src')
-rw-r--r-- | src/editorui/doodads.py | 39 | ||||
-rw-r--r-- | src/editorui/editormain.py | 92 | ||||
-rw-r--r-- | src/ui.py | 13 |
3 files changed, 137 insertions, 7 deletions
diff --git a/src/editorui/doodads.py b/src/editorui/doodads.py index 52d09fc..632551d 100644 --- a/src/editorui/doodads.py +++ b/src/editorui/doodads.py @@ -220,13 +220,48 @@ class KPEditorDoodad(KPEditorItem): data = data.toFloat()[0] else: data = str(data) + rowList.append(data) - anmList.append(tuple(rowList)) + + 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 - print anmList + self.update() class HiddenProxy(QtGui.QGraphicsProxyWidget): diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py index f25452b..4d8e1af 100644 --- a/src/editorui/editormain.py +++ b/src/editorui/editormain.py @@ -14,7 +14,40 @@ class KPMapScene(QtGui.QGraphicsScene): self.currentLayer = None KP.mapScene = self - + self.playing = False + self.timeLines = [] + self.ticker = QtCore.QTimeLine(100000) + self.ticker.setLoopCount(10) + self.ticker.setCurveShape(4) + self.ticker.setFrameRange(0,100000) + self.ticker.valueChanged.connect(self.thing) + self.ticker.setUpdateInterval + + + def playPause(self): + if self.playing == False: + self.playing = True + self.views()[0].setViewportUpdateMode(0) + self.ticker.start() + + for timeline in self.timeLines: + timeline.start() + self.views()[0].update() + + else: + self.playing = False + self.views()[0].setViewportUpdateMode(1) + self.ticker.stop() + + for timeline in self.timeLines: + timeline.stop() + self.views()[0].update() + + + @QtCore.pyqtSlot(int) + def thing(self, value): + self.views()[0].update() + def drawBackground(self, painter, rect): painter.fillRect(rect, QtGui.QColor(209, 218, 236)) @@ -55,13 +88,19 @@ class KPMapScene(QtGui.QGraphicsScene): continue for item in reversed(toDraw): + painter.save() - painter.setWorldTransform(item.sceneTransform(), True) - w, h = item._doodadRef().size - p = item._boundingRect - painter.drawPixmap(p.x(), p.y(), p.width(), p.height(), item.pixmap) + + if self.playing == False: + painter.setWorldTransform(item.sceneTransform(), True) + p = item._boundingRect + painter.drawPixmap(p.x(), p.y(), p.width(), p.height(), item.pixmap) + + else: + self.animateDoodad(painter, item) painter.restore() + elif isinstance(layer, KPTileLayer): left, top = layer.cacheBasePos width, height = layer.cacheSize @@ -109,6 +148,49 @@ class KPMapScene(QtGui.QGraphicsScene): destY += 24 + def animateDoodad(self, painter, item): + + doodad = item._doodadRef() + animations = doodad.animations + + transform = item.sceneTransform() + posRect = item._boundingRect.adjusted(0,0,0,0) + + # Anm indexes are Looping, Interpolation, Frame Len, Type, Start Value, End Value + # + # Anm Loops are Contiguous, Loop, Reversible Loop + # Anm Interpolations are Linear, Sinusoidial, Cosinoidial + # Anm Types are X Position, Y Position, Angle, X Scale, Y Scale, Opacity + + for anm in animations: + + Type = anm[3] + Timeline = anm[6] + + modifier = Timeline.currentFrame() + + if Type == "X Position": + posRect.adjust(modifier, 0, modifier, 0) + + elif Type == "Y Position": + posRect.adjust(0, modifier, 0, 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 == "Opacity": + painter.setOpacity(modifier/100.0) + + painter.setWorldTransform(transform, True) + painter.drawPixmap(posRect.x(), posRect.y(), posRect.width(), posRect.height(), item.pixmap) + + def setCurrentLayer(self, layer): if self.currentLayer is not None: self.currentLayer.setActivated(False) @@ -35,8 +35,20 @@ class KPLayerList(QtGui.QWidget): self.actRemove = tb.addAction(KP.icon('LayerRemove'), 'Remove', self.removeLayer) self.actMoveUp = tb.addAction(QtGui.QIcon(), 'Move Up', self.moveUp) self.actMoveDown = tb.addAction(QtGui.QIcon(), 'Move Down', self.moveDown) + self.actPlayPause = tb.addAction(KP.icon('APlay'), 'Play', self.toggleAnimatingScene) + playPaused = QtCore.pyqtSignal() + + def toggleAnimatingScene(self): + self.playPaused.emit() + if self.actPlayPause.text() == 'Play': + self.actPlayPause.setIcon(KP.icon('AStop')) + self.actPlayPause.setText('Stop') + else: + self.actPlayPause.setIcon(KP.icon('APlay')) + self.actPlayPause.setText('Play') + def setButtonStates(self): index = self.selectedLayerIndex() @@ -416,6 +428,7 @@ class KPMainWindow(QtGui.QMainWindow): self.layerListDock.setWidget(self.layerList) self.layerList.selectedLayerChanged.connect(self.handleSelectedLayerChanged) + self.layerList.playPaused.connect(self.scene.playPause) self.objectSelector = KPObjectSelector() self.objectSelector.objChanged.connect(self.handleSelectedObjectChanged) |