PlantList
This commit is contained in:
1 parent
ba49ef5015
commit
7c207ef5b9
44 files changed
+2795
-1147
No files matched your search
@@ -12,14 +12,16 @@ namespace Code.Infrastructure.UI
|
||||
{
|
||||
public interface IUIFactory
|
||||
{
|
||||
UniTaskVoid LoadPanel(UIPanelType panelType);
|
||||
UniTaskVoid LoadPanel(UIPanelType panelType, Transform parent = null);
|
||||
void ReleasePanel(UIPanel panel);
|
||||
Canvas Canvas { get; }
|
||||
bool CheckIsMultiple(UIPanelType panelType);
|
||||
}
|
||||
|
||||
public class UIFactory : IDisposable, IUIFactory
|
||||
{
|
||||
private Dictionary<UIPanelType, UIPanelSettingsConfig> _configs;
|
||||
public bool CheckIsMultiple(UIPanelType panelType) => _configs[panelType].Multiple;
|
||||
private AssetReference _canvasConfigReference;
|
||||
private string _configsLabel;
|
||||
private EventBus.EventBus _eventBus;
|
||||
@@ -41,9 +43,9 @@ namespace Code.Infrastructure.UI
|
||||
LoadConfigs().Forget();
|
||||
}
|
||||
|
||||
public async UniTaskVoid LoadPanel(UIPanelType panelType)
|
||||
public async UniTaskVoid LoadPanel(UIPanelType panelType, Transform parent = null)
|
||||
{
|
||||
var panel = (await Addressables.InstantiateAsync(_configs[panelType].Prefab, _canvas.transform).ToUniTask())
|
||||
var panel = (await Addressables.InstantiateAsync(_configs[panelType].Prefab, parent ?? _canvas.transform).ToUniTask())
|
||||
.GetComponent<UIPanel>();
|
||||
|
||||
UnityEngine.Debug.LogWarning($"Panel loaded {panelType}");
|
||||
@@ -52,7 +54,7 @@ namespace Code.Infrastructure.UI
|
||||
|
||||
public void ReleasePanel(UIPanel panel)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Panel released {panel.gameObject.name}");
|
||||
Debug.LogWarning($"Panel released {panel.gameObject.name}");
|
||||
Addressables.ReleaseInstance(panel.gameObject);
|
||||
}
|
||||
|
||||
@@ -90,5 +92,6 @@ namespace Code.Infrastructure.UI
|
||||
public interface IUIPanelLoadedHandle : IGlobalSubscriber
|
||||
{
|
||||
void UIPanelLoaded(UIPanel panel, UIPanelType panelType);
|
||||
List<UIPanel> TryGetMultiplePanels(UIPanelType panelType);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace Code.Infrastructure.UI
|
||||
{
|
||||
[ToConfig] public AssetReference Prefab;
|
||||
[ToConfig] public UIPanelType UIPanelType;
|
||||
[ToConfig] public bool Multiple;
|
||||
}
|
||||
|
||||
[Config("Configs/UI/CanvasSettings")]
|
||||
|
||||
@@ -7,6 +7,9 @@ namespace Code.Infrastructure.UI
|
||||
Calendar,
|
||||
Tasks,
|
||||
Plants,
|
||||
PlantAdd
|
||||
PlantAdd,
|
||||
TaskAdd,
|
||||
PlantList,
|
||||
PlantAsList
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Reflex.Core;
|
||||
using Reflex.Extensions;
|
||||
using Reflex.Injectors;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Code.Infrastructure.UI
|
||||
@@ -12,15 +14,17 @@ namespace Code.Infrastructure.UI
|
||||
{
|
||||
void OpenPanel(UIPanelType uiPanelType);
|
||||
void ClosePanel(UIPanelType uiPanelType);
|
||||
void TryLoadPanel(UIPanelType uiPanelType);
|
||||
void TryLoadCreatePanel(UIPanelType uiPanelType, Transform parent = null);
|
||||
void TryRemovePanel(UIPanelType uiPanelType);
|
||||
void SetCanvasCamera(UnityEngine.Camera camera);
|
||||
UIPanel TryGetPanel(UIPanelType panelType);
|
||||
UIPanel TryGetSinglePanel(UIPanelType panelType);
|
||||
void TryRemovePanel(UIPanel panel, Action callback = null);
|
||||
}
|
||||
|
||||
public class UIService : IUIPanelLoadedHandle, IUIService
|
||||
{
|
||||
private Dictionary<UIPanelType, UIPanel> _loadedPanels = new();
|
||||
private Dictionary<UIPanelType, UIPanel> _loadedSinglePanels = new();
|
||||
private Dictionary<UIPanelType, List<UIPanel>> _loadedMultiplePanels = new();
|
||||
|
||||
private EventBus.EventBus _eventBus;
|
||||
private IUIFactory _factory;
|
||||
@@ -32,7 +36,7 @@ namespace Code.Infrastructure.UI
|
||||
eventBus.Subscribe(this);
|
||||
}
|
||||
|
||||
public void SetCanvasCamera(UnityEngine.Camera camera)
|
||||
public void SetCanvasCamera(Camera camera)
|
||||
{
|
||||
_factory.Canvas.worldCamera = camera;
|
||||
_factory.Canvas.planeDistance = 0.3f;
|
||||
@@ -40,49 +44,87 @@ namespace Code.Infrastructure.UI
|
||||
|
||||
public void OpenPanel(UIPanelType uiPanelType)
|
||||
{
|
||||
_loadedPanels[uiPanelType].gameObject.SetActive(true);
|
||||
_loadedPanels[uiPanelType].Open();
|
||||
_loadedSinglePanels[uiPanelType].gameObject.SetActive(true);
|
||||
_loadedSinglePanels[uiPanelType].Open();
|
||||
}
|
||||
|
||||
// TODO Close event
|
||||
public void ClosePanel(UIPanelType uiPanelType)
|
||||
{
|
||||
_loadedPanels[uiPanelType].Close(() => { _loadedPanels[uiPanelType].gameObject.SetActive(false); });
|
||||
_loadedSinglePanels[uiPanelType].Close(() =>
|
||||
{
|
||||
_loadedSinglePanels[uiPanelType].gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void TryLoadPanel(UIPanelType uiPanelType) => _factory.LoadPanel(uiPanelType);
|
||||
public void TryLoadCreatePanel(UIPanelType uiPanelType, Transform parent = null) => _factory.LoadPanel(uiPanelType, parent);
|
||||
|
||||
public void UIPanelLoaded(UIPanel panel, UIPanelType panelType)
|
||||
{
|
||||
_loadedPanels.Add(panelType, panel);
|
||||
if (!_factory.CheckIsMultiple(panelType))
|
||||
_loadedSinglePanels.Add(panelType, panel);
|
||||
else
|
||||
{
|
||||
if (!_loadedMultiplePanels.ContainsKey(panelType))
|
||||
_loadedMultiplePanels.Add(panelType, new List<UIPanel>());
|
||||
_loadedMultiplePanels[panelType].Add(panel);
|
||||
}
|
||||
|
||||
if (panel.InjectMeSenpai)
|
||||
GameObjectInjector.InjectRecursive(panel.gameObject, Container.RootContainer);
|
||||
// GameObjectInjector.InjectRecursive(panel.gameObject, SceneManager.GetActiveScene().GetSceneContainer()); // Скорее всего будут нужны компоненты текущей сцены
|
||||
|
||||
_eventBus.RaiseEvent<IUIPanelLoaded>(ui => ui.UILoaded(panelType));
|
||||
if (!_factory.CheckIsMultiple(panelType)) _eventBus.RaiseEvent<IUIPanelLoaded>(ui => ui.UISinglePanelLoaded(panelType));
|
||||
else _eventBus.RaiseEvent<IUIPanelLoaded>(ui => ui.UIMultiplePanelLoaded(panelType, panel));
|
||||
}
|
||||
|
||||
public void TryRemovePanel(UIPanelType uiPanelType)
|
||||
{
|
||||
_loadedPanels[uiPanelType].Close(() =>
|
||||
_loadedSinglePanels[uiPanelType].Close(() =>
|
||||
{
|
||||
_loadedPanels[uiPanelType].gameObject.SetActive(false);
|
||||
_loadedSinglePanels[uiPanelType].gameObject.SetActive(false);
|
||||
RemovePanel(uiPanelType);
|
||||
});
|
||||
}
|
||||
public void TryRemovePanel(UIPanel panel, Action callback = null)
|
||||
{
|
||||
panel.Close(() =>
|
||||
{
|
||||
panel.gameObject.SetActive(false);
|
||||
RemovePanel(panel);
|
||||
callback?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
private void RemovePanel(UIPanelType panelType)
|
||||
{
|
||||
_factory.ReleasePanel(_loadedPanels[panelType]);
|
||||
_loadedPanels.Remove(panelType);
|
||||
if (!_factory.CheckIsMultiple(panelType))
|
||||
{
|
||||
_factory.ReleasePanel(_loadedSinglePanels[panelType]);
|
||||
|
||||
_loadedSinglePanels.Remove(panelType);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var panel in _loadedMultiplePanels[panelType])
|
||||
_factory.ReleasePanel(panel);
|
||||
|
||||
_loadedMultiplePanels.Remove(panelType);
|
||||
}
|
||||
}
|
||||
|
||||
public UIPanel TryGetPanel(UIPanelType panelType) => _loadedPanels.GetValueOrDefault(panelType);
|
||||
private void RemovePanel(UIPanel panel)
|
||||
{
|
||||
_factory.ReleasePanel(panel);
|
||||
}
|
||||
|
||||
public UIPanel TryGetSinglePanel(UIPanelType panelType) => _loadedSinglePanels.GetValueOrDefault(panelType);
|
||||
public List<UIPanel> TryGetMultiplePanels(UIPanelType panelType) => _loadedMultiplePanels.GetValueOrDefault(panelType);
|
||||
}
|
||||
|
||||
public interface IUIPanelLoaded : IGlobalSubscriber
|
||||
{
|
||||
void UILoaded(UIPanelType uiPanelType);
|
||||
void UISinglePanelLoaded(UIPanelType uiPanelType);
|
||||
void UIMultiplePanelLoaded(UIPanelType uiPanelType, UIPanel panel);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user