PlantList
This commit is contained in:
1 parent
ba49ef5015
commit
7c207ef5b9
44 files changed
+2795
-1147
No files matched your search
@@ -1,18 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace Code.Calendar.Constants
|
||||
{
|
||||
// Написать кодрайтер, который будет находить конфиги и добавлять их сюда пока написано само
|
||||
public class ConstantImagesService
|
||||
public interface IConstantImagesService
|
||||
{
|
||||
UniTaskVoid LoadImage(ConstantImageType imageType, Action<Sprite> callback);
|
||||
void ReleaseImage(ConstantImageType imageType);
|
||||
}
|
||||
|
||||
public class ConstantImagesService : IConstantImagesService
|
||||
{
|
||||
private readonly EventBus _eventBus;
|
||||
|
||||
public List<ConstantImageConfig> Configs { get; private set; }
|
||||
public Dictionary<ConstantImageType, ConstantImageConfig> Configs { get; private set; }
|
||||
|
||||
public ConstantImagesService(EventBus eventBus, IConfigLocator configLocator)
|
||||
{
|
||||
@@ -20,10 +29,10 @@ namespace Code.Calendar.Constants
|
||||
|
||||
var label = configLocator.TryGetManyConfigAssetReferences<ConstantImageConfig>();
|
||||
|
||||
LoadImage(label).Forget();
|
||||
LoadImages(label).Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid LoadImage(string imagesLabel)
|
||||
private async UniTaskVoid LoadImages(string imagesLabel)
|
||||
{
|
||||
if ((await Addressables.LoadResourceLocationsAsync(imagesLabel).Task).Count != 0)
|
||||
{
|
||||
@@ -32,13 +41,29 @@ namespace Code.Calendar.Constants
|
||||
|
||||
await images.ToUniTask();
|
||||
|
||||
Configs = images.Result.ToList();
|
||||
Configs = images.Result.ToDictionary(x=> x.imageType);
|
||||
}
|
||||
|
||||
_eventBus.RaiseEvent<IConstantImagesServiceHandle>(x=> x.ImagesLoaded());
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<ConstantImageType, AsyncOperationHandle<Sprite>> _spritesHandles = new();
|
||||
public async UniTaskVoid LoadImage(ConstantImageType imageType, Action<Sprite> callback)
|
||||
{
|
||||
if(!_spritesHandles.ContainsKey(imageType))
|
||||
_spritesHandles.Add(imageType, Addressables.LoadAssetAsync<Sprite>(Configs[imageType].image));
|
||||
|
||||
await _spritesHandles[imageType].ToUniTask();
|
||||
|
||||
callback?.Invoke(_spritesHandles[imageType].Result);
|
||||
}
|
||||
|
||||
public void ReleaseImage(ConstantImageType imageType)
|
||||
{
|
||||
_spritesHandles[imageType].Release();
|
||||
_spritesHandles.Remove(imageType);
|
||||
}
|
||||
}
|
||||
public interface IConstantImagesServiceHandle : IGlobalSubscriber
|
||||
{
|
||||
void ImagesLoaded();
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Code.Calendar.DataStructures
|
||||
public bool Active;
|
||||
|
||||
public string Description;
|
||||
public DateTime Date;
|
||||
public DateTime Date; // Если периодичная, то дата первого мероприятия
|
||||
|
||||
public bool IsPeriodic;
|
||||
public int PeriodicInterval;
|
||||
|
||||
@@ -28,11 +28,18 @@ namespace Code.Calendar.DataStructures
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
|
||||
LoadJsonTasks().Forget();
|
||||
LoadJsonPlants().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid LoadJsonTasks()
|
||||
private async UniTaskVoid LoadJsonPlants()
|
||||
{
|
||||
if (_inAction)
|
||||
{
|
||||
_reUseLoadRequest = true;
|
||||
return;
|
||||
}
|
||||
_inAction = true;
|
||||
|
||||
var path = Path.Combine(Application.persistentDataPath, "Plants.json");
|
||||
|
||||
if (File.Exists(path))
|
||||
@@ -46,16 +53,19 @@ namespace Code.Calendar.DataStructures
|
||||
await using (File.Create(path)) { }
|
||||
}
|
||||
|
||||
_eventBus.RaiseEvent<IPlantsServiceInitHandle>(x=> x.PlantsLoaded());
|
||||
_inAction = false;
|
||||
|
||||
if(!_reUseLoadRequest) _eventBus.RaiseEvent<IPlantsServiceInitHandle>(x=> x.PlantsLoaded());
|
||||
else LoadJsonPlants().Forget();
|
||||
}
|
||||
|
||||
private bool _inAction, _reUseRequest;
|
||||
private bool _inAction, _reUseSaveRequest, _reUseLoadRequest;
|
||||
|
||||
private async UniTaskVoid SaveJsonTasks()
|
||||
private async UniTaskVoid SaveJsonPlants()
|
||||
{
|
||||
if (_inAction)
|
||||
{
|
||||
_reUseRequest = true;
|
||||
_reUseSaveRequest = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -69,8 +79,8 @@ namespace Code.Calendar.DataStructures
|
||||
|
||||
_inAction = false;
|
||||
|
||||
if(!_reUseRequest) _eventBus.RaiseEvent<IPlantsServiceInitHandle>(x=> x.PlantsSaved());
|
||||
else SaveJsonTasks().Forget();
|
||||
if(!_reUseSaveRequest) _eventBus.RaiseEvent<IPlantsServiceInitHandle>(x=> x.PlantsSaved());
|
||||
else SaveJsonPlants().Forget();
|
||||
}
|
||||
|
||||
public void AddPlant(Plant plant)
|
||||
@@ -79,20 +89,20 @@ namespace Code.Calendar.DataStructures
|
||||
|
||||
_plants.Add(plant);
|
||||
|
||||
SaveJsonTasks().Forget();
|
||||
SaveJsonPlants().Forget();
|
||||
}
|
||||
|
||||
public void EditPlant(Guid guid, Plant newPlant)
|
||||
{
|
||||
_plants[_plants.FindIndex(x => x.Id == guid)] = newPlant;
|
||||
|
||||
SaveJsonTasks().Forget();
|
||||
SaveJsonPlants().Forget();
|
||||
}
|
||||
public void DeletePlant(Plant plant)
|
||||
{
|
||||
_plants.Remove(plant);
|
||||
|
||||
SaveJsonTasks().Forget();
|
||||
SaveJsonPlants().Forget();
|
||||
}
|
||||
|
||||
public Plant GetPlant(Guid plantId) => _plants.FirstOrDefault(x => x.Id == plantId);
|
||||
@@ -100,7 +110,7 @@ namespace Code.Calendar.DataStructures
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
SaveJsonTasks().Forget();
|
||||
SaveJsonPlants().Forget();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ namespace Code.Calendar.DataStructures
|
||||
|
||||
public void AddTask(Task task)
|
||||
{
|
||||
_tasks.Add(task);
|
||||
|
||||
task.Id = Guid.NewGuid();
|
||||
|
||||
_tasks.Add(task);
|
||||
|
||||
SaveJsonTasks().Forget();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8d3a5935f1c497bb56de2d94ef01cdd
|
||||
timeCreated: 1772468475
|
||||
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class SelectedDate {
|
||||
public static System.DateTime date = System.DateTime.Now;
|
||||
}
|
||||
public class DateCallback : AndroidJavaProxy
|
||||
{
|
||||
public DateCallback() : base("android.app.DatePickerDialog$OnDateSetListener") { }
|
||||
|
||||
public void onDateSet(AndroidJavaObject view, int year, int monthOfYear, int dayOfMonth) {
|
||||
SelectedDate.date = new System.DateTime(year, monthOfYear + 1, dayOfMonth);
|
||||
}
|
||||
}
|
||||
public class ExampleClass : MonoBehaviour
|
||||
{
|
||||
private AndroidJavaObject activity;
|
||||
|
||||
void PickDate(){
|
||||
new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(), SelectedDate.date.Year, SelectedDate.date.Month - 1, SelectedDate.date.Day).Call("show");
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
if (GUI.Button(new Rect(10, 10, 450, 100), System.String.Format("{0:yyyy-MM-dd}", SelectedDate.date)))
|
||||
{
|
||||
activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
|
||||
activity.Call("runOnUiThread", new AndroidJavaRunnable(PickDate));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcb51e6febb24b66870aad7e44df62e0
|
||||
timeCreated: 1772468482
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8cc1a025b3f422bb7187c11271c961f
|
||||
timeCreated: 1772560436
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Calendar.OtherUIElements
|
||||
{
|
||||
public class AddPlantButton : MonoBehaviour
|
||||
{
|
||||
public void OpenAddPlant()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67f6127a30aa48ea8157228ad37df8a6
|
||||
timeCreated: 1772560454
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Code.Calendar.Constants;
|
||||
using Code.Calendar.DataStructures;
|
||||
using Code.Infrastructure.UI;
|
||||
using Reflex.Attributes;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Code.Calendar.Panels
|
||||
{
|
||||
public class PlantAsListElement : UIPanel
|
||||
{
|
||||
[Inject] private IConstantImagesService _constantImagesService;
|
||||
[SerializeField] private Image image;
|
||||
[SerializeField] private TMP_Text plantName;
|
||||
public Guid PlantId { get; private set; }
|
||||
|
||||
public void SetPlant(Plant plant)
|
||||
{
|
||||
PlantId = plant.Id;
|
||||
plantName.text = plant.Name;
|
||||
_constantImagesService.LoadImage(ConstantImageType.NoPhoto,SetImage);
|
||||
}
|
||||
private void SetImage(Sprite sprite) => image.sprite = sprite;
|
||||
public override void Open(Action callback = null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65c40e2bdcb14b3ea164b84b80809b25
|
||||
timeCreated: 1772547821
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Code.Calendar.DataStructures;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Code.Infrastructure.Loadings;
|
||||
using Code.Infrastructure.UI;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Calendar.Panels
|
||||
{
|
||||
public class PlantsListPanel : UIPanel, IUIPanelLoaded
|
||||
{
|
||||
[SerializeField] private Transform contentParent;
|
||||
|
||||
private IPlantService _plantService;
|
||||
private IUIService _uiService;
|
||||
|
||||
private EventBus _eventBus;
|
||||
|
||||
private List<PlantAsListElement> _plantsPanels = new();
|
||||
private Stack<Plant> _plantsToCreate;
|
||||
|
||||
[Inject]
|
||||
private void Construct(EventBus eventBus, IPlantService plantService, IUIService uiService)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_plantService = plantService;
|
||||
_uiService = uiService;
|
||||
|
||||
eventBus.Subscribe(this);
|
||||
}
|
||||
|
||||
public override void Open(Action callback = null)
|
||||
{
|
||||
_plantsToCreate = new(_plantService.GetPlants());
|
||||
|
||||
for (var i = _plantsToCreate.Count; i > 0 ; i--) _uiService.TryLoadCreatePanel(UIPanelType.PlantAsList, contentParent);
|
||||
|
||||
callback?.Invoke();
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
{
|
||||
ClearPlants(callback);
|
||||
}
|
||||
|
||||
private Loading _panelClosureLoading;
|
||||
private void ClearPlants(Action callback = null)
|
||||
{
|
||||
if(_panelClosureLoading != null)
|
||||
_panelClosureLoading = new(_plantsPanels.Count + _panelClosureLoading.CurrentProgress, callback);
|
||||
else
|
||||
_panelClosureLoading = new(_plantsPanels.Count, callback);
|
||||
|
||||
foreach (var plantPanel in _plantsPanels) _uiService.TryRemovePanel(plantPanel);
|
||||
}
|
||||
|
||||
public void UISinglePanelLoaded(UIPanelType uiPanelType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void UIMultiplePanelLoaded(UIPanelType uiPanelType, UIPanel panel)
|
||||
{
|
||||
if (uiPanelType != UIPanelType.PlantAsList) return;
|
||||
|
||||
_plantsPanels.Add((PlantAsListElement)panel);
|
||||
((PlantAsListElement)panel).SetPlant(_plantsToCreate.Pop());
|
||||
if(_plantsToCreate.Count == 0) PlantPanelsLoaded();
|
||||
}
|
||||
|
||||
private void PlantPanelsLoaded()
|
||||
{
|
||||
foreach (var panel in _plantsPanels)
|
||||
{
|
||||
panel.Open();
|
||||
}
|
||||
Debug.LogWarning("PlantPanelsLoaded");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddc4b25ae5854a83ae0a1ba7f8dffb7d
|
||||
timeCreated: 1772547586
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using Code.Calendar.DataStructures;
|
||||
using Code.Infrastructure.UI;
|
||||
using PrimeTween;
|
||||
using Reflex.Attributes;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Code.Calendar.Panels
|
||||
{
|
||||
public class TaskAddPanel : UIPanel
|
||||
{
|
||||
[Inject] private ITaskService _taskService;
|
||||
[SerializeField] private TMP_InputField taskName;
|
||||
[SerializeField] private Toggle isPeriodic;
|
||||
|
||||
public void TryAddPlant()
|
||||
{
|
||||
Task newTask = new()
|
||||
{
|
||||
Active = true,
|
||||
IsPeriodic = isPeriodic.isOn,
|
||||
PeriodicInterval = 0,
|
||||
};
|
||||
_taskService.AddTask(newTask);
|
||||
}
|
||||
|
||||
public override void Open(Action callback = null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
// Tween.Alpha(image, 1f, 1f).OnComplete(target: this, _ => callback?.Invoke());
|
||||
}
|
||||
|
||||
public override void Close(Action callback = null)
|
||||
{
|
||||
callback?.Invoke();
|
||||
// Tween.Alpha(image, 0f, 1f).OnComplete(target: this, _ => callback?.Invoke());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd466bce2a8b41bbab38fd3ede5b7c35
|
||||
timeCreated: 1772467428
|
||||
Reference in new issue
Block a user