Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
66bb4c8
Added a publicization for Owlcat.UI
ScaredKurufinve Mar 6, 2023
c275609
Changed the access modifier to an overriden method due to the publici…
ScaredKurufinve Mar 6, 2023
7d399f3
Changed the access modifier to an overriden method due to the publici…
ScaredKurufinve Mar 6, 2023
9d78ab3
Changed the access modifier to an overriden method due to the publici…
ScaredKurufinve Mar 6, 2023
b72a53a
Added an empty Localized string to be used on several occasions
ScaredKurufinve Mar 6, 2023
ec231c3
New wrapper ckass which contains UI Setting Groups and mod info to ge…
ScaredKurufinve Mar 6, 2023
8c77f2a
New Setting Entity class with a ModsmenuEntry as a possible setting -…
ScaredKurufinve Mar 6, 2023
4860f08
Changed a postfix of the Switch Settings Screen to a boolean Prefix r…
ScaredKurufinve Mar 6, 2023
84ca27a
New UI Settings Dropdown - the main feature of the PR. I did not add …
ScaredKurufinve Mar 6, 2023
3548809
Updated the Builder to add new functionality.
ScaredKurufinve Mar 6, 2023
d07416d
Changed the AddSettings functions to fit the new reality
ScaredKurufinve Mar 6, 2023
73cf8f3
added a local variable to store the modEntry so that it can be used t…
ScaredKurufinve Mar 6, 2023
106f6d8
Changed the whole AddSettings stuff to fit the new reality
ScaredKurufinve Mar 6, 2023
6f75187
Added new methods to Test Settings.
ScaredKurufinve Mar 6, 2023
fe892a5
Some changes. Realized I was giving the mod description instead of th…
ScaredKurufinve Mar 9, 2023
4a25e62
Visual studio is crazy and did not fixate one change
ScaredKurufinve Mar 9, 2023
0bbd441
Basic cleanup
WittleWolfie Mar 10, 2023
6b5da80
Rename
WittleWolfie Mar 10, 2023
519f07d
Resolve ambiguity error
WittleWolfie Mar 10, 2023
439f213
Update UISettingsEntityDropDownModMenuEntry.cs
WittleWolfie Mar 10, 2023
0b347a4
Update UISettingsEntityDropDownModMenuEntry.cs
WittleWolfie Mar 10, 2023
28ccd99
Rename / cleanup
WittleWolfie Mar 10, 2023
6f57e30
Update UISettingsEntityDropDownModMenuEntry.cs
WittleWolfie Mar 10, 2023
314e771
More cleanup
WittleWolfie Mar 10, 2023
855d207
More cleanup
WittleWolfie Mar 10, 2023
a2dc617
More cleanup
WittleWolfie Mar 10, 2023
43a11af
All sorts of changes
ScaredKurufinve Oct 18, 2023
af7e54a
Added a safety check for Localization Manager initialized state to av…
ScaredKurufinve Oct 20, 2023
436e1fa
Fixed the constructor of SettingsEntityModMenuEntry to be properly pr…
ScaredKurufinve Oct 20, 2023
91d13d9
Made it so that former Collapsible Headers VMs return regular Header …
ScaredKurufinve Oct 20, 2023
c553ede
Added a missing empty tooltip description to the Empty instance (so t…
ScaredKurufinve Oct 20, 2023
14fa201
Fixed a horrible bug where the builder would not clean the settings b…
ScaredKurufinve Oct 20, 2023
69440f4
Fixed a stupid bug with the order of ModEntry constructor calls causi…
ScaredKurufinve Oct 20, 2023
2e431ea
deleted a couple random usings (Vs be VS)
ScaredKurufinve Oct 20, 2023
8b89099
Decided to make ModsMenuEntry internal. Removed all its constructors'…
ScaredKurufinve Nov 7, 2023
57c57a9
Merge branch 'main' into main
WittleWolfie Nov 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions ModMenu/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Kingmaker;
using Kingmaker.Localization;
using Kingmaker.Localization.Shared;
using Kingmaker.Utility;
using Kingmaker.UI.MVVM._PCView.Settings.Entities;
using Kingmaker.UI.MVVM._PCView.Settings;
using Kingmaker.UI.MVVM._VM.Settings.Entities;
Expand All @@ -19,12 +20,14 @@ namespace ModMenu
internal static class Helpers
{
private static readonly List<LocalString> Strings = new();
internal static LocalizedString EmptyString = CreateString("", "");

internal static LocalizedString CreateString(string key, string enGB, string ruRU = "")
internal static LocalizedString CreateString(string key, string enGB, string ruRU = null, string zhCN = null, string deDE = null, string frFR = null)
{
var localString = new LocalString(key, enGB, ruRU);
var localString = new LocalString(key, enGB, ruRU, zhCN, deDE, frFR);
Strings.Add(localString);
localString.Register();
if (LocalizationManager.Initialized)
localString.Register();
return localString.LocalizedString;
}

Expand All @@ -45,24 +48,43 @@ private class LocalString
public readonly LocalizedString LocalizedString;
private readonly string enGB;
private readonly string ruRU;
private readonly string zhCN;
private readonly string deDE;
private readonly string frFR;
const string NullString = "<null>";

public LocalString(string key, string enGB, string ruRU)
public LocalString(string key, string enGB, string ruRU, string zhCN, string deDE, string frFR)
{
LocalizedString = new LocalizedString() { m_Key = key };
this.enGB = enGB;
this.ruRU = ruRU;
this.zhCN = zhCN;
this.deDE = deDE;
this.frFR = frFR;
}

public void Register()
{
var localized = enGB;
switch (LocalizationManager.CurrentPack.Locale)
string localized;
if (LocalizationManager.CurrentPack.Locale == Locale.enGB)
{
case Locale.ruRU:
if (!string.IsNullOrEmpty(ruRU))
localized = ruRU;
break;
localized = enGB;
goto putString;
}

localized = (LocalizationManager.CurrentPack.Locale) switch
{
Locale.ruRU => ruRU,
Locale.zhCN => zhCN,
Locale.deDE => deDE,
Locale.frFR => frFR,
_ => ""
};

if (localized.IsNullOrEmpty() || localized == NullString)
localized = enGB;

;putString:
LocalizationManager.CurrentPack.PutString(LocalizedString.m_Key, localized);
}
}
Expand Down
13 changes: 10 additions & 3 deletions ModMenu/Main.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
using HarmonyLib;
using Kingmaker.Blueprints.Classes.Spells;
using Kingmaker.Blueprints.JsonSystem;
using Kingmaker.Utility;
using ModMenu.Settings;
using System;
using System.Linq;
using System.Reflection;
using static UnityModManagerNet.UnityModManager;
using static UnityModManagerNet.UnityModManager.ModEntry;

namespace ModMenu
{
public static class Main
internal static class Main
{
internal static ModLogger Logger;
private static Harmony Harmony;
internal static ModEntry Entry;
internal static Harmony Harmony;

public static bool Load(ModEntry modEntry)
{
try
{
Entry = modEntry;
Logger = modEntry.Logger;
modEntry.OnUnload = OnUnload;

Harmony = new(modEntry.Info.Id);
Harmony.DEBUG = true;
Harmony.PatchAll();

Logger.Log("Finished loading.");
}
catch (Exception e)
Expand Down Expand Up @@ -56,6 +62,7 @@ static void Postfix()
Logger.LogException("BlueprintsCache.Init", e);
}
}

}
#endif
}
Expand Down
104 changes: 94 additions & 10 deletions ModMenu/ModMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Kingmaker.Settings;
using JetBrains.Annotations;
using Kingmaker.Settings;
using Kingmaker.UI.SettingsUI;
using ModMenu.Settings;
using System;
Expand All @@ -25,8 +26,8 @@ public static class ModMenu
/// </exception>
public static void AddSettings(SettingsBuilder settings)
{
var settingsGroup = settings.Build();
foreach (var setting in settingsGroup.settings)
var result = settings.Build();
foreach (var setting in result.settings)
{
if (Settings.ContainsKey(setting.Key))
{
Expand All @@ -35,28 +36,111 @@ public static void AddSettings(SettingsBuilder settings)
}
Settings.Add(setting.Key, setting.Value);
}
ModsMenuEntity.Add(settingsGroup.group);
ModsMenuEntity.Add(result.info, result.groups);
}

