Inheritance: MonoBehaviour
Exemplo n.º 1
0
        public void RestoreSort()
        {
            var compound = new NbtCompound
            {
                new NbtLong("ccc", 3),
                new NbtShort("aaa", 3),
                new NbtCompound("bbb")
                {
                    new NbtInt("ccc", 3),
                    new NbtInt("bbb", 3),
                    new NbtInt("aaa", 3),
                }
            };
            var            original = (NbtCompound)compound.Clone();
            UndoableAction action   = null;

            compound.ActionPerformed += a => action = a;

            compound.Sort(new AlphabeticalSorter(), true);

            Assert.AreEqual(compound[0].Name, "aaa");
            Assert.AreEqual(compound[1].Name, "bbb");
            Assert.AreEqual(compound[2].Name, "ccc");
            Assert.AreEqual(compound["bbb"][0].Name, "aaa");
            Assert.AreEqual(compound["bbb"][1].Name, "bbb");
            Assert.AreEqual(compound["bbb"][2].Name, "ccc");

            action.Undo();

            AssertIdentical(compound, original);
        }
Exemplo n.º 2
0
    public void RegisterUndoableAction(UndoableAction act)
    {
        undoStack.Push(act);
        ClearRedoStack();

        UpdateButtonsInteractability();
    }
Exemplo n.º 3
0
 private void addToUndo(UndoableAction c)
 {
     _undoCommands.Push(c);
     if (_undoCommands.Count == 1)
     {
         OnPropertyChanged("CanUndo");
     }
 }
Exemplo n.º 4
0
            /// <inheritdoc/>
            public override bool TryMerge(DocumentEditorContext context, UndoableAction action)
            {
                if (action is InsertTextUndoableAction)
                {
                    return(TryMergeWith(context, (InsertTextUndoableAction)action));
                }
                else if (action is DeleteNextCharacterCommand.DeleteNextCharacterAction)
                {
                    return(TryMergeWith(context, (DeleteNextCharacterCommand.DeleteNextCharacterAction)action));
                }
                else if (action is DeletePreviousCharacterCommand.DeletePreviousCharacterAction)
                {
                    return(TryMergeWith(context, (DeletePreviousCharacterCommand.DeletePreviousCharacterAction)action));
                }

                return(false);
            }
Exemplo n.º 5
0
 public static void Execute(UndoableAction cmd)
 {
     cmd.Execute();
     Instance.addToUndo(cmd);
 }
Exemplo n.º 6
0
    public void RemoveClicked()
    {
        string oldObjName = SelectedKitchenObject.gameObject.name;
        int oldObjID = SelectedKitchenObject.ID;
        Vector3 oldPosition = SelectedKitchenObject.transform.position;
        Quaternion oldRotation = SelectedKitchenObject.transform.rotation;
        UndoableAction act = new UndoableAction(
            delegate
            {
                KitchenObject obj = Instantiate(kitchenObjectPrefabs.First(x => oldObjName.StartsWith(x.gameObject.name)));
                obj.Init(oldObjID);
                obj.gameObject.SetActive(true);
                obj.transform.position = oldPosition;
                obj.transform.rotation = oldRotation;
            },
            delegate
            {
                KitchenObject oldObj = GetObject(oldObjID);
                if (SelectedKitchenObject == oldObj)
                    SelectNewObject(null);
                Destroy(oldObj.gameObject);
            });
        UndoManager.Instance.RegisterUndoableAction(act);

        Destroy(SelectedKitchenObject.gameObject);
        SelectedKitchenObject = null;
    }
