mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: update fa enum and helper methods
This commit is contained in:
parent
d1a3129558
commit
b208124a28
6 changed files with 12840 additions and 7079 deletions
53
Dalamud/Interface/FontAwesome/FontAwesomeExtensions.cs
Normal file
53
Dalamud/Interface/FontAwesome/FontAwesomeExtensions.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using Dalamud.Utility;
|
||||
|
||||
namespace Dalamud.Interface;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="FontAwesomeIcon"/>.
|
||||
/// </summary>
|
||||
public static class FontAwesomeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert the FontAwesomeIcon to a <see cref="char"/> type.
|
||||
/// </summary>
|
||||
/// <param name="icon">The icon to convert.</param>
|
||||
/// <returns>The converted icon.</returns>
|
||||
public static char ToIconChar(this FontAwesomeIcon icon)
|
||||
{
|
||||
return (char)icon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the FontAwesomeIcon to a <see cref="string"/> type.
|
||||
/// </summary>
|
||||
/// <param name="icon">The icon to convert.</param>
|
||||
/// <returns>The converted icon.</returns>
|
||||
public static string ToIconString(this FontAwesomeIcon icon)
|
||||
{
|
||||
return string.Empty + (char)icon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get FontAwesome search terms.
|
||||
/// </summary>
|
||||
/// <param name="icon">The icon to pull search terms from.</param>
|
||||
/// <returns>string array of search terms or empty array if none.</returns>
|
||||
public static IEnumerable<string> GetSearchTerms(this FontAwesomeIcon icon)
|
||||
{
|
||||
var searchTermsAttribute = icon.GetAttribute<FontAwesomeSearchTermsAttribute>();
|
||||
return searchTermsAttribute == null ? new string[] { } : searchTermsAttribute.SearchTerms;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get FontAwesome categories.
|
||||
/// </summary>
|
||||
/// <param name="icon">The icon to pull categories from.</param>
|
||||
/// <returns>string array of categories or empty array if none.</returns>
|
||||
public static IEnumerable<string> GetCategories(this FontAwesomeIcon icon)
|
||||
{
|
||||
var categoriesAttribute = icon.GetAttribute<FontAwesomeCategoriesAttribute>();
|
||||
return categoriesAttribute == null ? new string[] { } : categoriesAttribute.Categories;
|
||||
}
|
||||
}
|
||||
117
Dalamud/Interface/FontAwesome/FontAwesomeHelpers.cs
Normal file
117
Dalamud/Interface/FontAwesome/FontAwesomeHelpers.cs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Dalamud.Utility;
|
||||
|
||||
namespace Dalamud.Interface;
|
||||
|
||||
/// <summary>
|
||||
/// Class containing various helper methods for use with Font Awesome inside Dalamud.
|
||||
/// </summary>
|
||||
public static class FontAwesomeHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Get all non-obsolete icons.
|
||||
/// </summary>
|
||||
/// <returns>list of font awesome icons.</returns>
|
||||
public static List<FontAwesomeIcon> GetIcons()
|
||||
{
|
||||
var icons = new List<FontAwesomeIcon>();
|
||||
foreach (var icon in Enum.GetValues(typeof(FontAwesomeIcon)).Cast<FontAwesomeIcon>().ToList())
|
||||
{
|
||||
if (icon.IsObsolete()) continue;
|
||||
icons.Add(icon);
|
||||
}
|
||||
|
||||
return icons;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all categories available on non-obsolete icons.
|
||||
/// </summary>
|
||||
/// <returns>list of font awesome icons.</returns>
|
||||
public static string[] GetCategories()
|
||||
{
|
||||
var icons = GetIcons();
|
||||
var result = new List<string>();
|
||||
foreach (var icon in icons)
|
||||
{
|
||||
var categories = icon.GetCategories();
|
||||
foreach (var category in categories)
|
||||
{
|
||||
if (!result.Contains(category))
|
||||
{
|
||||
result.Add(category);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.Sort();
|
||||
result.Insert(0, string.Empty);
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get icons by search term.
|
||||
/// </summary>
|
||||
/// <param name="search">search term string.</param>
|
||||
/// <param name="category">name of category to filter by.</param>
|
||||
/// <returns>list array of font awesome icons matching search term.</returns>
|
||||
public static List<FontAwesomeIcon> SearchIcons(string search, string category)
|
||||
{
|
||||
var icons = GetIcons();
|
||||
var result = new List<FontAwesomeIcon>();
|
||||
|
||||
// if no filters
|
||||
if (string.IsNullOrEmpty(search) && string.IsNullOrEmpty(category))
|
||||
{
|
||||
return icons;
|
||||
}
|
||||
|
||||
// if search with only search term
|
||||
if (!string.IsNullOrEmpty(search) && string.IsNullOrEmpty(category))
|
||||
{
|
||||
foreach (var icon in icons)
|
||||
{
|
||||
var name = Enum.GetName(icon)?.ToLower();
|
||||
var searchTerms = icon.GetSearchTerms();
|
||||
if (name!.Contains(search.ToLower()) || searchTerms.Contains(search.ToLower()))
|
||||
{
|
||||
result.Add(icon);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// if search with only category
|
||||
if (string.IsNullOrEmpty(search) && !string.IsNullOrEmpty(category))
|
||||
{
|
||||
foreach (var icon in icons)
|
||||
{
|
||||
var categories = icon.GetCategories();
|
||||
if (categories.Contains(category))
|
||||
{
|
||||
result.Add(icon);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// search by both terms and category
|
||||
foreach (var icon in icons)
|
||||
{
|
||||
var name = Enum.GetName(icon)?.ToLower();
|
||||
var searchTerms = icon.GetSearchTerms();
|
||||
var categories = icon.GetCategories();
|
||||
if ((name!.Contains(search.ToLower()) || searchTerms.Contains(search.ToLower())) && categories.Contains(category))
|
||||
{
|
||||
result.Add(icon);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
12669
Dalamud/Interface/FontAwesome/FontAwesomeIcon.cs
Normal file
12669
Dalamud/Interface/FontAwesome/FontAwesomeIcon.cs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,29 +0,0 @@
|
|||
// Font-Awesome - Version 5.0.9
|
||||
|
||||
namespace Dalamud.Interface;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="FontAwesomeIcon"/>.
|
||||
/// </summary>
|
||||
public static class FontAwesomeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Convert the FontAwesomeIcon to a <see cref="char"/> type.
|
||||
/// </summary>
|
||||
/// <param name="icon">The icon to convert.</param>
|
||||
/// <returns>The converted icon.</returns>
|
||||
public static char ToIconChar(this FontAwesomeIcon icon)
|
||||
{
|
||||
return (char)icon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conver the FontAwesomeIcon to a <see cref="string"/> type.
|
||||
/// </summary>
|
||||
/// <param name="icon">The icon to convert.</param>
|
||||
/// <returns>The converted icon.</returns>
|
||||
public static string ToIconString(this FontAwesomeIcon icon)
|
||||
{
|
||||
return string.Empty + (char)icon;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -733,7 +733,7 @@ internal class InterfaceManager : IDisposable, IServiceType
|
|||
// FontAwesome icon font
|
||||
Log.Verbose("[FONT] SetupFonts - FontAwesome icon font");
|
||||
{
|
||||
var fontPathIcon = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "FontAwesome5FreeSolid.otf");
|
||||
var fontPathIcon = Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "FontAwesomeFreeSolid.otf");
|
||||
if (!File.Exists(fontPathIcon))
|
||||
ShowFontError(fontPathIcon);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue