Skip to content

Problem with the menu #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Assets/Scripts/View/Control/NavigationScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
99 changes: 61 additions & 38 deletions Assets/Scripts/View/Control/ScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ namespace View.Control
/// </summary>
public class ScrollView : MonoBehaviour
{
public GameObject PuzzleGamePrefab;
[SerializeField]
private float _scrollButtonScale;

[SerializeField]
private GameObject _puzzleGamePrefab;

private bool _scrollEnabled;

Expand All @@ -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;

Expand All @@ -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<NavigationScript>();
_moveDisplay = GameObject.FindGameObjectWithTag("MoveDisplay").GetComponent<MoveDisplay>();
_gameAudio = GameObject.FindGameObjectWithTag("GameAudio").GetComponent<GameAudio>();
// Set the maximum number of simultaneous tweens
LeanTween.init(30000);

// Set the game's strings to their localized versions
var language = Levels.CurrentLanguage;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

}
}
4 changes: 3 additions & 1 deletion Assets/Scripts/View/Items/ButtonScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public enum ButtonType
RestartLevel,
Settings,
MusicToggle,
SfxToggle
SfxToggle,
ScrollUp,
ScrollDown
}
}
Binary file modified Assets/_Scenes/NodulusGame.unity
Binary file not shown.