summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/editorui.py237
-rw-r--r--src/mapdata.py1
-rw-r--r--src/ui.py4
3 files changed, 231 insertions, 11 deletions
diff --git a/src/editorui.py b/src/editorui.py
index 73eaa18..2ab3774 100644
--- a/src/editorui.py
+++ b/src/editorui.py
@@ -500,6 +500,73 @@ class KPEditorDoodad(KPEditorItem):
class KPEditorNode(KPEditorItem):
SNAP_TO = (12,12)
+
+ class toggleButton(QtGui.QPushButton):
+
+ stateToggled = QtCore.pyqtSignal(int)
+
+
+ def __init__(self):
+ QtGui.QPushButton.__init__(self)
+
+ self.setIconSize(QtCore.QSize(24, 24))
+ self.setFixedSize(24, 24)
+
+ self.iconList = [QtGui.QIcon("Resources/Through.png"),
+ QtGui.QIcon("Resources/Level.png"),
+ QtGui.QIcon("Resources/Stop.png")]
+
+ self.state = 0
+
+ self.setPalette(QtGui.QPalette(QtGui.QColor(0,0,0,0)))
+
+ self.released.connect(self.toggle)
+
+
+ def toggle(self):
+
+ self.state += 1
+ if self.state == 3:
+ self.state = 0
+
+ self.stateToggled.emit(self.state)
+
+
+ def paintEvent(self, event):
+
+ painter = QtGui.QPainter(self)
+
+ painter.setBackgroundMode(Qt.TransparentMode)
+ painter.setBrush(QtGui.QColor(0,0,0,0))
+ painter.setPen(QtGui.QColor(0,0,0,0))
+
+ if self.isDown():
+ self.iconList[self.state].paint(painter, self.contentsRect(), Qt.AlignCenter, QtGui.QIcon.Disabled)
+ else:
+ self.iconList[self.state].paint(painter, self.contentsRect())
+ painter.end()
+
+
+ class hiddenProxy(QtGui.QGraphicsProxyWidget):
+ def __init__(self, button):
+ QtGui.QGraphicsProxyWidget.__init__(self)
+
+ self.setWidget(button)
+ self.setZValue(self.zValue()+1000)
+ self.hide()
+
+
+ class levelSlotSpinner(QtGui.QSpinBox):
+
+ def __init__(self):
+ QtGui.QSpinBox.__init__(self)
+
+ self.setRange(1, 99)
+
+ self.setPalette(QtGui.QPalette(QtGui.QColor(0,0,0,0)))
+
+
+
def __init__(self, node):
KPEditorItem.__init__(self)
@@ -508,32 +575,137 @@ class KPEditorNode(KPEditorItem):
self.setZValue(101)
- self._boundingRect = QtCore.QRectF(-12, -12, 24, 24)
- self._selectionRect = QtCore.QRectF(-12, -12, 23, 23)
- self._updatePosition()
+ self._boundingRect = QtCore.QRectF(-24, -24, 48, 48)
+ self._tinyRect = QtCore.QRectF(-12, -12, 24, 24)
+
if not hasattr(KPEditorNode, 'SELECTION_PEN'):
KPEditorNode.SELECTION_PEN = QtGui.QPen(Qt.blue, 1, Qt.DotLine)
+ self.button = self.toggleButton()
+ self.buttonProxy = self.hiddenProxy(self.button)
+ self.button.stateToggled.connect(self.stateChange)
+
+
+ self.world = self.levelSlotSpinner()
+ self.worldProxy = self.hiddenProxy(self.world)
+ self.world.valueChanged.connect(self.worldChange)
+
+ self.stage = self.levelSlotSpinner()
+ self.stageProxy = self.hiddenProxy(self.stage)
+ self.stage.valueChanged.connect(self.stageChange)
+
+
+ self._updatePosition()
+
+
+
+ @QtCore.pyqtSlot(int)
+ def stateChange(self, state):
+
+ node = self._nodeRef()
+
+ if state == 1:
+ node.level = [1, 1]
+ self.world.setValue(node.level[0])
+ self.stage.setValue(node.level[1])
+
+ elif state == 2:
+ node.isStop = True
+ node.level = [0,0]
+
+ else:
+ node.isStop = False
+ node.level = [0,0]
+
+ self.update()
+
+
+ @QtCore.pyqtSlot(int)
+ def worldChange(self, world):
+
+ node = self._nodeRef()
+ node.level[0] = world
+
+
+ @QtCore.pyqtSlot(int)
+ def stageChange(self, stage):
+
+ node = self._nodeRef()
+ node.level[1] = stage
+
+
+
def _updatePosition(self):
node = self._nodeRef()
x, y = node.position
self.setPos(x+12, y+12)
+ self.buttonProxy.setPos(self.x()+12, self.y()-24)
+ self.worldProxy.setPos(self.x()-42, self.y()+24)
+ self.stageProxy.setPos(self.x()+6, self.y()+24)
+
def _itemMoved(self, oldX, oldY, newX, newY):
node = self._nodeRef()
node.position = (newX-12, newY-12)
+ self.buttonProxy.setPos(newX+12, newY-24)
+ self.worldProxy.setPos(newX-42, newY+24)
+ self.stageProxy.setPos(newX+6, newY+24)
+
for exit in node.exits:
exit.qtItem.updatePosition()
def paint(self, painter, option, widget):
- painter.fillRect(self._boundingRect, Qt.white)
+
+ node = self._nodeRef()
+
+ selectionRect = None
+
+ if node.level != [0,0]:
+ painter.setBrush(QtGui.QColor(0, 0, 0, 0))
+ painter.setPen(QtGui.QColor(0, 0, 0, 0))
+ painter.drawPixmap(self._boundingRect.topLeft(), QtGui.QPixmap("Resources/BlackLevel.png"))
+ selectionRect = self._boundingRect.adjusted(-1,-1,1,1)
+
+ elif node.isStop:
+ brush = QtGui.QBrush(QtGui.QColor(255, 220, 220))
+ painter.setPen(QtGui.QColor(255, 255, 255))
+ painter.setBrush(brush)
+ painter.drawEllipse(self._tinyRect)
+ selectionRect = self._tinyRect.adjusted(-1,-1,1,1)
+
+ else:
+ brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
+ painter.setPen(QtGui.QColor(255, 255, 255))
+ painter.setBrush(brush)
+ painter.drawEllipse(self._tinyRect)
+ selectionRect = self._tinyRect.adjusted(-1,-1,1,1)
+
+
if self.isSelected():
painter.setPen(self.SELECTION_PEN)
- painter.drawRect(self._selectionRect)
+ painter.setBrush(QtGui.QColor(0,0,0,0))
+ painter.drawEllipse(selectionRect)
+ self.buttonProxy.show()
+
+ if node.level != [0,0]:
+ self.worldProxy.show()
+ self.stageProxy.show()
+
+ else:
+ self.worldProxy.hide()
+ self.stageProxy.hide()
+
+ else:
+ self.buttonProxy.hide()
+ self.worldProxy.hide()
+ self.stageProxy.hide()
+
+
+
def remove(self, withItem=False):
node = self._nodeRef()
@@ -541,6 +713,10 @@ class KPEditorNode(KPEditorItem):
layer.nodes.remove(node)
+ self.scene().removeItem(self.buttonProxy)
+ self.scene().removeItem(self.stageProxy)
+ self.scene().removeItem(self.worldProxy)
+
if len(node.exits) == 2:
# let's try to join the two!
pathOne, pathTwo = node.exits
@@ -584,6 +760,7 @@ class KPEditorNode(KPEditorItem):
self.scene().removeItem(self)
+
class KPEditorPath(QtGui.QGraphicsLineItem):
def __init__(self, path):
QtGui.QGraphicsLineItem.__init__(self)
@@ -859,6 +1036,15 @@ class KPEditorWidget(QtGui.QGraphicsView):
if pathToCheck._endNodeRef() == destNode:
return
+ # No node can have more than four paths, because there are only
+ # four directions registered by a Wiimote DPad.
+
+ if len(sourceNode.exits) > 3:
+ return
+
+ if len(destNode.exits) > 3:
+ return
+
path = KPPath(sourceNode, destNode)
KP.map.pathLayer.paths.append(path)
@@ -869,7 +1055,7 @@ class KPEditorWidget(QtGui.QGraphicsView):
return
elif isinstance(item, KPEditorPath):
- # Split this path into two.. at this point
+ # Split this path into two... at this point
origPath = item._pathRef()
@@ -886,6 +1072,9 @@ class KPEditorWidget(QtGui.QGraphicsView):
nodeItem = KPEditorNode(node)
self.scene().addItem(nodeItem)
+ self.scene().addItem(nodeItem.buttonProxy)
+ self.scene().addItem(nodeItem.stageProxy)
+ self.scene().addItem(nodeItem.worldProxy)
self.painting = node
self.paintingItem = item
@@ -901,12 +1090,44 @@ class KPEditorWidget(QtGui.QGraphicsView):
# Paint a new node
node = KPNode()
- node.isStop = True
node.position = (x - 12, y - 12)
KP.map.pathLayer.nodes.append(node)
item = KPEditorNode(node)
self.scene().addItem(item)
+ self.scene().addItem(item.buttonProxy)
+ self.scene().addItem(item.stageProxy)
+ self.scene().addItem(item.worldProxy)
+
+ # Paint a path to this node (if one is selected)
+ sourceItem, sourceNode = None, None
+ selected = self.scene().selectedItems()
+
+ for selItem in selected:
+ if isinstance(item, KPEditorNode) and selItem != item:
+ sourceItem = selItem
+ sourceNode = selItem._nodeRef()
+ break
+
+ # No node can have more than four paths, because there are only
+ # four directions registered by a Wiimote DPad.
+
+ if not sourceItem is None:
+ if len(sourceNode.exits) > 3:
+ return
+
+ # There, now you can draw paths easily in a row.
+ path = KPPath(sourceNode, node)
+
+ KP.map.pathLayer.paths.append(path)
+
+ pathitem = KPEditorPath(path)
+ self.scene().addItem(pathitem)
+
+
+ # Switch the selection to the recently drawn node, so you can keep on rolling.
+ self.scene().clearSelection()
+ item.setSelected(True)
self.painting = node
self.paintingItem = item
@@ -966,6 +1187,7 @@ class KPEditorWidget(QtGui.QGraphicsView):
item._layerRef().updateCache()
+
def mousePressEvent(self, event):
if event.button() == Qt.RightButton:
self._tryToPaint(event)
@@ -973,6 +1195,7 @@ class KPEditorWidget(QtGui.QGraphicsView):
else:
QtGui.QGraphicsView.mousePressEvent(self, event)
+
def mouseMoveEvent(self, event):
if event.buttons() == Qt.RightButton and self.painting:
diff --git a/src/mapdata.py b/src/mapdata.py
index e864df0..a50c98e 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -165,6 +165,7 @@ class KPNode(object):
self.position = (0,0)
self.actions = []
self.exits = []
+ self.level = [0,0]
self.isStop = False
diff --git a/src/ui.py b/src/ui.py
index 0eaddc0..2ba49ba 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -140,10 +140,6 @@ class KPDoodadSelector(QtGui.QWidget):
self.doodadList.currentItemChanged.connect(self.handleRowChanged)
- # TODO: REMOVE THIS!!!
- pm = QtGui.QPixmap()
- pm.load('/home/me/Dropbox/NEWERsmbw/BildOlPipeThingy2x.png')
- self.addDoodad(pm, 'Test Doodad')
def keyPressEvent(self, event):