public override void OnMouseDown()
    {
        bool potionExecuted = LevelData.isPotionExecuted(new PotionPathIndexPair(this.gameObject.name, LevelData.getCurrentActivePath()));

        Debug.Log("executed? : " + potionExecuted);
        if (ExecutePathSelectScript.PotionIsOnCurrentPath(this.gameObject) && !potionExecuted)
        {
            // if the potion being clicked on is on the selected control flow path

            int tempCurrentMana;
            if (hasBreakpoint)
            {
                // plus one because player is trying to clear brkpt on THIS object
                tempCurrentMana = LevelData.getCurrentMana() - GetAllBreakpoints() + 1;
            }
            else
            {
                // minus one extra because player is trying to set brkpt on THIS object
                tempCurrentMana = LevelData.getCurrentMana() - GetAllBreakpoints() - 1;
            }

            // potion not executed but enough mana
            if ((tempCurrentMana >= 0))
            {
                hasBreakpoint = !hasBreakpoint;
                breakpointText.SetActive(hasBreakpoint);
                Button runOneStepBtn = GameObject.Find("RunStepBtn").GetComponent <Button> ();
                runOneStepBtn.interactable = (GetAllBreakpoints() != 0);
                if (!runOneStepBtn.interactable)
                {
                    ExecutePathSelectScript.ClearPotionStepCount();
                }
            }
            else
            {
                // potion not executed but not enough mana
                dialogue.SetActive(true);
            }
        }        // potion executed
        else if (potionExecuted)
        {
            ShowFormula(LevelData.getCurrentActivePath());
        }
        // show warning diaglogue if the potion selected in not on the current control flow path NOR executed
        else
        {
            dialogue.SetActive(true);
            foreach (Transform child in dialogue.transform)
            {
                if (child.gameObject.name.Equals("ManaWarning"))
                {
                    child.gameObject.SetActive(false);
                }
                else if (child.gameObject.name.Equals("PathWarning"))
                {
                    child.gameObject.SetActive(true);
                }
            }
        }
    }
Example #2
0
 private void ToggleActiveFlagOnOtherInputs()
 {
     foreach (GameObject otherInput in otherNeighbourInputs)
     {
         ExecutePathSelectScript epss = otherInput.GetComponent <ExecutePathSelectScript> ();
         epss.isActive = false;
     }
 }
Example #3
0
    public void OnMouseDown()
    {
        // set this input to be active, and other neighbour inputs as inactive
        isActive = true;
        ToggleActiveFlagOnOtherInputs();

        currentPathIndex = CalculateCurrentPathIndex();
        int index = pathIndex.IndexOf(currentPathIndex);

        currentPathObjects = pathObjects [index].list;
        //===================================================

        // update current active path
        LevelData.setCurrentActivePath(currentPathIndex);

        // change input opacity
        foreach (GameObject otherInput in otherNeighbourInputs)
        {
            otherInput.GetComponent <SpriteRenderer> ().color = new Color(1f, 1f, 1f, .4f);
        }

        this.gameObject.GetComponent <SpriteRenderer> ().color = new Color(1f, 1f, 1f, 1f);

        // un-highlight other control flow path
        foreach (GameObject otherInput in otherNeighbourInputs)
        {
            ExecutePathSelectScript         epss             = otherInput.GetComponent <ExecutePathSelectScript> ();
            List <PotionScript.ListWrapper> otherPathObjects = epss.pathObjects;
            foreach (PotionScript.ListWrapper otherPathObject in otherPathObjects)
            {
                ChangePipeColour(otherPathObject.list, new Color(1f, 1f, 1f, 1f));                 // white
            }
        }

        // highlight control flow path
        ChangePipeColour(currentPathObjects, new Color(1f, 1f, 0f, 1f));         // yellow

        //=======================================================================================

        // clear step count whenever a new path is selected
        potionStepCount = 0;
        ToggleBreakpointAndColliderOnPotions();

        // set RunStepBtn with THIS gameObject
        runOneStepBtn.onClick.RemoveAllListeners();
        runOneStepBtn.onClick.AddListener(RunOneStep);
        runOneStepBtn.interactable = false;         // initialise to false because player cannot run until at least a breakpoint is set

        //=======================================================================================
        previousOutputs.Clear();
        AddActiveIOToPreviousOutputs();
    }
Example #4
0
    private int CalculateCurrentPathIndex()
    {
        List <int> tempPathIndex = pathIndex;

        foreach (GameObject otherInput in otherInputs)
        {
            ExecutePathSelectScript epss = otherInput.GetComponent <ExecutePathSelectScript> ();
            if (epss.isActive)
            {
                return(FindIntersection(epss.pathIndex, pathIndex));
            }
        }
        // if no other input is active - there should be one element in pathIndex
        return(tempPathIndex[0]);
    }
Example #5
0
    private void AddActiveIOToPreviousOutputs()
    {
        GameObject[]  initialIO = GameObject.FindGameObjectsWithTag("IO");
        List <Sprite> sprites   = new List <Sprite> ();

        foreach (GameObject gb in initialIO)
        {
            ExecutePathSelectScript epss = gb.GetComponent <ExecutePathSelectScript> ();

            if (epss == null || epss.isActive)
            {
                Sprite sprite = gb.GetComponent <SpriteRenderer> ().sprite;
                //Debug.Log ("add sprite : " + sprite.name + " object name ; " + gb.name);
                sprites.Add(sprite);
            }
        }
        previousOutputs.Add(sprites);
    }