コード例 #1
0
        public void StartSpriteSheetGeneration()
        {
            SquidEditorPreferences prefs = SquidEditorForm.Instance.Preferences;

            CheckForNewEntry(comboBoxInputDir.Text, this.LastInputDir);
            CheckForNewEntry(comboBoxOutputDir.Text, this.LastOutputDir);
            CheckForNewEntry(comboBoxName.Text, this.LastNames);
            prefs.ToolSpritesheetLastInputFolder              = ConvertListToString(this.LastInputDir);
            prefs.ToolSpritesheetLastOutputFolder             = ConvertListToString(this.LastOutputDir);
            prefs.ToolSpritesheetLastOutputName               = ConvertListToString(this.LastNames);
            prefs.ToolSpritesheetLastSafeBorderSize           = (int)numericUpDownSafeBorderSize.Value;
            prefs.ToolSpritesheetLastCorrectTransparencyColor = checkBoxAlphaCorrection.Checked;
            prefs.ToolSpritesheetLastReplaceBaseColor         = checkBoxOverrideBaseColor.Checked;
            prefs.ToolSpritesheetLastPadTexturePowerOfTwo     = checkBoxPowerOf2.Checked;
            prefs.ToolSpritesheetLastBaseColor = new XnaColor(this.BaseTextureColor.R,
                                                              this.BaseTextureColor.G, this.BaseTextureColor.B);

            this.Sprites.Clear();
            String        path = comboBoxInputDir.Text;
            DirectoryInfo di   = new DirectoryInfo(path);

            FileInfo[] rgFiles = di.GetFiles("*.*");
            foreach (FileInfo fi in rgFiles)
            {
                String fileExt = fi.Extension.ToLower();
                if (fileExt == ".png" || fileExt == ".jpg" ||
                    fileExt == ".dds" || fileExt == ".bmp" || fileExt == ".tga")
                {
                    Console.WriteLine(Sprites.Count + "] Packing sprite " + fi.Name);
                    SpriteInfo newInfo = new SpriteInfo(Path.GetFileNameWithoutExtension(fi.Name));

                    System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open);
                    newInfo.Texture2D = Texture2D.FromStream(SquidEngine.Drawing.DrawingManager.GraphicsDevice, fs);
                    fs.Close();

                    newInfo.PixelData = new uint[newInfo.Texture2D.Width * newInfo.Texture2D.Height];
                    newInfo.Texture2D.GetData <uint>(newInfo.PixelData);
                    Sprites.Add(newInfo);
                }
            }
            PackSprites((int)numericUpDownSafeBorderSize.Value, comboBoxOutputDir.Text, comboBoxName.Text);
        }
コード例 #2
0
 /// <summary>
 /// Comparison function for sorting sprites by their original indices.
 /// </summary>
 static int CompareSpriteIndices(SpriteInfo a, SpriteInfo b)
 {
     return(a.Index.CompareTo(b.Index));
 }