ADVKagManager.cs 12 KB

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