示例#1
0
        /// <summary>
        /// Return a string of a word with the "color" tag enveloping a character. The word is already reversed and fixed for rendering.
        /// </summary>
        public static string GetWordWithMarkedLetterText(Database.WordData arabicWord, ArabicAlphabetHelper.ArabicStringPart letterToMark,
                                                         Color color, MarkType type)
        {
            string tagStart = "<color=#" + GenericHelper.ColorToHex(color) + ">";
            string tagEnd   = "</color>";

            string text = ArabicAlphabetHelper.ProcessArabicString(arabicWord.Arabic);

            string startText  = text.Substring(0, letterToMark.fromCharacterIndex);
            string letterText = text.Substring(letterToMark.fromCharacterIndex,
                                               letterToMark.toCharacterIndex - letterToMark.fromCharacterIndex + 1);
            string endText = (letterToMark.toCharacterIndex >= text.Length - 1 ? "" : text.Substring(letterToMark.toCharacterIndex + 1));

            if (type == MarkType.SingleLetter)
            {
                return(startText + tagStart + letterText + tagEnd + endText);
            }
            else if (type == MarkType.FromStartToLetter)
            {
                return(tagStart + startText + letterText + tagEnd + endText);
            }
            else
            {
                return(startText + tagStart + letterText + endText + tagEnd);
            }
        }
示例#2
0
        /// <summary>
        /// Returns a coroutine which creates a string with a letter that flashes over frames, with an option to mark the text before it.
        /// </summary>
        public IEnumerator GetWordWithFlashingText(WordData wordData, int fromIndexToFlash, int toIndexToFlash, Color flashColor,
                                                   float cycleDuration, int numCycles, Action <string> callback, bool markPrecedingLetters = false)
        {
            string text = ProcessString(wordData.Text);

            // Special behaviour for chars
            var markedPart = text.Substring(fromIndexToFlash, 1);

            if (markedPart == " ")
            {
                text = text.Replace(" ", "_");
            }

            string markTagStart = $"<color=#{GenericHelper.ColorToHex(flashColor)}>";
            string markTagEnd   = "</color>";

            float timeElapsed        = 0f;
            int   numCompletedCycles = 0;

            float halfDuration = cycleDuration * 0.5f;

            while (numCompletedCycles < numCycles)
            {
                float interpolant = timeElapsed < halfDuration
                    ? timeElapsed / halfDuration
                    : 1 - ((timeElapsed - halfDuration) / halfDuration);
                string flashTagStart = $"<color=#{GenericHelper.ColorToHex(Color.Lerp(Color.black, flashColor, interpolant))}>";
                string flashTagEnd   = "</color>";

                string resultOfThisFrame = "";

                if (markPrecedingLetters)
                {
                    resultOfThisFrame += markTagStart;
                }
                resultOfThisFrame += text.Substring(0, fromIndexToFlash);
                if (markPrecedingLetters)
                {
                    resultOfThisFrame += markTagEnd;
                }
                resultOfThisFrame += flashTagStart;
                resultOfThisFrame += text.Substring(fromIndexToFlash, toIndexToFlash - fromIndexToFlash + 1);
                resultOfThisFrame += flashTagEnd;
                if (toIndexToFlash + 1 < text.Length)
                {
                    resultOfThisFrame += text.Substring(toIndexToFlash + 1);
                }

                callback(resultOfThisFrame);

                timeElapsed += Time.fixedDeltaTime;
                if (timeElapsed >= cycleDuration)
                {
                    numCompletedCycles++;
                    timeElapsed = 0f;
                }

                yield return(new WaitForFixedUpdate());
            }
        }
示例#3
0
        /// <summary>
        /// Returns a completely colored string of an Arabic word.
        /// </summary>
        public static string GetWordWithMarkedText(Database.WordData arabicWord, Color color)
        {
            string tagStart = "<color=#" + GenericHelper.ColorToHex(color) + ">";
            string tagEnd   = "</color>";

            string text = ArabicAlphabetHelper.ProcessArabicString(arabicWord.Arabic);

            return(tagStart + text + tagEnd);
        }
