public void InitializePrefernces(TmxMap map) { this.Preferences = new List <LayerPreference>(); Dictionary <string, Color> layers2Colors = PerLayerColorData.StringCollectionToDictionary(Properties.Settings.Default.PerLayerColors); Color defaultColor = System.Drawing.Color.Tomato; foreach (var layer in map.Layers) { if (layer.Visible) { string name = layer.DefaultName; System.Drawing.Color color = layers2Colors.ContainsKey(name) ? layers2Colors[name] : defaultColor; this.Preferences.Add(new LayerPreference() { Name = name, Previewing = true, Color = color, CanEditColor = true }); } } // Object groups have a color setting from the map file. This is a purposeful setting so honor it and don't allow edits. foreach (var objects in map.ObjectGroups) { if (objects.Visible) { string name = objects.Name; Color color = objects.Color; this.Preferences.Add(new LayerPreference() { Name = name, Previewing = true, Color = color, CanEditColor = false }); } } for (int i = 0; i < this.Preferences.Count(); ++i) { var row = this.Preferences[i]; this.dataGridView.Rows.Add(new object[3] { row.Previewing, row.Name, row.Color }); if (row.CanEditColor == false) { this.dataGridView.Rows[i].Cells[2].ReadOnly = true; } } }
private void buttonApplyChanges_Click(object sender, EventArgs e) { // Apply changes to color settings Dictionary <string, Color> layers2Colors = PerLayerColorData.StringCollectionToDictionary(Properties.Settings.Default.PerLayerColors); // Override if needed for (int i = 0; i < this.dataGridView.Rows.Count; ++i) { string name = (string)this.dataGridView.Rows[i].Cells[1].Value; System.Drawing.Color color = (System.Drawing.Color) this.dataGridView.Rows[i].Cells[2].Value; layers2Colors[name] = color; } // Save changes to settings back out Properties.Settings.Default.PerLayerColors = PerLayerColorData.DictionaryToStringCollection(layers2Colors); Properties.Settings.Default.Save(); // Notify listeners that we've had a change if (this.ApplyChanges != null) { this.ApplyChanges(); } }