Esempio n. 1
0
        private void DoReplace()
        {
            string filename = cmbFilenames.SelectedIndex >= 0 ? imageLookup[cmbFilenames.SelectedIndex] : "";

            SpriteSheet spritesheet;

            if (TiledImport)
            {
                spritesheet = new SpriteSheet(SelectionOffset, SelectionSize,
                                              TilingMargin, TilingDirection, MaxTiles);
            }
            else
            {
                spritesheet = null;
            }

            try
            {
                SpriteTools.ReplaceSprite(replace, image, UseAlphaChannel, RemapToGamePalette,
                                          UseBackgroundSlots, SpriteImportMethod, filename, 0, spritesheet);
            }
            catch (AGSEditorException ex)
            {
                Factory.GUIController.ShowMessage(ex.Message, MessageBoxIcon.Warning);
            }
        }
Esempio n. 2
0
        private void cmbFilenames_SelectedIndexChanged(object sender, EventArgs e)
        {
            string filename = imageLookup[cmbFilenames.SelectedIndex];

            image = SpriteTools.LoadFirstImageFromFile(filename);
            PostImageLoad();
        }
Esempio n. 3
0
        private void OnReBakeSpriteSheet(bool showresult)
        {
            try
            {
                // Generate our Sprite Sheet
                SpriteTools.GenerateSpriteSheet(conRenderer.Actor, Globals.AppSettings.ProjectPath, conRenderer.Actor.Name);

                Image img = Image.FromFile(Globals.AppSettings.ProjectPath + @"\" + conRenderer.Actor.SpriteSheetFileName);

                MemoryStream stream = new MemoryStream();

                img.Save(stream, ImageFormat.Png);

                // Load the stream into a texture2D object
                conRenderer.Actor.ClipPlayer.Texture = Texture2D.FromStream(Globals.Game.GraphicsDevice, stream);

                // Close the Stream
                stream.Close();

                if (showresult)
                {
                    MessageBox.Show("Sprite sheet was successfully rebaked ..");
                }
            }
            catch (Exception er)
            {
                throw new Exception(er.Message);
            }
        }
Esempio n. 4
0
        public static Bitmap GetBitmapForSpriteResizedKeepingAspectRatio(Sprite sprite, int width, int height, bool centreInNewCanvas, bool drawOutline, Color backgroundColour)
        {
            float targetWidthHeightRatio = (float)width / (float)height;
            float spriteWidthHeightRatio = (float)sprite.Width / (float)sprite.Height;
            int   newWidth, newHeight;

            if ((sprite.Width < width / 2) && (sprite.Height < height / 2))
            {
                newWidth  = sprite.Width * 2;
                newHeight = sprite.Height * 2;
            }
            else if (spriteWidthHeightRatio > targetWidthHeightRatio)
            {
                newWidth  = width;
                newHeight = (int)(((float)width / (float)sprite.Width) * (float)sprite.Height);
            }
            else
            {
                newHeight = height;
                newWidth  = (int)(((float)height / (float)sprite.Height) * (float)sprite.Width);
            }

            // correct size if a very wide/tall image (eg. 400x2) is shrunk
            if (newWidth < 1)
            {
                newWidth = 1;
            }
            if (newHeight < 1)
            {
                newHeight = 1;
            }

            Bitmap newBmp = new Bitmap(width, height, PixelFormat.Format32bppRgb);

            using (Graphics g = Graphics.FromImage(newBmp))
            {
                g.Clear(backgroundColour);
                int x = 0, y = 0;

                using (Bitmap bitmapToDraw = Factory.NativeProxy.GetBitmapForSprite(sprite.Number, newWidth, newHeight))
                {
                    Bitmap bmp = bitmapToDraw ?? SpriteTools.GetPlaceHolder();
                    if (centreInNewCanvas)
                    {
                        x = width / 2 - bmp.Width / 2;
                        y = height - bmp.Height;
                    }

                    g.DrawImage(bmp, x, y, bmp.Width, bmp.Height);
                }

                if (drawOutline)
                {
                    g.DrawRectangle(Pens.Brown, x, y, newWidth - 1, newHeight - 1);
                }
            }

            return(newBmp);
        }
Esempio n. 5
0
        // return true when no more image to process
        private bool DoImport()
        {
            string      filename = cmbFilenames.SelectedIndex >= 0 ? imageLookup[cmbFilenames.SelectedIndex] : "";
            SpriteSheet spritesheet;

            if (TiledImport)
            {
                spritesheet = new SpriteSheet(SelectionOffset, SelectionSize,
                                              TilingMargin, TilingDirection, MaxTiles);
            }
            else
            {
                spritesheet = null;
            }

            try
            {
                if (frames == 1)
                {
                    // in the interest of speed, import the existing bitmap if the file has a single frame
                    SpriteTools.ImportNewSprites(folder, image, UseAlphaChannel, RemapToGamePalette,
                                                 UseBackgroundSlots, SpriteImportMethod, filename, 0, spritesheet);
                }
                else
                {
                    SpriteTools.ImportNewSprites(folder, filename, UseAlphaChannel, RemapToGamePalette,
                                                 UseBackgroundSlots, SpriteImportMethod, spritesheet);
                }
            }
            catch (AGSEditorException ex)
            {
                Factory.GUIController.ShowMessage(ex.Message, MessageBoxIcon.Warning);
            }

            hasImported = true;

            if (cmbFilenames.Items.Count == 1)
            {
                // this was the last image in the list
                return(true);
            }
            else if (cmbFilenames.Items.Count > 0)
            {
                // more images are in the list
                int index = cmbFilenames.SelectedIndex - 1;
                imageLookup.RemoveAt(cmbFilenames.SelectedIndex);
                cmbFilenames.Items.RemoveAt(cmbFilenames.SelectedIndex);
                cmbFilenames.SelectedIndex = Math.Max(index, 0);
                return(false);
            }

            // there was only one image, or no list to begin with
            return(true);
        }
Esempio n. 6
0
    public override void OnInspectorGUI()
    {
        _spriteTools = (SpriteTools)target;



        if (GUILayout.Button("Randomize Sprites"))
        {
            _spriteTools.RandomizeSprites();
        }



        base.OnInspectorGUI();
    }
Esempio n. 7
0
        private void cmbFilenames_SelectedIndexChanged(object sender, EventArgs e)
        {
            string filename = imageLookup[cmbFilenames.SelectedIndex];

            try
            {
                image = SpriteTools.LoadFirstImageFromFile(filename);
            }
            catch (Types.InvalidDataException ex)
            {
                // use a placeholder in-case of bad data
                Factory.GUIController.ShowMessage(ex.Message, MessageBoxIconType.Error);
                image = SpriteTools.GetPlaceHolder();
            }

            PostImageLoad();
        }
Esempio n. 8
0
    public override void OnInspectorGUI()
    {
        _spriteTools = (SpriteTools)target;

        //if(GUILayout.Button("Randomize Sprites"))
        //{
        //    _spriteTools.RandomizeSprites();
        //}

        //if (GUILayout.Button("Reset Sprites")) {
        //    _spriteTools.ResetSprites();
        //}

        if (GUILayout.Button("Randomzie"))
        {
            _spriteTools.RandomizeSprites();
        }

        if (GUILayout.Button("Colorize"))
        {
            _spriteTools.GetAndColorizeSprites();
        }

        if (GUILayout.Button("Shift Value"))
        {
            _spriteTools.GetAndShiftSpriteValues();
        }

        //if (GUILayout.Button("Shift Cached Value")) {
        //    _spriteTools.ShiftCachedColorsValue();
        //}

        if (GUILayout.Button("Set Order In Layer"))
        {
            _spriteTools.GetAndSetSpriteOrder();
        }

        if (GUILayout.Button("Set Layer"))
        {
            _spriteTools.GetAndSetSpriteLayer();
        }



        base.OnInspectorGUI();
    }
Esempio n. 9
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            if (HasFramesBeenAdded)
            {
                Actor actor = (Actor)Globals.RenderWindow.CurrentSelectedObject;

                if (actor != null)
                {
                    // Bake new sprite sheet!
                    SpriteTools.GenerateSpriteSheet(actor, Globals.AppSettings.ProjectPath, Path.GetFileName(actor.SpriteSheetFileName));
                }
                else
                {
                    MessageBox.Show(@"Error: The sprite sheet failed to be re-baked!");
                }
            }

            Globals.IsDialogWindowOpen = false;
            Service.CloseDropDown();
        }
