コード例 #1
0
        private bool LoadPath(string imageFilePath)
        {
            try {
                double   i      = 0;
                string[] dir    = Directory.GetFiles(imageFilePath, "*.png");
                double   length = dir.Length;
                foreach (var image in dir)
                {
                    player.LoadImage(image);
                    Progress.Value = (int)(i / length * 100);
                    i++;
                }
            }
            catch (Exception ex) {
                FrameNumber.Text = "Unable to Load Directory";
                return(false);
            }

            FrameNumber.Visible = true;
            Progress.Visible    = false;
            maxFrame            = player.imageLength - 1;
            FrameNumber.Text    = "Frame " + currentFrame + " out of " + maxFrame;

            this.Invalidate();
            MainGraphicPanel.Invalidate();
            LoadProperties();

            return(true);
        }
コード例 #2
0
        private void MainGraphicPanel_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseDown = true;
                mouseX    = MousePosition.X;
                mouseY    = MousePosition.Y;
            }

            if (e.Button == MouseButtons.Right)
            {
                hitBox = null;

                //<3 lambda
                player.sprites[currentFrame].hitBoxes.ForEach(i => { i.selected = false; });
                MainGraphicPanel.Invalidate();
            }

            if (mouseDown && tool == ToolType.AddHB && player != null)
            {
                hitBox = new HitBox(player.sprites[currentFrame], new Point(MainGraphicPanel.Width, MainGraphicPanel.Height));
                var p = MainGraphicPanel.PointToClient(new Point(mouseX, mouseY));
                hitBox.x = p.X;
                hitBox.y = p.Y;
            }

            if (mouseDown && tool == ToolType.AddAHB && player != null)
            {
                hitBox      = new HitBox(player.sprites[currentFrame], new Point(MainGraphicPanel.Width, MainGraphicPanel.Height));
                hitBox.type = 1;
                var p = MainGraphicPanel.PointToClient(new Point(mouseX, mouseY));
                hitBox.x = p.X;
                hitBox.y = p.Y;
            }

            if (mouseDown && tool == ToolType.Select && player != null)
            {
                foreach (var hb in player.sprites[currentFrame].hitBoxes)
                {
                    var p = MainGraphicPanel.PointToClient(new Point(mouseX, mouseY));
                    if (hb.CheckCollision(p))
                    {
                        player.sprites[currentFrame].hitBoxes.ForEach(i => { i.selected = false; });
                        hb.selected = true;
                        MainGraphicPanel.Invalidate();
                        break;
                    }
                }
            }
        }
