Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mod options menus to provide tooltip language IDs, similar to label language IDs. #268

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions SMLHelper/Options/Attributes/ConfigFileMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public void HandleToggleChanged(object sender, ToggleChangedEventArgs e)
}

/// <summary>
/// Generates tooltips for each <see cref="ModOption"/> with a specified <see cref="TooltipAttribute"/>, before
/// Generates tooltips as required for each <see cref="ModOption"/>, before
/// invoking any relevant method(s) specified with <see cref="OnGameObjectCreatedAttribute"/>(s) and passes
/// parameters when a <see cref="GameObject"/> is created in the options menu.
/// </summary>
Expand All @@ -477,8 +477,14 @@ public void HandleGameObjectCreated(object sender, GameObjectCreatedEventArgs e)
{
if (TryGetMetadata(e.Id, out ModOptionAttributeMetadata<T> modOptionMetadata))
{
// Create a tooltip if there is a TooltipAttribute specified
if (modOptionMetadata.ModOptionAttribute.Tooltip is string tooltip)
string tooltip = Language.main.TryGet(modOptionMetadata.ModOptionAttribute.TooltipLanguageId, out string languageTooltip) switch
{
true => languageTooltip,
false => modOptionMetadata.ModOptionAttribute.Tooltip
};

// Create a tooltip if specified
if (tooltip is not null)
{
e.GameObject.GetComponentInChildren<Text>().gameObject.AddComponent<ModOptionTooltip>().Tooltip = tooltip;
}
Expand Down
8 changes: 7 additions & 1 deletion SMLHelper/Options/Attributes/ModOptionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class ModOptionAttribute : Attribute, IModOptionAttribute
private static int i = 0;

/// <summary>
/// An optional tooltip to display for the field.
/// An optional tooltip to display for the field. If <see cref="TooltipLanguageId"/> is set, this will be ignored.
/// </summary>
public string Tooltip { get; set; }

Expand All @@ -46,6 +46,12 @@ public abstract class ModOptionAttribute : Attribute, IModOptionAttribute
/// <seealso cref="Language.Get(string)"/>
public string LabelLanguageId { get; set; }

/// <summary>
/// An optional id to be parsed with <see cref="Language.Get(string)"/> for the tooltip, allowing for custom lanaguage-based strings
/// via the <see cref="LanguageHandler"/> API. If this is set, it will take precedence.
/// </summary>
public string TooltipLanguageId { get; set; }

/// <summary>
/// Signifies the decorated member should be represented in the mod's options menu as a <see cref="ModOption"/>
/// with an optional label.
Expand Down