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

Commit

Permalink
fix: try to change the rotation tooltip display.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Feb 20, 2023
1 parent 5f53a42 commit 7e96cd2
Show file tree
Hide file tree
Showing 35 changed files with 344 additions and 188 deletions.
87 changes: 87 additions & 0 deletions RotationSolver/Attributes/RotationDescAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using ImGuiNET;
using RotationSolver.Actions;
using RotationSolver.Actions.BaseAction;
using RotationSolver.Data;
using RotationSolver.Localization;
using RotationSolver.Rotations.CustomRotation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RotationSolver.Attributes;

[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
internal class RotationDescAttribute : Attribute
{
public string Description { get; private set; } = string.Empty;
public DescType DescType { get; private set; } = DescType.None;
public IEnumerable<ActionID> Actions { get; private set; } = Enumerable.Empty<ActionID>();

public RotationDescAttribute(DescType descType)
{
DescType = descType;
}
public RotationDescAttribute(params ActionID[] actions)
:this(string.Empty, actions)
{
}

public RotationDescAttribute(string desc, params ActionID[] actions)
{
Description = desc;
Actions = actions;
}

private RotationDescAttribute()
{

}

public void Display(ICustomRotation rotation)
{
ImGui.Columns(2);
ImGui.SetColumnWidth(0, 100);
ImGui.Text(DescType.ToName());

ImGui.NextColumn();

ImGui.TextWrapped(Description);
var acts = rotation.AllActions;
foreach (var item in Actions)
{
var a = acts.FirstOrDefault(a => a.ID == (uint)item);
if (a == null) continue;
ImGui.Image(a.GetTexture().ImGuiHandle, new System.Numerics.Vector2(24, 24));
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip(a.Name);
}
ImGui.SameLine();
}


ImGui.Columns();
}

public static RotationDescAttribute Merge(IEnumerable<RotationDescAttribute> rotationDescAttributes)
{
var result = new RotationDescAttribute();
foreach (var attr in rotationDescAttributes)
{
if(!string.IsNullOrEmpty(attr.Description))
{
result.Description = attr.Description;
}
if(attr.DescType != DescType.None)
{
result.DescType = attr.DescType;
}
result.Actions = result.Actions.Union(attr.Actions);
}

if (result.DescType == DescType.None) return null;
return result;
}
}
21 changes: 17 additions & 4 deletions RotationSolver/Helpers/ImguiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
using System.Linq;
using System.Numerics;
using System.Reflection;
using static System.Net.Mime.MediaTypeNames;

namespace RotationSolver.Helpers;

internal static class ImGuiHelper
{
public static void DrawEnableTexture<T>(this T texture, bool isSelected, Action selected,
Action additonalHeader = null, Action otherThing = null) where T : class, ITexture
Action<string> showToolTip = null,Action additonalHeader = null, Action otherThing = null)
where T : class, ITexture
{
showToolTip ??= text =>
{
if (!string.IsNullOrEmpty(text)) ImGui.SetTooltip(text);
};

ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(3f, 3f));

ImGui.Columns(2, texture.Name, false);
Expand All @@ -30,8 +37,14 @@ public static void DrawEnableTexture<T>(this T texture, bool isSelected, Action
var able = texture as IEnable;

var desc = able?.Description;
HoveredString(desc, selected);

if (ImGui.IsItemHovered())
{
showToolTip(desc);
if (ImGui.IsMouseDown(ImGuiMouseButton.Left))
{
selected?.Invoke();
}
}
ImGui.NextColumn();

bool enable = false;
Expand All @@ -46,7 +59,7 @@ public static void DrawEnableTexture<T>(this T texture, bool isSelected, Action
}
if (isSelected) ImGui.PopStyleColor();

HoveredString(desc);
showToolTip(desc);
}


Expand Down
22 changes: 15 additions & 7 deletions RotationSolver/Localization/EnumTranslations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,21 @@ internal static class EnumTranslations