コード例 #3
0
        public bool UpdateFrame(int FrameNumber)
        {
            if (player != null)
            {
                if (FrameNumber >= 0 && FrameNumber < player.imageLength)
                {
                    currentFrame          = FrameNumber;
                    this.FrameNumber.Text = "Frame " + FrameNumber + " out of " + (player.imageLength - 1);
                    //this.FrameMoveBox.Text = "" + FrameNumber;
                    MainGraphicPanel.Invalidate();

                    if (filmRoll != null)
                    {
                        filmRoll.position = currentFrame;
                    }

                    LoadProperties();
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
        private void MainGraphicPanel_MouseUp(object sender, MouseEventArgs e)
        {
            if (mouseDown && (tool == ToolType.AddHB || tool == ToolType.AddAHB))
            {
                if (hitBox != null)
                {
                    hitBox.Correct();
                    player.sprites[currentFrame].hitBoxes.ForEach(i => { i.selected = false; });
                    player.sprites[currentFrame].hitBoxes.Add(hitBox);
                    hitBox.selected  = true;
                    tool             = ToolType.Select;
                    EditTool.Checked = true;
                    AddATool.Checked = false;
                    AddTool.Checked  = false;
                    MainGraphicPanel.Invalidate();

                    hitBox = null;
                }
            }

            resizing  = 0;
            mouseDown = false;
        }
コード例 #5
0
        private void Open_Click(object sender, EventArgs e)
        {
            OpenFileDialog sfd = new OpenFileDialog();

            sfd.DefaultExt       = "chr";
            sfd.Filter           = "Character File (*.chr)|*.chr";
            sfd.AddExtension     = true;
            sfd.RestoreDirectory = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                try{
                    var loadFilePath = sfd.FileName;

                    var x = new FileInfo(loadFilePath);
                    Decompress(x);

                    string origName = x.FullName.Remove(x.FullName.Length -
                                                        x.Extension.Length);

                    player = new Player();

                    var    fileStream = new FileStream(origName, FileMode.Open);
                    var    reader     = new StreamReader(fileStream);
                    string line       = reader.ReadLine();

                    imageFilePath     = reader.ReadLine();
                    curX              = Int32.Parse(reader.ReadLine());
                    curY              = Int32.Parse(reader.ReadLine());
                    player.animation  = Boolean.Parse(reader.ReadLine());
                    player.projectile = Boolean.Parse(reader.ReadLine());
                    player.projectile = Boolean.Parse(reader.ReadLine());

                    while (reader.ReadLine() != "\r\n")
                    {
                        ;
                    }

                    curY = Int32.Parse(reader.ReadLine());
                    LoadPath(imageFilePath);

                    line = reader.ReadLine();
                    var numb   = Int32.Parse(line.Split(',').Last());
                    var buffer = new char[numb];
                    reader.ReadBlock(buffer, 0, numb);
                    var stringBufffer = System.Text.UTF8Encoding.UTF8.GetString(System.Text.UTF8Encoding.UTF8.GetBytes(buffer));
                    var stringReader  = new StringReader(stringBufffer);

                    var saver = new XmlSerializer(typeof(List <PropertyGridCharacter>));
                    player.props = saver.Deserialize(stringReader) as List <PropertyGridCharacter>;


                    line   = reader.ReadLine();
                    line   = reader.ReadLine();
                    numb   = Int32.Parse(line.Split(',').Last());
                    buffer = new char[numb];
                    reader.ReadBlock(buffer, 0, numb);
                    stringBufffer = System.Text.UTF8Encoding.UTF8.GetString(System.Text.UTF8Encoding.UTF8.GetBytes(buffer));
                    stringReader  = new StringReader(stringBufffer);

                    var saver2 = new XmlSerializer(typeof(List <Sprite>));
                    var list   = saver2.Deserialize(stringReader) as List <Sprite>;
                    //player.sprites
                    for (int i = 0; i < list.Count; i++)
                    {
                        player.sprites[i].ID       = list[i].ID;
                        player.sprites[i].pos      = list[i].pos;
                        player.sprites[i].hitBoxes = list[i].hitBoxes;
                    }

                    saveFilePath = loadFilePath;
                    LoadProperties();

                    fileStream.Close();
                    File.Delete(origName);
                    MainGraphicPanel.Invalidate();
                }catch (Exception ex) {
                    MessageBox.Show("Error loading file");
                    Console.WriteLine(ex.ToString());
                }
            }
            sfd.Dispose();
        }
コード例 #6
0
 private void toolStripButton3_Click(object sender, EventArgs e)
 {
     scaleX = 1;
     scaleY = 1;
     MainGraphicPanel.Invalidate();
 }
コード例 #7
0
        private void HitBoxEditor_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                var result = player.sprites[currentFrame].hitBoxes.SingleOrDefault(i => i.selected == true);
                player.sprites[currentFrame].hitBoxes.Remove(result);
                MainGraphicPanel.Invalidate();
            }

            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.R)
            {
                if (filmRoll == null)
                {
                    filmRoll = new Film_Roll(this);
                }

                if (!filmRoll.Visible)
                {
                    filmRoll.Show();
                }
                else
                {
                    filmRoll.Hide();
                }
            }

            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.F)
            {
                if (summaryBox == null)
                {
                    summaryBox = new Summary(this);
                }

                if (!summaryBox.Visible)
                {
                    summaryBox.Show();
                }
                else
                {
                    summaryBox.Hide();
                }
            }

            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.C)
            {
                foreach (var hb in player.sprites[currentFrame].hitBoxes)
                {
                    var p = MainGraphicPanel.PointToClient(new Point(mouseX, mouseY));
                    if (hb.selected)
                    {
                        storedHitbox = hb;
                    }
                }
            }

            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.V)
            {
                if (storedHitbox != null)
                {
                    player.sprites[currentFrame].hitBoxes.ForEach(n => n.selected = false);
                    var hit = new HitBox();
                    hit.x        = storedHitbox.x;
                    hit.y        = storedHitbox.y;
                    hit.xx       = storedHitbox.xx;
                    hit.yy       = storedHitbox.yy;
                    hit.type     = storedHitbox.type;
                    hit.xoff     = storedHitbox.xoff;
                    hit.yoff     = storedHitbox.yoff;
                    hit.selected = true;
                    player.sprites[currentFrame].hitBoxes.Add(hit);
                    MainGraphicPanel.Invalidate();
                }
            }

            if (tool == ToolType.Move)
            {
                if (e.KeyCode == Keys.Left)
                {
                    if (curX > 0)
                    {
                        curX--;
                    }
                }
            }
        }
