summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mapdata.py42
-rw-r--r--src/ui.py105
2 files changed, 125 insertions, 22 deletions
diff --git a/src/mapdata.py b/src/mapdata.py
index 23c6b83..b8ab263 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -147,6 +147,40 @@ class KPTileLayer(KPLayer):
y += 1
+@mapfile.dumpable('tile_layer')
+class KPPathTileLayer(KPTileLayer):
+ __dump_attribs__ = KPLayer.__dump_attribs__ + ('tileset', 'objects')
+
+ def __repr__(self):
+ return "<KPPathTileLayer %r with %r connected to %r>" % (self.name, self.tileset, self.pathnode)
+
+ def __init__(self, pathnode):
+ KPLayer.__init__(self)
+ self.tileset = KP.map.pathNodeTileset
+ self.objects = []
+ self.doodads = []
+ self.pathnode = pathnode
+
+ self.cache = ['DUMMY_FLAG']
+ self.updateCache()
+
+ self.icon = KP.icon('LayerTile')
+
+ def getPathNode(self):
+ return self.pathnode
+
+ def _visibilityChanged(self, value):
+ for obj in self.objects:
+ item = obj.qtItem
+ if item:
+ item.setVisible(value)
+
+ for obj in self.doodads:
+ item = obj.qtItem
+ if item:
+ item.setVisible(value)
+
+
@mapfile.dumpable('doodad')
class KPDoodad(object):
__dump_attribs__ = ('position', 'size', 'angle', 'animations')
@@ -274,7 +308,6 @@ class KPNode(object):
return True if (self.level or self.mapChange or len(self.exits) != 2) else False
-
@mapfile.dumpable('path')
class KPPath(object):
__dump_attribs__ = ('unlocks', 'secret', 'animation', 'movementSpeed')
@@ -413,9 +446,14 @@ class KPMap(object):
self.loadTilesets()
+ try:
+ self.pathNodeTileset = self.tilesets[0]
+ except:
+ self.pathNodeTileset = ''
+
# LAYERS
- class LayerModel(QtCore.QAbstractListModel):
+ class LayerModel(QtCore.QAbstractItemModel):
def __init__(self, layerList):
QtCore.QAbstractListModel.__init__(self)
self.list = layerList
diff --git a/src/ui.py b/src/ui.py
index 9656137..db9d409 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -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):