diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/editorui/editormain.py | 4 | ||||
-rw-r--r-- | src/editorui/paths.py | 135 | ||||
-rw-r--r-- | src/mapdata.py | 10 |
3 files changed, 133 insertions, 16 deletions
diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py index 297ac34..8ffd034 100644 --- a/src/editorui/editormain.py +++ b/src/editorui/editormain.py @@ -307,8 +307,8 @@ class KPEditorWidget(QtGui.QGraphicsView): KP.map.pathLayer.paths.append(path) - pathitem = KPEditorPath(path) - self.scene().addItem(pathitem) + pathItem = KPEditorPath(path) + self.scene().addItem(pathItem) # Switch the selection to the recently drawn node, so you can keep on rolling. diff --git a/src/editorui/paths.py b/src/editorui/paths.py index c5a51b6..ad81fa0 100644 --- a/src/editorui/paths.py +++ b/src/editorui/paths.py @@ -73,7 +73,6 @@ class KPEditorNode(KPEditorItem): self.setPalette(self.PALETTE) - def __init__(self, node): KPEditorItem.__init__(self) @@ -108,7 +107,6 @@ class KPEditorNode(KPEditorItem): self._updatePosition() - @QtCore.pyqtSlot(int) def stateChange(self, state): @@ -145,7 +143,6 @@ class KPEditorNode(KPEditorItem): node.level[1] = stage - def _updatePosition(self): node = self._nodeRef() x, y = node.position @@ -162,6 +159,7 @@ class KPEditorNode(KPEditorItem): def paint(self, painter, option, widget): + painter.setRenderHint(QtGui.QPainter.Antialiasing) node = self._nodeRef() selectionRect = None @@ -208,8 +206,6 @@ class KPEditorNode(KPEditorItem): self.stageProxy.hide() - - def remove(self, withItem=False): node = self._nodeRef() layer = KP.map.pathLayer @@ -261,6 +257,98 @@ class KPEditorNode(KPEditorItem): class KPEditorPath(QtGui.QGraphicsLineItem): + + + class UnlockButton(QtGui.QPushButton): + def __init__(self, pathRef): + QtGui.QPushButton.__init__(self) + + self.setIconSize(QtCore.QSize(32,32)) + self.setFixedSize(64,64) + + self.iconList = [QtGui.QIcon("Resources/Key.png"), + QtGui.QIcon("Resources/SecretKey.png")] + + self.unlockIcon = QtGui.QIcon("Resources/Unlock.png") + self.arrowIcon = QtGui.QIcon("Resources/KeyArrow.png") + + self._pathRef = pathRef + + self.secret = 0 + self.path = 0 + + if not hasattr(KPEditorPath.UnlockButton, 'PALETTE'): + KPEditorPath.UnlockButton.PALETTE = QtGui.QPalette(Qt.transparent) + + self.setPalette(self.PALETTE) + + self.released.connect(self.toggle) + + + def toggle(self): + + path = self._pathRef() + + if KP.app.keyboardModifiers() == Qt.ShiftModifier: + if self.secret == 1: + self.secret = 0 + else: + self.secret = 1 + + path.secret = self.secret + + else: + self.path += 1 + + if self.path > 2: + self.path = 0 + + path.unlocks = self.path + + + def paintEvent(self, event): + + painter = QtGui.QPainter(self) + + if self.path > 0: + painter.save() + + pathItem = self._pathRef().qtItem.line() + + if self.path == 1: + angle = pathItem.angle() + else: + angle = 180 + pathItem.angle() + + painter.rotate(angle) + self.arrowIcon.paint(painter, self.contentsRect(), Qt.AlignCenter) + + painter.restore() + + if self.isDown(): + self.iconList[self.secret].paint(painter, self.contentsRect(), Qt.AlignCenter, QtGui.QIcon.Disabled) + else: + self.iconList[self.secret].paint(painter, self.contentsRect(), Qt.AlignCenter) + + else: + if self.isDown(): + self.unlockIcon.paint(painter, self.contentsRect(), Qt.AlignCenter, QtGui.QIcon.Disabled) + else: + self.unlockIcon.paint(painter, self.contentsRect(), Qt.AlignCenter) + + painter.end() + + + class HiddenProxy(QtGui.QGraphicsProxyWidget): + def __init__(self, button, parent, x, y): + QtGui.QGraphicsProxyWidget.__init__(self, parent) + + self.setWidget(button) + self.setPos(x, y) + self.setZValue(parent.zValue()+1000) + self.hide() + + def __init__(self, path): QtGui.QGraphicsLineItem.__init__(self) @@ -277,13 +365,19 @@ class KPEditorPath(QtGui.QGraphicsLineItem): path.qtItem = self - self.updatePosition() - if not hasattr(KPEditorPath, 'PEN'): KPEditorPath.BRUSH = QtGui.QBrush(QtGui.QColor(255, 255, 255, 140)) KPEditorPath.PEN = QtGui.QPen(KPEditorPath.BRUSH, 8, Qt.SolidLine, Qt.RoundCap) self.setPen(KPEditorPath.PEN) + if not hasattr(KPEditorPath, 'SELECTION_PEN'): + KPEditorPath.SELECTION_PEN = QtGui.QPen(Qt.blue, 1, Qt.DotLine) + + self.unlock = self.UnlockButton(self._pathRef) + self.unlockProxy = self.HiddenProxy(self.unlock, self, -32, -32) + + self.updatePosition() + def updatePosition(self): path = self._pathRef() @@ -291,9 +385,34 @@ class KPEditorPath(QtGui.QGraphicsLineItem): x1, y1 = path._startNodeRef().position x2, y2 = path._endNodeRef().position - self.setLine(QtCore.QLineF(x1+12, y1+12, x2+12, y2+12)) + originLine = QtCore.QLineF(x1+12, y1+12, x2+12, y2+12) + self.setPos(originLine.pointAt(0.5)) + dy = originLine.dy()/2 + dx = originLine.dx()/2 + + self.setLine(QtCore.QLineF(-dx, -dy, dx, dy)) + def paint(self, painter, option, widget): + + painter.setRenderHint(QtGui.QPainter.Antialiasing) + + painter.setPen(KPEditorPath.PEN) + painter.drawLine(self.line()) + + if self.isSelected(): + painter.setPen(self.SELECTION_PEN) + painter.setBrush(QtGui.QColor(0,0,0,0)) + painter.drawPath(self.shape()) + + self.unlockProxy.show() + + else: + self.unlockProxy.hide() + + + + def remove(self, withItem=False): path = self._pathRef() layer = KP.map.pathLayer diff --git a/src/mapdata.py b/src/mapdata.py index a50c98e..013e308 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -138,7 +138,6 @@ class KPDoodad(object): self.size = [pixmap.width(), pixmap.height()] - class KPDoodadLayer(KPLayer): def __repr__(self): return "<KPDoodadLayer %r>" % self.name @@ -154,13 +153,12 @@ class KPDoodadLayer(KPLayer): item.setVisible(value) - class KPNodeAction(object): def __init__(self): pass -class KPNode(object): +class KPNode(object): def __init__(self): self.position = (0,0) self.actions = [] @@ -177,6 +175,9 @@ class KPPath(object): startNode.exits.append(self) endNode.exits.append(self) + self.unlocks = 0 # 0 = always unlocked, 1 = unlocked from startNode, 2 = unlocked from endNode + self.secret = 0 # 0 = unlocks from normal exit, 1 = unlocks from secret exit + if cloneFrom is None: self.animation = None else: @@ -225,9 +226,6 @@ class KPPathLayer(KPLayer): item.setFlag(flag, value) - - - class KPMap(object): def __init__(self): self.nextLayerNumber = 1 |