Merge remote-tracking branch 'origin/work_branch' into savya

# Conflicts:
#	Assets/Darkmatter/Scenes/Colorbook.unity
This commit is contained in:
Savya Bikram Shah
2026-06-01 14:10:04 +05:45
207 changed files with 13770 additions and 269 deletions

View File

@@ -8,6 +8,10 @@ namespace Darkmatter.Core.Enums.Services.Audio
ShapeReturn = 102,
UiTap = 200,
PlayButtonTap = 201,
ColorSelection = 202,
LevelComplete = 300,
FireWorkLaunch = 400,
}
}

View File

@@ -6,7 +6,8 @@
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:b4c9f7fbf1e144933a1797dc208ece5f",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:6055be8ebefd69e48b49212b09b47b2f"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -39,6 +39,8 @@ namespace Darkmatter.Features.DrawingCatalog
_view.OnArtBookClicked += OnArtBookBtnClicked;
_view.OnLeftPageClicked += OnLeftPageBtnClicked;
_view.OnRightPageClicked += OnRightPageBtnClicked;
_view.OnPageChangedByScroll += OnPageChangedByScroll;
_view.OnPageNumberClicked += OnPageNumberClicked;
_controller.ListChanged += OnListChanged;
@@ -68,6 +70,18 @@ namespace Darkmatter.Features.DrawingCatalog
}
}
private void OnPageChangedByScroll(int page)
{
_currentPage = page;
}
private void OnPageNumberClicked(int page)
{
if (page < 0 || page >= _totalPages || page == _currentPage) return;
_currentPage = page;
_view.SetPagination(_currentPage, _totalPages);
}
private void OnArtBookBtnClicked()
{
_eventBus.Publish(new OpenArtBookSignal(()=> _view.Show()));
@@ -116,6 +130,8 @@ namespace Darkmatter.Features.DrawingCatalog
_view.OnArtBookClicked -= OnArtBookBtnClicked;
_view.OnLeftPageClicked -= OnLeftPageBtnClicked;
_view.OnRightPageClicked -= OnRightPageBtnClicked;
_view.OnPageChangedByScroll -= OnPageChangedByScroll;
_view.OnPageNumberClicked -= OnPageNumberClicked;
_openSubscription?.Dispose();
_cts.Cancel();
_cts.Dispose();

View File

@@ -20,15 +20,25 @@ namespace Darkmatter.Features.DrawingCatalog
[SerializeField] private ScrollRect scrollRect;
[SerializeField] private Button leftPageButton;
[SerializeField] private Button rightPageButton;
[Header("Page Numbers")]
[SerializeField] private RectTransform pageNumberContainer;
[SerializeField] private PageNumberButton pageNumberPrefab;
private readonly List<DrawingCatalogButton> _buttons = new();
private readonly List<PageNumberButton> _pageButtons = new();
public event Action<string> OnItemClicked;
public event Action OnBackClicked;
public event Action OnArtBookClicked;
public event Action OnLeftPageClicked;
public event Action OnRightPageClicked;
public event Action<int> OnPageChangedByScroll;
public event Action<int> OnPageNumberClicked;
private Coroutine _sliderCoroutine;
private int _currentPage;
private int _totalPages = 1;
private bool _suppressScrollEvents;
public void Start()
{
@@ -36,6 +46,7 @@ namespace Darkmatter.Features.DrawingCatalog
artBookButton.onClick.AddListener(() => OnArtBookClicked?.Invoke());
leftPageButton.onClick.AddListener(() => OnLeftPageClicked?.Invoke());
rightPageButton.onClick.AddListener(() => OnRightPageClicked?.Invoke());
scrollRect.onValueChanged.AddListener(OnScrollValueChanged);
}
public void Show()
{
@@ -69,8 +80,11 @@ namespace Darkmatter.Features.DrawingCatalog
public void SetPagination(int currentPage, int totalPages)
{
leftPageButton.interactable = currentPage > 0;
rightPageButton.interactable = currentPage < totalPages - 1;
_currentPage = currentPage;
_totalPages = totalPages;
BuildPageNumbers(totalPages);
UpdateArrowButtons();
UpdateActivePageNumber();
if (totalPages <= 1) return;
float pageWidth = scrollRect.viewport.rect.width;
@@ -84,8 +98,65 @@ namespace Darkmatter.Features.DrawingCatalog
_sliderCoroutine = StartCoroutine(SmoothScrollTo(targetPosition));
}
// Keeps the arrow buttons (and the presenter) in sync when the user scrolls manually.
private void OnScrollValueChanged(Vector2 _)
{
if (_suppressScrollEvents || _totalPages <= 1) return;
int page = PageFromScrollPosition();
if (page == _currentPage) return;
_currentPage = page;
UpdateArrowButtons();
UpdateActivePageNumber();
OnPageChangedByScroll?.Invoke(page);
}
private void BuildPageNumbers(int totalPages)
{
if (pageNumberPrefab == null || pageNumberContainer == null) return;
while (_pageButtons.Count < totalPages)
{
var button = Instantiate(pageNumberPrefab, pageNumberContainer);
int pageIndex = _pageButtons.Count;
button.Initialize(pageIndex, () => OnPageNumberClicked?.Invoke(pageIndex));
_pageButtons.Add(button);
}
while (_pageButtons.Count > totalPages)
{
var last = _pageButtons[^1];
_pageButtons.RemoveAt(_pageButtons.Count - 1);
Destroy(last.gameObject);
}
}
private void UpdateActivePageNumber()
{
for (int i = 0; i < _pageButtons.Count; i++)
_pageButtons[i].SetHighlighted(i == _currentPage);
}
private int PageFromScrollPosition()
{
float pageWidth = scrollRect.viewport.rect.width;
float maxScroll = content.rect.width - pageWidth;
if (maxScroll <= 0f) return 0;
int page = Mathf.RoundToInt(scrollRect.horizontalNormalizedPosition * maxScroll / pageWidth);
return Mathf.Clamp(page, 0, _totalPages - 1);
}
private void UpdateArrowButtons()
{
leftPageButton.interactable = _currentPage > 0;
rightPageButton.interactable = _currentPage < _totalPages - 1;
}
private System.Collections.IEnumerator SmoothScrollTo(float targetPosition)
{
_suppressScrollEvents = true;
const float duration = 0.3f;
float elapsed = 0f;
float startPosition = scrollRect.horizontalNormalizedPosition;
@@ -96,12 +167,15 @@ namespace Darkmatter.Features.DrawingCatalog
yield return null;
}
scrollRect.horizontalNormalizedPosition = targetPosition;
_suppressScrollEvents = false;
}
public void ResetScrollPosition()
{
_suppressScrollEvents = true;
scrollRect.horizontalNormalizedPosition = 0f;
_suppressScrollEvents = false;
}
}
}

