Add option to destroy window on close. Add API for creating windows.

This commit is contained in:
in0finite 2019-04-18 02:05:37 +02:00
parent 8080caad44
commit 127425a01c
2 changed files with 39 additions and 0 deletions

View file

@ -18,6 +18,7 @@ namespace SanAndreasUnity.UI {
this.windowName = "";
this.useScrollView = true;
this.DestroyOnClose = true;
// adjust rect
this.windowRect = GUIUtils.GetCenteredRect( new Vector2(400, 300) );
@ -39,5 +40,17 @@ namespace SanAndreasUnity.UI {
}
public static MessageBox Show(string title, string text, bool useTextField = false)
{
var msgBox = PauseMenuWindow.Create<MessageBox>();
msgBox.Title = title;
msgBox.Text = text;
msgBox.UseTextField = useTextField;
msgBox.IsOpened = true;
return msgBox;
}
}
}

View file

@ -16,14 +16,25 @@ namespace SanAndreasUnity.UI {
set {
if (m_isOpened == value)
return;
m_isOpened = value;
if (m_isOpened)
{
this.OnWindowOpened ();
}
else
{
if (this.DestroyOnClose)
Destroy(this);
this.OnWindowClosed ();
}
}
}
[SerializeField] private bool m_destroyOnClose = false;
public bool DestroyOnClose { get { return m_destroyOnClose; } set { m_destroyOnClose = value; } }
private static int lastWindowId = 1352345;
private int windowId = lastWindowId++;
public int WindowId { get { return this.windowId; } }
@ -58,8 +69,23 @@ namespace SanAndreasUnity.UI {
[SerializeField] private bool m_registerInMainMenuOnStart = false;
public bool IsRegisteredInMainMenu { get; private set; }
private static GameObject s_windowsContainer;
public static T Create<T>() where T : PauseMenuWindow
{
if (null == s_windowsContainer)
{
s_windowsContainer = new GameObject("Windows");
DontDestroyOnLoad( s_windowsContainer );
}
T window = s_windowsContainer.AddComponent<T>();
return window;
}
void WindowStart() {
if (m_registerInMainMenuOnStart)