Skip to content

Commit

Permalink
feat!: Add tooltip property to ModButtonOption class (#389)
Browse files Browse the repository at this point in the history
* add tooltip property to ModButtonOption

* minor cleanup
  • Loading branch information
LeeTwentyThree committed Jun 2, 2023
1 parent 5441b2d commit e943037
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions Nautilus/Options/ModButtonOption.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Events;
Expand Down Expand Up @@ -28,6 +28,11 @@ public class ModButtonOption : OptionItem
/// </summary>
public event Action<ButtonClickedEventArgs> OnPressed;

/// <summary>
/// The tooltip to show when hovering over the option.
/// </summary>
public string Tooltip { get; }

/// <summary>
/// Gets the Invocation List for the OnPressed event or returns null if none present.
/// </summary>
Expand Down Expand Up @@ -57,16 +62,21 @@ public override void AddToPanel(uGUI_TabbedControlsPanel panel, int tabIndex)
OnPressed?.Invoke(new ButtonClickedEventArgs(Id));
}));

// Add tooltip
MenuTooltip tooltip = OptionGameObject.EnsureComponent<MenuTooltip>();
tooltip.key = Tooltip;

// Add button to panel
base.AddToPanel(panel, tabIndex);
}

private ModButtonOption(string id, string label, Action<ButtonClickedEventArgs> onPressed) : base(label, id)
private ModButtonOption(string id, string label, Action<ButtonClickedEventArgs> onPressed, string tooltip) : base(label, id)
{
if(onPressed != null)
if (onPressed != null)
{
OnPressed += onPressed;
}
Tooltip = tooltip;
}

/// <summary>
Expand All @@ -75,9 +85,10 @@ private ModButtonOption(string id, string label, Action<ButtonClickedEventArgs>
/// <param name="id">The internal ID of this option.</param>
/// <param name="label">The display text to show on the in-game menus.</param>
/// <param name="onPressed"> Action to trigger when button is pressed. Can leave as Null and then add events using the OnPressed += method;</param>
public static ModButtonOption Create(string id, string label, Action<ButtonClickedEventArgs> onPressed = null)
/// <param name="tooltip">The tooltip to show when hovering over the option.</param>
public static ModButtonOption Create(string id, string label, Action<ButtonClickedEventArgs> onPressed = null, string tooltip = null)
{
return new ModButtonOption(id, label, onPressed);
return new ModButtonOption(id, label, onPressed, tooltip);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Options/ModKeybindOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private ModKeybindOption(string id, string label, GameInput.Device device, KeyCo
/// <param name="label">The display text to use in the in-game menu.</param>
/// <param name="device">The device name.</param>
/// <param name="key">The starting keybind value.</param>
/// /// <param name="tooltip">The tooltip to show when hovering over the option.</param>
/// <param name="tooltip">The tooltip to show when hovering over the option.</param>
public static ModKeybindOption Create(string id, string label, GameInput.Device device, KeyCode key, string tooltip = null)
{
return new ModKeybindOption(id, label, device, key, tooltip);
Expand Down

0 comments on commit e943037

Please sign in to comment.