Exemple #1
0
        /// <summary>
        /// Image button clicked
        /// </summary>
        private void butImage_Click(object sender, EventArgs e)
        {
            // Create an open file dialog box
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                // Set file filter
                ofd.Filter = "Supported Files (.bmp, .png, .gif, .gmk, .gm6, .gmd .gm81 .gmx)|*.bmp;*.png;*.gif;*.gmk;*.gm6;*.gmd;*.gm81;*.gmx;";

                // If the dialog result was not Ok, return
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // If getting a background object from a Game Maker project file
                if (ofd.FileName.Substring(ofd.FileName.LastIndexOf(".")).ToLower().Contains("gm") == true)
                {
                    // Create a Game Maker project form
                    using (ProjectIOForm iof = new ProjectIOForm(ofd.FileName, true))
                    {
                        // Show the form
                        iof.ShowDialog();

                        // Create a new import background form
                        using (ImportBackgroundForm backgroundForm = new ImportBackgroundForm(iof.GMProject.Backgrounds.ToArray()))
                        {
                            // If dialog result is Ok
                            if (backgroundForm.ShowDialog() == DialogResult.OK)
                            {
                                // Set background and update views
                                if (backgroundForm.Background != null)
                                {
                                    _background = backgroundForm.Background;
                                    SetUI();
                                }
                            }
                        }
                    }
                }
                else  // Normal image file
                {
                    // Create a new file stream
                    using (FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read))
                    {
                        // Get a bitmap from disk
                        Bitmap image = (Bitmap)Image.FromStream(fs);

                        // If the image is a valid size
                        if (CheckSize(image.Size, pnlImage.CellSize))
                        {
                            // Set GUI and set background name to the file name
                            pnlImage.Image          = image;
                            _background.GameMakerId = -1;
                            _background.Name        = Path.GetFileNameWithoutExtension(ofd.FileName);
                            txtName.Text            = _background.Name;

                            // Set transparency color
                            butSetColorKey_CheckedChanged(this);
                        }
                        else  // Not a valid size
                        {
                            image.Dispose();
                        }

                        // Update the status strip
                        UpdateStatusStrip();
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Set background button click
        /// </summary>
        private void butSetBackground_Click(object sender, EventArgs e)
        {
            // If a room has not been selected, return
            if (lstRooms.SelectedItem == null)
            {
                return;
            }

            // Create an open file dialog box
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                // Set file filter
                ofd.Filter = "Supported Files (.bmp, .png, .gif, .gmk, .gm6, .gmd .gm81 .gmx)|*.bmp;*.png;*.gif;*.gmk;*.gm6;*.gmd;*.gm81;*.gmx;";

                // If the dialog result was not Ok, return
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }


                // If getting a background object from a Game Maker project file
                if (ofd.FileName.Substring(ofd.FileName.LastIndexOf(".")).ToLower().Contains("gm") == true)
                {
                    // Create a Game Maker project form
                    using (ProjectIOForm iof = new ProjectIOForm(ofd.FileName, true))
                    {
                        // Show the form
                        iof.ShowDialog();

                        // Create a new import background form
                        using (ImportBackgroundForm backgroundForm = new ImportBackgroundForm(iof.GMProject.Backgrounds.FindAll(b => b.UseAsTileSet == true).ToArray()))
                        {
                            // If dialog result is not Ok, or the background is empty, return
                            if (backgroundForm.ShowDialog() != DialogResult.OK || backgroundForm.Background == null)
                            {
                                return;
                            }

                            (lstRooms.SelectedItem as ExportProject).Background = backgroundForm.Background;
                            UpdateProjectList(lstRooms.SelectedIndex);

                            // Export projects have changed
                            _changed = _allowChange;
                        }
                    }
                }
                else
                {
                    // Create a new file stream
                    using (FileStream fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read))
                    {
                        // Get a bitmap from disk
                        Bitmap          image      = (Bitmap)Image.FromStream(fs);
                        GMareBackground background = new GMareBackground();
                        background.Name  = Path.GetFileNameWithoutExtension(ofd.FileName);
                        background.Image = new Graphics.PixelMap(image);

                        (lstRooms.SelectedItem as ExportProject).Background = background;
                        UpdateProjectList(lstRooms.SelectedIndex);

                        // Export projects have changed
                        _changed = _allowChange;
                    }
                }
            }
        }