예제 #1
0
    // Toggle between the flowchart editor and the Python code viewer.
    void SwitchMode(EditorMode mode)
    {
        if (mode == EditorMode.FlowChart)
        {
            elementContainer.SetActive(true);
            generatedCodeContainer.SetActive(false);
            editorMode = mode;
        }
        else
        {
            if (editorMode == EditorMode.FlowChart)
            {
                choosingNode         = false;
                choosingFunctionCall = false;

                linkingNodes           = false;
                linkingNodesObjects[0] = linkingNodesObjects[1] = null;
                // Delete the linking preview line
                if (linkingPreviewLine != null)
                {
                    Destroy(linkingPreviewLine);
                }

                clueHud.SetCurrentPrompt(null, null);
            }

            if (!string.IsNullOrWhiteSpace(programStart.Serialize()))
            {
                elementContainer.SetActive(false);
                generatedCodeContainer.SetActive(true);
                generatedCodeText.text = programStart.Serialize();
                editorMode             = mode;
            }
        }
    }
예제 #2
0
    protected override void Update()
    {
        base.Update();

        if (clueHud.currentPromptCaller != null && clueHud.currentPromptCaller.GetComponent <EditorDraggableNode>() && !clueHud.currentPromptCaller.GetComponent <EditorDraggableNode>().enabled)
        {
            clueHud.SetCurrentPrompt(null, null);
        }
    }
예제 #3
0
    public void DispatchEditingProperty(System.Action <string> finishedCallback, string initValue)
    {
        owner.editedNodeValue = owner.editingNodeValue = initValue;

        Vector3[] corners = { Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero };

        // Get screen-space rectangle of the node
        rectTransform.GetWorldCorners(corners);
        Rect nodeRect = new Rect(corners[0], corners[2] - corners[0]);

        owner.editingNodeInPlaceRect = nodeRect;
        owner.editingNodeInPlace     = true;
        owner.editingNodeFinishedClb = finishedCallback;
        owner.editingNodeProperty    = true;

        clueHud.SetCurrentPrompt(clueHud.EditingParamHoveredPrompt, gameObject);
    }
    // Update is called once per frame
    void Update()
    {
        SymbolNames  = new List <string>(symbolTable.Keys);
        SymbolValues = new List <string>(symbolTable.Values.Select(v => v.Value));

        timeSinceTick += Time.deltaTime;
        if (currentNode == program.programStart && currentNode.NextNodeObject != null)
        {
            if (programRunning)
            {
                outputBuffer = "";
                currentNode  = (NodeBase)currentNode.nextNode;
            }
            timeSinceTick = tickTime; // Skip the ProgramStart tick
            InitSymTable();
            // TODO: this doesn't actually reset the buffer?
        }
        if (programRunning)
        {
            processingDoneLastFrame = processingDone;
            ExecuteFrame();
            // Has processing finished this frame? If yes, wait for next tick.
            if (!processingDoneLastFrame && processingDone)
            {
                waitForNextTick = true;
            }
        }

        // Before doing key detection, first check if the user isn't inputting anything in the editor
        if (!editorUi.GetComponent <EditorProgram>().editingNodeProperty)
        {
            if (DistanceCheck())
            {
                // Show controls on HUD
                if (clueHud.currentPromptSet == null)
                {
                    clueHud.SetCurrentPrompt(clueHud.FPPTerminalPrompts, gameObject);
                }

                if (Input.GetKeyUp(KeyCode.E))
                {
                    program.EditorActive = !program.EditorActive;
                }
                if (Input.GetKeyUp(KeyCode.Space) && !programRunning)
                {
                    processingDone = true;
                    programRunning = true;
                    currentNode    = program.programStart;

                    editorUi.GetComponent <EditorProgram>().errorNode = null;

                    // Make sure Start and End are linked if they're the only nodes in the program
                    if (!HasAnyNodes())
                    {
                        program.programStart.NextNodeObject = program.programEnd.gameObject;
                        program.programStart.nextNode       = program.programEnd;

                        program.programEnd.PrevNodeObject = program.programStart.gameObject;
                        program.programEnd.prevNode       = program.programStart;
                    }
                    // Otherwise, check if the End node is linked to by anything.
                    // If not, choose the node that isn't in a loop and doesn't have a nextNode yet.
                    else
                    {
                        if (program.programEnd.PrevNodeObject == null)
                        {
                            NodeBase[] nodes = program.elementContainer.GetComponentsInChildren <NodeBase>();
                            foreach (NodeBase node in nodes)
                            {
                                if (node.ownerLoop == null && node.NextNodeObject == null && node.PrevNodeObject != null)
                                {
                                    node.NextNodeObject = program.programEnd.gameObject;
                                    node.nextNode       = program.programEnd;

                                    program.programEnd.PrevNodeObject = node.gameObject;
                                    program.programEnd.prevNode       = node;

                                    break;
                                }
                            }
                        }
                    }
                }
            }
            // If we're outside the distance, make sure the ClueHUD is updated so it no longer displays the "Open Editor" control clue
            else
            {
                if (clueHud.currentPromptSet == clueHud.FPPTerminalPrompts && clueHud.currentPromptCaller == gameObject)
                {
                    clueHud.SetCurrentPrompt(null, null);
                }
            }
        }

        if (transform.Find("CurrentLine") && editorUi.GetComponent <EditorProgram>().EditorActive)
        {
            transform.Find("CurrentLine").gameObject.SetActive(false);
        }

        if (transform.Find("CurrentLine") && !editorUi.GetComponent <EditorProgram>().EditorActive&& programRunning)
        {
            transform.Find("CurrentLine").gameObject.SetActive(true);
        }

        if (editorUi.GetComponent <EditorProgram>().EditorActive)
        {
            if (clueHud.currentPromptSet == clueHud.FPPTerminalPrompts && clueHud.currentPromptCaller == gameObject)
            {
                clueHud.SetCurrentPrompt(null, null);
            }
        }
    }