Esempio n. 1
0
    def setCurrentTiles(self, tiles):
        if (self.mCurrentTiles == tiles):
            return
        del self.mCurrentTiles
        self.mCurrentTiles = tiles
        # Set the selected tiles on the map document
        if (tiles):
            selectedTiles = QList()
            for y in range(tiles.height()):
                for x in range(tiles.width()):
                    cell = tiles.cellAt(x, y)
                    if (not cell.isEmpty()):
                        selectedTiles.append(cell.tile)

            self.mMapDocument.setSelectedTiles(selectedTiles)

            # Create a tile stamp with these tiles
            map = self.mMapDocument.map()
            stamp = Map(map.orientation(), tiles.width(), tiles.height(),
                        map.tileWidth(), map.tileHeight())
            stamp.addLayer(tiles.clone())
            stamp.addTilesets(tiles.usedTilesets())

            self.mEmittingStampCaptured = True
            self.stampCaptured.emit(TileStamp(stamp))
            self.mEmittingStampCaptured = False
Esempio n. 2
0
 def __init__(self, parent=None):
     super().__init__(self.tr("Bucket Fill Tool"),
                      QIcon(":images/22x22/stock-tool-bucket-fill.png"),
                      QKeySequence(self.tr("F")), parent)
     self.mStamp = TileStamp()
     self.mFillOverlay = None
     self.mFillRegion = QRegion()
     self.mMissingTilesets = QVector()
     self.mIsActive = False
     self.mLastShiftStatus = False
     ##
     # Indicates if the tool is using the random mode.
     ##
     self.mIsRandom = False
     ##
     # Contains the value of mIsRandom at that time, when the latest call of
     # tilePositionChanged() took place.
     # This variable is needed to detect if the random mode was changed during
     # mFillOverlay being brushed at an area.
     ##
     self.mLastRandomStatus = False
     ##
     # Contains all used random cells to use in random mode.
     # The same cell can be in the list multiple times to make different
     # random weights possible.
     ##
     self.mRandomCellPicker = RandomPicker()
Esempio n. 3
0
    def endCapture(self):
        if (self.mBrushBehavior != BrushBehavior.Capture):
            return
        self.mBrushBehavior = BrushBehavior.Free
        tileLayer = self.currentTileLayer()
        # Intersect with the layer and translate to layer coordinates
        captured = self.capturedArea()
        captured &= QRect(tileLayer.x(), tileLayer.y(), tileLayer.width(),
                          tileLayer.height())
        if (captured.isValid()):
            captured.translate(-tileLayer.x(), -tileLayer.y())
            map = tileLayer.map()
            capture = tileLayer.copy(captured)

            stamp = Map(map.orientation(), capture.width(), capture.height(),
                        map.tileWidth(), map.tileHeight())
            # Add tileset references to map
            for tileset in capture.usedTilesets():
                stamp.addTileset(tileset)

            stamp.addLayer(capture)

            self.stampCaptured.emit(TileStamp(stamp))
        else:
            self.updatePreview()
Esempio n. 4
0
 def duplicate(self):
     index = self.mTileStampView.currentIndex()
     if (not index.isValid()):
         return
     sourceIndex = self.mProxyModel.mapToSource(index)
     if (not self.mTileStampModel.isStamp(sourceIndex)):
         return
     stamp = self.mTileStampModel.stampAt = TileStamp(sourceIndex)
     self.mTileStampModel.addStamp(stamp.clone())
Esempio n. 5
0
 def currentRowChanged(self, index):
     sourceIndex = self.mProxyModel.mapToSource(index)
     isStamp = self.mTileStampModel.isStamp(sourceIndex)
     self.mDuplicate.setEnabled(isStamp)
     self.mDelete.setEnabled(sourceIndex.isValid())
     self.mAddVariation.setEnabled(isStamp)
     if (isStamp):
         self.setStamp.emit(self.mTileStampModel.stampAt(sourceIndex))
     else:
         variation = self.mTileStampModel.variationAt(sourceIndex)
         if variation:
             # single variation clicked, use it specifically
             self.setStamp.emit(TileStamp(Map(variation.map)))
Esempio n. 6
0
    def __init__(self, parent=None):
        super().__init__(self.tr("Stamp Brush"),
                         QIcon(":images/22x22/stock-tool-clone.png"),
                         QKeySequence(self.tr("B")), parent)
        ##
        # This stores the current behavior.
        ##
        self.mBrushBehavior = BrushBehavior.Free

        self.mIsRandom = False
        self.mCaptureStart = QPoint()
        self.mRandomCellPicker = RandomPicker()
        ##
        # mStamp is a tile layer in which is the selection the user made
        # either by rightclicking (Capture) or at the tilesetdock
        ##
        self.mStamp = TileStamp()
        self.mPreviewLayer = None
        self.mMissingTilesets = QVector()
        self.mPrevTilePosition = QPoint()
        self.mStampReference = QPoint()
Esempio n. 7
0
def stampFromContext(selectedTool):
    stamp = TileStamp()
    stampBrush = dynamic_cast(selectedTool, StampBrush)
    if stampBrush:
        # take the stamp from the stamp brush
        stamp = stampBrush.stamp()
    else:
        fillTool = dynamic_cast(selectedTool, BucketFillTool)
        if fillTool:
            # take the stamp from the fill tool
            stamp = fillTool.stamp()
        else:
            mapDocument = DocumentManager.instance().currentDocument()
            if mapDocument:
                # try making a stamp from the current tile selection
                tileLayer = dynamic_cast(mapDocument.currentLayer(), TileLayer)
                if (not tileLayer):
                    return stamp
                selection = mapDocument.selectedArea()
                if (selection.isEmpty()):
                    return stamp
                selection.translate(-tileLayer.position())
                copy = tileLayer.copy(selection)
                if (copy.size().isEmpty()):
                    return stamp
                map = mapDocument.map()
                copyMap = Map(map.orientation(), copy.width(), copy.height(),
                              map.tileWidth(), map.tileHeight())
                # Add tileset references to map
                for tileset in copy.usedTilesets():
                    copyMap.addTileset(tileset)
                copyMap.setRenderOrder(map.renderOrder())
                copyMap.addLayer(copy.take())
                stamp.addVariation(copyMap)

    return stamp
Esempio n. 8
0
 def stamp(self):
     return TileStamp(self.mStamp)
Esempio n. 9
0
 def eraseQuickStamp(self, index):
     stamp = self.mQuickStamps.at(index)
     if (not stamp.isEmpty()):
         self.mQuickStamps[index] = TileStamp()
         if (not self.mQuickStamps.contains(stamp)):
             self.mTileStampModel.removeStamp(stamp)
Esempio n. 10
0
 def stampsDirectoryChanged(self):
     # erase current stamps
     self.mQuickStamps.fill(TileStamp())
     self.mStampsByName.clear()
     self.mTileStampModel.clear()
     self.loadStamps()
Esempio n. 11
0
 def beginCapture(self):
     if (self.mBrushBehavior != BrushBehavior.Free):
         return
     self.mBrushBehavior = BrushBehavior.Capture
     self.mCaptureStart = self.tilePosition()
     self.setStamp(TileStamp())