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);
    }
Exemplo n.º 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();
                        });
                    }
                }
            }
        }
    }