summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/editorui/doodads.py239
-rw-r--r--src/mapdata.py3
2 files changed, 241 insertions, 1 deletions
diff --git a/src/editorui/doodads.py b/src/editorui/doodads.py
index 5a02248..addfae3 100644
--- a/src/editorui/doodads.py
+++ b/src/editorui/doodads.py
@@ -8,6 +8,237 @@ import math
class KPEditorDoodad(KPEditorItem):
SNAP_TO = (12,12)
+
+ class DoodadAnmButton(QtGui.QPushButton):
+
+
+ class AnmOptionsWidget(QtGui.QWidget):
+
+
+ class AnmDelegate(QtGui.QStyledItemDelegate):
+
+ def createEditor(self, parent, option, index):
+
+ loop = ["Contiguous", "Loop", "Reversible Loop"]
+ interp = ["Linear", "Sinusoidial", "Cosinoidial"]
+ anmType = ["X Position", "Y Position", "Angle", "X Scale", "Y Scale", "Opacity"]
+
+ thing = index.data(Qt.DisplayRole)
+ thong = index.data(Qt.EditRole).toFloat()[0]
+
+ if thing in loop:
+ editWidget = QtGui.QComboBox(parent)
+ editWidget.addItems(loop)
+
+ return editWidget
+
+ elif thing in interp:
+ editWidget = QtGui.QComboBox(parent)
+ editWidget.addItems(interp)
+
+ return editWidget
+
+ elif thing in anmType:
+ editWidget = QtGui.QComboBox(parent)
+ editWidget.addItems(anmType)
+
+ return editWidget
+
+ elif isinstance(thong, float):
+ editWidget = QtGui.QDoubleSpinBox(parent)
+ editWidget.setSingleStep(0.05)
+ editWidget.setRange(-10000.0, 10000.0)
+ return editWidget
+
+ else:
+ print "Thing was something else!"
+ print thong
+ print type(thong)
+
+
+
+ def setEditorData(self, editor, index):
+
+
+ if isinstance(editor, QtGui.QDoubleSpinBox):
+ thing = index.data(Qt.EditRole).toFloat()[0]
+
+ editor.setValue(thing)
+
+ elif isinstance(editor, QtGui.QComboBox):
+ thing = index.data(Qt.DisplayRole).toString()
+
+ editor.setCurrentIndex(editor.findText(thing))
+
+ else:
+ print "editor is something else!"
+ print editor
+
+
+ def setModelData(self, editor, model, index):
+
+ if isinstance(editor, QtGui.QDoubleSpinBox):
+ editor.interpretText()
+ value = editor.value()
+
+ model.setData(index, value, QtCore.Qt.EditRole)
+
+ elif isinstance(editor, QtGui.QComboBox):
+ value = editor.currentText()
+
+ model.setData(index, value, QtCore.Qt.EditRole)
+
+ else:
+ print "editor is something else!"
+ print editor
+
+
+ def updateEditorGeometry(self, editor, option, index):
+ editor.setGeometry(option.rect)
+
+
+ def __init__(self, doodadRef):
+ QtGui.QWidget.__init__(self)
+
+ self._doodadRef = doodadRef
+
+ # Setup Layout
+ BottomLayout = QtGui.QGridLayout()
+
+
+ # Time for the Table View, model and Delegate
+ self.model = QtGui.QStandardItemModel(0, 6)
+ self.anmTable = QtGui.QTableView()
+ self.anmTable.setModel(self.model)
+
+ delegate = self.AnmDelegate()
+ self.anmTable.setItemDelegate(delegate)
+
+ self.model.setHorizontalHeaderLabels(["Looping", "Interpolation", "Frame Length", "Type", "Start Value", "End Value"])
+ self.anmTable.setColumnWidth(0, 80)
+ self.anmTable.setColumnWidth(0, 80)
+ self.anmTable.setColumnWidth(0, 30)
+ self.anmTable.setColumnWidth(0, 80)
+ self.anmTable.setColumnWidth(0, 30)
+ self.anmTable.setColumnWidth(0, 30)
+
+ self.anmTable.horizontalHeader().setVisible(True)
+ self.anmTable.verticalHeader().setVisible(False)
+
+ BottomLayout.addWidget(self.anmTable, 0, 0, 1, 4)
+
+
+ # Add/Remove Animation Buttons
+ addbutton = QtGui.QPushButton("Add Animation")
+ rembutton = QtGui.QPushButton("Remove Animation")
+ BottomLayout.addWidget(addbutton, 1, 0, 1, 1)
+ BottomLayout.addWidget(rembutton, 1, 1, 1, 1)
+ BottomLayout.addWidget(QtGui.QLabel(""), 1, 2, 1, 2)
+
+
+ # Annnnndddd we're spent.
+ self.setLayout(BottomLayout)
+
+ addbutton.released.connect(self.addAnmItem)
+ rembutton.released.connect(self.remAnmItem)
+
+
+ def sizeHint(self):
+ return QtCore.QSize(8000, 10000)
+
+
+
+ def addAnmItem(self):
+
+ itemA = QtGui.QStandardItem()
+ itemB = QtGui.QStandardItem()
+ itemC = QtGui.QStandardItem()
+
+ itemA.setData(1, QtCore.Qt.EditRole)
+ itemB.setData(0.0, QtCore.Qt.EditRole)
+ itemC.setData(0.0, QtCore.Qt.EditRole)
+
+ self.model.appendRow([QtGui.QStandardItem("Contiguous"), QtGui.QStandardItem("Linear"),
+ QtGui.QStandardItem(itemA), QtGui.QStandardItem("X Position"),
+ QtGui.QStandardItem(itemB), QtGui.QStandardItem(itemC)])
+
+
+ def remAnmItem(self):
+
+ if self.anmTable.rows() == 0:
+ return
+
+ rowNum, ok = QtGui.QInputDialog.getInteger(self,
+ "Select A Row", "Delete This Row:", 0, 0, self.anmTable.rows(), 1)
+ if ok:
+ rowNum = QtGui.Q
+ self.model.removeRows(rowNum, 1)
+
+
+ def __init__(self, doodadRef):
+ QtGui.QPushButton.__init__(self)
+
+ self._doodadRef = doodadRef
+ self.setText("Animate")
+
+ self.menu = QtGui.QMenu(self)
+ layout = QtGui.QVBoxLayout()
+ self.menuWidget = self.AnmOptionsWidget(doodadRef)
+ layout.addWidget(self.menuWidget)
+
+ self.menu.setLayout(layout)
+
+ menuPalette = self.menu.palette()
+ menuPalette.setColor(QtGui.QPalette.Window, Qt.black)
+ self.menu.setPalette(menuPalette)
+
+ self.setMenu(self.menu)
+
+ palette = self.palette()
+ palette.setColor(QtGui.QPalette.ButtonText, Qt.black)
+ palette.setColor(QtGui.QPalette.Window, Qt.transparent)
+
+ self.setPalette(palette)
+
+ self.menu.aboutToHide.connect(self.resolveAnmList)
+
+
+ def resolveAnmList(self):
+ doodad = self._doodadRef()
+
+ anmList = []
+ model = self.menuWidget.model
+ rows = model.rowCount()
+
+ for x in xrange(rows):
+ rowList = []
+
+ for item in xrange(6):
+ index = model.index(x, item)
+ data = model.data(index, Qt.EditRole).toString()
+ if data.toFloat()[1]:
+ data = data.toFloat()[0]
+ else:
+ data = str(data)
+ rowList.append(data)
+
+ anmList.append(tuple(rowList))
+
+ doodad.animations = anmList
+ print anmList
+
+
+
+ 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, doodad, layer):
KPEditorItem.__init__(self)
@@ -26,6 +257,9 @@ class KPEditorDoodad(KPEditorItem):
self._updatePosition()
self._updateSize()
+ self.anmButton = self.DoodadAnmButton(self._doodadRef)
+ self.anmProxy = self.HiddenProxy(self.anmButton, self, self.boundingRect().right() - 101, self.boundingRect().bottom() - 25)
+
self.setAcceptHoverEvents(True)
if not hasattr(KPEditorDoodad, 'SELECTION_PEN'):
@@ -70,6 +304,11 @@ class KPEditorDoodad(KPEditorItem):
if self.isSelected():
painter.setPen(self.SELECTION_PEN)
painter.drawRect(self._selectionRect)
+
+ self.anmProxy.show()
+
+ else:
+ self.anmProxy.hide()
def _itemMoved(self, oldX, oldY, newX, newY):
diff --git a/src/mapdata.py b/src/mapdata.py
index 5fbadb7..0a636f7 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -133,6 +133,7 @@ class KPDoodad(object):
self.size = [0,0]
self.angle = 0
self.index = 0
+ self.animations = []
def setDefaultSize(self):
source = KP.mainWindow.doodadSelector.getDoodad(self.index)
@@ -189,7 +190,7 @@ class KPPath(object):
self.movementSpeed = 1.0
self.linkedLayer = None
-
+
def setStart(self, newStart):
currentStart = self._startNodeRef()