Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dabao40 committed Oct 7, 2024
1 parent e681a4f commit 0b2ca34
Show file tree
Hide file tree
Showing 23 changed files with 249 additions and 34 deletions.
Binary file modified Strings.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions TheOtherRoles/CustomGameModes/FreePlayGM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void SetWidget(int tab)
guis
);

GUIContext inner = GUIEmptyWidget.Default;
GUIContext inner = GUIEmptyContext.Default;

if (tab == 0)
{
Expand Down Expand Up @@ -107,7 +107,7 @@ void SetWidget(int tab)
})), 4)}
);
}
roleScreen.SetContext(gui.VerticalHolder(GUIAlignment.Center, new List<GUIContext>() { holder, gui.ScrollView(GUIAlignment.Center, new(7.4f, 3.5f), null, inner, out _) }), out _);
roleScreen.SetContext(gui.VerticalHolder(GUIAlignment.Center, new List<GUIContext>() { holder, TORGUIContextEngine.API.VerticalMargin(0.15f), gui.ScrollView(GUIAlignment.Center, new(7.4f, 3.5f), null, inner, out _) }), out _);
}

SetWidget(0);
Expand Down
9 changes: 9 additions & 0 deletions TheOtherRoles/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ public static string camelString(this string input)
return firstLetter + remainingLetters;
}

public static string HeadLower(this string text) => char.ToLower(text[0]) + text[1..];
public static string HeadUpper(this string text) => char.ToUpper(text[0]) + text[1..];

public static IEnumerator CoGush(this PlayerControl player)
{

Expand Down Expand Up @@ -606,6 +609,12 @@ private static IEnumerator AnimateCoroutine(HideAndSeekDeathPopup __instance)
UnityEngine.Object.Destroy(andSeekDeathPopup.gameObject);
}

static public IEnumerator Action(Action action)
{
action.Invoke();
yield break;
}

