示例#1
0
        private void newSpriteSheet_Click(object sender, EventArgs e)
        {
            Form childForm = new SpriteSheetForm();

            childForm.MdiParent = this;
            childForm.Text      = "Sprite Sheet" + childFormNumber++;
            childForm.Show();
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (character != null)
            {
                SpriteSheetForm sheet = FindSheet();
                if (sheet != null)
                {
                    Layer layer = new Layer("Unnamed Layer");
                    layer.TileCoordinates = sheet.CurrentTile;
                    layer.Priority        = character.Layers.Count + 1;

                    character.Layers.Add(layer);

                    listViewTiles.Items.Add(layer.GetListViewItem());

                    DrawCharacter();
                }
            }
        }
        public SpriteSheetForm FindSheet()
        {
            MdiClient parent = Parent as MdiClient;

            if (parent != null)
            {
                foreach (Form child in parent.MdiChildren)
                {
                    if (child.GetType() == typeof(SpriteSheetForm))
                    {
                        SpriteSheetForm sheet = child as SpriteSheetForm;
                        if (sheet.Spritesheet == character.Spritesheet)
                        {
                            return(sheet);
                        }
                    }
                }
            }
            return(null);
        }
示例#4
0
        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter           = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string     FileName  = openFileDialog.FileName;
                SpriteForm childForm = new SpriteForm();

                // Use a BinaryFormatter or SoapFormatter
                IFormatter formatter = new SoapFormatter();
                childForm.DeserializeItem(FileName, formatter);

                // normally we would validate that the form loaded (as in didn't throw an exception)
                // before making it visible so we can cleanly exit on error

                // Check if the spritesheet form is open containing the same spritesheet, if not then open one
                SpriteSheetForm form = childForm.FindSheet();
                if (form == null)
                {
                    Form spritesheetForm = new SpriteSheetForm(childForm.Spritesheet);
                    spritesheetForm.MdiParent = this;
                    spritesheetForm.Text      = "Sprite Sheet" + childFormNumber++;
                    spritesheetForm.Show();
                }
                else
                {
                    childForm.Spritesheet = form.Spritesheet;
                }

                // Finally, display thr SpriteForm
                childForm.MdiParent = this;
                childForm.Text      = "Sprite " + childFormNumber++;
                childForm.Show();
            }
        }
示例#5
0
        private void SpriteForm_Activated(object sender, EventArgs e)
        {
            MdiClient parent = Parent as MdiClient;

            if (parent != null)
            {
                foreach (Form child in parent.MdiChildren)
                {
                    if (child.GetType() == typeof(SpriteSheetForm))
                    {
                        SpriteSheetForm sheet = child as SpriteSheetForm;
                        Spritesheet     ss    = sheet.Spritesheet;
                        if (ss != null && !comboBoxSheets.Items.Contains(ss))
                        {
                            comboBoxSheets.Items.Add(ss);
                        }
                    }
                }
            }

            if (character.Spritesheet != null)
            {
                comboBoxSheets.SelectedItem = character.Spritesheet;
            }
            else if (comboBoxSheets.Items.Count > 0)
            {
                comboBoxSheets.SelectedIndex = 0;
                character.Spritesheet        = comboBoxSheets.SelectedItem as Spritesheet;
            }

            // fill list view with any layers the character has
            listViewTiles.Items.Clear();
            for (int i = 0; i < character.Layers.Count; i++)
            {
                listViewTiles.Items.Add(character.Layers[i].GetListViewItem());
            }
        }