コード例 #1
0
        public static MapGeneratorLayerOptions FromString(string options)
        {
            MapGeneratorLayerOptions layer = new MapGeneratorLayerOptions();

            string[] optionParts = options.Split(new char[] { ',' });

            foreach (string option in optionParts) {
                string[] keyValuePair = option.Split(new char[] { '=' }, 2);
                string key = keyValuePair[0];
                string value = (keyValuePair.Length > 1) ? keyValuePair[1] : string.Empty;

                switch (key.ToLower()) {
                    case "drawbackground":
                        layer.DrawBackground = ParseBoolean(value, true);
                        break;

                    case "drawwalls":
                        layer.DrawWalls = ParseBoolean(value, true);
                        break;

                    case "drawbackgroundwater":
                        layer.DrawBackgroundWater = ParseBoolean(value, true);
                        break;

                    case "drawforegroundwater":
                        layer.DrawForegroundWater = ParseBoolean(value, true);
                        break;

                    case "drawbackgroundtiles":
                        layer.DrawBackgroundTiles = ParseBoolean(value, true);
                        break;

                    case "drawforegroundtiles":
                        layer.DrawForegroundTiles = ParseBoolean(value, true);
                        break;

                    default:
                        throw new ArgumentException("Unknown layer option: " + key, "options");
                }
            }

            return layer;
        }
コード例 #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            versionLabel.Text = "Version: " + Assembly.GetEntryAssembly().GetName().Version.ToString();

            zoomLevelsListView.Items[0].Tag = 2.0f;
            zoomLevelsListView.Items[1].Tag = 1.0f;
            zoomLevelsListView.Items[2].Tag = 0.5f;
            zoomLevelsListView.Items[3].Tag = 0.25f;
            zoomLevelsListView.Items[4].Tag = 0.125f;
            zoomLevelsListView.Items[5].Tag = 0.0625f;
            zoomLevelsListView.Items[6].Tag = 0.03125f;

            try {
                LoadSettings();
            } catch {
                MapGeneratorLayerOptions defaultLayer = new MapGeneratorLayerOptions();
                defaultLayer.DrawWalls = true;
                defaultLayer.DrawBackgroundWater = true;
                defaultLayer.DrawForegroundWater = true;
                defaultLayer.DrawBackgroundTiles = true;
                defaultLayer.DrawForegroundTiles = true;

                ListViewItem layerPropertiesListViewItem = new ListViewItem();
                layerPropertiesListViewItem.Text = "1";
                layerPropertiesListViewItem.SubItems.Add(defaultLayer.ToString());
                layerPropertiesListViewItem.Tag = defaultLayer;
                layersListView.Items.Add(layerPropertiesListViewItem);
            }

            if (string.IsNullOrWhiteSpace(terrariaPathTextBox.Text)) {
                terrariaPathTextBox.Text = GetTerrariaInstallationPath();
            }

            terrariaPathFolderBrowserDialog.SelectedPath = terrariaPathTextBox.Text;
            worldOpenFileDialog.InitialDirectory = GetWorldsPath();
            outputDirectoryFolderBrowserDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        }
コード例 #3
0
        private Image CreateBlockImage(World world, System.Drawing.Rectangle region, float zoomLevel, MapGeneratorLayerOptions layer)
        {
            Image blockImage = new Bitmap(16 * options.BlockSize.Width, 16 * options.BlockSize.Height, PixelFormat.Format32bppArgb);

            TextureSet textures = null;

            lock (availableTextureSetLock) {
                if (availableTextureSet.Count == 0) {
                    System.Diagnostics.Trace.WriteLine("Creating new texture set for thread: " + Thread.CurrentThread.ManagedThreadId);
                    textures = this.textures.Copy();
                } else {
                    textures = availableTextureSet.Dequeue();
                }
            }

            using (Graphics g = Graphics.FromImage(blockImage)) {
                g.Clip = new Region(new RectangleF(0, 0, region.Width * 16 * zoomLevel, region.Height * 16 * zoomLevel));
                g.ScaleTransform(zoomLevel, zoomLevel);

                g.PixelOffsetMode = PixelOffsetMode.Half;
                g.CompositingMode = CompositingMode.SourceOver;

                g.InterpolationMode = InterpolationMode.NearestNeighbor;
                g.CompositingQuality = CompositingQuality.HighSpeed;

                if (layer.DrawBackground) {
                    DrawSky(world, region, g);
                }

                if (layer.DrawBackgroundWater) {
                    DrawWater(world, region, true, g, textures);
                }

                if (layer.DrawBackground) {
                    DrawBackground(world, region, g, textures);
                }

                if (layer.DrawWalls) {
                    DrawWalls(world, region, g, textures);
                }

                if (layer.DrawBackgroundTiles) {
                    DrawTiles(world, region, false, g, textures);
                }

                if (layer.DrawForegroundTiles) {
                    DrawTiles(world, region, true, g, textures);
                }

                if (layer.DrawForegroundWater) {
                    DrawWater(world, region, false, g, textures);
                }
            }

            lock (availableTextureSetLock) {
                availableTextureSet.Enqueue(textures);
            }

            return blockImage;
        }