<commit_before>﻿using Mirror;
using UnityEngine;
using UnityEngine.UI;

namespace AdminTools
{
	public class AdminChatButtons : MonoBehaviour
	{
		public GUI_Notification adminNotification = null;
		public GUI_Notification playerNotification = null;
		public GUI_Notification prayerNotification = null;
		[SerializeField] private AdminChatWindows adminChatWindows = null;
		[SerializeField] private Button adminChatButton = null;
		[SerializeField] private Button playerChatButton = null;
		[SerializeField] private Button prayerWindowButton = null;
		[SerializeField] private Color selectedColor;
		[SerializeField] private Color unSelectedColor;

		private void OnEnable()
		{
			adminChatWindows.WindowChangeEvent += OnAdminChatWindowChange;
			ToggleButtons(AdminChatWindow.None);
		}

		private void OnDisable()
		{
			adminChatWindows.WindowChangeEvent -= OnAdminChatWindowChange;
		}

		void OnAdminChatWindowChange(AdminChatWindow selectedWindow)
		{
			ToggleButtons(selectedWindow);
		}

		void ToggleButtons(AdminChatWindow selectedWindow)
		{
			adminChatButton.image.color = unSelectedColor;
			playerChatButton.image.color = unSelectedColor;
			prayerWindowButton.image.color = unSelectedColor;

			switch (selectedWindow)
			{
				case AdminChatWindow.AdminPlayerChat:
					playerChatButton.image.color = selectedColor;
					break;
				case AdminChatWindow.AdminToAdminChat:
					adminChatButton.image.color = selectedColor;
					break;
				case AdminChatWindow.PrayerWindow:
					prayerWindowButton.image.color = selectedColor;
					break;
			}
		}

		public void ClearAllNotifications()
		{
			adminNotification.ClearAll();
			playerNotification.ClearAll();
			prayerNotification.ClearAll();
		}

		/// <summary>
		/// Use for initialization of admin chat notifications when the admin logs in
		/// </summary>
		/// <param name="adminConn"></param>
		public void ServerUpdateAdminNotifications(NetworkConnection adminConn)
		{
			var update = new AdminChatNotificationFullUpdate();

			foreach (var n in adminNotification.notifications)
			{
				update.notificationEntries.Add(new AdminChatNotificationEntry
				{
					Amount = n.Value,
					Key = n.Key,
					TargetWindow = AdminChatWindow.AdminToAdminChat
				});
			}

			foreach (var n in playerNotification.notifications)
			{
				update.notificationEntries.Add(new AdminChatNotificationEntry
				{
					Amount = n.Value,
					Key = n.Key,
					TargetWindow = AdminChatWindow.AdminPlayerChat
				});
			}

			foreach (var n in prayerNotification.notifications)
			{
				update.notificationEntries.Add(new AdminChatNotificationEntry
				{
					Amount = n.Value,
					Key = n.Key,
					TargetWindow = AdminChatWindow.PrayerWindow
				});
			}

			AdminChatNotifications.Send(adminConn, update);
		}