/// <summary>
/// Adds a new group of settings to the Mods menu page.
/// Adds a new entry containing the group of settings to the Mods menu dropdown.
/// Group's title will be displayed instead of the mod name.
/// </summary>
///
/// <remarks>
/// <para>
/// Using <see cref="AddSettings(SettingsBuilder)"/> is recommended. If you prefer to construct the settings
/// on your own you can use this method.
/// on your own you can use this method, but better choose a less deprecated overload using ModsMenuEntry.
/// The name of the settings group will be used as the display name for the mod in the selection dropdown .
/// </para>
///
/// <para>
/// Settings added in this way cannot be retrieved using <see cref="GetSetting{T, TValue}(string)"/> or
/// <see cref="GetSettingValue{T}(string)"/>.
/// </para>
/// </remarks>
public static void AddSettings(UISettingsGroup settingsGroup)
{
ModsMenuEntity.Add(settingsGroup);
}
/// <exception cref="ArgumentException">
/// settingGroups argument must not be null, have at least 1 group in it and none can be null
/// </exception>
[Obsolete("Please, use AddSettings(ModsMenuEntry modInfo) instead")]
public static void AddSettings([NotNull] UISettingsGroup settingsGroup)
=> ModsMenuEntity.Add(default, new UISettingsGroup[1] { settingsGroup });

