Exemplo n.º 1
0
        private void PV_addv_Click(object sender, EventArgs e)
        {
            saved = false;
            buttonsCount++;
            int           rc = keyboard.buttons.Count; //rowsCount
            List <object> l  = new List <object>();

            Keyboard.text kbo = new Keyboard.text();
            l.Add(kbo);
            keyboard.buttons.Add(l);

            TableLayoutPanel row = PV_addRow();

            kbo.action.label = row.Controls[0].Text;

            kbUpd();
        }
Exemplo n.º 2
0
        private void PV_addh_Click(object sender, EventArgs e)
        {
            saved = false;
            buttonsCount++;
            Button btn = (Button)sender;
            int    row = int.Parse(btn.Name.Substring("PV_addh_".Length));

            Keyboard.text kbo = new Keyboard.text();
            keyboard.buttons[row].Add(kbo);

            //TableLayoutPanel rowel = btn.Parent as TableLayoutPanel;//preview.Controls.Find("PV_row_" + row.ToString(), false).FirstOrDefault() as TableLayoutPanel;

            Button PV_btn = PV_addCol(row);

            kbo.action.label = PV_btn.Text;

            kbUpd();
        }
Exemplo n.º 3
0
        private void menu_open_Click(object sender, EventArgs e)
        {
            if (!askSave())
            {
                return;
            }

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.DefaultExt   = "json";
            ofd.AddExtension = true;
            ofd.Title        = "Загрузка клавиатуры";
            ofd.Filter       = "JSON files(*.JSON)|*.JSON|Text files(*.txt)|*.txt";

            if (ofd.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            fileName = ofd.FileName;
            //mb(ofd.FileName);
            string text = System.IO.File.ReadAllText(ofd.FileName);

            try {
                var settings = new JsonSerializerSettings()
                {
                    DefaultValueHandling = DefaultValueHandling.Populate
                };
                Keyboard kb_ = new Keyboard();//JsonConvert.DeserializeObject<Keyboard>(text, settings); //mb(keyboard.buttons[0][0] as Keyboard.text);

                JObject kb = JObject.Parse(text);
                if (kb.ContainsKey("inline") && (bool)kb["inline"])
                {
                    kb_.inline = true; CBinline.Checked = true;
                }
                ;
                if (kb.ContainsKey("one_time") && (bool)kb["one_time"])
                {
                    kb_.one_time = true; CBonetime.Checked = true;
                }
                ;
                JArray rows = (JArray)kb["buttons"];
                for (int r = 0; r < rows.Count; r++)
                {
                    JArray cols = (JArray)rows[r];
                    kb_.buttons.Add(new List <object>());
                    for (int c = 0; c < cols.Count; c++)
                    {
                        //mb($"{r}_{c}\n{cols[c]}");
                        JObject btn   = (JObject)cols[c];
                        object  b_add = null;
                        switch ((string)btn["action"]["type"])
                        {
                        case "text":
                        {
                            var b = new Keyboard.text();

                            b.color          = (btn.ContainsKey("color")) ? (string)btn["color"] : "primary";
                            b.action.label   = (string)btn["action"]["label"];
                            b.action.payload = (string)btn["action"]["payload"];
                            b_add            = b;
                        } break;

                        case "open_link":
                        {
                            var b = new Keyboard.open_link();

                            b.color          = (btn.ContainsKey("color")) ? (string)btn["color"] : "primary";
                            b.action.label   = (string)btn["action"]["label"];
                            b.action.link    = (string)btn["action"]["link"];
                            b.action.payload = (string)btn["action"]["payload"];
                            b_add            = b;
                        } break;

                        case "location":
                        {
                            var b = new Keyboard.location();

                            b.color          = (btn.ContainsKey("color")) ? (string)btn["color"] : "primary";
                            b.action.payload = (string)btn["action"]["payload"];
                            b_add            = b;
                        } break;

                        case "vkpay":
                        {
                            var b = new Keyboard.vkpay();

                            b.color          = (btn.ContainsKey("color")) ? (string)btn["color"] : "primary";
                            b.action.hash    = (string)btn["action"]["hash"];
                            b.action.payload = (string)btn["action"]["payload"];
                            b_add            = b;
                        } break;

                        case "open_app":
                        {
                            var b = new Keyboard.open_app();

                            b.color           = (btn.ContainsKey("color")) ? (string)btn["color"] : "primary";
                            b.action.app_id   = int.Parse((string)btn["action"]["app_id"]);
                            b.action.owner_id = int.Parse((string)btn["action"]["owner_id"]);
                            b.action.label    = (string)btn["action"]["label"];
                            b.action.hash     = (string)btn["action"]["hash"];
                            b.action.payload  = (string)btn["action"]["payload"];
                            b_add             = b;
                        } break;
                        }

                        kb_.buttons[r].Add(b_add);
                    }
                }
                ;
                keyboard = kb_;

                kbUpd();

                preview.Controls.Clear();
                preview.RowStyles.Clear();
                preview.RowCount = 1;
                preview.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
                preview.Controls.Add(this.PV_addv, 0, 0);

                for (int r = 0; r < keyboard.buttons.Count; r++)
                {
                    TableLayoutPanel row = PV_addRow();
                    PV_btn_set(row.Controls[0] as Button, keyboard.buttons[r][0]);

                    for (int c = 1; c < keyboard.buttons[r].Count; c++)
                    {
                        PV_btn_set(PV_addCol(r), keyboard.buttons[r][c]);
                    }
                }
                saved = true;
            } catch (Exception err)
            {
                mb($"Ошибка: {err}");
            }
        }
Exemplo n.º 4
0
        private void CBbtype_SelectionChangeCommitted(object sender, EventArgs e)
        {
            saved = false;
            int row = now.row;
            int col = now.col;
            var kbn = keyboard.buttons[row][col];

            switch (CBbtype.SelectedItem as string)
            {
            case "Text":
            {
                if (kbn is Keyboard.text)
                {
                    return;
                }
                Keyboard.text kn = new Keyboard.text();
                switch (kbn)
                {
                case Keyboard.open_link t:
                    kn.action.label   = t.action.label;
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.location t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.vkpay t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.open_app t:
                    kn.action.label   = t.action.label;
                    kn.action.payload = t.action.payload;
                    break;
                }
                keyboard.buttons[row][col] = kn;
            }
            break;

            case "Open Link":
            {
                if (kbn is Keyboard.open_link)
                {
                    return;
                }
                Keyboard.open_link kn = new Keyboard.open_link();
                switch (kbn)
                {
                case Keyboard.text t:
                    kn.action.label   = t.action.label;
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.location t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.vkpay t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.open_app t:
                    kn.action.label   = t.action.label;
                    kn.action.payload = t.action.payload;
                    break;
                }
                keyboard.buttons[row][col] = kn;
            }
            break;

            case "Location":
            {
                if (kbn is Keyboard.location)
                {
                    return;
                }
                Keyboard.location kn = new Keyboard.location();
                switch (kbn)
                {
                case Keyboard.text t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.open_link t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.vkpay t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.open_app t:
                    kn.action.payload = t.action.payload;
                    break;
                }
                keyboard.buttons[row][col] = kn;
            }
            break;

            case "VK Pay":
            {
                if (kbn is Keyboard.vkpay)
                {
                    return;
                }
                Keyboard.vkpay kn = new Keyboard.vkpay();
                switch (kbn)
                {
                case Keyboard.text t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.open_link t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.location t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.open_app t:
                    kn.action.payload = t.action.payload;
                    break;
                }
                keyboard.buttons[row][col] = kn;
            }
            break;

            case "VK Apps":
            {
                if (kbn is Keyboard.open_app)
                {
                    return;
                }
                Keyboard.open_app kn = new Keyboard.open_app();
                switch (kbn)
                {
                case Keyboard.text t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.open_link t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.location t:
                    kn.action.payload = t.action.payload;
                    break;

                case Keyboard.vkpay t:
                    kn.action.payload = t.action.payload;
                    break;
                }
                keyboard.buttons[row][col] = kn;
            }
            break;
            }
            setPanels(row, col);
            kbUpd();
        }