コード例 #8
0
 private void Grid_Click(object sender, EventArgs e)
 {
     displayGrid = !displayGrid;
     MainGraphicPanel.Invalidate();
 }
コード例 #9
0
 private void HitBoxEditor_Resize(object sender, EventArgs e)
 {
     MainGraphicPanel.Invalidate();
 }
コード例 #10
0
        private void MainGraphicPanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown && tool == ToolType.Move)
            {
                curX  += MousePosition.X - mouseX;
                curY  += MousePosition.Y - mouseY;
                mouseX = MousePosition.X;
                mouseY = MousePosition.Y;
                if (curX > MainGraphicPanel.Width)
                {
                    curX = MainGraphicPanel.Width;
                }
                if (curX < -MainGraphicPanel.Width)
                {
                    curX = -MainGraphicPanel.Width;
                }
                if (curY > MainGraphicPanel.Height)
                {
                    curY = MainGraphicPanel.Height;
                }
                if (curY < -MainGraphicPanel.Height)
                {
                    curY = -MainGraphicPanel.Height;
                }
                MainGraphicPanel.Invalidate();
            }
            if (mouseDown && tool == ToolType.MoveImage)
            {
                var pos = player.sprites[currentFrame].pos;
                int x   = pos.X += MousePosition.X - mouseX;
                int y   = pos.Y += MousePosition.Y - mouseY;
                mouseX = MousePosition.X;
                mouseY = MousePosition.Y;
                if (x > MainGraphicPanel.Width)
                {
                    x = MainGraphicPanel.Width;
                }
                if (x < -MainGraphicPanel.Width)
                {
                    x = -MainGraphicPanel.Width;
                }
                if (y > MainGraphicPanel.Height)
                {
                    y = MainGraphicPanel.Height;
                }
                if (y < -MainGraphicPanel.Height)
                {
                    y = -MainGraphicPanel.Height;
                }
                player.sprites[currentFrame].pos = new Rectangle(x, y, pos.Width, pos.Height);
                MainGraphicPanel.Invalidate();
            }

            if (mouseDown && (tool == ToolType.AddHB || tool == ToolType.AddAHB) && hitBox != null)
            {
                var p = MainGraphicPanel.PointToClient(new Point(MousePosition.X, MousePosition.Y));
                hitBox.xx = p.X;
                hitBox.yy = p.Y;
                MainGraphicPanel.Invalidate();
            }

            if (tool == ToolType.Select && player != null)
            {
                var result = player.sprites[currentFrame].hitBoxes.SingleOrDefault(i => i.selected == true);
                if (result != null)
                {
                    var p      = MainGraphicPanel.PointToClient(new Point(MousePosition.X, MousePosition.Y));
                    int corner = result.CheckCorners(p);
                    if (resizing != 5 && (corner == 7 /*top left*/ || resizing == 7))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeNWSE;
                        if (mouseDown)
                        {
                            result.x += MousePosition.X - mouseX;
                            result.y += MousePosition.Y - mouseY;
                            mouseX    = MousePosition.X;
                            mouseY    = MousePosition.Y;
                            MainGraphicPanel.Invalidate();
                            resizing = 7;
                        }
                    }
                    else
                    if (resizing != 5 && (corner == 9 /*top right*/ || resizing == 9))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeNESW;
                        if (mouseDown)
                        {
                            result.xx += MousePosition.X - mouseX;
                            result.y  += MousePosition.Y - mouseY;
                            mouseX     = MousePosition.X;
                            mouseY     = MousePosition.Y;
                            MainGraphicPanel.Invalidate();
                            resizing = 9;
                        }
                    }
                    else
                    if (resizing != 5 && (corner == 3 /*bottom right*/ || resizing == 3))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeNWSE;
                        if (mouseDown)
                        {
                            result.xx += MousePosition.X - mouseX;
                            result.yy += MousePosition.Y - mouseY;
                            mouseX     = MousePosition.X;
                            mouseY     = MousePosition.Y;
                            MainGraphicPanel.Invalidate();
                            resizing = 3;
                        }
                    }
                    else
                    if (resizing != 5 && (corner == 1 /*bottom left*/ || resizing == 1))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeNESW;
                        if (mouseDown)
                        {
                            result.x  += MousePosition.X - mouseX;
                            result.yy += MousePosition.Y - mouseY;
                            mouseX     = MousePosition.X;
                            mouseY     = MousePosition.Y;
                            MainGraphicPanel.Invalidate();
                            resizing = 1;
                        }
                    }
                    else
                    if (resizing != 5 && (corner == 2 /*bottom*/ || resizing == 2))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeNS;
                        if (mouseDown)
                        {
                            result.yy += MousePosition.Y - mouseY;
                            mouseY     = MousePosition.Y;
                            MainGraphicPanel.Invalidate();
                            resizing = 2;
                        }
                    }
                    else
                    if (resizing != 5 && (corner == 8 /*top*/ || resizing == 8))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeNS;
                        if (mouseDown)
                        {
                            result.y += MousePosition.Y - mouseY;
                            mouseY    = MousePosition.Y;
                            MainGraphicPanel.Invalidate();
                            resizing = 8;
                        }
                    }
                    else
                    if (resizing != 5 && (corner == 6 /*right*/ || resizing == 6))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeWE;
                        if (mouseDown)
                        {
                            result.xx += MousePosition.X - mouseX;
                            mouseX     = MousePosition.X;
                            mouseY     = MousePosition.Y;
                            MainGraphicPanel.Invalidate();
                            resizing = 6;
                        }
                    }
                    else
                    if (resizing != 5 && (corner == 4 /*left*/ || resizing == 4))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeWE;
                        if (mouseDown)
                        {
                            result.x += MousePosition.X - mouseX;
                            mouseX    = MousePosition.X;
                            mouseY    = MousePosition.Y;
                            MainGraphicPanel.Invalidate();
                            resizing = 4;
                        }
                    }
                    else if (mouseDown && (resizing == 0 || resizing == 5))
                    {
                        MainGraphicPanel.Cursor = Cursors.SizeAll;
                        result.x  += MousePosition.X - mouseX;
                        result.y  += MousePosition.Y - mouseY;
                        result.xx += MousePosition.X - mouseX;
                        result.yy += MousePosition.Y - mouseY;
                        mouseX     = MousePosition.X;
                        mouseY     = MousePosition.Y;
                        MainGraphicPanel.Invalidate();
                        resizing = 5;
                    }
                    else
                    {
                        MainGraphicPanel.Cursor = Cursors.Cross;
                    }

                    result.Correct();
                }
            }
        }
コード例 #11
0
 private void ToggleHitbox_Click(object sender, EventArgs e)
 {
     MainGraphicPanel.Invalidate();
 }