public override void LayoutText(string content)
    {
        //base.LayoutText (content);

        TypedText.TypedTextSettings textTyperSettings = new TypedText.TypedTextSettings();
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(",", new TypedText.RandomTimeDelay(0.075f, 0.1f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(":", new TypedText.RandomTimeDelay(0.125f, 0.175f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay("-", new TypedText.RandomTimeDelay(0.125f, 0.175f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(".", new TypedText.RandomTimeDelay(0.3f, 0.4f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay("\n", new TypedText.RandomTimeDelay(0.5f, 0.6f)));
        if (Main.Instance.gameState.hasMadeAChoice)
        {
            textTyperSettings.splitMode        = TypedText.TypedTextSettings.SplitMode.Character;
            textTyperSettings.defaultTypeDelay = new TypedText.RandomTimeDelay(0.06f, 0.09f);
        }
        else
        {
            textTyperSettings.splitMode        = TypedText.TypedTextSettings.SplitMode.Character;
            textTyperSettings.defaultTypeDelay = new TypedText.RandomTimeDelay(0.05f, 0.09f);
        }

        richText                    = new RichTextSubstring(content);
        textTyper                   = new TypedText();
        textTyper.OnTypeText       += OnTypeText;
        textTyper.OnCompleteTyping += CompleteTyping;
        textTyper.TypeText(richText.plainText, textTyperSettings);

        // richText = new RichTextSubstring (content);
        // textTyper = new TypedText();
        // textTyper.OnTypeText += "c";
        // textTyper.OnCompleteTyping += "b";
        // textTyper.TypeText(richText.plainText, textTyperSettings);
    }
    public void AppendText(string content)
    {
        base.LayoutText(text.text + " " + content);

        TypedText.TypedTextSettings textTyperSettings = new TypedText.TypedTextSettings();
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(",", new TypedText.RandomTimeDelay(0.075f, 0.1f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(":", new TypedText.RandomTimeDelay(0.125f, 0.175f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay("-", new TypedText.RandomTimeDelay(0.125f, 0.175f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(".", new TypedText.RandomTimeDelay(0.3f, 0.4f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay("\n", new TypedText.RandomTimeDelay(0.5f, 0.6f)));
        if (Main.Instance.gameState.hasMadeAChoice)
        {
            textTyperSettings.splitMode        = TypedText.TypedTextSettings.SplitMode.Word;
            textTyperSettings.defaultTypeDelay = new TypedText.RandomTimeDelay(0.04f, 0.065f);
        }
        else
        {
            textTyperSettings.splitMode        = TypedText.TypedTextSettings.SplitMode.Character;
            textTyperSettings.defaultTypeDelay = new TypedText.RandomTimeDelay(0.03f, 0.0425f);
        }

        startText                   = text.text;
        richText                    = new RichTextSubstring(content);
        textTyper                   = new TypedText();
        textTyper.OnTypeText       += OnAppendText;
        textTyper.OnCompleteTyping += CompleteTyping;
        textTyper.TypeText(richText.plainText, textTyperSettings);
    }
Esempio n. 3
0
        private void TypistForm_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (rightAfterImport &&
                e.KeyChar != ' ' && e.KeyChar != '\b' &&
                !char.IsControl(e.KeyChar))
            {
                PracticeMode = true;
            }

            if (PracticeMode)
            {
                lblStatusBarMain.Text = "Typing...";

                timeOfLastCharTyped = DateTime.Now;

                if (e.KeyChar == '\b' && (!userSettings.AllowBackspace || TypedText.Length == 0))
                {
                    playBeep();
                    return;
                }

                TypedText.ProcessKey(e.KeyChar);

                displayErrorCount();
                displayProgressStatistics();

                if (IsFinished)
                {
                    PracticeMode = false;
                }

                picTyping.Invalidate();
            }
        }
Esempio n. 4
0
    public async ValueTask <ActionResult> SubmitTypingResult(TypedText typedText)
    {
        // TODO: Use a separate DTO class, do not accept business entities here.

        var result = await _typingResultProcessor.AddTypingResultAsync(typedText, ProfileId);

        return(CreatedAtAction(nameof(SubmitTypingResult), result, result));
    }
Esempio n. 5
0
        /// <summary>
        /// Gets Completed TypedText from the specified text string.
        /// </summary>
        /// <returns>The completed text, as it should display in Unity.</returns>
        /// <param name="text">Text to complete.</param>
        public TypedText GetCompletedText(string text)
        {
            var printText = RemoveCustomTags(text);

            var typedText = new TypedText();

            typedText.TextToPrint     = printText;
            typedText.Delay           = 0.0f;
            typedText.LastPrintedChar = printText[printText.Length - 1];
            typedText.IsComplete      = true;

            return(typedText);
        }
    public void DeleteText(string content)
    {
        base.LayoutText(text.text);

        TypedText.TypedTextSettings textTyperSettings = new TypedText.TypedTextSettings();
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(",", new TypedText.RandomTimeDelay(0.075f, 0.1f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(":", new TypedText.RandomTimeDelay(0.125f, 0.175f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay("-", new TypedText.RandomTimeDelay(0.125f, 0.175f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay(".", new TypedText.RandomTimeDelay(0.3f, 0.4f)));
        textTyperSettings.customPostTypePause.Add(new TypedText.CustomStringTimeDelay("\n", new TypedText.RandomTimeDelay(0.5f, 0.6f)));

        textTyperSettings.splitMode        = TypedText.TypedTextSettings.SplitMode.Character;
        textTyperSettings.defaultTypeDelay = new TypedText.RandomTimeDelay(0.03f, 0.0425f);

        startText                   = text.text;
        richText                    = new RichTextSubstring(text.text);
        textTyper                   = new TypedText();
        textTyper.OnTypeText       += OnDeleteText;
        textTyper.OnCompleteTyping += CompleteTyping;
        textTyper.TypeText(richText.plainText, textTyperSettings);
    }
Esempio n. 7
0
    private void OnEnable()
    {
        TypedText.TypedTextSettings typedTextSettings = new TypedText.TypedTextSettings();
        typedTextSettings.splitMode        = TypedText.TypedTextSettings.SplitMode.Character;
        typedTextSettings.defaultTypeDelay = new TypedText.RandomTimeDelay(letterTypeTime.x, letterTypeTime.y);

        typedText = new TypedText();
        typedText.TypeText(content, typedTextSettings);
        typedText.OnTypeText += OnTypeText;
        text.text             = "";

        Canvas.ForceUpdateCanvases();

        TextGenerator          textGenerator         = new TextGenerator();
        TextGenerationSettings textGeneratorSettings = text.GetGenerationSettings(new Vector2(0, 100));

        textGeneratorSettings.updateBounds = true;
        textGeneratorSettings.scaleFactor  = 1;
        textGenerator.Populate(content, textGeneratorSettings);
        rectTransform.sizeDelta = new Vector2(textGenerator.rectExtents.width * 2, rectTransform.sizeDelta.y);
        text.alignment          = TextAnchor.MiddleLeft;
    }
    public async ValueTask <TypingResultSubmitData> AddTypingResultAsync(TypedText typedText, string userId)
    {
        var text = await _textRepository.FindAsync(typedText.TextId)
                   .ConfigureAwait(false);

        if (text == null)
        {
            throw new InvalidOperationException("Text was not found.");
        }

        var typingSessionId = await _typingSessionRepository.NextIdAsync()
                              .ConfigureAwait(false);

        var typingSession          = new TypingSession(typingSessionId, userId, DateTime.UtcNow, new TypingSessionConfiguration());
        var typingSessionTextIndex = typingSession.AddText(new TypingSessionText(typedText.TextId, text.Value));
        await _typingSessionRepository.SaveAsync(typingSession)
        .ConfigureAwait(false);

        var userSessionId = await _userSessionRepository.NextIdAsync()
                            .ConfigureAwait(false);

        var userSession = new UserSession(userSessionId, userId, typingSessionId, DateTime.UtcNow, typedText.UserTimeZoneOffsetMinutes);
        await _userSessionRepository.SaveAsync(userSession)
        .ConfigureAwait(false);

        var typingResultId = Guid.NewGuid().ToString();

        await AddTypingResultAsync(userSessionId, new TextTypingResult(
                                       typingResultId,
                                       typingSessionTextIndex,
                                       typedText.StartedTypingUtc,
                                       DateTime.UtcNow,
                                       typedText.Events))
        .ConfigureAwait(false);

        return(new TypingResultSubmitData(typedText.TextId, typingSessionId, userSessionId, typingResultId));
    }
 protected override void Awake()
 {
     textTyper  = new TypedText();
     text.color = wetColor;
     base.Awake();
 }
Esempio n. 10
0
        /// <summary>
        /// Gets the typed text at the specified visibleCharacterIndex. This is the text that should be written
        /// to the Text component.
        /// </summary>
        /// <returns>The <see cref="TypedText"/> generated at the specified visible character index.</returns>
        /// <param name="text">Text to parse.</param>
        /// <param name="visibleCharacterIndex">Visible character index (ignores tags).</param>
        public TypedText GetTypedTextAt(string text, int visibleCharacterIndex)
        {
            var textAsSymbolList = CreateSymbolListFromText(text);

            // Split the text into shown and hide strings based on the actual visible characters
            int printedCharCount     = 0;
            var shownText            = string.Empty;
            var hiddenText           = string.Empty;
            var lastVisibleCharacter = char.MinValue;

            foreach (var symbol in textAsSymbolList)
            {
                if (printedCharCount <= visibleCharacterIndex)
                {
                    shownText += symbol.Text;

                    // Keep track of the visible characters that have been printed
                    if (!symbol.IsTag)
                    {
                        lastVisibleCharacter = symbol.Character.ToCharArray()[0];
                    }
                }
                else
                {
                    hiddenText += symbol.Text;
                }

                if (!symbol.IsTag)
                {
                    printedCharCount++;
                }
            }

            var activeTags = GetActiveTagsInSymbolList(textAsSymbolList, visibleCharacterIndex);

            // Remove closing tags for active tags from hidden text (move to before color hide tag)
            foreach (var activeTag in activeTags)
            {
                hiddenText = RemoveFirstOccurance(hiddenText, activeTag.ClosingTagText);
            }

            // Remove all color tags from hidden text so that they don't cause it to be shown
            // ex: <color=clear>This should <color=red>be clear</color></color> will show 'be clear" in red
            hiddenText = RichTextTag.RemoveTagsFromString(hiddenText, "color");

            // Add the hidden text, provided there is text to hide
            if (!string.IsNullOrEmpty(hiddenText))
            {
                var hiddenTag = RichTextTag.ClearColorTag;
                hiddenText = hiddenText.Insert(0, hiddenTag.TagText);
                hiddenText = hiddenText.Insert(hiddenText.Length, hiddenTag.ClosingTagText);
            }

            // Add back in closing tags in reverse order
            for (int i = 0; i < activeTags.Count; ++i)
            {
                hiddenText = hiddenText.Insert(0, activeTags[i].ClosingTagText);
            }

            // Remove all custom tags since Unity will display them when printed (it doesn't recognize them as rich text tags)
            var printText = shownText + hiddenText;

            foreach (var customTag in CustomTagTypes)
            {
                printText = RichTextTag.RemoveTagsFromString(printText, customTag);
            }

            // Calculate Delay, if active
            var delay = 0.0f;

            foreach (var activeTag in activeTags)
            {
                if (activeTag.TagType == "delay")
                {
                    try
                    {
                        delay = activeTag.IsOpeningTag ? float.Parse(activeTag.Parameter) : 0.0f;
                    }
                    catch (System.FormatException e)
                    {
                        var warning = string.Format(
                            "TypedTextGenerator found Invalid paramter format in tag [{0}]. " +
                            "Parameter [{1}] does not parse to a float. Exception: {2}",
                            activeTag,
                            activeTag.Parameter,
                            e);
                        Debug.Log(warning);
                        delay = 0.0f;
                    }
                }
            }

            var typedText = new TypedText();

            typedText.TextToPrint     = printText;
            typedText.Delay           = delay;
            typedText.LastPrintedChar = lastVisibleCharacter;
            typedText.IsComplete      = string.IsNullOrEmpty(hiddenText);

            return(typedText);
        }
Esempio n. 11
0
        /// <summary>
        /// The action to be taken when a button on the T9 grid is pressed.
        /// </summary>
        /// <param name="obj">The parameter passed into the command</param>
        public void ButtonClick(object obj)
        {
            if (obj is ActionEnum)
            {
                ActionEnum enumValue = (ActionEnum)obj;
                switch (enumValue)
                {
                case ActionEnum.Backspace:
                    if (!PredictiveMode && TypedText.Length > 0)
                    {
                        // Delete a character if there are characters to delete
                        if (_keyTimer.Enabled)
                        {
                            TempText          = String.Empty;
                            _keyTimer.Enabled = false;
                        }
                        else
                        {
                            TypedText = TypedText.Substring(0, TypedText.Length - 1);
                        }
                    }
                    else if (PredictiveMode)
                    {
                        // Is there temporary text?
                        if (TempText.Length > 0)
                        {
                            // Erase the last regex and get a new word
                            _predictiveHandler.DropLastRegex();
                            if (_predictiveHandler.Regex.Length > 0)
                            {
                                TempText = _predictiveHandler.NextMatch();
                            }
                            else
                            {
                                TempText = String.Empty;
                            }
                        }
                        else
                        {
                            if (TypedText[TypedText.Length - 1] == ' ')
                            {
                                // Delete the last word
                                TypedText = TypedText.TrimEnd();
                                int endOfLastWord = TypedText.LastIndexOf(' ');
                                TypedText = TypedText.Substring(0, endOfLastWord + 1);
                            }
                        }
                    }
                    break;

                case ActionEnum.InsertSpace:
                    if (PredictiveMode)
                    {
                        // Append the temporary text and a space
                        AppendTempText();
                        TypedText += " ";

                        // Clear the regex
                        _predictiveHandler.Regex = null;
                    }
                    else
                    {
                        // Insert a space, clear out the last key stuff
                        AppendTempText();
                        TypedText        += " ";
                        _lastPressedIndex = 0;
                        _lastPressedKey   = null;
                    }
                    break;

                case ActionEnum.NextWord:
                    // This key only does something if we're in predictive mode
                    if (PredictiveMode)
                    {
                        // Grab the next matching word
                        TempText = _predictiveHandler.NextMatch();
                    }
                    break;
                }
            }
            else
            {
                if (PredictiveMode)
                {
                    // Process the predictive key press
                    PredictiveButtonPress(obj as string);
                }
                else
                {
                    // Process the non-predictive keypress
                    NonPredictiveButtonPress(obj as string);
                }
            }
        }
Esempio n. 12
0
    /// <summary>
    /// 获取在指定位置的可打印文本
    /// </summary>
    /// <param name="_text"></param>
    /// <param name="_visibleCharacterIndex"></param>
    /// <returns></returns>
    public static TypedText GetTypedTextAt(string _text, int _visibleCharacterIndex)
    {
        CreateSymbolsFromText(_text);

        // 根据指定位置拆分为可见的字符串和不可见的字符串
        int typedCharCount       = 0;
        var shownText            = string.Empty;
        var hiddenText           = string.Empty;
        var lastVisibleCharacter = char.MinValue;

        for (int i = 0; i < m_ValidTextSymbolCount; ++i)
        {
            var symbol = m_TextSymbols[i];

            if (typedCharCount <= _visibleCharacterIndex)
            {
                shownText += symbol.Text;

                if (!symbol.IsTag)
                {
                    lastVisibleCharacter = symbol.Character[0];
                }
            }
            else
            {
                hiddenText += symbol.Text;
            }

            if (!symbol.IsTag)
            {
                ++typedCharCount;
            }
        }

        ParseActiveTags(_visibleCharacterIndex);
        for (int i = m_ActiveTags.Count - 1; i >= 0; --i)
        {
            shownText = shownText.Insert(shownText.Length, m_ActiveTags[i].ClosingTagText);
        }

        /*
         * foreach (var activeTag in m_ActiveTags)
         * {
         *  hiddenText = RemoveFirstOccurance(hiddenText, activeTag.ClosingTagText);
         * }
         *
         * // 移除颜色标签,否则会产生显示错误
         * // 例如:<color=clear>ABC <color=red>DEF</color></color> DEF会显示为红色,不会被隐藏
         * hiddenText = RichTextTag.RemoveTagsFromString(hiddenText, "color");
         *
         * // 添加隐藏标签
         * if (!string.IsNullOrEmpty(hiddenText))
         * {
         *  var hiddenTag = RichTextTag.CLEAR_COLOR_TAG;
         *  hiddenText = hiddenText.Insert(0, hiddenTag.TagText);
         *  hiddenText = hiddenText.Insert(hiddenText.Length, hiddenTag.ClosingTagText);
         * }
         *
         * // 加回富文本标签的结束文本
         * for (int i = 0; i < m_ActiveTags.Count; ++i)
         * {
         *  hiddenText = hiddenText.Insert(0, m_ActiveTags[i].ClosingTagText);
         * }
         */

        var typedText = new TypedText
        {
            Text            = shownText
            , LastTypedChar = lastVisibleCharacter
            , IsFinished    = string.IsNullOrEmpty(hiddenText)
        };

        return(typedText);
    }
Esempio n. 13
0
        private void UpdateText()
        {
            var keyboard        = Keyboard.GetState();
            int shiftDifference = 0;

            if (keyboard.IsKeyDown(Keys.LeftShift))
            {
                shiftDifference = 32;
            }
            if (keyboard.IsKeyDown(Keys.Q))
            {
                this.TextInField += (char)('q' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.W))
            {
                this.TextInField += (char)('w' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.E))
            {
                this.TextInField += (char)('e' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.R))
            {
                this.TextInField += (char)('r' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.T))
            {
                this.TextInField += (char)('t' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.Y))
            {
                this.TextInField += (char)('y' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.U))
            {
                this.TextInField += (char)('u' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.I))
            {
                this.TextInField += (char)('i' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.O))
            {
                this.TextInField += (char)('o' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.P))
            {
                this.TextInField += (char)('p' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.A))
            {
                this.TextInField += (char)('a' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.S))
            {
                this.TextInField += (char)('s' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.D))
            {
                this.TextInField += (char)('d' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.F))
            {
                this.TextInField += (char)('f' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.G))
            {
                this.TextInField += (char)('g' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.H))
            {
                this.TextInField += (char)('h' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.J))
            {
                this.TextInField += (char)('j' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.K))
            {
                this.TextInField += (char)('k' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.L))
            {
                this.TextInField += (char)('l' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.Z))
            {
                this.TextInField += (char)('z' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.X))
            {
                this.TextInField += (char)('x' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.C))
            {
                this.TextInField += (char)('c' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.V))
            {
                this.TextInField += (char)('v' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.B))
            {
                this.TextInField += (char)('b' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.N))
            {
                this.TextInField += (char)('n' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.M))
            {
                this.TextInField += (char)('m' - shiftDifference);
            }
            if (keyboard.IsKeyDown(Keys.Back) && TextInField.Length > 0)
            {
                this.TextInField = TextInField.Substring(0, TextInField.Length - 1);
                TypedText.TrimEnd();
                if (TypedText.Length > TextInField.Length)
                {
                    this.TypedText       = TextInField;
                    this.TypedTextLength = TextInField.Length;
                }
            }
        }