예제 #1
0
    def __init__(self, mapDocument, index, tileset, parent=None):
        super().__init__(parent)

        self.mMapDocument = mapDocument
        self.mTileset = tileset
        self.mIndex = index
        # Make sure the tileset manager keeps watching this tileset
        TilesetManager.instance().addReference(self.mTileset)
예제 #2
0
 def __init__(self, mapDocument, index, tileset, parent=None):
     super().__init__(parent)
     
     self.mMapDocument = mapDocument
     self.mTileset = tileset
     self.mIndex = index
     # Make sure the tileset manager keeps watching this tileset
     TilesetManager.instance().addReference(self.mTileset)
예제 #3
0
    def setupTilesets(self, src, dst):
        existingTilesets = dst.tilesets()
        tilesetManager = TilesetManager.instance()
        # Add tilesets that are not yet part of dst map
        for tileset in src.tilesets():
            if (existingTilesets.contains(tileset)):
                continue
            undoStack = self.mMapDocument.undoStack()
            replacement = tileset.findSimilarTileset(existingTilesets)
            if (not replacement):
                self.mAddedTilesets.append(tileset)
                undoStack.push(AddTileset(self.mMapDocument, tileset))
                continue

            # Merge the tile properties
            sharedTileCount = min(tileset.tileCount(), replacement.tileCount())
            for i in range(sharedTileCount):
                replacementTile = replacement.tileAt(i)
                properties = replacementTile.properties()
                properties.merge(tileset.tileAt(i).properties())
                undoStack.push(
                    ChangeProperties(self.mMapDocument, self.tr("Tile"),
                                     replacementTile, properties))

            src.replaceTileset(tileset, replacement)
            tilesetManager.addReference(replacement)
            tilesetManager.removeReference(tileset)

        return True
예제 #4
0
    def setupTilesets(self, src, dst):
        existingTilesets = dst.tilesets()
        tilesetManager = TilesetManager.instance()
        # Add tilesets that are not yet part of dst map
        for tileset in src.tilesets():
            if (existingTilesets.contains(tileset)):
                continue
            undoStack = self.mMapDocument.undoStack()
            replacement = tileset.findSimilarTileset(existingTilesets)
            if (not replacement):
                self.mAddedTilesets.append(tileset)
                undoStack.push(AddTileset(self.mMapDocument, tileset))
                continue

            # Merge the tile properties
            sharedTileCount = min(tileset.tileCount(), replacement.tileCount())
            for i in range(sharedTileCount):
                replacementTile = replacement.tileAt(i)
                properties = replacementTile.properties()
                properties.merge(tileset.tileAt(i).properties())
                undoStack.push(ChangeProperties(self.mMapDocument,
                                                     self.tr("Tile"),
                                                     replacementTile,
                                                     properties))

            src.replaceTileset(tileset, replacement)
            tilesetManager.addReference(replacement)
            tilesetManager.removeReference(tileset)

        return True
예제 #5
0
 def setReloadTilesetsOnChanged(self, value):
     if (self.mReloadTilesetsOnChange == value):
         return
     self.mReloadTilesetsOnChange = value
     self.mSettings.setValue("Storage/ReloadTilesets",
                         self.mReloadTilesetsOnChange)
     tilesetManager = TilesetManager.instance()
     tilesetManager.setReloadTilesetsOnChange(self.mReloadTilesetsOnChange)
예제 #6
0
 def addVariation(self, arg1, probability = 1.0):
     tp = type(arg1)
     if tp==Map:
         ##
         # Adds a variation \a map to this tile stamp with a given \a probability.
         #
         # The tile stamp takes ownership over the map.
         ##
         map = arg1
         # increase tileset reference counts to keep watching them
         TilesetManager.instance().addReferences(map.tilesets())
         self.d.variations.append(TileStampVariation(map, probability))
     elif tp == TileStampVariation:
         ##
         # Adds a \a variation to this tile stamp.
         ##
         variation = arg1
         self.addVariation(Map(variation.map), variation.probability)
예제 #7
0
 def removeTilesetAt(self, index):
     self.tilesetAboutToBeRemoved.emit(index)
     tileset = self.mMap.tilesets().at(index)
     if (tileset == self.mCurrentObject or isFromTileset(self.mCurrentObject, tileset)):
         self.setCurrentObject(None)
     self.mMap.removeTilesetAt(index)
     self.tilesetRemoved.emit(tileset)
     tilesetManager = TilesetManager.instance()
     tilesetManager.removeReference(tileset)
