MotionWindow.cs 12 KB

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