示例#4
0
        /// <summary>
        /// Returns a completely colored string of an Arabic word.
        /// </summary>
        public string GetWordWithMarkedText(WordData wordData, Color color)
        {
            string tagStart = "<color=#" + GenericHelper.ColorToHex(color) + ">";
            string tagEnd   = "</color>";

            string text = ProcessString(wordData.Text);

            return(tagStart + text + tagEnd);
        }
示例#5
0
        /// <summary>
        /// Return a string of a word with the "color" tag enveloping multiple characters. The word is already reversed and fixed for rendering.
        /// </summary>
        public static string GetWordWithMarkedLettersText(Database.WordData arabicWord, List <ArabicAlphabetHelper.ArabicStringPart> lettersToMark,
                                                          Color color)
        {
            // Sort letters To Mark
            lettersToMark.Sort((g1, g2) => g1.fromCharacterIndex.CompareTo(g2.fromCharacterIndex));

            // Remove duplicates
            for (int i = 0; i < lettersToMark.Count; ++i)
            {
                var toCheck = lettersToMark[i];

                for (int j = i + 1; j < lettersToMark.Count; ++j)
                {
                    if (toCheck.fromCharacterIndex == lettersToMark[j].fromCharacterIndex)
                    {
                        // Remove j
                        lettersToMark.RemoveAt(j);
                        --j;
                    }
                }
            }

            string tagStart = "<color=#" + GenericHelper.ColorToHex(color) + ">";
            string tagEnd   = "</color>";

            string text = ArabicAlphabetHelper.ProcessArabicString(arabicWord.Arabic);

            string markedText = "";

            int currentPosition = 0;

            for (int i = 0, len = lettersToMark.Count; i < len; ++i)
            {
                var letterToMark = lettersToMark[i];
                if (currentPosition < letterToMark.fromCharacterIndex)
                {
                    markedText += text.Substring(currentPosition, letterToMark.fromCharacterIndex - currentPosition);
                }

                markedText += tagStart;

                markedText += text.Substring(letterToMark.fromCharacterIndex,
                                             letterToMark.toCharacterIndex - letterToMark.fromCharacterIndex + 1);

                markedText     += tagEnd;
                currentPosition = letterToMark.toCharacterIndex + 1;
            }

            markedText += (lettersToMark[lettersToMark.Count - 1].toCharacterIndex >= text.Length - 1 ? "" : text.Substring(lettersToMark[lettersToMark.Count - 1].toCharacterIndex + 1));

            return(markedText);
        }
示例#6
0
        /// <summary>
        /// Returns a coroutine which creates a string with a letter that flashes over frames, with an option to mark the text before it.
        /// </summary>
        public static IEnumerator GetWordWithFlashingText(Database.WordData arabicWord, int fromIndexToFlash, int toIndexToFlash, Color flashColor,
                                                          float cycleDuration, int numCycles, System.Action <string> callback, bool markPrecedingLetters = false)
        {
            string text = ArabicAlphabetHelper.ProcessArabicString(arabicWord.Arabic);

            string markTagStart = "<color=#" + GenericHelper.ColorToHex(flashColor) + ">";
            string markTagEnd   = "</color>";

            float timeElapsed        = 0f;
            int   numCompletedCycles = 0;

            float halfDuration = cycleDuration * 0.5f;

            while (numCompletedCycles < numCycles)
            {
                float interpolant = timeElapsed < halfDuration
                    ? timeElapsed / halfDuration
                    : 1 - ((timeElapsed - halfDuration) / halfDuration);
                string flashTagStart = "<color=#" + GenericHelper.ColorToHex(Color.Lerp(Color.black, flashColor, interpolant)) + ">";
                string flashTagEnd   = "</color>";

                string resultOfThisFrame = "";

                if (markPrecedingLetters)
                {
                    resultOfThisFrame += markTagStart;
                }
                resultOfThisFrame += text.Substring(0, fromIndexToFlash);
                if (markPrecedingLetters)
                {
                    resultOfThisFrame += markTagEnd;
                }
                resultOfThisFrame += flashTagStart;
                resultOfThisFrame += text.Substring(fromIndexToFlash, toIndexToFlash - fromIndexToFlash + 1);
                resultOfThisFrame += flashTagEnd;
                if (toIndexToFlash + 1 < text.Length)
                {
                    resultOfThisFrame += text.Substring(toIndexToFlash + 1);
                }

                callback(resultOfThisFrame);

                timeElapsed += Time.fixedDeltaTime;
                if (timeElapsed >= cycleDuration)
                {
                    numCompletedCycles++;
                    timeElapsed = 0f;
                }

                yield return(new WaitForFixedUpdate());
            }
        }
