コード例 #1
0
            protected override bool ProbeInternal(BoneRow node, Row row, RowLocation location)
            {
                if (!(location.ParentRow.Components.Contains <BoneRow>() || location.ParentRow.Components.Contains <FolderRow>()))
                {
                    return(false);
                }
                var targetParent = location.ParentRow.Components.Get <BoneRow>()?.Bone;

                try {
                    var bone = row.Components.Get <BoneRow>().Bone;
                    // Check if bone target parent is bone descendant
                    if (IsDescendant(bone, targetParent))
                    {
                        return(false);
                    }
                    if (bone.BaseIndex == 0 && !location.ParentRow.Components.Contains <BoneRow>())
                    {
                        MoveFolderItemTo(bone, location);
                    }
                    else
                    {
                        SetProperty.Perform(bone, nameof(Bone.Position), Vector2.Zero);
                    }

                    SetProperty.Perform(bone, nameof(Bone.BaseIndex), targetParent?.Index ?? 0);
                    SortBonesInChain.Perform(bone);
                    var nodes      = Document.Current.Container.Nodes;
                    var parentBone = nodes.GetBone(bone.BaseIndex);
                    while (parentBone != null && !parentBone.EditorState().ChildrenExpanded)
                    {
                        SetProperty.Perform(parentBone.EditorState(), nameof(NodeEditorState.ChildrenExpanded), true);
                        bone = nodes.GetBone(bone.BaseIndex);
                    }
                } catch (InvalidOperationException e) {
                    AlertDialog.Show(e.Message);
                    return(false);
                }
                return(true);
            }
コード例 #2
0
            protected override bool ProbeInternal(BoneRow node, Row row, RowLocation location)
            {
                if (!(location.ParentRow.Components.Contains <BoneRow>() || location.ParentRow.Components.Contains <FolderRow>()))
                {
                    return(false);
                }
                var targetParent = location.ParentRow.Components.Get <BoneRow>()?.Bone;

                try {
                    var bone = row.Components.Get <BoneRow>().Bone;
                    // Check if bone target parent is bone descendant
                    if (IsDescendant(bone, targetParent))
                    {
                        return(false);
                    }
                    if (bone.BaseIndex == 0 && !location.ParentRow.Components.Contains <BoneRow>())
                    {
                        MoveFolderItemTo(bone, location);
                    }
                    else if (!location.ParentRow.Components.Contains <BoneRow>())
                    {
                        SetAnimableProperty.Perform(
                            bone, nameof(Bone.Position),
                            bone.Position * bone.CalcLocalToParentWidgetTransform(),
                            CoreUserPreferences.Instance.AutoKeyframes);
                        var   boneEntry = bone.Parent.AsWidget.BoneArray[bone.Index];
                        float angle     = (boneEntry.Tip - boneEntry.Joint).Atan2Deg;
                        SetAnimableProperty.Perform(
                            bone, nameof(Bone.Rotation),
                            angle, CoreUserPreferences.Instance.AutoKeyframes);
                    }
                    else
                    {
                        SetAnimableProperty.Perform(
                            bone, nameof(Bone.Position),
                            Vector2.Zero, CoreUserPreferences.Instance.AutoKeyframes);
                        var   newParent   = location.ParentRow.Components.Get <BoneRow>().Bone;
                        var   parentEntry = newParent.Parent.AsWidget.BoneArray[newParent.Index];
                        float parentAngle = (parentEntry.Tip - parentEntry.Joint).Atan2Deg;
                        var   boneEntry   = bone.Parent.AsWidget.BoneArray[bone.Index];
                        float angle       = (boneEntry.Tip - boneEntry.Joint).Atan2Deg;
                        SetAnimableProperty.Perform(
                            bone, nameof(Bone.Rotation),
                            angle - parentAngle, CoreUserPreferences.Instance.AutoKeyframes);
                    }

                    SetProperty.Perform(bone, nameof(Bone.BaseIndex), targetParent?.Index ?? 0);
                    SortBonesInChain.Perform(bone);
                    var nodes      = Document.Current.Container.Nodes;
                    var parentBone = nodes.GetBone(bone.BaseIndex);
                    while (parentBone != null && !parentBone.EditorState().ChildrenExpanded)
                    {
                        SetProperty.Perform(parentBone.EditorState(), nameof(NodeEditorState.ChildrenExpanded), true);
                        bone = nodes.GetBone(bone.BaseIndex);
                    }
                } catch (InvalidOperationException e) {
                    AlertDialog.Show(e.Message);
                    return(false);
                }
                return(true);
            }