some additional fixes
This commit is contained in:
8
Assets/Darkmatter/Code/Features/ArtBook.meta
Normal file
8
Assets/Darkmatter/Code/Features/ArtBook.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d8eacd004e3e0649b6ff4a6b58c952c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "Features.Artbook",
|
||||
"rootNamespace": "Darkmatter.Features.Artbook",
|
||||
"references": [
|
||||
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
|
||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
|
||||
"GUID:b4c9f7fbf1e144933a1797dc208ece5f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd1597db9436d6f4da32f1391b905651
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Darkmatter/Code/Features/ArtBook/Installer.meta
Normal file
8
Assets/Darkmatter/Code/Features/ArtBook/Installer.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af74b0a63b3e4a746885f0e4b911cd91
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using Darkmatter.Libs.Installers;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
using VContainer.Unity;
|
||||
|
||||
namespace Darkmatter.Features.Artbook
|
||||
{
|
||||
public class ArtBookFeatureModule : MonoBehaviour, IModule
|
||||
{
|
||||
[SerializeField] private ArtbookView artbookView;
|
||||
|
||||
public void Register(IContainerBuilder builder)
|
||||
{
|
||||
if (artbookView != null) builder.RegisterEntryPoint<ArtbookPresenter>().WithParameter(artbookView);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e42bea53c6fa23c45a7c85e9b025bed7
|
||||
8
Assets/Darkmatter/Code/Features/ArtBook/UI.meta
Normal file
8
Assets/Darkmatter/Code/Features/ArtBook/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a13b92fe0335e04c8de0c5cbc54f6fb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using Darkmatter.Core;
|
||||
using Darkmatter.Libs.Observer;
|
||||
using UnityEngine;
|
||||
using VContainer.Unity;
|
||||
|
||||
namespace Darkmatter.Features.Artbook
|
||||
{
|
||||
public class ArtbookPresenter: IStartable
|
||||
{
|
||||
private readonly ArtbookView _view;
|
||||
private readonly IEventBus _eventBus;
|
||||
|
||||
public ArtbookPresenter(ArtbookView view, IEventBus eventBus)
|
||||
{
|
||||
_view = view;
|
||||
_eventBus = eventBus;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_view.OnBackButtonClicked += HandleBackButtonClicked;
|
||||
_view.OnColorbookButtonClicked += HandleColorbookButtonClicked;
|
||||
_eventBus.Subscribe<OpenArtBookSignal>(HandleOpenArtbookEvent);
|
||||
}
|
||||
|
||||
private void HandleOpenArtbookEvent(OpenArtBookSignal signal)
|
||||
{
|
||||
_view.Show();
|
||||
}
|
||||
|
||||
private void HandleBackButtonClicked()
|
||||
{
|
||||
_eventBus.Publish(new OpenColorBookSignal());
|
||||
_view.Hide();
|
||||
}
|
||||
|
||||
private void HandleColorbookButtonClicked()
|
||||
{
|
||||
_eventBus.Publish(new OpenColorBookSignal());
|
||||
_view.Hide();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_view.OnBackButtonClicked -= HandleBackButtonClicked;
|
||||
_view.OnColorbookButtonClicked -= HandleColorbookButtonClicked;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce45172769c70e044a56095bc9da281a
|
||||
32
Assets/Darkmatter/Code/Features/ArtBook/UI/ArtbookView.cs
Normal file
32
Assets/Darkmatter/Code/Features/ArtBook/UI/ArtbookView.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Darkmatter.Features.Artbook
|
||||
{
|
||||
public class ArtbookView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button backBtn;
|
||||
[SerializeField] private Button colorbookBtn;
|
||||
|
||||
public event Action OnBackButtonClicked;
|
||||
public event Action OnColorbookButtonClicked;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
backBtn.onClick.AddListener(() => OnBackButtonClicked?.Invoke());
|
||||
colorbookBtn.onClick.AddListener(() => OnColorbookButtonClicked?.Invoke());
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d635629f252db53479e66347a37c4f0b
|
||||
@@ -41,14 +41,6 @@ public sealed class DrawingCatalogController : IDrawingCatalogController
|
||||
{
|
||||
_bus.Publish(new DrawingSelectedSignal(id));
|
||||
}
|
||||
public void PublishBackBtnClickedSignal()
|
||||
{
|
||||
_bus.Publish(new BackBtnClickedSignal());
|
||||
}
|
||||
public void PublishOpenArtBookSignal()
|
||||
{
|
||||
_bus.Publish(new OpenArtBookSignal());
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
|
||||
@@ -2,43 +2,81 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Darkmatter.Core;
|
||||
using Darkmatter.Core.Contracts.Features.DrawingCatalog;
|
||||
using Darkmatter.Libs.Observer;
|
||||
using VContainer.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Features.DrawingCatalog
|
||||
{
|
||||
public class DrawingCatalogPresenter : IStartable, IDisposable
|
||||
{
|
||||
|
||||
private int _currentPage = 0;
|
||||
private int _totalPages = 1;
|
||||
private const int ItemPerPage = 8; //2 rows x 4 columns
|
||||
|
||||
private readonly DrawingCatalogView _view;
|
||||
private readonly IDrawingCatalogController _controller;
|
||||
private readonly IDrawingTemplateCatalog _catalog;
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
|
||||
public DrawingCatalogPresenter(DrawingCatalogView view, IDrawingCatalogController controller,
|
||||
IDrawingTemplateCatalog catalog)
|
||||
IDrawingTemplateCatalog catalog, IEventBus eventBus)
|
||||
{
|
||||
_view = view;
|
||||
_controller = controller;
|
||||
_catalog = catalog;
|
||||
_eventBus = eventBus;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_view.OnItemClicked += OnItemClicked;
|
||||
_view.OnBackClicked += OnBackBtnClicked;
|
||||
_view.OnArtBookClicked += OnArtBookBtnClicked;
|
||||
_view.OnLeftPageClicked += OnLeftPageBtnClicked;
|
||||
_view.OnRightPageClicked += OnRightPageBtnClicked;
|
||||
|
||||
_controller.ListChanged += OnListChanged;
|
||||
|
||||
_eventBus.Subscribe<OpenColorBookSignal>(HandleOpenColorBookSignal);
|
||||
}
|
||||
|
||||
private void HandleOpenColorBookSignal(OpenColorBookSignal signal)
|
||||
{
|
||||
_view.Show();
|
||||
}
|
||||
|
||||
private void OnRightPageBtnClicked()
|
||||
{
|
||||
if (_currentPage < _totalPages - 1)
|
||||
{
|
||||
_currentPage++;
|
||||
_view.SetPagination(_currentPage, _totalPages);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLeftPageBtnClicked()
|
||||
{
|
||||
if (_currentPage > 0)
|
||||
{
|
||||
_currentPage--;
|
||||
_view.SetPagination(_currentPage, _totalPages);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnArtBookBtnClicked()
|
||||
{
|
||||
_controller.PublishOpenArtBookSignal();
|
||||
_eventBus.Publish(new OpenArtBookSignal());
|
||||
_view.Hide();
|
||||
}
|
||||
|
||||
private void OnBackBtnClicked()
|
||||
{
|
||||
_controller.PublishBackBtnClickedSignal();
|
||||
_eventBus.Publish(new BackBtnClickedSignal());
|
||||
Debug.Log("Back button clicked in Drawing Catalog");
|
||||
}
|
||||
|
||||
private void OnItemClicked(string id) =>
|
||||
@@ -51,6 +89,10 @@ namespace Darkmatter.Features.DrawingCatalog
|
||||
{
|
||||
var ids = _controller.VisibleIds;
|
||||
var vms = new List<CatalogItemVM>(ids.Count);
|
||||
|
||||
_totalPages = (int)Math.Ceiling(ids.Count / (float)ItemPerPage);
|
||||
_currentPage = 0;
|
||||
|
||||
foreach (var id in ids)
|
||||
{
|
||||
if (ct.IsCancellationRequested) return;
|
||||
@@ -59,13 +101,20 @@ namespace Darkmatter.Features.DrawingCatalog
|
||||
}
|
||||
|
||||
if (ct.IsCancellationRequested) return;
|
||||
_view.ResetScrollPosition();
|
||||
_view.SetItems(vms);
|
||||
_view.SetPagination(_currentPage, _totalPages);
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_view.OnItemClicked -= OnItemClicked;
|
||||
_controller.ListChanged -= OnListChanged;
|
||||
_view.OnBackClicked -= OnBackBtnClicked;
|
||||
_view.OnArtBookClicked -= OnArtBookBtnClicked;
|
||||
_view.OnLeftPageClicked -= OnLeftPageBtnClicked;
|
||||
_view.OnRightPageClicked -= OnRightPageBtnClicked;
|
||||
_cts.Cancel();
|
||||
_cts.Dispose();
|
||||
}
|
||||
|
||||
@@ -12,21 +12,40 @@ namespace Darkmatter.Features.DrawingCatalog
|
||||
[SerializeField] private RectTransform content;
|
||||
[SerializeField] private DrawingCatalogButton buttonPrefab;
|
||||
|
||||
[Header("Buttons")]
|
||||
[Header("Header Buttons")]
|
||||
[SerializeField] private Button backButton;
|
||||
[SerializeField] private Button artBookButton;
|
||||
|
||||
[Header("Scroll Pagination")]
|
||||
[SerializeField] private ScrollRect scrollRect;
|
||||
[SerializeField] private Button leftPageButton;
|
||||
[SerializeField] private Button rightPageButton;
|
||||
private readonly List<DrawingCatalogButton> _buttons = new();
|
||||
|
||||
public event Action<string> OnItemClicked;
|
||||
public event Action OnBackClicked;
|
||||
public event Action OnArtBookClicked;
|
||||
public event Action OnLeftPageClicked;
|
||||
public event Action OnRightPageClicked;
|
||||
|
||||
private Coroutine _sliderCoroutine;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
backButton.onClick.AddListener(() => OnBackClicked?.Invoke());
|
||||
artBookButton.onClick.AddListener(() => OnArtBookClicked?.Invoke());
|
||||
leftPageButton.onClick.AddListener(() => OnLeftPageClicked?.Invoke());
|
||||
rightPageButton.onClick.AddListener(() => OnRightPageClicked?.Invoke());
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void SetItems(IReadOnlyList<CatalogItemVM> items)
|
||||
{
|
||||
while (_buttons.Count < items.Count)
|
||||
@@ -44,6 +63,45 @@ namespace Darkmatter.Features.DrawingCatalog
|
||||
_buttons.RemoveAt(_buttons.Count - 1);
|
||||
Destroy(last.gameObject);
|
||||
}
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(content);
|
||||
}
|
||||
|
||||
public void SetPagination(int currentPage, int totalPages)
|
||||
{
|
||||
leftPageButton.interactable = currentPage > 0;
|
||||
rightPageButton.interactable = currentPage < totalPages - 1;
|
||||
if (totalPages <= 1) return;
|
||||
|
||||
float pageWidth = scrollRect.viewport.rect.width;
|
||||
float maxScroll = content.rect.width - pageWidth;
|
||||
if (maxScroll <= 0f) return;
|
||||
|
||||
float targetPosition = Mathf.Clamp01(currentPage * pageWidth / maxScroll);
|
||||
|
||||
if (_sliderCoroutine != null)
|
||||
StopCoroutine(_sliderCoroutine);
|
||||
_sliderCoroutine = StartCoroutine(SmoothScrollTo(targetPosition));
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator SmoothScrollTo(float targetPosition)
|
||||
{
|
||||
const float duration = 0.3f;
|
||||
float elapsed = 0f;
|
||||
float startPosition = scrollRect.horizontalNormalizedPosition;
|
||||
while (elapsed < duration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
scrollRect.horizontalNormalizedPosition = Mathf.Lerp(startPosition, targetPosition, elapsed / duration);
|
||||
yield return null;
|
||||
}
|
||||
scrollRect.horizontalNormalizedPosition = targetPosition;
|
||||
}
|
||||
|
||||
|
||||
public void ResetScrollPosition()
|
||||
{
|
||||
scrollRect.horizontalNormalizedPosition = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user