private void ShowPopup(string header, Transform body, string ok = null, PopupWindowAction okCallback = null, string cancel = null, PopupWindowAction cancelCallback = null, float width = 500) { m_openedPopupWindows = FindObjectsOfType <PopupWindow>().Where( wnd => wnd.IsOpened && wnd.isActiveAndEnabled).ToArray(); foreach (PopupWindow wnd in m_openedPopupWindows) { wnd.gameObject.SetActive(false); } gameObject.SetActive(true); if (TxtHeader != null) { TxtHeader.text = header; } if (Body != null) { body.SetParent(Body, false); } if (BtnOk != null) { if (string.IsNullOrEmpty(ok)) { BtnOk.gameObject.SetActive(false); } else { Text text = BtnOk.GetComponentInChildren <Text>(); if (text != null) { text.text = ok; } } } if (BtnCancel != null) { if (string.IsNullOrEmpty(cancel)) { BtnCancel.gameObject.SetActive(false); } else { Text text = BtnCancel.GetComponentInChildren <Text>(); if (text != null) { text.text = cancel; } } } if (Panel != null) { Panel.preferredWidth = width; } m_okCallback = okCallback; m_cancelCallback = cancelCallback; m_isOpened = true; }
public static void Show(string header, string body, string ok, PopupWindowAction okCallback = null, string cancel = null, PopupWindowAction cancelCallback = null, float width = 530) { if (m_instance == null) { Debug.LogWarning("PopupWindows.m_instance is null"); return; } PopupWindow instance = Instantiate(m_instance.Prefab); instance.transform.position = Vector3.zero; instance.transform.SetParent(m_instance.transform, false); instance.DefaultBody.text = body; instance.ShowPopup(header, instance.DefaultBody.transform, ok, okCallback, cancel, cancelCallback, width); }
private PopupWindowAction GetAction() { PopupWindowAction action = new PopupWindowAction(); action.IsModal = true; action.CenterOverAssociatedObject = true; action.WindowContent = new NewTilesetWindow(); Style style = new Style(); style.TargetType = typeof(Window); style.Setters.Add(new Setter(FrameworkElement.MinWidthProperty, this.Width)); style.Setters.Add(new Setter(FrameworkElement.MinHeightProperty, this.Height)); style.Setters.Add(new Setter(FrameworkElement.WidthProperty, this.Width)); style.Setters.Add(new Setter(FrameworkElement.HeightProperty, this.Height)); action.WindowStyle = style; return(action); }
private void HidePopup() { if (m_openedPopupWindows != null) { foreach (PopupWindow wnd in m_openedPopupWindows) { if (wnd != null) { wnd.gameObject.SetActive(true); } } } m_openedPopupWindows = null; gameObject.SetActive(false); Destroy(gameObject); m_okCallback = null; m_cancelCallback = null; m_isOpened = false; }