void Start() { sameTab = false; MethodToCall = null; ID = new DefaultDataScript(); BG = GameObject.Find("GaudyBG"); ds = BG.GetComponentInChildren <ReaderDataScript>(); }
/** * Switches the active section. * Pass in the LinkToText */ public void SwitchSection(string sectionName, bool backwards = false) { string sName = null; if (SectionContentPar == null) { return; } //Enable the button of the section we're switching away from (show only the icon) Button[] sectionButtonsList = SectionContentPar.GetComponentsInChildren <Button>(); if (currentSection != null && !currentSection.Equals("")) { sName = currentSection.Replace(" ", "_") + "Button"; foreach (Button t in sectionButtonsList) { if (t.transform.name.Equals(sName)) { //t.transform.Find("StepIcon").GetComponent<Image>().color = new Color(1f, 1f, 1f, .5f); t.interactable = true; //t.GetComponent<Outline>().enabled = false; if (t.transform.Find("Overlay")) { t.transform.Find("Overlay").gameObject.SetActive(true); t.transform.Find("Overlay").GetComponent <CanvasGroup>().alpha = 1; } if (AllTabsVisited() && !t.transform.Find("AllTabsVisitedCheck").gameObject.activeInHierarchy) // !t.transform.GetChild(1).GetComponent<TextMeshProUGUI>().text.EndsWith("✓")) { //t.transform.GetChild(1).GetComponent<TextMeshProUGUI>().text += " ✓"; { t.transform.Find("AllTabsVisitedCheck").gameObject.SetActive(true); } break; } } } if (string.IsNullOrEmpty(sectionName)) //No section provided. Use default { if (ID == null) { ID = new DefaultDataScript(); } sectionName = ID.defaultSection; if (sectionButtonsList.Length > 0) { sectionName = sectionButtonsList[0].name.Remove(sectionButtonsList[0].name.Length - "Button".Length); } } else if (sectionName.Equals(currentSection)) //Trying to switch to current section { return; } if (currentSection != null) //Save data before switching away { currentSection = null; currentTab = null; } currentSection = sectionName; //Destroy Tab buttons and content //if (!ds.isReader) { /*foreach (Transform child in TabContentPar.GetComponentInChildren<Transform>()) { * Destroy (child.gameObject); * } * * foreach (Transform child in TabButtonContentPar.GetComponentInChildren<Transform>()) { * if (child.name != "AddTabButton") { * Destroy(child.gameObject); * } * }*/ int i = 0; for (i = 0; i < TabContentPar.transform.childCount; i++) { TabContentPar.transform.GetChild(i).gameObject.SetActive(false); Destroy(TabContentPar.transform.GetChild(i).gameObject); } for (i = 0; i < TabButtonContentPar.transform.childCount; i++) { TabButtonContentPar.transform.GetChild(i).gameObject.SetActive(false); Destroy(TabButtonContentPar.transform.GetChild(i).gameObject); } //} //Disable the current section's button sName = currentSection.Replace(" ", "_") + "Button"; foreach (Button t in sectionButtonsList) { if (t.name.Equals(sName)) { //t.transform.Find("StepIcon").GetComponent<Image>().color = new Color(1f, 1f, 1f, 1f); t.interactable = false; //t.GetComponent<Outline>().enabled = true; if (t.transform.Find("Overlay")) { t.transform.Find("Overlay").gameObject.SetActive(false); } t.GetComponent <ReaderSwapSectionScript>().SetColor(ds.GetImage(currentSection).color, true); } else { var sectionBtnScript = t.GetComponent <ReaderSwapSectionScript>(); if (sectionBtnScript != null) { sectionBtnScript.SetColor(ds.GetImage(sectionBtnScript.sectionName.text).color, false); } } } //Load in the Tab buttons for each tab List <string> sectionTabs = null; if (ds.GetData(currentSection) != null) { sectionTabs = ds.GetData(currentSection).GetTabList(); } i = 0; /*if (ds.isReader) { * //Need to spawn in a section object * GameObject currentTabContent = Instantiate(Resources.Load(GlobalData.resourcePath + "/Prefabs/Section"), TabContentPar.transform) as GameObject; * TabButtonContentPar = currentTabContent.transform.Find("TabButtons/Scroll View/Viewport/TabButtonContent").gameObject; * }*/ foreach (TabScrollButtonScript scrollButton in TabButtonContentPar.transform.parent.parent.parent.GetComponentsInChildren <TabScrollButtonScript>()) { scrollButton.gameObject.SetActive(false); /*if (scrollButton.name.EndsWith("Left")) { * NextFrame.Function(delegate { scrollButton.EnableButtons(); }); * }*/ } if (sectionTabs == null || sectionTabs.Count == 0) { } 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"; if (ds.GetData(currentSection).GetTabInfo(tabName).WasVisited()) { newTab.transform.Find("Visited").gameObject.SetActive(true); } else if (ds.forceInOrder && i > 2) { //newTab.transform.Find("Locked").gameObject.SetActive(true); //newTab.GetComponent<Button>().enabled = false; } } } //print(currentSection); //print(ds.GetImage(currentSection).color.ToString()); Color newColor; if (ds.GetImage(currentSection) != null) { newColor = ds.GetImage(currentSection).color; } else { newColor = new Color(1f, 1f, 1f, 0f); } if (newColor.a == 0f) //User never specified a color, load a default color { newColor = GlobalData.GDS.defaultGreen; //new Color(20.0f / 255.0f, 178.0f / 255.0f, 163.0f / 255.0f, 1); } TabContentPar.transform.parent.Find("TabButtons").GetComponent <Image>().color = newColor; TabContentPar.transform.parent.Find("ColorBorder").GetComponent <Image>().color = newColor; //Switch to the default/last active tab of the new section //Commented code below makes the user switch to the last active tab in a section. Doesn't work well with the Proceed To Next Step button /*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 ())); var tabList = ds.GetData(getCurrentSection()).GetTabList(); TabInfoScript newTabInfo; if (backwards) { newTabInfo = ds.GetData(getCurrentSection()).GetTabInfo(tabList[tabList.Count - 1]); } else { newTabInfo = ds.GetData(getCurrentSection()).GetTabInfo(tabList[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]); } }
/** * 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]); } }