ADVKagManager.cs 13 KB

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