예제 #8
0
 def addVariation(self, arg1, probability=1.0):
     tp = type(arg1)
     if tp == Map:
         ##
         # Adds a variation \a map to this tile stamp with a given \a probability.
         #
         # The tile stamp takes ownership over the map.
         ##
         map = arg1
         # increase tileset reference counts to keep watching them
         TilesetManager.instance().addReferences(map.tilesets())
         self.d.variations.append(TileStampVariation(map, probability))
     elif tp == TileStampVariation:
         ##
         # Adds a \a variation to this tile stamp.
         ##
         variation = arg1
         self.addVariation(Map(variation.map), variation.probability)
예제 #9
0
 def setShowTileAnimations(self, enabled):
     if (self.mShowTileAnimations == enabled):
         return
     self.mShowTileAnimations = enabled
     self.mSettings.setValue("Interface/ShowTileAnimations",
                         self.mShowTileAnimations)
     tilesetManager = TilesetManager.instance()
     tilesetManager.setAnimateTiles(self.mShowTileAnimations)
     self.showTileAnimationsChanged.emit(self.mShowTileAnimations)
예제 #10
0
 def readExternalTileset(self, source):
     error = ''
     # Check if this tileset is already loaded
     manager = TilesetManager.instance()
     tileset = manager.findTileset(source)
     # If not, try to load it
     if (not tileset):
         tileset, error = super().readExternalTileset(source)
     return tileset, error
예제 #11
0
    def __init__(self, map, fileName=QString()):
        super().__init__()

        ##
        # The filename of a plugin is unique. So it can be used to determine
        # the right plugin to be used for saving or reloading the map.
        # The nameFilter of a plugin can not be used, since it's translatable.
        # The filename of a plugin must not change while maps are open using this
        # plugin.
        ##
        self.mReaderFormat = None
        self.mWriterFormat = None
        self.mExportFormat = None
        self.mSelectedArea = QRegion()
        self.mSelectedObjects = QList()
        self.mSelectedTiles = QList()
        self.mCurrentLayerIndex = 0
        self.mLastSaved = QDateTime()
        self.mLastExportFileName = ''

        self.mFileName = fileName
        self.mMap = map
        self.mLayerModel = LayerModel(self)
        self.mCurrentObject = map  ## Current properties object. ##
        self.mRenderer = None
        self.mMapObjectModel = MapObjectModel(self)
        self.mTerrainModel = TerrainModel(self, self)
        self.mUndoStack = QUndoStack(self)
        self.createRenderer()
        if (map.layerCount() == 0):
            _x = -1
        else:
            _x = 0
        self.mCurrentLayerIndex = _x
        self.mLayerModel.setMapDocument(self)
        # Forward signals emitted from the layer model
        self.mLayerModel.layerAdded.connect(self.onLayerAdded)
        self.mLayerModel.layerAboutToBeRemoved.connect(
            self.onLayerAboutToBeRemoved)
        self.mLayerModel.layerRemoved.connect(self.onLayerRemoved)
        self.mLayerModel.layerChanged.connect(self.layerChanged)
        # Forward signals emitted from the map object model
        self.mMapObjectModel.setMapDocument(self)
        self.mMapObjectModel.objectsAdded.connect(self.objectsAdded)
        self.mMapObjectModel.objectsChanged.connect(self.objectsChanged)
        self.mMapObjectModel.objectsRemoved.connect(self.onObjectsRemoved)
        self.mMapObjectModel.rowsInserted.connect(
            self.onMapObjectModelRowsInserted)
        self.mMapObjectModel.rowsRemoved.connect(
            self.onMapObjectModelRowsInsertedOrRemoved)
        self.mMapObjectModel.rowsMoved.connect(self.onObjectsMoved)
        self.mTerrainModel.terrainRemoved.connect(self.onTerrainRemoved)
        self.mUndoStack.cleanChanged.connect(self.modifiedChanged)
        # Register tileset references
        tilesetManager = TilesetManager.instance()
        tilesetManager.addReferences(self.mMap.tilesets())
예제 #12
0
 def removeTilesetAt(self, index):
     self.tilesetAboutToBeRemoved.emit(index)
     tileset = self.mMap.tilesets().at(index)
     if (tileset == self.mCurrentObject
             or isFromTileset(self.mCurrentObject, tileset)):
         self.setCurrentObject(None)
     self.mMap.removeTilesetAt(index)
     self.tilesetRemoved.emit(tileset)
     tilesetManager = TilesetManager.instance()
     tilesetManager.removeReference(tileset)
