public void GoToAction(BIWCompleteAction action)
    {
        int index       = actionsMade.IndexOf(action);
        int stepsAmount = currentUndoStepIndex - index;

        for (int i = 0; i <= Mathf.Abs(stepsAmount); i++)
        {
            if (stepsAmount > 0)
            {
                UndoCurrentAction();
                if (currentUndoStepIndex > 0)
                {
                    currentUndoStepIndex--;
                }
            }
            else
            {
                RedoCurrentAction();
                if (currentUndoStepIndex + 1 < actionsMade.Count)
                {
                    currentUndoStepIndex++;
                }
            }
        }
    }
Ejemplo n.º 2
0
    public void SetContent(BIWCompleteAction action)
    {
        this.action = action;

        switch (this.action.actionType)
        {
        case BIWCompleteAction.ActionType.MOVE:
            actionImg.sprite = moveSprite;
            break;

        case BIWCompleteAction.ActionType.ROTATE:
            actionImg.sprite = rotateSprite;
            break;

        case BIWCompleteAction.ActionType.SCALE:
            actionImg.sprite = scaleSprite;
            break;

        case BIWCompleteAction.ActionType.CREATE:
            actionImg.sprite = createdSprite;
            break;

        default:
            actionImg.enabled = false;
            break;
        }

        actionTitle.text = this.action.actionType.ToString().Replace("_", " ");
        RefreshIsDone();
    }
    public void DuplicateSelectedEntities()
    {
        BIWCompleteAction buildAction = new BIWCompleteAction();

        buildAction.actionType = BIWCompleteAction.ActionType.CREATE;

        List <BIWEntityAction> entityActionList    = new List <BIWEntityAction>();
        List <BIWEntity>       entitiesToDuplicate = new List <BIWEntity>(selectedEntities);

        DeselectEntities();

        foreach (BIWEntity entityToDuplicate in entitiesToDuplicate)
        {
            if (entityToDuplicate.isNFT)
            {
                continue;
            }

            var             entityDuplicated = DuplicateEntity(entityToDuplicate);
            BIWEntityAction biwEntityAction  = new BIWEntityAction(entityDuplicated.rootEntity, entityDuplicated.rootEntity.entityId, BIWUtils.ConvertEntityToJSON(entityDuplicated.rootEntity));
            entityActionList.Add(biwEntityAction);
            SelectEntity(entityDuplicated);
        }

        currentActiveMode?.SetDuplicationOffset(DUPLICATE_OFFSET);

        buildAction.CreateActionType(entityActionList, BIWCompleteAction.ActionType.CREATE);
        actionController.AddAction(buildAction);
    }
    public void CreateActionEntityCreated(IDCLEntity entity)
    {
        BIWEntityAction biwEntityAction = new BIWEntityAction(entity, entity.entityId, BIWUtils.ConvertEntityToJSON(entity));

        BIWCompleteAction buildAction = new BIWCompleteAction();

        buildAction.CreateActionType(biwEntityAction, ActionType.CREATE);

        AddAction(buildAction);
    }
