public static void AddSubMenuDescription(TextMenu menu, bool inGame) { if (inGame) { subMenuItem.AddDescription(menu, "Hitbox Color Description 2".ToDialogText()); subMenuItem.AddDescription(menu, "Hitbox Color Description 1".ToDialogText()); } }
public static void CreateMenu(EverestModule everestModule, TextMenu menu, bool inGame) { TextMenu.Item enabledItem = new TextMenu.OnOff("Enabled".ToDialogText(), Settings.Enabled).Change((value) => { Settings.Enabled = value; foreach (TextMenu.Item item in options) { item.Visible = value; } }); menu.Add(enabledItem); CreateOptions(everestModule, menu, inGame); foreach (TextMenu.Item item in options) { menu.Add(item); item.Visible = Settings.Enabled; } foreach (string text in Split(InputController.TasFilePath, 60).Reverse()) { enabledItem.AddDescription(menu, text); } enabledItem.AddDescription(menu, "Working TAS File Path:"); HitboxTweak.AddSubMenuDescription(menu, inGame); InfoHud.AddSubMenuDescription(menu); keyConfigButton.AddDescription(menu, "Key Config Description".ToDialogText()); }
public static void CreateMenu(EverestModule everestModule, TextMenu menu, bool inGame) { List <TextMenuExt.EaseInSubHeaderExt> enabledDescriptions = new(); TextMenuExt.EaseInSubHeaderExt AddEnabledDescription(TextMenu.Item enabledItem, TextMenu containingMenu, string description) { TextMenuExt.EaseInSubHeaderExt descriptionText = new(description, false, containingMenu) { TextColor = Color.Gray, HeightExtra = 0f }; List <TextMenu.Item> items = containingMenu.GetItems(); if (items.Contains(enabledItem)) { containingMenu.Insert(items.IndexOf(enabledItem) + 1, descriptionText); } enabledItem.OnEnter += () => descriptionText.FadeVisible = Settings.Enabled; enabledItem.OnLeave += () => descriptionText.FadeVisible = false; return(descriptionText); } TextMenu.Item enabledItem = new TextMenu.OnOff("Enabled".ToDialogText(), Settings.Enabled).Change((value) => { Settings.Enabled = value; foreach (EaseInSubMenu easeInSubMenu in options) { easeInSubMenu.FadeVisible = value; } foreach (TextMenuExt.EaseInSubHeaderExt easeInSubHeader in enabledDescriptions) { easeInSubHeader.FadeVisible = value; } }); menu.Add(enabledItem); CreateOptions(everestModule, menu, inGame); foreach (EaseInSubMenu easeInSubMenu in options) { menu.Add(easeInSubMenu); } foreach (string text in Split(InputController.TasFilePath, 60).Reverse()) { enabledDescriptions.Add(AddEnabledDescription(enabledItem, menu, text)); } enabledDescriptions.Add(AddEnabledDescription(enabledItem, menu, "Enabled Description".ToDialogText())); HitboxMenu.AddSubMenuDescription(menu, inGame); InfoHud.AddSubMenuDescription(menu); hotkeysSubMenu.AddDescription(menu, "Hotkeys Description".ToDialogText()); }
public static void CreateMenu(EverestModule everestModule, TextMenu menu, bool inGame) { menu.Add(new TextMenu.OnOff("Enabled".ToDialogText(), Settings.Enabled).Change((value) => { Settings.Enabled = value; foreach (TextMenu.Item item in options) { item.Visible = value; } })); CreateOptions(everestModule, menu, inGame); foreach (TextMenu.Item item in options) { menu.Add(item); item.Visible = Settings.Enabled; } if (inGame) { showHitboxesSubmenu.AddDescription(menu, "Hitbox Color Description 2".ToDialogText()); showHitboxesSubmenu.AddDescription(menu, "Hitbox Color Description 1".ToDialogText()); } keyConfigButton.AddDescription(menu, "Key Config Description".ToDialogText()); }
public static void AddSubMenuDescription(TextMenu menu) { subMenuItem.AddDescription(menu, "Info HUD Description 2".ToDialogText()); subMenuItem.AddDescription(menu, "Info HUD Description 1".ToDialogText()); }
/// <summary> /// Create the mod menu subsection including the section header in the given menu. /// The default implementation uses reflection to attempt creating a menu. /// </summary> /// <param name="menu">Menu to add the section to.</param> /// <param name="inGame">Whether we're in-game (paused) or in the main menu.</param> /// <param name="snapshot">The Level.PauseSnapshot</param> public virtual void CreateModMenuSection(TextMenu menu, bool inGame, EventInstance snapshot) { Type type = SettingsType; EverestModuleSettings settings = _Settings; if (type == null || settings == null) { return; } // The default name prefix. string typeName = type.Name.ToLowerInvariant(); if (typeName.EndsWith("settings")) { typeName = typeName.Substring(0, typeName.Length - 8); } string nameDefaultPrefix = $"modoptions_{typeName}_"; // Any attributes we may want to get and read from later. SettingInGameAttribute attribInGame; SettingRangeAttribute attribRange; SettingNumberInputAttribute attribNumber; // If the settings type has got the InGame attrib, only show it in the matching situation. if ((attribInGame = type.GetCustomAttribute <SettingInGameAttribute>()) != null && attribInGame.InGame != inGame) { return; } bool headerCreated = false; if (GetType().GetMethod("CreateModMenuSection").DeclaringType != typeof(EverestModule)) { CreateModMenuSectionHeader(menu, inGame, snapshot); headerCreated = true; } PropertyInfo[] props; if (type == _PrevSettingsType) { props = _PrevSettingsProps; } else { _PrevSettingsProps = props = type.GetProperties(); _PrevSettingsType = type; } TextMenu.Item CreateItem(PropertyInfo prop, string name = null, object settingsObject = null) { settingsObject ??= settings; if ((attribInGame = prop.GetCustomAttribute <SettingInGameAttribute>()) != null && attribInGame.InGame != inGame) { return(null); } if (prop.GetCustomAttribute <SettingIgnoreAttribute>() != null) { return(null); } if (!prop.CanRead || !prop.CanWrite) { return(null); } if (name == null) { name = prop.GetCustomAttribute <SettingNameAttribute>()?.Name ?? $"{nameDefaultPrefix}{prop.Name.ToLowerInvariant()}"; name = name.DialogCleanOrNull() ?? prop.Name.SpacedPascalCase(); } TextMenu.Item item = null; Type propType = prop.PropertyType; object value = prop.GetValue(settingsObject); // Create the matching item based off of the type and attributes. if (propType == typeof(bool)) { item = new TextMenu.OnOff(name, (bool)value) .Change(v => prop.SetValue(settingsObject, v)) ; } else if ( propType == typeof(int) && (attribRange = prop.GetCustomAttribute <SettingRangeAttribute>()) != null ) { if (attribRange.LargeRange) { item = new TextMenuExt.IntSlider(name, attribRange.Min, attribRange.Max, (int)value) .Change(v => prop.SetValue(settingsObject, v)) ; } else { item = new TextMenu.Slider(name, i => i.ToString(), attribRange.Min, attribRange.Max, (int)value) .Change(v => prop.SetValue(settingsObject, v)) ; } } else if ((propType == typeof(int) || propType == typeof(float)) && (attribNumber = prop.GetCustomAttribute <SettingNumberInputAttribute>()) != null) { float currentValue; Action <float> valueSetter; if (propType == typeof(int)) { currentValue = (int)value; valueSetter = v => prop.SetValue(settingsObject, (int)v); } else { currentValue = (float)value; valueSetter = v => prop.SetValue(settingsObject, v); } int maxLength = attribNumber.MaxLength; bool allowNegatives = attribNumber.AllowNegatives; item = new TextMenu.Button(name + ": " + currentValue.ToString($"F{maxLength}").TrimEnd('0').TrimEnd('.')) .Pressed(() => { Audio.Play(SFX.ui_main_savefile_rename_start); menu.SceneAs <Overworld>().Goto <OuiNumberEntry>().Init <OuiModOptions>( currentValue, valueSetter, maxLength, propType == typeof(float), allowNegatives ); }) ; } else if (propType.IsEnum) { Array enumValues = Enum.GetValues(propType); Array.Sort((int[])enumValues); string enumNamePrefix = $"{nameDefaultPrefix}{prop.Name.ToLowerInvariant()}_"; item = new TextMenu.Slider(name, (i) => { string enumName = enumValues.GetValue(i).ToString(); return ($"{enumNamePrefix}{enumName.ToLowerInvariant()}".DialogCleanOrNull() ?? $"modoptions_{propType.Name.ToLowerInvariant()}_{enumName.ToLowerInvariant()}".DialogCleanOrNull() ?? enumName); }, 0, enumValues.Length - 1, (int)value) .Change(v => prop.SetValue(settingsObject, v)) ; } else if (!inGame && propType == typeof(string)) { int maxValueLength = prop.GetCustomAttribute <SettingMaxLengthAttribute>()?.Max ?? 12; int minValueLength = prop.GetCustomAttribute <SettingMinLengthAttribute>()?.Min ?? 1; item = new TextMenu.Button(name + ": " + value) .Pressed(() => { Audio.Play(SFX.ui_main_savefile_rename_start); menu.SceneAs <Overworld>().Goto <OuiModOptionString>().Init <OuiModOptions>( (string)value, v => prop.SetValue(settingsObject, v), maxValueLength, minValueLength ); }) ; } return(item); } foreach (PropertyInfo prop in props) { string name = prop.GetCustomAttribute <SettingNameAttribute>()?.Name ?? $"{nameDefaultPrefix}{prop.Name.ToLowerInvariant()}"; name = name.DialogCleanOrNull() ?? prop.Name.SpacedPascalCase(); MethodInfo creator = type.GetMethod( $"Create{prop.Name}Entry", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(TextMenu), typeof(bool) }, new ParameterModifier[0] ); if (creator != null) { if (!headerCreated) { CreateModMenuSectionHeader(menu, inGame, snapshot); headerCreated = true; } creator.GetFastDelegate()(settings, menu, inGame); continue; } TextMenu.Item item = CreateItem(prop, name); if (item == null && prop.PropertyType.GetCustomAttribute <SettingSubMenuAttribute>() != null) { object propObject = prop.GetValue(settings); if (propObject == null) { prop.SetValue(settings, propObject = Activator.CreateInstance(prop.PropertyType)); } TextMenuExt.SubMenu subMenu = new(name, false); foreach (PropertyInfo subTypeProp in prop.PropertyType.GetProperties()) { creator = prop.PropertyType.GetMethod( $"Create{subTypeProp.Name}Entry", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(TextMenuExt.SubMenu), typeof(bool) }, new ParameterModifier[0] ); if (creator != null) { creator.GetFastDelegate()(propObject, subMenu, inGame); continue; } TextMenu.Item subMenuItem = CreateItem(subTypeProp, settingsObject: propObject); if (subMenuItem != null) { subMenu.Add(subMenuItem); } } item = subMenu; } if (item == null) { continue; } if (!headerCreated) { CreateModMenuSectionHeader(menu, inGame, snapshot); headerCreated = true; } menu.Add(item); if (prop.GetCustomAttribute <SettingNeedsRelaunchAttribute>() != null) { item = item.NeedsRelaunch(menu); } string description = prop.GetCustomAttribute <SettingSubTextAttribute>()?.Description; if (description != null) { item = item.AddDescription(menu, description.DialogCleanOrNull() ?? description); } } foreach (PropertyInfo prop in type.GetProperties()) { if ((attribInGame = prop.GetCustomAttribute <SettingInGameAttribute>()) != null && attribInGame.InGame != inGame) { continue; } if (prop.GetCustomAttribute <SettingIgnoreAttribute>() != null) { continue; } if (!prop.CanRead || !prop.CanWrite) { continue; } if (!typeof(ButtonBinding).IsAssignableFrom(prop.PropertyType)) { continue; } if (!headerCreated) { CreateModMenuSectionHeader(menu, inGame, snapshot); headerCreated = true; } CreateModMenuSectionKeyBindings(menu, inGame, snapshot); break; } }