Esempio n. 10
0
        private void PostImageLoad()
        {
            try
            {
                frames = SpriteTools.GetFrameCountEstimateFromFile(imageLookup[cmbFilenames.SelectedIndex]);
            }
            catch
            {
                frames = 1;
            }

            string format    = image.PixelFormat.ToString().Substring(6).ToUpper().Replace("BPP", " bit ").Replace("INDEXED", "indexed");
            string frametext = frames > 1 ? String.Format(", {0} frames", frames) : "";

            lblImageDescription.Text = String.Format("{0} x {1}, {2}{3}", image.Width, image.Height, format, frametext);

            // clear old labels to reset the scrollbars
            previewPanel.Controls.Clear();

            // this label is a hack to get the scroll bars to stretch to the size we want
            Label scrollWindowSizer = new Label();

            scrollWindowSizer.Location = new Point(image.Width * zoomLevel, image.Height * zoomLevel);
            scrollWindowSizer.Text     = string.Empty;
            scrollWindowSizer.Width    = 0;
            scrollWindowSizer.Height   = 0;
            previewPanel.Controls.Add(scrollWindowSizer);

            // update colour preview
            try
            {
                panelIndex0.BackColor = image.Palette.Entries[0];
            }
            catch (IndexOutOfRangeException)
            {
                // not an indexed palette
            }

            previewPanel.Refresh();
        }
