From 192ba3cceb93524271135a7c0adc6a6c09ea1b71 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidoS@users.noreply.github.com> Date: Mon, 2 Sep 2024 00:36:49 -0500 Subject: [PATCH] Stickers: Added back Identify button --- .../BTKUI/UIAddon.Page.PlayerOptions.cs | 14 +++--- Stickers/Stickers/StickerData.cs | 18 +------ Stickers/Stickers/StickerSystem.Main.cs | 2 +- .../Stickers/StickerSystem.PlayerCallbacks.cs | 48 ++++++++++++------- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/Stickers/Integrations/BTKUI/UIAddon.Page.PlayerOptions.cs b/Stickers/Integrations/BTKUI/UIAddon.Page.PlayerOptions.cs index f44fc40..efc7a8e 100644 --- a/Stickers/Integrations/BTKUI/UIAddon.Page.PlayerOptions.cs +++ b/Stickers/Integrations/BTKUI/UIAddon.Page.PlayerOptions.cs @@ -15,8 +15,8 @@ public static partial class BTKUIAddon { Category category = QuickMenuAPI.PlayerSelectPage.AddCategory(ModSettings.SM_SettingsCategory, ModSettings.ModName); - //Button identifyButton = category.AddButton("Identify Stickers", "Stickers-magnifying-glass", "Identify this players stickers by making them flash."); - //identifyButton.OnPress += OnPressIdentifyPlayerStickersButton; + Button identifyButton = category.AddButton("Identify Stickers", "Stickers-magnifying-glass", "Identify this players stickers by making them flash."); + identifyButton.OnPress += OnPressIdentifyPlayerStickersButton; Button clearStickersButton = category.AddButton("Clear Stickers", "Stickers-eraser", "Clear this players stickers."); clearStickersButton.OnPress += OnPressClearSelectedPlayerStickersButton; @@ -30,11 +30,11 @@ public static partial class BTKUIAddon #region Callbacks - // private static void OnPressIdentifyPlayerStickersButton() - // { - // if (string.IsNullOrEmpty(QuickMenuAPI.SelectedPlayerID)) return; - // StickerSystem.Instance.OnStickerIdentifyReceived(QuickMenuAPI.SelectedPlayerID); - // } + private static void OnPressIdentifyPlayerStickersButton() + { + if (string.IsNullOrEmpty(QuickMenuAPI.SelectedPlayerID)) return; + StickerSystem.Instance.OnStickerIdentifyReceived(QuickMenuAPI.SelectedPlayerID); + } private static void OnPressClearSelectedPlayerStickersButton() { diff --git a/Stickers/Stickers/StickerData.cs b/Stickers/Stickers/StickerData.cs index f193d12..da33888 100644 --- a/Stickers/Stickers/StickerData.cs +++ b/Stickers/Stickers/StickerData.cs @@ -12,6 +12,7 @@ namespace NAK.Stickers public readonly string PlayerId; public float LastPlacedTime; public float DeathTime = -1f; + public float IdentifyTime = -1f; private Vector3 _lastPlacedPosition = Vector3.zero; @@ -200,22 +201,5 @@ namespace NAK.Stickers material.color = color; } } - - #region shitty identify - - public void Identify() - { - Color color = Color.HSVToRGB(Time.time % 1f, 1f, 1f); - foreach (Material material in _materials) - material.color = color; // cycle rainbow - } - - public void ResetIdentify() - { - foreach (Material material in _materials) - material.color = Color.white; - } - - #endregion shitty identify } } \ No newline at end of file diff --git a/Stickers/Stickers/StickerSystem.Main.cs b/Stickers/Stickers/StickerSystem.Main.cs index ad02060..a58e724 100644 --- a/Stickers/Stickers/StickerSystem.Main.cs +++ b/Stickers/Stickers/StickerSystem.Main.cs @@ -42,7 +42,7 @@ public partial class StickerSystem CVRGameEventSystem.Player.OnJoinEntity.AddListener(Instance.OnPlayerJoined); CVRGameEventSystem.Player.OnLeaveEntity.AddListener(Instance.OnPlayerLeft); - SchedulerSystem.AddJob(Instance.OnOccasionalUpdate, 10f, 1f); + SchedulerSystem.AddJob(Instance.OnUpdate, 10f, -1); LoadAllImagesAtStartup(); } diff --git a/Stickers/Stickers/StickerSystem.PlayerCallbacks.cs b/Stickers/Stickers/StickerSystem.PlayerCallbacks.cs index 3637abc..89394c9 100644 --- a/Stickers/Stickers/StickerSystem.PlayerCallbacks.cs +++ b/Stickers/Stickers/StickerSystem.PlayerCallbacks.cs @@ -25,24 +25,38 @@ public partial class StickerSystem stickerData.SetAlpha(1f); } - private void OnOccasionalUpdate() + private void OnUpdate() { float currentTime = Time.time; for (int i = 0; i < _playerStickers.Values.Count; i++) { StickerData stickerData = _playerStickers.Values.ElementAt(i); - - if (stickerData.DeathTime < 0f) - continue; - if (currentTime < stickerData.DeathTime) + if (stickerData.DeathTime > 0f) { - stickerData.SetAlpha(Mathf.Lerp(0f, 1f, (stickerData.DeathTime - currentTime) / StickerKillTime)); + if (currentTime < stickerData.DeathTime) + { + stickerData.SetAlpha(Mathf.Lerp(0f, 1f, (stickerData.DeathTime - currentTime) / StickerKillTime)); + continue; + } + + stickerData.Cleanup(); + _playerStickers.Remove(stickerData.PlayerId); continue; } - - stickerData.Cleanup(); - _playerStickers.Remove(stickerData.PlayerId); + + if (stickerData.IdentifyTime > 0) + { + if (currentTime < stickerData.IdentifyTime) + { + // blink alpha 3 times but not completely off + stickerData.SetAlpha(Mathf.Lerp(0.2f, 1f, Mathf.PingPong((stickerData.IdentifyTime - currentTime) * 2f, 1f))); + continue; + } + + stickerData.SetAlpha(1f); + stickerData.IdentifyTime = -1; + } } } @@ -59,15 +73,13 @@ public partial class StickerSystem public void OnStickerClearAllReceived(string playerId) => ClearStickersForPlayer(playerId); - // public void OnStickerIdentifyReceived(string playerId) - // { - // if (!_playerStickers.TryGetValue(playerId, out StickerData stickerData)) - // return; - // - // // todo: make prettier (idk shaders) - // SchedulerSystem.AddJob(() => stickerData.Identify(), 0f, 0.1f, 30); - // SchedulerSystem.AddJob(() => stickerData.ResetIdentify(), 4f, 1f, 1); - // } + public void OnStickerIdentifyReceived(string playerId) + { + if (!_playerStickers.TryGetValue(playerId, out StickerData stickerData)) + return; + + stickerData.IdentifyTime = Time.time + 3f; + } #endregion Player Callbacks }