예제 #13
0
    def loadFile(self, filePath):
        ret = True
        absPath = QFileInfo(filePath).path()
        rulesFile = QFile(filePath)
        if (not rulesFile.exists()):
            self.mError += self.tr("No rules file found at:\n%s\n" % filePath)
            return False

        if (not rulesFile.open(QIODevice.ReadOnly | QIODevice.Text)):
            self.mError += self.tr("Error opening rules file:\n%s\n" %
                                   filePath)
            return False

        i = QTextStream(rulesFile)
        line = ' '
        while line != '':
            line = i.readLine()
            rulePath = line.strip()
            if (rulePath == '' or rulePath.startswith('#')
                    or rulePath.startswith("//")):
                continue
            if (QFileInfo(rulePath).isRelative()):
                rulePath = absPath + '/' + rulePath
            if (not QFileInfo(rulePath).exists()):
                self.mError += self.tr("File not found:\n%s" % rulePath) + '\n'
                ret = False
                continue

            if (rulePath.lower().endswith(".tmx")):
                tmxFormat = TmxMapFormat()
                rules = tmxFormat.read(rulePath)
                if (not rules):
                    self.mError += self.tr("Opening rules map failed:\n%s" %
                                           tmxFormat.errorString()) + '\n'
                    ret = False
                    continue

                tilesetManager = TilesetManager.instance()
                tilesetManager.addReferences(rules.tilesets())
                autoMapper = None
                autoMapper = AutoMapper(self.mMapDocument, rules, rulePath)
                self.mWarning += autoMapper.warningString()
                error = autoMapper.errorString()
                if error != '':
                    self.mAutoMappers.append(autoMapper)
                else:
                    self.mError += error
                    del autoMapper

            if (rulePath.lower().endswith(".txt")):
                if (not self.loadFile(rulePath)):
                    ret = False
        return ret
예제 #14
0
 def cleanUpRulesMap(self):
     self.cleanTilesets()
     # mMapRules can be empty, when in prepareLoad the very first stages fail.
     if (not self.mMapRules):
         return
     tilesetManager = TilesetManager.instance()
     tilesetManager.removeReferences(self.mMapRules.tilesets())
     del self.mMapRules
     self.mMapRules = None
     self.cleanUpRuleMapLayers()
     self.mRulesInput.clear()
     self.mRulesOutput.clear()
예제 #15
0
    def __init__(self, map, fileName = QString()):
        super().__init__()

        ##
        # The filename of a plugin is unique. So it can be used to determine
        # the right plugin to be used for saving or reloading the map.
        # The nameFilter of a plugin can not be used, since it's translatable.
        # The filename of a plugin must not change while maps are open using this
        # plugin.
        ##
        self.mReaderFormat = None
        self.mWriterFormat = None
        self.mExportFormat = None
        self.mSelectedArea = QRegion()
        self.mSelectedObjects = QList()
        self.mSelectedTiles = QList()
        self.mCurrentLayerIndex = 0
        self.mLastSaved = QDateTime()
        self.mLastExportFileName = ''

        self.mFileName = fileName
        self.mMap = map
        self.mLayerModel = LayerModel(self)
        self.mCurrentObject = map ## Current properties object. ##
        self.mRenderer = None
        self.mMapObjectModel = MapObjectModel(self)
        self.mTerrainModel = TerrainModel(self, self)
        self.mUndoStack = QUndoStack(self)
        self.createRenderer()
        if (map.layerCount() == 0):
            _x = -1
        else:
            _x = 0
        self.mCurrentLayerIndex = _x
        self.mLayerModel.setMapDocument(self)
        # Forward signals emitted from the layer model
        self.mLayerModel.layerAdded.connect(self.onLayerAdded)
        self.mLayerModel.layerAboutToBeRemoved.connect(self.onLayerAboutToBeRemoved)
        self.mLayerModel.layerRemoved.connect(self.onLayerRemoved)
        self.mLayerModel.layerChanged.connect(self.layerChanged)
        # Forward signals emitted from the map object model
        self.mMapObjectModel.setMapDocument(self)
        self.mMapObjectModel.objectsAdded.connect(self.objectsAdded)
        self.mMapObjectModel.objectsChanged.connect(self.objectsChanged)
        self.mMapObjectModel.objectsRemoved.connect(self.onObjectsRemoved)
        self.mMapObjectModel.rowsInserted.connect(self.onMapObjectModelRowsInserted)
        self.mMapObjectModel.rowsRemoved.connect(self.onMapObjectModelRowsInsertedOrRemoved)
        self.mMapObjectModel.rowsMoved.connect(self.onObjectsMoved)
        self.mTerrainModel.terrainRemoved.connect(self.onTerrainRemoved)
        self.mUndoStack.cleanChanged.connect(self.modifiedChanged)
        # Register tileset references
        tilesetManager = TilesetManager.instance()
        tilesetManager.addReferences(self.mMap.tilesets())
