コード例 #1
0
        private void InitializeMapTreeView()
        {
            foreach (string realm in DataWrapper.GetRealms())
            {
                TreeNode realmNode = new TreeNode(realm);

                foreach (string expansion in DataWrapper.GetExpansionsByRealm(realm))
                {
                    TreeNode expansionNode = new TreeNode(expansion);

                    foreach (string mapType in DataWrapper.GetZoneTypesByRealmAndExpansion(realm, expansion).OrderBy(o => o.ToString()))
                    {
                        TreeNode mapTypeNode = new TreeNode(mapType);

                        foreach (KeyValuePair <string, string> zone in DataWrapper.GetZonesByRealmAndExpansionAndType(realm, expansion, mapType).OrderBy(o => o.Key))
                        {
                            if (mapType == "Capitol" || mapType == "Indoor" || mapType == "Dungeons" || mapType == "Instances")
                            {
                                continue;
                            }

                            ZoneSelection currentZone = new ZoneSelection(zone.Key, zone.Value, expansion, mapType);
                            TreeNode      zoneNode    = new TreeNode(currentZone.ToString());
                            zoneNode.Tag = currentZone;

                            m_allNodes.Add(zoneNode);
                            mapTypeNode.Nodes.Add(zoneNode);
                        }

                        if (mapTypeNode.Nodes.Count > 0)
                        {
                            expansionNode.Nodes.Add(mapTypeNode);
                        }
                    }

                    if (expansionNode.Nodes.Count == 1)
                    {
                        foreach (TreeNode node in expansionNode.Nodes[0].Nodes)
                        {
                            expansionNode.Nodes.Add(node);
                        }
                        expansionNode.Nodes.RemoveAt(0);
                        realmNode.Nodes.Add(expansionNode);
                    }
                    else if (expansionNode.Nodes.Count > 1)
                    {
                        realmNode.Nodes.Add(expansionNode);
                    }
                }

                mapsTreeView.Nodes.Add(realmNode);
            }
        }
