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); }