/**
     * Submits the changes from the edit tab panel
     */
    public void SubmitChanges()
    {
        string newName = tabEditPrefab.transform.Find(TitleValuePath).GetComponent <TMP_InputField> ().text;

        if (!ds.IsValidName(newName, "Tab"))
        {
            //ds.ShowMessage ("Tab name not valid. Cannot use:\n*, &, <, >, or //", true);
            throw new System.Exception("Name not valid: Please choose a new name for your tab.");
        }
        else if (!newName.Equals(tabName.text))
        {
            ds.EditTab(tabName.text, newName);
            string formattedNewName = newName;            //.Replace(" ", "_") + "Tab";
            tabName.transform.parent.Find("TabButtonDisplayText").GetComponent <TextMeshProUGUI> ().text = newName;
            //tObject.transform.parent.Find ("TabButtonLinkToText").GetComponent<Text> ().text = formattedNewName;
            tm.setCurrentTabName(newName + "Tab");             //formattedNewName);
            tabName.transform.parent.name = formattedNewName /*.Replace(" ", "_")*/ + "TabButton";
        }
        tabEditPrefab.transform.Find(TitleValuePath).GetComponent <TMP_InputField>().text = "";
        tabEditPrefab.gameObject.SetActive(false);
        tabName.transform.parent.GetComponent <ScriptButtonFixScript> ().FixTab();

        Destroy(tabEditPrefab);
    }
    /**
     * Submits the changes from the edit section panel
     */
    public void SubmitChanges()
    {
        //Sets the section's name to the new display name
        string sectionLinkTo = tObject.text;
        string newName       = sectionEditPrefab.transform.Find(TitleValuePath).GetComponent <TMP_InputField> ().text;

        if (newName.Equals("") || newName.Length == 0)
        {
            ds.ShowMessage("Cannot leave section name blank");
            return;
        }
        if (!ds.IsValidName(newName, "Section"))
        {
            //ds.ShowMessage ("Section name not valid. Cannot use:\n*, &, <, >, or //", true);
            throw new System.Exception("Name not valid: Please rename your section");
        }
        Debug.Log("SECTIONEDITPREFAB: " + sectionEditPrefab.name);
        if (newName != null && !newName.Equals(""))
        {
            sectionLinkTo = newName.Replace(" ", "_") + "Section";
            //try {
            Debug.Log("tObject.name: " + tObject.name + ", text: " + tObject.text);
            Debug.Log("newName: " + newName);
            Debug.Log("sectionLinkTo: " + sectionLinkTo);
            ds.EditSection(tObject.text, newName);
            var text = tObject.transform.parent.Find("SectionDisplayTMP").GetComponentInChildren <TextMeshProUGUI>();
            text.text    = newName;
            tObject.text = sectionLinkTo;
            if (text.preferredWidth > 270)
            {
                text.GetComponent <LayoutElement>().preferredWidth = 270;
            }
            else
            {
                text.GetComponent <LayoutElement>().preferredWidth = -1;
            }
            tObject.transform.parent.name = sectionLinkTo + "Button";
            //} catch (Exception e) {
            //	Debug.Log (e.Message);
            //}
        }

        //Finds and sets the section's icon to the chosen one
        Sprite spr = null;

        Transform[] sectionIcons = sectionEditPrefab.transform.Find("SectionEditorPanel/Content/ScrollView/Viewport/Content").GetComponentsInChildren <Transform>();
        foreach (Transform t in sectionIcons)
        {
            Toggle tog;
            if ((tog = t.GetComponent <Toggle> ()) != null && tog.isOn)
            {
                spr = t.Find("Icon").GetComponent <Image> ().sprite;
                ds.AddImg(sectionLinkTo, t.name);
                break;
            }
        }
        if (spr != null)
        {
            tObject.transform.parent.Find("Image").GetComponent <Image> ().sprite = spr;
        }


        //Sets the section's color to the chosen one
        foreach (Toggle t in colorPanelParent.GetChild(0).GetComponentsInChildren <Toggle>())
        {
            if (t.isOn)
            {
                ds.GetImage(sectionLinkTo).color    = t.transform.GetComponent <Image> ().color;
                ds.GetImage(sectionLinkTo).useColor = true;
                break;
            }
        }
        if (ds.GetImage(sectionLinkTo).useColor)
        {
            tObject.transform.parent /*.Find ("Image")*/.GetComponent <Image> ().color = ds.GetImage(sectionLinkTo).color;
            GameObject.Find("TabButtonsPanel").GetComponent <Image> ().color           = ds.GetImage(sectionLinkTo).color;
        }

        //Spawns/Removes the Background Info tab as needed
        bool   spawn     = sectionEditPrefab.transform.Find("SectionEditorPanel/Content/Row1").GetComponentInChildren <Toggle>().isOn;
        string tabName   = ds.GetData(tm.getCurrentSection()).GetTabList().Find((string obj) => obj.StartsWith("Background_InfoTab"));
        bool   tabExists = true;

        if (tabName == null || tabName.Equals(""))
        {
            tabExists = false;
        }

        if (!spawn && tabExists)
        {
            BG.GetComponent <EditTabScript> ().removeTab(tabName);

            //reactivate the option to select BG Info from the TabSelector
            BGInfoOption.gameObject.SetActive(true);
        }
        else if (spawn && !tabExists)
        {
            AddTab("Background Info");

            //deactivate the option to select BG Info from the TabSelector
            BGInfoOption.gameObject.SetActive(false);
        }

        //Disable the editor tab and update the section button layout so the button size is correct
        //sectionEditPrefab.gameObject.SetActive (false);
        Destroy(sectionEditPrefab.gameObject);
        tObject.transform.parent.GetComponent <ScriptButtonFixScript> ().FixTab();
    }
