void CreateLines(Transform[] points, int id)
    {
        // Creates the graphical strings.
        SpawnerOutput lGraphic = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ButtonWrapper));

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Image>(lGraphic, "Image").rectTransform.pivot = new Vector2(0.5f, 0);
        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Text>(lGraphic, "Text").text = "";

        // Adds event for changing of button colors
        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Button>(lGraphic).onClick.AddListener(() => {
            switch (mMode)
            {
            case MouseMode.EDIT_CONN:
                int[] linkData = abilityData.linkAddresses.l[id];

                if (!LoadedData.GetVariableType(abilityData.subclasses.l[linkData[0]].classType, linkData[1], VariableTypes.PERMENANT_TYPE))
                {
                    linkData[4] = (int)lMode;
                    UpdateLineColor(id);
                    mMode = MouseMode.NONE;
                }
                break;

            case MouseMode.REMOVE_CONN:
                RemoveLine(id);
                mMode = MouseMode.NONE;
                break;
            }
        });

        LineData line = new LineData(points[0], points[1], lGraphic);

        lineData.ModifyElementAt(id, line);
        UpdateLineColor(id);
        UpdateLines(id);
    }
Ejemplo n.º 2
0
 public void RemoveSpawn(int index)
 {
     playerSpawnedCentrals.ModifyElementAt(index,null);
     internalFreeSpaceTracker.Add(index);
 }
    public void CreateWindow(int id, Vector3 location)
    {
        EditableWindow editWindow = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(EditableWindow)).script as EditableWindow;

        editWindow.link = this;

        //Runs deletion delegate.
        Button del = editWindow.deleteButton.button;

        del.onClick.AddListener(() => {
            //Handles UI deletion.
            editWindow.gameObject.SetActive(false);

            for (int i = editWindow.linesRelated.Count - 1; i >= 0; i--)
            {
                //lineData.l[editWindow.linesRelated[i]].line.gameObject.SetActive(false);
                //abilityData.linkAddresses.Remove(editWindow.linesRelated[i]);
                RemoveLine(editWindow.linesRelated[i]);
            }

            abilityData.subclasses.Remove(id);
        });

        editWindow.transform.position = location;
        abilityWindows.ModifyElementAt(id, editWindow);

        //Initialises variable linear layouts.
        editWindow.variables = new SpawnerOutput[abilityData.subclasses.l[id].var.Length];

        Vector2 varGraphicsDimensions = new Vector2(0, 0);

        for (int i = 0; i < abilityData.subclasses.l[id].var.Length; i++)
        {
            if (LoadedData.GetVariableType(abilityData.subclasses.l[id].classType, i, VariableTypes.HIDDEN))
            {
                continue;
            }

            SpawnerOutput[] var = CreateVariableField(id, i);

            SpawnerOutput get = CreateVariableButtons(ActionType.RECIEVE, new int[] { id, i });
            SpawnerOutput set = CreateVariableButtons(ActionType.SEND, new int[] { id, i });

            LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Image>(get, "Image").color = Color.red;
            LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Image>(set, "Image").color = Color.green;

            SpawnerOutput align = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(LinearLayout));

            LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <LinearLayout>(align).o = LinearLayout.Orientation.X;
            LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <LinearLayout>(align).Add(get.script.transform as RectTransform);

            for (int j = 0; j < var.Length; j++)
            {
                LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <LinearLayout>(align).Add(var[j].script.transform as RectTransform);
            }

            LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <LinearLayout>(align).Add(set.script.transform as RectTransform);

            //(align.script.transform as RectTransform).sizeDelta = (align.script.transform as RectTransform).sizeDelta;
            editWindow.lL.Add(align.script.transform as RectTransform);
            editWindow.variables[i] = align;

            varGraphicsDimensions.y += (align.script.transform as RectTransform).sizeDelta.y;

            if ((align.script.transform as RectTransform).sizeDelta.x > varGraphicsDimensions.x)
            {
                varGraphicsDimensions.x = (align.script.transform as RectTransform).sizeDelta.x;
            }
        }

        editWindow.ChangeWindowsContentSize(varGraphicsDimensions);
        editWindow.windowsText.text = abilityData.subclasses.l[id].classType.Name;
    }
