Beispiel #1
0
        private void deleteSelected_Click(object sender, EventArgs e)
        {
            if (materialListBox.SelectedIndex == -1)
            {
                MessageBox.Show("No material selected.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            MaterialJSON = JObject.Parse(File.ReadAllText(AchievementJsonPath));
            MaterialJSON["materials"][materialListBox.SelectedIndex].Remove();
            File.WriteAllText(AchievementJsonPath, MaterialJSON.ToString(Formatting.Indented));

            UpdateEnum.RemoveEnum(UpdateEnum.MakeEnumName(materialListBox.SelectedItem.ToString()));
            ReloadList();

            MessageBox.Show("Selected material deleted.", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #2
0
        /* Save form content */
        private void saveMaterial_Click(object sender, EventArgs e)
        {
            if (MaterialName.Text == "")
            {
                MessageBox.Show("Please complete all fields before saving.", "Incomplete data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            JObject JsonConfig = JObject.Parse(File.ReadAllText(AchievementJsonPath));

            if (EditorContent == null)
            {
                foreach (JObject MaterialEntry in JsonConfig["materials"])
                {
                    if (MaterialEntry["type"].Value <string>() == MaterialName.Text.Trim())
                    {
                        MessageBox.Show("A material with this name already exists.", "Name conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
            }

            JObject NewMaterialEntry = new JObject();

            NewMaterialEntry["type"]        = MaterialName.Text.Trim();
            NewMaterialEntry["can_shatter"] = MaterialIsBreakable.Checked;
            NewMaterialEntry["strength"]    = MaterialStrength.Value;
            NewMaterialEntry["density"]     = MaterialDensity.Value;

            if (EditorContent != null)
            {
                JsonConfig["materials"][MaterialJsonIndex] = NewMaterialEntry;
                UpdateEnum.EditEnum(UpdateEnum.MakeEnumName(EditorContent["type"].Value <string>().Trim()), UpdateEnum.MakeEnumName(NewMaterialEntry["type"].Value <string>().Trim()));
            }
            else
            {
                ((JArray)JsonConfig["materials"]).Add(NewMaterialEntry);
                UpdateEnum.AddEnum(UpdateEnum.MakeEnumName(MaterialName.Text.Trim()));
            }

            File.WriteAllText(AchievementJsonPath, JsonConfig.ToString(Formatting.Indented));
            MessageBox.Show("Material saved!", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Close();
        }