private void CreatePureLogicEditor(Control parent) { var prettyNames = new string[_pureLogicTypes.Count()]; var index = 0; foreach (var type in _pureLogicTypes) { prettyNames[index++] = EditableAttribute.GetPrettyName(type); } var logicLabel = new Label(Manager) { Text = "Node Logic :: ", Width = 150, Left = 16, Top = 16, Parent = parent }; var logicChoices = new ComboBox(Manager) { Parent = parent, Width = 100, Left = logicLabel.Left + logicLabel.Width + 16, Top = 16, Height = 20 }; logicChoices.Items.AddRange(prettyNames); logicChoices.Init(); logicChoices.Width = 200; logicChoices.Parent = parent; pureLogicContainer = new Panel(Manager) { Width = parent.Width - 48, Top = logicChoices.Height + 32, Left = 16, AutoScroll = true, Parent = parent }; pureLogicContainer.Init(); pureLogicContainer.Visible = true; logicChoices.ItemIndexChanged += (sender, args) => PureLogicChanged(_pureLogicTypes[((ComboBox)sender).ItemIndex], pureLogicContainer); var currentPos = Array.IndexOf(_pureLogicTypes, _node.BindedLogic.PureLogic.GetType()); if (currentPos == -1) { Console.WriteLine("Missing logic type within drop down menu"); logicChoices.ItemIndex = 0; } else { logicChoices.ItemIndex = currentPos; } }
private static Type[] GetKnownTypes() { var type = typeof(WorldEditor); var pureLogicType = typeof(PureLogic); var editableList = type.Assembly.GetTypes().Where(i => i.IsSubclassOf(pureLogicType) && Attribute.IsDefined(i, typeof(EditableAttribute)) // Logical implication ~pVq // If a control needs admin mode, then we check the value of IsAdminMode, otherwise true. && (!EditableAttribute.GetEditableAttribute(i).AdminRequired || Constants.Editing.IsAdminMode)); return(editableList.ToArray()); }
public bool CreateInterface(Type type = null) { _currentType = type = type ?? typeof(T); SizeY = Spacing; var created = false; foreach (var prop in type.GetProperties(_bindingFlags).Where(i => Attribute.IsDefined(i, typeof(EditableAttribute)))) { Console.WriteLine(prop.Name); var fieldType = prop.PropertyType; // Test if there is a preferred edit system for this type var editableAttribute = EditableAttribute.GetEditableAttribute(prop); // Test if this control needs to have admin turned on if (editableAttribute.AdminRequired && !Constants.Editing.IsAdminMode) { Console.WriteLine("Admin required for prop {0}", prop.Name); continue; } IEditSystem editSystem; var preferredEditor = editableAttribute.PreferredEditor; if (preferredEditor != null) { editSystem = _controlFuncs.Select(i => i.Value).FirstOrDefault(i => i.GetType() == preferredEditor); } else { // If it's null, test if it's an enum.) if (!_controlFuncs.TryGetValue(fieldType, out editSystem) && fieldType.BaseType != null) { _controlFuncs.TryGetValue(fieldType.BaseType, out editSystem); } } if (editSystem != null) { var labelText = editableAttribute.PrettyName; object existingFieldValue = null; if (_instance != null) { existingFieldValue = _instance.GetType().GetProperty(prop.Name, _bindingFlags).GetValue(_instance, null); } var createdControl = editSystem.CreateControl(_manager, _control, prop, existingFieldValue); createdControl.Parent = _control; var label = new Label(_manager) { Text = labelText, Parent = _control, Width = 200, Left = 16, Top = SizeY }; label.Init(); createdControl.Top = SizeY; createdControl.Left = label.Width; label.Name = String.Format("{0}Label", prop.Name); SizeY += createdControl.Height + Spacing; createdControl.Width = Math.Max(createdControl.Width, 200); created = true; } else { Console.WriteLine("Wrong type for {0}", fieldType); } } _control.Height = SizeY + Spacing; return(created); }