This commit is contained in:
Hubert Mattusch 2023-10-18 11:56:57 +02:00
parent 15ea7f7328
commit 7131c14d99
5 changed files with 33 additions and 5 deletions

View File

@ -5,7 +5,7 @@ namespace NEG.UI.Popup
{ {
public class DefaultPopupData : PopupData public class DefaultPopupData : PopupData
{ {
private readonly IDefaultPopup defaultPopup; private IDefaultPopup defaultPopup;
private readonly string title; private readonly string title;
private readonly string content; private readonly string content;
@ -24,5 +24,12 @@ namespace NEG.UI.Popup
defaultPopup.SetContent(title, content, options); defaultPopup.SetContent(title, content, options);
base.Show(); base.Show();
} }
public void UpdatePopup(IDefaultPopup newPopup)
{
defaultPopup = newPopup;
popup = newPopup;
Show();
}
} }
} }

View File

@ -1,5 +1,6 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using System; using System;
using UnityEngine;
namespace NEG.UI.Popup namespace NEG.UI.Popup
{ {
@ -20,7 +21,9 @@ namespace NEG.UI.Popup
/// </summary> /// </summary>
public bool IsValid { get; protected set; } public bool IsValid { get; protected set; }
private readonly IPopup popup; public IPopup Popup => popup;
protected IPopup popup;
/// <summary> /// <summary>
/// PopupData constructor. /// PopupData constructor.
@ -40,7 +43,12 @@ namespace NEG.UI.Popup
/// <summary> /// <summary>
/// Hide popup. Close visuals without firing events; /// Hide popup. Close visuals without firing events;
/// </summary> /// </summary>
public virtual void Hide() => popup.Close(true); public virtual void Hide()
{
if(popup is MonoBehaviour behaviour && behaviour == null)
return;
popup.Close(true);
}
/// <summary> /// <summary>
/// Invalidate popup, <see cref="UiManager"/> will automatically skip this popup /// Invalidate popup, <see cref="UiManager"/> will automatically skip this popup

View File

@ -38,6 +38,8 @@ namespace NEG.UI
public PopupData CurrentPopup => currentShownPopup.data; public PopupData CurrentPopup => currentShownPopup.data;
public IDefaultPopup CurrentDefaultPopup => currentDefaultPopup;
private IArea currentArea; private IArea currentArea;
private (PopupData data, int priority) currentShownPopup; private (PopupData data, int priority) currentShownPopup;
protected IDefaultPopup currentDefaultPopup; protected IDefaultPopup currentDefaultPopup;
@ -166,7 +168,13 @@ namespace NEG.UI
UpdatePopupsState(false); UpdatePopupsState(false);
} }
protected void SetDefaultPopup(IDefaultPopup popup) => currentDefaultPopup = popup; protected void SetDefaultPopup(IDefaultPopup popup)
{
if(currentShownPopup.data != null && currentShownPopup.data is DefaultPopupData defaultData && currentShownPopup.data.Popup == currentDefaultPopup)
defaultData.UpdatePopup(popup);
currentDefaultPopup = popup;
}
private void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null) private void UpdatePopupsState(bool forceShow, int priority = 0, PopupData data = null)
@ -176,7 +184,8 @@ namespace NEG.UI
if(currentShownPopup.data != null && currentShownPopup.priority >= priority) if(currentShownPopup.data != null && currentShownPopup.priority >= priority)
return; return;
popupsToShow.Enqueue(currentShownPopup.data, currentShownPopup.priority); if(currentShownPopup.data != null)
popupsToShow.Enqueue(currentShownPopup.data, currentShownPopup.priority);
ShowPopup(data, priority); ShowPopup(data, priority);
return; return;
} }

View File

@ -50,8 +50,10 @@ namespace NEG.UI.Area
private void OnDestroy() private void OnDestroy()
{ {
#if !SERVER
if (ReferenceEquals(UiManager.Instance.CurrentArea, this)) if (ReferenceEquals(UiManager.Instance.CurrentArea, this))
UiManager.Instance.CurrentArea = null; UiManager.Instance.CurrentArea = null;
#endif
} }
public void TryUseBack(ref IControllable.BackUsed backUsed) => OnBackUsed?.Invoke(backUsed); public void TryUseBack(ref IControllable.BackUsed backUsed) => OnBackUsed?.Invoke(backUsed);

View File

@ -77,11 +77,13 @@ namespace NEG.UI.UnityUi.Buttons
protected virtual void Awake() protected virtual void Awake()
{ {
#if !SERVER
button.onClick.AddListener(OnClicked); button.onClick.AddListener(OnClicked);
if (groupButtonSettings == null) if (groupButtonSettings == null)
MonoUiManager.Instance.DefaultUiSettings.Apply(this); MonoUiManager.Instance.DefaultUiSettings.Apply(this);
else else
groupButtonSettings.Apply(this); groupButtonSettings.Apply(this);
#endif
} }
private void Start() => OnDeselect(null); private void Start() => OnDeselect(null);