Ejemplo n.º 1
0
    protected override void Update()
    {
        if (Unit == null || Operation == null)
        {
            return;
        }

        if (underlay.sprite != null)
        {
            float target_image_alpha    = 0;
            float target_underlay_alpha = 1;

            if (this.IsPointedAt())
            {
                target_image_alpha    = 1;
                target_underlay_alpha = 0.1f;
            }

            Image.color = Image.color.AlphaChangedTo(
                Mathf.Lerp(Image.color.a, target_image_alpha, Time.deltaTime * 5));
            underlay.color = underlay.color.AlphaChangedTo(
                Mathf.Lerp(underlay.color.a, target_underlay_alpha, Time.deltaTime * 5));
        }

        description_text.gameObject.SetActive(this.IsPointedAt());

        SelectionOverlay.gameObject.SetActive(IsSelected);

        InputNode.gameObject.SetActive(Operation.TakesInput);
        OutputNode.gameObject.SetActive(Operation.HasOutput);
        GotoNode.gameObject.SetActive(Operation.TakesGoto);


        if (IsInProgramInterface)
        {
            if (InputNode.VariableTile != null)
            {
                Operation.Input.PrimaryVariableName = InputNode.VariableTile.Variable.Name;
            }
            if (OutputNode.VariableTile != null)
            {
                Operation.Output.PrimaryVariableName = OutputNode.VariableTile.Variable.Name;
            }
            if (GotoNode.GotoOperationTile != null)
            {
                Operation.Goto = GotoNode.GotoOperationTile.Operation;
            }
        }
        else if (IsInOperationMenu && IsSelected)
        {
            bool is_complete = false;
            if (operation.TakesGoto)
            {
                is_complete = GotoNode.GotoOperationTile != null;
            }
            else if ((!operation.TakesInput || InputNode.VariableTile != null) &&
                     (!operation.HasOutput || OutputNode.VariableTile != null))
            {
                is_complete = true;
            }

            if (is_complete)
            {
                Operation operation = Operation.Instantiate();
                if (operation.TakesInput && InputNode.VariableTile != null)
                {
                    operation.Input.PrimaryVariableName = InputNode.VariableTile.Variable.Name;
                }
                if (operation.HasOutput && OutputNode.VariableTile != null)
                {
                    operation.Output.PrimaryVariableName = OutputNode.VariableTile.Variable.Name;
                }
                if (operation.TakesGoto && GotoNode.GotoOperationTile != null)
                {
                    operation.Goto = GotoNode.GotoOperationTile.Operation;
                }

                Unit.Program.Add(operation);
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    if (Unit.Program.Next == null)
                    {
                        Unit.Program.Next = operation;
                    }
                }
                else
                {
                    Unit.Program.Next = operation;

                    if (operation is Task)
                    {
                        Unit.Task = null;
                        operation.Execute(Unit);
                    }
                }

                InputNode.VariableName     = null;
                InputNode.IsSelected       = false;
                OutputNode.VariableName    = null;
                OutputNode.IsSelected      = false;
                GotoNode.GotoOperationTile = null;
                GotoNode.IsSelected        = false;
                IsSelected = false;
            }
        }

        if (!InputUtility.DidDragOccur &&
            this.IsPointedAt() &&
            !InputNode.IsPointedAt() && !OutputNode.IsPointedAt() && !GotoNode.IsPointedAt() &&
            this.UseMouseLeftRelease())
        {
            if (IsInOperationMenu)
            {
                IsSelected = true;
            }
            else if (IsInProgramInterface)
            {
                Unit.Program.Next = Operation;
                Operation.Execute(Unit);
            }
        }

        if (InputUtility.WasMouseRightReleased)
        {
            if (IsSelected)
            {
                IsSelected = false;
            }
        }

        if (IsSelected)
        {
            if (Operation.TakesInput && InputNode.VariableTile == null && !Operation.TakesGoto)
            {
                if (!InputNode.IsSelected)
                {
                    InputNode.IsSelected = true;
                }
            }
            else if (Operation.HasOutput && OutputNode.VariableTile == null)
            {
                if (!OutputNode.IsSelected)
                {
                    OutputNode.IsSelected = true;
                }
            }
            else if (Operation.TakesGoto && GotoNode.GotoOperationTile == null)
            {
                if (!GotoNode.IsSelected)
                {
                    GotoNode.IsSelected = true;
                }
            }
        }

        base.Update();
    }