Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
It should follow the format major.minor.patch (semantic versioning). If you publish your mod
as a library to NuGet, this version will also be used as the package version.
-->
<Version>0.4.1</Version>
<Version>0.4.2</Version>
</PropertyGroup>
</Project>
10 changes: 7 additions & 3 deletions Elements/LocalizedTextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine.UI;
using Silksong.ModMenu.Internal;
using UnityEngine.UI;

namespace Silksong.ModMenu.Elements;

Expand Down Expand Up @@ -27,8 +28,11 @@ public LocalizedText LocalizedText
{
if (!self.TryGetComponent<AutoLocalizeTextUI>(out var auto))
{
auto = self.gameObject.AddComponent<AutoLocalizeTextUI>();
auto.textField = self;
using (self.gameObject.TempInactive())
{
auto = self.gameObject.AddComponent<AutoLocalizeTextUI>();
auto.textField = self;
}
}

auto.text = value.Localized;
Expand Down
39 changes: 20 additions & 19 deletions Internal/CustomMappableKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,26 @@ internal static CustomMappableKey Replace(MappableKey src)
var obj = src.gameObject;
DestroyImmediate(src); // We cannot wait 1 frame to add a new Selectable component.

var wasActive = obj.activeSelf;
obj.SetActive(false);
CustomMappableKey dest = obj.AddComponent<CustomMappableKey>();
dest.animationTriggers = animationTriggers;
dest.buttonType = MenuButtonType.Proceed;
dest.cancelAction = CancelAction.DoNothing;
dest.colors = colors;
dest.DontPlaySelectSound = true;
dest.KeymapImage = keymapImage;
dest.KeymapText = keymapText;
dest.leftCursor = leftCursor;
dest.menuCancelVibration = menuCancelVibration;
dest.menuSubmitVibration = menuSubmitVibration;
dest.playSubmitSound = true;
dest.prevSelectedObject = obj;
dest.rightCursor = rightCursor;
dest.transition = Transition.None;
dest.uiAudioPlayer = UIManager.instance.uiAudioPlayer;
obj.SetActive(wasActive);
CustomMappableKey dest;
using (obj.TempInactive())
{
dest = obj.AddComponent<CustomMappableKey>();
dest.animationTriggers = animationTriggers;
dest.buttonType = MenuButtonType.Proceed;
dest.cancelAction = CancelAction.DoNothing;
dest.colors = colors;
dest.DontPlaySelectSound = true;
dest.KeymapImage = keymapImage;
dest.KeymapText = keymapText;
dest.leftCursor = leftCursor;
dest.menuCancelVibration = menuCancelVibration;
dest.menuSubmitVibration = menuSubmitVibration;
dest.playSubmitSound = true;
dest.prevSelectedObject = obj;
dest.rightCursor = rightCursor;
dest.transition = Transition.None;
dest.uiAudioPlayer = UIManager.instance.uiAudioPlayer;
}

return dest;
}
Expand Down
2 changes: 1 addition & 1 deletion Internal/EnumUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal static ReadOnlyDictionary<object, string> StringsForType(Type enumType)
fieldName ??= StringUtil.UnCamelCase(field.Name);
}

if (fieldName == null)
if (customName == null && fieldName == null)
continue;

names[value] = customName ?? fieldName!;
Expand Down
18 changes: 18 additions & 0 deletions Internal/GameObjectUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@ internal static void DestroyAllChildren(this GameObject self)
Object.Destroy(obj);
}
}

private class InactiveScope : System.IDisposable
{
private readonly bool prevActiveSelf;
private readonly GameObject gameObject;

internal InactiveScope(GameObject gameObject)
{
prevActiveSelf = gameObject.activeSelf;
this.gameObject = gameObject;
gameObject.SetActive(false);
}

public void Dispose() => gameObject.SetActive(prevActiveSelf);
}

internal static System.IDisposable TempInactive(this GameObject self) =>
new InactiveScope(self);
}
3 changes: 3 additions & 0 deletions Internal/IEnumeratorUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ IEnumerator Modified()
return Modified();
}

internal static IEnumerator PropagateContext<T>(this IEnumerator self)
where T : class => ThreadLocalContext<T>.Get(out var ctx) ? self.WithContext<T>(ctx) : self;

internal static IEnumerator Append(this IEnumerator self, Action action)
{
IEnumerator Modified()
Expand Down
1 change: 0 additions & 1 deletion Screens/AbstractMenuScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ internal void InvokeOnGoBack()

internal void InvokeOnHide(MenuScreenNavigation.NavigationType navigationType)
{
ModMenuPlugin.LogError($"{Container.name}{nameof(InvokeOnHide)}: {navigationType}");
OnHide?.Invoke(navigationType);
visibility.VisibleSelf = false;
}
Expand Down
12 changes: 9 additions & 3 deletions Screens/BasicMenuScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ namespace Silksong.ModMenu.Screens;
/// <summary>
/// A simple menu screen with a single content entity.
/// </summary>
public class BasicMenuScreen(string title, INavigableMenuEntity content) : AbstractMenuScreen(title)
public class BasicMenuScreen : AbstractMenuScreen
{
/// <summary>
/// Construct a basic menu screen with a single content entity.
/// </summary>
public BasicMenuScreen(string title, INavigableMenuEntity content)
: base(title) => Content = content;

/// <summary>
/// The content displayed by this menu screen, minus the back button.
/// </summary>
Expand All @@ -23,12 +29,12 @@ public INavigableMenuEntity Content
throw new ArgumentNullException(nameof(Content));

if (field != value)
field.ClearParents();
field?.ClearParents();

field = value;
AddChild(field);
}
} = content;
}

/// <summary>
/// Remove the content pane for this menu, showing nothing instead.
Expand Down
4 changes: 3 additions & 1 deletion Screens/MenuScreenNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ IEnumerator Routine()
{
var ui = UIManager.instance;
ui.isFadingMenu = true;
yield return ui.StartCoroutine(ui.HideMenu(screen.MenuScreen));
yield return ui.StartCoroutine(
ui.HideMenu(screen.MenuScreen).PropagateContext<NavigationTypeContext>()
);
ui.isFadingMenu = false;
}

Expand Down