summaryrefslogtreecommitdiff
path: root/src/editorui
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/editorui.py65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/editorui.py b/src/editorui.py
index 7969100..c7da106 100644
--- a/src/editorui.py
+++ b/src/editorui.py
@@ -236,6 +236,40 @@ class KPEditorObject(KPEditorItem):
self._layerRef().updateCache()
+class KPEditorDoodad(KPEditorItem):
+ def __init__(self, doodad, layer):
+ KPEditorItem.__init__(self)
+ obj.qtItem = self
+ self._doodadRef = weakref.ref(doodad)
+ self._layerRef = weakref.ref(layer)
+ self._updatePosition()
+ self._updateSize()
+
+ self.setAcceptHoverEvents(True)
+
+ def _updatePosition(self):
+ self.setPos(*self._doodadRef().position)
+
+ def _updateSize(self):
+ self.prepareGeometryChange()
+
+ w,h = self._doodadRef().size
+
+ self._boundingRect = QtCore.QRectF(0, 0, w, h)
+ self._selectionRect = QtCore.QRectF(0, 0, w, h)
+
+
+ def paint(self, painter, option, widget):
+ if self.isSelected():
+ painter.setPen(QtGui.QPen(Qt.white, 1, Qt.DotLine))
+ painter.drawRect(self._selectionRect)
+
+
+ def _itemMoved(self, oldX, oldY, newX, newY):
+ doodad = self._doodadRef()
+ doodad.position = (newX, newY)
+
+
class KPMapScene(QtGui.QGraphicsScene):
def __init__(self):
QtGui.QGraphicsScene.__init__(self, 0, 0, 512*24, 512*24)
@@ -259,10 +293,39 @@ class KPMapScene(QtGui.QGraphicsScene):
areaRightT = ceil(areaRight / 24)
areaBottomT = ceil(areaBottom / 24)
+ # compile a list of doodads
+ visibleDoodadsByLayer = {}
+
+ for obj in self.items(rect):
+ if not isinstance(obj, KPEditorDoodad): continue
+
+ layer = obj._layerRef()
+
+ try:
+ doodadList = visibleDoodadsByLayer[layer]
+ except KeyError:
+ doodadList = []
+ visibleDoodadsByLayer[layer] = doodadList
+
+ doodadList.append(obj)
+
+ # now draw everything!
for layer in reversed(KP.map.layers):
if not layer.visible: continue
- if isinstance(layer, KPTileLayer):
+ if isinstance(layer, KPDoodadLayer):
+ try:
+ toDraw = visibleDoodadsByLayer[layer]
+ except KeyError:
+ continue
+
+ for item in toDraw:
+ painter.save()
+ painter.setWorldTransform(item.transform(), True)
+ painter.drawPixmap(0, 0, item.pixmap)
+ painter.restore()
+
+ elif isinstance(layer, KPTileLayer):
left, top = layer.cacheBasePos
width, height = layer.cacheSize
right, bottom = left+width, top+height