View File

@@ -0,0 +1,47 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Darkmatter.Features.DrawingCatalog
{
public class PageNumberButton : MonoBehaviour
{
[SerializeField] private TMP_Text label;
[SerializeField] private Button button;
[Header("Highlight")]
[Tooltip("Image faded for unselected pages. Use the button's color block (below) to match the disabled look.")]
[SerializeField] private Image image;
[Tooltip("When on, unselected pages use the button's Disabled Color and selected use Normal Color. " +
"When off, only the alpha below is applied.")]
[SerializeField] private bool useButtonColors = true;
[Range(0f, 1f)]
[SerializeField] private float unselectedAlpha = 0.5f;
public int PageIndex { get; private set; }
public void Initialize(int pageIndex, UnityEngine.Events.UnityAction onClick)
{
PageIndex = pageIndex;
if (label != null) label.text = (pageIndex + 1).ToString();
button.onClick.RemoveAllListeners();
button.onClick.AddListener(onClick);
}
public void SetHighlighted(bool isActive)
{
if (image == null) return;
if (useButtonColors)
{
var colors = button.colors;
image.color = isActive ? colors.normalColor : colors.disabledColor;
return;
}
var c = image.color;
c.a = isActive ? 1f : unselectedAlpha;
image.color = c;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 19495f2daba89ce44abe376a40ca313d

View File

@@ -131,6 +131,7 @@ namespace Darkmatter.Features.GameplayFlow.Systems
{
await SaveCurrentAsync(ct);
_refs.Confetti.Play();
_sfx.Play(SfxId.FireWorkLaunch);
_sfx.Play(SfxId.LevelComplete);
await _coloring.PlayCompletionAnimationAsync(ct);
_progression.MarkCompleted(_templateId);