ADVKagManager.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using script;
  5. using UnityEngine;
  6. public class ADVKagManager : BaseKagManager
  7. {
  8. public ADVKagManager(TJSScript tjs, ScriptManager script_mgr, MessageWindowMgr message_mgr) : base(tjs, script_mgr)
  9. {
  10. this.message_mgr_ = message_mgr;
  11. this.update_count_ = 0UL;
  12. }
  13. public override void Initialize()
  14. {
  15. NDebug.AssertNull(this.message_mgr_ != null);
  16. base.Initialize();
  17. this.kag_.AddTagCallBack("scenecall", new KagScript.KagTagCallBack(this.TagSceneCall));
  18. this.kag_.AddTagCallBack("sceneunload", new KagScript.KagTagCallBack(this.TagSceneUnload));
  19. this.kag_.AddTagCallBack("talk", new KagScript.KagTagCallBack(this.TagTalk));
  20. this.kag_.AddTagCallBack("hitret", new KagScript.KagTagCallBack(this.TagHitRet));
  21. this.kag_.AddTagCallBack("messagewindow", new KagScript.KagTagCallBack(this.TagMessageWindow));
  22. this.kag_.AddTagCallBack("fade", new KagScript.KagTagCallBack(this.TagFade));
  23. this.kag_.AddTagCallBack("choicesset", new KagScript.KagTagCallBack(this.TagChoicesSet));
  24. this.kag_.AddTagCallBack("choicesrandomset", new KagScript.KagTagCallBack(this.TagChoicesRandomSet));
  25. this.kag_.AddTagCallBack("choicesrandomselect", new KagScript.KagTagCallBack(this.TagChoicesRandomSelect));
  26. this.kag_.AddTagCallBack("calldialog", new KagScript.KagTagCallBack(this.TagCallDialog));
  27. this.kag_.AddTagCallBack("_choicesshow", new KagScript.KagTagCallBack(this.Tag_ChoicesShow));
  28. this.kag_.LoadScenarioString("@macro name='choicesshow'\n\t@_choicesshow\n\t@s\n\t@endmacro\n");
  29. this.kag_.AddTagCallBack("voicewait", new KagScript.KagTagCallBack(this.TagVoiceWait));
  30. this.kag_.AddTagCallBack("talkRepeat", new KagScript.KagTagCallBack(this.TagTalk));
  31. this.kag_.Exec();
  32. }
  33. public override void Update()
  34. {
  35. base.Update();
  36. if (this.vr_commu_mode)
  37. {
  38. return;
  39. }
  40. if (!GameMain.Instance.SysDlg.IsDecided)
  41. {
  42. return;
  43. }
  44. if (this.skip_mode && this.update_count_ % 2UL == 0UL && this.message_mgr_.IsClickAction())
  45. {
  46. if (!GameMain.Instance.CMSystem.MsgVoiceNoStop)
  47. {
  48. GameMain.Instance.SoundMgr.VoiceStopAll();
  49. }
  50. this.Exec();
  51. }
  52. else if (this.auto_mode)
  53. {
  54. int exitWaitCount = this.message_mgr_.GetExitWaitCount();
  55. bool flag = GameMain.Instance.SoundMgr.isVoicePlaying();
  56. if (!GameMain.Instance.CMSystem.MsgVoiceNoStop)
  57. {
  58. flag = false;
  59. }
  60. if (this.auto_wait_count <= exitWaitCount && this.message_mgr_.IsClickAction() && !flag)
  61. {
  62. if (!GameMain.Instance.CMSystem.MsgVoiceNoStop)
  63. {
  64. GameMain.Instance.SoundMgr.VoiceStopAll();
  65. }
  66. this.Exec();
  67. }
  68. }
  69. this.update_count_ += 1UL;
  70. }
  71. public void OnClickEvent()
  72. {
  73. if (this.GetSettingSkipMode())
  74. {
  75. this.message_mgr_.CallEvent(MessageWindowMgr.MessageWindowUnderButton.Skip);
  76. return;
  77. }
  78. if (!GameMain.Instance.CMSystem.MsgVoiceNoStop)
  79. {
  80. GameMain.Instance.SoundMgr.VoiceStopAll();
  81. }
  82. this.Exec();
  83. }
  84. public override bool Exec()
  85. {
  86. base.ClearExecWait();
  87. if (this.IsExec() && this.message_mgr_.IsChAnimeEnabled())
  88. {
  89. this.message_mgr_.FinishChAnime();
  90. return true;
  91. }
  92. return base.Exec();
  93. }
  94. public bool TagSceneCall(KagTagSupport tag_data)
  95. {
  96. base.CheckAbsolutelyNecessaryTag(tag_data, "scenecall", new string[]
  97. {
  98. "name"
  99. });
  100. this.tag_backup_ = tag_data.GetTagList();
  101. if (tag_data.IsValid("add"))
  102. {
  103. GameMain.Instance.AddScene(tag_data.GetTagProperty("name").AsString());
  104. }
  105. else
  106. {
  107. this.script_mgr_.StopMotionScript();
  108. this.script_mgr_.is_motion_blend = true;
  109. this.message_mgr_.CloseMessageWindowPanel();
  110. this.message_mgr_.SetMessageViewerActive(true);
  111. this.message_mgr_.CancelSkipAndAuto();
  112. GameMain.Instance.LoadScene(tag_data.GetTagProperty("name").AsString());
  113. }
  114. if (tag_data.IsValid("enabled"))
  115. {
  116. base.enabled = tag_data.GetTagProperty("enabled").AsBool();
  117. }
  118. return true;
  119. }
  120. public bool TagSceneUnload(KagTagSupport tag_data)
  121. {
  122. if (tag_data.IsValid("name"))
  123. {
  124. GameMain.Instance.UnloadScene(tag_data.GetTagProperty("name").AsString());
  125. }
  126. else
  127. {
  128. GameMain.Instance.UnloadPopScene();
  129. }
  130. return false;
  131. }
  132. public bool TagTalk(KagTagSupport tag_data)
  133. {
  134. this.message_mgr_.OpenMessageWindowPanel();
  135. this.text_data_.talk_name = string.Empty;
  136. if (tag_data.IsValid("name"))
  137. {
  138. this.text_data_.talk_name = ScriptManager.ReplaceCharaName(tag_data.GetTagProperty("name").AsString());
  139. }
  140. this.text_data_.vice_name = string.Empty;
  141. if (tag_data.IsValid("real"))
  142. {
  143. this.text_data_.vice_name = tag_data.GetTagProperty("real").AsString();
  144. }
  145. this.text_data_.voice_file = string.Empty;
  146. if (tag_data.IsValid("voice"))
  147. {
  148. this.text_data_.voice_maid = BaseKagManager.GetVoiceTargetMaid(tag_data);
  149. if (this.text_data_.voice_maid != null)
  150. {
  151. this.text_data_.voice_maid.LipSyncEnabled(!tag_data.IsValid("np"));
  152. }
  153. this.text_data_.voice_file = tag_data.GetTagProperty("voice").AsString() + ".ogg";
  154. }
  155. return false;
  156. }
  157. public bool TagHitRet(KagTagSupport tag_data)
  158. {
  159. this.text_data_.text = this.kag_.GetText();
  160. this.kag_.TextClear();
  161. this.text_data_.text = ScriptManager.ReplaceCharaName(this.text_data_.text);
  162. StringInfo stringInfo = new StringInfo(this.text_data_.text);
  163. int lengthInTextElements = stringInfo.LengthInTextElements;
  164. int num = lengthInTextElements - 1;
  165. while (0 < num)
  166. {
  167. string value = stringInfo.SubstringByTextElements(num, 1);
  168. if (0 > "| \u3000".IndexOf(value))
  169. {
  170. break;
  171. }
  172. this.text_data_.text = stringInfo.SubstringByTextElements(0, num);
  173. num--;
  174. }
  175. this.text_data_.text = this.text_data_.text.Replace('|', '\n');
  176. int voice_pitch = 50;
  177. AudioSourceMgr.Type type = AudioSourceMgr.Type.Voice;
  178. if (this.text_data_.voice_maid != null)
  179. {
  180. voice_pitch = this.text_data_.voice_maid.VoicePitch;
  181. if (this.text_data_.voice_maid.AudioMan != null)
  182. {
  183. type = this.text_data_.voice_maid.AudioMan.SoundType;
  184. }
  185. }
  186. this.message_mgr_.SetText(this.text_data_.talk_name, this.text_data_.text, this.text_data_.voice_file, voice_pitch, type);
  187. if (!string.IsNullOrEmpty(this.text_data_.voice_file))
  188. {
  189. GameMain.Instance.SoundMgr.VoiceStopAll();
  190. if (!this.script_mgr_.adv_kag.skip_mode)
  191. {
  192. if (this.text_data_.voice_maid != null && this.text_data_.voice_maid.Visible)
  193. {
  194. this.text_data_.voice_maid.AudioMan.LoadPlay(this.text_data_.voice_file, 0f, false, false);
  195. }
  196. else
  197. {
  198. GameMain.Instance.SoundMgr.PlayDummyVoice(this.text_data_.voice_file, 0f, false, false, voice_pitch, type);
  199. }
  200. }
  201. this.text_data_.voice_maid = null;
  202. }
  203. return true;
  204. }
  205. public bool TagMessageWindow(KagTagSupport tag_data)
  206. {
  207. if (tag_data.IsValid("on"))
  208. {
  209. this.message_mgr_.OpenMessageWindowPanel();
  210. }
  211. else if (tag_data.IsValid("off"))
  212. {
  213. this.message_mgr_.CloseMessageWindowPanel();
  214. }
  215. return false;
  216. }
  217. public bool TagFade(KagTagSupport tag_data)
  218. {
  219. base.CheckAbsolutelyNecessaryTag(tag_data, "fade", new string[]
  220. {
  221. "time"
  222. });
  223. int millisecond = tag_data.GetTagProperty("time").AsInteger();
  224. float f_fTime = GameUty.MillisecondToSecond(millisecond);
  225. bool flag = tag_data.IsValid("sync");
  226. bool flag2 = tag_data.IsValid("color");
  227. Color black = Color.black;
  228. if (flag2)
  229. {
  230. string[] array = tag_data.GetTagProperty("color").AsString().Split(new char[]
  231. {
  232. ':'
  233. });
  234. black.r = float.Parse(array[0]) / 255f;
  235. black.g = float.Parse(array[1]) / 255f;
  236. black.b = float.Parse(array[2]) / 255f;
  237. }
  238. if (tag_data.IsValid("in"))
  239. {
  240. this.script_mgr_.is_motion_blend = true;
  241. GameMain.Instance.MainCamera.FadeIn(f_fTime, false, null, true, !flag2, black);
  242. }
  243. else
  244. {
  245. this.script_mgr_.is_motion_blend = false;
  246. GameMain.Instance.MainCamera.FadeOut(f_fTime, false, null, true, black);
  247. }
  248. this.message_mgr_.ClearText();
  249. if (flag)
  250. {
  251. base.SetFadeWait(true);
  252. }
  253. return flag;
  254. }
  255. public bool TagChoicesSet(KagTagSupport tag_data)
  256. {
  257. base.CheckAbsolutelyNecessaryTag(tag_data, "choicesset", new string[]
  258. {
  259. "text",
  260. "label"
  261. });
  262. string key = this.text_data_.text = ScriptManager.ReplaceCharaName(tag_data.GetTagProperty("text").AsString());
  263. bool value = true;
  264. if (tag_data.IsValid("enabled"))
  265. {
  266. value = tag_data.GetTagProperty("enabled").AsBool();
  267. }
  268. this.choise_data_.Add(new KeyValuePair<string, KeyValuePair<string, bool>>(key, new KeyValuePair<string, bool>(tag_data.GetTagProperty("label").AsString(), value)));
  269. return false;
  270. }
  271. public bool TagChoicesRandomSet(KagTagSupport tag_data)
  272. {
  273. base.CheckAbsolutelyNecessaryTag(tag_data, "choicesrandomse", new string[]
  274. {
  275. "text",
  276. "label"
  277. });
  278. string key = this.text_data_.text = ScriptManager.ReplaceCharaName(tag_data.GetTagProperty("text").AsString());
  279. bool value = true;
  280. if (tag_data.IsValid("enabled"))
  281. {
  282. value = tag_data.GetTagProperty("enabled").AsBool();
  283. }
  284. this.choise_random_data_.Add(new KeyValuePair<string, KeyValuePair<string, bool>>(key, new KeyValuePair<string, bool>(tag_data.GetTagProperty("label").AsString(), value)));
  285. return false;
  286. }
  287. public bool TagChoicesRandomSelect(KagTagSupport tag_data)
  288. {
  289. base.CheckAbsolutelyNecessaryTag(tag_data, "choicesrandomselect", new string[]
  290. {
  291. "num"
  292. });
  293. int num = tag_data.GetTagProperty("num").AsInteger();
  294. if (this.choise_random_data_.Count < num)
  295. {
  296. num = this.choise_random_data_.Count;
  297. }
  298. System.Random random = new System.Random();
  299. int i = this.choise_random_data_.Count;
  300. while (i > 1)
  301. {
  302. i--;
  303. int index = random.Next(i + 1);
  304. KeyValuePair<string, KeyValuePair<string, bool>> value = this.choise_random_data_[index];
  305. this.choise_random_data_[index] = this.choise_random_data_[i];
  306. this.choise_random_data_[i] = value;
  307. }
  308. for (int j = 0; j < num; j++)
  309. {
  310. this.choise_data_.Add(this.choise_random_data_[j]);
  311. }
  312. this.choise_random_data_.Clear();
  313. return false;
  314. }
  315. public bool TagCallDialog(KagTagSupport tag_data)
  316. {
  317. base.CheckAbsolutelyNecessaryTag(tag_data, "calldialog", new string[]
  318. {
  319. "text",
  320. "label"
  321. });
  322. string label = tag_data.GetTagProperty("label").AsString();
  323. string text = tag_data.GetTagProperty("term").AsString();
  324. if (string.IsNullOrEmpty(text) || !Product.supportMultiLanguage)
  325. {
  326. GameMain.Instance.SysDlg.Show(tag_data.GetTagProperty("text").AsString(), SystemDialog.TYPE.OK, delegate
  327. {
  328. GameMain.Instance.SysDlg.Close();
  329. this.kag_.GoToLabel(label);
  330. this.kag_.Exec();
  331. }, null);
  332. }
  333. else
  334. {
  335. GameMain.Instance.SysDlg.ShowFromLanguageTerm(text, null, SystemDialog.TYPE.OK, delegate
  336. {
  337. GameMain.Instance.SysDlg.Close();
  338. this.kag_.GoToLabel(label);
  339. this.kag_.Exec();
  340. }, null);
  341. }
  342. return false;
  343. }
  344. public bool Tag_ChoicesShow(KagTagSupport tag_data)
  345. {
  346. Action<string, string> onClickCallBack = delegate(string choices_title, string label_name)
  347. {
  348. if (!Product.supportMultiLanguage)
  349. {
  350. string text = "=> " + choices_title;
  351. this.message_mgr_.AddBackLog(string.Empty, text, string.Empty, 0, AudioSourceMgr.Type.VoiceHeroine);
  352. }
  353. this.kag_.GoToLabel(label_name);
  354. this.kag_.Exec();
  355. };
  356. this.message_mgr_.CreateSelectButtons(this.choise_data_, onClickCallBack);
  357. this.choise_data_.Clear();
  358. return false;
  359. }
  360. public bool TagVoiceWait(KagTagSupport tag_data)
  361. {
  362. return false;
  363. }
  364. protected override void PlayMaidMotion(Maid maid, string fn, bool additive = false, bool loop = false, bool boAddQue = false, float val = 0.5f)
  365. {
  366. if (maid == null || maid.body0 == null || !maid.body0.isLoadedBody)
  367. {
  368. this.script_mgr_.StopMotionScript();
  369. return;
  370. }
  371. if (!boAddQue)
  372. {
  373. WaitEventList waitEventList = base.GetWaitEventList("motion_script");
  374. waitEventList.Clear();
  375. }
  376. this.script_mgr_.StopMotionScript();
  377. base.PlayMaidMotion(maid, fn, additive, loop, boAddQue, val);
  378. }
  379. public void SetSettingSkipMode(bool is_skip)
  380. {
  381. this.skip_mode_ = is_skip;
  382. }
  383. public bool GetSettingSkipMode()
  384. {
  385. return this.skip_mode_;
  386. }
  387. public bool skip_mode
  388. {
  389. get
  390. {
  391. return this.skip_mode_ || GameMain.Instance.IsForceSkip();
  392. }
  393. }
  394. public bool auto_mode { get; set; }
  395. public bool vr_commu_mode { get; set; }
  396. public int auto_wait_count
  397. {
  398. get
  399. {
  400. return (100 - GameMain.Instance.CMSystem.MsgAutoSpeed) * 30;
  401. }
  402. }
  403. public Dictionary<string, string> tag_backup
  404. {
  405. get
  406. {
  407. return this.tag_backup_;
  408. }
  409. }
  410. public override string GetKagClassName()
  411. {
  412. return "ADV kag";
  413. }
  414. public MessageWindowMgr MessageWindowMgr
  415. {
  416. get
  417. {
  418. return this.message_mgr_;
  419. }
  420. }
  421. private bool skip_mode_;
  422. private MessageWindowMgr message_mgr_;
  423. private ADVKagManager.TextData text_data_;
  424. private List<KeyValuePair<string, KeyValuePair<string, bool>>> choise_data_ = new List<KeyValuePair<string, KeyValuePair<string, bool>>>();
  425. private List<KeyValuePair<string, KeyValuePair<string, bool>>> choise_random_data_ = new List<KeyValuePair<string, KeyValuePair<string, bool>>>();
  426. private ulong update_count_;
  427. private Dictionary<string, string> tag_backup_ = new Dictionary<string, string>();
  428. protected struct TextData
  429. {
  430. public string talk_name;
  431. public string text;
  432. public string voice_file;
  433. public string vice_name;
  434. public Maid voice_maid;
  435. }
  436. }