public void importRuleButtonPressed(int buttonIndex)
    {
        if (buttonIndex >= otherPartOfSpeech.Length)
        {
            return;
        }

        GameObject template = otherPartOfSpeech[buttonIndex];

        Debug.Log(template.transform.childCount);
        for (int i = 0; i < template.transform.childCount; i++)
        {
            RuleBannerPageSix bannerScriptOld = template.transform.GetChild(i).GetComponent <RuleBannerPageSix>();
            GameObject        instanceBanner  = (GameObject)Instantiate(prefabedBanner, thisPanel.transform);
            RuleBannerPageSix bannerScriptNew = instanceBanner.GetComponent <RuleBannerPageSix>();
            bannerScriptNew.description.text = bannerScriptOld.description.text;

            WordFormat newWordFormat = new WordFormat();
            // Copy the fields that is primary type or need not deep copy
            newWordFormat.numOfSyllable          = bannerScriptOld.format.numOfSyllable;
            newWordFormat.arabicStyle            = bannerScriptOld.format.arabicStyle;
            newWordFormat.consonantWithSemivowel = bannerScriptOld.format.consonantWithSemivowel;
            newWordFormat.specialVowel           = bannerScriptOld.format.specialVowel;
            newWordFormat.specialConsonant       = bannerScriptOld.format.specialConsonant;
            newWordFormat.vowelHolders           = bannerScriptOld.format.vowelHolders;

            // Deep copy other field
            Phoneme newLeading = new Phoneme();
            newLeading.addPhone(bannerScriptOld.format.specialLeading);
            Phoneme newEnding = new Phoneme();
            newEnding.addPhone(bannerScriptOld.format.specialEnding);
            newWordFormat.specialLeading = newLeading;
            newWordFormat.specialEnding  = newEnding;

            // Deep copy accent rules
            if (bannerScriptOld.format.accentRules != null && bannerScriptOld.format.accentRules.Length > 0)
            {
                WordFormat.AccentRule[] newAccentRuleList = new WordFormat.AccentRule[bannerScriptOld.format.accentRules.Length];
                for (int j = 0; j < newAccentRuleList.Length; j++)
                {
                    WordFormat.AccentRule newAccentRule = new WordFormat.AccentRule();
                    WordFormat.AccentRule oldAccentRule = bannerScriptOld.format.accentRules[j];
                    newAccentRule.backword = oldAccentRule.backword;
                    newAccentRule.position = oldAccentRule.position;
                    newAccentRule.accents  = new AccentPhone[oldAccentRule.accents.Length];

                    for (int k = 0; k < newAccentRule.accents.Length; k++)
                    {
                        newAccentRule.accents[k] = oldAccentRule.accents[k];
                    }

                    newAccentRuleList[j] = newAccentRule;
                }
                newWordFormat.accentRules = newAccentRuleList;
            }

            bannerScriptNew.format = newWordFormat;
        }
    }
