MessageWindowMgr.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class MessageWindowMgr : BaseMgr<MessageWindowMgr>
  5. {
  6. public void ForceDisableWindow(bool f_bDisable)
  7. {
  8. this.m_bForceDisable = f_bDisable;
  9. if (f_bDisable)
  10. {
  11. this.CloseMessageWindowPanel();
  12. }
  13. }
  14. public bool IsVisibleMessageViewer
  15. {
  16. get
  17. {
  18. return this.m_goMessageViewer.activeInHierarchy;
  19. }
  20. }
  21. public void Awake()
  22. {
  23. GameObject gameObject = GameObject.Find("__GameMain__/SystemUI Root");
  24. this.m_goMessageWindowPanel = gameObject.transform.Find("MessageWindowPanel").gameObject;
  25. if (this.m_goMessageWindowPanel == null)
  26. {
  27. Debug.LogError(string.Format("{0}が見つかりませんでした", "MessageWindowPanel"));
  28. return;
  29. }
  30. this.m_goMessageViewer = UTY.GetChildObject(this.m_goMessageWindowPanel, "MessageViewer", false);
  31. this.message_bg_ = UTY.GetChildObject(this.m_goMessageWindowPanel, "MessageViewer/MsgParent/MessageBox", false).GetComponent<UISprite>();
  32. Transform transform = gameObject.transform.Find("MessageWindowPanel/MessageViewer/MsgParent/Buttons");
  33. MessageWindowMgr.MessageWindowUnderButton[] array = new MessageWindowMgr.MessageWindowUnderButton[]
  34. {
  35. MessageWindowMgr.MessageWindowUnderButton.Skip,
  36. MessageWindowMgr.MessageWindowUnderButton.Auto,
  37. MessageWindowMgr.MessageWindowUnderButton.Voice,
  38. MessageWindowMgr.MessageWindowUnderButton.BackLog,
  39. MessageWindowMgr.MessageWindowUnderButton.Config
  40. };
  41. foreach (MessageWindowMgr.MessageWindowUnderButton key in array)
  42. {
  43. string text = key.ToString();
  44. GameObject gameObject2 = transform.Find(text).gameObject;
  45. if (gameObject2 == null)
  46. {
  47. NDebug.Assert(text + "が見つかりませんでした", false);
  48. return;
  49. }
  50. this.m_dicButtonGameObject.Add(key, new MessageWindowMgr.SystemButton(gameObject2));
  51. }
  52. this.m_messageWindowCtrl = this.m_goMessageWindowPanel.GetComponent<MessageWindowCtrl>();
  53. this.m_messageWindowCtrl.Init(this.m_goMessageWindowPanel);
  54. this.m_goMessageWindowPanel.SetActive(false);
  55. this.message_ = new MessageClass(this.m_goMessageWindowPanel, this);
  56. this.on_click_event_ = new MessageWindowMgr.OnClickEvent(GameMain.Instance.ScriptMgr.adv_kag.OnClickEvent);
  57. if (GameMain.Instance.VRMode)
  58. {
  59. GameObject childObject = UTY.GetChildObject(this.m_goMessageViewer, "MsgParent", false);
  60. this.m_vBackMsgParentPos = childObject.transform.localPosition;
  61. this.m_vBackMsgParentScale = childObject.transform.localScale;
  62. }
  63. }
  64. public bool IsClickAction()
  65. {
  66. return this.m_goMessageWindowPanel.activeSelf && !this.m_messageWindowCtrl.IsDisplayBackLog() && !BaseMgr<ConfigMgr>.Instance.IsOpenConfigPanel();
  67. }
  68. public void Update()
  69. {
  70. if (this.m_bForceDisable)
  71. {
  72. return;
  73. }
  74. if (this.m_goMessageWindowPanel.activeSelf)
  75. {
  76. float alpha = (float)(100 - GameMain.Instance.CMSystem.MsgWndAlpha) / 100f;
  77. this.message_bg_.alpha = alpha;
  78. }
  79. this.message_.Update();
  80. if (GameMain.Instance.VRMode && this.m_bVRControllerNew != GameMain.Instance.OvrMgr.OvrCamera.IsControllerModeNew)
  81. {
  82. GameObject childObject = UTY.GetChildObject(this.m_goMessageViewer, "MsgParent", false);
  83. if (GameMain.Instance.OvrMgr.OvrCamera.IsControllerModeNew)
  84. {
  85. childObject.transform.localPosition = new Vector3(0f, 70f, 0f);
  86. childObject.transform.localScale = new Vector3(2f, 2f, 1f);
  87. }
  88. else
  89. {
  90. childObject.transform.localPosition = this.m_vBackMsgParentPos;
  91. childObject.transform.localScale = this.m_vBackMsgParentScale;
  92. }
  93. this.m_bVRControllerNew = GameMain.Instance.OvrMgr.OvrCamera.IsControllerModeNew;
  94. }
  95. this.m_messageWindowCtrl.VRUIModeCheck();
  96. if (this.m_messageWindowCtrl.IsDisplayBackLog() && this.m_goMessageWindowPanel.activeSelf)
  97. {
  98. if (!BaseMgr<ConfigMgr>.Instance.IsOpenConfigPanel() && NInput.GetMouseButtonUp(1))
  99. {
  100. this.CloseBacklog();
  101. }
  102. else
  103. {
  104. Vector3 vector = Input.mouseScrollDelta;
  105. this.m_messageWindowCtrl.ScrollDisplayBackLog(vector.y);
  106. }
  107. }
  108. else
  109. {
  110. bool keyDown = Input.GetKeyDown(KeyCode.Return);
  111. if ((NInput.GetMouseButtonUp(0) && UICamera.isFallThrough) || keyDown)
  112. {
  113. this.ClickMessageBox(keyDown);
  114. }
  115. }
  116. }
  117. public void ClickMessageBox(bool is_leftclick_emulate)
  118. {
  119. if (this.m_bForceDisable)
  120. {
  121. return;
  122. }
  123. if (BaseMgr<ConfigMgr>.Instance.IsOpenConfigPanel())
  124. {
  125. return;
  126. }
  127. if (NInput.GetMouseButtonUp(0) || is_leftclick_emulate)
  128. {
  129. if (this.IsClickAction())
  130. {
  131. if (this.m_goMessageViewer.activeSelf)
  132. {
  133. if (this.on_click_event_ != null)
  134. {
  135. this.on_click_event_();
  136. }
  137. }
  138. else
  139. {
  140. this.SetMessageViewerActive(true);
  141. }
  142. }
  143. }
  144. else if (NInput.GetMouseButtonUp(1))
  145. {
  146. if (GameMain.Instance.ScriptMgr.adv_kag.GetSettingSkipMode())
  147. {
  148. this.CallEvent(MessageWindowMgr.MessageWindowUnderButton.Skip);
  149. }
  150. else if (this.m_goMessageWindowPanel.activeSelf && this.m_goMessageViewer.activeSelf)
  151. {
  152. if (this.m_messageWindowCtrl.IsDisplayBackLog())
  153. {
  154. this.CloseBacklog();
  155. }
  156. else
  157. {
  158. this.SetMessageViewerActive(false);
  159. }
  160. }
  161. }
  162. }
  163. public void ClickMessageWindowUnderButton()
  164. {
  165. MessageWindowMgr.MessageWindowUnderButton type = (MessageWindowMgr.MessageWindowUnderButton)Enum.Parse(typeof(MessageWindowMgr.MessageWindowUnderButton), UIButton.current.name);
  166. this.CallEvent(type);
  167. }
  168. public void CancelSkipAndAuto()
  169. {
  170. if (GameMain.Instance.ScriptMgr.adv_kag.GetSettingSkipMode())
  171. {
  172. this.CallEvent(MessageWindowMgr.MessageWindowUnderButton.Skip);
  173. }
  174. if (GameMain.Instance.ScriptMgr.adv_kag.auto_mode)
  175. {
  176. this.CallEvent(MessageWindowMgr.MessageWindowUnderButton.Auto);
  177. }
  178. }
  179. public void CallEvent(MessageWindowMgr.MessageWindowUnderButton type)
  180. {
  181. if (this.m_messageWindowCtrl.IsSelectButtonPlayingEffect() || BaseMgr<ConfigMgr>.Instance.IsOpenConfigPanel())
  182. {
  183. return;
  184. }
  185. switch (type)
  186. {
  187. case MessageWindowMgr.MessageWindowUnderButton.Skip:
  188. {
  189. bool settingSkipMode = GameMain.Instance.ScriptMgr.adv_kag.GetSettingSkipMode();
  190. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Skip].select = !settingSkipMode;
  191. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Auto].enabled = settingSkipMode;
  192. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Voice].enabled = settingSkipMode;
  193. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.BackLog].enabled = settingSkipMode;
  194. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Config].enabled = settingSkipMode;
  195. GameMain.Instance.ScriptMgr.adv_kag.SetSettingSkipMode(!settingSkipMode);
  196. if (this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Voice].enabled)
  197. {
  198. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Voice].enabled = !string.IsNullOrEmpty(this.current_voice_file_);
  199. }
  200. break;
  201. }
  202. case MessageWindowMgr.MessageWindowUnderButton.Auto:
  203. {
  204. bool auto_mode = GameMain.Instance.ScriptMgr.adv_kag.auto_mode;
  205. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Auto].select = !auto_mode;
  206. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Skip].enabled = auto_mode;
  207. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Voice].enabled = auto_mode;
  208. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.BackLog].enabled = auto_mode;
  209. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Config].enabled = auto_mode;
  210. GameMain.Instance.ScriptMgr.adv_kag.auto_mode = !auto_mode;
  211. if (this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Voice].enabled)
  212. {
  213. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Voice].enabled = !string.IsNullOrEmpty(this.current_voice_file_);
  214. }
  215. break;
  216. }
  217. case MessageWindowMgr.MessageWindowUnderButton.Voice:
  218. if (!string.IsNullOrEmpty(this.current_voice_file_))
  219. {
  220. GameMain.Instance.SoundMgr.VoiceStopAll();
  221. GameMain.Instance.SoundMgr.PlayDummyVoice(this.current_voice_file_, 0f, false, false, this.current_voice_pitch_, this.sound_type_);
  222. }
  223. break;
  224. case MessageWindowMgr.MessageWindowUnderButton.BackLog:
  225. this.OpenBacklog();
  226. break;
  227. case MessageWindowMgr.MessageWindowUnderButton.Config:
  228. if (!BaseMgr<ConfigMgr>.Instance.IsOpenConfigPanel())
  229. {
  230. BaseMgr<ConfigMgr>.Instance.OpenConfigPanel();
  231. }
  232. break;
  233. default:
  234. Debug.LogError("不適切なボタンがクリックされました。");
  235. break;
  236. }
  237. }
  238. public void ClickBackLogClose()
  239. {
  240. if (UICamera.currentTouchID != -2)
  241. {
  242. return;
  243. }
  244. this.CloseBacklog();
  245. }
  246. public void CreateSelectButtons(List<KeyValuePair<string, KeyValuePair<string, bool>>> dicSelectButton, Action<string, string> onClickCallBack)
  247. {
  248. this.m_messageWindowCtrl.CreateSelectButtons(dicSelectButton, onClickCallBack);
  249. }
  250. public void CreateBacklog(List<BacklogCtrl.BacklogUnit> dicBacklog)
  251. {
  252. this.m_messageWindowCtrl.CreateBacklog(dicBacklog);
  253. }
  254. public void SetMessageViewerActive(bool value)
  255. {
  256. if (this.m_bForceDisable)
  257. {
  258. value = false;
  259. }
  260. this.m_goMessageViewer.SetActive(value);
  261. this.m_messageWindowCtrl.GetSelectButtonCtrl().SetPanelAlpha((float)((!value) ? 0 : 1));
  262. }
  263. public void OpenMessageWindowPanel()
  264. {
  265. if (this.m_bForceDisable)
  266. {
  267. return;
  268. }
  269. if (!this.m_goMessageWindowPanel.activeSelf)
  270. {
  271. this.m_messageWindowCtrl.DisplayBacklog(false);
  272. this.m_goMessageWindowPanel.SetActive(true);
  273. }
  274. }
  275. public void CloseMessageWindowPanel()
  276. {
  277. this.message_.Clear();
  278. this.m_messageWindowCtrl.ClearSelectBtn();
  279. this.m_goMessageWindowPanel.SetActive(false);
  280. }
  281. private void OpenBacklog()
  282. {
  283. if (this.m_bForceDisable)
  284. {
  285. return;
  286. }
  287. this.backup_camera_control_ = GameMain.Instance.MainCamera.GetControl();
  288. GameMain.Instance.MainCamera.SetControl(false);
  289. this.m_messageWindowCtrl.DisplayBacklog(true);
  290. this.CreateBacklog(this.m_listBacklogUnit);
  291. this.m_goMessageWindowPanel.SetActive(true);
  292. }
  293. public void CloseBacklog()
  294. {
  295. GameMain.Instance.MainCamera.SetControl(this.backup_camera_control_);
  296. this.m_messageWindowCtrl.DisplayBacklog(false);
  297. this.m_goMessageWindowPanel.SetActive(true);
  298. }
  299. public void AddBackLog(string name, string text, string voice_file, int pitch, AudioSourceMgr.Type type)
  300. {
  301. this.AddBackLog(new KeyValuePair<string, string>(name, name), text, string.Empty, voice_file, pitch, type);
  302. }
  303. public void AddBackLog(KeyValuePair<string, string> nameSet, string text, string subtitle_text, string voice_file, int pitch, AudioSourceMgr.Type type)
  304. {
  305. BacklogCtrl.BacklogUnit backlogUnit = new BacklogCtrl.BacklogUnit();
  306. backlogUnit.m_speakerName = nameSet.Key;
  307. backlogUnit.m_speakerNameSet = nameSet;
  308. backlogUnit.m_msg = text;
  309. backlogUnit.m_subtitlemsg = subtitle_text;
  310. backlogUnit.m_voiceId = voice_file;
  311. backlogUnit.m_voicePitch = pitch;
  312. backlogUnit.m_voiceType = type;
  313. this.m_listBacklogUnit.Add(backlogUnit);
  314. if (30 < this.m_listBacklogUnit.Count)
  315. {
  316. this.m_listBacklogUnit.RemoveAt(0);
  317. }
  318. }
  319. public void SetText(string name, string text, string voice_file, int voice_pitch, AudioSourceMgr.Type sound_type)
  320. {
  321. if (this.m_bForceDisable)
  322. {
  323. return;
  324. }
  325. this.message_.SetText(name, text, voice_file, voice_pitch, sound_type);
  326. this.current_voice_file_ = voice_file;
  327. this.current_voice_pitch_ = voice_pitch;
  328. this.sound_type_ = sound_type;
  329. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Voice].enabled = !string.IsNullOrEmpty(this.current_voice_file_);
  330. }
  331. public void ClearText()
  332. {
  333. this.current_voice_file_ = string.Empty;
  334. this.current_voice_pitch_ = 50;
  335. this.sound_type_ = AudioSourceMgr.Type.Voice;
  336. this.message_.Clear();
  337. this.m_dicButtonGameObject[MessageWindowMgr.MessageWindowUnderButton.Voice].enabled = false;
  338. }
  339. public void ClearBackLogData()
  340. {
  341. this.m_listBacklogUnit.Clear();
  342. }
  343. public void FinishChAnime()
  344. {
  345. this.message_.FinishChAnime();
  346. }
  347. public int GetExitWaitCount()
  348. {
  349. return this.message_.GetExitWaitCount();
  350. }
  351. public bool IsChAnimeEnabled()
  352. {
  353. return this.message_.ch_anime_enabled;
  354. }
  355. public const int kBackLogSaveUnit = 30;
  356. public MessageWindowMgr.OnClickEvent on_click_event_;
  357. private bool m_bForceDisable;
  358. private Dictionary<MessageWindowMgr.MessageWindowUnderButton, MessageWindowMgr.SystemButton> m_dicButtonGameObject = new Dictionary<MessageWindowMgr.MessageWindowUnderButton, MessageWindowMgr.SystemButton>();
  359. private bool m_bVRControllerNew;
  360. private Vector3 m_vBackMsgParentPos;
  361. private Vector3 m_vBackMsgParentScale;
  362. private GameObject m_goMessageViewer;
  363. private GameObject m_goMessageWindowPanel;
  364. private MessageWindowCtrl m_messageWindowCtrl;
  365. private List<BacklogCtrl.BacklogUnit> m_listBacklogUnit = new List<BacklogCtrl.BacklogUnit>();
  366. private UISprite message_bg_;
  367. private MessageClass message_;
  368. private string current_voice_file_ = string.Empty;
  369. private int current_voice_pitch_ = 50;
  370. private AudioSourceMgr.Type sound_type_ = AudioSourceMgr.Type.Voice;
  371. private bool backup_camera_control_;
  372. public delegate void OnClickEvent();
  373. public enum MessageWindowUnderButton
  374. {
  375. None = -1,
  376. Skip,
  377. Auto,
  378. Voice,
  379. BackLog,
  380. Config
  381. }
  382. private class SystemButton
  383. {
  384. public SystemButton(GameObject obj)
  385. {
  386. this.game_object_ = obj;
  387. this.button_ = this.game_object_.GetComponent<UIButton>();
  388. this.select_color_ = (this.default_color_ = this.button_.defaultColor);
  389. this.select_color_.a = 1f;
  390. this.is_select_ = false;
  391. }
  392. public bool enabled
  393. {
  394. get
  395. {
  396. return this.button_.isEnabled;
  397. }
  398. set
  399. {
  400. this.button_.isEnabled = value;
  401. if (!value)
  402. {
  403. this.select = false;
  404. }
  405. }
  406. }
  407. public bool select
  408. {
  409. get
  410. {
  411. return this.is_select_;
  412. }
  413. set
  414. {
  415. if (this.is_select_ == value)
  416. {
  417. return;
  418. }
  419. if (value)
  420. {
  421. this.button_.isEnabled = true;
  422. this.button_.defaultColor = this.select_color_;
  423. }
  424. else
  425. {
  426. this.button_.defaultColor = this.default_color_;
  427. }
  428. this.button_.UpdateColor(false);
  429. this.is_select_ = value;
  430. }
  431. }
  432. private GameObject game_object_;
  433. private UIButton button_;
  434. private bool is_select_;
  435. private Color default_color_;
  436. private Color select_color_;
  437. }
  438. }