public static string ToName(this DescType type) => type switch
{
DescType.Description => LocalizationManager.RightLang.DescType_Description,
DescType.BreakingAction => LocalizationManager.RightLang.DescType_BreakingAction,
DescType.HealArea => LocalizationManager.RightLang.DescType_HealArea,
DescType.HealSingle => LocalizationManager.RightLang.DescType_HealSingle,
DescType.DefenseArea => LocalizationManager.RightLang.DescType_DefenseArea,
DescType.DefenseSingle => LocalizationManager.RightLang.DescType_DefenseSingle,
DescType.MoveAction => LocalizationManager.RightLang.DescType_MoveAction,
DescType.BurstActions => LocalizationManager.RightLang.DescType_BurstActions,

DescType.MoveForwardGCD => LocalizationManager.RightLang.DescType_MoveForwardGCD,
DescType.HealSingleGCD => LocalizationManager.RightLang.DescType_HealSingleGCD,
DescType.HealAreaGCD => LocalizationManager.RightLang.DescType_HealAreaGCD,
DescType.DefenseSingleGCD => LocalizationManager.RightLang.DescType_DefenseSingleGCD,
DescType.DefenseAreaGCD => LocalizationManager.RightLang.DescType_DefenseAreaGCD,

DescType.MoveForwardAbility => LocalizationManager.RightLang.DescType_MoveForwardAbility,
DescType.MoveBackAbility => LocalizationManager.RightLang.DescType_MoveBackAbility,
DescType.HealSingleAbility => LocalizationManager.RightLang.DescType_HealSingleAbility,
DescType.HealAreaAbility => LocalizationManager.RightLang.DescType_HealAreaAbility,
DescType.DefenceSingleAbility => LocalizationManager.RightLang.DescType_DefenseSingleAbility,
DescType.DefenceAreaAbility => LocalizationManager.RightLang.DescType_DefenseAreaAbility,

_ => string.Empty,
};

Expand Down
20 changes: 13 additions & 7 deletions RotationSolver/Localization/Strings_Major.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,19 @@ internal partial class Strings
#endregion

#region DescType
public string DescType_Description { get; set; } = "Loop Description";
public string DescType_BreakingAction { get; set; } = "Burst Skills";
public string DescType_HealArea { get; set; } = "Range Healing";
public string DescType_HealSingle { get; set; } = "Mono Healing";
public string DescType_DefenseArea { get; set; } = "Range Defense";
public string DescType_DefenseSingle { get; set; } = "Mono Defense";
public string DescType_MoveAction { get; set; } = "Move Skills";
public string DescType_BurstActions { get; set; } = "Burst Actions";
public string DescType_MoveForwardGCD { get; set; } = "Move forward GCD";
public string DescType_HealAreaGCD { get; set; } = "Range Healing GCD";
public string DescType_HealSingleGCD { get; set; } = "Mono Healing GCD";
public string DescType_DefenseAreaGCD { get; set; } = "Range Defense GCD";
public string DescType_DefenseSingleGCD { get; set; } = "Mono Defense GCD";

public string DescType_HealAreaAbility { get; set; } = "Range Healing Ability";
public string DescType_HealSingleAbility { get; set; } = "Mono Healing Ability";
public string DescType_DefenseAreaAbility { get; set; } = "Range Defense Ability";
public string DescType_DefenseSingleAbility { get; set; } = "Mono Defense Ability";
public string DescType_MoveForwardAbility { get; set; } = "Move forward Ability";
public string DescType_MoveBackAbility { get; set; } = "Move back Ability";

