From 0c68efbbcfeb63ea3196d9f16769ed0621a5dfa9 Mon Sep 17 00:00:00 2001 From: Colin Noga Date: Wed, 23 Nov 2011 06:29:41 -0600 Subject: Added options menu for paths. Includes movement speed, animation, and layer linking. --- src/editorui/paths.py | 122 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/mapdata.py | 4 ++ 2 files changed, 123 insertions(+), 3 deletions(-) diff --git a/src/editorui/paths.py b/src/editorui/paths.py index cec85fa..7e3d484 100644 --- a/src/editorui/paths.py +++ b/src/editorui/paths.py @@ -255,10 +255,123 @@ class KPEditorNode(KPEditorItem): self.scene().removeItem(self) - class KPEditorPath(QtGui.QGraphicsLineItem): + class PathOptionsMenuButton(QtGui.QPushButton): + + + class PathOptionsWidget(QtGui.QWidget): + def __init__(self, pathRef): + QtGui.QWidget.__init__(self) + + self._pathRef = pathRef + + Layout = QtGui.QGridLayout() + + # Make an exclusive button group for our animations. + AnimationList = ["Walk", "WalkSand", "WalkSnow", "WalkIce", + "Jump", "JumpSand", "JumpSnow", "SpinJump", + "Ladder", "LeftLadder", "RightLadder", "Ivy", + "Swim", "Roll", "Pipe", "Door"] + + self.ExclusiveButtons = QtGui.QButtonGroup() + + i = 0 + j = 1 + id = 0 + for anim in AnimationList: + newButton = QtGui.QPushButton(QtGui.QIcon("Resources/Anm" + anim), anim) + newButton.setCheckable(True) + self.ExclusiveButtons.addButton(newButton, id) + + Layout.addWidget(newButton, j, i) + + id += 1 + i += 1 + if i == 4: + i = 0 + j += 1 + + + # Movement Speed Spin Box + self.moveSpeedSpinner = QtGui.QDoubleSpinBox() + self.moveSpeedSpinner.setMinimum(0.0) + self.moveSpeedSpinner.setMaximum(256.0) + self.moveSpeedSpinner.setDecimals(2) + self.moveSpeedSpinner.setSingleStep(0.05) + self.moveSpeedSpinner.setValue(1.0) + + Layout.addWidget(self.moveSpeedSpinner, 0, 0) + + + # Layer Combo Box + self.linkedLayer = QtGui.QComboBox(self) + self.linkedLayer.setModel(KP.map.layerModel) + + Layout.addWidget(self.linkedLayer, 0, 1, 1, 3) + + + # Connections + + self.ExclusiveButtons.buttonReleased.connect(self.updatePathAnim) + self.moveSpeedSpinner.valueChanged.connect(self.updateMoveSpeed) + self.linkedLayer.currentIndexChanged.connect(self.updateLinkLayer) + + # Layout + self.setLayout(Layout) + + + @QtCore.pyqtSlot(float) + def updateMoveSpeed(self, speed): + path = self._pathRef() + + path.movementSpeed = speed + path.qtItem.update() + + + @QtCore.pyqtSlot(int) + def updatePathAnim(self, buttonID): + path = self._pathRef() + + path.animation = buttonID + path.qtItem.update() + + + @QtCore.pyqtSlot(int) + def updateLinkLayer(self, layerIndex): + path = self._pathRef() + + path.linkedLayer = KP.map.layers[layerIndex] + + + def __init__(self, pathRef): + QtGui.QPushButton.__init__(self) + + self.setText("Options") + + self.menu = QtGui.QMenu(self) + layout = QtGui.QVBoxLayout() + layout.addWidget(self.PathOptionsWidget(pathRef)) + + self.menu.setLayout(layout) + + menuPalette = self.menu.palette() + menuPalette.setColor(QtGui.QPalette.Window, Qt.black) + self.menu.setPalette(menuPalette) + + # dropShadow = QtGui.QGraphicsDropShadowEffect() + # self.menu.setGraphicsEffect(dropShadow) + self.setMenu(self.menu) + + palette = self.palette() + palette.setColor(QtGui.QPalette.ButtonText, Qt.black) + palette.setColor(QtGui.QPalette.Window, Qt.transparent) + + self.setPalette(palette) + + + class UnlockButton(QtGui.QPushButton): def __init__(self, pathRef): QtGui.QPushButton.__init__(self) @@ -383,6 +496,9 @@ class KPEditorPath(QtGui.QGraphicsLineItem): self.unlock = self.UnlockButton(self._pathRef) self.unlockProxy = self.HiddenProxy(self.unlock, self, -24, -24) + self.options = self.PathOptionsMenuButton(self._pathRef) + self.optionsProxy = self.HiddenProxy(self.options, self, -54, +24) + self.updatePosition() @@ -418,11 +534,11 @@ class KPEditorPath(QtGui.QGraphicsLineItem): painter.drawPath(self.shape()) self.unlockProxy.show() + self.optionsProxy.show() else: self.unlockProxy.hide() - - + self.optionsProxy.hide() def remove(self, withItem=False): diff --git a/src/mapdata.py b/src/mapdata.py index 131c669..5fbadb7 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -187,6 +187,10 @@ class KPPath(object): else: self.animation = cloneFrom.animation + self.movementSpeed = 1.0 + self.linkedLayer = None + + def setStart(self, newStart): currentStart = self._startNodeRef() if currentStart is not None: -- cgit v1.2.3