123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using System.Collections;
- public class AlertPanel : PopUpPanel {
- public enum AlertPanelType
- {
- Bordered,
- Fluted
- }
- public Animator panelType;
- public const uint TIME_OUT = 0;
- public const uint YES = 0x1;
- public const uint NO = 0x2;
- public const uint OK = 0x4;
- public const uint CANCEL = 0x8;
- public uint flags;
- protected string _okLabel;
- protected string _yesLabel;
- protected string _noLabel;
- protected string _cancelLabel;
- public Button okBtn;
- public Button yesBtn;
- public Button noBtn;
- public Button cancelBtn;
- public Button closeBtn;
- public Text yesBtnText;
- public Text noBtnText;
- public Text cancelBtnText;
- public Text titleText;
- public Sprite redBtn, greenBtn;
- public Text contentText;
- protected float oldTextHeight = 0;
- protected event AlertPanelCloseDelegate closeEvent;
- public object data;
- void Awake()
- {
- InitBackGround(transform);
- Transform panelTrans = transform.FindChild("Panel");
- panelType = panelTrans.GetComponent<Animator>();
- yesBtn = panelTrans.FindChild("BtnContainer/YesBtn").GetComponent<Button>();
- noBtn = panelTrans.FindChild("BtnContainer/NoBtn").GetComponent<Button>();
- cancelBtn = panelTrans.FindChild("BtnContainer/CancelBtn").GetComponent<Button>();
- if (panelTrans.FindChild("BtnContainer/OkBtn") != null)
- okBtn = panelTrans.FindChild("BtnContainer/OkBtn").GetComponent<Button>();
- yesBtnText = yesBtn.transform.FindChild("Text").GetComponent<Text>();
- noBtnText = noBtn.transform.FindChild("Text").GetComponent<Text>();
- cancelBtnText = cancelBtn.transform.FindChild("Text").GetComponent<Text>();
- titleText = panelTrans.FindChild("TitleContainer/Title").GetComponent<Text>();
- closeBtn = panelTrans.FindChild("CloseButton").GetComponent<Button>();
- if (panelTrans.FindChild("ButtonImage") != null)
- {
- redBtn = panelTrans.FindChild("ButtonImage").GetChild(0).GetComponent<Image>().sprite;
- greenBtn = panelTrans.FindChild("ButtonImage").GetChild(1).GetComponent<Image>().sprite;
- }
- contentText = panelTrans.FindChild("Line/Text").GetComponent<Text>();
- //redefine font
- if (Language.initialized)
- {
- if (okBtn != null)
- okBtn.GetComponentInChildren<Text>().font = Language.GetFont();
- contentText.font = Language.GetFont();
- titleText.font = Language.GetFont();
- yesBtnText.font = Language.GetFont();
- noBtnText.font = Language.GetFont();
- cancelBtnText.font = Language.GetFont();
- }
- else
- {
- if (okBtn != null)
- okBtn.GetComponentInChildren<Text>().font = Language.GetSystemFont();
- contentText.font = Language.GetSystemFont();
- titleText.font = Language.GetSystemFont();
- yesBtnText.font = Language.GetSystemFont();
- noBtnText.font = Language.GetSystemFont();
- cancelBtnText.font = Language.GetSystemFont();
- }
-
- //init sound
- if (okBtn != null)
- {
- //UISound okBtnSound = okBtn.gameObject.AddComponent<UISound>();
- //okBtnSound.soundType = UISound.Type.Normal;
- SoundManager.RegisterUISound(okBtn.gameObject, UISound.Type.Normal);
- }
- //UISound yesBtnSound = yesBtn.gameObject.AddComponent<UISound>();
- //yesBtnSound.soundType = UISound.Type.Normal;
- //UISound noBtnSound = noBtn.gameObject.AddComponent<UISound>();
- //noBtnSound.soundType = UISound.Type.Back;
- //UISound cancelBtnSound = cancelBtn.gameObject.AddComponent<UISound>();
- //cancelBtnSound.soundType = UISound.Type.Back;
- SoundManager.RegisterUISound(yesBtn.gameObject, UISound.Type.Normal);
- SoundManager.RegisterUISound(noBtn.gameObject, UISound.Type.Back);
- SoundManager.RegisterUISound(cancelBtn.gameObject, UISound.Type.Back);
- SoundManager.RegisterUISound(closeBtn, UISound.Type.Close);
-
- if(okBtn != null)
- {
- okBtn.onClick.AddListener(
- delegate
- {
- OnClick((int)OK);
- });
- }
- yesBtn.onClick.AddListener(
- delegate
- {
- OnClick((int)YES);
- });
- noBtn.onClick.AddListener(
- delegate
- {
- OnClick((int)NO);
- });
- cancelBtn.onClick.AddListener(
- delegate
- {
- OnClick((int)CANCEL);
- });
- closeBtn.onClick.AddListener(Close);
- }
- public string okLabel
- {
- set
- {
- _okLabel = value;
- if ((flags & OK) != 0)
- {
- yesBtnText.text = value;
- //yesBtn.GetComponent<Image>().sprite = redBtn;
- }
- }
- get
- {
- return _okLabel;
- }
- }
- public string yesLabel
- {
- set
- {
- _yesLabel = value;
- if ((flags & YES) != 0)
- {
- yesBtnText.text = value;
- //yesBtn.GetComponent<Image>().sprite = redBtn;
- }
- }
- get
- {
- return _yesLabel;
- }
- }
- public string noLabel
- {
- set
- {
- _noLabel = value;
- if ((flags & NO) != 0)
- {
- noBtnText.text = value;
- //noBtnText.GetComponent<Image>().sprite = greenBtn;
- }
- }
- get
- {
- return _noLabel;
- }
- }
- public string cancelLabel
- {
- set
- {
- _cancelLabel = value;
- if ((flags & CANCEL) != 0)
- {
- cancelBtnText.text = value;
- //cancelBtnText.GetComponent<Image>().sprite = greenBtn;
- }
- }
- get
- {
- return _cancelLabel;
- }
- }
- public virtual void OnClick(int detail)
- {
- if((flags & OK) != 0 && detail == YES)
- detail = (int)OK;
- AlertCloseEvent evt = new AlertCloseEvent();
- evt.detail = (uint)detail;
- evt.target = this;
- GameTime.timeScale = 1;
- if(closeEvent != null)
- {
- closeEvent(evt);
- }
- Close();
- }
- override public void Close()
- {
- OnClose();
- //PopUpManager.RemovePopUp(this);
- }
- void OnDestroy()
- {
- if (yesBtn != null) yesBtn.onClick.RemoveAllListeners();
- if (noBtn != null) noBtn.onClick.RemoveAllListeners();
- if (cancelBtn != null) cancelBtn.onClick.RemoveAllListeners();
- if(closeBtn != null)
- closeBtn.onClick.RemoveAllListeners();
- }
- public delegate void AlertPanelCloseDelegate(AlertCloseEvent evt);
- public static AlertPanel Show(string txt="", uint flags=0x4, AlertPanelCloseDelegate closeHandler=null, string title = null, bool showClose = false, bool pauseGame = false)
- {
- AlertPanel alertPanel = (AlertPanel)PopUpManager.AddPopUp(ResourcesUtil.GetInstance().GetGameObject("UI/AlertPanel/AlertPanel" + Language.lanForUI), null, true, typeof(AlertPanel));
- alertPanel.flags = flags;
- if(closeHandler != null)
- alertPanel.closeEvent += closeHandler;
- alertPanel.contentText.text = txt;
- if (title == null)
- alertPanel.titleText.text = Language.GetStr("AlertPanel", "title");
- else if (title != "")
- alertPanel.titleText.text = title;
- else
- alertPanel.titleText.gameObject.SetActive(false);
- if((flags & OK) == 0 && (flags & YES) == 0)
- {
- GameObject.Destroy(alertPanel.yesBtn.gameObject);
- }
- else
- {
- if((flags & OK) != 0)
- {
- if (Language.IsLanguageInit())
- alertPanel.yesBtnText.text = Language.GetStr("Public", "ok");
- else
- alertPanel.yesBtnText.text = "OK";
- }
- else if((flags & YES) != 0)
- alertPanel.yesBtnText.text = Language.GetStr("Public", "yes");
- }
- if((flags & NO) == 0)
- GameObject.Destroy(alertPanel.noBtn.gameObject);
- else
- alertPanel.noBtnText.text = Language.GetStr("Public", "no");
- if((flags & CANCEL) == 0)
- GameObject.Destroy(alertPanel.cancelBtn.gameObject);
- else
- alertPanel.cancelBtnText.text = Language.GetStr("Public", "cancel");
- alertPanel.closeBtn.gameObject.SetActive(showClose);
- //alertPanel.panelType.Play(type.ToString());
- if (pauseGame)
- {
- if (Session.GetInstance().networkMode == Session.NetworkMode.OffLine)
- GameTime.timeScale = 0;
- }
- return alertPanel;
- }
- }
|