Esempio n. 1
0
        private static System.Drawing.Color GetTreeColor(TreeRow treeRow)
        {
            if (treeColors.ContainsKey(treeRow.Name))
            {
                return(treeColors[treeRow.Name]);
            }

            string treeTextureFile = string.Format("{0}\\zones\\trees\\{1}", Properties.Settings.Default.game_path, treeRow.LeafTexture);

            if (!File.Exists(treeTextureFile))
            {
                MainForm.Log(string.Format("Unable to get texture for tree {0}. Using default color.", treeRow.Name));
                return(System.Drawing.ColorTranslator.FromHtml("#5e683a"));
            }
            else
            {
                using (ImageMagick.MagickImage texture = new ImageMagick.MagickImage(treeTextureFile))
                {
                    texture.Resize(1, 1);
                    ImageMagick.Pixel pixel = texture.GetPixels().First();

                    System.Drawing.Color color = pixel.ToColor();
                    treeColors.Add(treeRow.Name, color);
                    return(color);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Load all required CSV data
        /// </summary>
        private static void LoadCsvData()
        {
            MainForm.ProgressStartMarquee("Loading fixture data ...");

            List <string> nifsCsvRows  = DataWrapper.GetFileContent(zoneConf.CvsMpk, "nifs.csv");
            List <string> fixturesRows = DataWrapper.GetFileContent(zoneConf.CvsMpk, "fixtures.csv");

            // Create a NumberFormatInfo object for floats and set some of its properties.
            System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo();
            provider.NumberDecimalSeparator = ".";
            provider.NumberGroupSeparator   = "";
            provider.NumberGroupSizes       = new int[] { 2 };

            foreach (string row in nifsCsvRows)
            {
                if (row.StartsWith("Grid") || row.StartsWith("NIF"))
                {
                    continue;
                }

                string[] fields = row.Split(',');

                NifRow nifRow = new NifRow();
                nifRow.NifId       = Convert.ToInt32(fields[0]);
                nifRow.TextualName = fields[1];
                nifRow.Filename    = fields[2];
                nifRow.Color       = Convert.ToInt32(fields[5]);
                nifRows.Add(nifRow);
            }

            // Read fixtures.csv
            foreach (string row in fixturesRows)
            {
                if (row.StartsWith("Fixtures") || row.StartsWith("ID"))
                {
                    continue;
                }

                string[]   fields     = row.Split(',');
                FixtureRow fixtureRow = new FixtureRow();
                fixtureRow.Id          = Convert.ToInt32(fields[0]);
                fixtureRow.NifId       = Convert.ToInt32(fields[1]);
                fixtureRow.TextualName = fields[2];
                fixtureRow.X           = Convert.ToDouble(fields[3], provider);
                fixtureRow.Y           = Convert.ToDouble(fields[4], provider);
                fixtureRow.Z           = Convert.ToDouble(fields[5], provider);
                fixtureRow.A           = Convert.ToInt32(fields[6]);
                fixtureRow.Scale       = Convert.ToInt32(fields[7]);
                fixtureRow.OnGround    = (Convert.ToInt32(fields[11]) == 1) ? true : false;
                fixtureRow.Flip        = (Convert.ToInt32(fields[12]) == 1) ? true : false;

                if (fields.Length > 15)
                {
                    fixtureRow.Angle3D = Convert.ToDouble(fields[15], provider);
                    fixtureRow.AxisX3D = Convert.ToDouble(fields[16], provider);
                    fixtureRow.AxisY3D = Convert.ToDouble(fields[17], provider);
                    fixtureRow.AxisZ3D = Convert.ToDouble(fields[18], provider);
                }

                fixtureRows.Add(fixtureRow);
            }

            // Only load on first init
            if (treeRows.Count == 0)
            {
                string treeMpk        = string.Format("{0}\\zones\\trees\\treemap.mpk", Properties.Settings.Default.game_path);
                string treeClusterMpk = string.Format("{0}\\zones\\trees\\tree_clusters.mpk", Properties.Settings.Default.game_path);

                List <string> treesCsvRows       = DataWrapper.GetFileContent(treeMpk, "Treemap.csv");
                List <string> treeClusterCsvRows = DataWrapper.GetFileContent(treeClusterMpk, "tree_clusters.csv");

                foreach (string row in treesCsvRows)
                {
                    if (row.StartsWith("NIF Name"))
                    {
                        continue;
                    }

                    string[] fields = row.Split(',');
                    //if (fields[4] == "") continue;

                    TreeRow treeRow = new TreeRow();
                    treeRow.Name         = fields[0];
                    treeRow.ZOffset      = (string.IsNullOrEmpty(fields[4])) ? 0 : Convert.ToInt32(fields[4]);
                    treeRow.LeafTexture  = (string.IsNullOrEmpty(fields[3])) ? "" : fields[3];
                    treeRow.AverageColor = GetTreeColor(treeRow);
                    treeRows.Add(treeRow);
                }

                foreach (string row in treeClusterCsvRows)
                {
                    if (row.StartsWith("name"))
                    {
                        continue;
                    }
                    if (row == "")
                    {
                        continue;
                    }

                    string[]       fields         = row.Split(',');
                    TreeClusterRow treeClusterRow = new TreeClusterRow();
                    treeClusterRow.Name          = fields[0];
                    treeClusterRow.Tree          = fields[1];
                    treeClusterRow.TreeInstances = new List <SharpDX.Vector3>();
                    for (int i = 2; i < fields.Length; i = i + 3)
                    {
                        if (fields[i] == "" || fields[i + 1] == "" || fields[i + 2] == "")
                        {
                            break;
                        }

                        float x = Convert.ToSingle(fields[i], provider);
                        float y = Convert.ToSingle(fields[i + 1], provider);
                        float z = Convert.ToSingle(fields[i + 2], provider);
                        if (x == 0 && y == 0 && z == 0)
                        {
                            break;
                        }

                        treeClusterRow.TreeInstances.Add(new SharpDX.Vector3(x, y, z));
                    }

                    treeClusterRows.Add(treeClusterRow);
                }
            }

            // Add the trees of the clusters to the cache
            for (int i = 0; i < nifRows.Count; i++)
            {
                bool isTreeCluster = treeClusterRows.Any(tc => tc.Name.ToLower() == nifRows[i].Filename.ToLower());
                if (isTreeCluster)
                {
                    TreeClusterRow treeCluster = treeClusterRows.Where(tc => tc.Name.ToLower() == nifRows[i].Filename.ToLower()).FirstOrDefault();
                    if (treeCluster == null || nifRows.Where(n => n.Filename == treeCluster.Tree).Count() > 0)
                    {
                        continue;
                    }

                    NifRow tree = new NifRow();
                    tree.NifId       = 10000 + i;
                    tree.TextualName = treeCluster.Tree + " (cluster tree)";
                    tree.Filename    = treeCluster.Tree;
                    nifRows.Add(tree);
                }
            }

            MainForm.ProgressReset();
        }
Esempio n. 3
0
        /// <summary>
        /// Load all required CSV data
        /// </summary>
        private static void LoadCsvData()
        {
            MainForm.ProgressStartMarquee("Loading fixture data ...");

            List<string> nifsCsvRows = DataWrapper.GetFileContent(zoneConf.CvsMpk, "nifs.csv");
            List<string> fixturesRows = DataWrapper.GetFileContent(zoneConf.CvsMpk, "fixtures.csv");

            // Create a NumberFormatInfo object for floats and set some of its properties.
            System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo();
            provider.NumberDecimalSeparator = ".";
            provider.NumberGroupSeparator = "";
            provider.NumberGroupSizes = new int[] { 2 };

            foreach (string row in nifsCsvRows)
            {
                if (row.StartsWith("Grid") || row.StartsWith("NIF")) continue;

                string[] fields = row.Split(',');

                NifRow nifRow = new NifRow();
                nifRow.NifId = Convert.ToInt32(fields[0]);
                nifRow.TextualName = fields[1];
                nifRow.Filename = fields[2];
                nifRow.Color = Convert.ToInt32(fields[5]);
                nifRows.Add(nifRow);
            }

            // Read fixtures.csv
            foreach (string row in fixturesRows)
            {
                if (row.StartsWith("Fixtures") || row.StartsWith("ID")) continue;

                string[] fields = row.Split(',');
                FixtureRow fixtureRow = new FixtureRow();
                fixtureRow.Id = Convert.ToInt32(fields[0]);
                fixtureRow.NifId = Convert.ToInt32(fields[1]);
                fixtureRow.TextualName = fields[2];
                fixtureRow.X = Convert.ToDouble(fields[3], provider);
                fixtureRow.Y = Convert.ToDouble(fields[4], provider);
                fixtureRow.Z = Convert.ToDouble(fields[5], provider);
                fixtureRow.A = Convert.ToInt32(fields[6]);
                fixtureRow.Scale = Convert.ToInt32(fields[7]);
                fixtureRow.OnGround = (Convert.ToInt32(fields[11]) == 1) ? true : false;
                fixtureRow.Flip = (Convert.ToInt32(fields[12]) == 1) ? true : false;

                if (fields.Length > 15)
                {
                    fixtureRow.Angle3D = Convert.ToDouble(fields[15], provider);
                    fixtureRow.AxisX3D = Convert.ToDouble(fields[16], provider);
                    fixtureRow.AxisY3D = Convert.ToDouble(fields[17], provider);
                    fixtureRow.AxisZ3D = Convert.ToDouble(fields[18], provider);
                }

                fixtureRows.Add(fixtureRow);
            }

            // Only load on first init
            if (treeRows.Count == 0)
            {
                string treeMpk = string.Format("{0}\\zones\\trees\\treemap.mpk", Properties.Settings.Default.game_path);
                string treeClusterMpk = string.Format("{0}\\zones\\trees\\tree_clusters.mpk", Properties.Settings.Default.game_path);

                List<string> treesCsvRows = DataWrapper.GetFileContent(treeMpk, "Treemap.csv");
                List<string> treeClusterCsvRows = DataWrapper.GetFileContent(treeClusterMpk, "tree_clusters.csv");

                foreach (string row in treesCsvRows)
                {
                    if (row.StartsWith("NIF Name")) continue;

                    string[] fields = row.Split(',');
                    //if (fields[4] == "") continue;

                    TreeRow treeRow = new TreeRow();
                    treeRow.Name = fields[0];
                    treeRow.ZOffset = (string.IsNullOrEmpty(fields[4])) ? 0 : Convert.ToInt32(fields[4]);
                    treeRow.LeafTexture = (string.IsNullOrEmpty(fields[3])) ? "" : fields[3];
                    treeRow.AverageColor = GetTreeColor(treeRow);
                    treeRows.Add(treeRow);
                }

                foreach (string row in treeClusterCsvRows)
                {
                    if (row.StartsWith("name")) continue;
                    if (row == "") continue;

                    string[] fields = row.Split(',');
                    TreeClusterRow treeClusterRow = new TreeClusterRow();
                    treeClusterRow.Name = fields[0];
                    treeClusterRow.Tree = fields[1];
                    treeClusterRow.TreeInstances = new List<SharpDX.Vector3>();
                    for (int i = 2; i < fields.Length; i = i + 3)
                    {
                        if(fields[i] == "" || fields[i+1] == "" || fields[i+2] == "") break;

                        float x = Convert.ToSingle(fields[i], provider);
                        float y = Convert.ToSingle(fields[i + 1], provider);
                        float z = Convert.ToSingle(fields[i + 2], provider);
                        if (x == 0 && y == 0 && z == 0) break;

                        treeClusterRow.TreeInstances.Add(new SharpDX.Vector3(x, y, z));
                    }

                    treeClusterRows.Add(treeClusterRow);
                }
            }

            // Add the trees of the clusters to the cache
            for (int i = 0; i < nifRows.Count; i++ )
            {
                bool isTreeCluster = treeClusterRows.Any(tc => tc.Name.ToLower() == nifRows[i].Filename.ToLower());
                if (isTreeCluster)
                {
                    TreeClusterRow treeCluster = treeClusterRows.Where(tc => tc.Name.ToLower() == nifRows[i].Filename.ToLower()).FirstOrDefault();
                    if(treeCluster == null || nifRows.Where(n => n.Filename == treeCluster.Tree).Count() > 0) continue;

                    NifRow tree = new NifRow();
                    tree.NifId = 10000 + i;
                    tree.TextualName = treeCluster.Tree + " (cluster tree)";
                    tree.Filename = treeCluster.Tree;
                    nifRows.Add(tree);
                }
            }

            MainForm.ProgressReset();
        }
Esempio n. 4
0
 public TreeRowChangeEvent(TreeRow row, global::System.Data.DataRowAction action)
 {
     this.eventRow    = row;
     this.eventAction = action;
 }
Esempio n. 5
0
        private static System.Drawing.Color GetTreeColor(TreeRow treeRow)
        {
            if (treeColors.ContainsKey(treeRow.Name)) return treeColors[treeRow.Name];

            string treeTextureFile = string.Format("{0}\\zones\\trees\\{1}", Properties.Settings.Default.game_path, treeRow.LeafTexture);
            if (!File.Exists(treeTextureFile))
            {
                MainForm.Log(string.Format("Unable to get texture for tree {0}. Using default color.", treeRow.Name));
                return System.Drawing.ColorTranslator.FromHtml("#5e683a");
            }
            else
            {
                using (ImageMagick.MagickImage texture = new ImageMagick.MagickImage(treeTextureFile))
                {
                    texture.Resize(1, 1);
                    ImageMagick.Pixel pixel = texture.GetReadOnlyPixels(0, 0, 1, 1).First();

                    System.Drawing.Color color = pixel.ToColor();
                    treeColors.Add(treeRow.Name, color);
                    return color;
                }
            }
        }