/**
     * Called by the edit section panel to remove a section
     */
    public void removeSection()
    {
        string    removedSection = tObject.text;
        Transform par            = tm.SectionContentPar.transform;

        if (!tObject.text.Contains("/"))
        {
            Destroy(tm.SectionContentPar.transform.Find(tObject.text + "Button").gameObject);
        }
        else
        {
            for (int i = 0; i < tm.SectionContentPar.transform.childCount; i++)
            {
                if (tm.SectionContentPar.transform.GetChild(i).name.Equals(tObject.text + "Button"))
                {
                    Destroy(tm.SectionContentPar.transform.GetChild(i).gameObject);
                    break;
                }
            }
        }
        string sectionData = ds.GetData(removedSection).GetAllData();

        ds.RemoveSection(removedSection);
        //editSectionPanel.gameObject.SetActive (false);
        tm.RemoveCurrentSection();

        List <string> keyList = ds.GetImageKeys();        // ds.GetImages ().Keys.ToList ();

        foreach (string key in keyList)
        {
            if (key.StartsWith(tObject.text) || sectionData.Contains("<Image>" + key + "</Image>"))
            {
                Debug.Log("Removing Image: " + key);
                ds.RemoveImage(key);
                //ds.GetImages ().Remove (key);
            }
        }

        keyList = ds.GetDialogues().Keys.ToList();
        foreach (string key in keyList)
        {
            if (key.StartsWith(tObject.text))
            {
                ds.GetDialogues().Remove(key);
            }
        }

        keyList = ds.GetQuizes().Keys.ToList();
        foreach (string key in keyList)
        {
            if (key.StartsWith(tObject.text))
            {
                ds.GetQuizes().Remove(key);
            }
        }
        string switchTo = "";

        for (int i = 0; i < tm.SectionContentPar.transform.childCount; i++)
        {
            Transform child = tm.SectionContentPar.transform.GetChild(i);
            if (!child.name.Equals("Filler"))
            {
                switchTo = child.Find("SectionDisplayTMP").GetComponent <TextMeshProUGUI> ().text.Replace(" ", "_") + "Section";
                if (!switchTo.Equals(removedSection))
                {
                    break;
                }
            }
            else
            {
                switchTo = "";
            }
        }
        //Debug.Log (tm.SectionContentPar.transform.GetComponentsInChildren<Transform>()[1].name);
        //switchTo = tm.SectionContentPar.GetComponentsInChildren<Transform>()[1].Find("SectionDisplayText").GetComponent<TextMeshProUGUI>().text;
        if (switchTo.Equals(""))
        {
            BG.transform.Find("SectionCreatorBG").gameObject.SetActive(true);
            for (int i = 0; i < tm.TabContentPar.transform.childCount; i++)
            {
                Destroy(tm.TabContentPar.transform.GetChild(i).gameObject);
            }
        }
        else
        {
            tm.SwitchSection(switchTo);
        }

        //Destroy (editTabPanel);
    }
