Пример #1
0
    public void ToggleIsPatientImage(bool b)
    {
        print("Setting is patient for " + GetGuid() + " to " + b);
        isPatientImage = b;
        if (isPatientImage)
        {
            print(GlobalData.patientImageID);
            //if (GlobalData.patientImageID == null || GlobalData.patientImageID.Equals("")) {
            if (ds.GetImage(GlobalData.patientImageID) == null)
            {
                //No patient image set. Wait until Apply to set one
            }
            else if (displayImage?.sprite != null && !currentImage.GetComponent <OpenImageUploadPanelScript>().GetIsPatientImage())
            {
                //Ask to replace current image with patient image or replace patient image with current
                AskAboutReplace();
            }
            else
            {
                //Displayed image is null. Replace it with patient image
                if (updateThumbnail)
                {
                    currentImage.sprite = ds.GetImage(GlobalData.patientImageID).sprite;
                }
                LoadImage(ds.GetImage(GlobalData.patientImageID).sprite);
            }
        }
        else
        {
            LoadImage(ds.GetImage(GetGuid())?.sprite);
        }

        //transform.Find("ImageUploadPanel/Content/Row1/Toggle").GetComponent<Toggle>().isOn = isPatientImage;
    }
Пример #2
0
 /**
  * Updates all the section images to those in the imgDict
  */
 public void ChangeSectionImages()
 {
     foreach (Image t in SectionContentPar.GetComponentsInChildren <Image>())
     {
         if (t.transform.name.Equals("Image"))
         {
             t.sprite = null;
             t.sprite = ds.GetImage(t.transform.parent.Find("SectionLinkToText").GetComponent <TextMeshProUGUI>().text).sprite;
         }
     }
 }
    /**
     * 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);
    }
Пример #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);
         */
    }