def applyMapValue(self, id, val): command = None x = id if x == PropertyId.TileWidthProperty: command = ChangeMapProperty(self.mMapDocument, ChangeMapProperty.TileWidth, val) elif x == PropertyId.TileHeightProperty: command = ChangeMapProperty(self.mMapDocument, ChangeMapProperty.TileHeight, val) elif x == PropertyId.OrientationProperty: orientation = Map.Orientation((val + 1) % 5) command = ChangeMapProperty(self.mMapDocument, orientation) elif x == PropertyId.HexSideLengthProperty: command = ChangeMapProperty(self.mMapDocument, ChangeMapProperty.HexSideLength, val) elif x == PropertyId.StaggerAxisProperty: staggerAxis = Map.StaggerAxis(val) command = ChangeMapProperty(self.mMapDocument, staggerAxis) elif x == PropertyId.StaggerIndexProperty: staggerIndex = Map.StaggerIndex(val) command = ChangeMapProperty(self.mMapDocument, staggerIndex) elif x == PropertyId.LayerFormatProperty: format = Map.LayerDataFormat(val) command = ChangeMapProperty(self.mMapDocument, format) elif x == PropertyId.RenderOrderProperty: renderOrder = Map.RenderOrder(val) command = ChangeMapProperty(self.mMapDocument, renderOrder) elif x == PropertyId.ColorProperty: command = ChangeMapProperty(self.mMapDocument, val) if (command): self.mMapDocument.undoStack().push(command)
def createMap(self): if (self.exec() != QDialog.Accepted): return None mapWidth = self.mUi.mapWidth.value() mapHeight = self.mUi.mapHeight.value() tileWidth = self.mUi.tileWidth.value() tileHeight = self.mUi.tileHeight.value() orientationIndex = self.mUi.orientation.currentIndex() orientationData = self.mUi.orientation.itemData(orientationIndex) orientation = orientationData layerFormat = Map.LayerDataFormat(self.mUi.layerFormat.currentIndex()) renderOrder = Map.RenderOrder(self.mUi.renderOrder.currentIndex()) map = Map(orientation, mapWidth, mapHeight, tileWidth, tileHeight) map.setLayerDataFormat(layerFormat) map.setRenderOrder(renderOrder) gigabyte = 1073741824 memory = mapWidth * mapHeight * 8#sizeof(Cell) # Add a tile layer to new maps of reasonable size if (memory < gigabyte): map.addLayer(TileLayer(self.tr("Tile Layer 1"), 0, 0, mapWidth, mapHeight)) else: gigabytes = memory / gigabyte QMessageBox.warning(self, self.tr("Memory Usage Warning"), self.tr("Tile layers for this map will consume %.2f GB " "of memory each. Not creating one by default."%gigabytes)) # Store settings for next time prefs = preferences.Preferences.instance() prefs.setLayerDataFormat(layerFormat) prefs.setMapRenderOrder(renderOrder) s = preferences.Preferences.instance().settings() s.setValue(ORIENTATION_KEY, orientationIndex) s.setValue(MAP_WIDTH_KEY, mapWidth) s.setValue(MAP_HEIGHT_KEY, mapHeight) s.setValue(TILE_WIDTH_KEY, tileWidth) s.setValue(TILE_HEIGHT_KEY, tileHeight) return MapDocument(map)
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()