SystemDialog.cs 4.9 KB

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