ADVKagManager.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. if (this.text_data_.voice_maid != null)
  176. {
  177. voice_pitch = this.text_data_.voice_maid.VoicePitch;
  178. }
  179. this.message_mgr_.SetText(this.text_data_.talk_name, this.text_data_.text, this.text_data_.voice_file, voice_pitch);
  180. if (!string.IsNullOrEmpty(this.text_data_.voice_file))
  181. {
  182. GameMain.Instance.SoundMgr.VoiceStopAll();
  183. if (!this.script_mgr_.adv_kag.skip_mode)
  184. {
  185. if (this.text_data_.voice_maid != null && this.text_data_.voice_maid.Visible)
  186. {
  187. this.text_data_.voice_maid.AudioMan.LoadPlay(this.text_data_.voice_file, 0f, false, false);
  188. }
  189. else
  190. {
  191. GameMain.Instance.SoundMgr.PlayDummyVoice(this.text_data_.voice_file, 0f, false, false, voice_pitch);
  192. }
  193. }
  194. this.text_data_.voice_maid = null;
  195. }
  196. return true;
  197. }
  198. public bool TagMessageWindow(KagTagSupport tag_data)
  199. {
  200. if (tag_data.IsValid("on"))
  201. {
  202. this.message_mgr_.OpenMessageWindowPanel();
  203. }
  204. else if (tag_data.IsValid("off"))
  205. {
  206. this.message_mgr_.CloseMessageWindowPanel();
  207. }
  208. return false;
  209. }
  210. public bool TagFade(KagTagSupport tag_data)
  211. {
  212. base.CheckAbsolutelyNecessaryTag(tag_data, "fade", new string[]
  213. {
  214. "time"
  215. });
  216. int millisecond = tag_data.GetTagProperty("time").AsInteger();
  217. float f_fTime = GameUty.MillisecondToSecond(millisecond);
  218. bool flag = tag_data.IsValid("sync");
  219. bool flag2 = tag_data.IsValid("color");
  220. Color black = Color.black;
  221. if (flag2)
  222. {
  223. string[] array = tag_data.GetTagProperty("color").AsString().Split(new char[]
  224. {
  225. ':'
  226. });
  227. black.r = float.Parse(array[0]) / 255f;
  228. black.g = float.Parse(array[1]) / 255f;
  229. black.b = float.Parse(array[2]) / 255f;
  230. }
  231. if (tag_data.IsValid("in"))
  232. {
  233. this.script_mgr_.is_motion_blend = true;
  234. GameMain.Instance.MainCamera.FadeIn(f_fTime, false, null, true, !flag2, black);
  235. }
  236. else
  237. {
  238. this.script_mgr_.is_motion_blend = false;
  239. GameMain.Instance.MainCamera.FadeOut(f_fTime, false, null, true, black);
  240. }
  241. this.message_mgr_.ClearText();
  242. if (flag)
  243. {
  244. base.SetFadeWait(true);
  245. }
  246. return flag;
  247. }
  248. public bool TagChoicesSet(KagTagSupport tag_data)
  249. {
  250. base.CheckAbsolutelyNecessaryTag(tag_data, "choicesset", new string[]
  251. {
  252. "text",
  253. "label"
  254. });
  255. string key = this.text_data_.text = ScriptManager.ReplaceCharaName(tag_data.GetTagProperty("text").AsString());
  256. bool value = true;
  257. if (tag_data.IsValid("enabled"))
  258. {
  259. value = tag_data.GetTagProperty("enabled").AsBool();
  260. }
  261. this.choise_data_.Add(new KeyValuePair<string, KeyValuePair<string, bool>>(key, new KeyValuePair<string, bool>(tag_data.GetTagProperty("label").AsString(), value)));
  262. return false;
  263. }
  264. public bool TagChoicesRandomSet(KagTagSupport tag_data)
  265. {
  266. base.CheckAbsolutelyNecessaryTag(tag_data, "choicesrandomse", new string[]
  267. {
  268. "text",
  269. "label"
  270. });
  271. string key = this.text_data_.text = ScriptManager.ReplaceCharaName(tag_data.GetTagProperty("text").AsString());
  272. bool value = true;
  273. if (tag_data.IsValid("enabled"))
  274. {
  275. value = tag_data.GetTagProperty("enabled").AsBool();
  276. }
  277. this.choise_random_data_.Add(new KeyValuePair<string, KeyValuePair<string, bool>>(key, new KeyValuePair<string, bool>(tag_data.GetTagProperty("label").AsString(), value)));
  278. return false;
  279. }
  280. public bool TagChoicesRandomSelect(KagTagSupport tag_data)
  281. {
  282. base.CheckAbsolutelyNecessaryTag(tag_data, "choicesrandomselect", new string[]
  283. {
  284. "num"
  285. });
  286. int num = tag_data.GetTagProperty("num").AsInteger();
  287. if (this.choise_random_data_.Count < num)
  288. {
  289. num = this.choise_random_data_.Count;
  290. }
  291. System.Random random = new System.Random();
  292. int i = this.choise_random_data_.Count;
  293. while (i > 1)
  294. {
  295. i--;
  296. int index = random.Next(i + 1);
  297. KeyValuePair<string, KeyValuePair<string, bool>> value = this.choise_random_data_[index];
  298. this.choise_random_data_[index] = this.choise_random_data_[i];
  299. this.choise_random_data_[i] = value;
  300. }
  301. for (int j = 0; j < num; j++)
  302. {
  303. this.choise_data_.Add(this.choise_random_data_[j]);
  304. }
  305. this.choise_random_data_.Clear();
  306. return false;
  307. }
  308. public bool TagCallDialog(KagTagSupport tag_data)
  309. {
  310. base.CheckAbsolutelyNecessaryTag(tag_data, "calldialog", new string[]
  311. {
  312. "text",
  313. "label"
  314. });
  315. string label = tag_data.GetTagProperty("label").AsString();
  316. GameMain.Instance.SysDlg.Show(tag_data.GetTagProperty("text").AsString(), SystemDialog.TYPE.OK, delegate
  317. {
  318. GameMain.Instance.SysDlg.Close();
  319. this.kag_.GoToLabel(label);
  320. this.kag_.Exec();
  321. }, null);
  322. return false;
  323. }
  324. public bool Tag_ChoicesShow(KagTagSupport tag_data)
  325. {
  326. Action<string, string> onClickCallBack = delegate(string choices_title, string label_name)
  327. {
  328. this.kag_.GoToLabel(label_name);
  329. this.kag_.Exec();
  330. };
  331. this.message_mgr_.CreateSelectButtons(this.choise_data_, onClickCallBack);
  332. this.choise_data_.Clear();
  333. return false;
  334. }
  335. protected override void PlayMaidMotion(Maid maid, string fn, bool additive = false, bool loop = false, bool boAddQue = false, float val = 0.5f)
  336. {
  337. if (maid == null || maid.body0 == null || !maid.body0.isLoadedBody)
  338. {
  339. this.script_mgr_.StopMotionScript();
  340. return;
  341. }
  342. if (!boAddQue)
  343. {
  344. WaitEventList waitEventList = base.GetWaitEventList("motion_script");
  345. waitEventList.Clear();
  346. }
  347. this.script_mgr_.StopMotionScript();
  348. base.PlayMaidMotion(maid, fn, additive, loop, boAddQue, val);
  349. }
  350. public void SetSettingSkipMode(bool is_skip)
  351. {
  352. this.skip_mode_ = is_skip;
  353. }
  354. public bool GetSettingSkipMode()
  355. {
  356. return this.skip_mode_;
  357. }
  358. public bool skip_mode
  359. {
  360. get
  361. {
  362. return this.skip_mode_ || GameMain.Instance.IsForceSkip();
  363. }
  364. }
  365. public bool auto_mode { get; set; }
  366. public bool vr_commu_mode { get; set; }
  367. public int auto_wait_count
  368. {
  369. get
  370. {
  371. return (100 - GameMain.Instance.CMSystem.MsgAutoSpeed) * 30;
  372. }
  373. }
  374. public Dictionary<string, string> tag_backup
  375. {
  376. get
  377. {
  378. return this.tag_backup_;
  379. }
  380. }
  381. public override string GetKagClassName()
  382. {
  383. return "ADV kag";
  384. }
  385. public MessageWindowMgr MessageWindowMgr
  386. {
  387. get
  388. {
  389. return this.message_mgr_;
  390. }
  391. }
  392. private bool skip_mode_;
  393. private MessageWindowMgr message_mgr_;
  394. private ADVKagManager.TextData text_data_;
  395. private List<KeyValuePair<string, KeyValuePair<string, bool>>> choise_data_ = new List<KeyValuePair<string, KeyValuePair<string, bool>>>();
  396. private List<KeyValuePair<string, KeyValuePair<string, bool>>> choise_random_data_ = new List<KeyValuePair<string, KeyValuePair<string, bool>>>();
  397. private ulong update_count_;
  398. private Dictionary<string, string> tag_backup_ = new Dictionary<string, string>();
  399. protected struct TextData
  400. {
  401. public string talk_name;
  402. public string text;
  403. public string voice_file;
  404. public string vice_name;
  405. public Maid voice_maid;
  406. }
  407. }