/** * Used for tabs and sections * This script should be placed on the object that will be clicked on */ /** * Initialize most variables */ void Awake() { hover = false; cursor = GameObject.Find("CursorContainer").transform.Find("Cursor").GetComponent <Image> (); entries = new List <Transform> (); foreach (Transform entry in transform.parent.GetComponentsInChildren <Transform>()) { if (entry.parent == transform.parent && entry.name != transform.name && !entry.name.Equals("Filler") && !entry.name.Equals("AddTabButton") && !entry.name.Equals("AddSectionButton")) { entries.Add(entry); } } scrollRectTransform = transform.parent.parent.parent.GetComponent <RectTransform> (); //Scroll view scrollScrollRect = scrollRectTransform.transform.GetComponent <ScrollRect> (); rt = transform.GetComponent <RectTransform> (); dMPos = 0; clickPoint = 0; clicked = false; tm = GameObject.Find("GaudyBG").GetComponent <TabManager> (); ds = tm.GetComponent <DataScript> (); string tabType = ""; if (transform.Find("TabButtonLinkToText") != null) { linkToText = transform.Find("TabButtonLinkToText").GetComponent <TextMeshProUGUI> ().text; tabType = ds.GetData(tm.getCurrentSection()).GetTabInfo(linkToText).type; } else { linkToText = transform.Find("SectionLinkToText").GetComponent <TextMeshProUGUI> ().text; } draggable = !(!linkToText.EndsWith("Section") && ds.GetData(tm.getCurrentSection()).GetTabInfo(linkToText).persistant); if (tabType.StartsWith("Personal Info") || tabType.StartsWith("Office Visit")) { draggable = true; } //draggable = (draggable && !linkToText.StartsWith("Background_InfoTab")); //draggable = (draggable && (Test Condition)); Use this format to add other conditionals to draggable, such as for background info }
/** * Loads the data into xmlDoc to use */ public void LoadXML() { string text = ds.GetData(tm.getCurrentSection(), transform.name.Substring(0, transform.name.Length - 3)); if (text == null) { Debug.Log("No Data to load"); ds.newTabs.Add(this.transform); return; } Debug.Log("Loaded data: " + text); xmlDoc = new XmlDocument(); xmlDoc.LoadXml(text); //LoadXMLData(); NextFrame.Function(LoadXMLData); }
/** * Opens the edit section panel. Pass in display text value */ public void OpenSectionPanel(TextMeshProUGUI t) { if (BG == null) { Start(); } tObject = t; sectionEditPrefab = Instantiate(Resources.Load("Writer/Prefabs/Panels/SectionEditorBG")) as GameObject; sectionEditPrefab.transform.SetParent(parentBG.transform, false); //editSectionPanel = transform.Find ("SectionEditorBG").gameObject; sectionEditPrefab.transform.SetAsLastSibling(); sectionEditPrefab.transform.SetSiblingIndex(sectionEditPrefab.transform.GetSiblingIndex() - 1); sectionEditPrefab.transform.Find(TitleValuePath).GetComponent <TMP_InputField>().text = t.text; colorPanelParent = sectionEditPrefab.transform.Find("SectionEditorPanel/Content/Row3"); customColorParent = colorPanelParent.Find("Column0/RowCustomColor/TMPInputField/ColorHexValue"); colorSlidersParent = colorPanelParent.Find("Column1"); deleteButton = sectionEditPrefab.transform.Find("SectionEditorPanel/Content/Row5/DeleteSectionButton"); // Checks if this tab has Patient Info, if so then this section cannot be deleted foreach (Transform child in tm.TabButtonContentPar.transform) { if (child.name == "Personal InfoTabButton") { deleteButton.gameObject.SetActive(false); } } //Check the Background Info box if the background info tab is already spawned //Debug.Log(string.Join(",", ds.GetData(tm.getCurrentSection()).GetTabList().ToArray())); bool spawn = (ds.GetData(tm.getCurrentSection()).GetTabList().Find((string obj) => obj.StartsWith("Background_InfoTab")) != null); Toggle bgInfoToggle = sectionEditPrefab.transform.Find("SectionEditorPanel/Content/Row1").GetComponentInChildren <Toggle>(); bgInfoToggle.isOn = false; if (spawn) { bgInfoToggle.isOn = true; } //Set the selected section icon at the bottom to the section's current icon SpriteHolderScript shs = ds.GetImage(tObject.text); if (shs == null) { sectionEditPrefab.transform.Find("SectionEditorPanel/Content/ScrollView/Viewport/Content").GetChild(0).GetComponentInChildren <Toggle>().isOn = true; } else { foreach (Toggle tog in sectionEditPrefab.transform.Find("SectionEditorPanel/Content/ScrollView/Viewport/Content").GetComponentsInChildren <Toggle>()) { if (tog.name.Equals(shs.referenceName)) { tog.isOn = true; } else { tog.isOn = false; } } } //Set the selected color to the section's current color SpriteHolderScript temp; if ((temp = ds.GetImage(tObject.text)) != null && temp.useColor) { bool isColorCustom = true; foreach (Toggle tog in colorPanelParent.GetChild(0).GetComponentsInChildren <Toggle>()) { if (tog.transform.GetComponent <Image> ().color == temp.color) { isColorCustom = false; tog.isOn = true; } else { tog.isOn = false; } } if (isColorCustom) { customColorParent.parent.parent.GetChild(0).GetComponent <Image> ().color = temp.color; customColorParent.parent.parent.GetChild(0).GetComponent <Toggle> ().isOn = true; /* * //Set slider values * colorSlidersParent.Find ("Row0/RSlider").GetComponent<Slider> ().value = temp.color.r; * colorSlidersParent.Find ("Row1/GSlider").GetComponent<Slider> ().value = temp.color.g; * colorSlidersParent.Find ("Row2/BSlider").GetComponent<Slider> ().value = temp.color.b; * string newTextString = ""; * newTextString += ((int)(temp.color.r*255)).ToString ("X").PadLeft (2, '0'); * newTextString += ((int)(temp.color.g*255)).ToString ("X").PadLeft (2, '0'); * newTextString += ((int)(temp.color.b*255)).ToString ("X").PadLeft (2, '0'); * //Debug.Log (newTextString); * customColorParent.GetComponentInChildren<TextMeshProUGUI> ().text = newTextString; */ } else { customColorParent.parent.parent.GetChild(0).GetComponent <Toggle> ().isOn = false; } //Set the slider values to match the section's current color colorSlidersParent.Find("Row0/RSlider").GetComponent <Slider> ().value = temp.color.r; colorSlidersParent.Find("Row1/GSlider").GetComponent <Slider> ().value = temp.color.g; colorSlidersParent.Find("Row2/BSlider").GetComponent <Slider> ().value = temp.color.b; string newTextString = ""; newTextString += ((int)(temp.color.r * 255)).ToString("X").PadLeft(2, '0'); newTextString += ((int)(temp.color.g * 255)).ToString("X").PadLeft(2, '0'); newTextString += ((int)(temp.color.b * 255)).ToString("X").PadLeft(2, '0'); //Debug.Log (newTextString); customColorParent.GetComponentInChildren <TextMeshProUGUI> ().text = newTextString; } //editSectionPanel.gameObject.SetActive (true); }
/** * 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); }
/** * Saves the dictionary as an XML file to the local system (both formatted/easy to read and non-formatted) */ public void SubmitToFile() { if (TabManager == null) { BG = GameObject.Find("GaudyBG"); TabManager = BG.GetComponentInChildren <TabManager>(); ds = BG.GetComponentInChildren <DataScript>(); fileName = GlobalData.fileName; path = GlobalData.filePath; } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } TabManager.sameTab = true; TabManager.AddToDictionary(); TabManager.GetSectionImages(); fileName = GlobalData.fileName; string tempFileName = fileName.Remove(fileName.Length - 3); string data = "<body>" + ds.GetData() + "</body>"; Debug.Log(data); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(data); string textDataExtension = "ced"; if (autosaving) { textDataExtension = "auto"; } //Outputting regular file StreamWriter sw = new StreamWriter(path + tempFileName + textDataExtension, false); //sw.WriteLine(data); sw.Close(); sw.Dispose(); File.WriteAllBytes(path + tempFileName + textDataExtension, EncryptStringToBytes_Aes(data)); if (!autosaving) //Don't want to save images when autosaving, just text for now. //Formatted, easy to read version { sw = new StreamWriter(path + tempFileName + "xml", false); xmlDoc.Save(sw); sw.Close(); sw.Dispose(); //Easy to read images (For testing) sw = new StreamWriter(path + "ImageTest" + tempFileName + "xml", false); xmlDoc.LoadXml(ds.GetImagesXML()); xmlDoc.Save(sw); sw.Close(); sw.Dispose(); File.Delete(path + tempFileName + "auto"); File.Delete(path + tempFileName + "iauto"); ds.RestartAutosave(); } //Images string imgDataExtension = "cei"; if (autosaving) { textDataExtension = "iauto"; // Autosaving should have the most recent save GlobalData.caseObj.dateModified = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; } sw = new StreamWriter(path + tempFileName + imgDataExtension, false); //sw.WriteLine (ds.GetImagesXML ()); sw.Close(); sw.Dispose(); File.WriteAllBytes(path + tempFileName + imgDataExtension, EncryptStringToBytes_Aes(ds.GetImagesXML())); //Update the caseObj to create the menu file Transform content = transform.Find("SaveCasePanel/Content"); GlobalData.caseObj.description = content.Find("Row3/TMPInputField/DescriptionValue").GetComponent <TMP_InputField>().text; GlobalData.caseObj.summary = content.Find("Row5/TMPInputField/SummaryValue").GetComponent <TMP_InputField>().text; GlobalData.caseObj.tags = GetComponent <AutofillTMP>().enteredTags.ToArray(); GlobalData.caseObj.audience = content.Find("Row7/TargetAudienceValue").GetComponent <TMP_Dropdown>().captionText.text; GlobalData.caseObj.difficulty = content.Find("Row7/DifficultyValue").GetComponent <TMP_Dropdown>().captionText.text; DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime localFileModified = File.GetLastWriteTime(GlobalData.filePath + GlobalData.fileName); //GlobalData.caseObj.dateModified = (long) DateTime.UtcNow.Subtract (unixEpoch).TotalSeconds;// Old method GlobalData.caseObj.dateModified = (long)localFileModified.ToUniversalTime().Subtract(unixEpoch).TotalSeconds; File.WriteAllText(GlobalData.filePath + GlobalData.fileName.Remove(GlobalData.fileName.Length - 4) + " menu.txt", ds.ServerUploader.GetMenuText()); //Old demo menu appending system /*if (GlobalData.demo) { * bool append = true; * * StreamReader reader = new StreamReader(Application.streamingAssetsPath + GlobalData.filePath + GlobalData.fileName); * string fileText = reader.ReadToEnd(); * string[] cases = fileText.Split(new string[] { "::" }, System.StringSplitOptions.RemoveEmptyEntries); * foreach (string s in cases) { * string[] caseSplit = s.Split(new string[] { "--" }, System.StringSplitOptions.None); * if (caseSplit[1].Equals(GlobalData.fileName)) { * caseSplit[3] = GlobalData.firstName + "_" + GlobalData.lastName; * fileText = fileText.Replace(s, string.Join("--", caseSplit)); * append = false; * break; * } * } * reader.Close(); * StreamWriter writer = new StreamWriter(Application.streamingAssetsPath + "/DemoCases/Cases/MenuCases/MenuCases.txt", append); * if (append) { * writer.Write("0--{0}--ECGC Guest--{1}--000000--Beginner--User Custom Case--This case was created by one of our guests!--N/A--0--ECGC Guests--1.0--N/A::", tempFileName + "ced", GlobalData.firstName + "_" + GlobalData.lastName); * } else { * writer.Write(fileText); //Write all of the cases including the edited one * } * writer.Close(); * }*/ Debug.Log("Saved: " + path + tempFileName); //b.interactable = false; if (autosaving) { autosaving = false; Debug.Log("Data Autosaved!"); ds.ShowMessage("Data Autosaved!", false); } else { Debug.Log("Data successfully submitted!"); ds.ShowMessage("Data saved successfully!", false); } }
/** * Handles uploading all data to the server. * Currently it's a mess because I'm not sure if we'll need to store more than the max_allowed_packet variable * but it can do that if needed. Just remove most of the commented things/format them and it should work for that. */ private IEnumerator Upload() { print("Uploading to server..."); string fileName = GlobalData.fileName.Replace(" ", "_"); string serverURL = GlobalData.serverAddress + "Test.php"; string urlParams = "?webfilename=" + fileName + "&webusername=clinical&webpassword=encounters&mode=download"; string wwwText = ""; string imagesXML = ds.GetImagesXML(); int i = -1; int MAP = 0; do { //For uploading WWWForm form = new WWWForm(); form.AddField("mode", "upload"); form.AddField("fileN", fileName); form.AddField("account_id", GlobalData.accountId); form.AddField("index", i); //Used for segmenting image uploads //form.AddField ("column", "xmlData"); byte[] fileBytes = GetFileAsByteArray("<body>" + ds.GetData() + "</body>"); Debug.Log("Case file size (in bytes): " + fileBytes.Length); form.AddBinaryData("xmlData", fileBytes, fileName, "text/xml"); if (MAP == 0) { wwwText = imagesXML; //use "Placeholder" if trying to segment data; } else if (MAP * i + MAP > imagesXML.Length) { wwwText = imagesXML.Substring(MAP * i); } else { wwwText = imagesXML.Substring(MAP * i, MAP); } byte[] fileBytesImg = GetFileAsByteArray(wwwText); Debug.Log("Image file size (in bytes): " + fileBytesImg.Length); if (imagesXML.Length > 10000000) //If the xml length is greater than max_allowed_packet { print("Error: Images exceed upload size limit"); } else { form.AddBinaryData("imgData", fileBytesImg, fileName, "text/xml"); } using (UnityWebRequest webRequest = UnityWebRequest.Post(serverURL, form)) { yield return(webRequest.SendWebRequest()); while (!webRequest.isDone) { Debug.Log(webRequest.uploadProgress); yield return(new WaitForSeconds(0.5f)); } if (webRequest.error != null) { print("Error: " + webRequest.error); } else { if (webRequest.uploadProgress == 1 && webRequest.isDone) { Debug.Log("Returned text from PHP: \n" + webRequest.downloadHandler.text); } } try { MAP = int.Parse(webRequest.downloadHandler.text); } catch (Exception) { //print ("Number was not returned in www.text"); } i++; } } while (false);//MAP * i < imagesXML.Length); serverURL = GlobalData.serverAddress + "Test.php"; //Upload the truncated case preview for the main menu yield return(StartCoroutine(UploadMenuEntry())); //ShowConfirmation ("Upload finished!"); ds.ShowMessage("Upload finished!"); }
/** * Switches the active tab * Pass in the formatted tabName */ public void SwitchTab(string tabName) { Transform[] tabButtonsList = TabButtonContentPar.GetComponentsInChildren <Transform>(); /* For debugging * string str = ""; * foreach (Transform t in tabButtonsList) { * str += t.name + ", "; * } * Debug.Log (str);*/ string tName = null; string section = currentSection; string tabType; //Check if the tab is specified. If not, let the user choose their tab TabInfoScript tabScript = null; //int n = -1; if (tabName == null || tabName.Equals("")) //If no provided tab name { tabScript = ds.GetData(section).GetCurrentTab(); //Check to see if there were any active tabs for the current section if (tabScript == null || tabScript.type == "") //If no active tab //n = 0; { SectionDataScript sds = ds.GetData(section); if (sds.GetTabList().Count > 0) //If the section has any tabs at all { string tempTabName = sds.GetTabList()[0]; tempTabName = tempTabName.Replace('_', ' ').Substring(0, tempTabName.Length - "Tab".Length); sds.SetCurrentTab(tempTabName); tabType = tempTabName; } else //Section has no tabs. New Section. Let user pick tab //transform.Find("TabSelectorBG").gameObject.SetActive(true); { return; //This will set the tab as the default specified in the Default data script //sds.SetCurrentTab (new TabInfoScript(0, ID.defaultTab)); //tab = ID.defaultTab; } } else //Set tab to the section's last active tab { tabType = tabScript.type; } Destroy(currentTab); currentTab = null; } else { //Remove the number at the end of tab and store it as n /*string[] tabSplit = Regex.Split (tab, @"[0-9]*$"); * n = int.Parse (tab.Substring (tabSplit [0].Length, tab.Length - tabSplit [0].Length)); * tab = tabSplit [0];*/ /* Debugging test * GameObject test = Resources.Load(gData.resourcesPath + "/Prefabs/Tabs/" + tab.Replace("_", " ").Substring(0, tab.Length - 3) + " Tab" + "/" + tab.Replace (" ", String.Empty).Replace("_", String.Empty)) as GameObject; * if (test == null) { * Debug.Log ("Cannot load tab prefab"); * //return; * } */ //If we're switching away from a tab, save the data if (currentTab != null) { if ((tabName + "Tab").Equals(currentTab.name) && section.Equals(currentSection)) { sameTab = true; AddToDictionary(); sameTab = false; return; } else { AddToDictionary(); tName = currentTab.name /*.Replace (" ", "_")*/ + "Button"; foreach (Transform t in tabButtonsList) { if (t.name.Equals(tName)) { t.GetChild(t.childCount - 1).gameObject.SetActive(false); t.GetComponent <Button>().interactable = true; } } Destroy(currentTab); currentTab = null; } } //Debug.Log(string.Join(",", ds.GetData (currentSection).GetTabList().ToArray())); tabType = ds.GetData(currentSection).GetTabInfo(tabName).type; if (tabType.ToLower().EndsWith("tab")) //Remove the "Tab" from the end of the type { tabType = tabType.Substring(0, tabType.Length - 3); } } Debug.Log("Section: " + currentSection + ", Name: " + tabName + ", Type: " + tabType); //Type is _ + Tab, but should be prefab folder - " Tab" //Load in the specified tab string name = tabName; string folder = tabType + " Tab"; tabType = tabType.Replace(" ", string.Empty) + "Tab"; /*if (tabType.Contains (" ")) { * //name = tabName.Replace (" ", "_") + "Tab"; * tabType = tabType.Replace (" ", String.Empty); * tabType = tabType + "Tab"; * folder = tabType + " Tab"; * } else { * //name = tabName.Replace (" ", "_") + "Tab"; * folder = tabType.Replace ("_", " "); * if (!folder.EndsWith (" Tab") && folder.EndsWith ("Tab")) { * folder = folder.Substring (0, folder.Length - 3) + " Tab"; * } else if (!folder.EndsWith ("Tab")) { * folder = folder + " Tab"; * } * tabType = tabType.Replace ("_", String.Empty); * if (!tabType.EndsWith ("Tab")) { * tabType = tabType + "Tab"; * } * /*if (!name.EndsWith ("Tab")) { * name = name + "Tab"; * } * }*/ name = tabName; //Folder should be the same as the prefab folder. Tab should equal the prefab name. Name should be the link to text GameObject par = TabContentPar; //Debug.Log ("Prefabs/Tabs/" + folder + "/" + tabType); GameObject newPrefab = Resources.Load(GlobalData.resourcePath + "/Prefabs/Tabs/" + folder + "/" + tabType) as GameObject; GameObject newTab = Instantiate(newPrefab, par.transform); newTab.name = name + "Tab"; //newTab.AddComponent<Text> ().text = "" + n; currentTab = newTab; ds.GetData(section).SetCurrentTab(name); if (newTab.transform.Find("AddFieldButton") && ds.GetImage(getCurrentSection()) != null) { newTab.transform.Find("AddFieldButton").GetComponent <Image>().color = ds.GetImage(getCurrentSection()).color; } //Adjust the buttons tName = currentTab.name /*.Replace (" ", "_")*/ + "Button"; foreach (Transform t in tabButtonsList) { if (t.name.Equals(tName)) { if (!ds.GetData(currentSection).IsPersistant(name)) { t.GetChild(t.childCount - 1).gameObject.SetActive(true); } t.GetComponent <Button>().interactable = false; t.GetComponent <ScriptButtonFixScript>().FixTab(); t.GetComponent <ScriptButtonFixScript>().FixTab(); } } if (addTabButton != null) { addTabButton.transform.SetAsLastSibling(); if (ds.GetData(currentSection).GetTabList().Count >= 8) { addTabButton.SetActive(false); } else { addTabButton.SetActive(true); } } //Debug.Log(ds.GetData(getCurrentSection()).GetAllData()); Resources.UnloadUnusedAssets(); }
/** * 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); } } }
/** * Run every frame. Determins the world position of the entry being held as well as the placeholder's location */ void Update() { if (clicked) { if (Math.Abs(Input.mousePosition.x - clickPoint) > 30 && Input.GetMouseButton(0) && draggable) { UpdateEntryList(); drag = true; clicked = false; Color highlight = GetComponent <Button>().colors.highlightedColor; ColorBlock buttonColors = GetComponent <Button>().colors; buttonColors.highlightedColor = new Color(highlight.r, highlight.g, highlight.b, 1f); regularNormalColor = buttonColors.normalColor; buttonColors.normalColor = new Color(1f, 1f, 1f); GetComponent <Button>().colors = buttonColors; transform.GetComponent <CanvasGroup> ().alpha = .5f; placeholder = Instantiate(Resources.Load(GlobalData.resourcePath + "/Prefabs/Placeholder") as GameObject, transform.parent); transform.GetComponent <LayoutElement> ().ignoreLayout = true; placeholder.transform.SetSiblingIndex(transform.GetSiblingIndex()); placeholder.name = "placeholder"; placeholder.GetComponent <LayoutElement> ().preferredWidth = rt.rect.width; // - transform.parent.GetComponent<HorizontalLayoutGroup> ().spacing * 2; placeholder.GetComponent <LayoutElement> ().flexibleWidth = 0f; transform.GetComponent <ScriptButtonFixScript> ().FixPlaceholder(); LayoutRebuilder.ForceRebuildLayoutImmediate(placeholder.transform.parent.parent.GetComponent <RectTransform> ()); transform.SetAsLastSibling(); } else if (!Input.GetMouseButton(0)) { //tm.SwitchTab (linkToText); clicked = false; } } else if (drag) { //transform.parent.GetComponent<LayoutElement> ().ignoreLayout = true; //Check how far down the list of sibling entrys that this entry physically is rt.position = new Vector3(Input.mousePosition.x - dMPos, rt.position.y, 0f); int pos = 0; foreach (Transform entry in entries) { if (entry.transform.position.x < transform.position.x) { pos++; } else if (draggable) { } else if (!linkToText.EndsWith("Section") && ds.GetData(tm.getCurrentSection()).GetTabInfo(entry.Find("TabButtonLinkToText").GetComponent <TextMeshProUGUI> ().text).persistant) //If you're to the left of a persistant tab { pos++; } else if (!linkToText.EndsWith("Section") && entry.name.Equals("BackgroundData")) { pos++; } } placeholder.transform.SetSiblingIndex(pos); //Set the placeholder index to match Rect r = placeholder.GetComponent <RectTransform> ().rect; r.Set(r.x, r.y, rt.rect.width, r.height); //This is used for scrolling when held at the top/bottom of the scroll area. //Adjust the .01f to change the speed of the scrolling (.01 means 1% per frame as far as I can tell) Vector3[] corners = new Vector3[4]; scrollRectTransform.GetWorldCorners(corners); if (transform.position.x > corners[2].x - 40 && scrollScrollRect.verticalNormalizedPosition < 1.0f) { scrollScrollRect.verticalNormalizedPosition += .01f; } else if (transform.position.x < corners[0].x + 40 && scrollScrollRect.verticalNormalizedPosition > 0.0f) { scrollScrollRect.verticalNormalizedPosition -= .01f; } //If the user let go if (!Input.GetMouseButton(0)) { drag = false; ColorBlock buttonColors = GetComponent <Button>().colors; Color highlight = buttonColors.highlightedColor; buttonColors.highlightedColor = new Color(highlight.r, highlight.g, highlight.b, (200 / 255f)); buttonColors.normalColor = regularNormalColor; GetComponent <Button>().colors = buttonColors; transform.GetComponent <CanvasGroup> ().alpha = 1.0f; transform.GetComponent <LayoutElement> ().ignoreLayout = false; //Double check the position pos = 0; foreach (Transform entry in entries) { //Debug.Log ("dropped: " + transform.parent.localPosition.y + ", entry: " + entry.transform.localPosition.y); if (transform.position.x > entry.transform.position.x) { pos++; } /*else if (!linkToText.EndsWith("Section") && ds.GetData (tm.getCurrentSection ()).GetTabInfo (entry.Find ("TabButtonLinkToText").GetComponent<Text> ().text).persistant) { * //If you're to the left of a persistant tab * pos++; * }*/ } //Destroy the placeholder and set the entry to the correct new location transform.SetSiblingIndex(pos); placeholder.transform.SetAsLastSibling(); Destroy(placeholder); placeholder = null; //Adjust the mouse icon accordingly if (!hover) { cursor.sprite = cursorPicture; } List <Transform> buttons = new List <Transform> (); for (int i = 0; i < transform.parent.childCount; i++) { if (!transform.parent.GetChild(i).name.Equals("placeholder") && !transform.parent.GetChild(i).name.Equals("Filler") && !transform.parent.GetChild(i).name.Equals("AddTabButton") && !transform.parent.GetChild(i).name.Equals("AddSectionButton")) { buttons.Add(transform.parent.GetChild(i)); } } foreach (Transform t in buttons) { if (!linkToText.EndsWith("Section")) { //Debug.Log (t.name + ", SETTING POSITION: " + t.GetSiblingIndex() + ", FROM" + ds.GetData(tm.getCurrentSection ()).GetTabInfo (t.Find("TabButtonLinkToText").GetComponent<Text>().text).position); ds.GetData(tm.getCurrentSection()).GetTabInfo(t.Find("TabButtonDisplayText").GetComponent <TextMeshProUGUI> ().text).SetPosition(t.GetSiblingIndex()); } else { if (!t.name.Equals("AddSectionButton")) { ds.GetData(t.Find("SectionLinkToText").GetComponent <TextMeshProUGUI> ().text).SetPosition(t.GetSiblingIndex()); } } } transform.GetComponent <ScriptButtonFixScript> ().FixPlaceholder(); transform.GetComponent <Button> ().OnDeselect(null); PointerEventData pointer = new PointerEventData(EventSystem.current); ExecuteEvents.Execute(transform.gameObject, pointer, ExecuteEvents.pointerEnterHandler); } } }