Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add tooltips.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 10, 2023
1 parent 4f23833 commit f4a8f59
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 84 deletions.
5 changes: 4 additions & 1 deletion Resources/HostileCastingArea.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,5 +358,8 @@
26423,
26422,
23668,
24021
24021,
10132,
10162,
10168
]
41 changes: 20 additions & 21 deletions RotationSolver.Basic/Attributes/LinkDescriptionAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using ImGuiScene;
using Dalamud.Utility;
using ECommons.ImGuiMethods;
using ImGuiScene;
using static System.Windows.Forms.LinkLabel;

namespace RotationSolver.Basic.Attributes;

Expand All @@ -9,37 +12,33 @@ namespace RotationSolver.Basic.Attributes;
public class LinkDescriptionAttribute : Attribute
{
/// <summary>
/// Image from url.
/// The description.
/// </summary>
public TextureWrap Texture => IconSet.GetTexture(Path);

/// <summary>
/// Description.
/// </summary>
public string Description { get; set; }

/// <summary>
/// Url.
/// </summary>
public string Path { get; set; }
public LinkDescription LinkDescription { get; set; }

/// <summary>
/// Constructer.
/// </summary>
/// <param name="path"></param>
/// <param name="description"></param>
[Obsolete]
public LinkDescriptionAttribute(string path, string description = "")
{
Path = path;
Description = description;
LinkDescription = new() { Path = path, Description = description };
}
}

/// <summary>
/// Link description itself.
/// </summary>
public class LinkDescription
{
/// <summary>
///
/// Description.
/// </summary>
public LinkDescriptionAttribute()
{

}
public string Description { get; init; }

/// <summary>
/// Url.
/// </summary>
public string Path { get; init; }
}
12 changes: 6 additions & 6 deletions RotationSolver/Localization/ConfigTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,32 @@ internal static class ConfigTranslation
_ => string.Empty,
};

public static Action ToAction(this JobConfigInt config) => config switch
public static LinkDescription[] ToAction(this JobConfigInt config) => config switch
{
_ => null,
};

public static Action ToAction(this JobConfigFloat config) => config switch
public static LinkDescription[] ToAction(this JobConfigFloat config) => config switch
{
_ => null,
};

public static Action ToAction(this PluginConfigInt config) => config switch
public static LinkDescription[] ToAction(this PluginConfigInt config) => config switch
{
_ => null,
};

public static Action ToAction(this PluginConfigBool config) => config switch
public static LinkDescription[] ToAction(this PluginConfigBool config) => config switch
{
_ => null,
};

public static Action ToAction(this PluginConfigFloat config) => config switch
public static LinkDescription[] ToAction(this PluginConfigFloat config) => config switch
{
_ => null,
};

public static Action ToAction(this PluginConfigVector4 config) => config switch
public static LinkDescription[] ToAction(this PluginConfigVector4 config) => config switch
{
_ => null,
};
Expand Down
62 changes: 31 additions & 31 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,37 +572,37 @@ public unsafe static void Display(this ICustomRotation rotation, ICustomRotation
isFirst = false;
Spacing();
}
var hasTexture = texture.Texture != null;

if (IconButton(hasTexture ? FontAwesomeIcon.Image : FontAwesomeIcon.Question,
"Button" + rotation.GetHashCode().ToString() + texture.GetHashCode().ToString()))
{
try
{
Util.OpenLink(texture.Path);
}
catch
{
}
}
if (ImGui.IsItemHovered() && (hasTexture || !string.IsNullOrEmpty( texture.Description)))
{
ImguiTooltips.ShowTooltip(() =>
{
if(hasTexture)
{
var ratio = Math.Min(1, Math.Min(display.X / texture.Texture.Width, display.Y / texture.Texture.Height));
var size = new Vector2(texture.Texture.Width * ratio,
texture.Texture.Height * ratio);
ImGui.Image(texture.Texture.ImGuiHandle, size);
}
if (!string.IsNullOrEmpty(texture.Description))
{
ImGui.Text(texture.Description);
}

});
}
//var hasTexture = texture.Texture != null;

//if (IconButton(hasTexture ? FontAwesomeIcon.Image : FontAwesomeIcon.Question,
// "Button" + rotation.GetHashCode().ToString() + texture.GetHashCode().ToString()))
//{
// try
// {
// Util.OpenLink(texture.Path);
// }
// catch
// {
// }
//}
//if (ImGui.IsItemHovered() && (hasTexture || !string.IsNullOrEmpty( texture.Description)))
//{
// ImguiTooltips.ShowTooltip(() =>
// {
// if(hasTexture)
// {
// var ratio = Math.Min(1, Math.Min(display.X / texture.Texture.Width, display.Y / texture.Texture.Height));
// var size = new Vector2(texture.Texture.Width * ratio,
// texture.Texture.Height * ratio);
// ImGui.Image(texture.Texture.ImGuiHandle, size);
// }
// if (!string.IsNullOrEmpty(texture.Description))
// {
// ImGui.Text(texture.Description);
// }

// });
//}
}
}
}, () =>
Expand Down
27 changes: 16 additions & 11 deletions RotationSolver/UI/RotationConfigWindowNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,21 +656,26 @@ private static void DrawRotationDescription()

foreach (var link in links)
{
var hasTexture = link.Texture != null;
DrawLinkDescription(link.LinkDescription, wholeWidth);
}
}

