diff options
Diffstat (limited to 'src/ui.py')
-rw-r--r-- | src/ui.py | 293 |
1 files changed, 270 insertions, 23 deletions
@@ -7,6 +7,202 @@ import os import os.path +class KPPathNodeList(QtGui.QWidget): + + class KPPathNodeItem(QtGui.QTreeWidgetItem): + def __init__(self, parent, layer, associate): + QtGui.QTreeWidgetItem.__init__(self, parent) + + self.layer = layer + self.associate = associate + + self.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsEnabled) + + + def data(self, index, role=Qt.DisplayRole): + + if role == Qt.DecorationRole: + if isinstance(self.associate, KPNode): + node = self.associate + + if node.level: + return QtGui.QIcon('LevelNodeIcon') + elif node.mapChange != None: + return QtGui.QIcon('ExitNodeIcon') + elif len(node.exits) != 2: + return QtGui.QIcon('StopNodeIcon') + else: + return QtGui.QIcon('ThroughNodeIcon') + + else: + return QtGui.QIcon('PathIcon') + + elif role == Qt.DisplayRole: + if isinstance(self.associate, KPNode): + node = self.associate + + if node.level: + return "Level Node: {0}".format(node.level) + elif node.mapChange != None: + return "Exit to World {0}, entrance {1}".format(mapID, foreignID) + elif len(node.exits) == 3: + return "3-way Junction" + elif len(node.exits) == 4: + return "4-way Junction" + elif len(node.exits) > 4: + return "Illegal Node" + else: + return "Pass Through Node" + + else: + AnimationList = ["Walk", "WalkSand", "WalkSnow", "WalkIce", + "Jump", "JumpSand", "JumpSnow", "SpinJump", + "Ladder", "LadderLeft", "LadderRight", "Fall", + "Swim", "Run", "Pipe", "Door"] + animation = AnimationList[self.associate.animation] + if self.associate.secret == 0: + unlock = 'Normal' + else: + unlock = 'Secret' + + return 'Path: {0} Exit, {1}'.format(unlock, animation) + + else: + return QtGui.QTreeWidgetItem.data(self, index, role) + + + def layer(self): + return self.layer + + def associate(self): + return self.associate + + + def __init__(self): + QtGui.QWidget.__init__(self) + + self.layout = QtGui.QVBoxLayout() + self.layout.setSpacing(0) + + self.tree = QtGui.QTreeWidget() + self.tree.setColumnCount(1) + self.tree.setDragEnabled(True) + self.tree.setDragDropMode(self.tree.InternalMove) + self.tree.itemClicked.connect(self.handleRowChanged) + 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.addFolder) + self.actRemoveFolder = tb.addAction(KP.icon('LayerNewObjects'), '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() + try: + self.selectedLayerChanged.emit(item.layer) + except: + pass + + def addFolder(self): + item = QtGui.QTreeWidgetItem(self.tree) + item.setIcon(0, QtGui.QIcon('Folder')) + item.setText(0, 'Untitled Folder') + item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled | Qt.ItemIsEditable | Qt.ItemIsEnabled) + + def removeFolder(self): + item = self.tree.currentItem() + if not isinstance(item, self.KPPathNodeItem): + kids = item.takeChildren() + parent = item.parent() + if parent: + parent.takeChild(item) + else: + self.tree.takeTopLevelItem(self.tree.currentIndex().row()) + + self.tree.addTopLevelItems(kids) + + def setTileset(self): + from dialogs import KPTilesetChooserDialog + + tilesetName = KPTilesetChooserDialog.run('Choose a tileset for the path/node layers') + if tilesetName is None: + return + + KP.map.pathNodeTileset = tilesetName + + def addLayer(self, associate): + layer = KPPathTileLayer(associate) + item = self.KPPathNodeItem(self.tree, layer, associate) + + def removeLayer(self, associate): + trash = None + + for itemI in xrange(self.tree.topLevelItemCount()): + item = self.tree.topLevelItem(itemI) + + if item.associate == associate: + trash = item + else: + trash = self.removeRecursor(item, associate) + + if trash != None: + break + + parent = trash.parent() + if parent: + parent.takeChild(trash) + else: + self.tree.takeTopLevelItem(self.tree.indexOfTopLevelItem(trash)) + + def removeRecursor(self, parent, associate): + trash = None + + for itemI in xrange(parent.childCount()): + item = parent.child(itemI) + + if item.associate == associate: + trash = item + else: + trash = self.removeRecursor(item, associate) + + if trash != None: + return trash + + return None + + def getLayers(self): + layerList = [] + for itemI in xrange(self.tree.topLevelItemCount()): + item = self.tree.topLevelItem(itemI) + + if not isinstance(item, self.KPPathNodeItem): + self.recursiveLayerRetriever(item, layerList) + else: + layerList.append(item.layer) + + return layerList + + def recursiveLayerRetriever(self, parent, layerList): + + for itemI in xrange(parent.childCount()): + item = parent.child(itemI) + + if not isinstance(item, self.KPPathNodeItem): + self.recursiveLayerRetriever(item, layerList) + else: + layerList.append(item.layer) + + class KPLayerList(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) @@ -29,7 +225,7 @@ class KPLayerList(QtGui.QWidget): def updateModel(self): self.model = KP.map.layerModel self.listView.setModel(self.model) - self.listView.selectionModel().currentRowChanged.connect(self.handleRowChanged) + self.listView.clicked.connect(self.handleRowChanged) self.setButtonStates() @@ -63,12 +259,12 @@ 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) - @QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex) - def handleRowChanged(self, current, previous): + @QtCore.pyqtSlot(QtCore.QModelIndex) + def handleRowChanged(self, current): self.selectedLayerChanged.emit(KP.map.layers[current.row()]) self.setButtonStates() @@ -466,8 +662,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")) @@ -512,6 +709,11 @@ class KPMainWindow(QtGui.QMainWindow): self.layerList.selectedLayerChanged.connect(self.handleSelectedLayerChanged) self.layerList.playPaused.connect(self.playAnim) + self.pathNodeList = KPPathNodeList() + self.pathNodeDock = QtGui.QDockWidget('Path/Node Layers') + self.pathNodeDock.setWidget(self.pathNodeList) + self.pathNodeList.selectedLayerChanged.connect(self.handleSelectedPathNodeLayerChanged) + self.objectSelector = KPObjectSelector() self.objectSelector.objChanged.connect(self.handleSelectedObjectChanged) @@ -527,6 +729,7 @@ class KPMainWindow(QtGui.QMainWindow): self.doodadSelectorDock.hide() self.addDockWidget(Qt.RightDockWidgetArea, self.layerListDock) + self.addDockWidget(Qt.RightDockWidgetArea, self.pathNodeDock) self.addDockWidget(Qt.RightDockWidgetArea, self.objectSelectorDock) self.addDockWidget(Qt.RightDockWidgetArea, self.doodadSelectorDock) @@ -553,12 +756,14 @@ class KPMainWindow(QtGui.QMainWindow): - ##################### - # Slots for Widgets # - ##################### +##################### +# Slots for Widgets # +##################### @QtCore.pyqtSlot(KPLayer) def handleSelectedLayerChanged(self, layer): + self.pathNodeList.tree.selectionModel().clearSelection() + self.scene.setCurrentLayer(layer) showObjects, showDoodads = False, False @@ -576,23 +781,45 @@ class KPMainWindow(QtGui.QMainWindow): self.doodadSelectorDock.setVisible(showDoodads) + @QtCore.pyqtSlot(KPLayer) + def handleSelectedPathNodeLayerChanged(self, layer): + + self.layerList.listView.selectionModel().clearSelection() + + self.scene.setCurrentLayer(layer) + + KP.map.reloadTileset(KP.map.pathNodeTileset) + + self.objectSelector.setModel(KP.map.loadedTilesets[KP.map.pathNodeTileset].getModel()) + + self.objectSelectorDock.setVisible(True) + self.doodadSelectorDock.setVisible(True) + + + @QtCore.pyqtSlot(int, KPTileObject) def handleSelectedObjectChanged(self, index, obj): + self.doodadSelector.listView.selectionModel().clearSelection() + self.editor.objectToPaint = obj self.editor.objectIDToPaint = index + self.editor.typeToPaint = 'object' @QtCore.pyqtSlot(object) def handleSelectedDoodadChanged(self, doodad): + self.objectSelector.listView.selectionModel().clearSelection() + self.editor.doodadToPaint = doodad + self.editor.typeToPaint = 'doodad' - ######################## - # Slots for Menu Items # - ######################## +######################## +# Slots for Menu Items # +######################## - # File - ######################## +# File +######################## def newMap(self): if self.checkDirty(): return @@ -680,8 +907,8 @@ class KPMainWindow(QtGui.QMainWindow): ScreenshotImage.save(fn, 'PNG', 50) - # Edit - ######################## +# Edit +######################## @QtCore.pyqtSlot() def selectAll(self): @@ -696,8 +923,8 @@ class KPMainWindow(QtGui.QMainWindow): self.scene.clearSelection() - # Layers - ######################## +# Layers +######################## @QtCore.pyqtSlot() def moveTilesetToFolder(self): @@ -722,8 +949,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 +1081,8 @@ class KPMainWindow(QtGui.QMainWindow): settings.setValue('AnimationPresetData', mapfile.dump([])) - # Window - ######################## +# Window +######################## @QtCore.pyqtSlot() def ZoomActual(self): @@ -893,8 +1140,8 @@ class KPMainWindow(QtGui.QMainWindow): pass - # Help - ######################## +# Help +######################## @QtCore.pyqtSlot(bool) def aboutDialog(self): |