示例#1
0
        /// <summary>
        /// Gets a GMare background from imported backgrounds
        /// </summary>
        /// <returns>A GMare background</returns>
        private GMareBackground GetBackground()
        {
            // Create new background
            GMareBackground background = null;

            // If an item was selected
            if (lstBackgrounds.SelectedItem != null)
            {
                // Get GMare vackground from Game Maker background
                GMBackground back = lstBackgrounds.SelectedItem as GMBackground;

                // Set properties
                background             = new GMareBackground();
                background.GameMakerId = back.Id;
                background.Name        = back.Name;
                background.OffsetX     = back.HorizontalOffset;
                background.OffsetY     = back.VerticalOffset;
                background.SeparationX = back.HorizontalSeperation;
                background.SeparationY = back.VerticalSeperation;
                background.TileWidth   = back.TileWidth;
                background.TileHeight  = back.TileHeight;
                background.Image       = new Graphics.PixelMap(GMUtilities.GetBitmap(back.Image));

                // If the background is transparent
                if (back.Transparent == true)
                {
                    background.Image.UseKey   = true;
                    background.Image.ColorKey = Color.FromArgb(background.Image[0, background.Image.Height - 1]);
                }
            }

            // Return converted background
            return(background);
        }
示例#2
0
        /// <summary>
        /// Constructs a new room form with a room to edit
        /// </summary>
        public EditBackgroundForm(GMareBackground background)
        {
            InitializeComponent();

            // Set background to edit
            _background = background;

            // Update the UI with background data
            SetUI();
        }
示例#3
0
 public TilesetRefactorForm()
 {
     this.InitializeComponent();
     this._background     = App.Room.Backgrounds[0].Clone();
     this._originalSize   = new Size(this._background.Image.Width, this._background.Image.Height);
     this.butUndo.Enabled = false;
     this.butRedo.Enabled = false;
     this._history        = new UndoRedoHistory <ITilesOwner>((ITilesOwner)this, 20);
     this.PopulateTiles(this._background.GetCondensedTileset());
     this.SetUI();
 }
示例#4
0
        /// <summary>
        /// Constructs a new tileset refactor form
        /// </summary>
        public TilesetRefactorForm()
        {
            InitializeComponent();

            // Create a new room
            _background   = App.Room.Backgrounds[0].Clone();
            _originalSize = new Size(_background.Image.Width, _background.Image.Height);

            // Create new undo/redo history
            butUndo.Enabled = false;
            butRedo.Enabled = false;
            _history        = new UndoRedoHistory <ITilesOwner>(this, 20);

            // Get the tiles from the background
            PopulateTiles(_background.GetCondensedTileset());

            // Set up the UI based on the data given
            SetUI();
        }
示例#5
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();
                    }
                }
            }
        }