if(hasTexture && TextureButton(link.Texture, wholeWidth, wholeWidth))
{
Util.OpenLink(link.Path);
}
internal static void DrawLinkDescription(LinkDescription link, float wholeWidth)
{
var hasTexture = IconSet.GetTexture(link.Path, out var texture);

ImGui.TextWrapped(link.Description);
if (hasTexture && TextureButton(texture, wholeWidth, wholeWidth))
{
Util.OpenLink(link.Path);
}

ImGui.TextWrapped(link.Description);

if (!hasTexture && !string.IsNullOrEmpty(link.Path))
if (!hasTexture && !string.IsNullOrEmpty(link.Path))
{
if (ImGuiEx.IconButton(FontAwesomeIcon.Question, link.Description))
{
if(ImGuiEx.IconButton(FontAwesomeIcon.Question, link.Description))
{
Util.OpenLink(link.Path);
}
Util.OpenLink(link.Path);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/UI/SearchableConfigs/CheckBoxSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class CheckBoxSearchPlugin : CheckBoxSearch

public override string Description => _config.ToDescription();

public override Action DrawTooltip => _config.ToAction();
public override LinkDescription[] Tooltips => _config.ToAction();

public override string Command => _config.ToCommand();

Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/UI/SearchableConfigs/ColorEditSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class ColorEditSearchPlugin : ColorEditSearch

public override string Description => _config.ToDescription();

public override Action DrawTooltip => _config.ToAction();
public override LinkDescription[] Tooltips => _config.ToAction();

public override string Command => _config.ToCommand();

Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/UI/SearchableConfigs/DragFloatRangeSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class DragFloatRangeSearchJob : DragFloatRangeSearch

public override string Description => _configMin.ToDescription();

public override Action DrawTooltip => _configMin.ToAction();
public override LinkDescription[] Tooltips => _configMin.ToAction();

public override string Command => _configMin.ToCommand();

Expand Down Expand Up @@ -67,7 +67,7 @@ internal class DragFloatRangeSearchPlugin : DragFloatRangeSearch

public override string Description => _configMin.ToDescription();

public override Action DrawTooltip => _configMin.ToAction();
public override LinkDescription[] Tooltips => _configMin.ToAction();

public override string Command => _configMin.ToCommand();

Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/UI/SearchableConfigs/DragFloatSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class DragFloatSearchJob : DragFloatSearch

public override string Description => _config.ToDescription();

public override Action DrawTooltip => _config.ToAction();
public override LinkDescription[] Tooltips => _config.ToAction();

public override string Command => _config.ToCommand();

Expand Down Expand Up @@ -57,7 +57,7 @@ internal class DragFloatSearchPlugin : DragFloatSearch

public override string Description => _config.ToDescription();

public override Action DrawTooltip => _config.ToAction();
public override LinkDescription[] Tooltips => _config.ToAction();

public override string Command => _config.ToCommand();

Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/UI/SearchableConfigs/DragIntRangeSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class DragIntRangeSearchJob : DragIntRangeSearch

public override string Description => _configMin.ToDescription();

public override Action DrawTooltip => _configMin.ToAction();
public override LinkDescription[] Tooltips => _configMin.ToAction();

public override string Command => _configMin.ToCommand();

Expand Down Expand Up @@ -69,7 +69,7 @@ internal class DragIntRangeSearchPlugin : DragIntRangeSearch

public override string Description => _configMin.ToDescription();

public override Action DrawTooltip => _configMin.ToAction();
public override LinkDescription[] Tooltips => _configMin.ToAction();

public override string Command => _configMin.ToCommand();

Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/UI/SearchableConfigs/DragIntSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class DragIntSearchJob : DragIntSearch

public override string Description => _config.ToDescription();

public override Action DrawTooltip => _config.ToAction();
public override LinkDescription[] Tooltips => _config.ToAction();

public override string Command => _config.ToCommand();

Expand Down Expand Up @@ -56,7 +56,7 @@ internal class DragIntSearchPlugin : DragIntSearch

public override string Description => _config.ToDescription();

public override Action DrawTooltip => _config.ToAction();
public override LinkDescription[] Tooltips => _config.ToAction();

public override string Command => _config.ToCommand();

Expand Down
13 changes: 9 additions & 4 deletions RotationSolver/UI/SearchableConfigs/Searchable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal abstract class Searchable : ISearchable
public abstract string Name { get; }
public abstract string Description { get; }
public abstract string Command { get; }
public abstract Action DrawTooltip { get; }
public abstract LinkDescription[] Tooltips { get; }
public abstract string ID { get; }
private string Popup_Key => "Rotation Solver RightClicking: " + ID;

Expand Down Expand Up @@ -50,19 +50,24 @@ public void Draw(Job job)
protected void ShowTooltip(Job job, bool showHand = true)
{
var showDesc = !string.IsNullOrEmpty(Description);
if (showDesc || DrawTooltip != null)
if (showDesc || Tooltips != null)
{
ImguiTooltips.ShowTooltip(() =>
{
if (showDesc)
{
ImGui.TextWrapped(Description);
}
if (showDesc && DrawTooltip != null)
if (showDesc && Tooltips != null && Tooltips.Length > 0)
{
ImGui.Separator();
}
DrawTooltip?.Invoke();
var wholeWidth = ImGui.GetWindowWidth();

foreach (var tooltip in Tooltips)
{
RotationConfigWindowNew.DrawLinkDescription(tooltip, wholeWidth);
}
});
}

Expand Down

0 comments on commit f4a8f59

Please sign in to comment.