MotionWindow.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public class MotionWindow : BaseMaidPhotoWindow
  6. {
  7. public override void Awake()
  8. {
  9. base.Awake();
  10. PhotoMotionData.Create();
  11. this.noCharaActive = base.GetComponentInChildren<PhotoNoCharaActive>();
  12. Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
  13. Dictionary<string, List<KeyValuePair<string, object>>> dictionary2 = new Dictionary<string, List<KeyValuePair<string, object>>>();
  14. foreach (KeyValuePair<string, List<PhotoMotionData>> keyValuePair in PhotoMotionData.category_list)
  15. {
  16. if (!dictionary2.ContainsKey(keyValuePair.Key))
  17. {
  18. dictionary2.Add(keyValuePair.Key, new List<KeyValuePair<string, object>>());
  19. dictionary.Add(keyValuePair.Key, new List<string>());
  20. }
  21. for (int i = 0; i < keyValuePair.Value.Count; i++)
  22. {
  23. dictionary2[keyValuePair.Key].Add(new KeyValuePair<string, object>(keyValuePair.Value[i].name, keyValuePair.Value[i]));
  24. dictionary[keyValuePair.Key].Add(keyValuePair.Value[i].nameTerm);
  25. }
  26. }
  27. if (!GameUty.supportMultiLanguage)
  28. {
  29. dictionary = null;
  30. }
  31. this.PopupAndTabList.SetData(dictionary2, dictionary, true);
  32. this.PopupAndTabList.onChangePopUpListValue.Add(new Action<KeyValuePair<string, UnityEngine.Object>>(this.OnChangePopUpList));
  33. this.PopupAndTabList.onSelect.Add(new Action<object>(this.OnSelectItem));
  34. UTY.GetChildObject(this.content_game_object, "ListParent/DragMat", false).GetComponent<BoxCollider>().enabled = false;
  35. }
  36. public override void Start()
  37. {
  38. base.Start();
  39. this.noCharaActive.ChangeMode(true, true);
  40. this.pose_edit_window_ = (base.mgr.GetWindow(PhotoWindowManager.WindowType.PoseEdit) as PoseEditWindow);
  41. this.UpdateChildren();
  42. this.Slider.onChangeValue.Add(new Action<float>(this.OnChangeMotionSlider));
  43. this.CheckbtnStop.onClick.Add(new Action<WFCheckBox>(this.OnClickStopCheck));
  44. this.UpdateAnimationData(null);
  45. this.CopyAndPasteBtn.onCopyEvent.Add(delegate(StringWriter writer)
  46. {
  47. if (this.anime_state_ == null)
  48. {
  49. return;
  50. }
  51. writer.WriteLine(this.CheckbtnStop.check);
  52. writer.WriteLine(this.anime_state_.time);
  53. });
  54. this.CopyAndPasteBtn.onPasteEvent.Add(delegate(StringReader reader)
  55. {
  56. if (this.anime_state_ == null)
  57. {
  58. return;
  59. }
  60. this.CheckbtnStop.check = bool.Parse(reader.ReadLine());
  61. float num = float.Parse(reader.ReadLine());
  62. this.OnClickStopCheck(this.CheckbtnStop);
  63. if (this.CheckbtnStop.check)
  64. {
  65. if (this.Slider.MaxNum < num)
  66. {
  67. num = this.Slider.MaxNum;
  68. }
  69. this.Slider.value = num;
  70. this.anime_state_.enabled = true;
  71. this.animation_.Sample();
  72. this.anime_state_.enabled = false;
  73. }
  74. });
  75. }
  76. public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
  77. {
  78. base.OnMaidAddEvent(maid, is_deserialize_load);
  79. PhotoMotionData photoMotionData = maid.boMAN ? PhotoMotionData.init_data_for_man : PhotoMotionData.init_data;
  80. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(maid);
  81. if (!is_deserialize_load)
  82. {
  83. maidStoreData.Clear();
  84. maidStoreData.Add("id", photoMotionData.id.ToString());
  85. }
  86. if (!maidStoreData.ContainsKey("is_stop"))
  87. {
  88. maidStoreData.Add("is_stop", false.ToString());
  89. }
  90. if (!maidStoreData.ContainsKey("time"))
  91. {
  92. maidStoreData.Add("time", 0f.ToString());
  93. }
  94. photoMotionData = PhotoMotionData.Get(long.Parse(maidStoreData["id"]));
  95. this.Apply(photoMotionData, maid);
  96. }
  97. public new void Update()
  98. {
  99. if (this.anime_state_ == null || this.animation_ == null)
  100. {
  101. return;
  102. }
  103. float value = this.anime_state_.time;
  104. if (this.anime_state_.length < this.anime_state_.time)
  105. {
  106. if (this.anime_state_.wrapMode == WrapMode.ClampForever)
  107. {
  108. value = this.anime_state_.length;
  109. }
  110. else
  111. {
  112. value = this.anime_state_.time - this.anime_state_.length * (float)((int)(this.anime_state_.time / this.anime_state_.length));
  113. }
  114. }
  115. this.is_update_ = true;
  116. this.Slider.value = value;
  117. this.is_update_ = false;
  118. }
  119. public void OnChangeMotionSlider(float val)
  120. {
  121. if (this.is_update_ || this.anime_state_ == null)
  122. {
  123. return;
  124. }
  125. float time = this.anime_state_.time;
  126. this.anime_state_.time = val;
  127. this.anime_state_.enabled = true;
  128. if (base.mgr.select_maid != null)
  129. {
  130. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
  131. maidStoreData["time"] = val.ToString("G9");
  132. }
  133. this.animation_.Sample();
  134. if (this.CheckbtnStop.check)
  135. {
  136. this.anime_state_.enabled = false;
  137. }
  138. if (time != val)
  139. {
  140. this.pose_edit_window_.OnMotionUpdate(base.mgr.select_maid);
  141. }
  142. }
  143. public void OnClickStopCheck(WFCheckBox check_box)
  144. {
  145. if (base.mgr.select_maid == null || this.anime_state_ == null)
  146. {
  147. return;
  148. }
  149. if (!check_box.check && this.pose_edit_window_.CheckbtnUse.check)
  150. {
  151. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/ポーズ/ポーズエディットのセーブしていないデータは失われます。OFFにしますか?", null, SystemDialog.TYPE.YES_NO, delegate
  152. {
  153. this.pose_edit_window_.CheckbtnUse.check = false;
  154. this.pose_edit_window_.OnClickUseCheckRun(false);
  155. GameMain.Instance.SysDlg.Close();
  156. check_box.check = false;
  157. this.OnClickStopCheckRun(check_box.check);
  158. }, null);
  159. check_box.check = true;
  160. }
  161. else
  162. {
  163. this.OnClickStopCheckRun(check_box.check);
  164. }
  165. }
  166. public void OnClickStopCheckRun(bool check)
  167. {
  168. if (!check)
  169. {
  170. this.anime_state_.enabled = true;
  171. }
  172. else
  173. {
  174. this.anime_state_.enabled = false;
  175. }
  176. if (base.mgr.select_maid != null)
  177. {
  178. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
  179. maidStoreData["is_stop"] = check.ToString();
  180. float num = this.anime_state_.time;
  181. if (this.anime_state_.length < this.anime_state_.time)
  182. {
  183. if (this.anime_state_.wrapMode == WrapMode.ClampForever)
  184. {
  185. num = this.anime_state_.length;
  186. }
  187. else
  188. {
  189. num = this.anime_state_.time - this.anime_state_.length * (float)((int)(this.anime_state_.time / this.anime_state_.length));
  190. }
  191. }
  192. maidStoreData["time"] = num.ToString("G9");
  193. }
  194. }
  195. public override void OnMaidChangeEvent(Maid maid)
  196. {
  197. base.OnMaidChangeEvent(maid);
  198. this.PopupAndTabList.ResetSelect();
  199. this.noCharaActive.ChangeMode(maid == null, true);
  200. if (maid == null)
  201. {
  202. UTY.GetChildObject(this.content_game_object, "ListParent/DragMat", false).GetComponent<BoxCollider>().enabled = false;
  203. this.PopupAndTabList.popup_term_list = null;
  204. this.PopupAndTabList.popup_value_list = null;
  205. this.PopupAndTabList.SetPopupValue(this.PopupAndTabList.popup_value_list[0].Key);
  206. }
  207. else
  208. {
  209. UTY.GetChildObject(this.content_game_object, "ListParent/DragMat", false).GetComponent<BoxCollider>().enabled = true;
  210. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(maid);
  211. PhotoMotionData photoMotionData = PhotoMotionData.Get(long.Parse(maidStoreData["id"]));
  212. this.PopupAndTabList.popup_term_list = ((!GameUty.supportMultiLanguage) ? null : (maid.boMAN ? PhotoMotionData.popup_category_term_list_for_man : PhotoMotionData.popup_category_term_list));
  213. this.PopupAndTabList.popup_value_list = (maid.boMAN ? PhotoMotionData.popup_category_list_for_man : PhotoMotionData.popup_category_list);
  214. this.PopupAndTabList.SetPopupValue(photoMotionData.category);
  215. this.PopupAndTabList.SetSelectButton(photoMotionData, false);
  216. }
  217. this.UpdateAnimationData(maid);
  218. }
  219. protected void OnChangePopUpList(KeyValuePair<string, UnityEngine.Object> popup_val)
  220. {
  221. }
  222. public override void OnDeserializeEvent()
  223. {
  224. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  225. List<string> maidStoreGuidList = base.mgr.GetMaidStoreGuidList();
  226. for (int i = 0; i < maidStoreGuidList.Count; i++)
  227. {
  228. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(maidStoreGuidList[i]);
  229. if (maidStoreData.Count != 0)
  230. {
  231. bool flag = false;
  232. int num = 0;
  233. while (num < characterMgr.GetManCount() && !flag)
  234. {
  235. if (characterMgr.GetMan(num) != null && characterMgr.GetMan(num).status.guid == maidStoreGuidList[i])
  236. {
  237. flag = true;
  238. }
  239. num++;
  240. }
  241. PhotoMotionData photoMotionData = PhotoMotionData.Get(long.Parse(maidStoreData["id"]));
  242. if (photoMotionData == null)
  243. {
  244. photoMotionData = (flag ? PhotoMotionData.init_data_for_man : PhotoMotionData.init_data);
  245. }
  246. maidStoreData["id"] = photoMotionData.id.ToString();
  247. }
  248. }
  249. }
  250. private void OnSelectItem(object select_data_obj)
  251. {
  252. if (base.mgr.select_maid == null || select_data_obj == null)
  253. {
  254. return;
  255. }
  256. PhotoMotionData photoMotionData = select_data_obj as PhotoMotionData;
  257. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
  258. maidStoreData["id"] = photoMotionData.id.ToString();
  259. maidStoreData["time"] = 0f.ToString();
  260. this.Apply(photoMotionData, base.mgr.select_maid);
  261. }
  262. public void Apply(PhotoMotionData motion_data, Maid target_maid)
  263. {
  264. motion_data.Apply(target_maid);
  265. this.UpdateAnimationData(target_maid);
  266. this.pose_edit_window_.OnMotionUpdate(target_maid);
  267. }
  268. public bool AddMyPose(string full_path)
  269. {
  270. PhotoMotionData photoMotionData = PhotoMotionData.AddMyPose(full_path);
  271. if (photoMotionData != null)
  272. {
  273. this.PopupAndTabList.AddData("マイポーズ", new KeyValuePair<string, object>(photoMotionData.name, photoMotionData));
  274. }
  275. return photoMotionData != null;
  276. }
  277. public void OnUpdateMyPose(string full_path)
  278. {
  279. List<PhotoMotionData> list = PhotoMotionData.category_list["マイポーズ"];
  280. PhotoMotionData photoMotionData = null;
  281. for (int i = 0; i < list.Count; i++)
  282. {
  283. if (list[i].direct_file == full_path)
  284. {
  285. photoMotionData = list[i];
  286. break;
  287. }
  288. }
  289. if (photoMotionData == null)
  290. {
  291. Debug.LogError("モーションデータがnullです");
  292. return;
  293. }
  294. Dictionary<string, PhotoMotionData> dictionary = new Dictionary<string, PhotoMotionData>();
  295. List<string> maidStoreGuidList = base.mgr.GetMaidStoreGuidList();
  296. for (int j = 0; j < maidStoreGuidList.Count; j++)
  297. {
  298. Dictionary<string, string> maidStoreData = base.mgr.GetMaidStoreData(maidStoreGuidList[j], this);
  299. Dictionary<string, string> maidStoreData2 = base.mgr.GetMaidStoreData(maidStoreGuidList[j], base.mgr.GetWindow(PhotoWindowManager.WindowType.PoseEdit));
  300. if (maidStoreData.Count > 0 && maidStoreData2.Count > 0)
  301. {
  302. if (!bool.Parse(maidStoreData2["use"]) && long.Parse(maidStoreData["id"]) == photoMotionData.id)
  303. {
  304. photoMotionData.Apply(GameMain.Instance.CharacterMgr.GetMaid(maidStoreGuidList[j]));
  305. }
  306. }
  307. }
  308. }
  309. public void UpdateAnimationData(Maid target_maid)
  310. {
  311. if (target_maid != null && target_maid.body0 != null && target_maid.body0 != null && target_maid.body0.m_Bones.GetComponent<Animation>() != null)
  312. {
  313. this.animation_ = target_maid.body0.m_Bones.GetComponent<Animation>();
  314. this.anime_state_ = this.animation_[target_maid.body0.LastAnimeFN.ToLower()];
  315. if (this.anime_state_.length == 0f)
  316. {
  317. this.CopyAndPasteBtn.enabled = false;
  318. WFCheckBox checkbtnStop = this.CheckbtnStop;
  319. bool flag = false;
  320. this.CheckbtnStop.check = flag;
  321. checkbtnStop.enabled = flag;
  322. this.Slider.enabled = false;
  323. this.animation_ = null;
  324. this.anime_state_ = null;
  325. this.Slider.MaxNum = 1f;
  326. this.Slider.value = 0f;
  327. }
  328. else
  329. {
  330. Dictionary<string, string> maidStoreData = base.GetMaidStoreData(target_maid);
  331. this.Slider.enabled = true;
  332. this.Slider.MaxNum = this.anime_state_.length;
  333. if (this.anime_state_.wrapMode == WrapMode.Once)
  334. {
  335. this.anime_state_.wrapMode = WrapMode.ClampForever;
  336. }
  337. this.CopyAndPasteBtn.enabled = true;
  338. this.CheckbtnStop.enabled = true;
  339. this.CheckbtnStop.check = bool.Parse(maidStoreData["is_stop"]);
  340. if (this.CheckbtnStop.check)
  341. {
  342. this.OnClickStopCheck(this.CheckbtnStop);
  343. this.Slider.value = float.Parse(maidStoreData["time"]);
  344. this.anime_state_.enabled = true;
  345. this.animation_.Sample();
  346. this.anime_state_.enabled = false;
  347. }
  348. }
  349. }
  350. else
  351. {
  352. this.CopyAndPasteBtn.enabled = false;
  353. WFCheckBox checkbtnStop2 = this.CheckbtnStop;
  354. bool flag = false;
  355. this.CheckbtnStop.check = flag;
  356. checkbtnStop2.enabled = flag;
  357. this.Slider.enabled = false;
  358. this.animation_ = null;
  359. this.anime_state_ = null;
  360. this.Slider.MaxNum = 1f;
  361. this.Slider.value = 0f;
  362. }
  363. }
  364. public PopupAndTabList PopupAndTabList;
  365. public WFCheckBox CheckbtnStop;
  366. public PhotoSliderAndInput Slider;
  367. public WindowPartsInputSliderSet CopyAndPasteBtn;
  368. private PhotoNoCharaActive noCharaActive;
  369. private PoseEditWindow pose_edit_window_;
  370. private Animation animation_;
  371. private AnimationState anime_state_;
  372. private bool is_update_;
  373. }