2025-07-21 07:53:39 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace DDD
|
|
|
|
{
|
2025-07-22 04:09:38 +00:00
|
|
|
public class UiManager : Singleton<UiManager>, IManager, IEventHandler<OpenPopupUiEvent>, IEventHandler<ClosePopupUiEvent>
|
2025-07-21 07:53:39 +00:00
|
|
|
{
|
|
|
|
private readonly Dictionary<Type, PopupUi> _popupUIs = new();
|
|
|
|
|
|
|
|
private readonly object _uiPauseRequester = new();
|
|
|
|
|
|
|
|
public void PreInit()
|
|
|
|
{
|
|
|
|
EventBus.Register<OpenPopupUiEvent>(this);
|
|
|
|
EventBus.Register<ClosePopupUiEvent>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task Init()
|
|
|
|
{
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void PostInit()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
EventBus.Unregister<OpenPopupUiEvent>(this);
|
|
|
|
EventBus.Unregister<ClosePopupUiEvent>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RegisterPopupUI(PopupUi ui)
|
|
|
|
{
|
|
|
|
var type = ui.GetType();
|
|
|
|
_popupUIs.TryAdd(type, ui);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UnregisterPopupUI(PopupUi ui)
|
|
|
|
{
|
|
|
|
var type = ui.GetType();
|
|
|
|
if (_popupUIs.TryGetValue(type, out var registered) && registered == ui)
|
|
|
|
{
|
|
|
|
_popupUIs.Remove(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Invoke(OpenPopupUiEvent evt)
|
|
|
|
{
|
|
|
|
if (_popupUIs.TryGetValue(evt.UiType, out var popup))
|
|
|
|
{
|
|
|
|
popup.Open();
|
|
|
|
|
|
|
|
if (popup.IsBlockingTime)
|
|
|
|
{
|
2025-07-22 03:55:04 +00:00
|
|
|
var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
|
|
|
|
timeScaleChangeEvent.Requester = popup;
|
|
|
|
timeScaleChangeEvent.NewTimeScale = 0f;
|
|
|
|
EventBus.Broadcast(timeScaleChangeEvent);
|
2025-07-21 07:53:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Invoke(ClosePopupUiEvent evt)
|
|
|
|
{
|
2025-07-22 04:09:38 +00:00
|
|
|
if (_popupUIs.TryGetValue(evt.UiType, out var popup))
|
2025-07-21 07:53:39 +00:00
|
|
|
{
|
2025-07-22 03:55:04 +00:00
|
|
|
popup.Close();
|
2025-07-21 07:53:39 +00:00
|
|
|
|
2025-07-22 03:55:04 +00:00
|
|
|
if (popup.IsBlockingTime)
|
2025-07-21 07:53:39 +00:00
|
|
|
{
|
2025-07-22 03:55:04 +00:00
|
|
|
var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
|
|
|
|
timeScaleChangeEvent.Requester = popup;
|
|
|
|
timeScaleChangeEvent.NewTimeScale = 1f;
|
|
|
|
EventBus.Broadcast(timeScaleChangeEvent);
|
2025-07-21 07:53:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|