From e037c2d4256e2975e50d00517526794dff444f0d Mon Sep 17 00:00:00 2001 From: Colin Noga Date: Sat, 12 May 2012 18:49:08 -0500 Subject: Fixed up some formatting, made the animation panel into a dock widget, added a delay value to doodad animations and implemented it editor-side --- src/editorui/doodads.py | 10 +- src/editorui/editormain.py | 8 +- src/mapdata.py | 41 +++- src/ui.py | 460 ++++++++++++++++++++++++++++++++++++++------- 4 files changed, 431 insertions(+), 88 deletions(-) (limited to 'src') diff --git a/src/editorui/doodads.py b/src/editorui/doodads.py index 07eca43..6bb4576 100644 --- a/src/editorui/doodads.py +++ b/src/editorui/doodads.py @@ -365,8 +365,8 @@ class KPEditorDoodad(KPEditorItem): self._updateSize() self._updateTransform() - self.anmButton = self.DoodadAnmButton(self._doodadRef) - self.anmProxy = self.HiddenProxy(self.anmButton, self, self.boundingRect().right() - 101, self.boundingRect().bottom() - 25) + # self.anmButton = self.DoodadAnmButton(self._doodadRef) + # self.anmProxy = self.HiddenProxy(self.anmButton, self, self.boundingRect().right() - 101, self.boundingRect().bottom() - 25) self.setAcceptHoverEvents(True) @@ -377,7 +377,6 @@ class KPEditorDoodad(KPEditorItem): KPEditorDoodad.SELECTION_PEN = QtGui.QPen(Qt.red, 1, Qt.DotLine) - def _updatePixmap(self): pixmap = self.source[1] @@ -418,11 +417,6 @@ 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/editorui/editormain.py b/src/editorui/editormain.py index 1cd2948..263c547 100644 --- a/src/editorui/editormain.py +++ b/src/editorui/editormain.py @@ -703,8 +703,8 @@ class KPEditorWidget(QtGui.QGraphicsView): else: QtGui.QGraphicsView.mousePressEvent(self, event) - + def mouseMoveEvent(self, event): if event.buttons() == Qt.RightButton and self.painting: self._movedWhilePainting(event) @@ -714,6 +714,11 @@ class KPEditorWidget(QtGui.QGraphicsView): QtGui.QGraphicsView.mouseMoveEvent(self, event) + def mouseReleaseEvent(self, event): + QtGui.QGraphicsView.mouseReleaseEvent(self, event) + self.userClick.emit() + + def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Delete or event.key() == QtCore.Qt.Key_Backspace: scene = self.scene() @@ -730,6 +735,7 @@ class KPEditorWidget(QtGui.QGraphicsView): else: QtGui.QGraphicsView.keyPressEvent(self, event) + userClick = QtCore.pyqtSignal() diff --git a/src/mapdata.py b/src/mapdata.py index 8469ad4..44656b7 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -296,6 +296,31 @@ class KPDoodad(object): pixmap = self.source[1] self.size = [pixmap.width(), pixmap.height()] + class doodadTimeLine(QtCore.QTimeLine): + def __init__(self): + QtCore.QTimeLine.__init__(self) + + self.delayTimer = QtCore.QTimer() + self.delayTimer.timeout.connect(self.start) + self.delayTimer.setSingleShot(True) + + self.reversible = False + self.reversed = False + + def restartDelay(self): + + if self.reversible: + if not self.reversed: + self.reversed = True + self.toggleDirection() + self.start() + return + else: + self.toggleDirection() + self.reversed = False + + self.delayTimer.start() + def cleanUpAnimations(self): myTimelines = self.timelines if myTimelines is None: return @@ -317,9 +342,9 @@ class KPDoodad(object): myTimelines = [] for anim in self.animations: - Loop, Curve, Frames, Type, StartVal, EndVal = anim + Loop, Curve, Frames, Type, StartVal, EndVal, Delay = anim - Timeline = QtCore.QTimeLine() + Timeline = self.doodadTimeLine() # Interpolate the correct modifier if Curve == "Linear": @@ -334,13 +359,17 @@ class KPDoodad(object): if Loop == "Contiguous": Timeline.setLoopCount(1) elif Loop == "Loop": - Timeline.setLoopCount(0) # Dollars *holds pinky to corner of mouth* + Timeline.setLoopCount(1) + Timeline.finished.connect(Timeline.restartDelay) elif Loop == "Reversible Loop": Timeline.setLoopCount(1) - Timeline.finished.connect(Timeline.toggleDirection) - Timeline.finished.connect(Timeline.start) + Timeline.reversible = True + Timeline.finished.connect(Timeline.restartDelay) - Timeline.setDuration(Frames/60.0*1000) # Wii goes at 60 frames per second + # Setup the Delay Timer and Duration + # Wii goes at 60 frames per second + Timeline.delayTimer.setInterval(Delay/60.0*1000) + Timeline.setDuration(Frames/60.0*1000) timelineList.append(Timeline) myTimelines.append(Timeline) diff --git a/src/ui.py b/src/ui.py index fb8f4a4..a7d2524 100644 --- a/src/ui.py +++ b/src/ui.py @@ -87,7 +87,6 @@ class KPPathNodeList(QtGui.QWidget): def associate(self): return self.associate - def __init__(self): QtGui.QWidget.__init__(self) @@ -108,21 +107,17 @@ class KPPathNodeList(QtGui.QWidget): self.setupToolbar(self.toolbar) self.setLayout(self.layout) - def reset(self): self.tree.clear() for layer in KP.map.associateLayers: self.loadLayer(layer) - def setupToolbar(self, tb): self.actAddFolder = tb.addAction(KP.icon('NewFolder'), 'Add Folder', self.addFolder) self.actRemoveFolder = tb.addAction(KP.icon('DelFolder'), 'Remove Folder', self.removeFolder) self.selectTileset = tb.addAction(KP.icon('LayerNewTile'), 'Select Tileset', self.setTileset) - selectedLayerChanged = QtCore.pyqtSignal(KPLayer) - @QtCore.pyqtSlot() def handleRowChanged(self): item = self.tree.currentItem() @@ -241,6 +236,8 @@ class KPPathNodeList(QtGui.QWidget): else: layerList.append(item.layer) + selectedLayerChanged = QtCore.pyqtSignal(KPLayer) + class KPLayerList(QtGui.QWidget): def __init__(self): @@ -260,14 +257,12 @@ class KPLayerList(QtGui.QWidget): self.updateModel() self.setLayout(self.layout) - def updateModel(self): self.model = KP.map.layerModel self.listView.setModel(self.model) self.listView.clicked.connect(self.handleRowChanged) self.setButtonStates() - def setupToolbar(self, tb): self.actAddTile = tb.addAction(KP.icon('LayerNewTile'), 'Add Tile Layer', self.addTileLayer) self.actAddDoodad = tb.addAction(KP.icon('LayerNewObjects'), 'Add Doodad Layer', self.addDoodadLayer) @@ -276,9 +271,6 @@ class KPLayerList(QtGui.QWidget): self.actMoveDown = tb.addAction(QtGui.QIcon(), 'Move Down', self.moveDown) self.actPlayPause = tb.addAction(KP.icon('APlay'), 'Play', self.toggleAnimatingScene) - - playPaused = QtCore.pyqtSignal() - def toggleAnimatingScene(self): self.playPaused.emit() @@ -294,20 +286,17 @@ class KPLayerList(QtGui.QWidget): self.actMoveUp.setEnabled(index > 0) self.actMoveDown.setEnabled((index != -1) and (index < (len(KP.map.layers) - 1))) - def selectedLayerIndex(self): return self.listView.selectionModel().currentIndex().row() + def selectedLayer(self): return KP.map.layers[self.selectedLayerIndex()] - selectedLayerChanged = QtCore.pyqtSignal(KPLayer) - @QtCore.pyqtSlot(QtCore.QModelIndex) def handleRowChanged(self, current): self.selectedLayerChanged.emit(KP.map.layers[current.row()]) self.setButtonStates() - def addTileLayer(self): from dialogs import KPTilesetChooserDialog @@ -320,14 +309,12 @@ class KPLayerList(QtGui.QWidget): KP.map.appendLayer(layer) self.setButtonStates() - def addDoodadLayer(self): layer = KP.map.createNewDoodadLayer() KP.map.appendLayer(layer) self.setButtonStates() - def removeLayer(self): layer = self.selectedLayer() scene = KP.mainWindow.scene @@ -367,8 +354,12 @@ class KPLayerList(QtGui.QWidget): self.setButtonStates() KP.mainWindow.editor.viewport().update() + playPaused = QtCore.pyqtSignal() + selectedLayerChanged = QtCore.pyqtSignal(KPLayer) + class KPDoodadSelector(QtGui.QWidget): + def __init__(self): """Initialises the widget.""" @@ -397,16 +388,15 @@ class KPDoodadSelector(QtGui.QWidget): self.layout.addWidget(self.toolbar) self.layout.addWidget(self.listView) + self.setLayout(self.layout) - def updateModel(self): self.model = KP.map.doodadModel self.listView.setModel(self.model) self.listView.selectionModel().currentRowChanged.connect(self.handleRowChanged) self.setButtonStates() - def keyPressEvent(self, event): self.listView.keyPressEvent(event) @@ -424,23 +414,21 @@ class KPDoodadSelector(QtGui.QWidget): if msgBox.exec_() == QtGui.QMessageBox.AcceptRole: KP.map.removeDoodad(doodad) - # def addDoodad(self, image, name): - # # TODO: REMOVE - # """Takes a name and a QPixmap and turns it into an icon, then goes ahead and makes a doodad. - # Doodads are QListWidget items with an index number as Qt.UserRole #32.""" - + # TODO: REMOVE + # """Takes a name and a QPixmap and turns it into an icon, then goes ahead and makes a doodad. + # Doodads are QListWidget items with an index number as Qt.UserRole #32.""" - # doodie = QtGui.QListWidgetItem(QtGui.QIcon(image), name) - # # !! - # doodie.setSizeHint(QtCore.QSize(128,128)) - # doodie.setData(32, self.nextIndex) - # doodie.setToolTip(name) - # doodie.setTextAlignment(Qt.AlignBottom | Qt.AlignHCenter) - # self.doodadList.addItem(doodie) - # self.nextIndex += 1 + # doodie = QtGui.QListWidgetItem(QtGui.QIcon(image), name) + # # !! + # doodie.setSizeHint(QtCore.QSize(128,128)) + # doodie.setData(32, self.nextIndex) + # doodie.setToolTip(name) + # doodie.setTextAlignment(Qt.AlignBottom | Qt.AlignHCenter) + # self.doodadList.addItem(doodie) + # self.nextIndex += 1 def addDoodadFromFile(self): """Asks the user for files to load in as doodads.""" @@ -458,7 +446,6 @@ class KPDoodadSelector(QtGui.QWidget): KP.map.addDoodad(name, pix) - def removeDoodad(self): """Removes selected doodad""" @@ -466,25 +453,24 @@ class KPDoodadSelector(QtGui.QWidget): if item: KP.map.removeDoodad(item) - def setButtonStates(self): index = self.selectedDoodadIndex() self.removeDoodadButton.setEnabled(index != -1) - def selectedDoodadIndex(self): return self.listView.selectionModel().currentIndex().row() + def selectedDoodad(self): return KP.map.doodadDefinitions[self.listView.selectionModel().currentIndex().row()] - selectedDoodadChanged = QtCore.pyqtSignal(object) - @QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex) def handleRowChanged(self, current, previous): self.selectedDoodadChanged.emit(KP.map.doodadDefinitions[current.row()]) self.setButtonStates() + selectedDoodadChanged = QtCore.pyqtSignal(object) + class KPObjectSelector(QtGui.QWidget): def __init__(self): @@ -535,7 +521,6 @@ class KPObjectSelector(QtGui.QWidget): self.sorterMenu.aboutToShow.connect(self.fixUpMenuSize) self.sorterMenu.triggered.connect(self.toggleTopLevel) - def beginUsingMenu(self): if self.menuSetup: return @@ -546,11 +531,9 @@ class KPObjectSelector(QtGui.QWidget): self.sorterButton.setEnabled(True) self.menuSetup = True - def fixUpMenuSize(self): self.sorterMenu.setFixedWidth(self.sorterButton.width()) - def currentSelectedObject(self): """Returns the currently selected object reference, for painting purposes.""" @@ -559,7 +542,6 @@ class KPObjectSelector(QtGui.QWidget): return object - def setTileset(self, tileset): """Sets the model and the menu sorting list""" model = tileset.getModel() @@ -595,7 +577,6 @@ class KPObjectSelector(QtGui.QWidget): # set up signals self.listView.selectionModel().currentRowChanged.connect(self.handleRowChanged) - def toggleTopLevel(self, action): """Changes the top level group in the list view.""" @@ -614,7 +595,6 @@ class KPObjectSelector(QtGui.QWidget): self.sorterButton.setText(string) - @QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex) def handleRowChanged(self, current, previous): """Throws a signal emitting the current object when changed""" @@ -623,7 +603,6 @@ class KPObjectSelector(QtGui.QWidget): self.objChanged.emit(self.tileset.objects.index(object), object) - def handleObjReplace(self, index): """Throws a signal when the selected object is used as a replacement""" if QtGui.QApplication.keyboardModifiers() == QtCore.Qt.AltModifier: @@ -636,6 +615,335 @@ class KPObjectSelector(QtGui.QWidget): objReplaced = QtCore.pyqtSignal(int, KPTileObject) +class KPAnmOptions(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.QPushButton.__init__(self) + + # self._doodadRef = doodadRef + # self.setText("Animate") + + # self.menu = QtGui.QMenu(self) + # self.menuWidget = self.AnmOptionsWidget(doodadRef, self) + # self.menuWidgetAction = QtGui.QWidgetAction(self) + # self.menuWidgetAction.setDefaultWidget(self.menuWidget) + # self.menu.addAction(self.menuWidgetAction) + + + # 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 __init__(self): + QtGui.QWidget.__init__(self) + + self._doodadRef = None + self.doodadList = None + + # Setup Layout + BottomLayout = QtGui.QGridLayout() + + + # Time for the Table View, model and Delegate + self.model = QtGui.QStandardItemModel(0, 7) + self.anmTable = QtGui.QTableView() + self.anmTable.setModel(self.model) + + delegate = self.AnmDelegate() + self.anmTable.setItemDelegate(delegate) + + self.model.setHorizontalHeaderLabels(["Looping", "Interpolation", "Frame Len", "Type", "Start Value", "End Value", "Delay"]) + self.anmTable.setColumnWidth(0, 150) + self.anmTable.setColumnWidth(1, 100) + self.anmTable.setColumnWidth(2, 65) + self.anmTable.setColumnWidth(3, 120) + self.anmTable.setColumnWidth(4, 65) + self.anmTable.setColumnWidth(5, 65) + self.anmTable.setColumnWidth(6, 65) + + self.anmTable.horizontalHeader().setVisible(True) + self.anmTable.verticalHeader().setVisible(False) + + BottomLayout.addWidget(self.anmTable, 0, 0, 1, 6) + + + # Add/Remove Animation Buttons + addbutton = QtGui.QPushButton(QtGui.QIcon("Resources/Plus.png"), "") + rembutton = QtGui.QPushButton(QtGui.QIcon("Resources/Minus.png"), "") + presetbutton = QtGui.QPushButton(QtGui.QIcon("Resources/AddPreset.png"), "Add Preset") + newpbutton = QtGui.QPushButton(QtGui.QIcon("Resources/NewPreset.png"), "New Preset") + # savebutton = QtGui.QPushButton(QtGui.QIcon("Resources/SavePreset.png"), "Save") + # loadbutton = QtGui.QPushButton(QtGui.QIcon("Resources/LoadPreset.png"), "Load") + # clearbutton = QtGui.QPushButton(QtGui.QIcon("Resources/ClearPreset.png"), "Clear") + BottomLayout.addWidget(addbutton, 1, 0, 1, 1) + BottomLayout.addWidget(rembutton, 1, 1, 1, 1) + BottomLayout.addWidget(QtGui.QLabel(""), 1, 2, 1, 2) + BottomLayout.addWidget(presetbutton, 1, 4, 1, 1) + BottomLayout.addWidget(newpbutton, 1, 5, 1, 1) + # BottomLayout.addWidget(savebutton, 1, 6, 1, 1) + # BottomLayout.addWidget(loadbutton, 1, 7, 1, 1) + # BottomLayout.addWidget(clearbutton, 1, 8, 1, 1) + + + # Annnnndddd we're spent. + self.setLayout(BottomLayout) + + addbutton.released.connect(self.addAnmItem) + rembutton.released.connect(self.remAnmItem) + + presetbutton.released.connect(self.selectPreset) + newpbutton.released.connect(self.addToPreset) + # savebutton.released.connect(KP.mainWindow.saveAnimPresets) + # loadbutton.released.connect(KP.mainWindow.loadAnimPresets) + # clearbutton.released.connect(KP.mainWindow.clearAnimPresets) + + def setupAnms(self, doodadList): + self.doodadList = doodadList + self._doodadRef = doodadList[0] + doodad = self._doodadRef() + + for row in doodad.animations: + + # Fix for backwards compatibility + if len(row) == 6: + row.append(0.0) + + itemA = QtGui.QStandardItem() + itemB = QtGui.QStandardItem() + itemC = QtGui.QStandardItem() + itemD = QtGui.QStandardItem() + + itemA.setData(row[2], QtCore.Qt.EditRole) + itemB.setData(row[4], QtCore.Qt.EditRole) + itemC.setData(row[5], QtCore.Qt.EditRole) + itemD.setData(row[6], QtCore.Qt.EditRole) + + self.model.appendRow([QtGui.QStandardItem(row[0]), QtGui.QStandardItem(row[1]), + itemA, QtGui.QStandardItem(row[3]), itemB, itemC, itemD]) + + self.update() + + def sizeHint(self): + return QtCore.QSize(591,300) + + def addAnmItem(self): + + itemA = QtGui.QStandardItem() + itemB = QtGui.QStandardItem() + itemC = QtGui.QStandardItem() + itemD = QtGui.QStandardItem() + + itemA.setData(1, QtCore.Qt.EditRole) + itemB.setData(0.0, QtCore.Qt.EditRole) + itemC.setData(0.0, QtCore.Qt.EditRole) + itemD.setData(0.0, QtCore.Qt.EditRole) + + self.model.appendRow([QtGui.QStandardItem("Contiguous"), QtGui.QStandardItem("Linear"), + itemA, QtGui.QStandardItem("X Position"), + itemB, itemC, itemD]) + + def remAnmItem(self): + + if self.model.rowCount() == 0: + return + + rowNum, ok = QtGui.QInputDialog.getInteger(self, + "Select A Row", "Delete This Row:", 0, 0, self.model.rowCount(), 1) + if ok: + self.model.removeRows(rowNum, 1) + + def selectPreset(self): + from dialogs import KPAnimationPresetChooser + presetList = KPAnimationPresetChooser.run() + + if presetList is None: return + if presetList is []: return + if presetList is [[]]: return + + q = QtGui.QStandardItem + + for row in presetList: + a = q(row[0]) + b = q(row[1]) + c = q() + c.setData(row[2], Qt.EditRole) + d = q(row[3]) + e = q() + e.setData(row[4], Qt.EditRole) + f = q() + f.setData(row[5], Qt.EditRole) + g = q() + g.setData(row[6], Qt.EditRole) + + self.model.appendRow([a,b,c,d,e,f,g]) + + self.resolveAnmList() + + def addToPreset(self): + from dialogs import getTextDialog + + name = getTextDialog() + if name == None: + print 'Returning' + return + + print 'Adding.' + preset = [] + for row in xrange(self.model.rowCount()): + listrow = [] + for column in xrange(7): + item = self.model.item(row, column) + if (column == 0) or (column == 1) or (column == 2): + data = str(item.data(Qt.EditRole).toString()) + else: + data = item.data(Qt.EditRole).toFloat()[0] + + listrow.append(data) + + preset.append(listrow) + + settings = KP.app.settings + import mapfile + + if settings.contains('AnimationPresets'): + + presetList = mapfile.load(str(settings.value('AnimationPresets').toPyObject())) + presets = mapfile.load(str(settings.value('AnimationPresetData').toPyObject())) + + else: + + presetList = [] + presets = [] + + presetList.append(name) + presets.append(preset) + + settings.setValue('AnimationPresets', mapfile.dump(presetList)) + settings.setValue('AnimationPresetData', mapfile.dump(presets)) + + def resolveAnmList(self): + if self.doodadList == None: + return + + anmList = [] + model = self.model + rows = model.rowCount() + + for x in xrange(rows): + rowList = [] + + for item in xrange(7): + 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(rowList) + + for doodad in self.doodadList: + d = doodad() + + d.animations = anmList + d.setupAnimations() + + model.clear() + self.model.setHorizontalHeaderLabels(["Looping", "Interpolation", "Frame Len", "Type", "Start Value", "End Value", "Delay"]) + self._doodadRef = None + self.doodadList = None + + self.update() + + class KPMainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) @@ -644,7 +952,6 @@ class KPMainWindow(QtGui.QMainWindow): self.setWindowIcon(QtGui.QIcon('Resources/Koopatlas.png')) self.setIconSize(QtCore.QSize(16, 16)) - self.scene = KPMapScene() self.editor = KPEditorWidget(self.scene) @@ -657,7 +964,6 @@ class KPMainWindow(QtGui.QMainWindow): self.refreshMapState() - def _createAction(self, internalName, callback, title): act = QtGui.QAction(title, self) act.triggered.connect(callback) @@ -746,7 +1052,6 @@ class KPMainWindow(QtGui.QMainWindow): self.hb = h.addAction('Koopatlas Documentation', self.goToHelp) # self.hc = h.addAction('Keyboard Shortcuts') - def setupDocks(self): self.layerList = KPLayerList() self.layerListDock = QtGui.QDockWidget('Layers') @@ -774,12 +1079,21 @@ class KPMainWindow(QtGui.QMainWindow): self.doodadSelectorDock.setWidget(self.doodadSelector) self.doodadSelectorDock.hide() + self.anmOpts = KPAnmOptions() + self.editor.userClick.connect(self.anmPopulate) + + self.anmOptsDock = QtGui.QDockWidget('Doodad Animations') + self.anmOptsDock.setWidget(self.anmOpts) + self.anmOptsDock.setAllowedAreas(Qt.BottomDockWidgetArea | Qt.TopDockWidgetArea) + self.anmOptsDock.setFeatures(self.anmOptsDock.DockWidgetVerticalTitleBar | self.anmOptsDock.DockWidgetMovable | self.anmOptsDock.DockWidgetFloatable) + self.anmOptsDock.hide() + self.addDockWidget(Qt.RightDockWidgetArea, self.layerListDock) self.addDockWidget(Qt.RightDockWidgetArea, self.pathNodeDock) self.addDockWidget(Qt.LeftDockWidgetArea, self.objectSelectorDock) self.addDockWidget(Qt.LeftDockWidgetArea, self.doodadSelectorDock) + self.addDockWidget(Qt.BottomDockWidgetArea, self.anmOptsDock) - def refreshMapState(self): self.layerList.updateModel() self.doodadSelector.updateModel() @@ -802,7 +1116,6 @@ class KPMainWindow(QtGui.QMainWindow): return False - ##################### # Slots for Widgets # ##################### @@ -828,7 +1141,7 @@ class KPMainWindow(QtGui.QMainWindow): self.objectSelectorDock.setVisible(showObjects) self.doodadSelectorDock.setVisible(showDoodads) - + self.anmOptsDock.setVisible(showDoodads) @QtCore.pyqtSlot(KPLayer) def handleSelectedPathNodeLayerChanged(self, layer): @@ -846,8 +1159,6 @@ class KPMainWindow(QtGui.QMainWindow): self.objectSelectorDock.setVisible(True) self.doodadSelectorDock.setVisible(True) - - @QtCore.pyqtSlot(int, KPTileObject) def handleSelectedObjectChanged(self, index, obj): sel = self.doodadSelector.listView.selectionModel() @@ -858,7 +1169,6 @@ class KPMainWindow(QtGui.QMainWindow): self.editor.objectIDToPaint = index self.editor.typeToPaint = 'object' - @QtCore.pyqtSlot(object) def handleSelectedDoodadChanged(self, doodad): sel = self.objectSelector.listView.selectionModel() @@ -868,6 +1178,31 @@ class KPMainWindow(QtGui.QMainWindow): self.editor.doodadToPaint = doodad self.editor.typeToPaint = 'doodad' + def anmPopulate(self): + + selection = self.scene.selectedItems() + if len(selection) == 0: + self.anmOpts.resolveAnmList() + self.anmOptsDock.setWindowTitle("No Doodads Selected") + return + + doodadList = [] + + for selItem in selection: + if isinstance(selItem, KPEditorDoodad): + doodadList.append(selItem._doodadRef) + + self.anmOpts.resolveAnmList() + + if len(doodadList) == 0: + self.anmOptsDock.setWindowTitle("No Doodads Selected") + return + + suffix = '' + if len(doodadList) > 1: + suffix = 's' + self.anmOptsDock.setWindowTitle("Editing {0} Doodad{1}".format(len(doodadList), suffix)) + self.anmOpts.setupAnms(doodadList) ######################## # Slots for Menu Items # @@ -912,12 +1247,9 @@ class KPMainWindow(QtGui.QMainWindow): KP.map.save() - - def saveMapAs(self): self.saveMap(True) - def exportMap(self): target = KP.map.filePath @@ -930,7 +1262,6 @@ class KPMainWindow(QtGui.QMainWindow): KP.map.export(target) - @QtCore.pyqtSlot() def screenshot(self): items = ("Current Window", "Entire Map") @@ -964,7 +1295,6 @@ class KPMainWindow(QtGui.QMainWindow): # Edit ######################## - @QtCore.pyqtSlot() def selectAll(self): @@ -972,7 +1302,6 @@ class KPMainWindow(QtGui.QMainWindow): path.addRect(self.scene.sceneRect()) self.scene.setSelectionArea(path) - @QtCore.pyqtSlot() def deSelect(self): self.scene.clearSelection() @@ -980,7 +1309,6 @@ class KPMainWindow(QtGui.QMainWindow): # Layers ######################## - @QtCore.pyqtSlot() def moveTilesetToFolder(self): @@ -1001,7 +1329,6 @@ class KPMainWindow(QtGui.QMainWindow): KP.knownTilesets[name] = {'path': path} - @QtCore.pyqtSlot() def changeTileset(self): @@ -1024,13 +1351,11 @@ class KPMainWindow(QtGui.QMainWindow): # Animate ######################## - @QtCore.pyqtSlot() def playAnim(self): self.scene.playPause() self.playButtonChanged() - @QtCore.pyqtSlot() def playButtonChanged(self): if self.scene.playing: @@ -1042,14 +1367,12 @@ class KPMainWindow(QtGui.QMainWindow): self.layerList.actPlayPause.setIcon(KP.icon('APlay')) self.layerList.actPlayPause.setText('Play') - @QtCore.pyqtSlot() def resetAnim(self): if self.scene.playing == True: self.scene.playPause() self.scene.playPause() - @QtCore.pyqtSlot() def loadAnimPresets(self): path = QtGui.QFileDialog.getOpenFileName(self, @@ -1089,8 +1412,6 @@ class KPMainWindow(QtGui.QMainWindow): settings.setValue('AnimationPresets', mapfile.dump(presetList)) settings.setValue('AnimationPresetData', mapfile.dump(presets)) - - @QtCore.pyqtSlot() def saveAnimPresets(self): @@ -1123,8 +1444,6 @@ class KPMainWindow(QtGui.QMainWindow): file.write(mapfile.dump(output)) file.close() - - @QtCore.pyqtSlot() def clearAnimPresets(self): settings = KP.app.settings @@ -1136,7 +1455,6 @@ class KPMainWindow(QtGui.QMainWindow): # Window ######################## - @QtCore.pyqtSlot() def ZoomActual(self): """Handle zooming to the editor size""" @@ -1173,7 +1491,6 @@ class KPMainWindow(QtGui.QMainWindow): self.scene.update() - @QtCore.pyqtSlot() def showGrid(self): """Handle toggling of the grid being showed""" @@ -1187,7 +1504,6 @@ class KPMainWindow(QtGui.QMainWindow): print self.scene.grid self.scene.update() - @QtCore.pyqtSlot(bool) def showWiiZoom(self): pass @@ -1195,7 +1511,6 @@ class KPMainWindow(QtGui.QMainWindow): # Help ######################## - @QtCore.pyqtSlot(bool) def aboutDialog(self): caption = "About Koopatlas" @@ -1205,7 +1520,6 @@ class KPMainWindow(QtGui.QMainWindow): msg = QtGui.QMessageBox.about(KP.mainWindow, caption, text) - @QtCore.pyqtSlot(bool) def goToHelp(self): QtGui.QDesktopServices().openUrl(QtCore.QUrl('http://www.newerteam.com/koopatlas-help')) -- cgit v1.2.3