Skip to content

Commit

Permalink
Fixes for automated visibility (#45)
Browse files Browse the repository at this point in the history
* Forgot the front end of the API

* Restored for AI/HS2 support

added temporary game check

* Fix crashing

* Move visibilitycontrol  trigger

move trigger to inside selected makerslot change method to avoid firing multiple times
  • Loading branch information
jalil49 authored Aug 18, 2021
1 parent afede69 commit 7853388
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
30 changes: 28 additions & 2 deletions src/Shared.Core/Maker/MakerAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ public static T AddAccessoryWindowControl<T>(T control) where T : BaseGuiEntry
MakerInterfaceCreator.AddAccessoryWindowControl(control);
return control;
}

#if KK || KKS || EC //todo AI and HS2
/// <summary>
/// Add a control to the accessory selection and settings window.
/// For editable controls that depend on the selected accessory use <see cref="AddEditableAccessoryWindowControl{T,TVal}"/>.
/// To have API control visibility automatically set automate_visible to true.
/// </summary>
public static T AddAccessoryWindowControl<T>(T control, bool automate_visible) where T : BaseGuiEntry
{
if (control == null) throw new ArgumentNullException(nameof(control));
control.ThrowIfDisposed(nameof(control));
MakerInterfaceCreator.AddAccessoryWindowControl(control, automate_visible);
return control;
}
#endif
/// <summary>
/// Add a control to the accessory selection and settings window. The control is wrapped to properly respond to changes in selected accessory slot (has unique values for each slot).
/// </summary>
Expand All @@ -73,6 +86,19 @@ public static AccessoryControlWrapper<T, TVal> AddEditableAccessoryWindowControl
return new AccessoryControlWrapper<T, TVal>(control);
}

#if KK || KKS || EC //todo AI and HS2
/// <summary>
/// Add a control to the accessory selection and settings window. The control is wrapped to properly respond to changes in selected accessory slot (has unique values for each slot).
/// To have API control visibility automatically set automate_visible to true.
/// </summary>
public static AccessoryControlWrapper<T, TVal> AddEditableAccessoryWindowControl<T, TVal>(T control, bool automate_visible) where T : BaseEditableGuiEntry<TVal>
{
if (control == null) throw new ArgumentNullException(nameof(control));
control.ThrowIfDisposed(nameof(control));
MakerInterfaceCreator.AddAccessoryWindowControl(control, automate_visible);
return new AccessoryControlWrapper<T, TVal>(control);
}
#endif
/// <summary>
/// 0 is male, 1 is female
/// </summary>
Expand Down Expand Up @@ -329,7 +355,7 @@ internal static void OnReloadInterface(EventArgs args)
AccessoriesApi.AutomaticControlVisibility();
#endif
}

#if KK || KKS || EC
/// <summary>
/// Fired when the visbility state of accessory controls, added by <see cref="AddAccessoryWindowControl{T}"/>, should change state if not managed automatically by the api.
Expand Down
1 change: 0 additions & 1 deletion src/Shared.KKalike/Maker/AccessoriesApi.Hooks.KK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ private static class Hooks
public static void ChangeSlotPostfix(CustomAcsSelectKind __instance, int _no)
{
OnSelectedMakerSlotChanged(__instance, _no);
AutomaticControlVisibility();
}

[HarmonyBefore(new string[] { "com.joan6694.kkplugins.moreaccessories" })]
Expand Down
15 changes: 13 additions & 2 deletions src/Shared.KKalike/Maker/AccessoriesApi.KK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static partial class AccessoriesApi
private static Func<int, CvsAccessory> _getCvsAccessory;
private static Func<int, ChaFileAccessory.PartsInfo> _getPartsInfo;
private static Func<int> _getCvsAccessoryCount;
private static Func<int> _getPartsCount;
private static Func<ChaControl, int, ChaAccessoryComponent> _getChaAccessoryCmp;
private static Func<ChaControl, ChaAccessoryComponent, int> _getChaAccessoryCmpIndex;

Expand Down Expand Up @@ -237,12 +238,21 @@ internal static void Init()

var getPartsInfoM = AccessTools.Method(_moreAccessoriesType, "GetPart");
_getPartsInfo = i => (ChaFileAccessory.PartsInfo)getPartsInfoM.Invoke(_moreAccessoriesInstance, new object[] { i });

var getPartsCountM = AccessTools.Method(_moreAccessoriesType, "GetPartsLength");
_getPartsCount = () =>
{
if (MakerAPI.InsideAndLoaded)
return (int)getPartsCountM.Invoke(_moreAccessoriesInstance, null);
return 20;
};
}
else
{
_getChaAccessoryCmp = (control, i) => control.cusAcsCmp[i];
_getChaAccessoryCmpIndex = (control, component) => Array.IndexOf(control.cusAcsCmp, component);
_getPartsInfo = i => MakerAPI.GetCharacterControl().nowCoordinate.accessory.parts[i];
_getPartsCount = () => 20;
}
}

Expand Down Expand Up @@ -330,6 +340,8 @@ private static void OnSelectedMakerSlotChanged(object source, int newSlotIndex)
{
KoikatuAPI.Logger.LogError("Subscription to SelectedMakerSlot crashed: " + ex);
}

AutomaticControlVisibility();
}

private static void OnMakerAccSlotAdded(object source, int newSlotIndex, Transform newSlotTransform)
Expand Down Expand Up @@ -416,9 +428,8 @@ private static void OnChangeAcs(object instance, int selSrc, int selDst)
internal static void AutomaticControlVisibility()
{
var slot = SelectedMakerAccSlot;
if (slot < 0 || slot >= GetMakerAccessoryCount())
if (slot < 0 || slot >= _getPartsCount.Invoke())
return;

var partsinfo = GetPartsInfo(slot);

var accessoryExists = partsinfo.type != 120;
Expand Down

0 comments on commit 7853388

Please sign in to comment.