Exemple #1
0
        /// <summary>
        /// Создает пустую клавиатуру для поля
        /// </summary>
        public void CreateFieldKeyboard()
        {
            Keyboard = new MessageKeyboard
            {
                OneTime = false
            };
            Buttons = new MessageKeyboardButton[3, 3];
            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    MessageKeyboardButton button = new MessageKeyboardButton
                    {
                        Action = new MessageKeyboardButtonAction()
                    };

                    button.Action.Label   = "[   ]";
                    button.Action.Payload = "{\"button\":\"C" + i + "_" + j + "\"}";
                    button.Color          = KeyboardButtonColor.Default;
                    Buttons[i, j]         = button;
                }
            }


            Keyboard.Buttons = new[] {
                new[] { Buttons[0, 0], Buttons[0, 1], Buttons[0, 2] },
                new[] { Buttons[1, 0], Buttons[1, 1], Buttons[1, 2] },
                new[] { Buttons[2, 0], Buttons[2, 1], Buttons[2, 2] }
            };
        }
Exemple #2
0
        private MessageKeyboard ConvertToVkKeyboard(INucleusKeyboard keyboard)
        {
            var keyboardVkButtons = new List <List <MessageKeyboardButton> >();

            foreach (var buttonsLine in keyboard.Buttons)
            {
                var line = new List <MessageKeyboardButton>();
                foreach (var button in buttonsLine)
                {
                    var vkButton = new MessageKeyboardButton();
                    vkButton.Action = new MessageKeyboardButtonAction()
                    {
                        AppId   = button.AppID == 0? null: button?.AppID,
                        Hash    = button.Hash,
                        Label   = button.Caption,
                        OwnerId = button.OwnerID == 0? null: button?.OwnerID,
                        Payload = new PayloadBuilder().BuildToStringFromModel(button.Payload),
                        Type    = button.Type,
                    };

                    vkButton.Color = button.Color;
                    line.Add(vkButton);
                }
                keyboardVkButtons.Add(line);
            }

            var vkKeyboard = new MessageKeyboard();

            vkKeyboard.Buttons = keyboardVkButtons;
            vkKeyboard.OneTime = keyboard.OneTimeKeyboard;
            return(vkKeyboard);
        }
Exemple #3
0
        public MessageKeyboard ToMessageKeyboard()
        {
            if (buttons == null)
            {
                return(null);
            }
            MessageKeyboard kb = new MessageKeyboard();

            kb.OneTime = one_time;
            MessageKeyboardButton[][] buts = new MessageKeyboardButton[buttons.Length][];
            for (int i = 0; i < buttons.Length; i++)
            {
                buts[i] = new MessageKeyboardButton[buttons[i].Length];
                for (int j = 0; j < buttons[i].Length; j++)
                {
                    buts[i][j] = new MessageKeyboardButton();

                    buts[i][j].Action         = new MessageKeyboardButtonAction();
                    buts[i][j].Action.Label   = buttons[i][j].action.label;
                    buts[i][j].Action.Payload = buttons[i][j].action.payload;
                    buts[i][j].Action.Type    = KeyboardButtonActionType.Text;

                    switch (buttons[i][j].color)
                    {
                    case "primary":
                        buts[i][j].Color = KeyboardButtonColor.Primary;
                        break;

                    case "negative":
                        buts[i][j].Color = KeyboardButtonColor.Negative;
                        break;

                    case "positive":
                        buts[i][j].Color = KeyboardButtonColor.Positive;
                        break;

                    default:
                        buts[i][j].Color = KeyboardButtonColor.Default;
                        break;
                    }
                }
            }

            kb.Buttons = buts;
            return(kb);
        }