Skip to content

Commit

Permalink
add config options for Lookup Anything's collapsible fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Apr 23, 2024
1 parent 63b609c commit 1be2dc8
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ public void Register()
set: (config, value) => config.HighlightUnrevealedGiftTastes = value
)

// advanced options
.AddSectionTitle(I18n.Config_Title_CollapseFields)
.AddCheckbox(
name: I18n.Config_CollapseFields_Enabled_Name,
tooltip: I18n.Config_CollapseFields_Enabled_Desc,
get: config => config.CollapseLargeFields.Enabled,
set: (config, value) => config.CollapseLargeFields.Enabled = value
)
.AddNumberField(
name: I18n.Config_CollapseFields_ItemRecipes_Name,
tooltip: I18n.Config_CollapseFields_Any_Desc,
get: config => config.CollapseLargeFields.ItemRecipes,
set: (config, value) => config.CollapseLargeFields.ItemRecipes = value,
min: 1,
max: 1000
)
.AddNumberField(
name: I18n.Config_CollapseFields_NpcGiftTastes_Name,
tooltip: I18n.Config_CollapseFields_Any_Desc,
get: config => config.CollapseLargeFields.NpcGiftTastes,
set: (config, value) => config.CollapseLargeFields.NpcGiftTastes = value,
min: 1,
max: 1000
)

