diff options
author | Colin Noga <Tempus@Spectrum-Song.local> | 2011-11-09 10:23:50 -0600 |
---|---|---|
committer | Colin Noga <Tempus@Spectrum-Song.local> | 2011-11-09 10:23:50 -0600 |
commit | 45862beccd07de14d66d249fc368057bb0a33fd4 (patch) | |
tree | b76e29d91165629766cb99ccbaf5dd7d74127837 | |
parent | 02a1d81d760525f515337d2109feba8887aa5edb (diff) | |
download | koopatlas-45862beccd07de14d66d249fc368057bb0a33fd4.tar.gz koopatlas-45862beccd07de14d66d249fc368057bb0a33fd4.zip |
Bunches of object stuff relating to groups
Diffstat (limited to '')
-rwxr-xr-x | Koopuzzle/Koopuzzle.py | 10 | ||||
-rw-r--r-- | src/mapdata.py | 2 | ||||
-rw-r--r-- | src/tileset.py | 107 | ||||
-rw-r--r-- | src/ui.py | 31 |
4 files changed, 94 insertions, 56 deletions
diff --git a/Koopuzzle/Koopuzzle.py b/Koopuzzle/Koopuzzle.py index 510e5e0..73ced82 100755 --- a/Koopuzzle/Koopuzzle.py +++ b/Koopuzzle/Koopuzzle.py @@ -14,11 +14,13 @@ from PyQt4 import QtCore, QtGui ######################################################## # To Do: # -# - Object Editor -# - Moving objects around +# - Object List does not retain indices on loading a +# Tileset, but Groups do, causing a desync after +# save/open if at least one object has been deleted # -# - Make UI simpler for Pop -# - C speed saving +# - Properly refresh the group list icons on load +# +# - Do something about slopes # ######################################################## diff --git a/src/mapdata.py b/src/mapdata.py index d4eb2eb..4bde9a6 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -126,7 +126,7 @@ class KPMap(object): self.loadedTilesets = {} # TESTING CRAP - self.tilesets['Test'] = {'path': '/home/me/Dropbox/NEWERsmbw/Test2.arc'} + self.tilesets['Test'] = {'path': '/Users/Tempus/Dropbox/NEWERsmbw/Test2.arc'} self.reloadTileset('Test') diff --git a/src/tileset.py b/src/tileset.py index 50aaf38..8f7c437 100644 --- a/src/tileset.py +++ b/src/tileset.py @@ -33,7 +33,7 @@ class KPTileObject(object): # 'Upward slope' (LL to UR) # 'Downward slope' (UL to LR) - self.itemsize = QtCore.QSize(self.width * 24 + 4, self.height * 24 + 4) + self.itemsize = QtCore.QSize(self.icon.width() * 24 + 4, self.icon.height() * 24 + 4) @@ -178,6 +178,7 @@ class KPGroupModel(QtCore.QAbstractListModel): def __init__(self, groupItem): self.container = groupItem + self.view = None QtCore.QAbstractListModel.__init__(self) @@ -188,39 +189,67 @@ class KPGroupModel(QtCore.QAbstractListModel): def data(self, index, role=QtCore.Qt.DisplayRole): # Should return the contents of a row when asked for the index - + # + # Can be optimized by only dealing with the roles we need prior + # to lookup: Role order is 13, 6, 7, 9, 10, 1, 0, 8 + + if ((role > 1) and (role < 6)): + return None + + elif (role == QtCore.Qt.ForegroundRole): + return QtGui.QBrush(QtCore.Qt.black) + + elif role == QtCore.Qt.TextAlignmentRole: + return QtCore.Qt.AlignCenter + + if not index.isValid(): return None n = index.row() if n < 0: return None if n >= self.container.objectCount(): return None - item = self.container.getItem(n) + itemTuple = self.container.getItem(n) + item = itemTuple[0] + depth = itemTuple[1] + if role == QtCore.Qt.DecorationRole: if isinstance(item, KPTileObject): return item.icon - - if role == QtCore.Qt.BackgroundRole: - return QtGui.qApp.palette().base() - - if role == QtCore.Qt.UserRole: - if isinstance(item, KPTileObject): - return item.itemsize - - if role == QtCore.Qt.DisplayRole: + + elif role == QtCore.Qt.DisplayRole: if isinstance(item, KPGroupItem): return item.name - if role == QtCore.Qt.TextAlignmentRole: + elif (role == QtCore.Qt.SizeHintRole): + if isinstance(item, KPGroupItem): + return QtCore.QSize(self.view.viewport().width(), (28 - (depth * 2))) + + elif role == QtCore.Qt.BackgroundRole: if isinstance(item, KPGroupItem): - return item.alignment + colour = 165 + (depth * 15) + if colour > 255: + colour = 255 + + brush = QtGui.QBrush(QtGui.QColor(colour, colour, colour), QtCore.Qt.Dense4Pattern) + + return brush + + elif (role == QtCore.Qt.FontRole): + font = QtGui.QFont() + font.setPixelSize(20 - (depth * 2)) + font.setBold(True) + + return font + return None + class KPGroupItem(object): """Hierarchal object for making a 2D hierarchy recursively using classes""" @@ -248,24 +277,51 @@ class KPGroupItem(object): return objCount - def getItem(self, index): + def getItem(self, index, depth=0): ''' Retrieves an item of a specific index. The index is already checked for validity ''' + # print "{1} looking for item {0}".format(index, self.name) + if index == self.startIndex: - return self + # print "Olook, that's me!" + return self, depth - if (index < self.startIndex + len(self.objects)): - return self.objects[index - self.startIndex - 1] + if (index <= self.startIndex + len(self.objects)): + # print "Heyho, that's one of my objects!" + # print len(self.objects) + return self.objects[index - self.startIndex - 1], depth else: + # print "I don't have it." + # print self.groups - for group in groups: + depth += 1 - if (group.startIndex < index) and (index < group.endIndex): - return group.getItem(index) + for group in self.groups: + # print "Checking {0} - {1}, {2}".format(group.name, group.startIndex, group.endIndex) + if (group.startIndex <= index) and (index <= group.endIndex): + # print "Looks like it's in {0}".format(group.name) + return group.getItem(index, depth) + + + def calculateIndices(self, index): + print "{0} open[ ".format(self.name) + self.startIndex = index + + self.endIndex = self.objectCount() + index + + print "\t{0} - {1}".format(self.startIndex, self.endIndex) + indexAdd = 1 + + for group in self.groups: + print "\t{0}".format(indexAdd) + group.calculateIndices(self.startIndex + len(self.objects) + indexAdd) + indexAdd = group.endIndex + print indexAdd + print "{0} Close] ".format(self.name) class KPTileset(object): @@ -328,6 +384,7 @@ class KPTileset(object): self.processObjects(objectBuffer, objectMetadata) self.processGroup(groupBuffer) + self.groupItem.calculateIndices(0) self.groupModel = KPGroupModel(self.groupItem) @@ -404,7 +461,7 @@ class KPTileset(object): offset = entry[0] row = 0 - tex = QtGui.QPixmap(entry[2] * 24, entry[1] * 24) + tex = QtGui.QPixmap(entry[1] * 24, entry[2] * 24) tex.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(tex) @@ -414,7 +471,7 @@ class KPTileset(object): untile = struct.unpack_from('>h', objstrings, offset)[0] if untile != -1: - painter.drawPixmap(tilesA*24, tilesB*24, self.tiles[untile]) + painter.drawPixmap(tilesB*24, tilesA*24, self.tiles[untile]) rowlist.append(untile) offset += 2 @@ -442,7 +499,6 @@ class KPTileset(object): def makeTree(self, grovyle, treecko): - indexNum = treecko.startIndex for razorLeaf in grovyle: @@ -458,9 +514,8 @@ class KPTileset(object): a = KPGroupItem(razorLeaf[0]) treecko.groups.append(a) - makeTree(razorLeaf[1], a) + self.makeTree(razorLeaf[1], a) - treecko.endIndex = treecko.startIndex + treecko.objectCount() @@ -77,7 +77,6 @@ class KPObjectSelector(QtGui.QListView): self.setResizeMode(QtGui.QListView.Adjust) self.setWrapping(True) - # self.setItemDelegate(KPObjectSelector.ObjectItemDelegate()) # Borrowed the signals and junk from Reggie, figure we'll need em' self.clicked.connect(self.handleObjReplace) @@ -115,29 +114,6 @@ class KPObjectSelector(QtGui.QListView): objReplaced = QtCore.pyqtSignal(int) - class KPGroupItemDelegate(QtGui.QAbstractItemDelegate): - """Handles tileset groups, objects and their rendering""" - - def __init__(self): - """Initialises the delegate""" - QtGui.QAbstractItemDelegate.__init__(self) - - def paint(self, painter, option, index): - """Paints an object""" - if option.state & QtGui.QStyle.State_Selected: - painter.fillRect(option.rect, option.palette.highlight()) - - p = index.model().data(index, QtCore.Qt.DecorationRole) - painter.drawPixmap(option.rect.x()+2, option.rect.y()+2, p) - #painter.drawText(option.rect, str(index.row())) - - def sizeHint(self, option, index): - """Returns the size for the object""" - p = index.model().data(index, QtCore.Qt.UserRole) - return p - - - @@ -180,9 +156,14 @@ class KPMainWindow(QtGui.QMainWindow): self.addDockWidget(Qt.RightDockWidgetArea, self.layerListDock) self.addDockWidget(Qt.RightDockWidgetArea, self.objectSelectorDock) + @QtCore.pyqtSlot() def updateObjectSelector(self): - pass + tileset = KPTileset.loadFromArc('/Users/Tempus/Dropbox/NEWERsmbw/Test3.arc') + self.objectSelector.setModel(tileset.getModel()) + + tileset.getModel().view = self.objectSelector + |