Ejemplo n.º 1
0
 /**
  * Adds the section buttons' icons to the imgDict
  */
 public void GetSectionImages()
 {
     allChildren = SectionContentPar.GetComponentsInChildren <Transform>();
     foreach (Transform t in allChildren)
     {
         if (t.name.Equals("Image"))
         {
             if (t.GetComponent <Image>().sprite == null)
             {
                 continue;
             }
             if (t.GetComponent <Image>().sprite.name != null && !t.GetComponent <Image>().sprite.name.Equals(""))
             {
                 string             s   = t.GetComponent <Image>().sprite.name;
                 SpriteHolderScript shs = new SpriteHolderScript(s);
                 ds.AddImg(t.parent.Find("SectionLinkToText").GetComponent <TextMeshProUGUI>().text.Replace(GlobalData.EMPTY_WIDTH_SPACE + "", ""), t.GetComponent <Image>().sprite);
                 foreach (Image img in shs.iconHolder.GetComponentsInChildren <Image>())
                 {
                     if (img.sprite.name.Equals(s))
                     {
                         ds.AddImg(t.parent.Find("SectionLinkToText").GetComponent <TextMeshProUGUI>().text.Replace(GlobalData.EMPTY_WIDTH_SPACE + "", ""), img.transform.parent.name);
                         break;
                     }
                 }
             }
         }
     }
     //Debug.Log (string.Join (", ", ds.GetImages ().Keys.ToArray ()));
     //Debug.Log (string.Join ("-----", ds.GetImages ().Select (x => x.Value.GetXMLText()).ToArray ()));
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Replace the patient's image with the currently uploaded image
    /// </summary>
    public void ReplacePatientImage()
    {
        ds.AddImg(GlobalData.patientImageID, displayImage.sprite);

        patientCamera.transform.GetChild(0).gameObject.SetActive(true);
        Image i = patientCamera.transform.Find("Canvas/Image").GetComponent <Image>();

        i.sprite = displayImage.sprite;
    }
    /**
     * 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();
    }
Ejemplo n.º 4
0
    /**
     * Adds a new section from the SectionCreatorBG
     * Pass in the display name
     */
    public void addSection(TextMeshProUGUI sectionName)
    {
        if (sectionName.text.Equals("") || sectionName.text.Length == 0)
        {
            ds.ShowMessage("Cannot leave step name blank", true);
            return;
        }
        if (!ds.IsValidName(sectionName.text, "Section"))
        {
            //ds.ShowMessage ("Section name not valid. Cannot use:\n*, &, <, >, or //", true);
            throw new System.Exception("Name not valid: Please rename your step");
        }
        string xmlSectionName = sectionName.text.Replace(" ", "_").Replace(GlobalData.EMPTY_WIDTH_SPACE + "", "") + "Section";

        //Try to add the section. Return if any errors
        try {
            ds.AddSection(xmlSectionName);
        } catch (System.Exception e) {
            ds.ShowMessage("Cannot name two steps the same", true);
            Debug.Log(e.Message);
            return;
        }

        //Create the section button and link it accordingly
        GameObject newSection = Resources.Load(GlobalData.resourcePath + "/Prefabs/SectionButton") as GameObject;

        TextMeshProUGUI[] children = newSection.GetComponentsInChildren <TextMeshProUGUI>();
        foreach (TextMeshProUGUI child in children)
        {
            if (child.name.Equals("SectionLinkToText"))   //Where the button links to
            {
                child.text = xmlSectionName;
            }
            else if (child.name.Equals("SectionDisplayText"))     //What the button displays
            {
                child.text = sectionName.text;
            }
        }
        newSection.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = sectionName.text;

        //Spawn in the section button
        newSection      = Instantiate(newSection, SectionButtonContentPar.transform);
        newSection.name = xmlSectionName.Replace(" ", "_") + "Button";
        SectionButtonContentPar.transform.Find("AddSectionButton").SetAsLastSibling();
        SectionButtonContentPar.transform.Find("Filler").SetAsLastSibling();

        //Spawns/Removes the Background Info tab as needed
        bool   spawn     = transform.Find("SectionCreatorPanel/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 (BGInfoOption != null)
        {
            if (!spawn && tabExists)
            {
                ds.GetComponent <EditTabScript>().removeTab(tabName);

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

                //deactivate the option to select BG Info from the TabSelector
                BGInfoOption.gameObject.SetActive(false);
            }
        }
        else if (OverviewInfoOption != null)
        {
            if (!spawn && tabExists)
            {
                ds.GetComponent <EditTabScript>().removeTab(tabName);

                //reactivate the option to select BG Info from the TabSelector
                OverviewInfoOption.gameObject.SetActive(true);
            }
            else if (spawn && !tabExists)
            {
                AddBGInfoTab("Case Overview", xmlSectionName);

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

        //Set the section button's icon as the user's choice
        Sprite spr        = null;
        string imgRefName = "";

        Transform[] sectionIcons = transform.Find("SectionCreatorPanel/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;
                imgRefName = t.Find("Icon").GetComponent <Image>().name;
                break;
            }
        }
        if (spr != null)
        {
            newSection.transform.Find("Image").GetComponent <Image>().sprite = spr;
        }

        //Sets the section button's color as the selected color.
        Toggle[] colorButtons = transform.Find("SectionCreatorPanel/Content/Row3/Column0").GetComponentsInChildren <Toggle>();
        foreach (Toggle tog in colorButtons)
        {
            if (tog.isOn)
            {
                newSection.transform /*.Find ("Image")*/.GetComponent <Image>().color = tog.GetComponent <Image>().color;
                ds.AddImg(xmlSectionName, imgRefName);
                ds.GetImage(xmlSectionName).useColor = true;
                ds.GetImage(xmlSectionName).color    = tog.GetComponent <Image>().color;
            }
        }

        //This script is parented to the add section panel, so let's disable it
        gameObject.SetActive(false);

        bool startEnabled = true; //Whether you want to switch to tabs upon creation or not


        //Either switches to the newly created section or stays on the current section
        if (startEnabled)
        {
            tm.SwitchSection(xmlSectionName);
        }
        else
        {
            Transform[] components = newSection.GetComponentsInChildren <Transform>();
            foreach (Transform c in components)
            {
                if (!c.name.Equals(newSection.name))
                {
                    c.gameObject.SetActive(false);
                }
            }
            newSection.transform.GetChild(0).gameObject.SetActive(true); //The image
            newSection.GetComponent <Button>().interactable = true;
        }


        /* This spawns in a personal info tab by default. Place above startEnabled if needed
         *      //Create the SectionDataScript so the section can hold data and
         *      SectionDataScript sds = new SectionDataScript ();
         *      DefaultDataScript dds = new DefaultDataScript ();
         *      sds.AddData(dds.defaultTab.Replace(" ", "_") + "Tab" + 0, null);
         *      ds.AddData (xmlSectionName, sds.getTabList () [0], null);
         */
    }