summaryrefslogtreecommitdiff
path: root/src/tileset.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tileset.py107
1 files changed, 81 insertions, 26 deletions
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()