예제 #2
0
    private Morphome[] getOnePartOfSpeech(GameObject panel)
    {
        List <Morphome> result = new List <Morphome>();

        for (int i = 0; i < panel.transform.childCount; i++)
        {
            Transform         go     = panel.transform.GetChild(i);
            RuleBannerPageSix script = go.GetComponent <RuleBannerPageSix>();
            WordFormat        format = script.format;
            result.Add(getFormat(format));
        }

        return(result.ToArray());
    }
    // Save the newly created rule
    public void onSaveButtonPressed()
    {
        aFormat = new WordFormat();
        aFormat.numOfSyllable = syllableNum;

        if (arabicFormatToggle.isOn)
        {
            aFormat.arabicStyle            = true;
            aFormat.consonantWithSemivowel = useSemivoweledConsonant.isOn;
            aFormat.consonantCluster       = useClusteredConsonant.isOn;

            List <Phoneme> forVowelHolder = new List <Phoneme>();
            for (int i = 0; i < arabicFormatContent.transform.childCount; i++)
            {
                ToBePickedScript script = arabicFormatContent.transform.GetChild(i).GetComponent <ToBePickedScript>();
                if (script.aVowelPhoneme == null)
                {
                    aFormat.arabicStyle            = false;
                    aFormat.consonantWithSemivowel = false;
                    aFormat.consonantCluster       = false;
                    break;
                }
                forVowelHolder.Add(script.aVowelPhoneme);
            }
            aFormat.vowelHolders = forVowelHolder.ToArray();
        }
        else
        {
            aFormat.arabicStyle = false;

            // Get accent rules
            if (accentNum > 0)
            {
                List <WordFormat.AccentRule> aList = new List <WordFormat.AccentRule>();
                for (int i = 0; i < accentPanel.transform.childCount; i++)
                {
                    AddAccentPageSix      script = accentPanel.transform.GetChild(i).GetComponent <AddAccentPageSix>();
                    WordFormat.AccentRule wfar   = new WordFormat.AccentRule();

                    if (script.coundBack.options.ToArray()[script.coundBack.value].text.Equals("Backward"))
                    {
                        wfar.backword = true;
                    }
                    else
                    {
                        wfar.backword = false;
                    }

                    try
                    {
                        if (script.positionField.text.Equals(""))
                        {
                            wfar.position = int.Parse(script.holder.text);
                        }
                        else
                        {
                            wfar.position = int.Parse(script.positionField.text);
                        }
                        if (wfar.position > syllableNum)
                        {
                            continue;
                        }

                        Manager         manager         = UnityEngine.Object.FindObjectOfType <Manager>();
                        LanguageManager languageManager = manager.languageManager;
                        AccentPhone[]   accents         = languageManager.accents;

                        if (script.accentType.value.Equals("all"))
                        {
                            wfar.accents = accents;
                        }
                        else
                        {
                            List <AccentPhone> potentialAccent = new List <AccentPhone>();
                            foreach (AccentPhone actp in accents)
                            {
                                string value   = script.accentType.options.ToArray()[script.accentType.value].text;
                                string IPA     = actp.IPA;
                                string contour = actp.Contour;
                                string level   = actp.Level;
                                if (value.Equals(IPA) || value.Equals(contour) || value.Equals(level))
                                {
                                    potentialAccent.Add(actp);
                                }
                            }
                            wfar.accents = potentialAccent.ToArray();
                        }
                        aList.Add(wfar);
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }
                aFormat.accentRules = aList.ToArray();
            }

            // Get special affix
            if (specialAffixToggle.isOn)
            {
                if (specialPrefixToggle.isOn && prefixPhoneme != null && prefixPhoneme.phones.Length > 0)
                {
                    aFormat.specialLeading = prefixPhoneme;
                }
                if (specialSuffixToggle.isOn && suffixPhoneme != null && suffixPhoneme.phones.Length > 0)
                {
                    aFormat.specialEnding = suffixPhoneme;
                }
            }

            // Get special phone
            if (specialPhoneToggle.isOn)
            {
                if (specialVowelToggle.isOn && specialPickedVowel != null && specialPickedVowel.Length > 0)
                {
                    aFormat.specialVowel = specialPickedVowel;
                }

                if (specialConsonantToggle.isOn && specialPickedConsonant != null && specialPickedConsonant.Length > 0)
                {
                    aFormat.specialConsonant = specialPickedConsonant;
                }
            }

            // Create a rule banner
            // prefabedRuleBanner
            // RuleBannerPageSix
        }

        if (oldBanner != null)
        {
            oldBanner.format           = aFormat;
            oldBanner.description.text = aFormat.getDescription();
        }
        if (oldBanner == null && fromThisPanel != null)
        {
            GameObject        instanceBanner = (GameObject)Instantiate(prefabedRuleBanner, fromThisPanel.transform);
            RuleBannerPageSix instanceScript = instanceBanner.GetComponent <RuleBannerPageSix>();
            instanceScript.format           = aFormat;
            instanceScript.description.text = aFormat.getDescription();
        }


        Destroy(this.transform.gameObject);
    }