using System; using I2.Loc; using UnityEngine; public class SystemDialog : MonoBehaviour { public bool IsDecided { get { return this.m_bDecided; } } private void Awake() { } public void Init() { this.m_uiPanel = base.gameObject.GetComponent(); this.m_goMsg = UTY.GetChildObject(base.gameObject, "Base/Message", false); this.m_uiMsg = this.m_goMsg.GetComponent(); this.m_goOk = UTY.GetChildObject(base.gameObject, "Base/Ok", false); this.m_uiBtnOk = this.m_goOk.GetComponent(); this.m_goCancel = UTY.GetChildObject(base.gameObject, "Base/Cancel", false); this.m_uiBtnCancel = this.m_goCancel.GetComponent(); this.m_goOk.SetActive(false); this.m_goCancel.SetActive(false); EventDelegate.Set(this.m_uiBtnOk.onClick, new EventDelegate.Callback(this.OnClickOk)); EventDelegate.Set(this.m_uiBtnCancel.onClick, new EventDelegate.Callback(this.OnClickCancel)); base.gameObject.SetActive(false); } private void Start() { } public void SetOnClickCallBack(SystemDialog.OnClick f_dgOk, SystemDialog.OnClick f_dgCancel = null) { this.m_dgOnClickOk = f_dgOk; this.m_dgOnClickCancel = f_dgCancel; } public void Show(string f_strMsg, SystemDialog.TYPE f_eType, SystemDialog.OnClick f_dgOk = null, SystemDialog.OnClick f_dgCancel = null) { if (!this.m_bDecided) { NDebug.Assert("ダイアログの二重呼出しはできません。", false); } if (string.IsNullOrEmpty(f_strMsg)) { f_strMsg = string.Empty; } this.m_uiMsg.text = f_strMsg.Replace('|', '\n'); this.m_goOk.SetActive(true); if (f_eType == SystemDialog.TYPE.OK_CANCEL || f_eType == SystemDialog.TYPE.YES_NO) { this.m_goCancel.SetActive(true); } else { this.m_goCancel.SetActive(false); } if (f_eType == SystemDialog.TYPE.OK_CANCEL || f_eType == SystemDialog.TYPE.OK) { this.m_goOk.GetComponent().normalSprite = "cm3d2_dialog_buttom_ok"; this.m_goCancel.GetComponent().normalSprite = "cm3d2_dialog_buttom_cancel"; } else if (f_eType == SystemDialog.TYPE.YES_NO) { this.m_goOk.GetComponent().normalSprite = "cm3d2_dialog_buttom_yes"; this.m_goCancel.GetComponent().normalSprite = "cm3d2_dialog_buttom_no"; } if (f_dgOk == null) { f_dgOk = new SystemDialog.OnClick(this.OnCloseDefaultEvent); } if (f_dgCancel == null) { f_dgCancel = new SystemDialog.OnClick(this.OnCloseDefaultEvent); } if (f_dgOk != null) { if (f_dgCancel == null) { this.SetOnClickCallBack(f_dgOk, null); } else { this.SetOnClickCallBack(f_dgOk, f_dgCancel); } } base.gameObject.SetActive(true); iTween.StopByName(base.gameObject, "sysdlg"); iTween.ValueTo(base.gameObject, iTween.Hash(new object[] { "name", "sysdlg", "from", this.m_uiPanel.alpha, "to", 1.0, "time", 0.3 * (double)GameMain.Instance.CMSystem.FadeSpeedRate, "onUpdate", "UpdateAlpha" })); this.m_bDecided = false; } public void ShowFromLanguageTerm(string messageTerm, string[] args, SystemDialog.TYPE f_eType, SystemDialog.OnClick f_dgOk = null, SystemDialog.OnClick f_dgCancel = null) { string text = LocalizationManager.GetTranslation(messageTerm, true, 0, true, false, null, null); if (!string.IsNullOrEmpty(text) && args != null && 0 < args.Length) { text = string.Format(text, args); } this.Show(text, f_eType, f_dgOk, f_dgCancel); } public void UpdateAlpha(float f_fNewValue) { this.m_uiPanel.alpha = f_fNewValue; } public void CompleteHide() { this.Hide(); } public void Hide() { base.gameObject.SetActive(false); this.m_goOk.SetActive(false); this.m_goCancel.SetActive(false); this.m_dgOnClickOk = null; this.m_dgOnClickCancel = null; } public void Close() { if (base.gameObject.activeSelf) { iTween.StopByName(base.gameObject, "sysdlg"); iTween.ValueTo(base.gameObject, iTween.Hash(new object[] { "name", "sysdlg", "from", this.m_uiPanel.alpha, "to", 0.0, "time", 0.3 * (double)GameMain.Instance.CMSystem.FadeSpeedRate, "onUpdate", "UpdateAlpha", "onComplete", "CompleteHide" })); } } private void OnClickOk() { this.m_bDecided = true; if (this.m_dgOnClickOk != null) { SystemDialog.OnClick dgOnClickOk = this.m_dgOnClickOk; this.m_dgOnClickOk = null; dgOnClickOk(); } } private void OnClickCancel() { this.m_bDecided = true; if (this.m_dgOnClickCancel != null) { SystemDialog.OnClick dgOnClickCancel = this.m_dgOnClickCancel; this.m_dgOnClickCancel = null; dgOnClickCancel(); } } private void OnCloseDefaultEvent() { GameMain.Instance.SysDlg.Close(); } private void Update() { } private GameObject m_goOk; private UIButton m_uiBtnOk; private GameObject m_goCancel; private UIButton m_uiBtnCancel; private GameObject m_goMsg; private UILabel m_uiMsg; private UIPanel m_uiPanel; private SystemDialog.OnClick m_dgOnClickOk; private SystemDialog.OnClick m_dgOnClickCancel; private bool m_bDecided = true; public delegate void OnClick(); public enum TYPE { OK, OK_CANCEL, YES_NO } }