public static PassiveButton SetUpButton(this GameObject gameObject, bool withSound = false, SpriteRenderer buttonRenderer = null, Color? defaultColor = null, Color? selectedColor = null)
{
var button = gameObject.AddComponent<PassiveButton>();
Expand Down
2 changes: 1 addition & 1 deletion TheOtherRoles/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace TheOtherRoles
public class TheOtherRolesPlugin : BasePlugin
{
public const string Id = "me.eisbison.theotherroles";
public const string VersionString = "1.2.8";
public const string VersionString = "1.2.9";
public static uint betaDays = 0; // amount of days for the build to be usable (0 for infinite!)

public static Version Version = Version.Parse(VersionString);
Expand Down
37 changes: 20 additions & 17 deletions TheOtherRoles/MetaContext/MetaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public void Update()

public abstract class AbstractGUIContext : GUIContext
{
public GUIAlignment Alignment { get; private init; }
public GameObject Instantiate(Anchor anchor, Size size, out Size actualSize)
internal override GUIAlignment Alignment { get; init; }
internal override GameObject Instantiate(Anchor anchor, Size size, out Size actualSize)
{
var obj = Instantiate(size, out actualSize);

Expand All @@ -198,8 +198,6 @@ public GameObject Instantiate(Anchor anchor, Size size, out Size actualSize)
return obj;
}

public abstract GameObject Instantiate(Size size, out Size actualSize);

public AbstractGUIContext(GUIAlignment alignment)
{
Alignment = alignment;
Expand Down Expand Up @@ -299,7 +297,7 @@ public GUIScrollView(GUIAlignment alignment, UnityEngine.Vector2 size, GUIContex
}


public override GameObject Instantiate(Size size, out Size actualSize)
internal override GameObject Instantiate(Size size, out Size actualSize)
{
var view = Helpers.CreateObject("ScrollView", null, new UnityEngine.Vector3(0f, 0f, 0f), LayerMask.NameToLayer("UI"));
var inner = Helpers.CreateObject("Inner", view.transform, new UnityEngine.Vector3(-0.2f, 0f, -0.1f));
Expand Down Expand Up @@ -351,7 +349,7 @@ public class VerticalContextsHolder : ContextsHolder
public VerticalContextsHolder(GUIAlignment alignment, IEnumerable<GUIContext> contexts) : base(alignment, contexts) { }
public VerticalContextsHolder(GUIAlignment alignment, params GUIContext[] contexts) : base(alignment, contexts) { }
public float? FixedWidth { get; init; } = null;
public override GameObject Instantiate(Size size, out Size actualSize)
internal override GameObject Instantiate(Size size, out Size actualSize)
{
var results = contexts.Select(c => (c.Instantiate(size, out var acSize), acSize, c)).ToArray();
(float maxWidth, float sumHeight) = results.Aggregate((0f, 0f), (r, current) => (Math.Max(r.Item1, current.acSize.Width), r.Item2 + current.acSize.Height));
Expand Down Expand Up @@ -383,7 +381,7 @@ public HorizontalContextsHolder(GUIAlignment alignment, IEnumerable<GUIContext>
public HorizontalContextsHolder(GUIAlignment alignment, params GUIContext[] contexts) : base(alignment, contexts) { }
public float? FixedHeight { get; init; } = null;

public override GameObject Instantiate(Size size, out Size actualSize)
internal override GameObject Instantiate(Size size, out Size actualSize)
{
var results = contexts.Select(c => (c.Instantiate(size, out var acSize), acSize, c)).ToArray();
(float sumWidth, float maxHeight) = results.Aggregate((0f, 0f), (r, current) => (r.Item1 + current.acSize.Width, Math.Max(r.Item2, current.acSize.Height)));
Expand Down Expand Up @@ -447,10 +445,13 @@ public void SetHelpContext(PassiveUiElement related, string rawText)

public class TORGUIContextEngine : GUI
{
public static TORGUIContextEngine Instance { get; private set; } = new();
public static TORGUIContextEngine Instance { get; private set; } = new();
public static GUI API => Instance;

private Dictionary<AttributeParams, TextAttributes> allAttr = new();
private Dictionary<AttributeAsset, TextAttributes> allAttrAsset = new();

public GUIContext EmptyContext => GUIEmptyContext.Default;

public TextAttributes GetAttribute(AttributeParams attribute)
{
Expand All @@ -477,7 +478,9 @@ public TextAttributes GetAttribute(AttributeAsset attribute)
AttributeAsset.StandardMediumMasked => new TextAttributes(TextAlignment.Center, GetFont(FontAsset.Gothic), FontStyle.Bold, new(1.6f, 0.8f, 1.6f), new(1.45f, 0.3f), new(255, 255, 255), false),
AttributeAsset.StandardLargeWideMasked => new TextAttributes(TextAlignment.Center, GetFont(FontAsset.Gothic), FontStyle.Bold, new(1.7f, 1f, 1.7f), new(2.9f, 0.45f), new(255, 255, 255), false),
AttributeAsset.OverlayContent => new TextAttributes(Instance.GetAttribute(AttributeParams.StandardBaredLeft)) { FontSize = new(1.5f, 1.1f, 1.5f), Size = new(5f, 6f) },
AttributeAsset.MetaRoleButton => new TextAttributes(TextAlignment.Center, GetFont(FontAsset.GothicMasked), FontStyle.Bold, new(1.8f, 1f, 2f), new(1.4f, 0.26f), new(255, 255, 255), false),
AttributeAsset.MetaRoleButton => new TextAttributes(TextAlignment.Center, GetFont(FontAsset.GothicMasked), FontStyle.Bold, new(1.8f, 1f, 2f), new(1.4f, 0.26f), new(255, 255, 255), false),
AttributeAsset.DocumentTitle => new TextAttributes(Instance.GetAttribute(AttributeParams.StandardBoldLeft)) { FontSize = new(2.2f, 0.6f, 2.2f), Size = new(5f, 6f) },
AttributeAsset.DocumentStandard => new TextAttributes(Instance.GetAttribute(AttributeParams.StandardLeft)) { FontSize = new(1.2f, 0.6f, 1.2f), Size = new(7f, 6f) },
_ => null!
};
}
Expand Down Expand Up @@ -582,15 +585,15 @@ public GUIContext Button(GUIAlignment alignment, TextAttributes attribute, TextC

}

public class GUIEmptyWidget : AbstractGUIContext
public class GUIEmptyContext : AbstractGUIContext
{
static public GUIEmptyWidget Default = new();
static public GUIEmptyContext Default = new();

public GUIEmptyWidget(GUIAlignment alignment = GUIAlignment.Left) : base(alignment)
public GUIEmptyContext(GUIAlignment alignment = GUIAlignment.Left) : base(alignment)
{
}

public override GameObject Instantiate(Size size, out Size actualSize)
internal override GameObject Instantiate(Size size, out Size actualSize)
{
actualSize = new(0f, 0f);
return null;
Expand All @@ -611,7 +614,7 @@ public TORGUIImage(GUIAlignment alignment, Image image, FuzzySize size, Color? c
this.Color = color;
}

public override GameObject Instantiate(Size size, out Size actualSize)
internal override GameObject Instantiate(Size size, out Size actualSize)
{
var renderer = Helpers.CreateObject<SpriteRenderer>("Image", null, UnityEngine.Vector3.zero, LayerMask.NameToLayer("UI"));
renderer.sprite = Image.GetSprite();
Expand Down Expand Up @@ -654,7 +657,7 @@ public GUIButton(GUIAlignment alignment, TextAttributes attribute, TextComponent
}


public override GameObject Instantiate(Size size, out Size actualSize)
internal override GameObject Instantiate(Size size, out Size actualSize)
{
var inner = base.Instantiate(size, out actualSize)!;

Expand Down Expand Up @@ -720,7 +723,7 @@ public TORGUIMargin(GUIAlignment alignment, UnityEngine.Vector2 margin) : base(a
this.margin = margin;
}

public override GameObject Instantiate(Size size, out Size actualSize)
internal override GameObject Instantiate(Size size, out Size actualSize)
{
actualSize = new(margin);
return null;
Expand Down Expand Up @@ -758,7 +761,7 @@ private void ReflectMyAttribute(TMPro.TextMeshPro text, float width)
}
}

public override GameObject Instantiate(Size size, out Size actualSize)
internal override GameObject Instantiate(Size size, out Size actualSize)
{
if (Text == null)
{
Expand Down
19 changes: 14 additions & 5 deletions TheOtherRoles/MetaContext/MetaGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,31 @@ public GeneralizedArtifact(Artifact<V> inner)
public IEnumerator<T> GetEnumerator() => Inner.Select(v => v as T).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => Inner.Select(v => v as T).GetEnumerator();
}

public delegate GUIContext GUIContextSupplier();

/// <summary>
/// GUI上に表示できるオブジェクトの定義を表します。
/// </summary>
public interface GUIContext
public abstract class GUIContext
{
internal GUIAlignment Alignment { get; }
internal GameObject Instantiate(Size size, out Size actualSize);
internal GameObject Instantiate(Anchor anchor, Size size, out Size actualSize);
internal abstract GUIAlignment Alignment { get; init; }
internal abstract GameObject Instantiate(Size size, out Size actualSize);
internal abstract GameObject Instantiate(Anchor anchor, Size size, out Size actualSize);

public static implicit operator GUIContextSupplier(GUIContext widget) => () => widget ?? TORGUIContextEngine.Instance.EmptyContext;
}

/// <summary>
/// GUI上に表示する各種オブジェクトの定義や関連するオブジェクトを生成できます。
/// </summary>
public interface GUI
{
{
/// <summary>
/// 何も表示しないウィジェットです。
/// </summary>
GUIContext EmptyContext { get; }

/// <summary>
/// 生文字列のコンテキストです。
/// Textメソッドの呼び出しを簡素化した冗長なメソッドです。
Expand Down
82 changes: 82 additions & 0 deletions TheOtherRoles/MetaContext/MetaHint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.Rendering;
using UnityEngine;
using System.Collections;

namespace TheOtherRoles.MetaContext
{
public interface Hint
{
public GUIContextSupplier GUI { get; }
}

public class HintWithImage : Hint
{
private Image Image { get; init; }
private TextComponent Title { get; init; }
private TextComponent Detail { get; init; }

GUIContextSupplier Hint.GUI => () =>
{
return TORGUIContextEngine.API.VerticalHolder(GUIAlignment.Center,
TORGUIContextEngine.API.Margin(new(null, 0.5f)),
TORGUIContextEngine.API.Image(GUIAlignment.Center, Image, new(4f, 2.1f)),
TORGUIContextEngine.API.Margin(new(null, 0.6f)),
TORGUIContextEngine.API.Text(GUIAlignment.Left, TORGUIContextEngine.API.GetAttribute(AttributeAsset.DocumentTitle), Title),
TORGUIContextEngine.API.Margin(new(null, 0.1f)),
TORGUIContextEngine.API.HorizontalHolder(GUIAlignment.Center, TORGUIContextEngine.API.HorizontalMargin(0.16f), TORGUIContextEngine.API.Text(GUIAlignment.Left, TORGUIContextEngine.API.GetAttribute(AttributeAsset.DocumentStandard), Detail))
);
};

public HintWithImage(Image image, TextComponent title, TextComponent detail)
{
Image = image;
Title = title;
Detail = detail;
}
}

public class HintManager
{
internal static List<Hint> AllHints = new();

static private Hint WithImage(string id) => new HintWithImage(SpriteLoader.FromResource("TheOtherRoles.Resources.Hints." + id.HeadUpper() + ".png", 100f), new TranslateTextComponent("hint" + id.HeadUpper() + "Title"), new TranslateTextComponent("hint" + id.HeadUpper() + "Detail"));
static HintManager()
{
RegisterHint(WithImage("HelpInGame"));
RegisterHint(WithImage("Busker"));
RegisterHint(WithImage("Sherlock"));
RegisterHint(WithImage("Achievement"));
RegisterHint(WithImage("FreePlay"));
RegisterHint(WithImage("AboutSection"));
}

public static void RegisterHint(Hint hint) => AllHints.Add(hint);

public static IEnumerator CoShowHint(float delay = 0.5f)
{
yield return Effects.Wait(delay);

var overlay = GameObject.Instantiate(TransitionFade.Instance.overlay, null);
overlay.transform.position = TransitionFade.Instance.overlay.transform.position + new Vector3(0, 0, -100f);
overlay.color = Color.black;
overlay.gameObject.layer = LayerMask.NameToLayer("UI");
overlay.gameObject.AddComponent<SortingGroup>().sortingOrder = 150;

var mask = Helpers.CreateObject<SpriteMask>("Mask", overlay.transform, new Vector3(0, 0, 5f));
mask.sprite = overlay.sprite;
mask.transform.localScale = overlay.size;

var hint = AllHints[System.Random.Shared.Next(AllHints.Count)].GUI.Invoke().Instantiate(new(new(0.5f, 0.5f), new(0f, 0f, 0f)), new(6f, 4f), out _);
hint?.transform.SetParent(overlay.transform);
if (hint) hint!.transform.localPosition = new(0f, 0f, 10f);

yield return Effects.ColorFade(overlay, Color.black, Color.clear, 0.5f);
}

}
}
10 changes: 10 additions & 0 deletions TheOtherRoles/MetaContext/MetaText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public enum AttributeAsset
/// フリープレイの役職選択ボタンで使用されているテキスト属性です。
/// </summary>
MetaRoleButton,

/// <summary>
/// SerializableDocumentのTextStyle"Title"で提供されているテキスト属性です。
/// </summary>
DocumentTitle,

/// <summary>
/// SerializableDocumentのTextStyle"Standard"で提供されているテキスト属性です。
/// </summary>
DocumentStandard,
}

[Flags]
Expand Down
4 changes: 2 additions & 2 deletions TheOtherRoles/Modules/ChatCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public static bool Prefix(ChatController __instance, [HarmonyArgument(0)] Player
if (__instance != FastDestroyableSingleton<HudManager>.Instance.Chat)
return true;
PlayerControl localPlayer = CachedPlayer.LocalPlayer.PlayerControl;
return localPlayer == null || (MeetingHud.Instance != null || LobbyBehaviour.Instance != null || (localPlayer.Data.IsDead || (localPlayer.isLover() && Lovers.enableChat) || (Cupid.lovers1 != null
&& Cupid.lovers2 != null && (CachedPlayer.LocalPlayer.PlayerControl == Cupid.lovers1 || CachedPlayer.LocalPlayer.PlayerControl == Cupid.lovers2))) || (int)sourcePlayer.PlayerId == (int)CachedPlayer.LocalPlayer.PlayerId);
return localPlayer == null || MeetingHud.Instance != null || LobbyBehaviour.Instance != null || (localPlayer.Data.IsDead && !(localPlayer == Busker.busker && Busker.pseudocideFlag)) || (localPlayer.isLover() && Lovers.enableChat &&
sourcePlayer == localPlayer.getPartner()) || (localPlayer.isCupidLover() && sourcePlayer == localPlayer.getCupidLover()) || sourcePlayer.PlayerId == CachedPlayer.LocalPlayer.PlayerId;

}
}
Expand Down
2 changes: 2 additions & 0 deletions TheOtherRoles/Modules/CustomOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ public static void drawTab(LobbyViewSettingsPane __instance, CustomOptionType op

if (TORMapOptions.gameMode == CustomGamemodes.Guesser) // Exclude guesser options in neutral mode
relevantOptions = relevantOptions.Where(x => !(new List<int> { 310, 311, 312, 313, 314, 315, 316, 317, 318 }).Contains(x.id)).ToList();
if (TORMapOptions.gameMode != CustomGamemodes.FreePlay)
relevantOptions = relevantOptions.Where(x => x.id != 10424).ToList();

for (int j = 0; j < __instance.settingsInfo.Count; j++)
{
Expand Down
37 changes: 37 additions & 0 deletions TheOtherRoles/Patches/GameStartManagerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using TheOtherRoles.Utilities;
using System.Linq;
using Reactor.Utilities.Extensions;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using TheOtherRoles.MetaContext;

namespace TheOtherRoles.Patches {
[HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Update))]
Expand Down Expand Up @@ -36,6 +38,41 @@ public static void Postfix(AmongUsClient __instance) {
}
}

[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CoJoinOnlineGameFromCode))]
public class JoinGameLoadingPatch
{
public static void Postfix(AmongUsClient __instance, ref Il2CppSystem.Collections.IEnumerator __result)
{
var overlay = GameObject.Instantiate(TransitionFade.Instance.overlay, null);
overlay.transform.position = TransitionFade.Instance.overlay.transform.position;

System.Collections.IEnumerator CoFadeInIf()
{
if (AmongUsClient.Instance.ClientId < 0)
{
yield return Effects.ColorFade(overlay, Color.black, Color.clear, 0.2f);
GameObject.Destroy(overlay.gameObject);
}
}

__result = Effects.Sequence(
Effects.ColorFade(overlay, Color.clear, Color.black, 0.2f),
Helpers.Action(() => TORGUIManager.Instance.StartCoroutine(HintManager.CoShowHint(0.6f).WrapToIl2Cpp())).WrapToIl2Cpp(),
__result,
CoFadeInIf().WrapToIl2Cpp()
);
}
}

[HarmonyPatch(typeof(CreateGameOptions), nameof(CreateGameOptions.Confirm))]
public class CreateGameOptionsLoadingPatch
{
public static void Postfix(CreateGameOptions __instance)
{
TORGUIManager.Instance.StartCoroutine(HintManager.CoShowHint(0.6f + 0.2f).WrapToIl2Cpp());
}
}

[HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Start))]
public class GameStartManagerStartPatch {
public static void Postfix(GameStartManager __instance) {
Expand Down
Loading

0 comments on commit 0b2ca34

Please sign in to comment.