Exemple #1
0
 protected override bool IsValid(string path)
 {
     return(TangerineDefaultCharsetAttribute.IsValid(path, out var message) == ValidationResult.Ok);
 }
Exemple #2
0
        private void RenameAnimation()
        {
            var index     = GetSelectedAnimationIndex();
            var animation = GetAnimations()[index];
            var item      = (Widget)scrollView.Content.Nodes[index];
            var label     = item["Label"];

            label.Visible = false;
            var editor = new ThemedEditBox();

            label.Parent.Nodes.Insert(label.CollectionIndex(), editor);
            editor.Text = animation.Id;
            editor.SetFocus();
            editor.AddChangeWatcher(() => editor.IsFocused(), focused => {
                if (!focused)
                {
                    var newId = editor.Text.Trim();
                    if (!animation.Owner.Animations.Any(a => a.Id == newId))
                    {
                        RenameAnimationHelper(newId);
                    }
                    editor.Unlink();
                    label.Visible = true;
                }
            });
            editor.Submitted += s => {
                RenameAnimationHelper(s.Trim());
                editor.Unlink();
                label.Visible = true;
            };

            void RenameAnimationHelper(string newId)
            {
                string error = null;

                if (animation.IsLegacy)
                {
                    error = "Can't rename legacy animation";
                }
                else if (animation.Id == Animation.ZeroPoseId)
                {
                    error = "Can't rename zero pose animation";
                }
                else if (newId.IsNullOrWhiteSpace() || newId == Animation.ZeroPoseId)
                {
                    error = "Invalid animation id";
                }
                else if (TangerineDefaultCharsetAttribute.IsValid(newId, out var message) != ValidationResult.Ok)
                {
                    error = message;
                }
                else if (animation.Owner.Animations.Any(a => a.Id == newId))
                {
                    error = $"An animation '{newId}' already exists";
                }
                if (error != null)
                {
                    UI.AlertDialog.Show(error, "Ok");
                    return;
                }
                Document.Current.History.DoTransaction(() => {
                    var oldId = animation.Id;
                    Core.Operations.SetProperty.Perform(animation, nameof(Animation.Id), newId);
                    foreach (var a in animation.Owner.Animations)
                    {
                        foreach (var track in a.Tracks)
                        {
                            foreach (var animator in track.Animators)
                            {
                                if (animator.AnimationId == oldId)
                                {
                                    Core.Operations.SetProperty.Perform(animator, nameof(IAnimator.AnimationId), newId);
                                }
                            }
                        }
                    }
                    ChangeAnimatorsAnimationId(animation.OwnerNode);

                    void ChangeAnimatorsAnimationId(Node node)
                    {
                        foreach (var child in node.Nodes)
                        {
                            foreach (var animator in child.Animators)
                            {
                                if (animator.AnimationId == oldId)
                                {
                                    Core.Operations.SetProperty.Perform(animator, nameof(IAnimator.AnimationId), newId);
                                }
                            }
                            if (child.ContentsPath != null)
                            {
                                continue;
                            }
                            if (child.Animations.Any(i => i.Id == oldId))
                            {
                                continue;
                            }
                            ChangeAnimatorsAnimationId(child);
                        }
                    }
                });
            }
        }