Ejemplo n.º 4
0
    void RetrieveStartNodes()
    {
        int nonPsuedoNodes = dataVar.Length - 2;

        AutoPopulationList <bool> connected = new AutoPopulationList <bool>(nonPsuedoNodes);

        for (int i = 0; i < nonPsuedoNodes; i++)
        {
            int totalCurrLinks = 0;

            for (int j = 0; j < dataVar[i].Length; j++)
            {
                totalCurrLinks += dataVar[i][j].links.Length;

                for (int k = 0; k < dataVar[i][j].links.Length; k++)
                {
                    int[] currLink = dataVar[i][j].links[k];

                    // Marks target as true so it can't be root.
                    connected.ModifyElementAt(currLink[0], true);
                }
            }

            if (totalCurrLinks == 0)
            {
                dataVar[i][dataVar[i].Length - 1].links = new int[][] { new int[] { dataVar.Length - 1, 0, 0 } }
            }
            ;
        }

        List <int[]> rC = new List <int[]>();

        for (int i = 0; i < connected.l.Count; i++)
        {
            if (!connected.l[i])
            {
                rC.Add(new int[] { i, 0, 1 });
            }
        }

        rootSubclasses = rC.ToArray();
    }

    void RunNodeFlow(int nextNode, int targetVar, Tuple <int, int, int>[] pN = null)
    {
        int[] lC = LoadedData.loadedNodeInstance[dataType[nextNode]].ReturnLinkChannels();

        for (int k = 0; k < lC.Length; k++)
        {
            if (pN != null)
            {
                Tuple <int, int, int> precedingNode = pN[lC[k]];

                if (linkGenerator[lC[k]][precedingNode.Item1][precedingNode.Item2] == null)
                {
                    linkGenerator[lC[k]][precedingNode.Item1][precedingNode.Item2] = new HashSet <Tuple <int, int, int> >();
                }

                Tuple <int, int, int> currNode = Tuple.Create(nextNode, targetVar, precedingNode.Item3);

                if (!linkGenerator[lC[k]][precedingNode.Item1][precedingNode.Item2].Contains(currNode))
                {
                    linkGenerator[lC[k]][precedingNode.Item1][precedingNode.Item2].Add(currNode);
                }
            }
        }


        //if(LoadedData.loadedNodeInstance[dataType[nextNode]] is INodeNetworkPoint)
        //progenitor = nextNode;
        //Debug.LogFormat("Curr Node: {0}, {1}", nextNode,dataType[nextNode]);
        for (int i = 0; i < dataVar[nextNode].Length; i++)
        {
            for (int j = 0; j < dataVar[nextNode][i].links.Length; j++)
            {
                int[] currLink = dataVar[nextNode][i].links[j];

                // Adds links to rhs.
                Tuple <int, int, int, int> rhslinkTup = Tuple.Create(currLink[0], currLink[1], currLink[2], j);

                if (!linkData[nextNode].rHS.Contains(rhslinkTup))
                {
                    linkData[nextNode].rHS.Add(rhslinkTup);
                }

                // Adds links to target lhs.
                Tuple <int, int, int, int> lhslinkTup = Tuple.Create(nextNode, i, currLink[2], j);

                if (!linkData[currLink[0]].lHS.Contains(lhslinkTup))
                {
                    linkData[currLink[0]].lHS.Add(lhslinkTup);
                }


                Tuple <int, int, int>         nextNodeRef    = Tuple.Create <int, int, int>(nextNode, i, currLink[2]);
                List <Tuple <int, int, int> > precedingArray = new List <Tuple <int, int, int> >();

                if (pN != null)
                {
                    precedingArray.AddRange(pN);
                }
                else
                {
                    precedingArray.Add(null);
                    precedingArray.Add(null);
                }

                for (int k = 0; k < lC.Length; k++)
                {
                    precedingArray[lC[k]] = nextNodeRef;
                }

                // Iterates to target.
                RunNodeFlow(currLink[0], currLink[1], precedingArray.ToArray());
            }
        }

        //Debug.LogWarningFormat("End of Node: {0}, {1}", nextNode, dataType[nextNode]);
    }

    void GenerateLinks()
    {
        // Generate links after
        generatedLinks = new int[linkGenerator.Length][][][][];

        for (int i = 0; i < linkGenerator.Length; i++)
        {
            generatedLinks[i] = new int[linkGenerator[i].Length][][][];

            for (int j = 0; j < linkGenerator[i].Length; j++)
            {
                generatedLinks[i][j] = new int[linkGenerator[i][j].Length][][];

                for (int k = 0; k < linkGenerator[i][j].Length; k++)
                {
                    List <int[]> convertedLinks = new List <int[]>();
                    //generatedLinks[i][j][k] = new int[linkGenerator[i][j][k].Count];

                    if (linkGenerator[i][j][k] != null)
                    {
                        foreach (var item in linkGenerator[i][j][k])
                        {
                            convertedLinks.Add(new int[] { item.Item1, item.Item2, item.Item3 });
                        }
                    }


                    //Debug.LogFormat("Generating for: {0}, {1}, {2}", i, j, k);
                    generatedLinks[i][j][k] = convertedLinks.ToArray();
                }
            }
        }
    }

    void EditLinks()
    {
        lM = new LinkModifier();

        for (currBuildNode = 0; currBuildNode < dataType.Length; currBuildNode++)
        {
            LoadedData.loadedNodeInstance[dataType[currBuildNode]].ConstructionPhase(this);
        }
        //LoadedData.loadedNodeInstance[dataType[i]].LinkEdit(i, lD, lM, dataVar);

        foreach (var add in lM.add)
        {
            List <int[]> links = new List <int[]>(dataVar[add.Key.Item1][add.Key.Item2].links);

            foreach (var ele in add.Value)
            {
                links.Add(new int[] { ele.Item1, ele.Item2, ele.Item3 });
                Debug.LogFormat("Adding to {0},{1}. Content: {2},{3}", add.Key.Item1, add.Key.Item2, ele.Item1, ele.Item2);
            }

            dataVar[add.Key.Item1][add.Key.Item2].links = links.ToArray();
        }

        foreach (var rm in lM.remove)
        {
            int[] rmArr = rm.Value.ToArray();
            Array.Sort(rmArr);

            List <int[]> links = new List <int[]>(dataVar[rm.Key.Item1][rm.Key.Item2].links);

            for (int i = rmArr.Length - 1; i >= 0; i--)
            {
                Debug.LogFormat("Removing at {0},{1}. Content: {2},{3}", rm.Key.Item1, rm.Key.Item2, links[rmArr[i]][0], links[rmArr[i]][0]);
                links.RemoveAt(rmArr[i]);
            }

            dataVar[rm.Key.Item1][rm.Key.Item2].links = links.ToArray();
        }
    }

    void BeginDepenciesBuild()
    {
        nodeBranchingData    = new int[dataVar.Length];
        autoManagedVariables = new int[dataVar.Length][];
        boolData             = new AbilityBooleanData(dataVar);

        for (int i = 0; i < dataVar.Length; i++)
        {
            List <int> aMVar            = new List <int>();
            List <int> networkVariables = new List <int>();
            //Debug.Log("Printing for Node: " + i);

            for (int j = 0; j < dataVar[i].Length; j++)
            {
                //Debug.Log("Printing for Variable: " + j);
                bool interchangeable = LoadedData.GetVariableType(dataType[i], j, VariableTypes.INTERCHANGEABLE);

                AutoPopulationList <List <int[]> > varLinks = new AutoPopulationList <List <int[]> >(1);

                for (int k = 0; k < dataVar[i][j].links.Length; k++)
                {
                    int[] currLink = dataVar[i][j].links[k];

                    //Debug.LogFormat("{0},{1}", currLink[0], currLink[1]);

                    bool signal = currLink[2] == (int)LinkMode.SIGNAL ? true : false;//LoadedData.GetVariableType(dataType[i], j, VariableTypes.SIGNAL_ONLY);
                    // Marks target as true so it will be blocked.
                    if (!signal)
                    {
                        if (dataVar[i][j].field.t == dataVar[currLink[0]][currLink[1]].field.t || interchangeable)
                        {
                            boolData.varsBlocked[currLink[0]][currLink[1]] = true;
                            //Debug.LogFormat("From Node {0} Variable {1} link {2} name {3}", i, j, k, dataVar[i][j].field.n);
                            //Debug.LogFormat("To Node {0} Variable {1} link {2} signal {3} interchange {4} name {5}", currLink[0], currLink[1], k, signal, interchangeable, dataVar[i][j].field.n);
                            //Debug.Log("This was called true.");
                        }
                    }
                }

                if (LoadedData.GetVariableType(dataType[i],j,VariableTypes.BLOCKED))
                {
                    boolData.varsBlocked[i][j] = true;
                }

                if (LoadedData.GetVariableType(dataType[i],j,VariableTypes.AUTO_MANAGED))
                {
                    aMVar.Add(j);
                }


                if (!LoadedData.GetVariableType(dataType[i],j,VariableTypes.NON_LINK))
                {
                    nodeBranchingData[i] += dataVar[i][j].links.Length;
                }

                if (LoadedData.GetVariableType(dataType[i],j,VariableTypes.GLOBAL_VARIABLE))
                {
                    string gVN = (dataVar[i][j].field as RuntimeParameters <string>).v;
                    if (!AbilitiesManager.GetAssetData(playerId).globalVariables.ContainsKey(gVN))
                    {
                        AbilitiesManager.GetAssetData(playerId).globalVariables.Add(gVN,null);
                    }
                }

                if (LoadedData.GetVariableType(dataType[i],j,VariableTypes.NETWORK))
                {
                    networkVariables.Add(j);
                }
            }

            autoManagedVariables[i] = aMVar.ToArray();

            if (networkVariables.Count > 0)
            {
                nodeNetworkVariables.Add(i,networkVariables.ToArray());
            }
            //aMVar.Add(j);
        }
    }