コード例 #2
0
        private void InitializeMapTreeView()
        {
            foreach (string realm in DataWrapper.GetRealms())
            {
                TreeNode realmNode = new TreeNode(realm);

                foreach (string expansion in DataWrapper.GetExpansionsByRealm(realm))
                {
                    TreeNode expansionNode = new TreeNode(expansion);

                    foreach (string mapType in DataWrapper.GetZoneTypesByRealmAndExpansion(realm, expansion).OrderBy(o => o.ToString()))
                    {
                        TreeNode mapTypeNode = new TreeNode(mapType);

                        foreach (KeyValuePair<string, string> zone in DataWrapper.GetZonesByRealmAndExpansionAndType(realm, expansion, mapType).OrderBy(o => o.Key))
                        {
                            if (mapType == "Capitol" || mapType == "Indoor" || mapType == "Dungeons" || mapType == "Instances") continue;

                            ZoneSelection currentZone = new ZoneSelection(zone.Key, zone.Value, expansion, mapType);
                            TreeNode zoneNode = new TreeNode(currentZone.ToString());
                            zoneNode.Tag = currentZone;

                            m_allNodes.Add(zoneNode);
                            mapTypeNode.Nodes.Add(zoneNode);
                        }

                        if (mapTypeNode.Nodes.Count > 0)
                        {
                            expansionNode.Nodes.Add(mapTypeNode);
                        }
                    }

                    if (expansionNode.Nodes.Count == 1)
                    {
                        foreach (TreeNode node in expansionNode.Nodes[0].Nodes)
                        {
                            expansionNode.Nodes.Add(node);
                        }
                        expansionNode.Nodes.RemoveAt(0);
                        realmNode.Nodes.Add(expansionNode);
                    }
                    else if (expansionNode.Nodes.Count > 1)
                    {
                        realmNode.Nodes.Add(expansionNode);
                    }
                }

                mapsTreeView.Nodes.Add(realmNode);
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Graveen/DAoC-MapCreator
        /// <summary>
        /// Render selected Zones as Background Worker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void drawMapBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ZoneSelection zone = (ZoneSelection)e.Argument;

                // Start BackgroundWorker
                Log(string.Format("Start creating map for zone {0} ...", zone.Id), LogLevel.notice);

                // The filename
                string targetFilePath = string.Format("{0}\\maps", Application.StartupPath);

                string pattern = filePatternTextBox.Text;
                if (string.IsNullOrEmpty(pattern))
                {
                    pattern = "zone{id}_{size}";
                }

                // Replace some values
                pattern = pattern.Replace("{id}", zone.Id);
                pattern = pattern.Replace("{name}", zone.Name);
                pattern = pattern.Replace("{expansion}", zone.Expansion);
                pattern = pattern.Replace("{type}", zone.Type);
                pattern = pattern.Replace("{size}", TargetMapSize.ToString());
                pattern = Tools.MakeValidFileName(pattern);

                // File extension
                string fileExtension         = "jpg";
                string selectedFileExtension = "JPEG";
                this.Invoke((MethodInvoker) delegate()
                {
                    selectedFileExtension = fileTypeComboBox.Text;
                });
                switch (selectedFileExtension)
                {
                case "PNG":
                    fileExtension = "png";
                    break;

                case "JPEG":
                default:
                    fileExtension = "jpg";
                    break;
                }

                // The Target File
                FileInfo mapFile = new FileInfo(string.Format("{0}\\maps\\{1}.{2}", Application.StartupPath, pattern, fileExtension));
                if (!Directory.Exists(mapFile.DirectoryName))
                {
                    Directory.CreateDirectory(mapFile.DirectoryName);
                }

                bool     lightmap         = generateLightmapCheckBox.Checked;
                double   lightmapZScale   = Convert.ToDouble(heightmapZScaleTextBox.Value);
                double   lightmapLightMin = Convert.ToDouble(heightmapLightMinTextBox.Value);
                double   lightmapLightMax = Convert.ToDouble(heightmapLightMaxTextBox.Value);
                double[] lightmapZVector  = new double[] { Convert.ToDouble(heightmapZVector1TextBox.Value), Convert.ToDouble(heightmapZVector2TextBox.Value), Convert.ToDouble(heightmapZVector3TextBox.Value) };

                bool  rivers = generateRiversCheckBox.Checked;
                bool  riversUseDefaultColor = riversUseDefaultColorCheckBox.Checked;
                Color riversColor           = Properties.Settings.Default.mapRiverColor;
                int   riverOpacity          = Convert.ToInt32(mapRiversOpacityTextBox.Value);

                bool  bounds               = generateBoundsCheckBox.Checked;
                Color boundsColor          = Properties.Settings.Default.mapBoundsColor;
                int   boundsOpacity        = Convert.ToInt32(mapBoundsOpacityTextBox.Text);
                bool  excludeBoundsFromMap = excludeBoundsFromMapCheckbox.Checked;

                bool fixtures = drawFixturesCheckBox.Checked;
                bool trees    = drawTreesCheckBox.Checked;

                // Generate the map
                using (ZoneConfiguration conf = new ZoneConfiguration(zone.Id, TargetMapSize))
                {
                    // Create Background
                    MapBackground background = new MapBackground(conf);

                    MainForm.Log("Rendering background ...", LogLevel.notice);
                    using (MagickImage map = background.Draw())
                    {
                        if (map != null)
                        {
                            MainForm.Log("Finished background rendering!", LogLevel.success);

                            // Create lightmap
                            if (lightmap)
                            {
                                MainForm.Log("Rendering lightmap ...", LogLevel.notice);
                                MapLightmap lightmapGenerator = new MapLightmap(conf);
                                lightmapGenerator.ZScale   = lightmapZScale;
                                lightmapGenerator.LightMin = lightmapLightMin;
                                lightmapGenerator.LightMax = lightmapLightMax;
                                lightmapGenerator.ZVector  = lightmapZVector;
                                lightmapGenerator.RecalculateLights();
                                lightmapGenerator.Draw(map);
                                MainForm.Log("Finished lightmap rendering!", LogLevel.success);
                            }

                            // We need this for fixtures
                            MainForm.Log("Loading water configurations ...", LogLevel.notice);
                            MapWater river = new MapWater(conf);
                            MainForm.Log("Finished loading water configurations!", LogLevel.success);

                            MapFixtures fixturesGenerator = null;
                            if (fixtures || trees)
                            {
                                MainForm.Log("Loading fixtures ...", LogLevel.notice);
                                fixturesGenerator = new MapFixtures(conf, river.WaterAreas);
                                fixturesGenerator.DrawFixtures      = drawFixturesCheckBox.Checked;
                                fixturesGenerator.DrawTrees         = drawTreesCheckBox.Checked;
                                fixturesGenerator.DrawTreesAsImages = treesAsImages.Checked;
                                fixturesGenerator.TreeTransparency  = Convert.ToInt32(mapTreeTransparencyTextBox.Value);
                                fixturesGenerator.Start();
                                MainForm.Log("Finished loading fixtures!", LogLevel.success);
                            }

                            // Draw Fixtures below water
                            if (fixtures || trees)
                            {
                                MainForm.Log("Rendering fixtures below water level ...", LogLevel.notice);
                                fixturesGenerator.Draw(map, true);
                                MainForm.Log("Finished rendering fixtures below water level!", LogLevel.success);
                            }

                            // Create Rivers
                            if (rivers)
                            {
                                MainForm.Log("Rendering water ...", LogLevel.notice);
                                river.WaterColor        = riversColor;
                                river.WaterTransparency = riverOpacity;
                                river.UseClientColors   = riversUseDefaultColor;
                                river.Draw(map);
                                MainForm.Log("Finished water rendering!", LogLevel.success);
                            }

                            // Draw Fixtures above water
                            if (fixtures || trees)
                            {
                                MainForm.Log("Rendering fixtures above water level ...", LogLevel.notice);
                                fixturesGenerator.Draw(map, false);
                                MainForm.Log("Finished rendering fixtures above water level!", LogLevel.success);
                            }

                            if (fixturesGenerator != null)
                            {
                                fixturesGenerator.Dispose();
                            }

                            // Create bounds
                            if (bounds)
                            {
                                MainForm.Log("Adding zone bounds ...", LogLevel.notice);
                                MapBounds mapBounds = new MapBounds(conf);
                                mapBounds.BoundsColor    = boundsColor;
                                mapBounds.Transparency   = boundsOpacity;
                                mapBounds.ExcludeFromMap = excludeBoundsFromMap;
                                mapBounds.Draw(map);
                                MainForm.Log("Finished zone bunds!", LogLevel.success);
                            }

                            MainForm.Log(string.Format("Writing map image {0} ...", mapFile.Name));
                            ProgressStartMarquee("Writing map image ...");
                            map.Quality = Convert.ToInt32(mapQualityTextBox.Value);
                            map.Write(mapFile.FullName);
                        }
                    }
                }


                if (mapFile.Exists)
                {
                    LoadImage(mapFile.FullName);
                    ProgressReset();
                }
                else
                {
                    Log("Errors during progress!", LogLevel.error);
                }
            }
            catch (Exception ex)
            {
                MainForm.Log("Unhandled Exception thrown!", LogLevel.error);
                MainForm.Log(ex.Message, LogLevel.error);
                MainForm.Log(ex.StackTrace, LogLevel.error);
            }
        }