diff --git a/Assets/Scripts/View/Control/NavigationScript.cs b/Assets/Scripts/View/Control/NavigationScript.cs index 01499a9..893225a 100644 --- a/Assets/Scripts/View/Control/NavigationScript.cs +++ b/Assets/Scripts/View/Control/NavigationScript.cs @@ -42,6 +42,8 @@ public class NavigationScript : MonoBehaviour { ButtonType.Settings, scrollView => scrollView.ToggleSettings() }, { ButtonType.MusicToggle, scrollView => scrollView.ToggleMusic() }, { ButtonType.SfxToggle, scrollView => scrollView.ToggleSfx() }, + { ButtonType.ScrollUp, scrollView => scrollView.OnScrollUp() }, + { ButtonType.ScrollDown, scrollView => scrollView.OnScrollDown() }, }; public bool IsTweening => _buttonSelect.IsTweening; diff --git a/Assets/Scripts/View/Control/ScrollView.cs b/Assets/Scripts/View/Control/ScrollView.cs index 0f22df6..acdea60 100644 --- a/Assets/Scripts/View/Control/ScrollView.cs +++ b/Assets/Scripts/View/Control/ScrollView.cs @@ -15,7 +15,11 @@ namespace View.Control /// public class ScrollView : MonoBehaviour { - public GameObject PuzzleGamePrefab; + [SerializeField] + private float _scrollButtonScale; + + [SerializeField] + private GameObject _puzzleGamePrefab; private bool _scrollEnabled; @@ -26,6 +30,7 @@ public class ScrollView : MonoBehaviour private float _listBottom; private float _listTop; private bool _isPanning; + private float _scrollSpeed; private Vector3 _panVelocity; private Vector3 _magnetVelocity; @@ -36,18 +41,17 @@ public class ScrollView : MonoBehaviour private int _cameraZoomId; + [SerializeField] private NavigationScript _navigation; + [SerializeField] private MoveDisplay _moveDisplay; + [SerializeField] private GameAudio _gameAudio; private void Awake() { - // Set the maximum number of simultaneous tweens - LeanTween.init(30000); - - _navigation = GameObject.FindGameObjectWithTag("Navigation").GetComponent(); - _moveDisplay = GameObject.FindGameObjectWithTag("MoveDisplay").GetComponent(); - _gameAudio = GameObject.FindGameObjectWithTag("GameAudio").GetComponent(); + // Set the maximum number of simultaneous tweens + LeanTween.init(30000); // Set the game's strings to their localized versions var language = Levels.CurrentLanguage; @@ -341,7 +345,7 @@ private void GenerateLevelsList() private void GenerateLevel(int level, float margin, ref float prevOffset) { - var puzzleGame = Instantiate(PuzzleGamePrefab); + var puzzleGame = Instantiate(_puzzleGamePrefab); puzzleGame.name = $"PuzzleGame ({level})"; puzzleGame.transform.SetParent(transform); @@ -452,38 +456,23 @@ private void OnPuzzleWin(int level) private void OnPan(TKPanRecognizer recognizer) { - if (!_scrollEnabled) { - return; - } - - _isPanning = true; - - _panVelocity = Vector2.zero; - _magnetVelocity = Vector2.zero; - - // TODO: make configurable - const float scalingFactor = 100f; - transform.Translate(Vector3.up * recognizer.deltaTranslation.y / scalingFactor); - - var clampedPos = Mathf.Clamp(transform.position.y, _listBottom, _listTop); - transform.position = new Vector2(transform.position.x, clampedPos); + ScrollBegin(recognizer.deltaTranslation.y); } - + private void OnPanComplete(TKPanRecognizer recognizer) { - if (!_scrollEnabled) { - return; - } - - _isPanning = false; - - // TODO: make configurable - var delta = recognizer.deltaTranslation.y; - var velocityMagnitude = Mathf.Abs(delta) < 5f ? 0f : Mathf.Clamp(delta, -50f, 50f); - - _panVelocity = Vector3.up * velocityMagnitude / VelocityScalingFactor; + ScrollEnd(); + } + public void OnScrollUp() + { + ScrollBegin(-1f * _scrollButtonScale); + ScrollEnd(); + } + public void OnScrollDown() + { + ScrollBegin(_scrollButtonScale); + ScrollEnd(); } - private static void OnLevelStateChanged(Level level, bool win) { Levels.SaveLevel(level, win); @@ -552,11 +541,45 @@ public void ToggleMusic() public void ToggleSfx() { _gameAudio.SfxEnabled = !_gameAudio.SfxEnabled; - } - + } public void ToggleFreeze() { _scrollEnabled = !_scrollEnabled; } + + private void ScrollBegin(float speed) + { + if (!_scrollEnabled){ + return; + } + + _isPanning = true; + _scrollSpeed = speed; + _panVelocity = Vector2.zero; + _magnetVelocity = Vector2.zero; + + const float scalingFactor = 100f; + + transform.Translate(Vector3.up * speed / scalingFactor); + + var clampedPos = Mathf.Clamp(transform.position.y, _listBottom, _listTop); + transform.position = new Vector2(transform.position.x, clampedPos); + } + + private void ScrollEnd() + { + if (!_scrollEnabled){ + return; + } + + _isPanning = false; + + // TODO: make configurable + var delta = _scrollSpeed; + var velocityMagnitude = Mathf.Abs(delta) < 5f ? 0f : Mathf.Clamp(delta, -50f, 50f); + + _panVelocity = Vector3.up * velocityMagnitude / VelocityScalingFactor; + } + } } diff --git a/Assets/Scripts/View/Items/ButtonScript.cs b/Assets/Scripts/View/Items/ButtonScript.cs index c3749a8..7128d8e 100644 --- a/Assets/Scripts/View/Items/ButtonScript.cs +++ b/Assets/Scripts/View/Items/ButtonScript.cs @@ -85,6 +85,8 @@ public enum ButtonType RestartLevel, Settings, MusicToggle, - SfxToggle + SfxToggle, + ScrollUp, + ScrollDown } } diff --git a/Assets/_Scenes/NodulusGame.unity b/Assets/_Scenes/NodulusGame.unity index c6b7526..b9a5727 100644 Binary files a/Assets/_Scenes/NodulusGame.unity and b/Assets/_Scenes/NodulusGame.unity differ