示例#1
0
        public IEnumerable <KeyboardRow> GetKeyboardRows(long chatId)
        {
            if (!_employeeRecords.ContainsKey(chatId))
            {
                LoadRecords(chatId);
            }

            var employeeRow = new List <string>();

            foreach (var employeeRecord in _employeeRecords[chatId])
            {
                employeeRow.Add(employeeRecord.EmployeeName);
                if (string.Join(',', employeeRow.ToArray()).Length > 12)
                {
                    var keyboardRow = new KeyboardRow(employeeRow.ToArray());
                    employeeRow.Clear();
                    yield return(keyboardRow);
                }
            }

            if (employeeRow.Count > 0)
            {
                yield return(new KeyboardRow(employeeRow.ToArray()));
            }

            yield return(new KeyboardRow(new[] { PredefinedEmployeesKeyboard.AllKey }));
        }
        public void KeyboardRowtest()
        {
            var solution = new KeyboardRow();
            var input    = new string[] { "Hello", "Alaska", "Dad", "Peace" };
            var output   = new string[] { "Alaska", "Dad" };
            var results  = solution.FindWords(input);

            Assert.Equal(output.Length, results.Length);

            for (int i = 0; i < 2; i++)
            {
                Assert.Equal(output[i], results[i]);
            }
        }
示例#3
0
    private void Populate(GameObject parent, KeyboardRow row, KeyboardSkin skin)
    {
        foreach (KeyboardObject keyboardObject in row.Keys)
        {
            GameObject keyObj = new GameObject(keyboardObject.Name);
            keyObj.transform.parent   = parent.transform;
            keyObj.transform.position = Vector3.zero;

            // Set key background image (rounded rectangle)
            Image backgroundImage = keyObj.AddComponent <Image>();
            backgroundImage.sprite = skin.GetKeyBackgroundImage();
            backgroundImage.type   = Image.Type.Sliced;
            backgroundImage.color  = skin.GetKeyBackgroundColor();

            if (keyboardObject is Spacer)
            {
                backgroundImage.color = Color.clear;
            }

            // Add the button
            Button button = keyObj.AddComponent <Button>();

            // Adds the shadow
            Shadow shadow = keyObj.AddComponent <Shadow>();
            shadow.effectColor    = new Color(0, 0, 0, 80);
            shadow.effectDistance = new Vector2(0, -0.5f);

            // Adjust width and height
            RectTransform rectTransform = keyObj.GetComponent <RectTransform>();
            rectTransform.sizeDelta     = new Vector2(keyboardObject.Width, keyboardObject.Height);
            rectTransform.localPosition = Vector3.zero;

            GameObject image = null;

            // Add image
            if (keyboardObject is ImageObjectButton imageObjectButton)
            {
                image = new GameObject("Image");
                image.transform.parent = keyObj.transform;

                Image img = image.AddComponent <Image>();
                img.sprite = skin.Load <Sprite>(imageObjectButton.ImageKey);

                RectTransform imgRectTransform = image.GetComponent <RectTransform>();
                imgRectTransform.sizeDelta     = new Vector2(10, 10);
                imgRectTransform.localPosition = new Vector3(0, 0, 0);
            }

            // Add text
            if (keyboardObject is TextButton TextButton)
            {
                var color = backgroundImage.color;

                backgroundImage.color = new Color(
                    color.r,
                    color.g,
                    color.b,
                    0.8f);

                TextButtonBehaviour textButtonBehaviour = keyObj.AddComponent <TextButtonBehaviour>();
                textButtonBehaviour.Init(TextButton, skin);

                if (keyboardObject is Key key)
                {
                    KeyBehaviour keyBehaviour = keyObj.AddComponent <KeyBehaviour>();
                    keyBehaviour.Init(textButtonBehaviour.Text);
                    _keys.Add(keyBehaviour);

                    button.onClick.AddListener(() => { Write(key.Name); });
                }
                else
                {
                    textButtonBehaviour.SlightlyDarker();
                }
            }

            if (keyboardObject is UppercaseToggle uppercaseToggle)
            {
                _uppercaseBehaviour = image.AddComponent <UppercaseToggleBehaviour>();
                _uppercaseBehaviour.Init(uppercaseToggle, skin);

                button.onClick.AddListener(ToggleUppercase);
            }

            if (keyboardObject is BackspaceButton)
            {
                button.onClick.AddListener(Backspace);
            }

            if (keyboardObject is SymbolsToggle toggle)
            {
                _toggleableTextButton = keyObj.AddComponent <ToggleableTextButtonBehaviour>();
                _toggleableTextButton.Init(toggle);

                button.onClick.AddListener(ToggleSymbols);
            }

            if (keyboardObject is SpaceBarButton)
            {
                button.onClick.AddListener(() => { Write(" "); });
            }
        }

        UpdateUppercase();
    }