Ejemplo n.º 5
0
    protected void ActionFinish(BIWCompleteAction.ActionType type)
    {
        if (actionList.Count > 0 && selectedEntities.Count > 0)
        {
            BIWCompleteAction buildModeAction = new BIWCompleteAction();

            buildModeAction.actionType = type;
            buildModeAction.CreateActionType(actionList, type);
            OnActionGenerated?.Invoke(buildModeAction);

            actionList = new List <BIWEntityAction>();
        }
    }
    public void UndoRedoChangeFloorAction()
    {
        BIWCatalogManager.Init();

        BIWTestHelper.CreateTestCatalogLocalMultipleFloorObjects();

        CatalogItem       oldFloor        = DataStore.i.dataStoreBuilderInWorld.catalogItemDict.GetValues()[0];
        CatalogItem       newFloor        = DataStore.i.dataStoreBuilderInWorld.catalogItemDict.GetValues()[1];
        BIWCompleteAction buildModeAction = new BIWCompleteAction();

        biwCreatorController.EnterEditMode(scene);
        biwFloorHandler.EnterEditMode(scene);

        biwFloorHandler.CreateFloor(oldFloor);
        biwFloorHandler.ChangeFloor(newFloor);

        buildModeAction.CreateChangeFloorAction(oldFloor, newFloor);
        biwActionController.AddAction(buildModeAction);

        foreach (BIWEntity entity in entityHandler.GetAllEntitiesFromCurrentScene())
        {
            if (entity.isFloor)
            {
                Assert.AreEqual(entity.GetCatalogItemAssociated().id, newFloor.id);
                break;
            }
        }

        biwActionController.TryToUndoAction();

        foreach (BIWEntity entity in entityHandler.GetAllEntitiesFromCurrentScene())
        {
            if (entity.isFloor)
            {
                Assert.AreEqual(entity.GetCatalogItemAssociated().id, oldFloor.id);

                break;
            }
        }

        biwActionController.TryToRedoAction();

        foreach (BIWEntity entity in entityHandler.GetAllEntitiesFromCurrentScene())
        {
            if (entity.isFloor)
            {
                Assert.AreEqual(entity.GetCatalogItemAssociated().id, newFloor.id);
                break;
            }
        }
    }
    public void CreateActionEntityDeleted(List <BIWEntity> entityList)
    {
        BIWCompleteAction      buildAction      = new BIWCompleteAction();
        List <BIWEntityAction> entityActionList = new List <BIWEntityAction>();

        foreach (BIWEntity entity in entityList)
        {
            BIWEntityAction biwEntityAction = new BIWEntityAction(entity.rootEntity.entityId, BIWUtils.ConvertEntityToJSON(entity.rootEntity), entity.rootEntity.entityId);
            entityActionList.Add(biwEntityAction);
        }

        buildAction.CreateActionType(entityActionList, BIWCompleteAction.ActionType.DELETE);

        AddAction(buildAction);
    }
Ejemplo n.º 8
0
    public void ChangeFloor(CatalogItem newFloorObject)
    {
        saveController.SetSaveActivation(false);
        CatalogItem lastFloor = lastFloorCalalogItemUsed;

        if (lastFloor == null)
        {
            lastFloor = FindCurrentFloorCatalogItem();
        }

        entityHandler.DeleteFloorEntities();

        CreateFloor(newFloorObject);

        BIWCompleteAction buildAction = new BIWCompleteAction();

        buildAction.CreateChangeFloorAction(lastFloor, newFloorObject);
        actionController.AddAction(buildAction);

        saveController.SetSaveActivation(true, true);
    }
    public void UndoRedoScaleAction()
    {
        BIWCompleteAction buildModeAction = new BIWCompleteAction();

        Vector3 oldScale = scene.entities[ENTITY_ID].gameObject.transform.localScale;
        Vector3 newScale = new Vector3(5, 5, 5);

        BIWEntityAction entityAction = new BIWEntityAction(ENTITY_ID);

        entityAction.oldValue = oldScale;
        entityAction.newValue = newScale;

        buildModeAction.CreateActionType(entityAction, BIWCompleteAction.ActionType.SCALE);

        scene.entities[ENTITY_ID].gameObject.transform.localScale = newScale;
        biwActionController.AddAction(buildModeAction);

        biwActionController.TryToUndoAction();
        Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.localScale == oldScale);

        biwActionController.TryToRedoAction();
        Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.localScale == newScale);
    }
Ejemplo n.º 10
0
    public void UndoRedoRotateAction()
    {
        BIWCompleteAction buildModeAction = new BIWCompleteAction();

        Vector3 oldRotation = scene.entities[ENTITY_ID].gameObject.transform.rotation.eulerAngles;
        Vector3 newRotation = new Vector3(5, 5, 5);

        BIWEntityAction entityAction = new BIWEntityAction(ENTITY_ID);

        entityAction.oldValue = oldRotation;
        entityAction.newValue = newRotation;

        buildModeAction.CreateActionType(entityAction, BIWCompleteAction.ActionType.ROTATE);

        scene.entities[ENTITY_ID].gameObject.transform.rotation = Quaternion.Euler(newRotation);
        biwActionController.AddAction(buildModeAction);

        biwActionController.TryToUndoAction();
        Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.rotation.eulerAngles == oldRotation);

        biwActionController.TryToRedoAction();
        Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.rotation.eulerAngles == newRotation);
    }
