Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditionally add to hudstring, remove unneeded patch #223

Closed
wants to merge 3 commits into from
Closed
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
27 changes: 26 additions & 1 deletion source/Patches/CustomOption/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ public class CustomOption


protected internal CustomOption(int id, MultiMenu menu, string name, CustomOptionType type, object defaultValue,
Func<object, string> format = null)
Func<object, string> format = null, CustomOption dependsOn = null, int? stringoptionneedstobe = null)
{
ID = id;
Menu = menu;
Name = name;
Type = type;
DefaultValue = Value = defaultValue;
Format = format ?? (obj => $"{obj}");
DependsOn = dependsOn;
RequiredStringOptionValue = stringoptionneedstobe;

if (Type == CustomOptionType.Button) return;
AllOptions.Add(this);
Expand All @@ -32,6 +34,8 @@ protected internal CustomOption(int id, MultiMenu menu, string name, CustomOptio
protected internal OptionBehaviour Setting { get; set; }
protected internal CustomOptionType Type { get; set; }
public object DefaultValue { get; set; }
public CustomOption DependsOn { get; set; }
public int? RequiredStringOptionValue { get; set; }

public static bool LobbyTextScroller { get; set; } = true;

Expand All @@ -45,6 +49,27 @@ public virtual void OptionCreated()
Setting.name = Setting.gameObject.name = Name;
}

public virtual bool ShouldShow()
{
if (DependsOn == null) return true;

if (DependsOn is CustomToggleOption toggle && toggle.Get() == false)
{
return false;
}
else if (DependsOn is CustomNumberOption number && number.Get() == 0)
{
return false;
}
else if (DependsOn is CustomStringOption stringtoggle)
{
var selected = stringtoggle.Get();
if (selected != RequiredStringOptionValue) return false;
}

return true;
}


protected internal void Set(object value, bool SendRpc = true)
{
Expand Down
620 changes: 316 additions & 304 deletions source/Patches/CustomOption/Generate.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/Patches/CustomOption/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace TownOfUs.CustomOption
{
public class CustomHeaderOption : CustomOption
{
protected internal CustomHeaderOption(int id, MultiMenu menu, string name) : base(id, menu, name, CustomOptionType.Header, 0)
protected internal CustomHeaderOption(int id, MultiMenu menu, string name, CustomOption dependsOn = null, int? stringoptionneedstobe = null) : base(id, menu, name, CustomOptionType.Header, 0, dependsOn: dependsOn, stringoptionneedstobe: stringoptionneedstobe)
{
}

Expand Down
2 changes: 1 addition & 1 deletion source/Patches/CustomOption/Number.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TownOfUs.CustomOption
public class CustomNumberOption : CustomOption
{
protected internal CustomNumberOption(int id, MultiMenu menu, string name, float value, float min, float max, float increment,
Func<object, string> format = null) : base(id, menu, name, CustomOptionType.Number, value, format)
Func<object, string> format = null, CustomOption dependsOn = null, int? stringoptionneedstobe = null) : base(id, menu, name, CustomOptionType.Number, value, format, dependsOn, stringoptionneedstobe)
{
Min = min;
Max = max;
Expand Down
12 changes: 0 additions & 12 deletions source/Patches/CustomOption/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,18 +478,6 @@ public static bool Prefix(StringOption __instance)
}
}

[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.RpcSyncSettings))]
private class PlayerControlPatch
{
public static void Postfix()
{
if (PlayerControl.AllPlayerControls.Count < 2 || !AmongUsClient.Instance ||
!PlayerControl.LocalPlayer || !AmongUsClient.Instance.AmHost) return;

Rpc.SendRpc();
}
}

[HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.CoSpawnPlayer))]
private class PlayerJoinPatch
{
Expand Down
5 changes: 2 additions & 3 deletions source/Patches/CustomOption/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ namespace TownOfUs.CustomOption
{
public class CustomStringOption : CustomOption
{
protected internal CustomStringOption(int id, MultiMenu menu, string name, string[] values) : base(id, menu, name,
CustomOptionType.String,
0)
protected internal CustomStringOption(int id, MultiMenu menu, string name, string[] values, CustomOption dependsOn = null, int? stringoptionneedstobe = null) : base(id, menu, name,
CustomOptionType.String, 0, dependsOn: dependsOn, stringoptionneedstobe: stringoptionneedstobe)
{
Values = values;
Format = value => Values[(int) value];
Expand Down
5 changes: 2 additions & 3 deletions source/Patches/CustomOption/Toggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ namespace TownOfUs.CustomOption
{
public class CustomToggleOption : CustomOption
{
protected internal CustomToggleOption(int id, MultiMenu menu, string name, bool value = true) : base(id, menu, name,
CustomOptionType.Toggle,
value)
protected internal CustomToggleOption(int id, MultiMenu menu, string name, bool value = true, CustomOption dependsOn = null, int? stringoptionneedstobe = null) : base(id, menu, name,
CustomOptionType.Toggle, value, dependsOn: dependsOn, stringoptionneedstobe: stringoptionneedstobe)
{
Format = val => (bool) val ? "On" : "Off";
}
Expand Down
8 changes: 6 additions & 2 deletions source/Patches/GameSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ private static void Postfix(ref string __result)
if (option.Type == CustomOptionType.Button)
continue;

if (option.Type == CustomOptionType.Header)
if (option.Type == CustomOptionType.Header && option.ShouldShow())
{
builder.AppendLine($"\n{option.Name}");
else
}
else if (option.ShouldShow())
{
builder.AppendLine($" {option.Name}: {option}");
}
}
}

Expand Down
Loading