Example #1
0
    public void ApprovedPinRemove(GameObject pin)
    {
        //Dropdown pDrop = pin.transform.parent.parent.Find ("AddPinButton").GetComponentInChildren<Dropdown> ();
        //pDrop.AddOptions (new List<Dropdown.OptionData>(){new Dropdown.OptionData ("Quiz", pin.transform.Find ("ItemIcon").GetComponent<Image> ().sprite)});
        //pDrop.GetComponent<PinTabScript>().myOptions.Add (pin.name.Remove (pin.name.Length - "pin".Length));

        DataScript ds         = GameObject.Find("GaudyBG").GetComponent <DataScript> ();
        string     uniquePath = "";

        Debug.Log(pin.transform.name);
        Transform tempPin = pin.transform;

        if (!tempPin.GetComponentInParent <HistoryFieldManagerScript> ())
        {
            Transform uniqueParent = tempPin;
            uniquePath = "";
            while (uniqueParent.parent != null && !uniqueParent.parent.name.Equals("Content"))
            {
                if (uniqueParent.parent.GetComponent <HistoryFieldManagerScript> () != null)
                {
                    break;
                }
                uniqueParent = uniqueParent.parent;
            }
            uniquePath = uniqueParent.name;

            while (!uniqueParent.name.Equals(ds.GetComponent <TabManager>().getCurrentTab() + "Tab"))
            {
                uniqueParent = uniqueParent.parent;
                if (uniqueParent == null)
                {
                    break;
                }
                uniquePath = uniqueParent.name + "/" + uniquePath;
            }
            uniquePath = ds.GetComponent <TabManager>().getCurrentSection() + "/" + uniquePath;
        }
        else
        {
            while (tempPin != null)
            {
                if (tempPin.name.StartsWith("LabEntry:"))
                {
                    //uniquePath = "LabEntry: " + tempPin.GetSiblingIndex() + uniquePath;
                    uniquePath = tempPin.name + uniquePath;
                }
                if (tempPin.name.EndsWith("Tab"))
                {
                    uniquePath = tempPin.name + "/" + uniquePath;
                }
                tempPin = tempPin.parent;
            }
            uniquePath = ds.GetComponent <TabManager>().getCurrentSection() + "/" + uniquePath;
        }
        Debug.Log("Removing: " + uniquePath);
        switch (pin.transform.name)
        {
        case "DialoguePin":
            ds.GetDialogues().Remove(uniquePath);
            break;

        case "QuizPin":
            Dictionary <string, string> quizes = ds.GetQuizes();
            string quizData = "";
            if (quizes.ContainsKey(uniquePath))
            {
                quizData = quizes [uniquePath];
            }
            else
            {
                break;
            }
            ds.GetQuizes().Remove(uniquePath);
            List <string> imagesToRemove = new List <string> ();
            foreach (string key in ds.GetImageKeys())
            {
                if (quizData.Contains("<Image>" + key + "</Image>"))
                {
                    Debug.Log("Removing image: " + key);
                    imagesToRemove.Add(key);
                }
            }

            foreach (string s in imagesToRemove)
            {
                quizes.Remove(s);
            }
            break;

        case "FlagPin":
            ds.GetFlags().Remove(uniquePath);
            break;

        case "EventPin":
            // Wipe event input
            break;
        }

        if (pin.transform.Find("Item Background Off"))
        {
            pin.transform.Find("Item Background Off").gameObject.SetActive(true);
            pin.transform.Find("Item Background On").gameObject.SetActive(false);
        }
        else
        {
            Destroy(pin.gameObject);
        }
    }
