Beispiel #1
0
        private void SelectKeyGrid(KeyFrameGrid grid)
        {
            if (_LastSelected == grid)
            {
                return;
            }
            if (_LastSelected != null)
            {
                _LastSelected.IsSelected = false;
            }
            if (grid != null)
            {
                grid.IsSelected            = true;
                _Parent.SelectedFrameIndex = new FrameIndex(grid.Segment, grid.Frame);
            }
            else
            {
                //clear selected
                _Parent.SelectedFrameIndex = new FrameIndex(-1, -1);
            }
            _LastSelected = grid;

            if (_Control != null)
            {
                _Control.Invalidate();
            }
        }
Beispiel #2
0
        private int GetKeyFrameIndex(List <KeyFrameGrid> list, KeyFrameGrid grid)
        {
            var index = list.FindIndex(g => g == grid);

            if (index == -1)
            {
                return(list.Count - 1);
            }
            return(index);
        }
Beispiel #3
0
        public void ShowSelectImageForm()
        {
            if (_LastSelected != null)
            {
                var grid = (KeyFrameGrid)_LastSelected;

                var action = _Parent.CurrentAction;
                if (action == null)
                {
                    return;
                }

                var frame = action.Segments[grid.Segment].Frames[grid.Frame];

                var dialog = new ImageSelectForm(_Parent.Project)
                {
                    SelectedImage = frame.ImageID,
                };
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    frame.ImageID = dialog.SelectedImage;
                    RefreshList();
                }
            }
            else
            {
                var dialog = new ImageSelectForm(_Parent.Project)
                {
                    SelectedImage = null,
                };
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    //create a new frame
                    var action = _Parent.CurrentAction;
                    if (action == null)
                    {
                        return;
                    }

                    if (action.Segments.Count == 0)
                    {
                        action.Segments.Add(new Pat.AnimationSegment()
                        {
                            Frames = new List <Pat.Frame>(),
                        });
                    }
                    var segment = action.Segments.Last();

                    int duration = 1;
                    if (segment.Frames.Count > 0)
                    {
                        duration = segment.Frames.Last().Duration;
                    }

                    var frame = new Pat.Frame()
                    {
                        Duration    = duration,
                        ImageID     = dialog.SelectedImage,
                        AttackBoxes = new List <Pat.Box>(),
                        HitBoxes    = new List <Pat.Box>(),
                        Points      = new List <Pat.FramePoint>(),
                        ScaleX      = 100,
                        ScaleY      = 100,
                    };
                    segment.Frames.Add(frame);

                    //ensure after refreshing, the new frame is selected
                    _LastSelected = new KeyFrameGrid(null, 0, 0, 0, 0, frame);

                    RefreshList();
                }
            }
        }
Beispiel #4
0
        private void RefreshList()
        {
            //save the list
            var lastList = _GridList
                           .Where(g => g is KeyFrameGrid)
                           .Cast <KeyFrameGrid>().ToArray();

            _GridList.Clear();

            var data = _Parent.CurrentAction;

            if (data == null)
            {
                UpdateControlWidth();
                SelectKeyGrid(null);
                return;
            }

            var          imageList   = _Parent.Project.ImageList;
            KeyFrameGrid newSelected = null;

            for (int i = 0; i < data.Segments.Count; ++i)
            {
                var seg = data.Segments[i];

                //calculate cancellable frame
                int cancellableJump = -1, cancellableSkill = -1;
                if (seg.JumpCancellable != null)
                {
                    int sum = 0;
                    for (int fi = 0; fi < seg.Frames.Count; ++fi)
                    {
                        if (sum >= seg.JumpCancellable.StartFrom)
                        {
                            cancellableJump = fi;
                            break;
                        }
                        sum += seg.Frames[fi].Duration;
                    }
                }
                if (seg.SkillCancellable != null)
                {
                    int sum = 0;
                    for (int fi = 0; fi < seg.Frames.Count; ++fi)
                    {
                        if (sum >= seg.SkillCancellable.StartFrom)
                        {
                            cancellableSkill = fi;
                            break;
                        }
                        sum += seg.Frames[fi].Duration;
                    }
                }
                for (int j = 0; j < seg.Frames.Count; ++j)
                {
                    var frame = seg.Frames[j];
                    var image = frame.ImageID == null ? null : imageList.GetImage(frame.ImageID);

                    //flags
                    KeyFrameFlags flags = 0;
                    if (j == 0)
                    {
                        flags |= KeyFrameFlags.IsKeyFrame;
                    }
                    if (j == 0 && seg.Damage != null)
                    {
                        flags |= KeyFrameFlags.HasDamage;
                    }
                    if (j == cancellableJump)
                    {
                        flags |= KeyFrameFlags.JumpCancellable;
                    }
                    if (j == cancellableSkill)
                    {
                        flags |= KeyFrameFlags.SkillCancellable;
                    }

                    //create
                    var keyFrame = new KeyFrameGrid(image, _GridList.Count, i, j, flags, frame);

                    //restore status
                    //selected
                    if (_LastSelected != null && frame == _LastSelected.FrameObject)
                    {
                        keyFrame.IsSelected = true;
                        newSelected         = keyFrame;
                    }
                    var lastItem = lastList.Where(g => g.FrameObject == frame).FirstOrDefault();
                    if (lastItem != null && !lastItem.IsFolded)
                    {
                        keyFrame.IsFolded = false;
                    }

                    _GridList.Add(keyFrame);
                    for (int k = 0; k < frame.Duration - 1; ++k)
                    {
                        _GridList.Add(new NormalFrameGrid(keyFrame, image, _GridList.Count));
                    }
                }
            }

            _GridList.Add(new EmptyGrid());

            UpdateControlWidth();

            if (_GridList.Count > 0 && _GridList[0] is KeyFrameGrid && newSelected == null)
            {
                newSelected = (KeyFrameGrid)_GridList[0];
            }
            SelectKeyGrid(newSelected);
        }
Beispiel #5
0
 private void OnAnimationReset()
 {
     _LastSelected = null;
     RefreshList();
 }
Beispiel #6
0
 public NormalFrameGrid(KeyFrameGrid key, Bitmap bitmap, int index)
     : base(bitmap, index)
 {
     KeyFrame = key;
 }