예제 #16
0
 def cleanUpRulesMap(self):
     self.cleanTilesets()
     # mMapRules can be empty, when in prepareLoad the very first stages fail.
     if (not self.mMapRules):
         return
     tilesetManager = TilesetManager.instance()
     tilesetManager.removeReferences(self.mMapRules.tilesets())
     del self.mMapRules
     self.mMapRules = None
     self.cleanUpRuleMapLayers()
     self.mRulesInput.clear()
     self.mRulesOutput.clear()
예제 #17
0
    def loadFile(self, filePath):
        ret = True
        absPath = QFileInfo(filePath).path()
        rulesFile = QFile(filePath)
        if (not rulesFile.exists()):
            self.mError += self.tr("No rules file found at:\n%s\n"%filePath)
            return False

        if (not rulesFile.open(QIODevice.ReadOnly | QIODevice.Text)):
            self.mError += self.tr("Error opening rules file:\n%s\n"%filePath)
            return False

        i = QTextStream(rulesFile)
        line = ' '
        while line != '':
            line = i.readLine()
            rulePath = line.strip()
            if (rulePath=='' or rulePath.startswith('#') or rulePath.startswith("//")):
                continue
            if (QFileInfo(rulePath).isRelative()):
                rulePath = absPath + '/' + rulePath
            if (not QFileInfo(rulePath).exists()):
                self.mError += self.tr("File not found:\n%s"%rulePath) + '\n'
                ret = False
                continue

            if (rulePath.lower().endswith(".tmx")):
                tmxFormat = TmxMapFormat()
                rules = tmxFormat.read(rulePath)
                if (not rules):
                    self.mError += self.tr("Opening rules map failed:\n%s"%tmxFormat.errorString()) + '\n'
                    ret = False
                    continue

                tilesetManager = TilesetManager.instance()
                tilesetManager.addReferences(rules.tilesets())
                autoMapper = None
                autoMapper = AutoMapper(self.mMapDocument, rules, rulePath)
                self.mWarning += autoMapper.warningString()
                error = autoMapper.errorString()
                if error != '':
                    self.mAutoMappers.append(autoMapper)
                else:
                    self.mError += error
                    del autoMapper

            if (rulePath.lower().endswith(".txt")):
                if (not self.loadFile(rulePath)):
                    ret = False
        return ret
예제 #18
0
    def __init__(self, parent):
        super().__init__(parent)
        self.mMapDocument = None
        self.mSelectedTool = None
        self.mActiveTool = None
        self.mObjectSelectionItem = None
        self.mUnderMouse = False
        self.mCurrentModifiers = Qt.NoModifier,
        self.mDarkRectangle = QGraphicsRectItem()
        self.mDefaultBackgroundColor = Qt.darkGray

        self.mLayerItems = QVector()
        self.mObjectItems = QMap()
        self.mObjectLineWidth = 0.0
        self.mSelectedObjectItems = QSet()
        self.mLastMousePos = QPointF()
        self.mShowTileObjectOutlines = False
        self.mHighlightCurrentLayer = False
        self.mGridVisible = False

        self.setBackgroundBrush(self.mDefaultBackgroundColor)
        tilesetManager = TilesetManager.instance()
        tilesetManager.tilesetChanged.connect(self.tilesetChanged)
        tilesetManager.repaintTileset.connect(self.tilesetChanged)
        prefs = preferences.Preferences.instance()
        prefs.showGridChanged.connect(self.setGridVisible)
        prefs.showTileObjectOutlinesChanged.connect(
            self.setShowTileObjectOutlines)
        prefs.objectTypesChanged.connect(self.syncAllObjectItems)
        prefs.highlightCurrentLayerChanged.connect(
            self.setHighlightCurrentLayer)
        prefs.gridColorChanged.connect(self.update)
        prefs.objectLineWidthChanged.connect(self.setObjectLineWidth)
        self.mDarkRectangle.setPen(QPen(Qt.NoPen))
        self.mDarkRectangle.setBrush(Qt.black)
        self.mDarkRectangle.setOpacity(darkeningFactor)
        self.addItem(self.mDarkRectangle)
        self.mGridVisible = prefs.showGrid()
        self.mObjectLineWidth = prefs.objectLineWidth()
        self.mShowTileObjectOutlines = prefs.showTileObjectOutlines()
        self.mHighlightCurrentLayer = prefs.highlightCurrentLayer()
        # Install an event filter so that we can get key events on behalf of the
        # active tool without having to have the current focus.
        QCoreApplication.instance().installEventFilter(self)