/// <summary>
/// Adds a new entry containing groups of settings to the Mods menu dropdown.
/// The title of the first group will displayed instead of the mod name
/// </summary>
///
/// <remarks>
/// <para>
/// Using <see cref="AddSettings(SettingsBuilder)"/> is recommended. If you prefer to construct the settings
/// on your own you can use this method, but better choose a less deprecated overload using ModsMenuEntry.
/// The name of the first settings group from the list will be used as the display name for the mod in the selection dropdown .
/// </para>
///
/// <para>
/// Settings added in this way cannot be retrieved using <see cref="GetSetting{T, TValue}(string)"/> or
/// <see cref="GetSettingValue{T}(string)"/>.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException">
/// settingGroups argument must not be null, have at least 1 group in it and none can be null
/// </exception>
[Obsolete("Please, use AddSettings(ModsMenuEntry modInfo) instead")]
public static void AddSettings([NotNull] List<UISettingsGroup> settingsGroups)
=> ModsMenuEntity.Add(default, settingsGroups);

/// <summary>
/// Adds a new entry containing groups of settings to the Mods menu page.
/// </summary>
///
/// <remarks>
/// <para>
/// Use this method if you prefer to construct settings on your own; you can use this method
/// instead of using the recommended <see cref="AddSettings(SettingsBuilder)"/>.
/// </para>
///
/// <param name="modInfo"> Structure containing basic info about the mod - name, version, description, author name et cetera.
/// This information will be displayed when user is choosing the mod from the dropdown
/// </param>
/// <param name="group"> Group of settings created with original Owlcat API. If you did not set any mod name inside the modInfo structure,
/// name of this settings group will be instead used as the display name of the mod.
/// </param>
///
/// <para>
/// Settings added in this way cannot be retrieved using <see cref="GetSetting{T, TValue}(string)"/> or
/// <see cref="GetSettingValue{T}(string)"/>.
/// </para>
/// </remarks>
/// <exception cref="ArgumentException">
/// settingGroups argument must not be null, have at least 1 group in it and none can be null
/// </exception>
///
public static void AddSettings(Info modInfo, [NotNull] UISettingsGroup group)
=> ModsMenuEntity.Add(modInfo, new UISettingsGroup[1] { group });

/// <summary>
/// Adds a new entry containing groups of settings to the Mods menu page.
/// </summary>
///
/// <remarks>
/// <para>
/// Use this method if you prefer to construct settings on your own; you can use this method
/// instead of using the recommended <see cref="AddSettings(SettingsBuilder)"/>.
///
/// Settings added in this way cannot be retrieved using <see cref="GetSetting{T, TValue}(string)"/> or
/// <see cref="GetSettingValue{T}(string)"/>.
/// </para>
/// </remarks>
///
/// <param name="modInfo"> Structure containing basic info about the mod - name, version, description, author name et cetera.
/// This information will be displayed when user is choosing the mod from the dropdown
/// </param>param>
/// <param name="groups"> Groups of settings created with original Owlcat API. If you did not set any mod name inside the modInfo structure,
/// name of the first settings group from the list will be instead used as the display name of the mod.
/// </param>param>
/// <exception cref="ArgumentException">
/// settingGroups argument must not be null, have at least 1 group in it and none can be null
/// </exception>
public static void AddSettings(Info modInfo, [NotNull] List<UISettingsGroup> groups)
=> ModsMenuEntity.Add(modInfo, groups);

/// <returns>
/// The setting with the specified <paramref name="key"/>, or null if it does not exist or has the wrong type.
Expand Down
33 changes: 18 additions & 15 deletions ModMenu/ModMenu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,25 @@
<ItemGroup>
<!-- Main Wrath Assembly, Publicized -->
<Reference Include="Assembly-CSharp.dll">
<HintPath>$(SolutionDir)lib\Assembly-CSharp.dll</HintPath>
<HintPath>$(SolutionDir)lib\Assembly-CSharp_public.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Pathfinder Second Adventure\Wrath_Data\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Owlcat.Runtime.UI.dll">
<HintPath>$(SolutionDir)lib\Owlcat.Runtime.UI_public.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>$(SolutionDir)lib\Unity.TextMeshPro_public.dll</HintPath>
</Reference>