// advanced options
.AddSectionTitle(I18n.Config_Title_AdvancedOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ private ISubject BuildSubject(NPC npc)
progressionMode: config.ProgressionMode,
highlightUnrevealedGiftTastes: config.HighlightUnrevealedGiftTastes,
showGiftTastes: config.ShowGiftTastes,
collapseFieldsConfig: config.CollapseLargeFields,
enableTargetRedirection: config.EnableTargetRedirection,
showUnownedGifts: config.ShowUnownedGifts
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ internal class CharacterSubject : BaseSubject
/// <summary>Which gift taste levels to show.</summary>
private readonly ModGiftTasteConfig ShowGiftTastes;

/// <summary>The configured minimum field values needed before they're auto-collapsed.</summary>
private readonly ModCollapseLargeFieldsConfig CollapseFieldsConfig;

/// <summary>Whether to look up the original entity when the game spawns a temporary copy.</summary>
private readonly bool EnableTargetRedirection;

Expand Down Expand Up @@ -76,16 +79,18 @@ internal class CharacterSubject : BaseSubject
/// <param name="progressionMode">Whether to only show content once the player discovers it.</param>
/// <param name="highlightUnrevealedGiftTastes">Whether to highlight item gift tastes which haven't been revealed in the NPC profile.</param>
/// <param name="showGiftTastes">Which gift taste levels to show.</param>
/// <param name="collapseFieldsConfig">The configured minimum field values needed before they're auto-collapsed.</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, bool progressionMode, bool highlightUnrevealedGiftTastes, ModGiftTasteConfig showGiftTastes, bool enableTargetRedirection, bool showUnownedGifts)
public CharacterSubject(ISubjectRegistry codex, GameHelper gameHelper, NPC npc, SubjectType type, Metadata metadata, bool progressionMode, bool highlightUnrevealedGiftTastes, ModGiftTasteConfig showGiftTastes, ModCollapseLargeFieldsConfig collapseFieldsConfig, bool enableTargetRedirection, bool showUnownedGifts)
: base(gameHelper)
{
this.Codex = codex;
this.ProgressionMode = progressionMode;
this.HighlightUnrevealedGiftTastes = highlightUnrevealedGiftTastes;
this.ShowGiftTastes = showGiftTastes;
this.CollapseFieldsConfig = collapseFieldsConfig;
this.EnableTargetRedirection = enableTargetRedirection;
this.ShowUnownedGifts = showUnownedGifts;

Expand Down Expand Up @@ -405,7 +410,7 @@ private IEnumerable<ICustomField> GetDataForVillager(NPC npc)
private ICustomField GetGiftTasteField(string label, IDictionary<GiftTaste, GiftTasteModel[]> giftTastes, IDictionary<string, bool> ownedItemsCache, GiftTaste taste)
{
var field = new CharacterGiftTastesField(label, giftTastes, taste, onlyRevealed: this.ProgressionMode, highlightUnrevealed: this.HighlightUnrevealedGiftTastes, onlyOwned: !this.ShowUnownedGifts, ownedItemsCache);
if (giftTastes.TryGetValue(taste, out GiftTasteModel[]? tastes) && tastes.Length > 30)
if (this.CollapseFieldsConfig.Enabled && giftTastes.TryGetValue(taste, out GiftTasteModel[]? tastes) && tastes.Length >= this.CollapseFieldsConfig.NpcGiftTastes)
field.CollapseByDefault(I18n.Generic_ShowXResults(tastes.Length));
return field;
}
Expand Down
2 changes: 2 additions & 0 deletions LookupAnything/Framework/Lookups/Items/ItemLookupProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ private ISubject BuildSubject(Item target, ObjectContext context, GameLocation?
progressionMode: config.ProgressionMode,
highlightUnrevealedGiftTastes: config.HighlightUnrevealedGiftTastes,
showGiftTastes: config.ShowGiftTastes,
collapseFieldsConfig: config.CollapseLargeFields,
item: target,
context: context,
knownQuality: knownQuality,
Expand Down Expand Up @@ -367,6 +368,7 @@ private ISubject BuildSubject(Crop target, ObjectContext context, HoeDirt? dirt)
progressionMode: config.ProgressionMode,
highlightUnrevealedGiftTastes: config.HighlightUnrevealedGiftTastes,
showGiftTastes: config.ShowGiftTastes,
collapseFieldsConfig: config.CollapseLargeFields,
item: ItemRegistry.Create(indexOfHarvest),
context: context,
location: dirt?.Location,
Expand Down
9 changes: 7 additions & 2 deletions LookupAnything/Framework/Lookups/Items/ItemSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ internal class ItemSubject : BaseSubject
/// <summary>Which gift taste levels to show.</summary>
private readonly ModGiftTasteConfig ShowGiftTastes;

/// <summary>The configured minimum field values needed before they're auto-collapsed.</summary>
private readonly ModCollapseLargeFieldsConfig CollapseFieldsConfig;

/// <summary>Provides subject entries.</summary>
private readonly ISubjectRegistry Codex;

Expand All @@ -79,20 +82,22 @@ internal class ItemSubject : BaseSubject
/// <param name="progressionMode">Whether to only show content once the player discovers it.</param>
/// <param name="highlightUnrevealedGiftTastes">Whether to highlight item gift tastes which haven't been revealed in the NPC profile.</param>
/// <param name="showGiftTastes">Which gift taste levels to show.</param>
/// <param name="collapseFieldsConfig">The configured minimum field values needed before they're auto-collapsed.</param>
/// <param name="item">The underlying target.</param>
/// <param name="context">The context of the object being looked up.</param>
/// <param name="knownQuality">Whether the item quality is known. This is <c>true</c> for an inventory item, <c>false</c> for a map object.</param>
/// <param name="location">The location containing the item, if applicable.</param>
/// <param name="getCropSubject">Get a lookup subject for a crop.</param>
/// <param name="fromCrop">The crop associated with the item (if applicable).</param>
/// <param name="fromDirt">The dirt containing the crop (if applicable).</param>
public ItemSubject(ISubjectRegistry codex, GameHelper gameHelper, bool progressionMode, bool highlightUnrevealedGiftTastes, ModGiftTasteConfig showGiftTastes, Item item, ObjectContext context, bool knownQuality, GameLocation? location, Func<Crop, ObjectContext, HoeDirt?, ISubject> getCropSubject, Crop? fromCrop = null, HoeDirt? fromDirt = null)
public ItemSubject(ISubjectRegistry codex, GameHelper gameHelper, bool progressionMode, bool highlightUnrevealedGiftTastes, ModGiftTasteConfig showGiftTastes, ModCollapseLargeFieldsConfig collapseFieldsConfig, Item item, ObjectContext context, bool knownQuality, GameLocation? location, Func<Crop, ObjectContext, HoeDirt?, ISubject> getCropSubject, Crop? fromCrop = null, HoeDirt? fromDirt = null)
: base(gameHelper)
{
this.Codex = codex;
this.ProgressionMode = progressionMode;
this.HighlightUnrevealedGiftTastes = highlightUnrevealedGiftTastes;
this.ShowGiftTastes = showGiftTastes;
this.CollapseFieldsConfig = collapseFieldsConfig;
this.Target = item;
this.FromCrop = fromCrop ?? fromDirt?.crop;
this.FromDirt = fromDirt;
Expand Down Expand Up @@ -286,7 +291,7 @@ select name
if (recipes.Length > 0)
{
var field = new ItemRecipesField(this.GameHelper, I18n.Item_Recipes(), item, recipes);
if (recipes.Length > 10)
if (this.CollapseFieldsConfig.Enabled && recipes.Length >= this.CollapseFieldsConfig.ItemRecipes)
field.CollapseByDefault(I18n.Generic_ShowXResults(count: recipes.Length));
yield return field;
}
Expand Down
15 changes: 15 additions & 0 deletions LookupAnything/Framework/ModCollapseLargeFieldsConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Pathoschild.Stardew.LookupAnything.Framework
{
/// <summary>As part of <see cref="ModConfig"/>, the minimum field values needed before they're auto-collapsed.</summary>
public class ModCollapseLargeFieldsConfig
{
/// <summary>Whether to collapse large fields.</summary>
public bool Enabled { get; set; } = true;

/// <summary>In an item lookup, the minimum recipes needed before the field is collapsed by default.</summary>
public int ItemRecipes { get; set; } = 11;

/// <summary>In a character lookup, the minimum gift tastes needed before the field is collapsed by default.</summary>
public int NpcGiftTastes { get; set; } = 31;
}
}
4 changes: 4 additions & 0 deletions LookupAnything/Framework/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ internal class ModConfig
/// <summary>Which gift taste levels to show in NPC and item lookups.</summary>
public ModGiftTasteConfig ShowGiftTastes { get; set; } = new();

/// <summary>The minimum field values needed before they're auto-collapsed.</summary>
public ModCollapseLargeFieldsConfig CollapseLargeFields { get; set; } = new();

/// <summary>Whether to show gift tastes that the player doesn't own somewhere in the world.</summary>
public bool ShowUnownedGifts { get; set; } = true;

Expand Down Expand Up @@ -63,6 +66,7 @@ public void OnDeserialized(StreamingContext context)
{
this.Controls ??= new ModConfigKeys();
this.ShowGiftTastes ??= new ModGiftTasteConfig();
this.CollapseLargeFields ??= new ModCollapseLargeFieldsConfig();
}
}
}
3 changes: 3 additions & 0 deletions LookupAnything/docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[← back to readme](README.md)

# Release notes
## Upcoming release
* Added config options for the new collapsible fields.

## 1.42.0
Released 21 April 2024 for SMAPI 4.0.0 or later.

Expand Down
11 changes: 11 additions & 0 deletions LookupAnything/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,17 @@
"config.highlight-unrevealed-gift-tastes.name": "Hebe unentdeckte Geschenkvorlieben hervor",
"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.",

// collapse fields
// TODO
"config.title.collapse-fields": "Collapse large fields",

"config.collapse-fields.enabled.name": "Enabled",
"config.collapse-fields.enabled.desc": "Whether to collapse large fields, so the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

"config.collapse-fields.npc-gift-tastes.name": "NPC lookup: gift tastes",
"config.collapse-fields.item-recipes.name": "Item lookup: recipes",
"config.collapse-fields.any.desc": "If the field contains this many values, the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

// advanced options
"config.title.advanced-options": "Erweiterte Optionen",
"config.tile-lookups.name": "Nachschlagen von Kacheln",
Expand Down
10 changes: 10 additions & 0 deletions LookupAnything/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@
"config.highlight-unrevealed-gift-tastes.name": "Highlight unrevealed gifts",
"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.",

// collapse fields
"config.title.collapse-fields": "Collapse large fields",

"config.collapse-fields.enabled.name": "Enabled",
"config.collapse-fields.enabled.desc": "Whether to collapse large fields, so the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

"config.collapse-fields.npc-gift-tastes.name": "NPC lookup: gift tastes",
"config.collapse-fields.item-recipes.name": "Item lookup: recipes",
"config.collapse-fields.any.desc": "If the field contains this many values, the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

// advanced options
"config.title.advanced-options": "Advanced options",
"config.tile-lookups.name": "Tile lookups",
Expand Down
11 changes: 11 additions & 0 deletions LookupAnything/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,17 @@
"config.highlight-unrevealed-gift-tastes.name": "Destacar los gustos de los regalos no revelados",
"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.",

// collapse fields
// TODO
"config.title.collapse-fields": "Collapse large fields",

"config.collapse-fields.enabled.name": "Enabled",
"config.collapse-fields.enabled.desc": "Whether to collapse large fields, so the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

"config.collapse-fields.npc-gift-tastes.name": "NPC lookup: gift tastes",
"config.collapse-fields.item-recipes.name": "Item lookup: recipes",
"config.collapse-fields.any.desc": "If the field contains this many values, the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

// advanced options
"config.title.advanced-options": "Opciones avanzadas",
"config.tile-lookups.name": "Búsqueda de baldosas",
Expand Down
11 changes: 11 additions & 0 deletions LookupAnything/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,17 @@
"config.highlight-unrevealed-gift-tastes.name": "Mettre en évidence les goûts des cadeaux non révélés",
"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.",

// collapse fields
// TODO
"config.title.collapse-fields": "Collapse large fields",

"config.collapse-fields.enabled.name": "Enabled",
"config.collapse-fields.enabled.desc": "Whether to collapse large fields, so the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

"config.collapse-fields.npc-gift-tastes.name": "NPC lookup: gift tastes",
"config.collapse-fields.item-recipes.name": "Item lookup: recipes",
"config.collapse-fields.any.desc": "If the field contains this many values, the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

// advanced options
"config.title.advanced-options": "Options avancées",
"config.tile-lookups.name": "Recherche de tuiles",
Expand Down
11 changes: 11 additions & 0 deletions LookupAnything/i18n/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,17 @@
"config.highlight-unrevealed-gift-tastes.name": "Highlight unrevealed gift tastes",
"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.",

// collapse fields
// TODO
"config.title.collapse-fields": "Collapse large fields",

"config.collapse-fields.enabled.name": "Enabled",
"config.collapse-fields.enabled.desc": "Whether to collapse large fields, so the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

"config.collapse-fields.npc-gift-tastes.name": "NPC lookup: gift tastes",
"config.collapse-fields.item-recipes.name": "Item lookup: recipes",
"config.collapse-fields.any.desc": "If the field contains this many values, the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

// advanced options
// TODO
"config.title.advanced-options": "Advanced options",
Expand Down
11 changes: 11 additions & 0 deletions LookupAnything/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,17 @@
"config.highlight-unrevealed-gift-tastes.name": "Evidenzia i gusti dei regali non rivelati",
"config.highlight-unrevealed-gift-tastes.desc": "Scegli se evidenziare i gusti dei regali degli oggetti che non sono stati rivelati nel profilo del PNG. Se abilitato, i gusti dei regali non rivelati saranno in grassetto.",

// collapse fields
// TODO
"config.title.collapse-fields": "Collapse large fields",

"config.collapse-fields.enabled.name": "Enabled",
"config.collapse-fields.enabled.desc": "Whether to collapse large fields, so the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

"config.collapse-fields.npc-gift-tastes.name": "NPC lookup: gift tastes",
"config.collapse-fields.item-recipes.name": "Item lookup: recipes",
"config.collapse-fields.any.desc": "If the field contains this many values, the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

// advanced options
"config.title.advanced-options": "Opzioni avanzate",
"config.tile-lookups.name": "Ricerca piastrelle",
Expand Down
11 changes: 11 additions & 0 deletions LookupAnything/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,17 @@
"config.highlight-unrevealed-gift-tastes.name": "Highlight unrevealed gift tastes",
"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.",

// collapse fields
// TODO
"config.title.collapse-fields": "Collapse large fields",

"config.collapse-fields.enabled.name": "Enabled",
"config.collapse-fields.enabled.desc": "Whether to collapse large fields, so the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

"config.collapse-fields.npc-gift-tastes.name": "NPC lookup: gift tastes",
"config.collapse-fields.item-recipes.name": "Item lookup: recipes",
"config.collapse-fields.any.desc": "If the field contains this many values, the lookup menu will replace the list with a clickable 'show X values' link to expand it.",

// advanced options
// TODO
"config.title.advanced-options": "Advanced options",
Expand Down
Loading

0 comments on commit 1be2dc8

Please sign in to comment.