Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions Patches/Content/CustomEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public KeywordPropertiesAttribute(AutoKeywordPosition position, bool richKeyword

public AutoKeywordPosition Position { get; }
public bool RichKeyword { get; }

/// <summary>
/// The pool whose energy icon the keyword's tooltip should use, e.g. typeof(MyCardPool).
/// Only relevant for rich keywords whose description contains energy icons.
/// If not supplied, the icon is resolved from the character being played, which fails outside of a run
/// (in the card library the tooltip falls back to the colorless icon).
/// </summary>
public Type? Pool { get; set; }
}

public enum AutoKeywordPosition
Expand All @@ -71,7 +79,12 @@ public readonly struct KeywordInfo(string key)
public readonly string Key = key;
public required AutoKeywordPosition AutoPosition { get; init; }
public required bool RichKeyword { get; init; }


/// <summary>
/// Pool supplying the energy icon for this keyword's tooltip. Null if the keyword did not declare one.
/// </summary>
public Type? PoolType { get; init; }

public static implicit operator string(KeywordInfo info) => info.Key;
}

Expand Down Expand Up @@ -315,7 +328,8 @@ static void FindAndGenerate()
CustomKeywords.KeywordIDs.Add((int) key, new(keywordId)
{
AutoPosition = autoPosition,
RichKeyword = poolAttribute?.RichKeyword ?? true
RichKeyword = poolAttribute?.RichKeyword ?? true,
PoolType = poolAttribute?.Pool
});
continue;
}
Expand Down
19 changes: 17 additions & 2 deletions Patches/Localization/CustomTooltips.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using BaseLib.Patches.Content;
using HarmonyLib;
using MegaCrit.Sts2.Core.Entities.Cards;
using MegaCrit.Sts2.Core.Helpers;
using MegaCrit.Sts2.Core.HoverTips;
using MegaCrit.Sts2.Core.Localization;
using MegaCrit.Sts2.Core.Models;

namespace BaseLib.Patches.Localization;

Expand All @@ -23,13 +25,26 @@ public static bool CustomKeyword(CardKeyword keyword, ref IHoverTip __result)
if (info.RichKeyword)
{
LocString description = keyword.GetDescription();
description.Add("energyPrefix", "");
description.Add("energyPrefix", GetEnergyPrefix(info));
__result = new HoverTip(keyword.GetTitle(), description);
return false;
}
}

return true;
}

/// <summary>
/// Resolve the keyword's energy icon from the pool it declared, the way the game resolves it for cards and
/// powers. An empty prefix makes EnergyIconsFormatter fall back to the character being played, which does not
/// exist outside of a run, so the tooltip would show the colorless icon in the card library.
/// </summary>
private static string GetEnergyPrefix(CustomKeywords.KeywordInfo info)
{
if (info.PoolType == null) return "";

AbstractModel? pool = ModelDb.GetByIdOrNull<AbstractModel>(ModelDb.GetId(info.PoolType));
return pool is IPoolModel ? EnergyIconHelper.GetPrefix(pool) : "";
}
}
}