summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/editorui/doodads.py6
-rw-r--r--src/editorui/editormain.py1
-rw-r--r--src/editorui/paths.py37
-rw-r--r--src/exporter.py64
-rw-r--r--src/main.py10
-rw-r--r--src/mapdata.py6
-rw-r--r--src/mapfile.py7
-rw-r--r--src/tileset.py5
-rw-r--r--src/ui.py124
9 files changed, 178 insertions, 82 deletions
diff --git a/src/editorui/doodads.py b/src/editorui/doodads.py
index bdba4d4..7e150cd 100644
--- a/src/editorui/doodads.py
+++ b/src/editorui/doodads.py
@@ -47,7 +47,8 @@ class KPEditorDoodad(KPEditorItem):
elif isinstance(thong, float):
editWidget = QtGui.QDoubleSpinBox(parent)
editWidget.setSingleStep(0.05)
- editWidget.setRange(-10000.0, 10000.0)
+ editWidget.setDecimals(2)
+ editWidget.setRange(-99999.0, 99999.0)
return editWidget
else:
@@ -313,8 +314,6 @@ class KPEditorDoodad(KPEditorItem):
model = self.menuWidget.model
rows = model.rowCount()
- print 'Resolving'
-
for x in xrange(rows):
rowList = []
@@ -330,7 +329,6 @@ class KPEditorDoodad(KPEditorItem):
anmList.append(rowList)
- print anmList
doodad.animations = anmList
doodad.setupAnimations()
diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py
index 1ff08ee..3ee593b 100644
--- a/src/editorui/editormain.py
+++ b/src/editorui/editormain.py
@@ -764,7 +764,6 @@ class KPEditorWidget(QtGui.QGraphicsView):
KP.mainWindow.handleSelectedLayerChanged(kLayer)
index = KP.map.refLayer(kLayer)
- print 'selecting row {0}'.format(index)
KP.mainWindow.layerList.selectLayer(index)
itemsUnder[0].setSelected(True)
diff --git a/src/editorui/paths.py b/src/editorui/paths.py
index 70c3b99..394b82a 100644
--- a/src/editorui/paths.py
+++ b/src/editorui/paths.py
@@ -86,6 +86,17 @@ class KPEditorNode(KPEditorItem):
self.setPalette(palette)
+ class SecretBox(QtGui.QCheckBox):
+ def __init__(self):
+ QtGui.QCheckBox.__init__(self)
+
+ palette = self.palette()
+ palette.setColor(QtGui.QPalette.ButtonText, Qt.black)
+ palette.setColor(QtGui.QPalette.Window, Qt.transparent)
+
+ self.setPalette(palette)
+
+
class mapArcEdit(QtGui.QLineEdit):
def __init__(self):
QtGui.QLineEdit.__init__(self)
@@ -129,10 +140,17 @@ class KPEditorNode(KPEditorItem):
self.stageProxy = self.HiddenProxy(self.stage, self, 6, 24)
self.stage.valueChanged.connect(self.stageChange)
+ self.secret = self.SecretBox()
+ self.secretProxy = self.HiddenProxy(self.secret, self, -60, 26)
+ self.secret.stateChanged.connect(self.secretChange)
+
if node.level != None:
self.world.setValue(node.level[0])
self.stage.setValue(node.level[1])
+ if node.hasSecret != None:
+ self.secret.setChecked(node.hasSecret)
+
self.foreignID = self.LevelSlotSpinner()
self.foreignIDProxy = self.HiddenProxy(self.foreignID, self, 60, 24)
@@ -217,6 +235,15 @@ class KPEditorNode(KPEditorItem):
@QtCore.pyqtSlot(int)
+ def secretChange(self, secret):
+
+ node = self._nodeRef()
+ node.hasSecret = secret
+
+ KP.mainWindow.pathNodeList.update()
+
+
+ @QtCore.pyqtSlot(int)
def foreignIDChange(self, ID):
node = self._nodeRef()
@@ -329,11 +356,12 @@ class KPEditorNode(KPEditorItem):
if node.level:
self.worldProxy.show()
self.stageProxy.show()
+ self.secretProxy.show()
else:
self.worldProxy.hide()
self.stageProxy.hide()
-
+ self.secretProxy.hide()
if node.mapChange != None:
self.foreignID.show()
@@ -349,6 +377,7 @@ class KPEditorNode(KPEditorItem):
self.buttonProxy.hide()
self.worldProxy.hide()
self.stageProxy.hide()
+ self.secretProxy.hide()
self.foreignID.hide()
self.transition.hide()
self.mapChange.hide()
@@ -358,7 +387,11 @@ class KPEditorNode(KPEditorItem):
node = self._nodeRef()
layer = KP.map.pathLayer
- layer.nodes.remove(node)
+ try:
+ layer.nodes.remove(node)
+ except ValueError:
+ pass
+
KP.mainWindow.pathNodeList.removeLayer(node)
if len(node.exits) == 2:
diff --git a/src/exporter.py b/src/exporter.py
index bd28221..3e91e9f 100644
--- a/src/exporter.py
+++ b/src/exporter.py
@@ -177,6 +177,7 @@ class KPMapExporter:
requiredFixUps = []
stringsToAdd = set()
textures = set()
+ texInfo = set()
tilesets = set()
offsets = {None: 0xFFFFFFFF}
@@ -250,6 +251,8 @@ class KPMapExporter:
w, h = doodad.size
data += struct.pack('>fffffii', x, y, w, h, doodad.angle, 0, len(doodad.animations))
+
+ texInfo.add((doodad.source[0], doodad.source[1].height() * doodad.source[1].width() * 2))
texture = doodad.source[1]
textures.add(texture)
requiredFixUps.append((len(data) - 8, texture))
@@ -296,35 +299,34 @@ class KPMapExporter:
current = len(data)
data += struct.pack('>hhiiiiii', x+12, y+12, 0, 0, 0, 0, 0, 0)
- # figure out the exits by direction
- exits = [None, None, None, None]
- left, right, up, down = 0, 1, 2, 3
+ # this varies
+ if node.isStop():
+ # figure out the exits by direction
+ leftExit, rightExit, upExit, downExit = None, None, None, None
- for exit in node.exits:
- start, end = exit._startNodeRef(), exit._endNodeRef()
- opposite = end if (start == node) else start
+ for exit in node.exits:
+ start, end = exit._startNodeRef(), exit._endNodeRef()
+ opposite = end if (start == node) else start
- oX, oY = opposite.position
- deltaX, deltaY = oX-x, oY-y
- angle = math.degrees(math.atan2(deltaX, deltaY)) % 360
- print "Here: %d,%d Opposite %d,%d Delta: %d,%d Angle: %d" % (x,y,oX,oY,deltaX,deltaY,angle)
+ oX, oY = opposite.position
+ deltaX, deltaY = oX-x, oY-y
+ angle = math.degrees(math.atan2(deltaX, deltaY)) % 360
- # Left = 270, Right = 90, Up = 180, Down = 0
- if angle >= 225 and angle <= 315:
- direction = left
- elif angle >= 45 and angle <= 135:
- direction = right
- elif angle > 135 and angle < 225:
- direction = up
- elif angle > 315 or angle < 45:
- direction = down
+ # Left = 270, Right = 90, Up = 180, Down = 0
+ if angle >= 225 and angle <= 315:
+ leftExit = exit
+ elif angle >= 45 and angle <= 135:
+ rightExit = exit
+ elif angle > 135 and angle < 225:
+ upExit = exit
+ elif angle > 315 or angle < 45:
+ downExit = exit
- if exits[direction]:
- print "Conflicting directions!"
- while exits[direction]:
- direction = (direction + 1) % 4
+ exits = [leftExit, rightExit, upExit, downExit]
- exits[direction] = exit
+ else:
+ # not a stop, so just dump them in
+ exits = node.exits + [None,None,None,None]
requiredFixUps.append((current+4, exits[0]))
requiredFixUps.append((current+8, exits[1]))
@@ -394,6 +396,20 @@ class KPMapExporter:
data += '\0'
# textures
+ texA = sorted(texInfo, key=lambda x: x[1])
+
+ s = 0
+ d = 0
+ for texItem in texA:
+ print texItem[1]/1000, "kb:", texItem[0]
+ s += texItem[1]
+ d += 1
+ if d == 10:
+ d = 0
+ print "So far:", s/1000, "kb"
+
+ print "Total:", s/1000, "kb"
+
texPadding = ((len(data) + 0x1F) & ~0x1F) - len(data)
data += ('\0' * texPadding)
diff --git a/src/main.py b/src/main.py
index f417d94..951e927 100644
--- a/src/main.py
+++ b/src/main.py
@@ -76,9 +76,15 @@ class KP:
tsInfo['hash'] = newHash
from tileset import KPTileset
- print "Loading set: %s" % name
+
+ import time
+ b = time.clock()
+
cls.loadedTilesets[name] = KPTileset.loadFromArc(data)
-
+
+ e = time.clock()
+ print "Loading set: {0} in {1}".format(name, e-b)
+
@classmethod
def tileset(cls, name):
diff --git a/src/mapdata.py b/src/mapdata.py
index 5d46685..8f3842a 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -149,7 +149,7 @@ class KPTileLayer(KPLayer):
@mapfile.dumpable('associate_layer')
class KPPathTileLayer(KPLayer):
- __dump_attribs__ = KPLayer.__dump_attribs__ + ('tileset', 'objects', 'doodads')
+ __dump_attribs__ = KPLayer.__dump_attribs__ + ('tileset', 'objects', 'doodads', 'folder')
def _dump(self, mapObj, dest):
if isinstance(self.associate, KPNode):
@@ -182,6 +182,7 @@ class KPPathTileLayer(KPLayer):
self.objects = []
self.doodads = []
self.associate = pathnode
+ self.folder = ''
self.updateCache()
@@ -282,8 +283,6 @@ class KPDoodad(object):
def _dump(self, mapObj, dest):
dest['sourceRef'] = mapObj.refDoodad(self.source)
- print self.animations
- print mapObj, dest
def _load(self, mapObj, src):
self.source = mapObj.derefDoodad(src['sourceRef'])
@@ -574,6 +573,7 @@ class KPMap(object):
if path is None:
raise "no path specified for this map"
+ KP.mainWindow.pathNodeList.setLayerFolders()
self.associateLayers = KP.mainWindow.pathNodeList.getLayers()
import mapfile
diff --git a/src/mapfile.py b/src/mapfile.py
index e1494b1..27e2ff9 100644
--- a/src/mapfile.py
+++ b/src/mapfile.py
@@ -66,7 +66,6 @@ def load(string):
try:
clsName = source['_t']
clsObj = DUMPABLE_CLASSES_BY_NAME[clsName]
- print "Loading %s" % clsName
except KeyError:
# let's give this one more shot with the loadable proxies
try:
@@ -82,7 +81,11 @@ def load(string):
try:
setattr(obj, attrName, source[attrName])
except:
- print "{0} was missing the attribute {1}".format(obj, attrName)
+ if attrName == 'folder':
+ obj.folder = ''
+
+ else:
+ print "{0} was missing the attribute {1}".format(obj, attrName)
if hasattr(obj, '_preload'):
obj._preload(source)
diff --git a/src/tileset.py b/src/tileset.py
index cc36d18..ab6ac69 100644
--- a/src/tileset.py
+++ b/src/tileset.py
@@ -423,8 +423,6 @@ class KPTileset(object):
@staticmethod
def RGB4A3Decode(tex):
- import time
- b = time.clock()
out = bytearray(896*448*4)
dest = QtGui.QImage(896,448,QtGui.QImage.Format_ARGB32)
@@ -461,9 +459,6 @@ class KPTileset(object):
)
i += 2
- e = time.clock()
- print(e - b)
-
return dest
diff --git a/src/ui.py b/src/ui.py
index d5f9cdf..864b9ed 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -204,44 +204,74 @@ class KPPathNodeList(QtGui.QWidget):
item = self.KPPathNodeItem(self.tree, layer, associate)
def loadLayer(self, layer):
- item = self.KPPathNodeItem(self.tree, layer, layer.associate)
- def removeLayer(self, associate):
- trash = None
+ # If there is a folder path available...
+ if layer.folder != '':
+ folder = layer.folder.split('/')
- for itemI in xrange(self.tree.topLevelItemCount()):
- item = self.tree.topLevelItem(itemI)
+ # Remove the last empty
+ folder.pop()
- if item.associate == associate:
- trash = item
- else:
- trash = self.removeRecursor(item, associate)
+ myFolder = None
+
+ # Go Through each subfolder
+ for subfolder in folder:
+ itemList = self.findFolder(subfolder)
+
+ if itemList:
+ myFolder = itemList
+
+ else:
+ if myFolder:
+ item = QtGui.QTreeWidgetItem(myFolder)
+ else:
+ item = QtGui.QTreeWidgetItem(self.tree)
+
+ item.setIcon(0, KP.icon('Folder'))
+ item.setText(0, subfolder)
+ item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled | Qt.ItemIsEditable | Qt.ItemIsEnabled)
+ myFolder = item
- if trash != None:
- break
+ # Now that we've got all the folders, put it in!
+ self.KPPathNodeItem(myFolder, layer, layer.associate)
- parent = trash.parent()
- if parent:
- parent.takeChild(trash)
else:
- self.tree.takeTopLevelItem(self.tree.indexOfTopLevelItem(trash))
+ self.KPPathNodeItem(self.tree, layer, layer.associate)
- def removeRecursor(self, parent, associate):
- trash = None
+ def findFolder(self, matchString):
- for itemI in xrange(parent.childCount()):
- item = parent.child(itemI)
+ itemList = QtGui.QTreeWidgetItemIterator(self.tree, QtGui.QTreeWidgetItemIterator.Editable)
- if item.associate == associate:
- trash = item
- else:
- trash = self.removeRecursor(item, associate)
+ while itemList.value():
+ item = itemList.value()
+
+ if str(item.text(0)) == matchString:
+ return item
+
+ itemList += 1
- if trash != None:
- return trash
-
return None
+ def removeLayer(self, associate):
+ itemList = QtGui.QTreeWidgetItemIterator(self.tree, QtGui.QTreeWidgetItemIterator.NotEditable)
+
+ while itemList.value():
+ item = itemList.value()
+
+ if not isinstance(item, self.KPPathNodeItem):
+ continue
+
+ if item.associate == associate:
+ parent = item.parent()
+ if parent:
+ parent.removeChild(item)
+ else:
+ index = self.tree.indexFromItem(item).row()
+ self.tree.takeTopLevelItem(self.tree.indexOfTopLevelItem(item))
+ return
+
+ itemList += 1
+
def getLayers(self):
layerList = []
for itemI in xrange(self.tree.topLevelItemCount()):
@@ -264,6 +294,27 @@ class KPPathNodeList(QtGui.QWidget):
else:
layerList.append(item.layer)
+ def setLayerFolders(self):
+
+ itemList = QtGui.QTreeWidgetItemIterator(self.tree, QtGui.QTreeWidgetItemIterator.NotEditable)
+
+ while itemList.value():
+ item = itemList.value()
+
+ if not isinstance(item, self.KPPathNodeItem):
+ continue
+
+ item.layer.folder = ''
+ daddy = item.parent()
+
+ while daddy:
+ item.layer.folder = str(daddy.text(0)) + '/' + item.layer.folder
+
+ daddy = daddy.parent()
+
+ itemList += 1
+
+
selectedLayerChanged = QtCore.pyqtSignal(KPLayer)
@@ -1373,15 +1424,17 @@ class KPMainWindow(QtGui.QMainWindow):
target = unicode(QtGui.QFileDialog.getExistingDirectory(self, 'Choose a folder'))
for fileName in os.listdir(target):
-
- if fileName[:-6] == ".kpmap":
+ print fileName
+
+ if fileName[-6:] == ".kpmap":
import mapfile
- obj = mapfile.load(open(target, 'rb').read())
- obj.save()
- obj.export(target + filename[:-6] + '.kpbin')
+ print 'Found a map'
+ obj = mapfile.load(open(target + "/" + fileName, 'rb').read())
+ # obj.save()
+ obj.export(target + "/" + fileName[:-6] + '.kpbin')
- print 'Saved and Exported {0}'.format(filename[:-6])
+ print 'Saved and Exported {0}'.format(fileName[:-6])
# Edit
@@ -1510,7 +1563,6 @@ class KPMainWindow(QtGui.QMainWindow):
loaded = mapfile.load(data)
file.close()
- print loaded
settings = KP.app.settings
presetList = []
@@ -1524,15 +1576,9 @@ class KPMainWindow(QtGui.QMainWindow):
presetList = []
presets = []
- print presetList, presets
- print dir(presetList)
-
presetList.extend(loaded[0])
presets.extend(loaded[1])
- print presetList
- print presets
-
settings.setValue('AnimationPresets', mapfile.dump(presetList))
settings.setValue('AnimationPresetData', mapfile.dump(presets))