private void BreakLink(bool withUndo = true)
    {
        VoosActor actor = currActor;

        // Save for undo
        string prevParent = actor.GetCloneParent();

        SetActorInternal(null);
        actor.SetCloneParent(null);
        actor.MakeOwnCopyOfBrain();

        if (withUndo)
        {
            // Setup undo item
            string actorName = actor.GetName();
            string newBrain  = actor.GetBrainName();
            undo.Push(new UndoStack.Item
            {
                actionLabel         = $"Break copy-link of {actor.GetDisplayName()}",
                getUnableToDoReason = () => ActorUndoUtil.GetUnableToEditActorReason(voosEngine, actorName),
                doIt = () =>
                {
                    var redoActor = voosEngine.GetActor(actorName);
                    redoActor.SetCloneParent(null);
                    // A bit sloppy: We're relying on the fact that brains are never deleted
                    // (except on load).
                    redoActor.SetBrainName(newBrain);
                    OnBreakLinkChanged(redoActor);
                },
                getUnableToUndoReason = () =>
                {
                    var prevParentActor = voosEngine.GetActor(prevParent);
                    if (prevParentActor == null)
                    {
                        return($"The original copy no longer exists.");
                    }
                    return(null);
                },
                undo = () =>
                {
                    var undoActor       = voosEngine.GetActor(actorName);
                    var prevParentActor = voosEngine.GetActor(prevParent);
                    Debug.Assert(prevParent != null, "BreakLink undo action: prevParent does not exist anymore");
                    undoActor.SetCloneParent(prevParent);
                    undoActor.SetBrainName(prevParentActor.GetBrainName());
                    OnBreakLinkChanged(undoActor);
                }
            });
        }

        SetActorInternal(actor);
    }
예제 #2
0
    void EndTextEditing()
    {
        if (IsEditing())
        {
            // Erm, do this first, cuz deactivating stuff could cause this to be
            // called again recursively. Like deactivating the inputFieldObject!
            lastActorEdited  = actorBeingEdited;
            actorBeingEdited = null;

            inputFieldObject.SetActive(false);
            cooldownRoutine = StartCoroutine(CooldownRoutine());
            if (inputField.text == EMPTY_TEXT)
            {
                engine.DestroyActor(lastActorEdited);
            }
            else
            {
                editMain.SetTargetActor(lastActorEdited);
                // editMain.SetFocusedTargetActor(lastActorEdited);

                string undoText = actorTextBeforeEditing;

                if (actorWasJustCreated)
                {
                    var engine    = lastActorEdited.GetEngine();
                    var actorData = engine.SaveActor(lastActorEdited);
                    undoStack.PushUndoForCreatingActor(lastActorEdited, $"Create text panel");
                }
                else
                {
                    string currText = lastActorEdited.GetCommentText();
                    if (ActorUndoUtil.GetUnableToEditActorReason(lastActorEdited.GetEngine(), lastActorEdited.GetName()) == null)
                    {
                        undoStack.PushUndoForActor(
                            lastActorEdited,
                            $"Edit text panel",
                            redoActor =>
                        {
                            redoActor.SetCommentText(currText);
                            redoActor.ApplyPropertiesToClones();
                        },
                            undoActor =>
                        {
                            undoActor.SetCommentText(undoText);
                            undoActor.ApplyPropertiesToClones();
                        });
                    }
                }
            }
        }
    }
예제 #3
0
    public void DeleteTargetActors()
    {
        VoosActor builtin = targetActors.FirstOrDefault(a => a.IsBuiltinActor());

        if (builtin != null)
        {
            popups.Show($"Sorry, built-in actors such as {builtin.GetDisplayName()} cannot be deleted.", "OK");
        }
        var deletableActors = targetActors.Where(a => a != null && !a.IsLockedByAnother() && !a.IsBuiltinActor()).ToList();

        if (deletableActors.Count == 0)
        {
            return;
        }
        var actorStates = engine.SaveActorHierarchy(deletableActors);
        var label       = deletableActors.Count > 1 ? $"Delete {deletableActors.Count} actors" : $"Delete {deletableActors[0].GetDisplayName()}";

        undoStack.Push(new UndoStack.Item
        {
            actionLabel           = label,
            getUnableToDoReason   = () => null,
            getUnableToUndoReason = () => null,
            doIt = () =>
            {
                foreach (var state in actorStates)
                {
                    ActorUndoUtil.GetValidActorThen(
                        engine, state.name,
                        validActor => this.DeleteActor(validActor));
                }
            },
            undo = () => engine.RestoreActorHierarchy(actorStates)
        });

        SetCameraFollowingActor(false);
    }