private void bEditAction_Click(object sender, EventArgs e)
 {
     if (lbAction.SelectedItem != null)
     {
         ActionType at = scene.getActionType(lbAction.SelectedItem as ActionU);
         if (at != null)
         {
             AddAction newForm = new AddAction(lbAction.SelectedItem as ActionU, at);
             newForm.FormClosed += AddAction_FormClosed;
             newForm.Owner       = this;
             newForm.ShowDialog();
         }
         else
         {
             MessageBox.Show("Not this type action");
         }
     }
 }
 private void bSave_Click(object sender, EventArgs e)
 {
     if (tb.Text != "")
     {
         if (lbActions.SelectedItem != null)
         {
             AddAction newForm = new AddAction(lbActions.SelectedItem as ActionType, usingM, tb.Text);
             newForm.Owner = this;
             this.Hide();
             newForm.ShowDialog();
             this.Close();
         }
         else
         {
             MessageBox.Show("No select action");
         }
     }
     else
     {
         MessageBox.Show("No name");
     }
 }
Exemple #3
0
        public void constrList(List <Ent> list, Dictionary <string, object> fields)
        {
            foreach (Ent ent in list)
            {
                if (ent.Type == "Number")
                {
                    Label label = new Label();
                    label.Location = new Point(12, yPos);
                    yPos          += 25;
                    label.Text     = ent.Name;
                    TextBox textBox = new TextBox();
                    textBox.Location = new Point(12, yPos);
                    yPos            += 35;

                    object v;
                    fields.TryGetValue(ent.Name, out v);
                    if (fields.TryGetValue(ent.Name, out v))
                    {
                        textBox.Text += (double)v;
                    }
                    else
                    {
                        fields.Add(ent.Name, 0);
                        textBox.Text = "0";
                    }
                    textBox.KeyPress    += KeyPressNumber;
                    textBox.TextChanged += TextChangedNumber;
                    textBox.Size         = new Size(300, 23);


                    textBox.TextChanged += (s, e) =>
                    {
                        double value;
                        Double.TryParse((s as TextBox).Text, out value);
                        fields[ent.Name] = value;
                    };

                    this.Controls.Add(label);
                    this.Controls.Add(textBox);
                }
                else if (ent.Type == "Text")
                {
                    Label label = new Label();
                    label.Location = new Point(12, yPos);
                    yPos          += 25;
                    label.Text     = ent.Name;
                    TextBox textBox = new TextBox();
                    textBox.Location = new Point(12, yPos);
                    yPos            += 35;
                    textBox.Size     = new Size(300, 23);

                    object v;
                    fields.TryGetValue(ent.Name, out v);
                    if (fields.TryGetValue(ent.Name, out v))
                    {
                        textBox.Text = (string)v;
                    }
                    else
                    {
                        fields.Add(ent.Name, "");
                    }

                    textBox.TextChanged += (s, e) =>
                    {
                        fields[ent.Name] = (s as TextBox).Text;
                    };

                    this.Controls.Add(label);
                    this.Controls.Add(textBox);
                }
                else if (ent.Type == "Position")
                {
                    Position pos = new Position();


                    Label label = new Label();
                    label.Location = new Point(12, yPos);
                    yPos          += 25;
                    label.Text     = ent.Name;

                    TextBox textBox1 = new TextBox();
                    textBox1.Location     = new Point(12, yPos);
                    textBox1.Text         = "0";
                    textBox1.KeyPress    += KeyPressNumber;
                    textBox1.TextChanged += TextChangedNumber;
                    textBox1.Size         = new Size(80, 23);
                    textBox1.TextChanged += (s, e) =>
                    {
                        double value;
                        Double.TryParse((s as TextBox).Text, out value);
                        pos.x = value;
                    };

                    TextBox textBox2 = new TextBox();
                    textBox2.Location     = new Point(112, yPos);
                    textBox2.Text         = "0";
                    textBox2.KeyPress    += KeyPressNumber;
                    textBox2.TextChanged += TextChangedNumber;
                    textBox2.Size         = new Size(80, 23);
                    textBox2.TextChanged += (s, e) =>
                    {
                        double value;
                        Double.TryParse((s as TextBox).Text, out value);
                        pos.y = value;
                    };

                    TextBox textBox3 = new TextBox();
                    textBox3.Location     = new Point(212, yPos);
                    textBox3.Text         = "0";
                    textBox3.KeyPress    += KeyPressNumber;
                    textBox3.TextChanged += TextChangedNumber;
                    textBox3.Size         = new Size(80, 23);
                    textBox3.TextChanged += (s, e) =>
                    {
                        double value;
                        Double.TryParse((s as TextBox).Text, out value);
                        pos.z = value;
                    };

                    yPos += 35;

                    object v;
                    fields.TryGetValue(ent.Name, out v);
                    if (fields.TryGetValue(ent.Name, out v))
                    {
                        try
                        {
                            textBox1.Text = "" + ((JObject)v).GetValue("x");
                            textBox2.Text = "" + ((JObject)v).GetValue("y");
                            textBox3.Text = "" + ((JObject)v).GetValue("z");
                        }
                        catch
                        {
                            textBox1.Text = "" + ((Position)v).x;
                            textBox2.Text = "" + ((Position)v).y;
                            textBox3.Text = "" + ((Position)v).z;
                        }
                    }
                    else
                    {
                        fields.Add(ent.Name, pos);
                    }


                    this.Controls.Add(label);
                    this.Controls.Add(textBox1);
                    this.Controls.Add(textBox2);
                    this.Controls.Add(textBox3);
                }
                else if (ent.Type == "ListObject")
                {
                    List <Dictionary <string, object> > entList;
                    object v;
                    fields.TryGetValue(ent.Name, out v);
                    if (fields.TryGetValue(ent.Name, out v))
                    {
                        try
                        {
                            entList = (v as JArray).ToObject <List <Dictionary <string, object> > >();
                        }
                        catch
                        {
                            entList = (List <Dictionary <string, object> >)v;
                        }
                    }
                    else
                    {
                        entList = new List <Dictionary <string, object> >();
                        fields.Add(ent.Name, entList);
                    }

                    Label label = new Label();
                    label.Location = new Point(12, yPos);
                    yPos          += 25;
                    label.Text     = ent.Name;

                    ListBox listBox = new ListBox();
                    listBox.Location   = new Point(12, yPos);
                    listBox.DataSource = entList;

                    Button bAdd = new Button();
                    bAdd.Text     = "Добавить";
                    bAdd.Location = new Point(142, yPos);
                    bAdd.Click   += (s, e) =>
                    {
                        AddAction newForm = new AddAction(ent.ents, entList);
                        newForm.Owner       = this;
                        newForm.FormClosed += (sen, ee) =>
                        {
                            listBox.DataSource = null;
                            listBox.DataSource = entList;
                        };
                        newForm.ShowDialog();
                    };

                    yPos += 35;


                    Button bEdit = new Button();
                    bEdit.Text     = "Редактировать";
                    bEdit.Location = new Point(142, yPos);
                    bEdit.Click   += (s, e) =>
                    {
                        if (listBox.SelectedItem != null)
                        {
                            AddAction newForm = new AddAction(ent.ents, listBox.SelectedItem as Dictionary <string, object>);
                            newForm.Owner       = this;
                            newForm.FormClosed += (sen, ee) =>
                            {
                                listBox.DataSource = null;
                                listBox.DataSource = entList;
                            };
                            newForm.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show("Not select");
                        }
                    };

                    yPos += 35;


                    Button bDelete = new Button();
                    bDelete.Text     = "Удалить";
                    bDelete.Location = new Point(142, yPos);
                    bDelete.Click   += (s, e) =>
                    {
                        if (listBox.SelectedItem != null)
                        {
                            entList.Remove(listBox.SelectedItem as Dictionary <string, object>);
                        }
                        else
                        {
                            MessageBox.Show("Not select");
                        }
                    };

                    yPos += 35;


                    this.Controls.Add(label);
                    this.Controls.Add(listBox);
                    this.Controls.Add(bAdd);
                    this.Controls.Add(bEdit);
                    this.Controls.Add(bDelete);
                }
            }
        }