SystemDialog.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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, string[] args, SystemDialog.TYPE f_eType, SystemDialog.OnClick f_dgOk = null, SystemDialog.OnClick f_dgCancel = null)
  106. {
  107. string text = LocalizationManager.GetTranslation(messageTerm, true, 0, true, false, null, null);
  108. if (!string.IsNullOrEmpty(text) && args != null && 0 < args.Length)
  109. {
  110. text = string.Format(text, args);
  111. }
  112. this.Show(text, f_eType, f_dgOk, f_dgCancel);
  113. }
  114. public void UpdateAlpha(float f_fNewValue)
  115. {
  116. this.m_uiPanel.alpha = f_fNewValue;
  117. }
  118. public void CompleteHide()
  119. {
  120. this.Hide();
  121. }
  122. public void Hide()
  123. {
  124. base.gameObject.SetActive(false);
  125. this.m_goOk.SetActive(false);
  126. this.m_goCancel.SetActive(false);
  127. this.m_dgOnClickOk = null;
  128. this.m_dgOnClickCancel = null;
  129. }
  130. public void Close()
  131. {
  132. if (base.gameObject.activeSelf)
  133. {
  134. iTween.StopByName(base.gameObject, "sysdlg");
  135. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  136. {
  137. "name",
  138. "sysdlg",
  139. "from",
  140. this.m_uiPanel.alpha,
  141. "to",
  142. 0.0,
  143. "time",
  144. 0.3 * (double)GameMain.Instance.CMSystem.FadeSpeedRate,
  145. "onUpdate",
  146. "UpdateAlpha",
  147. "onComplete",
  148. "CompleteHide"
  149. }));
  150. }
  151. }
  152. private void OnClickOk()
  153. {
  154. this.m_bDecided = true;
  155. if (this.m_dgOnClickOk != null)
  156. {
  157. SystemDialog.OnClick dgOnClickOk = this.m_dgOnClickOk;
  158. this.m_dgOnClickOk = null;
  159. dgOnClickOk();
  160. }
  161. }
  162. private void OnClickCancel()
  163. {
  164. this.m_bDecided = true;
  165. if (this.m_dgOnClickCancel != null)
  166. {
  167. SystemDialog.OnClick dgOnClickCancel = this.m_dgOnClickCancel;
  168. this.m_dgOnClickCancel = null;
  169. dgOnClickCancel();
  170. }
  171. }
  172. private void OnCloseDefaultEvent()
  173. {
  174. GameMain.Instance.SysDlg.Close();
  175. }
  176. private void Update()
  177. {
  178. }
  179. private GameObject m_goOk;
  180. private UIButton m_uiBtnOk;
  181. private GameObject m_goCancel;
  182. private UIButton m_uiBtnCancel;
  183. private GameObject m_goMsg;
  184. private UILabel m_uiMsg;
  185. private UIPanel m_uiPanel;
  186. private SystemDialog.OnClick m_dgOnClickOk;
  187. private SystemDialog.OnClick m_dgOnClickCancel;
  188. private bool m_bDecided = true;
  189. public delegate void OnClick();
  190. public enum TYPE
  191. {
  192. OK,
  193. OK_CANCEL,
  194. YES_NO
  195. }
  196. }