Esempio n. 11
0
        private void btnAddActor_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show("Are you sure you want to add this to the scene?", "Add Actor Confirmation", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            // Disable all thse
            tbName.Enabled      = false;
            cbRole.Enabled      = false;
            gbSequences.Enabled = false;
            gbPreview.Enabled   = false;
            btnSave.Enabled     = false;

            pgBar.Style = ProgressBarStyle.Continuous;

            // Create our actor
            Actor = new EditorActor(Globals.Game, string.Empty, string.Empty);

            if (tvSequences.Nodes.Count >= 0)
            {
                // Set our Actors Role
                switch (cbRole.Text)
                {
                case "Player":
                    Actor.Role = ActorRole.Player;
                    break;

                case "Enemy":
                    Actor.Role = ActorRole.Enemy;
                    break;

                case "NPC":
                    Actor.Role = ActorRole.NPC;
                    break;

                case "Prop":
                    Actor.Role = ActorRole.Prop;
                    break;
                }

                Actor.Name = tbName.Text;

                // Init our clip player
                Actor.ClipPlayer = new AnimationPlayer2D(Globals.Game);
                Actor.ClipPlayer.Initialize();

                // Loop thru the Tree view controls Nodes adding our Key Frames to our Clip Player
                foreach (TreeNode node in tvSequences.Nodes)
                {
                    // Reset our frame index
                    {
                        int endFrameIndex = (node.Nodes.Count - 1);

                        Sequence2D sequence = new Sequence2D(node.Name);
                        sequence.StartFrame = 0;
                        sequence.EndFrame   = endFrameIndex;

                        // Add our Frames
                        foreach (TreeNode child in tvSequences.Nodes[node.Name].Nodes)
                        {
                            KeyFrame2D frame = new KeyFrame2D();
                            frame.Duration      = 1f;
                            frame.AssetFilename = child.Tag.ToString();

                            sequence.Frames.Add(frame);
                        }

                        // Add our Sequence
                        Actor.ClipPlayer.Sequences.Add(sequence);
                    }
                }

                // Generate our Sprite Sheet for the Clip Player
                SpriteTools.GenerateSpriteSheet(Actor, Globals.AppSettings.ProjectPath, tbName.Text);

                Actor.ClipPlayer.Texture = Catalyst3D.XNA.Engine.UtilityClasses.Utilitys.TextureFromFile(
                    Globals.Game.GraphicsDevice, Globals.AppSettings.ProjectPath + @"\" + Actor.SpriteSheetFileName);
            }

            // Default to the idle sequence
            if (Actor.Sequences.Count > 0)
            {
                Actor.Play(Actor.ClipPlayer.Sequences[0].Name, true);
            }

            // Add it to our Scene
            Globals.ActorAdded.Invoke(Actor);

            tvSequences.Nodes.Clear();

            Close();
        }
Esempio n. 12
0
 string IAGSEditor.GetSpriteUsageReport(int spriteNumber)
 {
     return(SpriteTools.GetSpriteUsageReport(spriteNumber, _agsEditor.CurrentGame));
 }