Beispiel #1
0
        void ActionsTabTIMTextureUsageButton_Click(object sender, EventArgs e)
        {
            //=======================================================================
            // Find all the TIMs that might be textures
            //=======================================================================
            Dictionary <int, List <string> > lUsageCount = new Dictionary <int, List <string> >();
            int lIndex = 0;

            foreach (Chunk lGroup in mMainForm.CurrentLevel.NamedImageGroups.GetChildren())
            {
                if (!(lGroup is NamedImageGroup))
                {
                    continue;
                }

                foreach (Chunk lChunk in lGroup.GetChildren())
                {
                    if (lChunk is TIMChunk && ((TIMChunk)lChunk).ImageWidth == 64 && ((TIMChunk)lChunk).ImageHeight == 64)
                    {
                        lUsageCount[lIndex] = new List <string>();
                    }

                    lIndex++;
                }
            }

            //=======================================================================
            // Find all the TIMs that are actually in use as textures
            //=======================================================================
            foreach (FlatChunk lFlat in mMainForm.CurrentLevel.SHET.Flats)
            {
                for (int ii = 0; ii < lFlat.Width; ii++)
                {
                    for (int jj = 0; jj < lFlat.Height; jj++)
                    {
                        if (lUsageCount.ContainsKey(lFlat.TextureIds[ii][jj]))
                        {
                            lUsageCount[lFlat.TextureIds[ii][jj]].Add(lFlat.Name + string.Format(" ({0},{1})", ii, jj));
                        }
                    }
                }
            }

            //=======================================================================
            // Generate the report
            //=======================================================================
            StringBuilder lBuilder = new StringBuilder();

            int[] lTextureIds = new List <int>(lUsageCount.Keys).ToArray();
            int[] lUsages     = new List <List <string> >(lUsageCount.Values).ConvertAll <int>(delegate(List <string> xiList) { return(xiList.Count); }).ToArray();
            Array.Sort(lUsages, lTextureIds);

            foreach (int lTextureId in lTextureIds)
            {
                if (lUsageCount[lTextureId].Count == 0)
                {
                    lBuilder.AppendLine(string.Format("{0}: Not used",
                                                      lTextureId));
                }
                else if (lUsageCount[lTextureId].Count <= 3)
                {
                    lBuilder.AppendLine(string.Format("{0}: Used in {1}",
                                                      lTextureId,
                                                      string.Join(", ", lUsageCount[lTextureId].ToArray())));
                }
                else
                {
                    lBuilder.AppendLine(string.Format("{0}: Used in {1} and {2} other places",
                                                      lTextureId,
                                                      lUsageCount[lTextureId][0],
                                                      lUsageCount[lTextureId].Count - 1));
                }
            }

            ReportForm.ShowReport("TIM Texture Usage Report", lBuilder.ToString());
        }