示例#7
0
        string FormatCredits(string _txt)
        {
            // Format
            string lv0 = "<size=" + Level0FontPerc + "%><color=#" + GenericHelper.ColorToHex(Level0Color) + ">";
            string lv1 = "<size=" + Level1FontPerc + "%><color=#" + GenericHelper.ColorToHex(Level1Color) + ">";

            _txt = _txt.Replace("[0]", lv0);
            _txt = _txt.Replace("[0E]", "</color></size>");
            _txt = _txt.Replace("[1]", lv1);
            _txt = _txt.Replace("[1E]", "</color></size>");
            // Fix missing characters
            _txt = _txt.Replace("ö", "o");

            return(_txt);
        }
        private IEnumerator FlashLetterInWordCoroutine(LetterData letterToFlash, Color color)
        {
            if (letterData is LL_WordData) {
                var splitLetters = ArabicAlphabetHelper.SplitWord(AppManager.I.DB, ((LL_WordData)letterData).Data);

                int charPosition = 0;
                List<int> foundLetterIndices = new List<int>();

                for (int index = 0; index < splitLetters.Count; ++index) {
                    if (splitLetters[index].letter.Id == letterToFlash.Id) {
                        foundLetterIndices.Add(charPosition);
                    }

                    charPosition += splitLetters[index].letter.GetStringForDisplay().Length;
                }

                if (foundLetterIndices.Count != 0) {
                    string originalText = ((LL_WordData)letterData).TextForLivingLetter;

                    letterObjectView.Label.SetText(originalText);

                    float timeElapsed = 0f;
                    int numCompletedCycles = 0;

                    float halfDuration = FLASH_CYCLE_DURATION * 0.5f;

                    string preparedText = ArabicAlphabetHelper.ProcessArabicString(originalText);
                    preparedText = originalText;

                    while (numCompletedCycles < NUM_FLASH_CYCLES) {
                        float interpolant = timeElapsed < halfDuration
                            ? timeElapsed / halfDuration
                            : 1 - ((timeElapsed - halfDuration) / halfDuration);
                        string tagStart = "<color=#" + GenericHelper.ColorToHex(Color.Lerp(Color.black, color, interpolant)) + ">";
                        string tagEnd = "</color>";

                        string composedString = "";

                        for (int i = 0; i < foundLetterIndices.Count; i++) {
                            int startIdx = i == 0 ? 0 : foundLetterIndices[i - 1] + letterToFlash.GetStringForDisplay().Length;
                            int endIdx = foundLetterIndices[i] - 1;

                            composedString += preparedText.Substring(startIdx, endIdx - startIdx + 1);

                            composedString += tagStart;
                            composedString += preparedText.Substring(foundLetterIndices[i], letterToFlash.GetStringForDisplay().Length);
                            composedString += tagEnd;
                        }

                        composedString += preparedText.Substring(foundLetterIndices[foundLetterIndices.Count - 1] + letterToFlash.GetStringForDisplay().Length);

                        letterObjectView.Label.SetText(composedString);

                        timeElapsed += Time.fixedDeltaTime;
                        if (timeElapsed >= FLASH_CYCLE_DURATION) {
                            numCompletedCycles++;
                            timeElapsed = 0f;
                        }

                        yield return new WaitForFixedUpdate();
                    }

                    letterObjectView.Label.SetText(originalText);
                }
            }

            flashLetterInWordCoroutine = null;
        }