		public void ClientUpdateNotifications(string notificationKey, AdminChatWindow targetWindow,
			int amt, bool clearAll)
		{
			switch (targetWindow)
			{
				case AdminChatWindow.AdminPlayerChat:
					if (clearAll)
					{
						playerNotification.RemoveNotification(notificationKey);
						if (amt == 0) return;
					}
					//No need to update notification if the player is already selected in admin chat
					if (adminChatWindows.SelectedWindow == AdminChatWindow.AdminPlayerChat)
					{
						if (adminChatWindows.adminPlayerChat.SelectedPlayer != null
						    && adminChatWindows.adminPlayerChat.SelectedPlayer.uid == notificationKey)
						{
							break;
						}
					}
					playerNotification.AddNotification(notificationKey, amt);
					break;
				case AdminChatWindow.AdminToAdminChat:
					if (clearAll)
					{
						adminNotification.RemoveNotification(notificationKey);
						if (amt == 0) return;
					}

					if (adminChatWindows.adminToAdminChat.gameObject.activeInHierarchy) return;
					
					adminNotification.AddNotification(notificationKey, amt);
					break;<commit_msg>Clears Notifications on scene load<commit_after>﻿using Mirror;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

namespace AdminTools
{
	public class AdminChatButtons : MonoBehaviour
	{
		public GUI_Notification adminNotification = null;
		public GUI_Notification playerNotification = null;
		public GUI_Notification prayerNotification = null;
		[SerializeField] private AdminChatWindows adminChatWindows = null;
		[SerializeField] private Button adminChatButton = null;
		[SerializeField] private Button playerChatButton = null;
		[SerializeField] private Button prayerWindowButton = null;
		[SerializeField] private Color selectedColor;
		[SerializeField] private Color unSelectedColor;

		private void OnEnable()
		{
			adminChatWindows.WindowChangeEvent += OnAdminChatWindowChange;
			SceneManager.activeSceneChanged += OnSceneChange;
			ToggleButtons(AdminChatWindow.None);
		}

		private void OnDisable()
		{
			adminChatWindows.WindowChangeEvent -= OnAdminChatWindowChange;
			SceneManager.activeSceneChanged -= OnSceneChange;
		}

		void OnSceneChange(Scene oldScene, Scene newScene)
		{
			ClearAllNotifications();
		}

		void OnAdminChatWindowChange(AdminChatWindow selectedWindow)
		{
			ToggleButtons(selectedWindow);
		}

		void ToggleButtons(AdminChatWindow selectedWindow)
		{
			adminChatButton.image.color = unSelectedColor;
			playerChatButton.image.color = unSelectedColor;
			prayerWindowButton.image.color = unSelectedColor;

			switch (selectedWindow)
			{
				case AdminChatWindow.AdminPlayerChat:
					playerChatButton.image.color = selectedColor;
					break;
				case AdminChatWindow.AdminToAdminChat:
					adminChatButton.image.color = selectedColor;
					break;
				case AdminChatWindow.PrayerWindow:
					prayerWindowButton.image.color = selectedColor;
					break;
			}
		}

		public void ClearAllNotifications()
		{
			adminNotification.ClearAll();
			playerNotification.ClearAll();
			prayerNotification.ClearAll();
		}

		/// <summary>
		/// Use for initialization of admin chat notifications when the admin logs in
		/// </summary>
		/// <param name="adminConn"></param>
		public void ServerUpdateAdminNotifications(NetworkConnection adminConn)
		{
			var update = new AdminChatNotificationFullUpdate();

			foreach (var n in adminNotification.notifications)
			{
				update.notificationEntries.Add(new AdminChatNotificationEntry
				{
					Amount = n.Value,
					Key = n.Key,
					TargetWindow = AdminChatWindow.AdminToAdminChat
				});
			}

			foreach (var n in playerNotification.notifications)
			{
				update.notificationEntries.Add(new AdminChatNotificationEntry
				{
					Amount = n.Value,
					Key = n.Key,
					TargetWindow = AdminChatWindow.AdminPlayerChat
				});
			}

			foreach (var n in prayerNotification.notifications)
			{
				update.notificationEntries.Add(new AdminChatNotificationEntry
				{
					Amount = n.Value,
					Key = n.Key,
					TargetWindow = AdminChatWindow.PrayerWindow
				});
			}

			AdminChatNotifications.Send(adminConn, update);
		}

		public void ClientUpdateNotifications(string notificationKey, AdminChatWindow targetWindow,
			int amt, bool clearAll)
		{
			switch (targetWindow)
			{
				case AdminChatWindow.AdminPlayerChat:
					if (clearAll)
					{
						playerNotification.RemoveNotification(notificationKey);
						if (amt == 0) return;
					}
					//No need to update notification if the player is already selected in admin chat
					if (adminChatWindows.SelectedWindow == AdminChatWindow.AdminPlayerChat)
					{
						if (adminChatWindows.adminPlayerChat.SelectedPlayer != null
						    && adminChatWindows.adminPlayerChat.SelectedPlayer.uid == notificationKey)
						{
							break;
						}
					}
					playerNotification.AddNotification(notificationKey, amt);
					break;
				case AdminChatWindow.AdminToAdminChat:
					if (clearAll)
					{
						adminNotification.RemoveNotification(notificationKey);
						if (amt == 0) return;
					}

					if (adminChatWindows.adminToAdminChat.gameObject.activeInHierarchy) return;

					adminNotification.AddNotification(notificationKey, amt);
					break;
{'fraction_non_alphanumeric': 0.07855439829338687, 'fraction_numerical': 0.0005019450370184465, 'mean_word_length': 3.83030303030303, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '935672', 'n_tokens_mistral': 2773, 'n_tokens_neox': 2148, 'n_words': 467}