Artt book tweaks

This commit is contained in:
Savya Bikram Shah
2026-05-29 18:20:25 +05:45
parent 931515193a
commit 676b389244
20 changed files with 3667 additions and 3168 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f69d14fcc0bdd4b93aeb1717d030a9ca
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
namespace Darkmatter.Core.Data.Signals.Features.Capture
{
public record struct GallerySaveCompletedSignal(bool Success);
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 04fbdae933fab4011879c232a1041042

View File

@@ -0,0 +1,4 @@
namespace Darkmatter.Core.Data.Signals.Features.Capture
{
public record struct GallerySaveStartedSignal;
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: cff479845a55e4dd0a6d66043c91f661

View File

@@ -1,6 +1,7 @@
using System;
using UnityEngine;
namespace Darkmatter.Core
{
public record struct OpenArtBookSignal;
}
public record struct OpenArtBookSignal(Action OnClose);
}

View File

@@ -26,7 +26,7 @@ namespace Darkmatter.Features.Artbook
private readonly List<ArtbookEntry> _entries = new();
private readonly List<Sprite> _ownedSprites = new();
private readonly List<Texture2D> _ownedTextures = new();
private Action _onClose;
private CancellationTokenSource _cts;
private IDisposable _openSubscription;
private int _currentSpread;
@@ -60,10 +60,12 @@ namespace Darkmatter.Features.Artbook
private void HandleOpenArtbookEvent(OpenArtBookSignal signal)
{
_onClose = null;
_view.Show();
_cts?.Cancel();
_cts?.Dispose();
_cts = new CancellationTokenSource();
_onClose = signal.OnClose;
LoadAndShowAsync(_cts.Token).Forget();
}
@@ -164,7 +166,7 @@ namespace Darkmatter.Features.Artbook
private void HandleBackButtonClicked()
{
_eventBus.Publish(new OpenColorBookSignal());
_onClose?.Invoke();
_view.Hide();
}
@@ -198,4 +200,4 @@ namespace Darkmatter.Features.Artbook
ClearOwnedAssets();
}
}
}
}

View File

@@ -4,6 +4,7 @@
"references": [
"GUID:6a0a834eb41764f12ba55c3fb04a40cb",
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
"GUID:b4c9f7fbf1e144933a1797dc208ece5f",
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],

View File

@@ -11,6 +11,7 @@ namespace Darkmatter.Features.Capture
{
[SerializeField, Range(0.1f, 2f)] private float captureScale = 1f;
[SerializeField] private CaptureButtonView captureButtonView;
[SerializeField] private GallerySaveView gallerySaveView;
public void Register(IContainerBuilder builder)
{
@@ -19,6 +20,9 @@ namespace Darkmatter.Features.Capture
if (captureButtonView != null)
builder.RegisterEntryPoint<CaptureButtonPresenter>().WithParameter(captureButtonView);
if (gallerySaveView != null)
builder.RegisterEntryPoint<GallerySavePresenter>().WithParameter(gallerySaveView);
}
}
}

View File

@@ -5,6 +5,8 @@ using Darkmatter.Core.Contracts.Features.Capture;
using Darkmatter.Core.Contracts.Features.GameplayFlow;
using Darkmatter.Core.Contracts.Services.Capture;
using Darkmatter.Core.Contracts.Services.Gallery;
using Darkmatter.Core.Data.Signals.Features.Capture;
using Darkmatter.Libs.Observer;
using UnityEngine;
namespace Darkmatter.Features.Capture
@@ -14,17 +16,20 @@ namespace Darkmatter.Features.Capture
private readonly ICaptureService _captureService;
private readonly IGalleryService _galleryService;
private readonly IGameplaySceneRefs _refs;
private readonly IEventBus _bus;
private readonly CaptureConfig _config;
public CaptureSystem(
ICaptureService captureService,
IGalleryService galleryService,
IGameplaySceneRefs refs,
IEventBus bus,
CaptureConfig config)
{
_captureService = captureService;
_galleryService = galleryService;
_refs = refs;
_bus = bus;
_config = config;
}
@@ -34,15 +39,21 @@ namespace Darkmatter.Features.Capture
if (!saveToGallery || png == null || png.Length == 0) return png;
var tex = new Texture2D(2, 2, TextureFormat.RGBA32, mipChain: false);
var success = false;
try
{
if (tex.LoadImage(png))
{
_bus.Publish(new GallerySaveStartedSignal());
await _galleryService.SaveImageAsync(tex,
$"colorbook_{DateTime.UtcNow:yyyyMMdd_HHmmss}.png", ct);
success = true;
}
}
finally
{
UnityEngine.Object.Destroy(tex);
_bus.Publish(new GallerySaveCompletedSignal(success));
}
return png;
}