Example #2
0
    /**
     * Adds the active tab to the dictionary
     */
    public void AddToDictionary()
    {
        //GetSectionImages ();

        //If another tab has specified another AddToDictionary method, use that one
        if (MethodToCall != null)
        {
            MethodToCall();
            if (!sameTab)
            {
                MethodToCall = null;
            }
            return;
        }
        else
        {
            if (currentTab == null)
            {
                return;
            }

            string xml       = "<data>";
            string imageData = "<images>";
            int    imgCount  = 0;

            //string customName = ds.GetData (currentSection).getTabInfo (currentTab.name + currentTab.GetComponent<Text>().text).customName;
            //xml += "<customName>" + customName + "</customName><data>";

            //Sets up the XML string to be passed into the dictionary
            allChildren = currentTab.GetComponentsInChildren <Transform>();
            Transform nextChild = null;
            string    UID       = "";
            foreach (Transform child in allChildren)
            {
                //Debug.Log(child.name);
                if (child != null)
                {
                    if (child.tag.Equals("Image"))   //Handle images
                    {
                        Sprite img = child.GetComponent <Image>().sprite;
                        imageData += "<image" + imgCount + ">";

                        UID        = child.GetComponent <OpenImageUploadPanelScript>().GetGuid();
                        imageData += "<key>" + UID + "</key>";
                        //imageData += "<key>" + currentSection + currentTab.transform.Find ("TabButtonLinkToText").GetComponent<Text>().text + "</key>";
                        string imgRef;
                        if ((imgRef = ds.GetImage(currentSection + currentTab.transform.Find("TabButtonLinkToText").GetComponent <TextMeshProUGUI>().text).referenceName) != null)
                        {
                            imageData += imgRef;
                        }
                        else
                        {
                            imageData += "<width>" + img.texture.width + "</width><height>" + img.texture.height + "</height>";
                            Texture2D dictTexture = img.texture;
                            Texture2D newTexture  = new Texture2D(dictTexture.width, dictTexture.height, TextureFormat.ARGB32, false);
                            newTexture.SetPixels(0, 0, dictTexture.width, dictTexture.height, dictTexture.GetPixels());
                            newTexture.Apply();
                            byte[] bytes      = newTexture.EncodeToPNG();
                            string base64Data = Convert.ToBase64String(bytes);
                            imageData += "<data>" + base64Data + "</data>";
                        }
                        imageData += "</image" + imgCount + ">";
                        imgCount++;
                    }
                    else if (child.GetComponent <HistoryFieldManagerScript>() != null)
                    {
                        xml += child.GetComponent <HistoryFieldManagerScript>().getData();
                        Transform tempChild = child;
                        while (nextChild == null)
                        {
                            if (tempChild.GetSiblingIndex() + 1 == tempChild.parent.childCount)
                            {
                                tempChild = tempChild.parent;
                            }
                            else
                            {
                                nextChild = tempChild.parent.GetChild(tempChild.GetSiblingIndex() + 1);
                            }
                        }
                    }
                    else if (nextChild == null && (child.name.ToLower().EndsWith("value") || child.name.ToLower().EndsWith("toggle") || child.tag.Equals("Value")))     //Input object/field
                    {
                        if (child.gameObject.GetComponent <Toggle>() != null)
                        {
                            if (true)  // || child.gameObject.GetComponent<Toggle> ().isOn) { //Leaving as true for now. May change later
                            {
                                xml += "<" + child.name + ">";
                                xml += child.gameObject.GetComponent <Toggle>().isOn;
                                xml += "</" + child.name + ">";
                            }
                        }
                        else if (child.name.ToLower().EndsWith("toggle") || child.name.ToLower().EndsWith("radio"))
                        {
                            continue;
                        }
                        else
                        {
                            xml += "<" + child.name + ">";

                            //Handle reading the child
                            if (child.gameObject.GetComponent <InputField>() != null)
                            {
                                xml += UnityWebRequest.EscapeURL(child.gameObject.GetComponent <InputField>().text);
                            }
                            else if (child.gameObject.GetComponent <Text>() != null)
                            {
                                xml += UnityWebRequest.EscapeURL(child.gameObject.GetComponent <Text>().text);
                            }
                            else if (child.gameObject.GetComponent <Dropdown>() != null)
                            {
                                xml += UnityWebRequest.EscapeURL(child.gameObject.GetComponent <Dropdown>().captionText.text);
                            }
                            else if (child.name.Equals("DialoguePin") || child.name.Equals("QuizPin") || child.name.Equals("FlagPin") || child.name.Equals("EventPin"))
                            {
                                Transform uniqueParent = child;
                                string    path         = "";
                                while (uniqueParent.parent != null && !uniqueParent.parent.name.Equals("Content"))
                                {
                                    uniqueParent = uniqueParent.parent;
                                }
                                path = uniqueParent.name;
                                while (!uniqueParent.name.EndsWith("Tab"))  //Once you hit the Tab container
                                {
                                    uniqueParent = uniqueParent.parent;
                                    path         = uniqueParent.name + "/" + path;
                                }
                                path = getCurrentSection() + "/" + path;

                                //If the dialogue entry has been moved, adjust the dictionary accordingly
                                if (child.name.Equals("DialoguePin") && ds.GetDialogues().ContainsKey(path))
                                {
                                    string dialogueXML = ds.GetDialogues()[path]; //Dialogue data
                                    ds.AddDialogue(path, dialogueXML);

                                    xml += dialogueXML;
                                }
                                else if (child.name.Equals("DialoguePin"))
                                {
                                    xml = xml.Substring(0, xml.Length - ("<" + child.name + ">").Length);
                                    continue;
                                }

                                //If the quiz entry has been moved, adjust the dictionary accordingly
                                if (child.name.Equals("QuizPin") && ds.GetQuizes().ContainsKey(path))
                                {
                                    string quizXML = ds.GetQuizes()[path]; //Quiz data
                                    ds.AddQuiz(path, quizXML);
                                    xml += quizXML;
                                }
                                else if (child.name.Equals("QuizPin"))
                                {
                                    xml = xml.Substring(0, xml.Length - ("<" + child.name + ">").Length);
                                    continue;
                                }

                                if (child.name.Equals("FlagPin") && ds.GetFlags().ContainsKey(path))
                                {
                                    string flagXML = ds.GetFlags()[path]; //Dialogue data
                                    ds.AddFlag(path, flagXML);

                                    xml += flagXML;
                                }
                                else if (child.name.Equals("FlagPin"))
                                {
                                    xml = xml.Substring(0, xml.Length - ("<" + child.name + ">").Length);
                                    continue;
                                }
                            }

                            xml += "</" + child.name + ">";
                        }
                    }
                    if (child == nextChild)
                    {
                        nextChild = null;
                    }
                }
            }
            imageData += "</images>";
            xml       += "</data>";

            //Add the current Tab to the Dictionary. Replace any existing tab if it exists
            if (ds == null)
            {
                ds = GameObject.Find("GaudyBG").GetComponentInChildren <DataScript>();
            }
            //ds.AddData (currentSection, tabName, xml);
            ds.AddData(currentSection, currentTab.name.Substring(0, currentTab.name.Length - 3), xml);
            Debug.Log("Saved value: " + xml);
        }
    }