Skip to content
New issue

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

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

Already on GitHub? # to your account

Allow the checkbox textures to be customized #125

Merged
merged 1 commit into from
Jul 7, 2023
Merged
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
41 changes: 38 additions & 3 deletions LemonUI/Menus/NativeCheckboxItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ public class NativeCheckboxItem : NativeItem

#endregion

#region Defaults

/// <summary>
/// The default checkbox textures when the checkbox is checked.
/// </summary>
public static readonly BadgeSet DefaultCheckedSet = new BadgeSet
{
NormalDictionary = "commonmenu",
NormalTexture = "shop_box_blank",
HoveredDictionary = "commonmenu",
HoveredTexture = "shop_box_blankb"
};
/// <summary>
/// The default checkbox textures when the checkbox is not checked.
/// </summary>
public static readonly BadgeSet DefaultUncheckedSet = new BadgeSet
{
NormalDictionary = "commonmenu",
NormalTexture = "shop_box_tick",
HoveredDictionary = "commonmenu",
HoveredTexture = "shop_box_tickb"
};

#endregion

#region Properties

/// <summary>
Expand All @@ -41,6 +66,14 @@ public bool Checked
CheckboxChanged?.Invoke(this, EventArgs.Empty);
}
}
/// <summary>
/// The textures used when the checkbox is checked.
/// </summary>
public BadgeSet CheckedSet { get; set; } = DefaultCheckedSet;
/// <summary>
/// The textures used when the checkbox is unchecked.
/// </summary>
public BadgeSet UncheckedSet { get; set; } = DefaultUncheckedSet;

#endregion

Expand Down Expand Up @@ -110,15 +143,17 @@ public NativeCheckboxItem(string title, string description, bool check) : base(t
/// </summary>
protected internal void UpdateTexture(bool selected)
{
bool showLight = !selected || !Enabled;

// If the item is not selected or is not enabled, use the white pictures
if (!selected || !Enabled)
if (Checked)
{
check.Texture = Checked ? "shop_box_tick" : "shop_box_blank";
check.Texture = showLight ? CheckedSet.NormalTexture : CheckedSet.HoveredTexture;
}
// Otherwise, use the black ones
else
{
check.Texture = Checked ? "shop_box_tickb" : "shop_box_blankb";
check.Texture = showLight ? UncheckedSet.NormalTexture : UncheckedSet.HoveredTexture;
}
}

Expand Down