diff options
Diffstat (limited to 'src/ui.py')
-rw-r--r-- | src/ui.py | 65 |
1 files changed, 51 insertions, 14 deletions
@@ -18,7 +18,6 @@ class KPPathNodeList(QtGui.QWidget): self.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable) - def data(self, index, role=Qt.DisplayRole): if role == Qt.DecorationRole: @@ -75,12 +74,10 @@ class KPPathNodeList(QtGui.QWidget): else: return QtGui.QTreeWidgetItem.data(self, index, role) - def setData(self, column, role = Qt.EditRole, value = None): if role == Qt.CheckStateRole: self.layer.visible = value.toBool() - def layer(self): return self.layer @@ -98,7 +95,8 @@ class KPPathNodeList(QtGui.QWidget): self.tree.setDragEnabled(True) self.tree.setDragDropMode(self.tree.InternalMove) self.tree.setHeaderHidden(True) - self.tree.itemClicked.connect(self.handleRowChanged) + self.tree.currentItemChanged.connect(self.handleRowChanged) + self.tree.itemDoubleClicked.connect(self.jumpToPathNode) self.layout.addWidget(self.tree) self.toolbar = QtGui.QToolBar() @@ -106,6 +104,8 @@ class KPPathNodeList(QtGui.QWidget): self.setupToolbar(self.toolbar) self.setLayout(self.layout) + + self.lastTileset = '' def reset(self): self.tree.clear() @@ -118,11 +118,21 @@ class KPPathNodeList(QtGui.QWidget): self.actRemoveFolder = tb.addAction(KP.icon('DelFolder'), 'Remove Folder', self.removeFolder) self.selectTileset = tb.addAction(KP.icon('LayerNewTile'), 'Select Tileset', self.setTileset) - @QtCore.pyqtSlot() - def handleRowChanged(self): - item = self.tree.currentItem() + @QtCore.pyqtSlot(KPPathNodeItem, KPPathNodeItem) + def handleRowChanged(self, currentItem, previousItem): + print currentItem, previousItem + try: + self.selectedLayerChanged.emit(currentItem.layer) + previousItem.associate.qtItem.setLayerSelected(False) + currentItem.associate.qtItem.setLayerSelected(True) + except: + pass + + @QtCore.pyqtSlot(KPPathNodeItem, KPPathNodeItem) + def jumpToPathNode(self, item): try: - self.selectedLayerChanged.emit(item.layer) + pos = item.associate.qtItem.pos() + KP.mainWindow.editor.centerOn(pos) except: pass @@ -161,17 +171,28 @@ class KPPathNodeList(QtGui.QWidget): layer.setTileset(tilesetName) - def addLayer(self, associate): + def addLayer(self, associate, dialog): layer = KPPathTileLayer(associate) name = 'path' if isinstance(associate, KPPath) else 'node' from dialogs import KPTilesetChooserDialog - tilesetName = None - while tilesetName is None: - tilesetName = KPTilesetChooserDialog.run('Choose a tileset for the %s layer' % name) + if dialog: + tilesetName = None + while tilesetName is None: + tilesetName = KPTilesetChooserDialog.run('Choose a tileset for the %s layer' % name) - layer.tileset = tilesetName + self.lastTileset = tilesetName + + else: + if self.lastTileset == '': + tilesetName = None + while tilesetName is None: + tilesetName = KPTilesetChooserDialog.run('Choose a tileset for the %s layer' % name) + + self.lastTileset = tilesetName + + layer.tileset = self.lastTileset item = self.KPPathNodeItem(self.tree, layer, associate) @@ -1001,7 +1022,8 @@ class KPMainWindow(QtGui.QMainWindow): f.addSeparator() self.fd = f.addAction('Save', self.saveMap, QKeySequence("Ctrl+S")) self.fe = f.addAction('Save As...', self.saveMapAs, QKeySequence("Ctrl+Shift+S")) - self.ff = f.addAction('Export...', self.exportMap, QKeySequence("Ctrl+Shift+E")) + self.ff = f.addAction('Export...', self.exportMap, QKeySequence("Ctrl+E")) + self.fj = f.addAction('Batch...', self.batchSave, QKeySequence("Ctrl+Shift+E")) f.addSeparator() self.fg = f.addAction('Take Screenshot...', self.screenshot, QKeySequence("Ctrl+Alt+S")) self.fh = f.addAction('Export Doodads...', self.exportDoodads, QKeySequence("Ctrl+Alt+Shift+D")) @@ -1245,6 +1267,7 @@ class KPMainWindow(QtGui.QMainWindow): obj = mapfile.load(open(target, 'rb').read()) obj.filePath = target KP.map = obj + KP.map.filePath = target self.refreshMapState() def saveMap(self, forceNewName=False): @@ -1319,6 +1342,20 @@ class KPMainWindow(QtGui.QMainWindow): d[1].save(fn + d[0] + '.png', 'PNG') + def batchSave(self): + target = unicode(QtGui.QFileDialog.getExistingDirectory(self, 'Choose a folder')) + + for fileName in os.listdir(target): + + if fileName[:-6] == ".kpmap": + import mapfile + + obj = mapfile.load(open(target, 'rb').read()) + obj.save() + obj.export(target + filename[:-6] + '.kpbin') + + print 'Saved and Exported {0}'.format(filename[:-6]) + # Edit ######################## |