Skip to content

Commit

Permalink
tweak new code & add translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Mar 27, 2023
1 parent 7e3315c commit d54790b
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 56 deletions.
60 changes: 34 additions & 26 deletions LookupAnything/Framework/Fields/CharacterGiftTastesField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ internal class CharacterGiftTastesField : GenericField
/// <param name="label">A short field label.</param>
/// <param name="giftTastes">The items by how much this NPC likes receiving them.</param>
/// <param name="showTaste">The gift taste to show.</param>
/// <param name="onlyRevealed">Only show gift tastes the player has discovered for themselves.</param>
/// <param name="onlyRevealed">Whether to only show gift tastes the player has discovered for themselves.</param>
/// <param name="highlightUnrevealed">Whether to highlight items which haven't been revealed in the NPC profile yet.</param>
/// <param name="onlyOwned">Whether to only show gift tastes for items which the player owns somewhere in the world.</param>
/// <param name="ownedItemsCache">A lookup cache for owned items, as created by <see cref="GetOwnedItemsCache"/>.</param>
public CharacterGiftTastesField(string label, IDictionary<GiftTaste, GiftTasteModel[]> giftTastes, GiftTaste showTaste, bool onlyRevealed, bool highlightUnrevealed, bool showUnowned, IDictionary<string, bool> ownedItemsCache)
: base(label, CharacterGiftTastesField.GetText(giftTastes, showTaste, onlyRevealed, highlightUnrevealed, showUnowned, ownedItemsCache)) { }
public CharacterGiftTastesField(string label, IDictionary<GiftTaste, GiftTasteModel[]> giftTastes, GiftTaste showTaste, bool onlyRevealed, bool highlightUnrevealed, bool onlyOwned, IDictionary<string, bool> ownedItemsCache)
: base(label, CharacterGiftTastesField.GetText(giftTastes, showTaste, onlyRevealed, highlightUnrevealed, onlyOwned, ownedItemsCache)) { }

