From bd62c887e956b658d3ec1b47099fa07882386d1f Mon Sep 17 00:00:00 2001 From: Colin Noga Date: Sat, 3 Dec 2011 02:08:17 -0600 Subject: Fixed up some UI stuff, added animation presets to make life easier for animations --- Resources/Koopatlas.png | Bin 0 -> 236352 bytes src/dialogs.py | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ src/editorui/doodads.py | 80 +++++++++++++++++++++++++++++++++++++-- src/main.py | 3 ++ src/mapdata.py | 4 +- src/ui.py | 37 +++++++++--------- 6 files changed, 198 insertions(+), 24 deletions(-) create mode 100644 Resources/Koopatlas.png diff --git a/Resources/Koopatlas.png b/Resources/Koopatlas.png new file mode 100644 index 0000000..e584f52 Binary files /dev/null and b/Resources/Koopatlas.png differ diff --git a/src/dialogs.py b/src/dialogs.py index b033294..0419f4f 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -69,3 +69,101 @@ class KPTilesetChooserDialog(QtGui.QDialog): return None + + +class KPAnimationPresetChooser(QtGui.QDialog): + def __init__(self, label='Choose a preset to add:', specials=None): + QtGui.QDialog.__init__(self) + + self.label = QtGui.QLabel(label) + self.label.setWordWrap(True) + + # can't be assed to create a model + self.chooser = QtGui.QListWidget() + + settings = KP.app.settings + + if settings.contains('AnimationPresets'): + self.presetList = settings.value('AnimationPresets').toPyObject() + self.presets = settings.value('AnimationPresetData').toPyObject() + + else: + self.presetList = ["Circle", "Wiggle", "Drifting Cloud"] + self.presets = [ [["Loop", "Sinusoidial", 200.0, "X Position", -200.0, 200.0], + ["Loop", "Cosinoidial", 200.0, "Y Position", -200.0, 200.0]], + + [["Reversible Loop", "Sinusoidial", 50.0, "Y Scale", 100.0, 120.0], + ["Loop", "Cosinoidial", 50.0, "X Scale", 100.0, 90.0], + ["Reversible Loop", "Sinusoidial", 20.0, "Angle", 10.0, -10.0]], + + [["Loop", "Sinusoidial", 5000.0, "X Position", -400.0, 400.0], + ["Loop", "Sinusoidial", 200.0, "Y Position", 10.0, -10.0], + ["Reversible Loop", "Linear", 500.0, "Opacity", 80.0, 40.0]] ] + + + settings.setValue('AnimationPresets', self.presetList) + settings.setValue('AnimationPresetData', self.presets) + + + self.chooser.addItems(self.presetList) + + self.chooser.currentRowChanged.connect(self.handleCurrentRowChanged) + self.chooser.itemActivated.connect(self.handleItemActivated) + + self.buttons = QtGui.QDialogButtonBox( + QtGui.QDialogButtonBox.Ok | + QtGui.QDialogButtonBox.Cancel) + + self.okButton = self.buttons.button(QtGui.QDialogButtonBox.Ok) + self.okButton.setEnabled(False) + + self.buttons.accepted.connect(self.accept) + self.buttons.rejected.connect(self.reject) + + self.layout = QtGui.QVBoxLayout() + self.layout.addWidget(self.label) + self.layout.addWidget(self.chooser) + self.layout.addWidget(self.buttons) + self.setLayout(self.layout) + + def handleCurrentRowChanged(self, row): + self.okButton.setEnabled(row != -1) + + def handleItemActivated(self, item): + self.accept() + + def getChoice(self): + item = self.chooser.currentItem() + number = self.chooser.currentRow() + + if item is None: + return None + else: + return self.presets[number] + + + @classmethod + def run(cls, *args): + dialog = cls(*args) + result = dialog.exec_() + + if result == QtGui.QDialog.Accepted: + return dialog.getChoice() + else: + return None + + + + + +def getTextDialog(): + + text, ok = QtGui.QInputDialog.getText(KP.mainWindow, "Choose Preset Name", "Preset name:") + + print text + if ok and text != '': + return text + else: + return None + + diff --git a/src/editorui/doodads.py b/src/editorui/doodads.py index f57502a..d7f767f 100644 --- a/src/editorui/doodads.py +++ b/src/editorui/doodads.py @@ -125,15 +125,19 @@ class KPEditorDoodad(KPEditorItem): self.anmTable.horizontalHeader().setVisible(True) self.anmTable.verticalHeader().setVisible(False) - BottomLayout.addWidget(self.anmTable, 0, 0, 1, 4) + BottomLayout.addWidget(self.anmTable, 0, 0, 1, 6) # Add/Remove Animation Buttons addbutton = QtGui.QPushButton("Add Animation") rembutton = QtGui.QPushButton("Remove Animation") + presetbutton = QtGui.QPushButton("Add Preset") + newpbutton = QtGui.QPushButton("New Preset") 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) # Annnnndddd we're spent. @@ -142,6 +146,9 @@ class KPEditorDoodad(KPEditorItem): addbutton.released.connect(self.addAnmItem) rembutton.released.connect(self.remAnmItem) + presetbutton.released.connect(self.selectPreset) + newpbutton.released.connect(self.addToPreset) + def sizeHint(self): return QtCore.QSize(591,300) @@ -165,16 +172,81 @@ class KPEditorDoodad(KPEditorItem): def remAnmItem(self): - if self.anmTable.rows() == 0: + if self.model.rowCount() == 0: return rowNum, ok = QtGui.QInputDialog.getInteger(self, - "Select A Row", "Delete This Row:", 0, 0, self.anmTable.rows(), 1) + "Select A Row", "Delete This Row:", 0, 0, self.model.rowCount(), 1) if ok: - rowNum = QtGui.Q 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) + + self.model.appendRow([a,b,c,d,e,f]) + + + 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(6): + 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 + + if settings.contains('AnimationPresets'): + + presetList = settings.value('AnimationPresets').toPyObject() + presets = settings.value('AnimationPresetData').toPyObject() + + else: + + presetList = [] + presets = [] + + presetList.append(name) + presets.append(preset) + + settings.setValue('AnimationPresets', presetList) + settings.setValue('AnimationPresetData', presets) + + def __init__(self, doodadRef): QtGui.QPushButton.__init__(self) diff --git a/src/main.py b/src/main.py index e6b72d2..a429916 100644 --- a/src/main.py +++ b/src/main.py @@ -5,6 +5,9 @@ class KP: def run(): KP.app = QtGui.QApplication(sys.argv) + KP.app.settings = QtCore.QSettings('Koopatlas', 'Newer Team') + + from mapdata import KPMap KP.map = KPMap() diff --git a/src/mapdata.py b/src/mapdata.py index 1eb35c8..ea62111 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -556,9 +556,11 @@ class KPMap(object): doodad = self.list[index.row()] if role == Qt.DecorationRole: - return doodad[1] + return QtGui.QIcon(doodad[1]) elif role == Qt.ToolTipRole: return doodad[0] + elif role == Qt.DisplayRole: + return doodad[0] except IndexError: pass diff --git a/src/ui.py b/src/ui.py index d3b9d56..bd447ca 100644 --- a/src/ui.py +++ b/src/ui.py @@ -46,12 +46,6 @@ class KPLayerList(QtGui.QWidget): def toggleAnimatingScene(self): self.playPaused.emit() - if self.actPlayPause.text() == 'Play': - self.actPlayPause.setIcon(KP.icon('AStop')) - self.actPlayPause.setText('Stop') - else: - self.actPlayPause.setIcon(KP.icon('APlay')) - self.actPlayPause.setText('Play') def setButtonStates(self): index = self.selectedLayerIndex() @@ -192,21 +186,21 @@ class KPDoodadSelector(QtGui.QWidget): 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.""" + # 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.""" - 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) + # 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 + # self.doodadList.addItem(doodie) + # self.nextIndex += 1 def addDoodadFromFile(self): @@ -404,6 +398,11 @@ class KPMainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) + self.setWindowTitle('Koopatlas') + self.setWindowIcon(QtGui.QIcon('Resources/Koopatlas.png')) + self.setIconSize(QtCore.QSize(16, 16)) + + self.scene = KPMapScene() self.editor = KPEditorWidget(self.scene) @@ -645,7 +644,7 @@ class KPMainWindow(QtGui.QMainWindow): item, ok = QtGui.QInputDialog.getItem(self, "QInputDialog.getItem()", "Choose a Screenshot Source:", items, 0, False) if ok and item: - fn = QtGui.QFileDialog.getSaveFileName(self, 'Choose a new filename', '/untitled.png', 'Portable Network Graphics (*.png)') + fn = QtGui.QFileDialog.getSaveFileName(self, 'Choose a new filename', 'untitled.png', 'Portable Network Graphics (*.png)') if fn == '': return fn = unicode(fn) -- cgit v1.2.3