예제 #19
0
    def __init__(self, *args):
        l = len(args)
        if l==0:
            self.name = ''
            self.fileName = ''
            self.variations = QVector()
            self.quickStampIndex = -1
        elif l==1:
            other = args[0]
            self.name = other.name
            self.fileName = ''# not copied
            self.variations = other.variations
            self.quickStampIndex = -1

            tilesetManager = TilesetManager.instance()
            # deep-copy the map data
            for variation in self.variations:
                variation.map = Map(variation.map)
                tilesetManager.addReferences(variation.map.tilesets())
예제 #20
0
    def __init__(self, *args):
        l = len(args)
        if l == 0:
            self.name = ''
            self.fileName = ''
            self.variations = QVector()
            self.quickStampIndex = -1
        elif l == 1:
            other = args[0]
            self.name = other.name
            self.fileName = ''  # not copied
            self.variations = other.variations
            self.quickStampIndex = -1

            tilesetManager = TilesetManager.instance()
            # deep-copy the map data
            for variation in self.variations:
                variation.map = Map(variation.map)
                tilesetManager.addReferences(variation.map.tilesets())
예제 #21
0
    def __init__(self, parent):
        super().__init__(parent)
        self.mMapDocument = None
        self.mSelectedTool = None
        self.mActiveTool = None
        self.mObjectSelectionItem = None
        self.mUnderMouse = False
        self.mCurrentModifiers = Qt.NoModifier,
        self.mDarkRectangle = QGraphicsRectItem()
        self.mDefaultBackgroundColor = Qt.darkGray

        self.mLayerItems = QVector()
        self.mObjectItems = QMap()
        self.mObjectLineWidth = 0.0
        self.mSelectedObjectItems = QSet()
        self.mLastMousePos = QPointF()
        self.mShowTileObjectOutlines = False
        self.mHighlightCurrentLayer = False
        self.mGridVisible = False

        self.setBackgroundBrush(self.mDefaultBackgroundColor)
        tilesetManager = TilesetManager.instance()
        tilesetManager.tilesetChanged.connect(self.tilesetChanged)
        tilesetManager.repaintTileset.connect(self.tilesetChanged)
        prefs = preferences.Preferences.instance()
        prefs.showGridChanged.connect(self.setGridVisible)
        prefs.showTileObjectOutlinesChanged.connect(self.setShowTileObjectOutlines)
        prefs.objectTypesChanged.connect(self.syncAllObjectItems)
        prefs.highlightCurrentLayerChanged.connect(self.setHighlightCurrentLayer)
        prefs.gridColorChanged.connect(self.update)
        prefs.objectLineWidthChanged.connect(self.setObjectLineWidth)
        self.mDarkRectangle.setPen(QPen(Qt.NoPen))
        self.mDarkRectangle.setBrush(Qt.black)
        self.mDarkRectangle.setOpacity(darkeningFactor)
        self.addItem(self.mDarkRectangle)
        self.mGridVisible = prefs.showGrid()
        self.mObjectLineWidth = prefs.objectLineWidth()
        self.mShowTileObjectOutlines = prefs.showTileObjectOutlines()
        self.mHighlightCurrentLayer = prefs.highlightCurrentLayer()
        # Install an event filter so that we can get key events on behalf of the
        # active tool without having to have the current focus.
        QCoreApplication.instance().installEventFilter(self)
예제 #22
0
 def insertTileset(self, index, tileset):
     self.tilesetAboutToBeAdded.emit(index)
     self.mMap.insertTileset(index, tileset)
     tilesetManager = TilesetManager.instance()
     tilesetManager.addReference(tileset)
     self.tilesetAdded.emit(index, tileset)
예제 #23
0
 def __del__(self):
     # Unregister tileset references
     tilesetManager = TilesetManager.instance()
     tilesetManager.removeReferences(self.mMap.tilesets())
     del self.mRenderer
     del self.mMap