<!-- Wrath Assemblies -->
<Reference Include="Assembly-CSharp-firstpass.dll">
<HintPath>$(WrathPath)\Wrath_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Owlcat.Runtime.UI.dll">
<HintPath>$(WrathPath)\Wrath_Data\Managed\Owlcat.Runtime.UI.dll</HintPath>
</Reference>
<Reference Include="Owlcat.Runtime.Validation.dll">
<HintPath>$(WrathPath)\Wrath_Data\Managed\Owlcat.Runtime.Validation.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro.dll">
<HintPath>$(WrathPath)\Wrath_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule.dll">
<HintPath>$(WrathPath)\Wrath_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -89,16 +92,16 @@
</None>
</ItemGroup>

<!-- Generates Assembly-CSharp_public.dll -->
<Target Name="Publicize" AfterTargets="Clean">
<ItemGroup>
<Assemblies Include="$(WrathPath)\Wrath_Data\Managed\Assembly-CSharp.dll" />
<PublicAssembly Include="$(SolutionDir)lib\Assembly-CSharp_public.dll" />
<RenamedAssembly Include="$(SolutionDir)lib\Assembly-CSharp.dll" />
<!-- Generates Assembly-CSharp_public.dll and Owlcat.Runtime.UI_public.dll -->
<Target Name="Publicize" AfterTargets="Clean">
<ItemGroup>
<Assemblies Include="$(WrathPath)\Wrath_Data\Managed\Owlcat.Runtime.UI.dll" />
<Assemblies Include="$(WrathPath)\Wrath_Data\Managed\Assembly-CSharp.dll" />
<Assemblies Include="$(WrathPath)\Wrath_Data\Managed\Unity.TextMeshPro.dll" />

</ItemGroup>

<PublicizeTask InputAssemblies="@(Assemblies)" OutputDir="$(SolutionDir)lib/" />
<Move SourceFiles="@(PublicAssembly)" DestinationFiles="@(RenamedAssembly)" />
<PublicizeTask InputAssemblies="@(Assemblies)" OutputDir="$(SolutionDir)lib\" />
</Target>

<!-- Automatically deploys the mod on build -->
Expand Down
56 changes: 56 additions & 0 deletions ModMenu/NewTypes/DropdownItemWithHighlightCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Owlcat.Runtime.UI.MVVM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UniRx.Triggers;
using UniRx;
using HarmonyLib;
using Epic.OnlineServices;
using UnityEngine.EventSystems;
using Steamworks;

namespace ModMenu.NewTypes
{
[HarmonyPatch]
internal class DropdownOptionWithHighlightCallback : TMP_Dropdown.OptionData
{
public List<Action<TMP_Dropdown.DropdownItem>> OnMouseEnter = new();
public List<Action<TMP_Dropdown.DropdownItem>> OnMouseExit = new();


[HarmonyPatch(typeof(TMP_Dropdown), nameof(TMP_Dropdown.AddItem))]
[HarmonyPostfix]
static void TMP_Dropdown_AddItem_Patch(TMP_Dropdown.OptionData data, TMP_Dropdown __instance, TMP_Dropdown.DropdownItem __result)
{
if (data is not DropdownOptionWithHighlightCallback workaround)
return;
else
{
var observer = __result.gameObject.AddComponent<PointerObserverWorkaround>();
foreach (var action in workaround.OnMouseEnter)
observer.PointerEnter += action;
foreach (var action in workaround.OnMouseExit)
observer.PointerExit += action;
}
}


class PointerObserverWorkaround : UIBehaviour, IPointerEnterHandler, IPointerExitHandler
{
internal event Action<TMP_Dropdown.DropdownItem> PointerEnter;
internal event Action<TMP_Dropdown.DropdownItem> PointerExit;

public void OnPointerEnter(PointerEventData eventData)
{
PointerEnter?.Invoke(GetComponent<TMP_Dropdown.DropdownItem>());
}
public void OnPointerExit(PointerEventData eventData)
{
PointerExit?.Invoke(GetComponent<TMP_Dropdown.DropdownItem>());
}
}
}
}
6 changes: 3 additions & 3 deletions ModMenu/NewTypes/SettingsEntityCollapsibleHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ public override VirtualListLayoutElementSettings LayoutSettings
public OwlcatMultiButton Button;
public ExpandableCollapseMultiButtonPC ButtonPC;

protected override void BindViewImplementation()
public override void BindViewImplementation()
{
Title.text = UIUtility.GetSaberBookFormat(ViewModel.Tittle, size: GetFontSize());
Button.OnLeftClick.RemoveAllListeners();
Button.OnLeftClick.AddListener(() => ViewModel.Toggle(ButtonPC));
ViewModel.Init(ButtonPC);
}

protected virtual int GetFontSize() { return 140; }
public virtual int GetFontSize() { return 140; }

protected override void DestroyViewImplementation() { }
public override void DestroyViewImplementation() { }
}
}
Loading