Skip to content

Commit f11d2a4

Browse files
committed
Implement config for wiki buttons through session shares
1 parent ee33b34 commit f11d2a4

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

WikiIntegration/OpenWikiArticleButton.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313

1414
namespace WikiIntegration
1515
{
16+
/// <summary>
17+
/// This monkey must not be disabled to generate wiki buttons for anyone else in the session.
18+
/// </summary>
1619
[HarmonyPatchCategory(nameof(OpenWikiArticleButton))]
1720
[HarmonyPatch(typeof(ProtoFluxNodeVisual), nameof(ProtoFluxNodeVisual.GenerateVisual))]
1821
internal sealed class OpenWikiArticleButton : ConfiguredResoniteInspectorMonkey<OpenWikiArticleButton, WikiButtonConfig, BuildInspectorHeaderEvent, Worker>
1922
{
2023
private static readonly Lazy<LocaleString> _componentLocale = new(() => Mod.GetLocaleString("WikiHyperlink.Component"));
2124
private static readonly Lazy<LocaleString> _protoFluxLocale = new(() => Mod.GetLocaleString("WikiHyperlink.ProtoFlux"));
2225

23-
public override bool CanBeDisabled => true;
2426
public override int Priority => HarmonyLib.Priority.HigherThanNormal;
2527
private static LocaleString ComponentLocale => _componentLocale.Value;
2628
private static LocaleString ProtoFluxLocale => _protoFluxLocale.Value;
@@ -37,6 +39,8 @@ protected override void Handle(BuildInspectorHeaderEvent eventData)
3739
.WithTooltip(eventData.Worker is ProtoFluxNode ? ProtoFluxLocale : ComponentLocale);
3840

3941
AddHyperlink(button.Slot, eventData.Worker);
42+
43+
ConfigSection.Components.DriveFromVariable(button.Slot.ActiveSelf_Field);
4044
ConfigSection.ComponentOffset.DriveFromVariable(button.Slot._orderOffset);
4145

4246
ui.PopStyle();
@@ -79,9 +83,6 @@ private static void AddHyperlink(Slot slot, Worker worker)
7983

8084
private static void Postfix(ProtoFluxNodeVisual __instance, ProtoFluxNode node)
8185
{
82-
if (!Enabled)
83-
return;
84-
8586
if (node.SupressHeaderAndFooter && node.NodeName.Contains("Relay", StringComparison.OrdinalIgnoreCase))
8687
return;
8788

@@ -98,6 +99,8 @@ private static void Postfix(ProtoFluxNodeVisual __instance, ProtoFluxNode node)
9899
button.Slot.AttachComponent<Button>().WithTooltip(ProtoFluxLocale);
99100

100101
AddHyperlink(button.Slot, node);
102+
103+
ConfigSection.ProtoFlux.DriveFromVariable(button.Slot.ActiveSelf_Field);
101104
}
102105
}
103106
}

WikiIntegration/WikiButtonConfig.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ namespace WikiIntegration
99
{
1010
internal sealed class WikiButtonConfig : ConfigSection
1111
{
12-
private static readonly DefiningConfigKey<bool> _components = new("Components", "Whether to add the Wiki button to Components in Worker Inspectors.", () => true);
13-
private static readonly DefiningConfigKey<bool> _protoFlux = new("ProtoFlux", "Whether to add the Wiki button to ProtoFlux nodes.", () => true);
12+
private static readonly DefiningConfigKey<bool> _components = new("Components", "Whether to add the Wiki button to Components in Worker Inspectors.", () => true)
13+
{
14+
new ConfigKeySessionShare<bool>(true)
15+
};
16+
17+
private static readonly DefiningConfigKey<bool> _protoFlux = new("ProtoFlux", "Whether to add the Wiki button to ProtoFlux nodes.", () => true)
18+
{
19+
new ConfigKeySessionShare<bool>(true)
20+
};
1421

1522
private readonly DefiningConfigKey<int> _componentOffset = new("ComponentOffset", "The Order Offset of the Wiki button on Inspector Headers. Higher is further right.", () => 2)
1623
{
@@ -23,11 +30,13 @@ internal sealed class WikiButtonConfig : ConfigSection
2330
/// </summary>
2431
public ConfigKeySessionShare<int, long> ComponentOffset => _componentOffset.Components.Get<ConfigKeySessionShare<int, long>>();
2532

26-
public bool Components => _components;
33+
public ConfigKeySessionShare<bool> Components => _components.Components.Get<ConfigKeySessionShare<bool>>();
2734

2835
public override string Description => "Contains settings for the Resonite Wiki buttons on components and ProtoFlux nodes.";
2936
public override string Id => "Buttons";
30-
public bool ProtoFlux => _protoFlux;
37+
38+
public ConfigKeySessionShare<bool> ProtoFlux => _protoFlux.Components.Get<ConfigKeySessionShare<bool>>();
39+
3140
public override Version Version { get; } = new(1, 0, 0);
3241
}
3342
}

WikiIntegration/WikiIntegration.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageId>WikiIntegration</PackageId>
1212
<Title>Wiki Integration</Title>
1313
<Authors>Banane9</Authors>
14-
<Version>0.2.0-beta</Version>
14+
<Version>0.3.0-beta</Version>
1515
<Description>This MonkeyLoader mod for Resonite that adds links to the Wiki to Components in Worker Inspectors, and ProtoFlux nodes.</Description>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>
1717
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>

0 commit comments

Comments
 (0)