diff --git a/build/common.props b/build/common.props index 9e875757..b72606c1 100644 --- a/build/common.props +++ b/build/common.props @@ -4,12 +4,12 @@ - 2.1.2 + 2.1.3 2.0.2 - 1.0.0.32 - 1.6.1.22 + 1.0.0.33 + 1.6.1.31 2.0.0.4 1.4.3 diff --git a/changelog.txt b/changelog.txt index 2e1d1bf5..f7a9ad41 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ --------------------------------------------------------------------------------------------------- +Version: 2.1.3 +Game Versions: e1.4.3,e1.5.0,e1.5.1,e1.5.2,e1.5.3,e1.5.4,e1.5.5,e1.5.6,e1.5.7,e1.5.8,e1.5.9 +* Added support for patching widgets fully in e1.5.9 +--------------------------------------------------------------------------------------------------- Version: 2.1.2 Game Versions: e1.4.3,e1.5.0,e1.5.1,e1.5.2,e1.5.3,e1.5.4,e1.5.5,e1.5.6,e1.5.7,e1.5.8,e1.5.9 * Added a new Register(Types) method diff --git a/src/Bannerlord.UIExtenderEx/Attributes/PrefabExtensionAttribute.cs b/src/Bannerlord.UIExtenderEx/Attributes/PrefabExtensionAttribute.cs index 8e45e07d..5878119e 100644 --- a/src/Bannerlord.UIExtenderEx/Attributes/PrefabExtensionAttribute.cs +++ b/src/Bannerlord.UIExtenderEx/Attributes/PrefabExtensionAttribute.cs @@ -19,15 +19,22 @@ public sealed class PrefabExtensionAttribute : BaseUIExtenderAttribute /// public string? XPath { get; } + /// + /// Gauntlet Movie name to prevent from loading as an auto-generated Widget (optional) + /// + public string? AutoGenWidgetName { get; } + /// /// Constructor /// /// Gauntlet Movie name to extend /// XPath of the node to operate against (optional) - public PrefabExtensionAttribute(string movie, string? xpath = null) + /// Gauntlet Movie name to prevent from loading as an auto-generated Widget (optional) + public PrefabExtensionAttribute(string movie, string? xpath = null, string? autoGenWidgetName = null) { Movie = movie; XPath = xpath; + AutoGenWidgetName = autoGenWidgetName; } } } \ No newline at end of file diff --git a/src/Bannerlord.UIExtenderEx/Patches/GauntletMoviePatch.cs b/src/Bannerlord.UIExtenderEx/Patches/GauntletMoviePatch.cs new file mode 100644 index 00000000..80dee9f4 --- /dev/null +++ b/src/Bannerlord.UIExtenderEx/Patches/GauntletMoviePatch.cs @@ -0,0 +1,45 @@ +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; + +using HarmonyLib; + +using TaleWorlds.GauntletUI.Data; + +namespace Bannerlord.UIExtenderEx.Patches +{ + internal static class GauntletMoviePatch + { + private static readonly ConcurrentDictionary> WidgetNames = new(); + + public static void Register(UIExtenderRuntime runtime, string autoGenWidgetName) + { + WidgetNames.AddOrUpdate(runtime, + _ => new List { autoGenWidgetName }, + (_, list) => + { + list.Add(autoGenWidgetName); + return list; + }); + } + + public static void Patch(Harmony harmony) + { + if (AccessTools.Method(typeof(GauntletMovie), "Load") is { } methodInfo && + methodInfo.GetParameters() is { } @params && + @params.Any(p => p.Name == "doNotUseGeneratedPrefabs")) + { + harmony.Patch( + methodInfo, + prefix: new HarmonyMethod(AccessTools.Method(typeof(GauntletMoviePatch), nameof(LoadPrefix)))); + } + } + + private static void LoadPrefix(string movieName, ref bool doNotUseGeneratedPrefabs) + { + var movies = WidgetNames.Where(kv => kv.Key.PrefabComponent.Enabled).SelectMany(kv => kv.Value); + if (movies.Contains(movieName)) + doNotUseGeneratedPrefabs = true; + } + } +} \ No newline at end of file diff --git a/src/Bannerlord.UIExtenderEx/SubModule.cs b/src/Bannerlord.UIExtenderEx/SubModule.cs index 10d8cd85..382509da 100644 --- a/src/Bannerlord.UIExtenderEx/SubModule.cs +++ b/src/Bannerlord.UIExtenderEx/SubModule.cs @@ -11,6 +11,8 @@ namespace Bannerlord.UIExtenderEx { public class SubModule : MBSubModuleBase { + private delegate void SetDoNotUseGeneratedPrefabs(bool value); + // We can't rely on EN since the game assumes that the default locale is always English private const string SErrorHarmonyNotFound = @"{=EEVJa5azpB}Bannerlord.Harmony module was not found!"; diff --git a/src/Bannerlord.UIExtenderEx/UIExtender.cs b/src/Bannerlord.UIExtenderEx/UIExtender.cs index c0d6e951..5cf2f22a 100644 --- a/src/Bannerlord.UIExtenderEx/UIExtender.cs +++ b/src/Bannerlord.UIExtenderEx/UIExtender.cs @@ -20,6 +20,7 @@ public class UIExtender static UIExtender() { + GauntletMoviePatch.Patch(Harmony); ViewModelPatch.Patch(Harmony); WidgetPrefabPatch.Patch(Harmony); WidgetFactoryPatch.Patch(Harmony); diff --git a/src/Bannerlord.UIExtenderEx/UIExtenderRuntime.cs b/src/Bannerlord.UIExtenderEx/UIExtenderRuntime.cs index 51d18388..0075b5ce 100644 --- a/src/Bannerlord.UIExtenderEx/UIExtenderRuntime.cs +++ b/src/Bannerlord.UIExtenderEx/UIExtenderRuntime.cs @@ -1,5 +1,6 @@ using Bannerlord.UIExtenderEx.Attributes; using Bannerlord.UIExtenderEx.Components; +using Bannerlord.UIExtenderEx.Patches; using System; using System.Collections.Generic; @@ -97,6 +98,8 @@ public void Register(IEnumerable types) break; } + GauntletMoviePatch.Register(this, xmlExtension.AutoGenWidgetName); + break; }