public override void LoadMemberControl(AutoTileBase obj, TableLayoutPanel control, string name, Type type, object[] attributes, object member, bool isWindow) { if (type == typeof(List <TileLayer>)) { List <TileLayer> anims = (List <TileLayer>)member; DataEditor.LoadLabelControl(control, name); Dev.TilePreview preview = new Dev.TilePreview(); preview.Size = new Size(GraphicsManager.TileSize, GraphicsManager.TileSize); preview.SetChosenAnim(anims.Count > 0 ? anims[0] : new TileLayer()); preview.Tag = member; control.Controls.Add(preview); preview.TileClick += (object sender, EventArgs e) => { Dev.ElementForm frmData = new Dev.ElementForm(); frmData.Text = "Edit Tile"; Rectangle boxRect = new Rectangle(new Point(), frmData.Size); DataEditor.StaticLoadMemberControl(frmData.ControlPanel, name, type, attributes, preview.Tag, true); if (frmData.ShowDialog() == DialogResult.OK) { object element = preview.Tag; DataEditor.StaticSaveMemberControl(frmData.ControlPanel, name, type, attributes, ref element, true); List <TileLayer> new_anims = (List <TileLayer>)element; preview.SetChosenAnim(new_anims.Count > 0 ? new_anims[0] : new TileLayer()); preview.Tag = element; } }; } else { base.LoadMemberControl(obj, control, name, type, attributes, member, isWindow); } }
public override void LoadClassControls(ISpawnList obj, TableLayoutPanel control) { SpawnListBox lbxValue = new SpawnListBox(); lbxValue.Dock = DockStyle.Fill; lbxValue.Size = new Size(0, 200); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ISpawnList <>), obj.GetType(), 0); lbxValue.StringConv = DataEditor.GetStringRep(elementType, new object[0] { }); //add lambda expression for editing a single element lbxValue.OnEditItem = (int index, object element, SpawnListBox.EditElementOp op) => { ElementForm frmData = new ElementForm(); if (element == null) { frmData.Text = "New " + elementType.Name; } else { frmData.Text = element.ToString(); } DataEditor.StaticLoadMemberControl(frmData.ControlPanel, "(SpawnList) [" + index + "]", elementType, new object[0] { }, element, true); frmData.OnOK += (object okSender, EventArgs okE) => { DataEditor.StaticSaveMemberControl(frmData.ControlPanel, "SpawnList", elementType, new object[0] { }, ref element, true); op(index, element); frmData.Close(); }; frmData.OnCancel += (object okSender, EventArgs okE) => { frmData.Close(); }; frmData.Show(); }; lbxValue.LoadFromList(obj.GetType(), obj); control.Controls.Add(lbxValue); }
public virtual void SaveMemberControl(T obj, TableLayoutPanel control, string name, Type type, object[] attributes, ref object member, bool isWindow) { DataEditor.StaticSaveMemberControl(control, name, type, attributes, ref member, isWindow); }
public override void LoadClassControls(ITypeDict obj, TableLayoutPanel control) { CollectionBox lbxValue = new CollectionBox(); lbxValue.Dock = DockStyle.Fill; lbxValue.Size = new Size(0, 150); Type elementType = ReflectionExt.GetBaseTypeArg(typeof(ITypeDict <>), obj.GetType(), 0); lbxValue.StringConv = DataEditor.GetStringRep(elementType, new object[0] { }); //add lambda expression for editing a single element lbxValue.OnEditItem = (int index, object element, CollectionBox.EditElementOp op) => { ElementForm frmData = new ElementForm(); if (element == null) { frmData.Text = "New " + elementType.Name; } else { frmData.Text = element.ToString(); } DataEditor.StaticLoadMemberControl(frmData.ControlPanel, "(StateCollection) [" + index + "]", elementType, new object[0] { }, element, true); frmData.OnOK += (object okSender, EventArgs okE) => { DataEditor.StaticSaveMemberControl(frmData.ControlPanel, "StateCollection", elementType, new object[0] { }, ref element, true); bool itemExists = false; for (int ii = 0; ii < lbxValue.Collection.Count; ii++) { if (ii != index) { if (lbxValue.Collection[ii].GetType() == element.GetType()) { itemExists = true; } } } if (itemExists) { MessageBox.Show("Cannot add duplicate states.", "Entry already exists.", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { op(index, element); frmData.Close(); } }; frmData.OnCancel += (object okSender, EventArgs okE) => { frmData.Close(); }; frmData.Show(); }; List <object> states = new List <object>(); foreach (object state in obj) { states.Add(state); } lbxValue.LoadFromList(typeof(List <object>), states); control.Controls.Add(lbxValue); }