WindowPartsFingerBlend.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class WindowPartsFingerBlend : MonoBehaviour
  6. {
  7. public void Awake()
  8. {
  9. this.CheckBoxEnabled.check = false;
  10. this.CheckBoxEnabled.onClick.Add(new Action<WFCheckBox>(this.OnClickFingerBlendEnabled));
  11. this.InputFingerBlend.enabled = false;
  12. this.InputFingerBlend.onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetBlendValue));
  13. this.BtnEnter.isEnabled = false;
  14. EventDelegate.Add(this.BtnEnter.onClick, new EventDelegate.Callback(this.OnClickEnter));
  15. for (int i = 0; i < this.FingerLockCheckBox.Length; i++)
  16. {
  17. WFCheckBox wfcheckBox = this.FingerLockCheckBox[i];
  18. bool flag = false;
  19. this.FingerLockCheckBox[i].enabled = flag;
  20. wfcheckBox.check = flag;
  21. this.FingerLockCheckBox[i].onClick.Add(new Action<WFCheckBox>(this.OnClickFingerLockCheckBox));
  22. }
  23. }
  24. public void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
  25. {
  26. if (this.pose_edit_window_ == null)
  27. {
  28. this.pose_edit_window_ = (this.mgr.GetWindow(PhotoWindowManager.WindowType.PoseEdit) as PoseEditWindow);
  29. }
  30. Dictionary<string, string> maidStoreData = this.pose_edit_window_.GetMaidStoreData(maid);
  31. if (!maidStoreData.ContainsKey(this.store_str_enabled))
  32. {
  33. maidStoreData[this.store_str_enabled] = false.ToString();
  34. }
  35. if (!maidStoreData.ContainsKey(this.store_str_backup))
  36. {
  37. maidStoreData[this.store_str_backup] = string.Empty;
  38. }
  39. if (!maidStoreData.ContainsKey(this.store_str_value))
  40. {
  41. maidStoreData[this.store_str_value] = Vector2.zero.ToString("G9");
  42. }
  43. for (int i = 0; i < this.FingerLockCheckBox.Length; i++)
  44. {
  45. if (!maidStoreData.ContainsKey(this.store_str_lockvalue + int.Parse(this.FingerLockCheckBox[i].name)))
  46. {
  47. maidStoreData[this.store_str_lockvalue + this.FingerLockCheckBox[i].name] = string.Empty;
  48. }
  49. }
  50. }
  51. public void ChangeEnabeled(bool use)
  52. {
  53. if (!use || this.mgr.select_maid == null)
  54. {
  55. WFCheckBox checkBoxEnabled = this.CheckBoxEnabled;
  56. bool flag = false;
  57. this.InputFingerBlend.enabled = flag;
  58. flag = flag;
  59. this.CheckBoxEnabled.enabled = flag;
  60. checkBoxEnabled.check = flag;
  61. PhotoSliderAndInput sliderAndInput = this.InputFingerBlend.GetSliderAndInput("x");
  62. float value = 0f;
  63. this.InputFingerBlend.GetSliderAndInput("y").value = value;
  64. sliderAndInput.value = value;
  65. return;
  66. }
  67. this.CheckBoxEnabled.enabled = true;
  68. this.CheckBoxEnabled.check = bool.Parse(this.pose_edit_window_.GetMaidStoreData(this.mgr.select_maid)[this.store_str_enabled]);
  69. this.OnClickFingerBlendEnabled(this.CheckBoxEnabled);
  70. }
  71. public void OnMotionUpdate()
  72. {
  73. if (this.mgr.select_maid == null)
  74. {
  75. return;
  76. }
  77. if (this.CheckBoxEnabled.check)
  78. {
  79. this.CheckBoxEnabled.check = false;
  80. this.OnClickFingerBlendEnabled(this.CheckBoxEnabled);
  81. }
  82. }
  83. public void OnClickFingerBlendEnabled(WFCheckBox check_box)
  84. {
  85. if (this.mgr.select_maid == null)
  86. {
  87. WindowPartsInputSliderSet inputFingerBlend = this.InputFingerBlend;
  88. bool flag = false;
  89. this.BtnEnter.isEnabled = flag;
  90. inputFingerBlend.enabled = flag;
  91. for (int i = 0; i < this.FingerLockCheckBox.Length; i++)
  92. {
  93. this.FingerLockCheckBox[i].enabled = false;
  94. }
  95. return;
  96. }
  97. if (this.OnClickFingerBlendEnabledEvent != null)
  98. {
  99. this.OnClickFingerBlendEnabledEvent(this.BlendType, check_box.check);
  100. }
  101. Dictionary<string, string> maidStoreData = this.pose_edit_window_.GetMaidStoreData(this.mgr.select_maid);
  102. FingerBlend finger_blend = this.pose_edit_window_.ik_mgr.finger_blend;
  103. FingerBlend.BaseFinger baseFingerClass = this.GetBaseFingerClass(this.mgr.select_maid, this.BlendType);
  104. maidStoreData[this.store_str_enabled] = check_box.check.ToString();
  105. WindowPartsInputSliderSet inputFingerBlend2 = this.InputFingerBlend;
  106. bool check = check_box.check;
  107. this.BtnEnter.isEnabled = check;
  108. inputFingerBlend2.enabled = check;
  109. for (int j = 0; j < this.FingerLockCheckBox.Length; j++)
  110. {
  111. WFCheckBox wfcheckBox = this.FingerLockCheckBox[j];
  112. check = check_box.check;
  113. this.FingerLockCheckBox[j].check = check;
  114. wfcheckBox.enabled = check;
  115. }
  116. if (check_box.check && string.IsNullOrEmpty(maidStoreData[this.store_str_backup]))
  117. {
  118. maidStoreData[this.store_str_backup] = Convert.ToBase64String(baseFingerClass.GetBinary());
  119. }
  120. else
  121. {
  122. if (!string.IsNullOrEmpty(maidStoreData[this.store_str_backup]))
  123. {
  124. byte[] data_byte = Convert.FromBase64String(maidStoreData[this.store_str_backup]);
  125. baseFingerClass.SetBinary(data_byte, false);
  126. }
  127. if (!check_box.check)
  128. {
  129. maidStoreData[this.store_str_backup] = string.Empty;
  130. }
  131. }
  132. Vector2 vector = Parse.Vector2(maidStoreData[this.store_str_value]);
  133. this.InputFingerBlend.GetSliderAndInput("x").value = vector.x;
  134. this.InputFingerBlend.GetSliderAndInput("y").value = vector.y;
  135. if (check_box.check)
  136. {
  137. for (int k = 0; k < this.FingerLockCheckBox.Length; k++)
  138. {
  139. string key = this.store_str_lockvalue + this.FingerLockCheckBox[k].name;
  140. this.FingerLockCheckBox[k].check = !string.IsNullOrEmpty(maidStoreData[key]);
  141. }
  142. }
  143. this.Apply();
  144. }
  145. public void OnClickFingerLockCheckBox(WFCheckBox check_box)
  146. {
  147. if (this.mgr.select_maid == null)
  148. {
  149. return;
  150. }
  151. Dictionary<string, string> maidStoreData = this.pose_edit_window_.GetMaidStoreData(this.mgr.select_maid);
  152. if (!check_box.check)
  153. {
  154. maidStoreData[this.store_str_lockvalue + check_box.name] = string.Empty;
  155. }
  156. else if (string.IsNullOrEmpty(maidStoreData[this.store_str_lockvalue + check_box.name]))
  157. {
  158. Dictionary<string, string> dictionary = maidStoreData;
  159. string key = this.store_str_lockvalue + check_box.name;
  160. Vector2 vector = new Vector2(this.InputFingerBlend.GetSliderAndInput("x").value, this.InputFingerBlend.GetSliderAndInput("y").value);
  161. dictionary[key] = vector.ToString();
  162. }
  163. this.Apply();
  164. }
  165. public void OnChangetBlendValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
  166. {
  167. if (this.mgr == null || this.mgr.select_maid == null)
  168. {
  169. if (input_object.Object.value != 0f)
  170. {
  171. input_object.Object.value = 0f;
  172. }
  173. return;
  174. }
  175. Dictionary<string, string> maidStoreData = this.pose_edit_window_.GetMaidStoreData(this.mgr.select_maid);
  176. if (!bool.Parse(maidStoreData["use"]))
  177. {
  178. if (input_object.Object.value != 0f)
  179. {
  180. input_object.Object.value = 0f;
  181. }
  182. return;
  183. }
  184. Vector2 vector = Parse.Vector2(maidStoreData[this.store_str_value]);
  185. if (input_object.Name == "x")
  186. {
  187. vector.x = val;
  188. }
  189. else
  190. {
  191. vector.y = val;
  192. }
  193. maidStoreData[this.store_str_value] = vector.ToString("G9");
  194. this.Apply();
  195. }
  196. public void OnClickEnter()
  197. {
  198. if (this.mgr.select_maid == null || !this.BtnEnter.isEnabled)
  199. {
  200. return;
  201. }
  202. Dictionary<string, string> maidStoreData = this.pose_edit_window_.GetMaidStoreData(this.mgr.select_maid);
  203. maidStoreData[this.store_str_backup] = string.Empty;
  204. this.CheckBoxEnabled.check = false;
  205. this.OnClickFingerBlendEnabled(this.CheckBoxEnabled);
  206. this.pose_edit_window_.ik_mgr.HistoryPush();
  207. }
  208. public void ApplyPresetData(string base64_text, bool mirroring, bool history_push = true)
  209. {
  210. FingerBlend.BaseFinger baseFingerClass = this.GetBaseFingerClass(this.mgr.select_maid, this.BlendType);
  211. try
  212. {
  213. byte[] data_byte = Convert.FromBase64String(base64_text);
  214. baseFingerClass.SetBinary(data_byte, mirroring);
  215. if (history_push)
  216. {
  217. this.pose_edit_window_.ik_mgr.HistoryPush();
  218. }
  219. Dictionary<string, string> maidStoreData = this.pose_edit_window_.GetMaidStoreData(this.mgr.select_maid);
  220. maidStoreData[this.store_str_backup] = string.Empty;
  221. this.CheckBoxEnabled.check = false;
  222. this.OnClickFingerBlendEnabled(this.CheckBoxEnabled);
  223. }
  224. catch
  225. {
  226. }
  227. }
  228. public void Apply()
  229. {
  230. if (this.mgr.select_maid == null)
  231. {
  232. return;
  233. }
  234. Dictionary<string, string> maidStoreData = this.pose_edit_window_.GetMaidStoreData(this.mgr.select_maid);
  235. if (!bool.Parse(maidStoreData["use"]))
  236. {
  237. return;
  238. }
  239. FingerBlend.BaseFinger baseFingerClass = this.GetBaseFingerClass(this.mgr.select_maid, this.BlendType);
  240. baseFingerClass.enabled = bool.Parse(maidStoreData[this.store_str_enabled]);
  241. if (baseFingerClass.enabled)
  242. {
  243. for (int i = 0; i < this.FingerLockCheckBox.Length; i++)
  244. {
  245. int value_no = int.Parse(this.FingerLockCheckBox[i].name);
  246. if (this.FingerLockCheckBox[i].check)
  247. {
  248. string text = maidStoreData[this.store_str_lockvalue + this.FingerLockCheckBox[i].name];
  249. if (string.IsNullOrEmpty(text))
  250. {
  251. this.FingerLockCheckBox[i].check = false;
  252. baseFingerClass.LockSingleItem(false, value_no);
  253. }
  254. else
  255. {
  256. Vector2 value = Parse.Vector2(text);
  257. baseFingerClass.LockSingleItemValue(true, value_no, value);
  258. }
  259. }
  260. else
  261. {
  262. baseFingerClass.LockSingleItem(false, value_no);
  263. }
  264. }
  265. Vector2 vector = Parse.Vector2(maidStoreData[this.store_str_value]);
  266. baseFingerClass.value_open = vector.x;
  267. baseFingerClass.value_fist = vector.y;
  268. baseFingerClass.Apply();
  269. }
  270. }
  271. public string store_str_enabled
  272. {
  273. get
  274. {
  275. return "finger_blend_enabled_" + this.BlendType.ToString();
  276. }
  277. }
  278. public string store_str_backup
  279. {
  280. get
  281. {
  282. return "finger_blend_backup_" + this.BlendType.ToString();
  283. }
  284. }
  285. public string store_str_value
  286. {
  287. get
  288. {
  289. return "finger_blend_value_" + this.BlendType.ToString();
  290. }
  291. }
  292. public string store_str_lockvalue
  293. {
  294. get
  295. {
  296. return "finger_blend_lockvalue_" + this.BlendType.ToString();
  297. }
  298. }
  299. public FingerBlend.BaseFinger GetBaseFingerClass(Maid maid, WindowPartsFingerBlend.Type type)
  300. {
  301. Dictionary<string, string> maidStoreData = this.pose_edit_window_.GetMaidStoreData(maid);
  302. FingerBlend finger_blend = this.pose_edit_window_.ik_mgr.finger_blend;
  303. FingerBlend.BaseFinger result = null;
  304. if (type == WindowPartsFingerBlend.Type.RightArm)
  305. {
  306. result = finger_blend.right_arm_finger;
  307. }
  308. else if (type == WindowPartsFingerBlend.Type.LeftArm)
  309. {
  310. result = finger_blend.left_arm_finger;
  311. }
  312. else if (type == WindowPartsFingerBlend.Type.RightLeg)
  313. {
  314. result = finger_blend.right_leg_finger;
  315. }
  316. else if (type == WindowPartsFingerBlend.Type.LeftLeg)
  317. {
  318. result = finger_blend.left_leg_finger;
  319. }
  320. return result;
  321. }
  322. [HideInInspector]
  323. public PhotoWindowManager mgr;
  324. public WindowPartsFingerBlend.Type BlendType;
  325. public WFCheckBox CheckBoxEnabled;
  326. public WindowPartsInputSliderSet InputFingerBlend;
  327. public UIButton BtnEnter;
  328. public Action<WindowPartsFingerBlend.Type, bool> OnClickFingerBlendEnabledEvent;
  329. public WFCheckBox[] FingerLockCheckBox;
  330. private UIGrid[] grid_array_;
  331. private PoseEditWindow pose_edit_window_;
  332. public enum Type
  333. {
  334. RightArm,
  335. LeftArm,
  336. RightLeg,
  337. LeftLeg
  338. }
  339. }