Skip to content

Commit

Permalink
Add a bunch of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkellly committed Dec 21, 2023
1 parent 48c2880 commit 538933f
Show file tree
Hide file tree
Showing 20 changed files with 1,442 additions and 24 deletions.
12 changes: 6 additions & 6 deletions Jungle/Buttons/CooldownButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CooldownButton : MonoBehaviour

public static T Create<T>() where T : CooldownButton
{
var buttonObj = new GameObject(typeof(T).Name) {layer = 5};
GameObject buttonObj = new GameObject(typeof(T).Name) {layer = 5};
buttonObj.transform.parent = HudManager.Instance.transform;
return buttonObj.AddComponent<T>();
}
Expand All @@ -44,7 +44,7 @@ public void Awake()
{
Buttons.Add(this);

var buttonObj = gameObject;
GameObject buttonObj = gameObject;

// SpriteRenderer
Renderer = buttonObj.AddComponent<SpriteRenderer>();
Expand All @@ -60,7 +60,7 @@ public void Awake()
Aspect.parentCam = HudManager.Instance.UICamera;

// PassiveButton
var buttonColl = buttonObj.AddComponent<BoxCollider2D>();
BoxCollider2D buttonColl = buttonObj.AddComponent<BoxCollider2D>();
buttonColl.size = new Vector2(1.15f, 1.15f);

Button = buttonObj.AddComponent<PassiveButton>();
Expand Down Expand Up @@ -104,7 +104,7 @@ public virtual void Update()

public void OnDestroy()
{
var myHashCode = GetHashCode();
int myHashCode = GetHashCode();
Buttons.RemoveAll(b => b.GetHashCode() == myHashCode);
}

Expand All @@ -114,7 +114,7 @@ public void OnDestroy()

public void SetPosition(AspectPosition.EdgeAlignments alignment, int buttonIndex = Int32.MaxValue)
{
var myHashCode = GetHashCode();
int myHashCode = GetHashCode();
if (buttonIndex == Int32.MaxValue) buttonIndex = Buttons.Count(c => c.GetHashCode() != myHashCode && c.Aspect!.Alignment == alignment);

Vector3 distanceFromEdge = new(0.7f, 0.7f, -5f);
Expand Down Expand Up @@ -158,7 +158,7 @@ public virtual bool ShouldBeVisible()
{
if (!ShipStatus.Instance) return false;
if (!HudManager.Instance.UseButton.gameObject.active) return false;
var localPlayer = PlayerControl.LocalPlayer;
PlayerControl localPlayer = PlayerControl.LocalPlayer;
if (!localPlayer || localPlayer.Data == null) return false;
if (localPlayer.Data.IsDead) return false;
return true;
Expand Down
62 changes: 62 additions & 0 deletions Jungle/Buttons/EffectButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using Il2CppInterop.Runtime.Attributes;
using Jungle.Effects;
using Reactor.Utilities.Attributes;
using UnityEngine;

namespace Jungle.Buttons;

[RegisterInIl2Cpp]
public class EffectButton : CooldownButton
{
public EffectButton(IntPtr ptr) : base(ptr) { }

public IEffect Effect;
public Coroutine EffectRoutine;

public override void PerformClick()
{
if (!ShouldCooldown() || !ShouldBeVisible() || !CanUse()) return;

CurrentTime = int.MaxValue;
StopAllCoroutines();
Effect = null;
EffectRoutine = StartCoroutine(ShowEffectDuration().WrapToIl2Cpp());
OnClickAction?.Invoke();
}

public override bool CanUse()
{
return EffectRoutine == null && base.CanUse();
}

[HideFromIl2Cpp]
public IEnumerator ShowEffectDuration()
{
while (Effect == null)
{
CurrentTime = int.MaxValue;
yield return null;
}

float duration = Effect.Timer;

while (Effect is { Timer: > 0 })
{
CurrentTime = int.MaxValue;
TimerText!.text = Mathf.CeilToInt(Effect.Timer).ToString();
TimerText.color = Effect.Timer / duration < 0.5
? Color.Lerp(new Color32(255, 0, 0, 255), new Color32(255, 242, 0, 255), (Effect.Timer / duration) * 2)
: Color.Lerp(new Color32(255, 242, 0, 255), new Color32(30, 150, 0, 255), ((Effect.Timer / duration) - 0.5f) * 2);

yield return null;
}

CurrentTime = Cooldown;
TimerText!.color = Color.white;
EffectRoutine = null;
Effect = null;
}
}
56 changes: 56 additions & 0 deletions Jungle/Buttons/TargetButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using AmongUs.GameOptions;
using Reactor.Utilities.Attributes;
using UnityEngine;

namespace Jungle.Buttons;

[RegisterInIl2Cpp]
// ReSharper disable once ClassWithVirtualMembersNeverInherited.Global
public class TargetButton : CooldownButton
{
public TargetButton(IntPtr ptr) : base(ptr) { }

public PlayerControl Target { get; set; }

public virtual float TargetRange() => GameOptionsData.KillDistances[Mathf.Clamp(GameOptionsManager.Instance.currentNormalGameOptions.KillDistance, 0, 2)];

public virtual PlayerControl GetClosest()
{
PlayerControl current = null;
float maxDistance = TargetRange();
Vector2 myPosition = PlayerControl.LocalPlayer.GetTruePosition();
foreach (PlayerControl player in PlayerControl.AllPlayerControls)
{
if (player.AmOwner || player.Data.IsDead) continue;
float distance = Vector2.Distance(myPosition, player.GetTruePosition());
if (distance <= maxDistance)
{
current = player;
maxDistance = distance;
}
}

return current;
}

public override void PerformClick()
{
if (!Target) return;
base.PerformClick();
}

public override bool CanUse()
{
if (!Target) return false;
return base.CanUse();
}

public override void Update()
{
base.Update();

Target = GetClosest();
SetButtonSaturation(Target);
}
}
58 changes: 58 additions & 0 deletions Jungle/Buttons/TargetEffectButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using AmongUs.GameOptions;
using Reactor.Utilities.Attributes;
using UnityEngine;

namespace Jungle.Buttons;

[RegisterInIl2Cpp]
// ReSharper disable once ClassWithVirtualMembersNeverInherited.Global
public class TargetEffectButton : EffectButton
{
public TargetEffectButton(IntPtr ptr) : base(ptr) { }

public PlayerControl Target { get; set; }
public virtual float TargetRange() => GameOptionsData.KillDistances[Mathf.Clamp(GameOptionsManager.Instance.currentNormalGameOptions.KillDistance, 0, 2)];


public virtual PlayerControl GetClosest()
{
PlayerControl current = null;
float maxDistance = TargetRange();
Vector2 myPosition = PlayerControl.LocalPlayer.GetTruePosition();
foreach (PlayerControl player in PlayerControl.AllPlayerControls)
{
if (player.AmOwner || player.Data.IsDead) continue;
float distance = Vector2.Distance(myPosition, player.GetTruePosition());
if (distance <= maxDistance)
{
current = player;
maxDistance = distance;
}
}

return current;
}

public override void PerformClick()
{
if (!Target) return;
base.PerformClick();
}

public override bool CanUse()
{
if (!Target) return false;
return base.CanUse();
}

public override void Update()
{
base.Update();
if (CurrentTime != int.MaxValue)
{
Target = GetClosest();
SetButtonSaturation(Target);
}
}
}
35 changes: 34 additions & 1 deletion Jungle/Config/MapConfig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using Jungle.Extensions;
using Jungle.Map;
using UnityEngine;

namespace Jungle.Config;
Expand All @@ -19,6 +22,17 @@ public static class MapConfig
/// </summary>
public static bool DisableRoomTracker { get; set; }

/// <summary>
/// Removes the snow particles on polus
/// </summary>
public static bool DisableSnow { get; set; }

/// <summary>
/// Sets the new Colors for the lava
/// Leaving as default will keep original
/// </summary>
public static Color32[] LavaColors { get; set; } = LavaColorChanger.Default;

/// <summary>
/// AssetBundles containing the Sprites used to swap textures on the map
/// </summary>
Expand All @@ -37,7 +51,7 @@ public static class MapConfigPatches
{
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.Awake))]
[HarmonyPostfix]
public static void SetupConfig()
public static void SetupConfig(ShipStatus __instance)
{
if (MapConfig.DisableShadows)
{
Expand All @@ -51,6 +65,25 @@ public static void SetupConfig()

if (MapConfig.DisableRoomTracker) HudManager.Instance.roomTracker.text.renderer.enabled = false;

foreach (AssetBundle textureSwapBundle in MapConfig.TextureSwapBundles)
{
if (!MapConfig.SwapRawTextures)
{
List<Sprite> sprites = textureSwapBundle.LoadAllAssets().OfIl2CppType<Sprite>().ToList();
SpriteSwapper.Swap(__instance.gameObject, sprites);
}
else
{
SpriteSwapper.SwapMapSpritesRaw(textureSwapBundle);
}
}

// Map specific
if (__instance.Type == ShipStatus.MapType.Pb)
{
if (MapConfig.DisableSnow) Object.FindObjectOfType<SnowManager>()?.gameObject.SetActive(false);
}

// TODO: Texture swapping
}
}
Loading

0 comments on commit 538933f

Please sign in to comment.