示例#6
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;
                    }
                }
            }
        }
        /// <summary>
        /// Sets the given Game Maker room properties to GMare project room properties
        /// </summary>
        /// <param name="room">The room to set properties of</param>
        /// <param name="id">Id of the room</param>
        /// <returns>If the room property set was sucessful</returns>
        private bool SetRoomProperties(GMRoom room, int id)
        {
            // Set room properties
            room.Id              = id == -1 ? room.Id : id;
            room.Name            = txtName.Text;
            room.BackgroundColor = GMUtilities.ColorToGMColor(App.Room.BackColor);
            room.Width           = App.Room.Width;
            room.Height          = App.Room.Height;
            room.TileWidth       = App.Room.Backgrounds[0].TileWidth;
            room.TileHeight      = App.Room.Backgrounds[0].TileHeight;
            room.Caption         = App.Room.Caption;
            room.CreationCode    = App.Room.CreationCode;
            room.Speed           = App.Room.Speed;
            room.Persistent      = App.Room.Persistent;

            // If exporting tiles, set tiles
            if (chkWriteTiles.Checked)
            {
                // Get the game maker background selected
                GMBackground background = (GMBackground)lstBackgrounds.SelectedItem;

                // If the selected background dimensions do not match the GMare project's background
                if (chkWriteTiles.Checked && (App.Room.Backgrounds[0].Image.Width != background.Width || App.Room.Backgrounds[0].Image.Height != background.Height))
                {
                    // Give warning, and cancel export
                    DialogResult result = MessageBox.Show("The selected background's size does not match the background used for this room. Please select a background that is the same size as the used background.",
                                                          "GMare", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                    return(false);
                }

                // Copy the room's background, set the game maker background id
                GMareBackground gmareBackground = App.Room.Backgrounds[0].Clone();
                gmareBackground.GameMakerId = background.Id;
                gmareBackground.Name        = background.Name;

                // Get tile array
                GMTile[] tiles = App.Room.GMareTilesToGMTiles(_project.LastTileId, gmareBackground, chkOptimizeTiles.Checked);

                // Set unique names
                foreach (GMTile tile in tiles)
                {
                    tile.Name = GetUniqueName(true);
                }

                // Set the room's tiles
                room.Tiles = tiles;
            }

            // If the room's instances should be written, write instances
            if (chkWriteInstances.Checked)
            {
                room.Instances = SetInstances();

                // If no instances, return  unsuccessful
                if (room.Instances == null)
                {
                    return(false);
                }
            }

            // Successful
            return(true);
        }
        /// <summary>
        /// On get glyph
        /// </summary>
        public override System.Drawing.Bitmap OnGetGlyph(DrawItemEventArgs e)
        {
            // Get glyph based on data type
            switch (_listboxMode)
            {
            case ListboxType.Brushes:

                // Get brush, return the glyph of the brush
                GMareBrush brush = Items[e.Index] as GMareBrush;
                return(brush == null || brush.Glyph == null ? (GDI.Bitmap)GMare.Properties.Resources.brush.Clone() : (GDI.Bitmap)brush.Glyph.Clone());

            case ListboxType.Projects:

                // Get background
                GMareBackground background = (Items[e.Index] as ExportProject).Background;

                // If the background is empty, return null
                if (background == null)
                {
                    return(null);
                }

                // Image to draw
                GDI.Bitmap image = null;

                // Get the background image
                if (background.Image != null)
                {
                    image = ScaleImage(background.Image.ToBitmap(), _cellSize.Width, _cellSize.Height);
                }
                else
                {
                    // Create an empty image
                    image = new GDI.Bitmap(_cellSize.Width, _cellSize.Height);
                    GDI.Pen             border      = new GDI.Pen(GDI.Color.Gray);
                    GDI.Pen             innerBorder = new GDI.Pen(GDI.Color.White);
                    GDI.Graphics        gfx         = GDI.Graphics.FromImage(image);
                    GDI.Rectangle       rect        = new GDI.Rectangle(0, 0, image.Width - 1, image.Height - 1);
                    GDI.RectangleF      rectF       = new GDI.RectangleF(0, 0, image.Width, image.Height);
                    LinearGradientBrush gradient    = new LinearGradientBrush(rect.Location, new GDI.Point(rect.Right, rect.Bottom), GDI.Color.Gray, GDI.Color.LightGray);

                    // String render format
                    GDI.StringFormat stringFormat = new GDI.StringFormat();
                    stringFormat.Alignment     = GDI.StringAlignment.Center;
                    stringFormat.LineAlignment = GDI.StringAlignment.Center;

                    // Draw image
                    gfx.FillRectangle(gradient, rect);
                    gfx.DrawRectangle(border, rect);
                    rect.Inflate(new GDI.Size(-1, -1));
                    gfx.DrawRectangle(innerBorder, rect);
                    rect.Inflate(new GDI.Size(-1, -1));
                    gfx.DrawRectangle(border, rect);
                    gfx.DrawString("?", this.DisplayFont, GDI.Brushes.White, rectF, stringFormat);

                    // Dispose
                    border.Dispose();
                    innerBorder.Dispose();
                    stringFormat.Dispose();
                    gradient.Dispose();
                    gfx.Dispose();
                }

                return(image);

            default: return(Glyph);
            }
        }