예제 #24
0
    def __init__(self):
        super().__init__()

        self.mSettings = QSettings(self)

        self.mObjectTypes = QVector()

        # Retrieve storage settings
        self.mSettings.beginGroup("Storage")
        self.mLayerDataFormat = Map.LayerDataFormat(self.intValue("LayerDataFormat", Map.LayerDataFormat.Base64Zlib.value))
        self.mMapRenderOrder = Map.RenderOrder(self.intValue("MapRenderOrder", Map.RenderOrder.RightDown.value))
        self.mDtdEnabled = self.boolValue("DtdEnabled")
        self.mReloadTilesetsOnChange = self.boolValue("ReloadTilesets", True)
        self.mStampsDirectory = self.stringValue("StampsDirectory")
        self.mSettings.endGroup()
        # Retrieve interface settings
        self.mSettings.beginGroup("Interface")
        self.mShowGrid = self.boolValue("ShowGrid")
        self.mShowTileObjectOutlines = self.boolValue("ShowTileObjectOutlines")
        self.mShowTileAnimations = self.boolValue("ShowTileAnimations", True)
        self.mSnapToGrid = self.boolValue("SnapToGrid")
        self.mSnapToFineGrid = self.boolValue("SnapToFineGrid")
        self.mGridColor = self.colorValue("GridColor", Qt.black)
        self.mGridFine = self.intValue("GridFine", 4)
        self.mObjectLineWidth = self.realValue("ObjectLineWidth", 2)
        self.mHighlightCurrentLayer = self.boolValue("HighlightCurrentLayer")
        self.mShowTilesetGrid = self.boolValue("ShowTilesetGrid", True)
        self.mLanguage = self.stringValue("Language")
        self.mUseOpenGL = self.boolValue("OpenGL")
        self.mObjectLabelVisibility = self.intValue("ObjectLabelVisibility", ObjectLabelVisiblity.AllObjectLabels)
        self.mSettings.endGroup()
        # Retrieve defined object types
        self.mSettings.beginGroup("ObjectTypes")
        names = self.mSettings.value("Names", QStringList())
        colors = self.mSettings.value("Colors", QStringList())
        self.mSettings.endGroup()
        count = min(len(names), len(colors))
        for i in range(count):
            self.mObjectTypes.append(ObjectType(names[i], QColor(colors[i])))
        self.mSettings.beginGroup("Automapping")
        self.mAutoMapDrawing = self.boolValue("WhileDrawing")
        self.mSettings.endGroup()
        self.mSettings.beginGroup("MapsDirectory")
        self.mMapsDirectory = self.stringValue("Current")
        self.mSettings.endGroup()
        tilesetManager = TilesetManager.instance()
        tilesetManager.setReloadTilesetsOnChange(self.mReloadTilesetsOnChange)
        tilesetManager.setAnimateTiles(self.mShowTileAnimations)
        # Keeping track of some usage information
        self.mSettings.beginGroup("Install")
        self.mFirstRun = QDate.fromString(self.mSettings.value("FirstRun"))
        self.mRunCount = self.intValue("RunCount", 0) + 1
        self.mIsPatron = self.boolValue("IsPatron")
        if (not self.mFirstRun.isValid()):
            self.mFirstRun = QDate.currentDate()
            self.mSettings.setValue("FirstRun", self.mFirstRun.toString(Qt.ISODate))

        self.mSettings.setValue("RunCount", self.mRunCount)
        self.mSettings.endGroup()
        
        # Retrieve startup settings
        self.mSettings.beginGroup("Startup")
        self.mOpenLastFilesOnStartup = self.boolValue("OpenLastFiles", True)
        self.mSettings.endGroup()
예제 #25
0
 def deleteVariation(self, index):
     map = self.takeVariation(index)
     TilesetManager.instance().removeReferences(map.tilesets())
     del map
예제 #26
0
 def __del__(self):
     tilesetManager = TilesetManager.instance()
     # decrease reference to tilesets and delete maps
     for variation in self.variations:
         tilesetManager.removeReferences(variation.map.tilesets())
         del variation.map
예제 #27
0
 def deleteVariation(self, index):
     map = self.takeVariation(index)
     TilesetManager.instance().removeReferences(map.tilesets())
     del map
예제 #28
0
    def unifyTilesets(self, *args):
        l = len(args)
        if l==1:
            ##
            # Makes sure the all tilesets which are used at the given \a map will be
            # present in the map document.
            #
            # To reach the aim, all similar tilesets will be replaced by the version
            # in the current map document and all missing tilesets will be added to
            # the current map document.
            #
            # \warning This method assumes that the tilesets in \a map are managed by
            #          the TilesetManager!
            ##
            map = args[0]
            undoCommands = QList()
            existingTilesets = self.mMap.tilesets()
            tilesetManager = TilesetManager.instance()
            # Add tilesets that are not yet part of this map
            for tileset in map.tilesets():
                if (existingTilesets.contains(tileset)):
                    continue
                replacement = tileset.findSimilarTileset(existingTilesets)
                if (not replacement):
                    undoCommands.append(AddTileset(self, tileset))
                    continue

                # Merge the tile properties
                sharedTileCount = min(tileset.tileCount(), replacement.tileCount())
                for i in range(sharedTileCount):
                    replacementTile = replacement.tileAt(i)
                    properties = replacementTile.properties()
                    properties.merge(tileset.tileAt(i).properties())
                    undoCommands.append(ChangeProperties(self,
                                                             self.tr("Tile"),
                                                             replacementTile,
                                                             properties))

                map.replaceTileset(tileset, replacement)
                tilesetManager.addReference(replacement)
                tilesetManager.removeReference(tileset)

            if (not undoCommands.isEmpty()):
                self.mUndoStack.beginMacro(self.tr("Tileset Changes"))
                for command in undoCommands:
                    self.mUndoStack.push(command)
                self.mUndoStack.endMacro()
        elif l==2:
            map, missingTilesets = args
            
            existingTilesets = self.mMap.tilesets()
            tilesetManager = TilesetManager.instance()

            for tileset in map.tilesets():
                # tileset already added
                if existingTilesets.contains(tileset):
                    continue

                replacement = tileset.findSimilarTileset(existingTilesets)

                # tileset not present and no replacement tileset found
                if not replacement:
                    if not missingTilesets.contains(tileset):
                        missingTilesets.append(tileset)
                    continue

                # replacement tileset found, change given map
                map.replaceTileset(tileset, replacement)

                tilesetManager.addReference(replacement)
                tilesetManager.removeReference(tileset)
