Example #1
0
        private void customPropertyAddButton_Click(object sender, EventArgs e)
        {
            if (Editor.Instance.SelectedItems.Count == 0)
            {
                MessageBox.Show("select some items first");
                return;
            }
            SerializableDictionary props = new SerializableDictionary();
            AddCustomProperty      form  = new AddCustomProperty(props);

            form.ShowDialog();

            foreach (String key in props.Keys)
            {
                CustomProperty cp = props[key];
                foreach (Item selitem in Editor.Instance.SelectedItems)
                {
                    selitem.CustomProperties.Add(key, cp.clone());
                }
            }
        }
Example #2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (cbbName.Text.Length == 0)
            {
                MessageBox.Show("Please enter a Property Name.");
                return;
            }

            CustomProperty cp = new CustomProperty();

            cp.name        = cbbName.Text;
            cp.description = textBox2.Text;
            if (rdbFreeText.Checked)
            {
                cp.type  = typeof(string);
                cp.value = txbFreetext.Text;
            }
            if (rdbBoolean.Checked)
            {
                cp.type  = typeof(bool);
                cp.value = cbbBoolean.SelectedItem.ToString().Equals("true");
            }
            if (rdbVector2.Checked)
            {
                cp.type = typeof(Vector2);
                Regex r = new Regex(@"^\d+(\.)?\d*$");
                if (r.IsMatch(txbX.Text) && r.IsMatch(txbY.Text))
                {
                    float x = float.Parse(txbX.Text);
                    float y = float.Parse(txbY.Text);
                    cp.value = new Vector2(x, y);
                }
                else
                {
                    MessageBox.Show("Please enter valid numeric value.");
                    return;
                }
            }
            if (rdbColor.Checked)
            {
                cp.type = typeof(Color);
                byte R = byte.Parse(numUDR.Value.ToString());
                byte G = byte.Parse(numUDG.Value.ToString());
                byte B = byte.Parse(numUDB.Value.ToString());
                cp.value = new Color(R, G, B);
            }
            if (rdbItem.Checked)
            {
                cp.type  = typeof(Item);
                cp.value = null;
            }
            if (cbxToAllSelected.Checked)//add to all selected items
            {
                foreach (Item item in Editor.Instance.SelectedItems)
                {
                    if (cbxAddMode.Checked)
                    {
                        item.CustomProperties[cp.name] = cp.clone();
                    }
                    else
                    {
                        if (item.CustomProperties.ContainsKey(cp.name) == false)
                        {
                            item.CustomProperties[cp.name] = cp.clone();
                        }
                    }
                }
            }
            else//add to selected
            {
                if (customproperties.ContainsKey(cbbName.Text))
                {
                    MessageBox.Show("A Custom Property with that name already exists.");
                    return;
                }
                customproperties[cp.name] = cp;
            }
            updateControls();
            MainForm.Instance.propertyGrid1.Refresh();
        }
Example #3
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (txbPropName.Text.Length == 0)
            {
                MessageBox.Show("Please enter a Property Name.");
                return;
            }

            CustomProperty cp = new CustomProperty();

            cp.name        = (String)txbPropName.Text.Clone();
            cp.description = (String)txbDescription.Text.Clone();
            if (rdbFreeText.Checked)
            {
                cp.type  = typeof(string);
                cp.value = txbFreetext.Text;
            }
            if (rdbBoolean.Checked)
            {
                cp.type  = typeof(bool);
                cp.value = cbbBoolean.SelectedItem.ToString().Equals("true");
            }
            if (rdbVector2.Checked)
            {
                cp.type = typeof(Vector2);
                Regex r = new Regex(@"^\d+(\.)?\d*$");
                if (r.IsMatch(txbX.Text) && r.IsMatch(txbY.Text))
                {
                    float x = float.Parse(txbX.Text);
                    float y = float.Parse(txbY.Text);
                    cp.value = new Vector2(x, y);
                }
                else
                {
                    MessageBox.Show("Please enter valid numeric value.");
                    return;
                }
            }
            if (rdbColor.Checked)
            {
                cp.type = typeof(Color);
                byte R = byte.Parse(numUDR.Value.ToString());
                byte G = byte.Parse(numUDG.Value.ToString());
                byte B = byte.Parse(numUDB.Value.ToString());
                cp.value = new Color(R, G, B);
            }
            if (rdbItem.Checked)
            {
                cp.type  = typeof(Item);
                cp.value = null;
            }
            if (cbxToAllSelected.Checked)//to all selected items
            {
                foreach (CustomPropertyGroup group in Editor.Instance.CustomPropertyGroups.Values)
                {
                    if (cbxAddMode.Checked)
                    {
                        group.customproperties[cp.name] = cp.clone();
                    }
                    else
                    {
                        if (group.customproperties.ContainsKey(cp.name) == false)
                        {
                            group.customproperties[cp.name] = cp.clone();
                        }
                    }
                }
            }
            else//to selected
            {
                if (customproperties.ContainsKey(txbPropName.Text) &&
                    MessageBox.Show("A Custom Property with that name already exists.\nAre you sure to overwrite property \"" + txbPropName.Text + "\" from selected items(s)", "Confirm overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                {
                    return;
                }
                customproperties[cp.name] = cp.clone();
            }
            updatePropertyEditControls();
            MainForm.Instance.propertyGrid1.Refresh();
        }
Example #4
0
 private void btnAddCake_Click(object sender, EventArgs e)
 {
     if (Editor.Instance.CustomPropertyGroups.ContainsKey(cbbGroup.Text))
     {
         CustomPropertyGroup group = Editor.Instance.CustomPropertyGroups[cbbGroup.Text];
         foreach (CustomProperty prop in group.customproperties.Values)
         {
             CustomProperty cp = new CustomProperty();
             cp.name        = (String)prop.name.Clone();
             cp.description = (String)prop.description.Clone();
             cp.type        = prop.type;
             if (prop.type == typeof(Vector2))
             {
                 Regex r = new Regex(@"^\d+(\.)?\d*$");
                 float x = ((Vector2)(prop.value)).X;
                 float y = ((Vector2)(prop.value)).Y;
                 cp.value = new Vector2(x, y);
             }
             else if (prop.type == typeof(Color))
             {
                 byte R = ((Color)(prop.value)).R;
                 byte G = ((Color)(prop.value)).G;
                 byte B = ((Color)(prop.value)).B;
                 cp.value = new Color(R, G, B);
             }
             else
             {
                 cp.value = prop.value;
             }
             if (cbxToAllSelected.Checked)//add to all selected items
             {
                 foreach (Item item in Editor.Instance.SelectedItems)
                 {
                     if (cbxAddMode.Checked)
                     {
                         item.CustomProperties[cp.name] = cp.clone();
                     }
                     else
                     {
                         if (item.CustomProperties.ContainsKey(cp.name) == false)
                         {
                             item.CustomProperties[cp.name] = cp.clone();
                         }
                     }
                 }
             }
             else//add to selected
             {
                 if (customproperties.ContainsKey(cp.name) && cbxAddMode.Checked == false)
                 {
                     continue;
                 }
                 customproperties[cp.name] = cp.clone();
             }
         }
         updateControls();
         MainForm.Instance.propertyGrid1.Refresh();
     }
     else
     {
         MessageBox.Show("A Custom Property Group with name \"" + cbbGroup.Text + "\" doesn't exists.");
     }
 }