WindowPartsFingerPreset.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Xml.Linq;
  5. using UnityEngine;
  6. using wf;
  7. public class WindowPartsFingerPreset : MonoBehaviour
  8. {
  9. public void Awake()
  10. {
  11. this.PresetLoad.CheckBoxPresetVisibleSwitch.check = false;
  12. this.PresetLoad.CheckBoxPresetVisibleSwitch.onClick.Add(new Action<WFCheckBox>(this.OnClickPresetSwitch));
  13. for (int i = 0; i < this.PresetSaveBtnDataArray.Length; i++)
  14. {
  15. EventDelegate.Add(this.PresetSaveBtnDataArray[i].btn.onClick, new EventDelegate.Callback(this.OnClickPresetSave));
  16. }
  17. if (this.RightCopyToLeft != null)
  18. {
  19. EventDelegate.Add(this.RightCopyToLeft.onClick, new EventDelegate.Callback(this.OnClickRightCopyToLeft));
  20. EventDelegate eventDelegate = new EventDelegate(this, "OnBtnMouseHoverIn");
  21. eventDelegate.parameters[0].value = "左へコピー";
  22. this.RightCopyToLeft.gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate);
  23. EventDelegate.Add(this.RightCopyToLeft.gameObject.GetComponent<UIEventTrigger>().onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
  24. }
  25. if (this.LeftCopyToRight != null)
  26. {
  27. EventDelegate.Add(this.LeftCopyToRight.onClick, new EventDelegate.Callback(this.OnClickLeftCopyToLeft));
  28. EventDelegate eventDelegate2 = new EventDelegate(this, "OnBtnMouseHoverIn");
  29. eventDelegate2.parameters[0].value = "右へコピー";
  30. this.LeftCopyToRight.gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate2);
  31. EventDelegate.Add(this.LeftCopyToRight.gameObject.GetComponent<UIEventTrigger>().onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
  32. }
  33. if (this.Swap != null)
  34. {
  35. EventDelegate.Add(this.Swap.onClick, new EventDelegate.Callback(this.OnClickSwap));
  36. EventDelegate eventDelegate3 = new EventDelegate(this, "OnBtnMouseHoverIn");
  37. eventDelegate3.parameters[0].value = "交換";
  38. this.Swap.gameObject.GetComponent<UIEventTrigger>().onHoverOver.Add(eventDelegate3);
  39. EventDelegate.Add(this.Swap.gameObject.GetComponent<UIEventTrigger>().onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
  40. }
  41. }
  42. public void Start()
  43. {
  44. this.OnClickPresetSwitch(this.PresetLoad.CheckBoxPresetVisibleSwitch);
  45. }
  46. public void OnClickPresetSwitch(WFCheckBox check_box)
  47. {
  48. if (check_box.check)
  49. {
  50. this.PresetLoad.PresetList.SetActive(true);
  51. foreach (GameObject gameObject in this.HideObjectArray)
  52. {
  53. gameObject.SetActive(false);
  54. }
  55. this.UpdatePresetList();
  56. }
  57. else
  58. {
  59. this.PresetLoad.PresetList.SetActive(false);
  60. foreach (GameObject gameObject2 in this.HideObjectArray)
  61. {
  62. gameObject2.SetActive(true);
  63. }
  64. }
  65. }
  66. private void UpdatePresetList()
  67. {
  68. if (this.PresetLoad.Grid == null)
  69. {
  70. return;
  71. }
  72. UIGrid grid = this.PresetLoad.Grid;
  73. List<Transform> childList = grid.GetChildList();
  74. for (int i = 0; i < childList.Count; i++)
  75. {
  76. UnityEngine.Object.DestroyImmediate(childList[i].gameObject);
  77. }
  78. Action<string, List<string>> action = delegate(string path, List<string> result_list)
  79. {
  80. string[] files = Directory.GetFiles(path);
  81. for (int j = 0; j < files.Length; j++)
  82. {
  83. if (Path.GetExtension(files[j]) == ".xml")
  84. {
  85. result_list.Add(files[j]);
  86. }
  87. }
  88. };
  89. List<string> list = new List<string>();
  90. action(this.GetFolderPath(this.PresetLoad.type), list);
  91. foreach (string path2 in list)
  92. {
  93. GameObject gameObject = Utility.CreatePrefab(grid.gameObject, "ScenePhotoMode/WindowListItemFingerPresetButton", true);
  94. gameObject.name = Path.GetFileNameWithoutExtension(path2);
  95. UTY.GetChildObject(gameObject, "Text", false).GetComponent<UILabel>().text = gameObject.name;
  96. EventDelegate.Add(UTY.GetChildObject(gameObject, "LeftBtn", false).GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnClickPresetBtnLeft));
  97. UTY.GetChildObject(gameObject, "LeftBtn", false).name = gameObject.name;
  98. EventDelegate.Add(UTY.GetChildObject(gameObject, "RightBtn", false).GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnClickPresetBtnRight));
  99. UTY.GetChildObject(gameObject, "RightBtn", false).name = gameObject.name;
  100. }
  101. grid.Reposition();
  102. NGUITools.FindInParents<UIScrollView>(grid.transform).ResetPosition();
  103. }
  104. public void OnClickPresetBtnRight()
  105. {
  106. this.OnClickPresetBtn(this.PresetLoad.right_blend);
  107. }
  108. public void OnClickPresetBtnLeft()
  109. {
  110. this.OnClickPresetBtn(this.PresetLoad.left_blend);
  111. }
  112. public void OnClickPresetBtn(WindowPartsFingerBlend target)
  113. {
  114. string name = UIButton.current.name;
  115. string text = this.GetFolderPath(this.PresetLoad.type) + "/" + name + ".xml";
  116. if (!File.Exists(text))
  117. {
  118. return;
  119. }
  120. XDocument xdocument = XDocument.Load(text);
  121. XElement xelement = xdocument.Element("FingerData");
  122. if (xelement.IsEmpty || xelement.Element("GameVersion").IsEmpty || xelement.Element("RightData").IsEmpty || xelement.Element("BinaryData").IsEmpty)
  123. {
  124. return;
  125. }
  126. bool flag = bool.Parse(xelement.Element("RightData").Value);
  127. string value = xelement.Element("BinaryData").Value;
  128. bool mirroring;
  129. if (flag)
  130. {
  131. mirroring = (target.BlendType != WindowPartsFingerBlend.Type.RightArm && target.BlendType != WindowPartsFingerBlend.Type.RightLeg);
  132. }
  133. else
  134. {
  135. mirroring = (target.BlendType != WindowPartsFingerBlend.Type.LeftArm && target.BlendType != WindowPartsFingerBlend.Type.LeftLeg);
  136. }
  137. target.ApplyPresetData(value, mirroring, true);
  138. }
  139. private void OnClickRightCopyToLeft()
  140. {
  141. FingerBlend.BaseFinger baseFingerClass = this.RightFingerBlend.GetBaseFingerClass(this.RightFingerBlend.mgr.select_maid, this.RightFingerBlend.BlendType);
  142. this.LeftFingerBlend.ApplyPresetData(Convert.ToBase64String(baseFingerClass.GetBinary()), true, true);
  143. }
  144. private void OnClickLeftCopyToLeft()
  145. {
  146. FingerBlend.BaseFinger baseFingerClass = this.LeftFingerBlend.GetBaseFingerClass(this.LeftFingerBlend.mgr.select_maid, this.LeftFingerBlend.BlendType);
  147. this.RightFingerBlend.ApplyPresetData(Convert.ToBase64String(baseFingerClass.GetBinary()), true, true);
  148. }
  149. private void OnClickSwap()
  150. {
  151. FingerBlend.BaseFinger baseFingerClass = this.RightFingerBlend.GetBaseFingerClass(this.RightFingerBlend.mgr.select_maid, this.RightFingerBlend.BlendType);
  152. string base64_text = Convert.ToBase64String(baseFingerClass.GetBinary());
  153. baseFingerClass = this.LeftFingerBlend.GetBaseFingerClass(this.LeftFingerBlend.mgr.select_maid, this.LeftFingerBlend.BlendType);
  154. string base64_text2 = Convert.ToBase64String(baseFingerClass.GetBinary());
  155. this.LeftFingerBlend.ApplyPresetData(base64_text, true, false);
  156. this.RightFingerBlend.ApplyPresetData(base64_text2, true, true);
  157. }
  158. private void OnClickPresetSave()
  159. {
  160. foreach (WindowPartsFingerPreset.PresetSaveData presetSaveData in this.PresetSaveBtnDataArray)
  161. {
  162. if (presetSaveData.btn == UIButton.current)
  163. {
  164. this.PresetSave(presetSaveData.window_finger_blend);
  165. break;
  166. }
  167. }
  168. }
  169. private void PresetSave(WindowPartsFingerBlend tareget_blend)
  170. {
  171. WindowPartsFingerBlend.Type blendType = tareget_blend.BlendType;
  172. FingerBlend.BaseFinger baseFingerClass = tareget_blend.GetBaseFingerClass(tareget_blend.mgr.select_maid, blendType);
  173. XElement xelement = new XElement("GameVersion", 1130);
  174. XElement xelement2 = new XElement("RightData", blendType == WindowPartsFingerBlend.Type.RightArm || blendType == WindowPartsFingerBlend.Type.RightLeg);
  175. XElement xelement3 = new XElement("BinaryData", Convert.ToBase64String(baseFingerClass.GetBinary()));
  176. XNode[] contents = new XNode[]
  177. {
  178. xelement,
  179. xelement2,
  180. xelement3
  181. };
  182. XElement xelement4 = new XElement("FingerData", contents);
  183. XDocument save_target_xml = new XDocument(new XDeclaration("1.0", "utf-8", "true"), new object[]
  184. {
  185. new XComment("CM3D2 FingerData"),
  186. xelement4
  187. });
  188. string save_dir_name = "arm";
  189. if (blendType == WindowPartsFingerBlend.Type.RightLeg || blendType == WindowPartsFingerBlend.Type.LeftLeg)
  190. {
  191. save_dir_name = "leg";
  192. }
  193. this.PoseEditWindow.PanelSave.OpenFingerSaveMode(save_target_xml, save_dir_name, null);
  194. }
  195. private void OnBtnMouseHoverIn(string text)
  196. {
  197. MouseExposition @object = MouseExposition.GetObject();
  198. @object.text = text;
  199. }
  200. private void OnMouseHoverOut()
  201. {
  202. MouseExposition @object = MouseExposition.GetObject();
  203. @object.text = string.Empty;
  204. }
  205. private string GetFolderPath(WindowPartsFingerBlend.Type type)
  206. {
  207. if (!Directory.Exists(PhotoWindowManager.path_photo_folder + "FingerData"))
  208. {
  209. Directory.CreateDirectory(PhotoWindowManager.path_photo_folder + "FingerData");
  210. }
  211. string str = "arm";
  212. if (type == WindowPartsFingerBlend.Type.RightLeg || type == WindowPartsFingerBlend.Type.LeftLeg)
  213. {
  214. str = "leg";
  215. }
  216. string text = PhotoWindowManager.path_photo_folder + "FingerData/" + str;
  217. if (!Directory.Exists(text))
  218. {
  219. Directory.CreateDirectory(text);
  220. }
  221. return text;
  222. }
  223. private string GetFolderPath(WindowPartsFingerPreset.PresetLoadData.Type type)
  224. {
  225. return this.GetFolderPath((type != WindowPartsFingerPreset.PresetLoadData.Type.Arm) ? WindowPartsFingerBlend.Type.RightLeg : WindowPartsFingerBlend.Type.RightArm);
  226. }
  227. public PoseEditWindow PoseEditWindow;
  228. public WindowPartsFingerPreset.PresetSaveData[] PresetSaveBtnDataArray;
  229. public WindowPartsFingerPreset.PresetLoadData PresetLoad;
  230. public GameObject[] HideObjectArray;
  231. public WindowPartsFingerBlend RightFingerBlend;
  232. public WindowPartsFingerBlend LeftFingerBlend;
  233. public UIButton RightCopyToLeft;
  234. public UIButton LeftCopyToRight;
  235. public UIButton Swap;
  236. [Serializable]
  237. public class PresetSaveData
  238. {
  239. public WindowPartsFingerBlend window_finger_blend;
  240. public UIButton btn;
  241. }
  242. [Serializable]
  243. public class PresetLoadData
  244. {
  245. public UIGrid Grid
  246. {
  247. get
  248. {
  249. if (this.grid_ == null)
  250. {
  251. this.grid_ = this.PresetList.GetComponentInChildren<UIGrid>();
  252. }
  253. return this.grid_;
  254. }
  255. }
  256. public WindowPartsFingerPreset.PresetLoadData.Type type;
  257. public WFCheckBox CheckBoxPresetVisibleSwitch;
  258. public WindowPartsFingerBlend right_blend;
  259. public WindowPartsFingerBlend left_blend;
  260. public GameObject PresetList;
  261. private UIGrid grid_;
  262. public enum Type
  263. {
  264. Arm,
  265. Leg
  266. }
  267. }
  268. }