Esempio n. 3
0
    /**
     * Adds a tab from the TabSelectorBG
     * Pass in the display name
     */
    public void addTab(TextMeshProUGUI tabName)
    {
        /*
         * tabCustomName = tabName
         * xmlTabName = tabType
         * tabName.text = displayed name
         */
        if (!ds.IsValidName(tabName.text, "Tab"))
        {
            //ds.ShowMessage("Tab name not valid. Cannot use:\n*, &, <, >, or //", true);
            ds.ShowMessage("Name not valid: Please rename your tab", true);
            throw new System.Exception("Name not valid: Please rename your tab");
        }
        var tabTemplate = FindSelected();

        if (tabTemplate == null)
        {
            ds.ShowMessage("A tab template must be selected.", true);
            throw new System.Exception("A tab template must be selected");
        }

        string        tabCustomName;
        List <string> tempTabList = ds.GetData(tm.getCurrentSection()).GetTabList();

        //Do not remove last compare below. It's looking for a zero width space (unicode 8203 / Alt+200B)
        if (tabName.text == null || tabName.text.Equals("") || tabName.text.ToCharArray()[0].Equals(GlobalData.EMPTY_WIDTH_SPACE))
        {
            tabCustomName = tabTemplate.text;//.Replace(" ", "_") + "Tab";
        }
        else
        {
            if (tabToSpawn != null)
            {
                tabName.text = tabToSpawn.text;
            }
            tabCustomName = tabName.text;//.Replace(" ", "_") + "Tab";
        }
        tabCustomName = tabCustomName.Replace(GlobalData.EMPTY_WIDTH_SPACE + "", "");
        //Debug.Log(tabCustomName + "--------------");
        //tabName = "Test History";

        if (tempTabList.Contains(tabCustomName))
        {
            ds.ShowMessage("Cannot name two tabs the same in one step!", true);
            throw new System.Exception("Cannot name two tabs the same in one step!");
        }

        string selected   = tabTemplate.text;
        string prefabName = selected;

        print("Selected: " + selected);
        System.IO.StreamReader reader = new System.IO.StreamReader(Application.streamingAssetsPath + "/Instructions/" + tabsFileName);
        string[] split;
        split = reader.ReadLine().Split(splitChar); //Skip the first line
        while (!reader.EndOfStream)
        {
            split = reader.ReadLine().Split(splitChar);
            if (split.Length < 3)
            {
                continue;
            }
            //print ("split 1: " + split[DISPLAY]);
            if (split[DISPLAY].Equals(selected))
            {
                //print ("split 2: " + split[PREFAB]);
                prefabName = split[PREFAB];
                break;
            }
        }
        reader.Close();

        string xmlTabName = prefabName;//.Replace (" ", "_") + "Tab";
        string xml        = "<data></data>";

        //Debug.Log (GlobalData.resourcePath + "Prefabs/Tabs/" + prefabName + " Tab" + "/" + prefabName.Replace (" ", string.Empty) + "Tab");
        GameObject test = Resources.Load(GlobalData.resourcePath + "/Prefabs/Tabs/" + prefabName + " Tab" + "/" + prefabName.Replace(" ", string.Empty) + "Tab") as GameObject;

        if (test == null)
        {
            Debug.Log("Cannot load tab prefab " + prefabName);
            Debug.Log(GlobalData.resourcePath + "Prefabs/Tabs/" + prefabName + " Tab" + "/" + prefabName.Replace(" ", string.Empty) + "Tab");
            return;
        }
        Debug.Log("-----: " + xmlTabName + ", " + tabCustomName);
        ds.AddData(tm.getCurrentSection(), xmlTabName, tabCustomName, xml);


        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 = tabCustomName;
            }
            else if (child.name.Equals("TabButtonDisplayText")) //What the button displays
            {
                child.text = tabCustomName;                     //.Replace("_", " ").Substring(0, tabCustomName.Length - 3);
                                                                //This converts the custom name back to display format since tabName.text can be left blank
            }
        }
        //The button's position
        newTab      = Instantiate(newTab, TabButtonContentPar.transform);
        newTab.name = tabCustomName /*.Replace(" ", "_")*/ + "TabButton";
        if (tabName.text.Equals("Background Info") || tabName.text.Equals("Case Overview"))
        {
            newTab.transform.SetSiblingIndex(0);
            if (!BGInfoOption)
            {
                BGInfoOption = ds.transform.Find("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/BackgroundInfoTabPanel");
            }

            if (!OverviewInfoOption)
            {
                OverviewInfoOption = ds.transform.Find("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/CaseOverviewTab");
            }
            BGInfoOption.gameObject.SetActive(false);
            UpdateTabPos();
            //tm.SwitchTab (xmlTabName + tabCount);
        }
        tm.setTabName(tabCustomName);
        //Debug.Log (xmlTabName);
        //tm.SwitchTab (xmlTabName);
        tm.SwitchTab(tabCustomName);
        Destroy(BG.transform.Find("TabSelectorBG(Clone)").gameObject);
    }