diff options
Diffstat (limited to 'src/editorui')
-rw-r--r-- | src/editorui/editormain.py | 126 | ||||
-rw-r--r-- | src/editorui/paths.py | 4 |
2 files changed, 126 insertions, 4 deletions
diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py index 5575453..46660f4 100644 --- a/src/editorui/editormain.py +++ b/src/editorui/editormain.py @@ -20,7 +20,7 @@ class KPMapScene(QtGui.QGraphicsScene): self.ticker.setLoopCount(0) self.ticker.setCurveShape(4) self.ticker.setFrameRange(0,100000) - self.ticker.valueChanged.connect(self.thing) + self.ticker.valueChanged.connect(self.viewportUpdateProxy) self.ticker.setUpdateInterval(16.6666666666667) self.grid = False @@ -64,7 +64,7 @@ class KPMapScene(QtGui.QGraphicsScene): @QtCore.pyqtSlot(int) - def thing(self, value): + def viewportUpdateProxy(self, value): self.views()[0].viewport().update() @@ -249,6 +249,68 @@ class KPMapScene(QtGui.QGraphicsScene): srcY += 1 destY += 24 + + elif isinstance(layer, KPPathLayer): + for pnLayer in reversed(KP.mainWindow.pathNodeList.getLayers()): + + # Render Tiles + left, top = pnLayer.cacheBasePos + width, height = pnLayer.cacheSize + right, bottom = left+width, top+height + + if not (width == 0) or (height == 0) or (right < areaLeftT) or (left > areaRightT) or (bottom < areaTopT) or (top > areaBottomT): + + drawLeft = int(max(areaLeftT, left)) + drawRight = int(min(areaRightT, right)) + + drawTop = int(max(areaTopT, top)) + drawBottom = int(min(areaBottomT, bottom)) + + srcY = drawTop - top + destY = drawTop * 24 + + baseSrcX = drawLeft - left + baseDestX = drawLeft * 24 + + rows = pnLayer.cache + tileset = KP.map.loadedTilesets[KP.map.pathNodeTileset] + tileList = tileset.tiles + + for y in xrange(drawTop, drawBottom): + srcX = baseSrcX + destX = baseDestX + row = rows[srcY] + + for x in xrange(drawLeft, drawRight): + tile = row[srcX] + if tile != -1: + painter.drawPixmap(destX, destY, tileList[tile]) + + srcX += 1 + destX += 24 + + srcY += 1 + destY += 24 + + # Render Doodads + try: + toDraw = visibleDoodadsByLayer[pnLayer] + except KeyError: + continue + + for item in reversed(toDraw): + + painter.save() + + 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() + def animateDoodad(self, painter, item): @@ -317,7 +379,7 @@ class KPEditorWidget(QtGui.QGraphicsView): self.setVerticalScrollBar(self.yScrollBar) self.assignNewScene(scene) - + def assignNewScene(self, scene): self.setScene(scene) self.centerOn(0,0) @@ -326,6 +388,8 @@ class KPEditorWidget(QtGui.QGraphicsView): self.objectToPaint = None self.objectIDToPaint = None self.doodadToPaint = None + self.typeToPaint = None + self._resetPaintVars() def _resetPaintVars(self): @@ -430,6 +494,7 @@ class KPEditorWidget(QtGui.QGraphicsView): path = KPPath(sourceNode, destNode) KP.map.pathLayer.paths.append(path) + KP.mainWindow.pathNodeList.addLayer(path) item = KPEditorPath(path) self.scene().addItem(item) @@ -444,6 +509,7 @@ class KPEditorWidget(QtGui.QGraphicsView): node = KPNode() node.position = (x - 12, y - 12) KP.map.pathLayer.nodes.append(node) + KP.mainWindow.pathNodeList.addLayer(node) # Start node => Original path => New node => New path => End node @@ -464,6 +530,7 @@ class KPEditorWidget(QtGui.QGraphicsView): newPath = KPPath(node, endNode, origPath) KP.map.pathLayer.paths.append(newPath) + KP.mainWindow.pathNodeList.addLayer(newPath) pathItem = KPEditorPath(newPath) self.scene().addItem(pathItem) @@ -474,6 +541,7 @@ class KPEditorWidget(QtGui.QGraphicsView): node = KPNode() node.position = (x - 12, y - 12) KP.map.pathLayer.nodes.append(node) + KP.mainWindow.pathNodeList.addLayer(node) item = KPEditorNode(node) self.scene().addItem(item) @@ -499,6 +567,7 @@ class KPEditorWidget(QtGui.QGraphicsView): path = KPPath(sourceNode, node) KP.map.pathLayer.paths.append(path) + KP.mainWindow.pathNodeList.addLayer(path) pathItem = KPEditorPath(path) self.scene().addItem(pathItem) @@ -512,6 +581,57 @@ class KPEditorWidget(QtGui.QGraphicsView): self.paintingItem = item self.paintBeginPosition = (x - 12, y - 12) + elif isinstance(layer, KPPathTileLayer): + if self.typeToPaint == 'object': + paint = self.objectToPaint + if paint is None: return + + clicked = self.mapToScene(event.x(), event.y()) + x, y = clicked.x(), clicked.y() + if x < 0: x = 0 + if y < 0: y = 0 + + x = int(x / 24) + y = int(y / 24) + + obj = KPObject() + obj.position = (x,y) + obj.size = (1,1) + obj.tileset = layer.tileset + obj.kind = paint + obj.updateCache() + layer.objects.append(obj) + layer.updateCache() + + item = KPEditorObject(obj, layer) + self.scene().addItem(item) + + self.painting = obj + self.paintingItem = item + self.paintBeginPosition = (x, y) + + elif self.typeToPaint == 'doodad': + + paint = self.doodadToPaint + if paint is None: return + + clicked = self.mapToScene(event.x(), event.y()) + x, y = clicked.x(), clicked.y() + if x < 0: x = 0 + if y < 0: y = 0 + + obj = KPDoodad() + obj.position = [x,y] + obj.source = paint + obj.setDefaultSize() + layer.doodads.append(obj) + + item = KPEditorDoodad(obj, layer) + self.scene().addItem(item) + + self.painting = obj + self.paintingItem = item + self.paintBeginPosition = (x, y) def _movedWhilePainting(self, event): diff --git a/src/editorui/paths.py b/src/editorui/paths.py index 617e981..55bfac0 100644 --- a/src/editorui/paths.py +++ b/src/editorui/paths.py @@ -325,6 +325,7 @@ class KPEditorNode(KPEditorItem): layer = KP.map.pathLayer layer.nodes.remove(node) + KP.mainWindow.pathNodeList.removeLayer(node) if len(node.exits) == 2: # let's try to join the two! @@ -354,6 +355,7 @@ class KPEditorNode(KPEditorItem): if not nope: joinedPath = KPPath(start, end, pathOne) + KP.mainWindow.pathNodeList.addLayer(joinedPath) layer.paths.append(joinedPath) item = KPEditorPath(joinedPath) self.scene().addItem(item) @@ -501,7 +503,6 @@ class KPEditorPath(QtGui.QGraphicsLineItem): self.setPalette(palette) - class UnlockButton(QtGui.QPushButton): def __init__(self, pathRef): QtGui.QPushButton.__init__(self) @@ -682,6 +683,7 @@ class KPEditorPath(QtGui.QGraphicsLineItem): path = self._pathRef() layer = KP.map.pathLayer + KP.mainWindow.pathNodeList.removeLayer(path) layer.paths.remove(path) |