예제 #29
0
 def __del__(self):
     tilesetManager = TilesetManager.instance()
     # decrease reference to tilesets and delete maps
     for variation in self.variations:
         tilesetManager.removeReferences(variation.map.tilesets())
         del variation.map
예제 #30
0
 def insertTileset(self, index, tileset):
     self.tilesetAboutToBeAdded.emit(index)
     self.mMap.insertTileset(index, tileset)
     tilesetManager = TilesetManager.instance()
     tilesetManager.addReference(tileset)
     self.tilesetAdded.emit(index, tileset)
예제 #31
0
 def __del__(self):
     # Unregister tileset references
     tilesetManager = TilesetManager.instance()
     tilesetManager.removeReferences(self.mMap.tilesets())
     del self.mRenderer
     del self.mMap
예제 #32
0
    def unifyTilesets(self, *args):
        l = len(args)
        if l == 1:
            ##
            # Makes sure the all tilesets which are used at the given \a map will be
            # present in the map document.
            #
            # To reach the aim, all similar tilesets will be replaced by the version
            # in the current map document and all missing tilesets will be added to
            # the current map document.
            #
            # \warning This method assumes that the tilesets in \a map are managed by
            #          the TilesetManager!
            ##
            map = args[0]
            undoCommands = QList()
            existingTilesets = self.mMap.tilesets()
            tilesetManager = TilesetManager.instance()
            # Add tilesets that are not yet part of this map
            for tileset in map.tilesets():
                if (existingTilesets.contains(tileset)):
                    continue
                replacement = tileset.findSimilarTileset(existingTilesets)
                if (not replacement):
                    undoCommands.append(AddTileset(self, tileset))
                    continue

                # Merge the tile properties
                sharedTileCount = min(tileset.tileCount(),
                                      replacement.tileCount())
                for i in range(sharedTileCount):
                    replacementTile = replacement.tileAt(i)
                    properties = replacementTile.properties()
                    properties.merge(tileset.tileAt(i).properties())
                    undoCommands.append(
                        ChangeProperties(self, self.tr("Tile"),
                                         replacementTile, properties))

                map.replaceTileset(tileset, replacement)
                tilesetManager.addReference(replacement)
                tilesetManager.removeReference(tileset)

            if (not undoCommands.isEmpty()):
                self.mUndoStack.beginMacro(self.tr("Tileset Changes"))
                for command in undoCommands:
                    self.mUndoStack.push(command)
                self.mUndoStack.endMacro()
        elif l == 2:
            map, missingTilesets = args

            existingTilesets = self.mMap.tilesets()
            tilesetManager = TilesetManager.instance()

            for tileset in map.tilesets():
                # tileset already added
                if existingTilesets.contains(tileset):
                    continue

                replacement = tileset.findSimilarTileset(existingTilesets)

                # tileset not present and no replacement tileset found
                if not replacement:
                    if not missingTilesets.contains(tileset):
                        missingTilesets.append(tileset)
                    continue

                # replacement tileset found, change given map
                map.replaceTileset(tileset, replacement)

                tilesetManager.addReference(replacement)
                tilesetManager.removeReference(tileset)
