diff options
Diffstat (limited to '')
-rw-r--r-- | src/ui.py | 105 |
1 files changed, 85 insertions, 20 deletions
@@ -7,6 +7,50 @@ import os import os.path +class KPPathNodeList(QtGui.QWidget): + def __init__(self): + QtGui.QWidget.__init__(self) + + self.layout = QtGui.QVBoxLayout() + self.layout.setSpacing(0) + + self.tree = QtGui.QTreeWidget() + self.layout.addWidget(self.tree) + + self.toolbar = QtGui.QToolBar() + self.layout.addWidget(self.toolbar) + + self.setupToolbar(self.toolbar) + self.setLayout(self.layout) + + + def setupToolbar(self, tb): + self.actAddFolder = tb.addAction(KP.icon('LayerNewTile'), 'Add Folder', self.addTileLayer) + self.actRemoveFolder = tb.addAction(KP.icon('LayerNewObjects'), 'Remove Folder', self.addDoodadLayer) + self.actMoveUp = tb.addAction(QtGui.QIcon(), 'Move Up', self.moveUp) + self.actMoveDown = tb.addAction(QtGui.QIcon(), 'Move Down', self.moveDown) + + + selectedLayerChanged = QtCore.pyqtSignal(KPLayer) + + @QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex) + def handleRowChanged(self, current, previous): + self.selectedLayerChanged.emit(KP.map.layers[current.row()]) + self.setButtonStates() + + def moveUp(self): + index = self.selectedLayerIndex() + KP.map.moveLayer(index, index - 1) + KP.mainWindow.editor.viewport().update() + + def moveDown(self): + index = self.selectedLayerIndex() + KP.map.moveLayer(index, index + 2) + KP.mainWindow.editor.viewport().update() + + + + class KPLayerList(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) @@ -63,7 +107,7 @@ class KPLayerList(QtGui.QWidget): def selectedLayerIndex(self): return self.listView.selectionModel().currentIndex().row() def selectedLayer(self): - return KP.map.layers[self.listView.selectionModel().currentIndex().row()] + return KP.map.layers[self.selectedLayerIndex()] selectedLayerChanged = QtCore.pyqtSignal(KPLayer) @@ -466,8 +510,9 @@ class KPMainWindow(QtGui.QMainWindow): self.lf = l.addAction('Move Layer to Top', self.layerList.moveTop, QKeySequence("Ctrl+Shift+Up")) self.lg = l.addAction('Move Layer to Bottom', self.layerList.moveBottom, QKeySequence("Ctrl+Shift+Down")) l.addSeparator() - self.lh = l.addAction('Add Tileset...', self.moveTilesetToFolder, QKeySequence("Ctrl+Shift+T")) self.li = l.addAction('Add Doodad...', self.doodadSelector.addDoodadFromFile, QKeySequence("Ctrl+Shift+R")) + self.lh = l.addAction('Add Tileset...', self.moveTilesetToFolder, QKeySequence("Ctrl+Shift+T")) + self.lj = l.addAction('Change Tileset...', self.changeTileset, QKeySequence("Ctrl+Shift+Alt+T")) a = mb.addMenu('Animate') self.aa = a.addAction('Play Animations', self.playAnim, QKeySequence("Ctrl+P")) @@ -553,9 +598,9 @@ class KPMainWindow(QtGui.QMainWindow): - ##################### - # Slots for Widgets # - ##################### +##################### +# Slots for Widgets # +##################### @QtCore.pyqtSlot(KPLayer) def handleSelectedLayerChanged(self, layer): @@ -587,12 +632,12 @@ class KPMainWindow(QtGui.QMainWindow): self.editor.doodadToPaint = doodad - ######################## - # Slots for Menu Items # - ######################## +######################## +# Slots for Menu Items # +######################## - # File - ######################## +# File +######################## def newMap(self): if self.checkDirty(): return @@ -680,8 +725,8 @@ class KPMainWindow(QtGui.QMainWindow): ScreenshotImage.save(fn, 'PNG', 50) - # Edit - ######################## +# Edit +######################## @QtCore.pyqtSlot() def selectAll(self): @@ -696,8 +741,8 @@ class KPMainWindow(QtGui.QMainWindow): self.scene.clearSelection() - # Layers - ######################## +# Layers +######################## @QtCore.pyqtSlot() def moveTilesetToFolder(self): @@ -722,8 +767,28 @@ class KPMainWindow(QtGui.QMainWindow): KP.map.loadedTilesets[name] = KPTileset.loadFromArc(path) - # Animate - ######################## + @QtCore.pyqtSlot() + def changeTileset(self): + + layer = self.layerList.selectedLayer() + + if not isinstance(layer, KPTileLayer): + return + + + from dialogs import KPTilesetChooserDialog + + tilesetName = KPTilesetChooserDialog.run('Choose a tileset to change to') + if tilesetName is None: + return + + KPTileLayer.tileset = tilesetName + + self.objectSelector.setModel(KP.map.loadedTilesets[layer.tileset].getModel()) + + +# Animate +######################## @QtCore.pyqtSlot() def playAnim(self): @@ -834,8 +899,8 @@ class KPMainWindow(QtGui.QMainWindow): settings.setValue('AnimationPresetData', mapfile.dump([])) - # Window - ######################## +# Window +######################## @QtCore.pyqtSlot() def ZoomActual(self): @@ -893,8 +958,8 @@ class KPMainWindow(QtGui.QMainWindow): pass - # Help - ######################## +# Help +######################## @QtCore.pyqtSlot(bool) def aboutDialog(self): |