View File

@@ -0,0 +1,71 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using Darkmatter.Core.Data.Signals.Features.Capture;
using Darkmatter.Libs.Observer;
using VContainer.Unity;
namespace Darkmatter.Features.Capture.UI
{
public class GallerySavePresenter : IStartable, IDisposable
{
private readonly GallerySaveView _view;
private readonly IEventBus _bus;
private IDisposable _startedSub;
private IDisposable _completedSub;
private CancellationTokenSource _popupCts;
public GallerySavePresenter(GallerySaveView view, IEventBus bus)
{
_view = view;
_bus = bus;
}
public void Start()
{
_startedSub = _bus.Subscribe<GallerySaveStartedSignal>(OnStarted);
_completedSub = _bus.Subscribe<GallerySaveCompletedSignal>(OnCompleted);
}
private void OnStarted(GallerySaveStartedSignal _)
{
CancelPopup();
_view.ShowSaving();
}
private void OnCompleted(GallerySaveCompletedSignal signal)
{
_view.HideSaving();
if (!signal.Success) return;
CancelPopup();
_popupCts = new CancellationTokenSource();
ShowPopupAsync(_popupCts.Token).Forget();
}
private async UniTaskVoid ShowPopupAsync(CancellationToken ct)
{
_view.ShowSuccess();
try
{
await UniTask.Delay(TimeSpan.FromSeconds(_view.PopupAutoHideSeconds), cancellationToken: ct);
}
catch (OperationCanceledException) { return; }
_view.HideSuccess();
}
private void CancelPopup()
{
_popupCts?.Cancel();
_popupCts?.Dispose();
_popupCts = null;
}
public void Dispose()
{
_startedSub?.Dispose();
_completedSub?.Dispose();
CancelPopup();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 71d8cccc7b3a3436ba83ca3683fbea9f

View File

@@ -0,0 +1,40 @@
using UnityEngine;
namespace Darkmatter.Features.Capture.UI
{
public class GallerySaveView : MonoBehaviour
{
[SerializeField] private GameObject savingIndicator;
[SerializeField] private GameObject successPopup;
[SerializeField, Min(0f)] private float popupAutoHideSeconds = 1.5f;
public float PopupAutoHideSeconds => popupAutoHideSeconds;
private void Awake()
{
if (savingIndicator != null) savingIndicator.SetActive(false);
if (successPopup != null) successPopup.SetActive(false);
}
public void ShowSaving()
{
if (savingIndicator != null) savingIndicator.SetActive(true);
if (successPopup != null) successPopup.SetActive(false);
}
public void HideSaving()
{
if (savingIndicator != null) savingIndicator.SetActive(false);
}
public void ShowSuccess()
{
if (successPopup != null) successPopup.SetActive(true);
}
public void HideSuccess()
{
if (successPopup != null) successPopup.SetActive(false);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bbcc5a579d90f4763a781379f5213d6e

View File

@@ -70,7 +70,7 @@ namespace Darkmatter.Features.DrawingCatalog
private void OnArtBookBtnClicked()
{
_eventBus.Publish(new OpenArtBookSignal());
_eventBus.Publish(new OpenArtBookSignal(()=> _view.Show()));
_view.Hide();
}