PlantList

This commit is contained in:
ThomasCharester committed 2026-03-05 11:27:10 +03:00
1 parent ba49ef5015
commit 7c207ef5b9
44 files changed
+2795 -1147

No files matched your search

@@ -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