private void saveMBDToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Save MBD File"; //saveDialog.DefaultExt = "*.mbd"; if (saveDialog.ShowDialog() == DialogResult.OK) { string fileContents = "#IsoCaves Map Brush Data\n#ID NAME R G B\n"; foreach (int key in TilePaint.nameDict.Keys) { int id = key; string name = TilePaint.nameDict[key]; TilePaint paint = paintDict[name]; int r = paint.color.R; int g = paint.color.G; int b = paint.color.B; string output = id.ToString() + " " + name + " " + r.ToString() + " " + g.ToString() + " " + b.ToString() + "\n"; fileContents += output; } File.WriteAllText(saveDialog.FileName, fileContents); } else { MessageBox.Show("Failed to save MBD", "Failed"); } }
void LoadMbdToPaint(string contents) { ClearPaint(); contents = contents.Replace("\r", ""); string[] lines = contents.Split('\n'); foreach (string l in lines) { if (l.StartsWith("#")) { continue; } if (l == "") { continue; } string[] commands = l.Split(' '); int id = Convert.ToInt32(commands[0]); string name = commands[1]; int r = Convert.ToInt32(commands[2]); int g = Convert.ToInt32(commands[3]); int b = Convert.ToInt32(commands[4]); TilePaint newPaint = new TilePaint(name, r, g, b, id); AddPaint(newPaint); } }
void AddPaint(TilePaint newPaint) { string name = newPaint.name; if (paintDict.ContainsKey(name)) { paintDict[name] = newPaint; } else { paintDict.Add(name, newPaint); } if (!paintList.Items.Contains(name)) { paintList.Items.Add(name); } }
void AddPaint(string name, int r, int g, int b) { TilePaint newPaint = new TilePaint(name, r, g, b); if (paintDict.ContainsKey(name)) { paintDict[name] = newPaint; } else { paintDict.Add(name, newPaint); } if (!paintList.Items.Contains(name)) { paintList.Items.Add(name); } }
private void paintList_SelectedIndexChanged(object sender, EventArgs e) { if (paintList.SelectedIndex == -1) { return; } string selectedName = (string)paintList.Items[paintList.SelectedIndex]; TilePaint selectedPaint = null; if (paintDict.ContainsKey(selectedName)) { selectedPaint = paintDict[selectedName]; } if (selectedPaint != null) { paintNameInput.Text = selectedPaint.name; redInput.Text = selectedPaint.color.R.ToString(); greenInput.Text = selectedPaint.color.G.ToString(); blueInput.Text = selectedPaint.color.B.ToString(); } }