Пример #2
0
    /**
     * Switches the active section.
     * Pass in the LinkToText
     */
    public void SwitchSection(string sectionName)
    {
        string sName = null;
        //Disable the text and edit button of the section we're switching away from (show only the icon)
        List <Button> sectionButtonsList = SectionContentPar.GetComponentsInChildren <Button>().ToList();

        sectionButtonsList.RemoveAt(sectionButtonsList.Count - 1); //Remove the AddSectionButton
        if (currentSection != null && !currentSection.Equals(""))
        {
            sName = currentSection.Replace(" ", "_") + "Button";
            foreach (Button t in sectionButtonsList)
            {
                if (t.transform.name.Equals(sName))
                {
                    Transform[] components = t.transform.GetComponentsInChildren <Transform>();
                    foreach (Transform c in components)
                    {
                        if (!c.name.Equals(t.name) && !c.name.Equals("SectionDisplayTMP"))
                        {
                            c.gameObject.SetActive(false);
                        }
                        if (c.name.Equals("SectionDisplayTMP") && c.GetComponent <TextMeshProUGUI>().preferredWidth > 85)
                        {
                            c.GetComponent <LayoutElement>().preferredWidth = 85;
                        }
                    }
                    t.transform.GetChild(0).gameObject.SetActive(true);
                    t.interactable = true;
                }
            }
        }

        if (sectionName == null || sectionName.Equals(""))   //No section provided. Use default
        {
            if (ID == null)
            {
                ID = new DefaultDataScript();
            }
            sectionName = ID.defaultSection;
            print(string.Join(",", sectionButtonsList.Select(b => b.name)));
            if (sectionButtonsList.Count > 0 && sectionButtonsList[0].name.Length > 0)
            {
                sectionName = sectionButtonsList[0].name.Remove(sectionButtonsList[0].name.Length - "Button".Length);
            }
            print(sectionName);
        }
        else if (sectionName.Equals(currentSection))     //Trying to switch to current section
        {
            return;
        }

        if (currentSection != null && !currentSection.Equals(""))   //Save data before switching away
        {
            AddToDictionary();
            currentSection = null;
            currentTab     = null;
        }

        currentSection = sectionName;
        //Destroy Tab buttons and content
        foreach (Transform child in TabContentPar.GetComponentInChildren <Transform>())
        {
            Destroy(child.gameObject);
        }

        foreach (Transform child in TabButtonContentPar.GetComponentInChildren <Transform>())
        {
            if (child.name != "AddTabButton")
            {
                Destroy(child.gameObject);
            }
        }
        //Enable the new section's text and edit button
        sName = currentSection.Replace(" ", "_") + "Button";
        foreach (Button t in sectionButtonsList)
        {
            if (t.name.Equals(sName) && !t.name.Equals("AddSectionButton"))
            {
                Transform[] components = t.GetComponentsInChildren <Transform>(true);
                foreach (Transform c in components)
                {
                    if (c.name.Equals("SectionDisplayText"))
                    {
                        continue;
                    }
                    c.gameObject.SetActive(true);
                    if (c.name.Equals("SectionDisplayTMP"))
                    {
                        if (c.GetComponent <TextMeshProUGUI>().preferredWidth > 270)
                        {
                            c.GetComponent <LayoutElement>().preferredWidth = 270;
                        }
                        else
                        {
                            c.GetComponent <LayoutElement>().preferredWidth = -1;
                        }
                    }
                }
                t.GetComponent <Button>().interactable = false;
                t.GetComponent <ScriptButtonFixScript>().FixTab();
            }
        }

        //Load in the Tab buttons for each tab
        List <string> sectionTabs = null;

        if (ds.GetData(currentSection) != null)
        {
            sectionTabs = ds.GetData(currentSection).GetTabList();
        }
        int i = 0;

        if (sectionTabs == null || sectionTabs.Count == 0)   //Spawn a default tab

        //transform.Find("TabSelectorBG").gameObject.SetActive(true); //Let the user choose their new tab
        {
            GameObject savePrefab = Instantiate(Resources.Load("Writer/Prefabs/Panels/TabSelectorBG")) as GameObject;
            savePrefab.transform.SetParent(BG.transform, false);

            if (savePrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton"))
            {
                savePrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton").gameObject.SetActive(false);
            }
            //This code spawns in the default tab listed in DefaultDataScript

            /*string tabName = ID.defaultTab;
             *          GameObject newTab = Resources.Load (gData.resourcesPath + "/Prefabs/TabButton") as GameObject;
             *          Text[] children = newTab.GetComponentsInChildren<Text> ();
             *          foreach (Text child in children) {
             *                  if (child.name.Equals ("TabButtonLinkToText")) { //Where the button links to
             *                          child.text = tabName.Replace (" ", "_") + "Tab" + i;
             *                  } else if (child.name.Equals ("TabButtonDisplayText")) { //What the button displays
             *                          child.text = tabName;
             *                  }
             *          }
             *          //The button's position
             *          newTab = Instantiate (newTab, TabButtonContentPar.transform);
             *          newTab.name = tabName + "Button";
             *          ds.GetData (currentSection).AddData (tabName.Replace (" ", "_") + "Tab" + i, null);
             *          ds.GetData (currentSection).SetCurrentTab (new TabInfoScript (i, tabName.Replace (" ", "_") + "Tab"));*/
        }
        else
        {
            //Spawn in the section's tab buttons
            Debug.Log("TABS = " + string.Join(",", sectionTabs.ToArray()));
            foreach (string tabName in sectionTabs)
            {
                GameObject        newTab   = Resources.Load(GlobalData.resourcePath + "/Prefabs/TabButton") as GameObject;
                TextMeshProUGUI[] children = newTab.GetComponentsInChildren <TextMeshProUGUI>();
                foreach (TextMeshProUGUI child in children)
                {
                    if (child.name.Equals("TabButtonLinkToText"))   //Where the button links to
                    {
                        child.text = tabName;
                    }
                    else if (child.name.Equals("TabButtonDisplayText"))     //What the button displays
                    {
                        string customName = ds.GetData(currentSection).GetTabInfo(tabName).customName;
                        if (customName != null)  // && customName != tabName) {
                        {
                            child.text = customName;
                        }
                        else
                        {
                            if (child.text.Contains(" "))
                            {
                                //child.text = tabName.Replace ("_", " ").Substring (0, tabName.Length - "Tab".Length); //Unformat it
                                //child.text = child.text.Replace(" ", "_") + "Tab";
                            }
                            child.text = tabName;
                            ds.GetData(currentSection).GetTabInfo(tabName).customName = child.text;
                        }
                    }
                }
                //The button's position
                i++;
                newTab      = Instantiate(newTab, TabButtonContentPar.transform);
                newTab.name = tabName /*.Replace (" ", "_")*/ + "TabButton";
            }
            //transform.Find ("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/BackgroundInfoTabPanel").gameObject.SetActive (activateBGInfoOption);
            for (int j = 0; j < TabButtonContentPar.transform.childCount; j++)
            {
                //foreach (string tabName in sectionTabs) {
                //TabButtonContentPar.transform.Find (tabName/*.Replace (" ", "_")*/ + "TabButton").GetComponent<TabAndSectionDragScript> ().UpdateEntryList ();
                if (!TabButtonContentPar.transform.GetChild(j).name.Equals("AddTabButton"))
                {
                    TabButtonContentPar.transform.GetChild(j).GetComponent <TabAndSectionDragScript>().UpdateEntryList();
                }
            }
        }
        //If the section had a custom icon image (and can load it), then set the tab background bar color to the icon image color
        if (currentSection != null && ds.GetImageKeys().Contains(currentSection))
        {
            if (ds.GetImage(currentSection).color.a > 0)
            {
                GameObject.Find("TabButtonsPanel").GetComponent <Image>().color = ds.GetImage(currentSection).color;
            }
            else
            {
                GameObject.Find("TabButtonsPanel").GetComponent <Image>().color = ID.defaultColor;
            }
        }
        else if (currentSection == ID.defaultSection)
        {
            GameObject.Find("TabButtonsPanel").GetComponent <Image>().color = ID.defaultColor;
        }

        addTabButton.transform.SetAsLastSibling();

        //Switch to the default/last active tab of the new section
        TabInfoScript tab = ds.GetData(currentSection).GetCurrentTab();

        if (tab != null)
        {
            string formattedName = tab.customName; //.Replace (" ", "_") + "Tab";
                                                   //Debug.Log ("CUSTOM NAME: " + tab.customName);
            setTabName(formattedName);
            SwitchTab(formattedName);
        }
        else if (ds.GetData(getCurrentSection()).GetTabList().Count <= 0)
        {
            return;
        }
        else
        {
            //Debug.Log (string.Join (",", ds.GetData (getCurrentSection ()).GetTabList ().ToArray ()));
            TabInfoScript newTabInfo    = ds.GetData(getCurrentSection()).GetTabInfo(ds.GetData(getCurrentSection()).GetTabList()[0]);
            string        formattedName = newTabInfo.customName; //.Replace (" ", "_") + "Tab";
                                                                 //Debug.Log ("DEFAULT'S CUSTOM NAME: " + newTabInfo.customName);
            setTabName(formattedName);
            SwitchTab(formattedName);
            //SwitchTab (ds.GetData (getCurrentSection ()).GetTabList () [0]);
        }
    }
Пример #3
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);
        }
    }
