diff options
author | Colin Noga <Tempus@chronometry.ca> | 2012-07-23 13:29:54 -0500 |
---|---|---|
committer | Colin Noga <Tempus@chronometry.ca> | 2012-07-23 13:29:54 -0500 |
commit | 1498632b8bc91d0f83dcbfbdd03fa7499ef0985e (patch) | |
tree | bc43b079e61da3c617a103564e6e422f7933bcbb | |
parent | e3bbfbabe74bb525adcf16b784338c4cf4e7507c (diff) | |
download | koopatlas-1498632b8bc91d0f83dcbfbdd03fa7499ef0985e.tar.gz koopatlas-1498632b8bc91d0f83dcbfbdd03fa7499ef0985e.zip |
Streamlined node drawing with auto-tilesets (bypass with Alt-click), double click a node layer to jump to it, selecting a path/node layer makes it visibly red (except level nodes)
Diffstat (limited to '')
-rw-r--r-- | src/editorui/editormain.py | 15 | ||||
-rw-r--r-- | src/editorui/paths.py | 32 | ||||
-rw-r--r-- | src/ui.py | 65 |
3 files changed, 89 insertions, 23 deletions
diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py index 4b2e686..11df8dd 100644 --- a/src/editorui/editormain.py +++ b/src/editorui/editormain.py @@ -506,6 +506,11 @@ class KPEditorWidget(QtGui.QGraphicsView): x, y = clicked.x(), clicked.y() itemsUnder = self.scene().items(clicked) + if event.modifiers() & Qt.AltModifier: + dialog = True + else: + dialog = False + for item in itemsUnder: if isinstance(item, KPEditorNode): # Paint a path to this node (if one is selected) @@ -541,7 +546,7 @@ class KPEditorWidget(QtGui.QGraphicsView): path = KPPath(sourceNode, destNode) KP.map.pathLayer.paths.append(path) - KP.mainWindow.pathNodeList.addLayer(path) + KP.mainWindow.pathNodeList.addLayer(path, dialog) item = KPEditorPath(path) self.scene().addItem(item) @@ -556,7 +561,7 @@ class KPEditorWidget(QtGui.QGraphicsView): node = KPNode() node.position = (x - 12, y - 12) KP.map.pathLayer.nodes.append(node) - KP.mainWindow.pathNodeList.addLayer(node) + KP.mainWindow.pathNodeList.addLayer(node, dialog) # Start node => Original path => New node => New path => End node @@ -577,7 +582,7 @@ class KPEditorWidget(QtGui.QGraphicsView): newPath = KPPath(node, endNode, origPath) KP.map.pathLayer.paths.append(newPath) - KP.mainWindow.pathNodeList.addLayer(newPath) + KP.mainWindow.pathNodeList.addLayer(newPath, dialog) pathItem = KPEditorPath(newPath) self.scene().addItem(pathItem) @@ -588,7 +593,7 @@ class KPEditorWidget(QtGui.QGraphicsView): node = KPNode() node.position = (x - 12, y - 12) KP.map.pathLayer.nodes.append(node) - KP.mainWindow.pathNodeList.addLayer(node) + KP.mainWindow.pathNodeList.addLayer(node, dialog) item = KPEditorNode(node) self.scene().addItem(item) @@ -614,7 +619,7 @@ class KPEditorWidget(QtGui.QGraphicsView): path = KPPath(sourceNode, node) KP.map.pathLayer.paths.append(path) - KP.mainWindow.pathNodeList.addLayer(path) + KP.mainWindow.pathNodeList.addLayer(path, dialog) pathItem = KPEditorPath(path) self.scene().addItem(pathItem) diff --git a/src/editorui/paths.py b/src/editorui/paths.py index a40ab2b..4110188 100644 --- a/src/editorui/paths.py +++ b/src/editorui/paths.py @@ -111,7 +111,7 @@ class KPEditorNode(KPEditorItem): self._levelRect = self._boundingRect self._stopRect = QtCore.QRectF(-12, -12, 24, 24) self._tinyRect = QtCore.QRectF(-6, -6, 12, 12) - + self.isLayerSelected = False if not hasattr(KPEditorNode, 'SELECTION_PEN'): KPEditorNode.SELECTION_PEN = QtGui.QPen(Qt.blue, 1, Qt.DotLine) @@ -261,6 +261,11 @@ class KPEditorNode(KPEditorItem): exit.qtItem.updatePosition() + def setLayerSelected(self, selected): + self.isLayerSelected = selected + self.update() + + def paint(self, painter, option, widget): painter.setRenderHint(QtGui.QPainter.Antialiasing) @@ -294,14 +299,20 @@ class KPEditorNode(KPEditorItem): selectionRect = self._boundingRect.adjusted(1,5,-1,-5) elif len(node.exits) != 2: - brush = QtGui.QBrush(QtGui.QColor(255, 220, 220)) + if self.isLayerSelected: + brush = QtGui.QBrush(QtGui.QColor(255, 40, 40)) + else: + brush = QtGui.QBrush(QtGui.QColor(255, 220, 220)) painter.setPen(QtGui.QColor(255, 255, 255)) painter.setBrush(brush) painter.drawEllipse(self._stopRect) selectionRect = self._stopRect.adjusted(-1,-1,1,1) else: - brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) + if self.isLayerSelected: + brush = QtGui.QBrush(QtGui.QColor(255, 40, 40)) + else: + brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) painter.setPen(QtGui.QColor(255, 255, 255)) painter.setBrush(brush) painter.drawEllipse(self._tinyRect) @@ -640,6 +651,7 @@ class KPEditorPath(QtGui.QGraphicsLineItem): self._startNodeRef = weakref.ref(startNode) self._endNodeRef = weakref.ref(endNode) self._pathRef = weakref.ref(path) + self.isLayerSelected = False path.qtItem = self @@ -685,11 +697,23 @@ class KPEditorPath(QtGui.QGraphicsLineItem): self.setLine(QtCore.QLineF(-dx, -dy, dx, dy)) + def setLayerSelected(self, selected): + self.isLayerSelected = selected + self.update() + + def paint(self, painter, option, widget): painter.setRenderHint(QtGui.QPainter.Antialiasing) - painter.setPen(KPEditorPath.PEN) + if self.isLayerSelected: + brush = QtGui.QBrush(QtGui.QColor(255, 40, 40, 200)) + pen = QtGui.QPen(brush, 12, Qt.SolidLine, Qt.RoundCap) + painter.setPen(pen) + painter.setBrush(brush) + else: + painter.setPen(KPEditorPath.PEN) + painter.drawLine(self.line()) if self.isSelected(): @@ -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 ######################## |