/** * Creates ui elements to configure each settings in given group. * * Returns a GuiComponent containing the controls. */ private GuiComponent CreateUIFromSettingsGroup(SettingsGroup group) { GuiContainer result = new GuiScrollableArea(WINDOW_WIDTH - 50, WINDOW_HEIGHT - 150) { Y = 50 }; result.Name = group.Name; int atY = 10; var binding = (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (var property in group.GetType().GetProperties(binding)) { var attribute = getAttribute <SettingAttribute>(property, SettingAttribute.Default); var divider = getAttribute <SettingDivider>(property); // filter out some properties if (property.Name == "Item") { continue; } if (!property.CanRead) { continue; } if (attribute.Ignore) { continue; } GuiLabeledComponent control = CreateControl(group, property); if (control == null) { Trace.Log("No suitable control found for property " + property.Name + " of type " + property.PropertyType); continue; } if (group.isDisabled(property.Name)) { if (control is GuiToggleButton) { (control as GuiToggleButton).Value = false; } control.SelfEnabled = false; } if (divider != null) { string dividerText = divider.Name; var dividerControl = new GuiLabel(dividerText); dividerControl.TextAlign = TextAnchor.MiddleLeft; dividerControl.FontColor = new Color(0.75f, 0.75f, 0.75f); result.Add(dividerControl, 20, atY + 3); atY += (dividerText == "") ? 5 : 30; } // apply attributes if (control.Enabled) { control.LabelColor = attribute.Color; } else { control.LabelColor = Color.Lerp(attribute.Color, Color.gray, 0.75f); } control.LabelText = attribute.DisplayName ?? property.Name; result.Add(control, 200, atY); int spacing = Util.ClampInt(control.Height + 10, 30, 999); atY += spacing; } result.FitToChildren(); result = GuiWindow.CreateFrame(result); (result as GuiWindow).WindowStyle = GuiWindowStyle.Transparent; result.Color = new Color(0.25f, 0.25f, 0.25f, 0.5f); result.FitToChildren(); result.Width = WINDOW_WIDTH - 40; return(result); }