Skip to content

Commit

Permalink
Merge pull request #30 from BUTR/dev
Browse files Browse the repository at this point in the history
v2.1.3
  • Loading branch information
Aragas authored Apr 3, 2021
2 parents 4fed729 + 48fe42c commit b8cd824
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
6 changes: 3 additions & 3 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<!--Development Variables-->
<PropertyGroup>
<!--Module Version-->
<Version>2.1.2</Version>
<Version>2.1.3</Version>
<!--Harmony Version-->
<HarmonyVersion>2.0.2</HarmonyVersion>
<!--BuildResources Version-->
<BuildResourcesVersion>1.0.0.32</BuildResourcesVersion>
<BUTRSharedVersion>1.6.1.22</BUTRSharedVersion>
<BuildResourcesVersion>1.0.0.33</BuildResourcesVersion>
<BUTRSharedVersion>1.6.1.31</BUTRSharedVersion>
<HarmonyExtensionsVersion>2.0.0.4</HarmonyExtensionsVersion>
<!--Current Bannerlord Version-->
<GameVersion>1.4.3</GameVersion>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@ public sealed class PrefabExtensionAttribute : BaseUIExtenderAttribute
/// </summary>
public string? XPath { get; }

/// <summary>
/// Gauntlet Movie name to prevent from loading as an auto-generated Widget (optional)
/// </summary>
public string? AutoGenWidgetName { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="movie">Gauntlet Movie name to extend</param>
/// <param name="xpath">XPath of the node to operate against (optional)</param>
public PrefabExtensionAttribute(string movie, string? xpath = null)
/// <param name="autoGenWidgetName">Gauntlet Movie name to prevent from loading as an auto-generated Widget (optional)</param>
public PrefabExtensionAttribute(string movie, string? xpath = null, string? autoGenWidgetName = null)
{
Movie = movie;
XPath = xpath;
AutoGenWidgetName = autoGenWidgetName;
}
}
}
45 changes: 45 additions & 0 deletions src/Bannerlord.UIExtenderEx/Patches/GauntletMoviePatch.cs
Original file line number Diff line number Diff line change
@@ -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<UIExtenderRuntime, List<string>> WidgetNames = new();

public static void Register(UIExtenderRuntime runtime, string autoGenWidgetName)
{
WidgetNames.AddOrUpdate(runtime,
_ => new List<string> { 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;
}
}
}
2 changes: 2 additions & 0 deletions src/Bannerlord.UIExtenderEx/SubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
1 change: 1 addition & 0 deletions src/Bannerlord.UIExtenderEx/UIExtender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class UIExtender

static UIExtender()
{
GauntletMoviePatch.Patch(Harmony);
ViewModelPatch.Patch(Harmony);
WidgetPrefabPatch.Patch(Harmony);
WidgetFactoryPatch.Patch(Harmony);
Expand Down
3 changes: 3 additions & 0 deletions src/Bannerlord.UIExtenderEx/UIExtenderRuntime.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bannerlord.UIExtenderEx.Attributes;
using Bannerlord.UIExtenderEx.Components;
using Bannerlord.UIExtenderEx.Patches;

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -97,6 +98,8 @@ public void Register(IEnumerable<Type> types)
break;
}

GauntletMoviePatch.Register(this, xmlExtension.AutoGenWidgetName);

break;
}

Expand Down

0 comments on commit b8cd824

Please sign in to comment.