Пример #4
0
    /**
     * Called when removing a tab from the edit tab panel
     */
    public void removeTab()
    {
        //Debug.Log (tObject.text);
        tm.AddToDictionary();
        string tabData = ds.GetData(tm.getCurrentSection(), tabName.text);

        ds.RemoveTab(tabName.text);
        tm.DestroyCurrentTab();
        tm.TabButtonContentPar.transform.Find(tabName.text + "TabButton");
        if (!tabName.text.Contains("/"))
        {
            Destroy(tm.TabButtonContentPar.transform.Find(tabName.text + "TabButton").gameObject);
        }
        else
        {
            for (int i = 0; i < tm.TabButtonContentPar.transform.childCount; i++)
            {
                if (tm.TabButtonContentPar.transform.GetChild(i).name.Equals(tabName.text + "TabButton"))
                {
                    Destroy(tm.TabButtonContentPar.transform.GetChild(i).gameObject);
                    break;                     //break out of the loop
                }
            }
        }
        if (ds.GetData(tm.getCurrentSection()).GetTabList().Count != 0)
        {
            TabInfoScript newTabInfo = ds.GetData(tm.getCurrentSection()).GetTabInfo(ds.GetData(tm.getCurrentSection()).GetTabList() [0]);
            tm.setTabName(newTabInfo.customName);
            tm.SwitchTab(ds.GetData(tm.getCurrentSection()).GetTabList() [0]);
        }
        else
        {
            //BG.transform.Find ("TabSelectorBG").gameObject.SetActive (true);
            GameObject tabSelectorPrefab = Instantiate(Resources.Load("Writer/Prefabs/Panels/TabSelectorBG")) as GameObject;
            tabSelectorPrefab.transform.SetParent(BG.transform, false);

            if (tabSelectorPrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton"))
            {
                tabSelectorPrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton").gameObject.SetActive(false);
            }
        }
        //Debug.Log (ds.GetData (tm.getCurrentSection()).getTabList ()[0]);
        tabEditPrefab.transform.Find(TitleValuePath).GetComponent <TMP_InputField>().text = "";
        //tabEditPrefab.gameObject.SetActive (false);
        if (tabName.text.StartsWith("Background_InfoTab"))
        {
            ds.transform.Find("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/BackgroundInfoTabPanel").gameObject.SetActive(true);
        }

        Destroy(tabEditPrefab);

        List <string> keyList = ds.GetImageKeys();        //  ds.GetImages ().Keys.ToList();

        foreach (string key in keyList)
        {
            if (tabData.Contains("<Image>" + key + "</Image>"))
            {
                Debug.Log("Removing Image: " + key);
                ds.RemoveImage(key);
                //ds.GetImages ().Remove (key);
            }
        }

        keyList = ds.GetDialogues().Keys.ToList();
        foreach (string key in keyList)
        {
            if (key.StartsWith(tm.getCurrentSection() + "/" + tabName.text + "Tab"))
            {
                ds.GetDialogues().Remove(key);
            }
        }

        keyList = ds.GetQuizes().Keys.ToList();
        foreach (string key in keyList)
        {
            if (key.StartsWith(tm.getCurrentSection() + "/" + tabName.text + "Tab"))
            {
                ds.GetQuizes().Remove(key);
            }
        }
    }