예제 #33
0
    def __init__(self, parent=None):
        super().__init__(parent)

        # Shared tileset references because the dock wants to add new tiles
        self.mTilesets = QVector()
        self.mCurrentTilesets = QMap()
        self.mMapDocument = None
        self.mTabBar = QTabBar()
        self.mViewStack = QStackedWidget()
        self.mToolBar = QToolBar()
        self.mCurrentTile = None
        self.mCurrentTiles = None
        self.mNewTileset = QAction(self)
        self.mImportTileset = QAction(self)
        self.mExportTileset = QAction(self)
        self.mPropertiesTileset = QAction(self)
        self.mDeleteTileset = QAction(self)
        self.mEditTerrain = QAction(self)
        self.mAddTiles = QAction(self)
        self.mRemoveTiles = QAction(self)
        self.mTilesetMenuButton = TilesetMenuButton(self)
        self.mTilesetMenu = QMenu(self)  # opens on click of mTilesetMenu
        self.mTilesetActionGroup = QActionGroup(self)
        self.mTilesetMenuMapper = None  # needed due to dynamic content
        self.mEmittingStampCaptured = False
        self.mSynchronizingSelection = False

        self.setObjectName("TilesetDock")
        self.mTabBar.setMovable(True)
        self.mTabBar.setUsesScrollButtons(True)
        self.mTabBar.currentChanged.connect(self.updateActions)
        self.mTabBar.tabMoved.connect(self.moveTileset)
        w = QWidget(self)
        horizontal = QHBoxLayout()
        horizontal.setSpacing(0)
        horizontal.addWidget(self.mTabBar)
        horizontal.addWidget(self.mTilesetMenuButton)
        vertical = QVBoxLayout(w)
        vertical.setSpacing(0)
        vertical.setContentsMargins(5, 5, 5, 5)
        vertical.addLayout(horizontal)
        vertical.addWidget(self.mViewStack)
        horizontal = QHBoxLayout()
        horizontal.setSpacing(0)
        horizontal.addWidget(self.mToolBar, 1)
        vertical.addLayout(horizontal)
        self.mNewTileset.setIcon(QIcon(":images/16x16/document-new.png"))
        self.mImportTileset.setIcon(QIcon(":images/16x16/document-import.png"))
        self.mExportTileset.setIcon(QIcon(":images/16x16/document-export.png"))
        self.mPropertiesTileset.setIcon(
            QIcon(":images/16x16/document-properties.png"))
        self.mDeleteTileset.setIcon(QIcon(":images/16x16/edit-delete.png"))
        self.mEditTerrain.setIcon(QIcon(":images/16x16/terrain.png"))
        self.mAddTiles.setIcon(QIcon(":images/16x16/add.png"))
        self.mRemoveTiles.setIcon(QIcon(":images/16x16/remove.png"))
        Utils.setThemeIcon(self.mNewTileset, "document-new")
        Utils.setThemeIcon(self.mImportTileset, "document-import")
        Utils.setThemeIcon(self.mExportTileset, "document-export")
        Utils.setThemeIcon(self.mPropertiesTileset, "document-properties")
        Utils.setThemeIcon(self.mDeleteTileset, "edit-delete")
        Utils.setThemeIcon(self.mAddTiles, "add")
        Utils.setThemeIcon(self.mRemoveTiles, "remove")
        self.mNewTileset.triggered.connect(self.newTileset)
        self.mImportTileset.triggered.connect(self.importTileset)
        self.mExportTileset.triggered.connect(self.exportTileset)
        self.mPropertiesTileset.triggered.connect(self.editTilesetProperties)
        self.mDeleteTileset.triggered.connect(self.removeTileset)
        self.mEditTerrain.triggered.connect(self.editTerrain)
        self.mAddTiles.triggered.connect(self.addTiles)
        self.mRemoveTiles.triggered.connect(self.removeTiles)
        self.mToolBar.addAction(self.mNewTileset)
        self.mToolBar.setIconSize(QSize(16, 16))
        self.mToolBar.addAction(self.mImportTileset)
        self.mToolBar.addAction(self.mExportTileset)
        self.mToolBar.addAction(self.mPropertiesTileset)
        self.mToolBar.addAction(self.mDeleteTileset)
        self.mToolBar.addAction(self.mEditTerrain)
        self.mToolBar.addAction(self.mAddTiles)
        self.mToolBar.addAction(self.mRemoveTiles)
        self.mZoomable = Zoomable(self)
        self.mZoomComboBox = QComboBox()
        self.mZoomable.connectToComboBox(self.mZoomComboBox)
        horizontal.addWidget(self.mZoomComboBox)
        self.mViewStack.currentChanged.connect(self.updateCurrentTiles)
        TilesetManager.instance().tilesetChanged.connect(self.tilesetChanged)
        DocumentManager.instance().documentAboutToClose.connect(
            self.documentAboutToClose)
        self.mTilesetMenuButton.setMenu(self.mTilesetMenu)
        self.mTilesetMenu.aboutToShow.connect(self.refreshTilesetMenu)
        self.setWidget(w)
        self.retranslateUi()
        self.setAcceptDrops(True)
        self.updateActions()