Beispiel #1
0
        public PListDefinition Scale(float scale)
        {
            PListDefinition pListDefinition = new PListDefinition(this.Name);

            pListDefinition.DestinationX           = (int)Math.Round((float)this.DestinationX * scale, MidpointRounding.AwayFromZero);
            pListDefinition.DestinationY           = (int)Math.Round((float)this.DestinationY * scale, MidpointRounding.AwayFromZero);
            pListDefinition.OriginX                = (int)Math.Round((float)this.OriginX * scale, MidpointRounding.AwayFromZero);
            pListDefinition.OriginY                = (int)Math.Round((float)this.OriginY * scale, MidpointRounding.AwayFromZero);
            pListDefinition.Rotate                 = this.Rotate;
            pListDefinition.TotalHorizontalRepeats = this.TotalHorizontalRepeats;
            pListDefinition.TotalVerticalRepeats   = this.TotalVerticalRepeats;

            return(pListDefinition);
        }
Beispiel #2
0
        private void btnDown_Click(object sender, EventArgs e)
        {
            var row = gvDefinitions.CurrentRow;

            if (row != null &&
                row.Index < gvDefinitions.Rows.Count - 2)
            {
                int             index = row.Index;
                PListDefinition value = _PListDefinitions[row.Index];
                _PListDefinitions.Remove(value);
                _PListDefinitions.Insert(index + 1, value);

                gvDefinitions.CurrentRow.Selected      = false;
                gvDefinitions.CurrentCell              = gvDefinitions.Rows[index + 1].Cells[0];
                gvDefinitions.Rows[index + 1].Selected = true;

                Refresh();
            }
        }
Beispiel #3
0
        private void loadFromPListMenuItem_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter      = "Texture Packer Definition (*.plist)|*.plist";
                openFileDialog.Multiselect = true;
                switch (openFileDialog.ShowDialog())
                {
                case DialogResult.OK:

                    foreach (string fileName in openFileDialog.FileNames)
                    {
                        FileInfo fileInfo = new FileInfo(fileName);
                        if (fileInfo.Exists)
                        {
                            string content = File.ReadAllText(fileInfo.FullName);
                            content = content.Remove(0, content.IndexOf("<plist"));
                            XElement doc = XElement.Parse(content);

                            XElement               keyElement;
                            XElement               valueElement;
                            PListDefinition        definition;
                            List <PListDefinition> definitions = new List <PListDefinition>();
                            int index = 0;

                            try
                            {
                                foreach (var dictElement in doc.Descendants("dict"))
                                {
                                    keyElement = dictElement.PreviousNode as XElement;

                                    if (keyElement != null &&
                                        keyElement.Name == "key" &&
                                        keyElement.Value != "texture" &&
                                        keyElement.Value != "frames")
                                    {
                                        definition       = new PListDefinition(keyElement.Value);
                                        definition.Index = index++;

                                        foreach (var definitionKeyElement in dictElement.Elements("key"))
                                        {
                                            valueElement = definitionKeyElement.NextNode as XElement;
                                            if (valueElement != null)
                                            {
                                                switch (definitionKeyElement.Value)
                                                {
                                                case "x": definition.OriginX = int.Parse(valueElement.Value.Trim()); break;

                                                case "y": definition.OriginY = int.Parse(valueElement.Value.Trim()); break;

                                                case "width": definition.DestinationX = definition.OriginX - 1 + int.Parse(valueElement.Value.Trim()); break;

                                                case "height": definition.DestinationY = definition.OriginY - 1 + int.Parse(valueElement.Value.Trim()); break;

                                                case "rotate": definition.Rotate = string.Compare(valueElement.Name.LocalName, "true", true) == 0; break;
                                                }
                                            }
                                        }

                                        definitions.Add(definition);
                                    }
                                }

                                AddNewTabPage(definitions);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                return;
                            }
                        }
                    }
                    break;
                }
            }
        }