/// <summary>Get a lookup cache for owned items.</summary>
/// <param name="gameHelper">Provides utility methods for interacting with the game code.</param>
Expand All @@ -48,10 +49,11 @@ private static string GetOwnedItemKey(Item item)
/// <summary>Get the text to display.</summary>
/// <param name="giftTastes">The items by how much this NPC likes receiving them.</param>
/// <param name="showTaste">The gift taste to show.</param>
/// <param name="onlyRevealed">Only show gift tastes the player has discovered for themselves.</param>
/// <param name="onlyRevealed">Whether to only show gift tastes the player has discovered for themselves.</param>
/// <param name="highlightUnrevealed">Whether to highlight items which haven't been revealed in the NPC profile yet.</param>
/// <param name="onlyOwned">Whether to only show gift tastes for items which the player owns somewhere in the world.</param>
/// <param name="ownedItemsCache">A lookup cache for owned items, as created by <see cref="GetOwnedItemsCache"/>.</param>
private static IEnumerable<IFormattedText> GetText(IDictionary<GiftTaste, GiftTasteModel[]> giftTastes, GiftTaste showTaste, bool onlyRevealed, bool highlightUnrevealed, bool showUnowned, IDictionary<string, bool> ownedItemsCache)
private static IEnumerable<IFormattedText> GetText(IDictionary<GiftTaste, GiftTasteModel[]> giftTastes, GiftTaste showTaste, bool onlyRevealed, bool highlightUnrevealed, bool onlyOwned, IDictionary<string, bool> ownedItemsCache)
{
if (!giftTastes.ContainsKey(showTaste))
yield break;
Expand All @@ -63,50 +65,56 @@ private static IEnumerable<IFormattedText> GetText(IDictionary<GiftTaste, GiftTa
from entry in giftTastes[showTaste]
let item = entry.Item

let inInventory = ownedItemsCache.TryGetValue(CharacterGiftTastesField.GetOwnedItemKey(item), out bool rawVal)
? rawVal
: null as bool?
let isOwned = inInventory != null
let ownership = ownedItemsCache.TryGetValue(CharacterGiftTastesField.GetOwnedItemKey(item), out bool rawVal) ? rawVal : null as bool? // true = in inventory, false = owned elsewhere, null = none found
let isOwned = ownership is not null
let inInventory = ownership is true

where !onlyRevealed || entry.IsRevealed
orderby inInventory ?? false descending, isOwned descending, item.DisplayName
select new { Item = item, IsInventory = inInventory ?? false, IsOwned = isOwned, isRevealed = entry.IsRevealed }
orderby inInventory descending, isOwned descending, item.DisplayName
select new { Item = item, IsInventory = inInventory, IsOwned = isOwned, entry.IsRevealed }
)
.ToArray();
int unrevealed = onlyRevealed
? giftTastes[showTaste].Count(p => !p.IsRevealed)
: 0;
int unowned = showUnowned
? 0
: items.Count(i => !i.IsInventory && !i.IsOwned);

// generate text
if (items.Any())
{
int unrevealed = 0;
int unowned = 0;

for (int i = 0, last = items.Length - 1; i <= last; i++)
{
var entry = items[i];

if (onlyRevealed && !entry.IsRevealed)
{
unrevealed++;
continue;
}

if (onlyOwned && !entry.IsOwned)
{
unowned++;
continue;
}

string text = i != last
? entry.Item.DisplayName + ", "
: entry.Item.DisplayName;
bool bold = highlightUnrevealed && !entry.isRevealed;
bool bold = highlightUnrevealed && !entry.IsRevealed;

if (entry.IsInventory)
yield return new FormattedText(text, Color.Green, bold);
else if (entry.IsOwned)
yield return new FormattedText(text, Color.Black, bold);
else if (showUnowned)
else
yield return new FormattedText(text, Color.Gray, bold);
}

if (unowned > 0)
yield return new FormattedText(I18n.Npc_UnownedGiftTasteAppended(count: unowned), Color.Gray);

if (unrevealed > 0)
yield return new FormattedText(I18n.Npc_UndiscoveredGiftTasteAppended(count: unrevealed), Color.Gray);
yield return new FormattedText(I18n.Npc_UndiscoveredGiftTaste(count: unrevealed), Color.Gray);

if (unowned > 0)
yield return new FormattedText(I18n.Npc_UnownedGiftTaste(count: unowned), Color.Gray);
}
else
yield return new FormattedText(I18n.Npc_UndiscoveredGiftTaste(count: unrevealed), Color.Gray);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public void Register()
get: config => config.ShowAllGiftTastes,
set: (config, value) => config.ShowAllGiftTastes = value
)
.AddCheckbox(
name: I18n.Config_ShowUnownedGifts_Name,
tooltip: I18n.Config_ShowUnownedGifts_Desc,
get: config => config.ShowUnownedGifts,
set: (config, value) => config.ShowUnownedGifts = value
)

