Skip to content

Commit

Permalink
[slothsoft#59] make locked bundle display configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
slothsoft committed Nov 14, 2022
1 parent 71e0aec commit 60fa775
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 96 deletions.
21 changes: 21 additions & 0 deletions Informant.Test/Harness/Test/I18NTestUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Linq;
using NUnit.Framework;

namespace StardewTests.Harness.Test;

public static class I18NTestUtil {

public static void Assert18NCorrect(string modFolder, LocalizedContentManager.LanguageCode locale) {
var translationHelper = new TestTranslationHelper(modFolder);
var allDefaultTranslations = translationHelper.GetTranslations().ToArray();

// now set to tested locale and assert
translationHelper.LocaleEnum = locale;
foreach (var defaultTranslation in allDefaultTranslations) {
// this throws an exception if the key does not exist at all
var translation = translationHelper.Get(defaultTranslation.Key).ToString();
// warn if the key exists, but is English (since I can't translate those keys myself)
Warn.If(translation.Equals(defaultTranslation.ToString()), () => $"{defaultTranslation.Key} was not translated in locale {locale}");
}
}
}
30 changes: 19 additions & 11 deletions Informant/Implementation/Decorator/BundleDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ public BundleDecorator(IModHelper modHelper) {

public bool HasDecoration(Item input) {
if (_bundle != null && input is SObject obj && !obj.bigCraftable.Value) {

int[]? allowedAreas;

// if player can't read Junimo text, they can't have bundles yet
if (!Game1.player.mailReceived.Contains("canReadJunimoText")) {
return false;
// if player can't read Junimo text, they can't have bundles yet
allowedAreas = null;
} else {
// let the community center calculate which bundles are allowed
var communityCenter = Game1.getLocationFromName("CommunityCenter") as CommunityCenter;
allowedAreas = communityCenter?.areasComplete
.Select((complete, index) => new { complete, index})
.Where(area => communityCenter.shouldNoteAppearInArea(area.index) && !area.complete)
.Select(area => area.index)
.ToArray();
}

// let the community center calculate which bundles are allowed
var communityCenter = Game1.getLocationFromName("CommunityCenter") as CommunityCenter;
var allowedAreas = communityCenter?.areasComplete
.Select((complete, index) => new { complete, index})
.Where(area => communityCenter.shouldNoteAppearInArea(area.index) && !area.complete)
.Select(area => area.index)
.ToArray();

return GetNeededItems(allowedAreas).Contains(input.ParentSheetIndex);
}
return false;
Expand All @@ -58,14 +60,20 @@ internal static IEnumerable<int> GetNeededItems(int[]? allowedAreas) {
// bundleTitle = Boiler Room/22
// bundleData = Adventurer's/R 518 1/766 99 0 767 10 0 768 1 0 881 10 0/1/2/22

var decorateLockedBundles = InformantMod.Instance?.Config.DecorateLockedBundles ?? false;
if ((allowedAreas == null || allowedAreas.Length == 0) && !decorateLockedBundles) {
// no areas are allowed, and we don't decorate locked bundles; so no bundle is needed yet
yield break;
}

var bundleData = Game1.netWorldState.Value.BundleData;
var bundlesCompleted = Game1.netWorldState.Value.Bundles.Pairs
.ToDictionary(p => p.Key, p => p.Value.ToArray());

foreach (var bundleTitle in bundleData.Keys) {
var bundleTitleSplit = bundleTitle.Split('/');
var bundleTitleId = bundleTitleSplit[0];
if (allowedAreas != null && !allowedAreas.Contains(CommunityCenter.getAreaNumberFromName(bundleTitleId))) {
if ((allowedAreas != null && !allowedAreas.Contains(CommunityCenter.getAreaNumberFromName(bundleTitleId))) && !decorateLockedBundles) {
// bundle was not yet unlocked or already completed
continue;
}
Expand Down
1 change: 1 addition & 0 deletions Informant/InformantConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal record InformantConfig {
public TooltipTrigger TooltipTrigger { get; set; } = TooltipTrigger.Hover;
public SButton TooltipTriggerButton { get; set; } = SButton.MouseRight;
public HideMachineTooltips HideMachineTooltips { get; set; } = HideMachineTooltips.ForNonMachines;
public bool DecorateLockedBundles { get; set; }
}

internal enum TooltipTrigger {
Expand Down
2 changes: 1 addition & 1 deletion Informant/InformantMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class InformantMod : Mod {

private IInformant? _api;
internal InformantConfig Config = null!;

/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="modHelper">Provides simplified APIs for writing mods.</param>
public override void Entry(IModHelper modHelper) {
Expand Down
26 changes: 17 additions & 9 deletions Informant/ThirdParty/HookToGenericModConfigMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,45 @@ public static void Apply(InformantMod informantMod, IInformant api) {
);

// add some config options for tooltip generators
configMenu.AddSectionTitle(informantMod.ModManifest, () => informantMod.Helper.Translation.Get("TooltipGenerators.GeneralSection"));
configMenu.AddSectionTitle(informantMod.ModManifest, () => informantMod.Helper.Translation.Get("Config.TooltipGenerators.GeneralSection"));
configMenu.AddEnumOption(
mod: informantMod.ModManifest,
name: () => informantMod.Helper.Translation.Get("TooltipTrigger"),
name: () => informantMod.Helper.Translation.Get("Config.TooltipTrigger"),
getValue: () => informantMod.Config.TooltipTrigger,
setValue: value => informantMod.Config.TooltipTrigger = value,
getDisplayName: value => informantMod.Helper.Translation.Get("TooltipTrigger." + value)
getDisplayName: value => informantMod.Helper.Translation.Get("Config.TooltipTrigger." + value)
);
configMenu.AddKeybind(
mod: informantMod.ModManifest,
name: () => informantMod.Helper.Translation.Get("TooltipTriggerButton"),
name: () => informantMod.Helper.Translation.Get("Config.TooltipTriggerButton"),
getValue: () => informantMod.Config.TooltipTriggerButton,
setValue: value => informantMod.Config.TooltipTriggerButton = value
);
configMenu.AddEnumOption(
mod: informantMod.ModManifest,
name: () => informantMod.Helper.Translation.Get("HideMachineTooltips"),
name: () => informantMod.Helper.Translation.Get("Config.HideMachineTooltips"),
getValue: () => informantMod.Config.HideMachineTooltips,
setValue: value => informantMod.Config.HideMachineTooltips = value,
getDisplayName: value => informantMod.Helper.Translation.Get("HideMachineTooltips." + value)
getDisplayName: value => informantMod.Helper.Translation.Get("Config.HideMachineTooltips." + value)
);

configMenu.AddSectionTitle(informantMod.ModManifest, () => informantMod.Helper.Translation.Get("TooltipGenerators.Visibility"));
configMenu.AddSectionTitle(informantMod.ModManifest, () => informantMod.Helper.Translation.Get("Config.TooltipGenerators.Visibility"));
var configurables = new List<IDisplayable>();
configurables.AddRange(api.ObjectTooltipGenerators.Generators);
configurables.AddRange(api.TerrainFeatureTooltipGenerators.Generators);
CreateDisplayableOptions(configMenu, configurables, informantMod);

// add some config options for decorators
// TODO: commong soon? configMenu.AddSectionTitle(informantMod.ModManifest, () => informantMod.Helper.Translation.Get("Decorators.GeneralSection"));
configMenu.AddSectionTitle(informantMod.ModManifest, () => informantMod.Helper.Translation.Get("Decorators.Visibility"));
configMenu.AddSectionTitle(informantMod.ModManifest, () => informantMod.Helper.Translation.Get("Config.Decorators.GeneralSection"));
configMenu.AddBoolOption(
mod: informantMod.ModManifest,
name: () => informantMod.Helper.Translation.Get("Config.DecorateLockedBundles"),
tooltip: () => informantMod.Helper.Translation.Get("Config.DecorateLockedBundles.Description"),
getValue: () => informantMod.Config.DecorateLockedBundles,
setValue: value => informantMod.Config.DecorateLockedBundles = value
);

configMenu.AddSectionTitle(informantMod.ModManifest, () => informantMod.Helper.Translation.Get("Config.Decorators.Visibility"));
configurables = new List<IDisplayable>();
configurables.AddRange(api.ItemDecorators.Decorators);
configurables.AddRange(api.GeneralDisplayables);
Expand Down
27 changes: 15 additions & 12 deletions Informant/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
"TreeTooltipGenerator.Type8" : "Mahagoni-Baum",
"TreeTooltipGenerator.Type9" : "Palme",

"Decorators.GeneralSection" : "Dekorationen - Allgemein",
"Decorators.Visibility" : "Dekorationen - Sichtbarkeit",
"TooltipGenerators.GeneralSection" : "Tooltips - Allgemein",
"TooltipGenerators.Visibility" : "Tooltips - Sichtbarkeit",
"Config.Decorators.GeneralSection" : "Dekorationen - Allgemein",
"Config.Decorators.Visibility" : "Dekorationen - Sichtbarkeit",
"Config.TooltipGenerators.GeneralSection" : "Tooltips - Allgemein",
"Config.TooltipGenerators.Visibility" : "Tooltips - Sichtbarkeit",

"Config.DecorateLockedBundles" : "Dekoriere versteckte Bündel",
"Config.DecorateLockedBundles.Description" : "Bündel-Dekoration wird auch für noch versteckte Bündel angezeigt",

"TooltipTrigger": "Tooltip-Auslöser",
"TooltipTrigger.Hover": "Mausberührung",
"TooltipTrigger.ButtonHeld": "Bei gedrückter Taste",
"TooltipTriggerButton": "Tooltip-Taste",
"Config.TooltipTrigger": "Tooltip-Auslöser",
"Config.TooltipTrigger.Hover": "Mausberührung",
"Config.TooltipTrigger.ButtonHeld": "Bei gedrückter Taste",
"Config.TooltipTriggerButton": "Tooltip-Taste",

"HideMachineTooltips": "Verstecke Machinen-Tooltips",
"HideMachineTooltips.ForNonMachines": "Alle außer Machinen",
"HideMachineTooltips.ForChests": "Kisten",
"HideMachineTooltips.Never": "Keine"
"Config.HideMachineTooltips": "Verstecke Machinen-Tooltips",
"Config.HideMachineTooltips.ForNonMachines": "Alle außer Machinen",
"Config.HideMachineTooltips.ForChests": "Kisten",
"Config.HideMachineTooltips.Never": "Keine"
}
27 changes: 15 additions & 12 deletions Informant/i18n/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
"TreeTooltipGenerator.Type8" : "Mahogany Tree",
"TreeTooltipGenerator.Type9" : "Palm Tree",

"Decorators.GeneralSection" : "Decorators - General",
"Decorators.Visibility" : "Decorators - Visibility",
"TooltipGenerators.GeneralSection" : "Tooltips - General",
"TooltipGenerators.Visibility" : "Tooltips - Visibility",
"Config.Decorators.GeneralSection" : "Decorators - General",
"Config.Decorators.Visibility" : "Decorators - Visibility",
"Config.TooltipGenerators.GeneralSection" : "Tooltips - General",
"Config.TooltipGenerators.Visibility" : "Tooltips - Visibility",

"Config.DecorateLockedBundles" : "Decorate Locked Bundles",
"Config.DecorateLockedBundles.Description" : "Displays Bundles Decorator for still locked bundles",

"TooltipTrigger": "Tooltip Trigger",
"TooltipTrigger.Hover": "On hover",
"TooltipTrigger.ButtonHeld": "On button held",
"TooltipTriggerButton": "Tooltip Button",
"Config.TooltipTrigger": "Tooltip Trigger",
"Config.TooltipTrigger.Hover": "On hover",
"Config.TooltipTrigger.ButtonHeld": "On button held",
"Config.TooltipTriggerButton": "Tooltip Button",

"HideMachineTooltips": "Hide Machine Tooltips",
"HideMachineTooltips.ForNonMachines": "For non-machines",
"HideMachineTooltips.ForChests": "For chests",
"HideMachineTooltips.Never": "Never"
"Config.HideMachineTooltips": "Hide Machine Tooltips",
"Config.HideMachineTooltips.ForNonMachines": "For non-machines",
"Config.HideMachineTooltips.ForChests": "For chests",
"Config.HideMachineTooltips.Never": "Never"
}
27 changes: 15 additions & 12 deletions Informant/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
"TreeTooltipGenerator.Type8" : "마호가니 나무",
"TreeTooltipGenerator.Type9" : "야자수",

"Decorators.GeneralSection" : "표시기 - 일반",
"Decorators.Visibility" : "표시기 - 활성화",
"TooltipGenerators.GeneralSection" : "정보 - 일반",
"TooltipGenerators.Visibility" : "정보 - 활성화",
"Config.Decorators.GeneralSection" : "표시기 - 일반",
"Config.Decorators.Visibility" : "표시기 - 활성화",
"Config.TooltipGenerators.GeneralSection" : "정보 - 일반",
"Config.TooltipGenerators.Visibility" : "정보 - 활성화",

"Config.DecorateLockedBundles" : "Decorate Locked Bundles",
"Config.DecorateLockedBundles.Description" : "Displays Bundles Decorator for still locked bundles",

"TooltipTrigger": "정보 표시 조건",
"TooltipTrigger.Hover": "마우스 올릴 때",
"TooltipTrigger.ButtonHeld": "버튼 누를 때",
"TooltipTriggerButton": "정보 표시 버튼",
"Config.TooltipTrigger": "정보 표시 조건",
"Config.TooltipTrigger.Hover": "마우스 올릴 때",
"Config.TooltipTrigger.ButtonHeld": "버튼 누를 때",
"Config.TooltipTriggerButton": "정보 표시 버튼",

"HideMachineTooltips": "기계 정보 숨기기",
"HideMachineTooltips.ForNonMachines": "비기계류에 대해",
"HideMachineTooltips.ForChests": "상자에 대해",
"HideMachineTooltips.Never": "숨기지 않음"
"Config.HideMachineTooltips": "기계 정보 숨기기",
"Config.HideMachineTooltips.ForNonMachines": "비기계류에 대해",
"Config.HideMachineTooltips.ForChests": "상자에 대해",
"Config.HideMachineTooltips.Never": "숨기지 않음"
}
29 changes: 16 additions & 13 deletions Informant/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
"TreeTooltipGenerator.Type8" : "Maun Ağacı",
"TreeTooltipGenerator.Type9" : "Palmiye Ağacı",

"Decorators.GeneralSection" : "Belirteçler - Genel",
"Decorators.Visibility" : "Belirteçler - Görünürlük",
"TooltipGenerators.GeneralSection" : "İpuçları - Genel",
"TooltipGenerators.Visibility" : "İpuçları - Görünürlük",
"Config.Decorators.GeneralSection" : "Belirteçler - Genel",
"Config.Decorators.Visibility" : "Belirteçler - Görünürlük",
"Config.TooltipGenerators.GeneralSection" : "İpuçları - Genel",
"Config.TooltipGenerators.Visibility" : "İpuçları - Görünürlük",

"Config.DecorateLockedBundles" : "Decorate Locked Bundles",
"Config.DecorateLockedBundles.Description" : "Displays Bundles Decorator for still locked bundles",

"TooltipTrigger": "İpucu aktifleşmesi",
"TooltipTrigger.Hover": "Üzerinde imleç ile gezinildiğinde",
"TooltipTrigger.ButtonHeld": "Düğme basılı tutulduğunda",
"TooltipTriggerButton": "İpucu Butonu",

"HideMachineTooltips": "Makine İpucunu Gizle",
"HideMachineTooltips.ForNonMachines": "Makine olmayanlar için",
"HideMachineTooltips.ForChests": "Sandıklar için",
"HideMachineTooltips.Never": "Asla"
"Config.TooltipTrigger": "İpucu aktifleşmesi",
"Config.TooltipTrigger.Hover": "Üzerinde imleç ile gezinildiğinde",
"Config.TooltipTrigger.ButtonHeld": "Düğme basılı tutulduğunda",
"Config.TooltipTriggerButton": "İpucu Butonu",

"Config.HideMachineTooltips": "Makine İpucunu Gizle",
"Config.HideMachineTooltips.ForNonMachines": "Makine olmayanlar için",
"Config.HideMachineTooltips.ForChests": "Sandıklar için",
"Config.HideMachineTooltips.Never": "Asla"
}
27 changes: 15 additions & 12 deletions Informant/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
"TreeTooltipGenerator.Type8" : "桃花心木",
"TreeTooltipGenerator.Type9" : "棕榈树",

"Decorators.GeneralSection" : "通用标记",
"Decorators.Visibility" : "标记开关",
"TooltipGenerators.GeneralSection" : "通用信息",
"TooltipGenerators.Visibility" : "信息开关",
"Config.Decorators.GeneralSection" : "通用标记",
"Config.Decorators.Visibility" : "标记开关",
"Config.TooltipGenerators.GeneralSection" : "通用信息",
"Config.TooltipGenerators.Visibility" : "信息开关",

"Config.DecorateLockedBundles" : "Decorate Locked Bundles",
"Config.DecorateLockedBundles.Description" : "Displays Bundles Decorator for still locked bundles",

"TooltipTrigger": "信息显示模式",
"TooltipTrigger.Hover": "鼠标悬停",
"TooltipTrigger.ButtonHeld": "按键按下",
"TooltipTriggerButton": "信息显示按键",
"Config.TooltipTrigger": "信息显示模式",
"Config.TooltipTrigger.Hover": "鼠标悬停",
"Config.TooltipTrigger.ButtonHeld": "按键按下",
"Config.TooltipTriggerButton": "信息显示按键",

"HideMachineTooltips": "隐藏机器信息",
"HideMachineTooltips.ForNonMachines": "隐藏非机器",
"HideMachineTooltips.ForChests": "隐藏箱子",
"HideMachineTooltips.Never": "永不"
"Config.HideMachineTooltips": "隐藏机器信息",
"Config.HideMachineTooltips.ForNonMachines": "隐藏非机器",
"Config.HideMachineTooltips.ForChests": "隐藏箱子",
"Config.HideMachineTooltips.Never": "永不"
}
Loading

0 comments on commit 60fa775

Please sign in to comment.