<commit_before>﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.U2D;

public class CameraZoomHandler : MonoBehaviour
{
	public float ZoomLevel => displaySettings.ZoomLevel;

	public bool ScrollWheelZoom => displaySettings.ScrollWheelZoom;

	private DisplaySettings displaySettings = null;
	private PixelPerfectCamera pixelPerfectCamera;

	void OnEnable()
	{
		displaySettings.SettingsChanged += DisplaySettings_SettingsChanged;
		Refresh();
	}
	private void OnDisable()
	{
		displaySettings.SettingsChanged -= DisplaySettings_SettingsChanged;
	}

	 

	private void OnLevelWasLoaded(int level)
	{
		// Connect up to the PixelPerfectCamera in the OnlineScene
		PixelPerfectCamera current = Camera.main.GetComponent<PixelPerfectCamera>();

		// Discard our old reference if it is from an old OnlineScene
		if (current != null && pixelPerfectCamera != current)
		{
			pixelPerfectCamera = current;
			Refresh();
		}
	}

	private void DisplaySettings_SettingsChanged(object sender, DisplaySettings.DisplaySettingsChangedEventArgs e)
	{
		if (e.ZoomLevelChanged)
		{
			Refresh();
		}
	}

	void Awake()
	{
		displaySettings = FindObjectOfType<DisplaySettings>();
	}

	/// <summary>
	/// Increment at which zoom changes when using Increase / DecreaseZoomLevel().
	/// </summary>
	private readonly int zoomIncrement = 8;

	void Update()
	{
		//Process any scroll wheel zooming:
		if (displaySettings.ScrollWheelZoom && !EventSystem.current.IsPointerOverGameObject())
		{
			if (Input.mouseScrollDelta.y > 0f)
			{
				if (!MouseOutside()) IncreaseZoomLevel();
			}

			if (Input.mouseScrollDelta.y < 0f)
			{
				if (!MouseOutside()) DecreaseZoomLevel();
			}
		}
	}

	bool MouseOutside()
	{
		var view = Camera.main.ScreenToViewportPoint(Input.mousePosition);
		return view.x < 0 || view.x > 1 || view.y < 0 || view.y > 1;
	}

	// Refreshes after setting zoom level.
	public void Refresh()
	{
		if (pixelPerfectCamera == null) pixelPerfectCamera = Camera.main.GetComponent<PixelPerfectCamera>();
		if (pixelPerfectCamera == null) return; //probably in the lobby
		pixelPerfectCamera.assetsPPU = displaySettings.ZoomLevel;

		if (Camera2DFollow.followControl != null)
		{
			Camera2DFollow.followControl.SetCameraXOffset();
		}
	}

	public void SetZoomLevel(int _zoomLevel)
	{
		displaySettings.ZoomLevel = _zoomLevel;
	}

	/// <summary>
	/// A convenient way to increase zoom level
	/// <summary>
	public void IncreaseZoomLevel()
	{
		displaySettings.ZoomLevel += zoomIncrement;
	}

	/// <summary>
	/// A convenient way to increase zoom level
	/// ZoomLevel of 0 = Auto Zoom
	/// <summary>
	public void DecreaseZoomLevel()<commit_msg>CameraZoomHandler: replace deprecated OnLevelWasLoaded method<commit_after>﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.U2D;
using UnityEngine.SceneManagement;

public class CameraZoomHandler : MonoBehaviour
{
	public float ZoomLevel => displaySettings.ZoomLevel;

	public bool ScrollWheelZoom => displaySettings.ScrollWheelZoom;

	private DisplaySettings displaySettings = null;
	private PixelPerfectCamera pixelPerfectCamera;

	void OnEnable()
	{
		displaySettings.SettingsChanged += DisplaySettings_SettingsChanged;
		SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
		UpdatePixelPerfectCamera();
	}

	private void OnDisable()
	{
		displaySettings.SettingsChanged -= DisplaySettings_SettingsChanged;
		SceneManager.activeSceneChanged -= SceneManager_activeSceneChanged;
	}

	private void SceneManager_activeSceneChanged(Scene arg0, Scene arg1)
	{
		UpdatePixelPerfectCamera();
	}

	private void UpdatePixelPerfectCamera()
	{
		// Connect up to the PixelPerfectCamera in the OnlineScene
		PixelPerfectCamera current = Camera.main.GetComponent<PixelPerfectCamera>();

		// Discard our old reference if it is from an old OnlineScene
		if (current != null && pixelPerfectCamera != current)
		{
			pixelPerfectCamera = current;
		}

		Refresh();
	}

	private void DisplaySettings_SettingsChanged(object sender, DisplaySettings.DisplaySettingsChangedEventArgs e)
	{
		if (e.ZoomLevelChanged)
		{
			Refresh();
		}
	}

	void Awake()
	{
		displaySettings = FindObjectOfType<DisplaySettings>();
	}

	/// <summary>
	/// Increment at which zoom changes when using Increase / DecreaseZoomLevel().
	/// </summary>
	private readonly int zoomIncrement = 8;

	void Update()
	{
		//Process any scroll wheel zooming:
		if (displaySettings.ScrollWheelZoom && !EventSystem.current.IsPointerOverGameObject())
		{
			if (Input.mouseScrollDelta.y > 0f)
			{
				if (!MouseOutside()) IncreaseZoomLevel();
			}

			if (Input.mouseScrollDelta.y < 0f)
			{
				if (!MouseOutside()) DecreaseZoomLevel();
			}
		}
	}

	bool MouseOutside()
	{
		var view = Camera.main.ScreenToViewportPoint(Input.mousePosition);
		return view.x < 0 || view.x > 1 || view.y < 0 || view.y > 1;
	}

	// Refreshes after setting zoom level.
	public void Refresh()
	{
		if (pixelPerfectCamera == null)
		{
			return; //probably in the lobby
		}

		pixelPerfectCamera.assetsPPU = displaySettings.ZoomLevel;

		if (Camera2DFollow.followControl != null)
		{
			Camera2DFollow.followControl.SetCameraXOffset();
		}
	}

	public void SetZoomLevel(int _zoomLevel)
	{
		displaySettings.ZoomLevel = _zoomLevel;
	}

	/// <summary>
	/// A convenient way to increase zoom level
	/// <summary>
	public void IncreaseZoomLevel()
	{
		displaySettings.ZoomLevel += zoomIncrement;
	}

	/// <summary>
	/// A convenient way to increase zoom level
	/// ZoomLevel of 0 = Auto Zoom
	/// <summary>
	public void DecreaseZoomLevel()
{'fraction_non_alphanumeric': 0.10240315638450502, 'fraction_numerical': 0.00430416068866571, 'mean_word_length': 4.246472248353716, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 30, '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': '4886576', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1630, 'n_words': 410}