.AddSectionTitle(I18n.Config_Title_AdvancedOptions)
.AddCheckbox(
Expand All @@ -89,12 +95,6 @@ public void Register()
get: config => config.EnableTargetRedirection,
set: (config, value) => config.EnableTargetRedirection = value
)
.AddCheckbox(
name: I18n.Config_ShowUnownedGifts_Name,
tooltip: I18n.Config_ShowUnownedGifts_Desc,
get: config => config.ShowUnownedGifts,
set: (config, value) => config.ShowUnownedGifts = value
)
.AddNumberField(
name: I18n.Config_ScrollAmount_Name,
tooltip: I18n.Config_ScrollAmount_Desc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private ISubject BuildSubject(NPC npc)
highlightUnrevealedGiftTastes: config.HighlightUnrevealedGiftTastes,
showAllGiftTastes: config.ShowAllGiftTastes,
enableTargetRedirection: config.EnableTargetRedirection,
showUnowned: config.ShowUnownedGifts
showUnownedGifts: config.ShowUnownedGifts
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class CharacterSubject : BaseSubject
/// <summary>Whether to look up the original entity when the game spawns a temporary copy.</summary>
private readonly bool EnableTargetRedirection;

/// <summary>Whether to show unowned gift tastes. </summary>
/// <summary>Whether to show gift tastes that the player doesn't own somewhere in the world.</summary>
private readonly bool ShowUnownedGifts;

/// <summary>Whether the NPC is Gourmand in the Fern Islands farm cave.</summary>
Expand All @@ -78,8 +78,9 @@ internal class CharacterSubject : BaseSubject
/// <param name="highlightUnrevealedGiftTastes">Whether to highlight item gift tastes which haven't been revealed in the NPC profile.</param>
/// <param name="showAllGiftTastes">Whether to show all NPC gift tastes.</param>
/// <param name="enableTargetRedirection">Whether to look up the original entity when the game spawns a temporary copy.</param>
/// <param name="showUnownedGifts">Whether to show gift tastes that the player doesn't own somewhere in the world.</param>
/// <remarks>Reverse engineered from <see cref="NPC"/>.</remarks>
public CharacterSubject(ISubjectRegistry codex, GameHelper gameHelper, NPC npc, SubjectType type, Metadata metadata, IReflectionHelper reflectionHelper, bool progressionMode, bool highlightUnrevealedGiftTastes, bool showAllGiftTastes, bool enableTargetRedirection, bool showUnowned)
public CharacterSubject(ISubjectRegistry codex, GameHelper gameHelper, NPC npc, SubjectType type, Metadata metadata, IReflectionHelper reflectionHelper, bool progressionMode, bool highlightUnrevealedGiftTastes, bool showAllGiftTastes, bool enableTargetRedirection, bool showUnownedGifts)
: base(gameHelper)
{
this.Codex = codex;
Expand All @@ -88,7 +89,7 @@ public CharacterSubject(ISubjectRegistry codex, GameHelper gameHelper, NPC npc,
this.HighlightUnrevealedGiftTastes = highlightUnrevealedGiftTastes;
this.ShowAllGiftTastes = showAllGiftTastes;
this.EnableTargetRedirection = enableTargetRedirection;
this.ShowUnownedGifts = showUnowned;
this.ShowUnownedGifts = showUnownedGifts;

// initialize
this.Target = npc;
Expand Down Expand Up @@ -402,7 +403,7 @@ private IEnumerable<ICustomField> GetDataForVillager(NPC npc)
/// <param name="taste">The gift taste to display.</param>
private ICustomField GetGiftTasteField(string label, IDictionary<GiftTaste, GiftTasteModel[]> giftTastes, IDictionary<string, bool> ownedItemsCache, GiftTaste taste)
{
return new CharacterGiftTastesField(label, giftTastes, taste, onlyRevealed: this.ProgressionMode, highlightUnrevealed: this.HighlightUnrevealedGiftTastes, showUnowned: this.ShowUnownedGifts, ownedItemsCache);
return new CharacterGiftTastesField(label, giftTastes, taste, onlyRevealed: this.ProgressionMode, highlightUnrevealed: this.HighlightUnrevealedGiftTastes, onlyOwned: !this.ShowUnownedGifts, ownedItemsCache);
}

/*****
Expand Down
2 changes: 1 addition & 1 deletion LookupAnything/Framework/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class ModConfig
/// <summary>Whether to show advanced data mining fields.</summary>
public bool ShowDataMiningFields { get; set; }

/// <summary>Whether to show gift tastes that are unowned. </summary>
/// <summary>Whether to show gift tastes that the player doesn't own somewhere in the world.</summary>
public bool ShowUnownedGifts { get; set; } = true;
}
}
4 changes: 3 additions & 1 deletion LookupAnything/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@
"npc.friendship.need-bouquet": "Blumenstrauß für nächstes erforderlich",
"npc.friendship.need-points": "nächstes in {{count}} Punkten",
"npc.undiscovered-gift-taste": "{{count}} unaufgedeckte Gegenstände",
"npc.undiscovered-gift-taste-appended": " und {{count}} unaufgedeckte Gegenstände",
"npc.unowned-gift-taste": "{{count}} unowned items", // TODO


/*********
Expand Down Expand Up @@ -713,6 +713,8 @@
"config.highlight-unrevealed-gift-tastes.desc": "Hervorhebung von Gegenstandsgeschenken, die im NSC-Profil noch nicht offenbart wurden. Wenn diese Option aktiviert ist, werden nicht enthüllte Geschenkvorlieben fett dargestellt und es werden auch ungeliebte/gehasste Geschenke angezeigt.",
"config.show-all-gift-tastes.name": "Zeige alle Geschenk Vorlieben",
"config.show-all-gift-tastes.desc": "Ob alle Geschenkvorlieben bei der Suche nach NSCs und Gegenständen angezeigt werden sollen; wenn deaktiviert, werden nur die relevantesten Vorlieben (z.B. geliebte oder beliebte Geschenke) angezeigt.",
"config.show-unowned-gifts.name": "Show unowned gift tastes", // TODO
"config.show-unowned-gifts.desc": "Whether to show gift tastes for items that the player doesn't own somewhere in the world.", // TODO

// advanced options
"config.title.advanced-options": "Erweiterte Optionen",
Expand Down
7 changes: 3 additions & 4 deletions LookupAnything/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,7 @@
"npc.friendship.need-bouquet": "need bouquet for next",
"npc.friendship.need-points": "next in {{count}} pts",
"npc.undiscovered-gift-taste": "{{count}} unrevealed items",
"npc.undiscovered-gift-taste-appended": ", and {{count}} unrevealed items",
"npc.unowned-gift-taste-appended": " and {{count}} unowned items",
"npc.unowned-gift-taste": "{{count}} unowned items",


/*********
Expand Down Expand Up @@ -713,6 +712,8 @@
"config.highlight-unrevealed-gift-tastes.desc": "Whether to highlight item gift tastes which haven't been revealed in the NPC profile. When enabled, unrevealed gift tastes will be bold and lookups will also show disliked/hated gifts.",
"config.show-all-gift-tastes.name": "Show all gift tastes",
"config.show-all-gift-tastes.desc": "Whether to show all gift tastes for NPC and item lookups; when disabled, only the most relevant tastes (e.g. loved or liked gifts) are shown.",
"config.show-unowned-gifts.name": "Show unowned gift tastes",
"config.show-unowned-gifts.desc": "Whether to show gift tastes for items that the player doesn't own somewhere in the world.",

// advanced options
"config.title.advanced-options": "Advanced options",
Expand All @@ -726,8 +727,6 @@
"config.target-redirection.desc": "In some cases the game spawns a temporary entity to represent another one. For example, Abigail in the mines is actually a temporary NPC with the name 'AbigailMine', so looking her up there won't show Abigail's real info. With this option enabled, Lookup Anything will look up the original Abigail instead.",
"config.scroll-amount.name": "Scroll amount",
"config.scroll-amount.desc": "The number of pixels to shift content on each up/down scroll.",
"config.show-unowned-gifts.name": "Show Unowned Gifts",
"config.show-unowned-gifts.desc": "Whether to show gifts that the player doesn't own or have in their inventory",

// controls section
"config.title.controls": "Controls",
Expand Down
4 changes: 3 additions & 1 deletion LookupAnything/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
"npc.friendship.need-bouquet": "Necesitas un ramo de flores para lo siguiente",
"npc.friendship.need-points": "siguiente en {{count}} puntos",
"npc.undiscovered-gift-taste": "{{count}} items sin revelar",
"npc.undiscovered-gift-taste-appended": ", y {{count}} items sin revelar",
"npc.unowned-gift-taste": "{{count}} unowned items", // TODO


/*********
Expand Down Expand Up @@ -714,6 +714,8 @@
"config.highlight-unrevealed-gift-tastes.desc": "Si se desea resaltar los gustos de los regalos que no han sido revelados en el perfil del NPC. Cuando se activa, los gustos de los regalos no revelados estarán en negrita y las búsquedas también mostrarán los regalos que no gustan/odian.",
"config.show-all-gift-tastes.name": "Mostrar todos los gustos de los regalos",
"config.show-all-gift-tastes.desc": "Mostrar o no todos los gustos de los regalos en las búsquedas de PNJs y objetos; cuando se desactiva, sólo se muestran los gustos más relevantes (por ejemplo, los regalos amados o gustados).",
"config.show-unowned-gifts.name": "Show unowned gift tastes", // TODO
"config.show-unowned-gifts.desc": "Whether to show gift tastes for items that the player doesn't own somewhere in the world.", // TODO

// advanced options
"config.title.advanced-options": "Opciones avanzadas",
Expand Down
4 changes: 3 additions & 1 deletion LookupAnything/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@
"npc.friendship.need-bouquet": "besoin d'un bouquet",
"npc.friendship.need-points": "manque {{count}} pts",
"npc.undiscovered-gift-taste": "{{count}} goût(s) non révelé(s)",
"npc.undiscovered-gift-taste-appended": ", et {{count}} goût(s) non révelé(s)",
"npc.unowned-gift-taste": "{{count}} unowned items", // TODO


/*********
Expand Down Expand Up @@ -711,6 +711,8 @@
"config.highlight-unrevealed-gift-tastes.desc": "Si vous souhaitez mettre en évidence les goûts en matière de cadeaux qui n'ont pas été révélés dans le profil du PNJ. Lorsque cette option est activée, les goûts des cadeaux qui n'ont pas été révélés seront en gras et les recherches montreront également les cadeaux pas aimé ou détesté.",
"config.show-all-gift-tastes.name": "Afficher tous les goûts en matière de cadeaux",
"config.show-all-gift-tastes.desc": "Afficher ou non tous les goûts en matière de cadeaux pour les recherches de PNJ et d'objets ; si cette option est désactivée, seuls les goûts les plus pertinents (par exemple, les cadeaux aimés ou appréciés) sont affichés.",
"config.show-unowned-gifts.name": "Show unowned gift tastes", // TODO
"config.show-unowned-gifts.desc": "Whether to show gift tastes for items that the player doesn't own somewhere in the world.", // TODO

// advanced options
"config.title.advanced-options": "Options avancées",
Expand Down
4 changes: 3 additions & 1 deletion LookupAnything/i18n/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@
"npc.friendship.need-bouquet": "a következőhöz adjál neki virágcsokrot.",
"npc.friendship.need-points": "Következő szint {{count}} pont múlva",
"npc.undiscovered-gift-taste": "{{count}} fel nem fedezett dolog",
"npc.undiscovered-gift-taste-appended": ", és {{count}} fel nem fedezett dolog",
"npc.unowned-gift-taste": "{{count}} unowned items", // TODO


/*********
Expand Down Expand Up @@ -723,6 +723,8 @@
"config.highlight-unrevealed-gift-tastes.desc": "Whether to highlight item gift tastes which haven't been revealed in the NPC profile. When enabled, unrevealed gift tastes will be bold and lookups will also show disliked/hated gifts.",
"config.show-all-gift-tastes.name": "Show all gift tastes",
"config.show-all-gift-tastes.desc": "Whether to show all gift tastes for NPC and item lookups; when disabled, only the most relevant tastes (e.g. loved or liked gifts) are shown.",
"config.show-unowned-gifts.name": "Show unowned gift tastes", // TODO
"config.show-unowned-gifts.desc": "Whether to show gift tastes for items that the player doesn't own somewhere in the world.", // TODO

// advanced options
// TODO
Expand Down
Loading

0 comments on commit d54790b

Please sign in to comment.