summaryrefslogtreecommitdiff
path: root/src/ui.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.py')
-rw-r--r--src/ui.py222
1 files changed, 202 insertions, 20 deletions
diff --git a/src/ui.py b/src/ui.py
index db9d409..13d0039 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -8,6 +8,76 @@ 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)
@@ -15,6 +85,10 @@ class KPPathNodeList(QtGui.QWidget):
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()
@@ -25,30 +99,108 @@ class KPPathNodeList(QtGui.QWidget):
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)
-
+ 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(QtCore.QModelIndex, QtCore.QModelIndex)
- def handleRowChanged(self, current, previous):
- self.selectedLayerChanged.emit(KP.map.layers[current.row()])
- self.setButtonStates()
+ @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())
- def moveUp(self):
- index = self.selectedLayerIndex()
- KP.map.moveLayer(index, index - 1)
- KP.mainWindow.editor.viewport().update()
+ self.tree.addTopLevelItems(kids)
- def moveDown(self):
- index = self.selectedLayerIndex()
- KP.map.moveLayer(index, index + 2)
- KP.mainWindow.editor.viewport().update()
+ 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):
@@ -73,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()
@@ -111,8 +263,8 @@ class KPLayerList(QtGui.QWidget):
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()
@@ -557,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)
@@ -572,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)
@@ -604,6 +762,8 @@ class KPMainWindow(QtGui.QMainWindow):
@QtCore.pyqtSlot(KPLayer)
def handleSelectedLayerChanged(self, layer):
+ self.pathNodeList.tree.selectionModel().clearSelection()
+
self.scene.setCurrentLayer(layer)
showObjects, showDoodads = False, False
@@ -621,15 +781,37 @@ 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'
########################