SystemDialog.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System;
  2. using UnityEngine;
  3. public class SystemDialog : MonoBehaviour
  4. {
  5. public bool IsDecided
  6. {
  7. get
  8. {
  9. return this.m_bDecided;
  10. }
  11. }
  12. private void Awake()
  13. {
  14. }
  15. public void Init()
  16. {
  17. this.m_uiPanel = base.gameObject.GetComponent<UIPanel>();
  18. this.m_goMsg = UTY.GetChildObject(base.gameObject, "Base/Message", false);
  19. this.m_uiMsg = this.m_goMsg.GetComponent<UILabel>();
  20. this.m_goOk = UTY.GetChildObject(base.gameObject, "Base/Ok", false);
  21. this.m_uiBtnOk = this.m_goOk.GetComponent<UIButton>();
  22. this.m_goCancel = UTY.GetChildObject(base.gameObject, "Base/Cancel", false);
  23. this.m_uiBtnCancel = this.m_goCancel.GetComponent<UIButton>();
  24. this.m_goOk.SetActive(false);
  25. this.m_goCancel.SetActive(false);
  26. EventDelegate.Set(this.m_uiBtnOk.onClick, new EventDelegate.Callback(this.OnClickOk));
  27. EventDelegate.Set(this.m_uiBtnCancel.onClick, new EventDelegate.Callback(this.OnClickCancel));
  28. base.gameObject.SetActive(false);
  29. }
  30. private void Start()
  31. {
  32. }
  33. public void SetOnClickCallBack(SystemDialog.OnClick f_dgOk, SystemDialog.OnClick f_dgCancel = null)
  34. {
  35. this.m_dgOnClickOk = f_dgOk;
  36. this.m_dgOnClickCancel = f_dgCancel;
  37. }
  38. public void Show(string f_strMsg, SystemDialog.TYPE f_eType, SystemDialog.OnClick f_dgOk = null, SystemDialog.OnClick f_dgCancel = null)
  39. {
  40. if (!this.m_bDecided)
  41. {
  42. NDebug.Assert("ダイアログの二重呼出しはできません。", false);
  43. }
  44. this.m_uiMsg.text = f_strMsg.Replace('|', '\n');
  45. this.m_goOk.SetActive(true);
  46. if (f_eType == SystemDialog.TYPE.OK_CANCEL || f_eType == SystemDialog.TYPE.YES_NO)
  47. {
  48. this.m_goCancel.SetActive(true);
  49. }
  50. else
  51. {
  52. this.m_goCancel.SetActive(false);
  53. }
  54. if (f_eType == SystemDialog.TYPE.OK_CANCEL || f_eType == SystemDialog.TYPE.OK)
  55. {
  56. this.m_goOk.GetComponent<UIButton>().normalSprite = "cm3d2_dialog_buttom_ok";
  57. this.m_goCancel.GetComponent<UIButton>().normalSprite = "cm3d2_dialog_buttom_cancel";
  58. }
  59. else if (f_eType == SystemDialog.TYPE.YES_NO)
  60. {
  61. this.m_goOk.GetComponent<UIButton>().normalSprite = "cm3d2_dialog_buttom_yes";
  62. this.m_goCancel.GetComponent<UIButton>().normalSprite = "cm3d2_dialog_buttom_no";
  63. }
  64. if (f_dgOk == null)
  65. {
  66. f_dgOk = new SystemDialog.OnClick(this.OnCloseDefaultEvent);
  67. }
  68. if (f_dgCancel == null)
  69. {
  70. f_dgCancel = new SystemDialog.OnClick(this.OnCloseDefaultEvent);
  71. }
  72. if (f_dgOk != null)
  73. {
  74. if (f_dgCancel == null)
  75. {
  76. this.SetOnClickCallBack(f_dgOk, null);
  77. }
  78. else
  79. {
  80. this.SetOnClickCallBack(f_dgOk, f_dgCancel);
  81. }
  82. }
  83. base.gameObject.SetActive(true);
  84. iTween.StopByName(base.gameObject, "sysdlg");
  85. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  86. {
  87. "name",
  88. "sysdlg",
  89. "from",
  90. this.m_uiPanel.alpha,
  91. "to",
  92. 1.0,
  93. "time",
  94. 0.3 * (double)GameMain.Instance.CMSystem.FadeSpeedRate,
  95. "onUpdate",
  96. "UpdateAlpha"
  97. }));
  98. this.m_bDecided = false;
  99. }
  100. public void UpdateAlpha(float f_fNewValue)
  101. {
  102. this.m_uiPanel.alpha = f_fNewValue;
  103. }
  104. public void CompleteHide()
  105. {
  106. this.Hide();
  107. }
  108. public void Hide()
  109. {
  110. base.gameObject.SetActive(false);
  111. this.m_goOk.SetActive(false);
  112. this.m_goCancel.SetActive(false);
  113. this.m_dgOnClickOk = null;
  114. this.m_dgOnClickCancel = null;
  115. }
  116. public void Close()
  117. {
  118. if (base.gameObject.activeSelf)
  119. {
  120. iTween.StopByName(base.gameObject, "sysdlg");
  121. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  122. {
  123. "name",
  124. "sysdlg",
  125. "from",
  126. this.m_uiPanel.alpha,
  127. "to",
  128. 0.0,
  129. "time",
  130. 0.3 * (double)GameMain.Instance.CMSystem.FadeSpeedRate,
  131. "onUpdate",
  132. "UpdateAlpha",
  133. "onComplete",
  134. "CompleteHide"
  135. }));
  136. }
  137. }
  138. private void OnClickOk()
  139. {
  140. this.m_bDecided = true;
  141. if (this.m_dgOnClickOk != null)
  142. {
  143. SystemDialog.OnClick dgOnClickOk = this.m_dgOnClickOk;
  144. this.m_dgOnClickOk = null;
  145. dgOnClickOk();
  146. }
  147. }
  148. private void OnClickCancel()
  149. {
  150. this.m_bDecided = true;
  151. if (this.m_dgOnClickCancel != null)
  152. {
  153. SystemDialog.OnClick dgOnClickCancel = this.m_dgOnClickCancel;
  154. this.m_dgOnClickCancel = null;
  155. dgOnClickCancel();
  156. }
  157. }
  158. private void OnCloseDefaultEvent()
  159. {
  160. GameMain.Instance.SysDlg.Close();
  161. }
  162. private void Update()
  163. {
  164. }
  165. private GameObject m_goOk;
  166. private UIButton m_uiBtnOk;
  167. private GameObject m_goCancel;
  168. private UIButton m_uiBtnCancel;
  169. private GameObject m_goMsg;
  170. private UILabel m_uiMsg;
  171. private UIPanel m_uiPanel;
  172. private SystemDialog.OnClick m_dgOnClickOk;
  173. private SystemDialog.OnClick m_dgOnClickCancel;
  174. private bool m_bDecided = true;
  175. public delegate void OnClick();
  176. public enum TYPE
  177. {
  178. OK,
  179. OK_CANCEL,
  180. YES_NO
  181. }
  182. }