Ejemplo n.º 11
0
    public void UndoRedoMoveAction()
    {
        BIWCompleteAction buildModeAction = new BIWCompleteAction();

        Vector3 oldPosition = scene.entities[ENTITY_ID].gameObject.transform.position;
        Vector3 newPosition = new Vector3(5, 5, 5);

        BIWEntityAction entityAction = new BIWEntityAction(ENTITY_ID);

        entityAction.oldValue = oldPosition;
        entityAction.newValue = newPosition;

        buildModeAction.CreateActionType(entityAction, BIWCompleteAction.ActionType.MOVE);

        scene.entities[ENTITY_ID].gameObject.transform.position = newPosition;
        biwActionController.AddAction(buildModeAction);

        biwActionController.TryToUndoAction();
        Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.position == oldPosition);

        biwActionController.TryToRedoAction();
        Assert.IsTrue(scene.entities[ENTITY_ID].gameObject.transform.position == newPosition);
    }
    public void AddAction(BIWCompleteAction action)
    {
        if (currentRedoStepIndex < actionsMade.Count - 1)
        {
            actionsMade.RemoveRange(currentRedoStepIndex, actionsMade.Count - currentRedoStepIndex);
        }
        else if (actionsMade.Count > 0 && !actionsMade[currentRedoStepIndex].isDone)
        {
            actionsMade.RemoveAt(actionsMade.Count - 1);
        }

        actionsMade.Add(action);

        currentUndoStepIndex = actionsMade.Count - 1;
        currentRedoStepIndex = actionsMade.Count - 1;


        if (VERBOSE)
        {
            Debug.Log("Redo:  Current actions " + actionsMade.Count + "   Current undo index " + currentUndoStepIndex + "   Current redo index " + currentRedoStepIndex);
        }
        action.OnApplyValue += ApplyAction;
        CheckButtonsInteractability();
    }
Ejemplo n.º 13
0
    private void MouseUp(int buttonID, Vector3 position)
    {
        if (!mousePressed || buttonID != 0)
        {
            return;
        }

        if (isCreatingMultipleVoxels)
        {
            lastVoxelCreated.rootEntity.transform.SetParent(null);
            bool canVoxelsBeCreated = true;

            foreach (VoxelPrefab voxel in createdVoxels.Values)
            {
                if (!voxel.IsAvailable())
                {
                    canVoxelsBeCreated = false;
                    break;
                }
            }

            BIWCompleteAction buildAction = new BIWCompleteAction();
            buildAction.actionType = BIWCompleteAction.ActionType.CREATE;

            List <BIWEntityAction> entityActionList = new List <BIWEntityAction>();

            foreach (Vector3Int voxelPosition in createdVoxels.Keys)
            {
                if (canVoxelsBeCreated)
                {
                    IDCLEntity entity = biwEntityHandler.DuplicateEntity(lastVoxelCreated).rootEntity;
                    entity.gameObject.tag = BIWSettings.VOXEL_TAG;
                    entity.gameObject.transform.position = voxelPosition;

                    BIWEntityAction biwEntityAction = new BIWEntityAction(entity, entity.entityId, BIWUtils.ConvertEntityToJSON(entity));
                    entityActionList.Add(biwEntityAction);
                }

                GameObject.Destroy(createdVoxels[voxelPosition].gameObject);
            }

            if (!canVoxelsBeCreated)
            {
                biwEntityHandler.DeleteEntity(lastVoxelCreated);
            }
            else
            {
                buildAction.CreateActionType(entityActionList, BIWCompleteAction.ActionType.CREATE);
                biwActionController.AddAction(buildAction);
            }

            createdVoxels.Clear();
            biwEntityHandler.DeselectEntities();

            lastVoxelCreated         = null;
            isCreatingMultipleVoxels = false;

            mousePressed = false;
            freeCameraMovement.SetCameraCanMove(true);
        }
    }