Exemplo n.º 7
0
    void ReplaceSelectedKitchenObject(KitchenObject newObj)
    {
        if (SelectedKitchenObject == null)
            return;
        if (SelectedKitchenObject.isCornerObject != newObj.isCornerObject)
        {
            Debug.Log("Corner objects can only be replaced with another corner objects");
            return;
        }
        if(SelectedKitchenObject.mustLayOnGround != newObj.mustLayOnGround)
        {
            Debug.Log("Cant replace these objects");
            return;
        }

        List<ObjectState> oldState = allKitchenObjects.Select(x => new ObjectState(x)).ToList();

        KitchenObject newObjInstance = Instantiate(newObj, new Vector3(-100, -100, -100), Quaternion.identity) as KitchenObject;
        if(newObjInstance.TryPlace(SelectedKitchenObject.transform.position, SelectedKitchenObject.transform.right))
        {
            Debug.Log("DestroyA");

            List<ObjectState> newState = allKitchenObjects.Where(z => z.ID != SelectedKitchenObject.ID).Select(x => new ObjectState(x)).ToList();

            newObjInstance.Init();
            int newObjID = newObjInstance.ID;
            int oldObjID = SelectedKitchenObject.ID;
            string oldObjName = SelectedKitchenObject.gameObject.name;
            string newObjName = newObjInstance.gameObject.name;
            Vector3 oldObjPosition = SelectedKitchenObject.transform.position;
            Quaternion oldObjRotation = SelectedKitchenObject.transform.rotation;
            Vector3 newObjPosition = newObjInstance.transform.position;
            Quaternion newObjRotation = newObjInstance.transform.rotation;
            UndoableAction act = new UndoableAction(
                delegate
                {
                    KitchenObject oldObj = GetObject(newObjID);
                    Destroy(oldObj.gameObject);
                    KitchenObject obj = Instantiate(kitchenObjectPrefabs.First(x => oldObjName.StartsWith(x.gameObject.name)).gameObject).GetComponent<KitchenObject>();
                    obj.Init(oldObjID);
                    obj.transform.position = oldObjPosition;
                    obj.transform.rotation = oldObjRotation;
                    obj.gameObject.SetActive(true);

                    Helper.WaitOneFrame(
                        delegate
                        {
                            foreach (var state in oldState)
                            {
                                state.Reset();
                            }
                        });

                    SelectNewObject(null);
                },
                delegate
                {
                    KitchenObject oldObj = GetObject(oldObjID);
                    Destroy(oldObj.gameObject);
                    KitchenObject obj = Instantiate(kitchenObjectPrefabs.First(x =>newObjName.StartsWith(x.gameObject.name)).gameObject).GetComponent<KitchenObject>();
                    obj.Init(newObjID);
                    obj.transform.position = newObjPosition;
                    obj.transform.rotation = newObjRotation;
                    obj.gameObject.SetActive(true);

                    Helper.WaitOneFrame(
                        delegate
                        {
                            foreach (var state in newState)
                            {
                                state.Reset();
                            }
                        });
                    SelectNewObject(null);
                });
            UndoManager.Instance.RegisterUndoableAction(act);

            Destroy(SelectedKitchenObject.gameObject);
            newObjInstance.gameObject.SetActive(true);
        }
        else
        {
            Debug.Log("DestroyB");
            Destroy(newObjInstance.gameObject);
        }

        SelectedKitchenObject = null;
    }
Exemplo n.º 8
0
    IEnumerator MoveObject(KitchenObject obj)
    {
        SelectNewObject(null);
        isMovingObject = true;
        SetButtonEnabled(false, 0);
        SetButtonEnabled(false, 1);
        SetButtonEnabled(false, 2);
        SetButtonEnabled(false, 3);
        SetButtonEnabled(false, 4);

        obj.gameObject.layer = Physics.IgnoreRaycastLayer;
        LayerMask layer = obj.mustLayOnGround == true ? LayerMask.GetMask("Floor") : LayerMask.GetMask("Walls");
        layer = LayerMask.GetMask("Floor", "Walls");
        LayerMask wallsMask = LayerMask.GetMask("Walls", "KitchenObjects");
        Vector3 oldPos = obj.transform.position;
        Quaternion oldRot = obj.transform.rotation;
        bool wasMoved = false;

        while (true)
        {
            wasMoved = true;
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                wasMoved = false;
                obj.transform.position = oldPos;
                obj.transform.rotation = oldRot;
                break;
            }

            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (!(Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("KitchenObjectsSelect")) && hit.transform != obj.transform) && Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
            {
                obj.gameObject.SetActive(true);
                if (obj.mustLayOnGround)
                {
                    PlaceObjectOnGround(hit, obj, 1.5f, wallsMask);
                }
                else
                {
                    PlaceObjectOnWall(hit, obj, 1.5f, wallsMask);
                }

            }
            else
            {
                obj.transform.position = new Vector3(0, 0, -1000);
                //obj.gameObject.SetActive(false);
                yield return null;
                continue;
            }

            if (Input.GetMouseButtonDown(0) && !obj.transform.GetChild(0).GetComponent<ColliderManager>().IsColliding)
            {
                break;
            }

            yield return null;
        }

        if (wasMoved)
        {
            Vector3 newPosition = obj.transform.position;
            Quaternion newRotation = obj.transform.rotation;
            int objID = obj.ID;

            UndoableAction act = new UndoableAction(
                delegate
                {
                    KitchenObject oldObj = GetObject(objID);
                    oldObj.transform.rotation = oldRot;
                    oldObj.transform.position = oldPos;
                },
                delegate
                {
                    KitchenObject oldObj = GetObject(objID);
                    oldObj.transform.rotation = newRotation;
                    oldObj.transform.position = newPosition;
                });
            UndoManager.Instance.RegisterUndoableAction(act);
        }

        obj.gameObject.layer = LayerMask.NameToLayer("KitchenObjects");

        isMovingObject = false;
        SelectNewObject(obj.transform);
        SetButtonEnabled(true, 0);
        SetButtonEnabled(true, 1);
        SetButtonEnabled(true, 2);
        SetButtonEnabled(true, 3);
        SetButtonEnabled(true, 4);
    }