#endregion

Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/Rotations/Basic/BLU_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ public override bool CanUse(out IAction act, bool mustUse = false, bool emptyOrS

#endregion

private protected override bool MoveGCD(out IAction act)
private protected override bool MoveForwardGCD(out IAction act)
{
if (Loom.CanUse(out act)) return true;
return base.MoveGCD(out act);
return base.MoveForwardGCD(out act);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using RotationSolver.Actions;
using RotationSolver.Actions.BaseAction;
using RotationSolver.Attributes;
using RotationSolver.Commands;
using RotationSolver.Data;
using RotationSolver.Helpers;
Expand Down Expand Up @@ -266,31 +267,37 @@ private protected virtual bool EmergencyAbility(byte abilitiesRemaining, IAction
return false;
}

[RotationDesc(DescType.MoveForwardAbility)]
private protected virtual bool MoveForwardAbility(byte abilitiesRemaining, out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.MoveBackAbility)]
private protected virtual bool MoveBackAbility(byte abilitiesRemaining, out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.HealSingleAbility)]
private protected virtual bool HealSingleAbility(byte abilitiesRemaining, out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.HealAreaAbility)]
private protected virtual bool HealAreaAbility(byte abilitiesRemaining, out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.DefenceSingleAbility)]
private protected virtual bool DefenceSingleAbility(byte abilitiesRemaining, out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.DefenceAreaAbility)]
private protected virtual bool DefenceAreaAbility(byte abilitiesRemaining, out IAction act)
{
act = null; return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using Dalamud.Game.ClientState.Objects.Types;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Actions.BaseAction;
using RotationSolver.Attributes;
using RotationSolver.Configuration.RotationConfig;
using RotationSolver.Data;
using RotationSolver.Localization;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace RotationSolver.Rotations.CustomRotation;

[RotationDesc(DescType.BurstActions)]
internal abstract partial class CustomRotation : ICustomRotation
{
public abstract ClassJobID[] JobIDs { get; }
Expand Down Expand Up @@ -43,20 +46,20 @@ public bool IsEnabled
public uint IconID { get; }

public IRotationConfigSet Configs { get; }
private protected CustomRotation()
{
IconID = IconSet.GetJobIcon(this);
Configs = CreateConfiguration();
}

public BattleChara MoveTarget { get; private set; }

public string Description => string.Join('\n', DescriptionDict.Select(pair => pair.Key.ToName() + " → " + pair.Value));
public virtual string Description { get; } = string.Empty;

/// <summary>
/// Description about the actions.
/// </summary>
public virtual SortedList<DescType, string> DescriptionDict { get; } = new SortedList<DescType, string>();
//public virtual SortedList<DescType, string> DescriptionDict { get; } = new SortedList<DescType, string>();
private protected CustomRotation()
{
IconID = IconSet.GetJobIcon(this);
Configs = CreateConfiguration();
}

private protected virtual IRotationConfigSet CreateConfiguration()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
using Dalamud.Interface;
using Dalamud.Utility;
using ImGuiNET;
using RotationSolver.Attributes;
using RotationSolver.Helpers;
using RotationSolver.Localization;
using RotationSolver.Timeline;
using RotationSolver.Windows.RotationConfigWindow;
using System.Reflection;

namespace RotationSolver.Rotations.CustomRotation
{
internal abstract partial class CustomRotation
{
public unsafe void Display(ICustomRotation[] rotations, bool canAddButton) => this.DrawEnableTexture(canAddButton, null, () =>
public unsafe void Display(ICustomRotation[] rotations, bool canAddButton)
=> this.DrawEnableTexture(canAddButton, null,
text =>
{
ImGui.OpenPopup("Popup" + GetHashCode().ToString());

if (ImGui.BeginPopup("Popup" + GetHashCode().ToString()))
{
if(!string.IsNullOrEmpty(text))
{
ImGui.TextWrapped(text);
ImGui.NewLine();
}

var type = this.GetType();
RotationDescAttribute.Merge(type.GetCustomAttributes<RotationDescAttribute>())?.Display(this);

foreach (var m in type.GetMethods())
{
RotationDescAttribute.Merge(m.GetCustomAttributes<RotationDescAttribute>())?.Display(this);
}

ImGui.EndPopup();
}
}, () =>
{
if (!string.IsNullOrEmpty(RotationName) && rotations != null)
{
Expand Down
11 changes: 9 additions & 2 deletions RotationSolver/Rotations/CustomRotation/CustomRotation_GCD.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using RotationSolver.Actions;
using RotationSolver.Actions.BaseAction;
using RotationSolver.Attributes;
using RotationSolver.Commands;
using RotationSolver.Data;
using RotationSolver.Helpers;
using RotationSolver.Localization;
using RotationSolver.Updaters;
using System.Linq;

Expand All @@ -21,7 +23,7 @@ private IAction GCD(byte abilityRemain, bool helpDefenseAOE, bool helpDefenseSin

if (RaiseSpell(specialType, out act, abilityRemain, false)) return act;

if (specialType == SpecialCommandType.MoveForward && MoveGCD(out act))
if (specialType == SpecialCommandType.MoveForward && MoveForwardGCD(out act))
{
if (act is BaseAction b && ObjectHelper.DistanceToPlayer(b.Target) > 5) return act;
}
Expand Down Expand Up @@ -89,26 +91,31 @@ private protected virtual bool EmergencyGCD(out IAction act)
act = null; return false;
}

private protected virtual bool MoveGCD(out IAction act)
[RotationDesc(DescType.MoveForwardGCD)]
private protected virtual bool MoveForwardGCD(out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.HealSingleGCD)]
private protected virtual bool HealSingleGCD(out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.HealAreaGCD)]
private protected virtual bool HealAreaGCD(out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.DefenseSingleGCD)]
private protected virtual bool DefenseSingleGCD(out IAction act)
{
act = null; return false;
}

[RotationDesc(DescType.DefenseAreaGCD)]
private protected virtual bool DefenseAreaGCD(out IAction act)
{
act = null; return false;
Expand Down
Loading

0 comments on commit 7e96cd2

Please sign in to comment.