Exemplo n.º 9
0
    IEnumerator AddKitchenObject(KitchenObject obj)
    {
        SelectNewObject(null);
        KitchenObject objInstance = Instantiate<KitchenObject>(obj);
        objInstance.gameObject.layer = Physics.IgnoreRaycastLayer;
        isAddingObject = true;
        LayerMask layer = objInstance.mustLayOnGround == true ? LayerMask.GetMask("Floor") : LayerMask.GetMask("Walls");
        layer = LayerMask.GetMask("Floor", "Walls");
        LayerMask wallsMask = LayerMask.GetMask("Walls", "KitchenObjects");
        SetButtonEnabled(false, 0);
        SetButtonEnabled(false, 1);
        SetButtonEnabled(false, 2);
        SetButtonEnabled(false, 3);
        SetButtonEnabled(false, 4);

        while(true)
        {
            if(Input.GetKeyDown(KeyCode.Escape))
            {
                Destroy(objInstance.gameObject);
                SelectNewObject(null);
                yield break;
            }

            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if(!(Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("KitchenObjectsSelect")) && hit.transform != objInstance.transform) && Physics.Raycast(ray, out hit, Mathf.Infinity, layer))
            {
                objInstance.gameObject.SetActive(true);
                if(objInstance.mustLayOnGround)
                {
                    PlaceObjectOnGround(hit, objInstance, 1.5f, wallsMask);
                }
                else
                {
                    PlaceObjectOnWall(hit, objInstance, 1.5f, wallsMask);
                }

            }
            else
            {
                objInstance.transform.position = new Vector3(0, 0, -1000);
                //obj.gameObject.SetActive(false);
                yield return null;
                continue;
            }

            if(Input.GetMouseButtonDown(0) && objInstance.gameObject.activeSelf && !objInstance.transform.GetChild(0).GetComponent<ColliderManager>().IsColliding)
            {
                break;
            }

            yield return null;
        }
        objInstance.Init();
        int objID = objInstance.ID;
        string objName = objInstance.name;
        Vector3 objPosition = objInstance.transform.position;
        Quaternion objRotation = objInstance.transform.rotation;

        UndoableAction act = new UndoableAction(
            delegate
            {
                Destroy(GetObject(objID).gameObject);
                SelectNewObject(null);
            },
            delegate
            {
                KitchenObject newObj = Instantiate(kitchenObjectPrefabs.First(x => objName.StartsWith(x.gameObject.name)));
                newObj.Init(objID);
                newObj.transform.position = objPosition;
                newObj.transform.rotation = objRotation;
                newObj.gameObject.SetActive(true);
                SelectNewObject(null);
            });
        UndoManager.Instance.RegisterUndoableAction(act);

        objInstance.gameObject.layer = LayerMask.NameToLayer("KitchenObjects");
        isAddingObject = false;
        SelectNewObject(objInstance.transform);
        SetButtonEnabled(true, 0);
        SetButtonEnabled(true, 1);
        SetButtonEnabled(true, 2);
        SetButtonEnabled(true, 3);
        SetButtonEnabled(true, 4);
    }
Exemplo n.º 10
0
    public void ResizeConfirmed()
    {
        InputField xInput = resizePanel.transform.GetChild(2).GetComponent<InputField>();
        InputField zInput = resizePanel.transform.GetChild(3).GetComponent<InputField>();

        Vector3 newSize = SelectedKitchenObject.Size;
        if(!string.IsNullOrEmpty(xInput.text))
        {
            newSize.x = float.Parse(xInput.text);
        }
        if (!string.IsNullOrEmpty(zInput.text))
        {
            newSize.z = float.Parse(zInput.text);
        }

        if (newSize != SelectedKitchenObject.Size)
        {
            Vector3 oldSize = SelectedKitchenObject.Size;
            int objID = SelectedKitchenObject.ID;
            List<ObjectState> oldState = allKitchenObjects.Select(x => new ObjectState(x)).ToList();
            SelectedKitchenObject.Size = newSize;
            List<ObjectState> newState = allKitchenObjects.Select(x => new ObjectState(x)).ToList();
            UndoableAction act = new UndoableAction(
                delegate
                {
                    KitchenObject obj = GetObject(objID);
                    obj.Size = oldSize;

                    foreach(var state in oldState)
                    {
                        state.Reset();
                    }
                },
                delegate
                {
                    KitchenObject obj = GetObject(objID);
                    obj.Size = newSize;

                    foreach (var state in newState)
                    {
                        state.Reset();
                    }
                });
            UndoManager.Instance.RegisterUndoableAction(act);
        }
    }
Exemplo n.º 11
0
 private void RootTag_ActionPerformed(UndoableAction action)
 {
     NoticeAction(action);
 }
Exemplo n.º 12
0
 public void Do(UndoableAction undoableAction)
 {
     Action = undoableAction;
 }
Exemplo n.º 13
0
 private void Region_ActionPerformed(UndoableAction action)
 {
     NoticeAction(action);
 }
Exemplo n.º 14
0
 private void Data_ActionPerformed(UndoableAction action)
 {
     NoticeAction(action);
 }
Exemplo n.º 15
0
 // save an undoable action to the model
 protected void NoticeAction(UndoableAction action)
 {
     Tree.UndoHistory.SaveAction(action);
 }