PhotoFaceDataShortcutSetter.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using I2.Loc;
  5. using Kasizuki;
  6. using UnityEngine;
  7. public class PhotoFaceDataShortcutSetter : MonoBehaviour
  8. {
  9. public float fadeSpeed
  10. {
  11. get
  12. {
  13. return this.m_FadeSpeed;
  14. }
  15. set
  16. {
  17. this.m_FadeSpeed = Mathf.Clamp(value, 0.001f, 1f);
  18. }
  19. }
  20. private PhotoFaceDataShortcut targetControllerRight { get; set; }
  21. private PhotoFaceDataShortcut targetControllerLeft { get; set; }
  22. private PhotoFaceDataShortcut.ItemData nowSelectItem
  23. {
  24. get
  25. {
  26. return this.m_NowSelectItem;
  27. }
  28. set
  29. {
  30. this.m_NowSelectItem = value;
  31. }
  32. }
  33. public void Init(PhotoFaceDataShortcut rightHandUI, PhotoFaceDataShortcut LeftHandUI)
  34. {
  35. this.m_FadeWindowShortcutButtonsRight = this.m_ButtonListShortcutRight.GetComponent<NGUIWindow>();
  36. this.m_FadeWindowShortcutButtonsLeft = this.m_ButtonListShortcutLeft.GetComponent<NGUIWindow>();
  37. this.m_FadeWindowFaceDataList = this.m_WindowListFaceData.GetComponent<NGUIWindow>();
  38. this.targetControllerRight = rightHandUI;
  39. this.targetControllerLeft = LeftHandUI;
  40. PhotoFaceData.Create();
  41. List<PhotoFaceData> data2 = PhotoFaceData.data;
  42. ListViewerWindow windowListFaceData = this.m_WindowListFaceData;
  43. windowListFaceData.Show<PhotoFaceData, UIWFTabButton>(data2, delegate(int index, PhotoFaceData data, UIWFTabButton item)
  44. {
  45. UILabel componentInChildren = item.GetComponentInChildren<UILabel>();
  46. componentInChildren.text = data.name;
  47. componentInChildren.GetComponent<Localize>().SetTerm(data.termName);
  48. EventDelegate.Add(item.onClick, delegate()
  49. {
  50. this.OnClickData(data);
  51. });
  52. });
  53. UIWFTabPanel component = windowListFaceData.viewer.parentItemArea.GetComponent<UIWFTabPanel>();
  54. if (component)
  55. {
  56. component.UpdateChildren();
  57. }
  58. this.m_ButtonListShortcutRight.Show<Transform>(this.targetControllerRight.itemDataList.Count, delegate(int index, Transform trans)
  59. {
  60. PhotoFaceDataShortcut.ItemData data = this.targetControllerRight.itemDataList[index];
  61. UILabel componentInChildren = trans.GetComponentInChildren<UILabel>();
  62. UIButton componentInChildren2 = trans.GetComponentInChildren<UIButton>();
  63. Localize componentInChildren3 = trans.GetComponentInChildren<Localize>();
  64. componentInChildren.text = data.GetDataName();
  65. componentInChildren3.SetTerm(data.GetDataTermName());
  66. EventDelegate.Add(componentInChildren2.onClick, delegate()
  67. {
  68. this.OnClickShortcutButton(data);
  69. });
  70. PhotoFaceDataShortcutSetter.ItemData itemData = trans.gameObject.AddComponent<PhotoFaceDataShortcutSetter.ItemData>();
  71. itemData.label = componentInChildren;
  72. itemData.localize = componentInChildren3;
  73. this.m_ItemPairDic.Add(data, itemData);
  74. });
  75. this.m_ButtonListShortcutLeft.Show<Transform>(this.targetControllerLeft.itemDataList.Count, delegate(int index, Transform trans)
  76. {
  77. PhotoFaceDataShortcut.ItemData data = this.targetControllerLeft.itemDataList[index];
  78. UILabel componentInChildren = trans.GetComponentInChildren<UILabel>();
  79. UIButton componentInChildren2 = trans.GetComponentInChildren<UIButton>();
  80. Localize componentInChildren3 = trans.GetComponentInChildren<Localize>();
  81. componentInChildren.text = data.GetDataName();
  82. componentInChildren3.SetTerm(data.GetDataTermName());
  83. EventDelegate.Add(componentInChildren2.onClick, delegate()
  84. {
  85. this.OnClickShortcutButton(data);
  86. });
  87. PhotoFaceDataShortcutSetter.ItemData itemData = trans.gameObject.AddComponent<PhotoFaceDataShortcutSetter.ItemData>();
  88. itemData.label = componentInChildren;
  89. itemData.localize = componentInChildren3;
  90. this.m_ItemPairDic.Add(data, itemData);
  91. });
  92. Transform transform = this.m_ParentAddFaceOptions.transform.Find("Buttons");
  93. for (int i = 0; i < transform.childCount; i++)
  94. {
  95. WFCheckBox component2 = transform.GetChild(i).GetComponent<WFCheckBox>();
  96. component2.check = false;
  97. component2.enabled = true;
  98. this.m_AddFaceOptionDic.Add(component2.GetComponentInChildren<UILabel>().text, component2);
  99. component2.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBoxAddOption));
  100. }
  101. EventDelegate.Add(this.m_ButtonFaceListOK.onClick, new EventDelegate.Callback(this.OnClickFaceListOK));
  102. NGUIWindow fadeWindowFaceDataList = this.m_FadeWindowFaceDataList;
  103. fadeWindowFaceDataList.OnOpen = (Action)Delegate.Combine(fadeWindowFaceDataList.OnOpen, new Action(delegate()
  104. {
  105. this.m_WindowListFaceData.Reposition();
  106. }));
  107. }
  108. private void OnClickData(PhotoFaceData data)
  109. {
  110. TMorph.AddBlendType blendType = this.ConvertBlendType();
  111. this.ApplyItemData(this.nowSelectItem, data, blendType);
  112. PhotoFaceDataShortcutSetter.ItemData itemData;
  113. if (this.m_ItemPairDic != null && this.m_ItemPairDic.TryGetValue(this.nowSelectItem, out itemData))
  114. {
  115. itemData.label.text = this.nowSelectItem.GetDataName();
  116. itemData.localize.SetTerm(this.nowSelectItem.GetDataTermName());
  117. }
  118. if (this.nowSelectItem != null)
  119. {
  120. if (this.targetControllerRight.itemDataList.Contains(this.nowSelectItem))
  121. {
  122. this.targetControllerRight.Emulate(this.nowSelectItem);
  123. }
  124. else if (this.targetControllerLeft.itemDataList.Contains(this.nowSelectItem))
  125. {
  126. this.targetControllerLeft.Emulate(this.nowSelectItem);
  127. }
  128. else
  129. {
  130. Debug.LogWarning("コントローラに存在しない項目を更新しているかも");
  131. }
  132. }
  133. }
  134. private void OnClickShortcutButton(PhotoFaceDataShortcut.ItemData item)
  135. {
  136. this.nowSelectItem = item;
  137. this.m_FadeWindowShortcutButtonsRight.Close(this.fadeSpeed, null);
  138. this.m_FadeWindowShortcutButtonsLeft.Close(this.fadeSpeed, null);
  139. this.WaitTime(this.fadeSpeed, delegate
  140. {
  141. this.m_FadeWindowFaceDataList.Open(this.fadeSpeed, null);
  142. });
  143. UIWFTabPanel component = this.m_WindowListFaceData.viewer.parentItemArea.GetComponent<UIWFTabPanel>();
  144. UIWFTabButton selectButtonObject = component.GetSelectButtonObject();
  145. if (selectButtonObject != null)
  146. {
  147. selectButtonObject.SetSelect(false);
  148. }
  149. component.ResetSelect();
  150. component.UpdateChildren();
  151. this.UpdateCheckBoxAddOption(item);
  152. }
  153. private void OnClickFaceListOK()
  154. {
  155. this.m_FadeWindowFaceDataList.Close(this.fadeSpeed, null);
  156. this.WaitTime(this.fadeSpeed, delegate
  157. {
  158. this.m_FadeWindowShortcutButtonsRight.Open(this.fadeSpeed, null);
  159. this.m_FadeWindowShortcutButtonsLeft.Open(this.fadeSpeed, null);
  160. });
  161. ControllerShortcutSettingData.config.Write();
  162. }
  163. private void ApplyItemData(PhotoFaceDataShortcut.ItemData itemData, PhotoFaceData data, TMorph.AddBlendType blendType)
  164. {
  165. if (itemData == null)
  166. {
  167. Debug.Log("コントローラの項目の参照がありませんでした");
  168. return;
  169. }
  170. if (data == null)
  171. {
  172. Debug.Log("表情データがnullらしい");
  173. }
  174. itemData.data = data;
  175. itemData.blendType = blendType;
  176. itemData.isOpenMouth = this.IsOpenMouth();
  177. }
  178. private TMorph.AddBlendType ConvertBlendType()
  179. {
  180. TMorph.AddBlendType addBlendType = TMorph.AddBlendType.None;
  181. Dictionary<string, TMorph.AddBlendType> dictionary = new Dictionary<string, TMorph.AddBlendType>
  182. {
  183. {
  184. "頬染め1",
  185. TMorph.AddBlendType.Cheek1
  186. },
  187. {
  188. "頬染め2",
  189. TMorph.AddBlendType.Cheek2
  190. },
  191. {
  192. "頬染め3",
  193. TMorph.AddBlendType.Cheek3
  194. },
  195. {
  196. "涙1",
  197. TMorph.AddBlendType.Tear1
  198. },
  199. {
  200. "涙2",
  201. TMorph.AddBlendType.Tear2
  202. },
  203. {
  204. "涙3",
  205. TMorph.AddBlendType.Tear3
  206. },
  207. {
  208. "涙(玉)",
  209. TMorph.AddBlendType.TearBig
  210. },
  211. {
  212. "涎",
  213. TMorph.AddBlendType.Yodare
  214. },
  215. {
  216. "赤面",
  217. TMorph.AddBlendType.Blush
  218. },
  219. {
  220. "ショック",
  221. TMorph.AddBlendType.Shock
  222. }
  223. };
  224. foreach (KeyValuePair<string, TMorph.AddBlendType> keyValuePair in dictionary)
  225. {
  226. if (this.m_AddFaceOptionDic.ContainsKey(keyValuePair.Key) && this.m_AddFaceOptionDic[keyValuePair.Key].check)
  227. {
  228. addBlendType |= keyValuePair.Value;
  229. }
  230. }
  231. return addBlendType;
  232. }
  233. private bool IsOpenMouth()
  234. {
  235. return this.m_AddFaceOptionDic["口を開く"].check;
  236. }
  237. private void UpdateCheckBoxAddOption(PhotoFaceDataShortcut.ItemData itemData)
  238. {
  239. if (itemData == null || itemData.data == null)
  240. {
  241. Debug.Log("表情データが空だったので、追加表情データの表示は最後の状態を引き継ぐ");
  242. return;
  243. }
  244. Dictionary<string, TMorph.AddBlendType> dictionary = new Dictionary<string, TMorph.AddBlendType>
  245. {
  246. {
  247. "頬染め1",
  248. TMorph.AddBlendType.Cheek1
  249. },
  250. {
  251. "頬染め2",
  252. TMorph.AddBlendType.Cheek2
  253. },
  254. {
  255. "頬染め3",
  256. TMorph.AddBlendType.Cheek3
  257. },
  258. {
  259. "涙1",
  260. TMorph.AddBlendType.Tear1
  261. },
  262. {
  263. "涙2",
  264. TMorph.AddBlendType.Tear2
  265. },
  266. {
  267. "涙3",
  268. TMorph.AddBlendType.Tear3
  269. },
  270. {
  271. "涙(玉)",
  272. TMorph.AddBlendType.TearBig
  273. },
  274. {
  275. "涎",
  276. TMorph.AddBlendType.Yodare
  277. },
  278. {
  279. "赤面",
  280. TMorph.AddBlendType.Blush
  281. },
  282. {
  283. "ショック",
  284. TMorph.AddBlendType.Shock
  285. }
  286. };
  287. foreach (KeyValuePair<string, TMorph.AddBlendType> keyValuePair in dictionary)
  288. {
  289. this.m_AddFaceOptionDic[keyValuePair.Key].check = ((itemData.blendType & keyValuePair.Value) != TMorph.AddBlendType.None);
  290. }
  291. }
  292. private void OnClickCheckBoxAddOption(WFCheckBox check_box)
  293. {
  294. string[] array = new string[]
  295. {
  296. "頬染め1",
  297. "頬染め2",
  298. "頬染め3"
  299. };
  300. string[] array2 = new string[]
  301. {
  302. "涙1",
  303. "涙2",
  304. "涙3"
  305. };
  306. string[][] array3 = new string[][]
  307. {
  308. array,
  309. array2
  310. };
  311. foreach (KeyValuePair<string, WFCheckBox> keyValuePair in this.m_AddFaceOptionDic)
  312. {
  313. if (keyValuePair.Value == check_box)
  314. {
  315. foreach (string[] array4 in array3)
  316. {
  317. if (0 <= Array.IndexOf<string>(array4, keyValuePair.Key))
  318. {
  319. for (int j = 0; j < array4.Length; j++)
  320. {
  321. if (!(array4[j] == keyValuePair.Key))
  322. {
  323. if (this.m_AddFaceOptionDic[array4[j]].check)
  324. {
  325. this.m_AddFaceOptionDic[array4[j]].check = false;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. }
  333. if (this.nowSelectItem != null && this.nowSelectItem.data != null)
  334. {
  335. this.ApplyItemData(this.nowSelectItem, this.nowSelectItem.data, this.ConvertBlendType());
  336. if (this.nowSelectItem != null)
  337. {
  338. if (this.targetControllerRight.itemDataList.Contains(this.nowSelectItem))
  339. {
  340. this.targetControllerRight.Emulate(this.nowSelectItem);
  341. }
  342. else if (this.targetControllerLeft.itemDataList.Contains(this.nowSelectItem))
  343. {
  344. this.targetControllerLeft.Emulate(this.nowSelectItem);
  345. }
  346. else
  347. {
  348. Debug.LogWarning("コントローラに存在しない項目を更新しているかもしれない");
  349. }
  350. }
  351. }
  352. }
  353. private void WaitTime(float time, Action onFinish)
  354. {
  355. base.StartCoroutine(this.CoWaitTime(time, onFinish));
  356. }
  357. private IEnumerator CoWaitTime(float time, Action onFinish)
  358. {
  359. yield return new WaitForSeconds(time);
  360. if (onFinish != null)
  361. {
  362. onFinish();
  363. }
  364. yield break;
  365. }
  366. [SerializeField]
  367. [Range(0.001f, 1f)]
  368. private float m_FadeSpeed = 0.25f;
  369. [SerializeField]
  370. private CircleCommandUI m_ButtonListShortcutRight;
  371. [SerializeField]
  372. private CircleCommandUI m_ButtonListShortcutLeft;
  373. [SerializeField]
  374. private ListViewerWindow m_WindowListFaceData;
  375. [SerializeField]
  376. private GameObject m_ParentAddFaceOptions;
  377. [SerializeField]
  378. private UIButton m_ButtonFaceListOK;
  379. private NGUIWindow m_FadeWindowShortcutButtonsRight;
  380. private NGUIWindow m_FadeWindowShortcutButtonsLeft;
  381. private NGUIWindow m_FadeWindowFaceDataList;
  382. private PhotoFaceDataShortcut.ItemData m_NowSelectItem;
  383. private Dictionary<PhotoFaceDataShortcut.ItemData, PhotoFaceDataShortcutSetter.ItemData> m_ItemPairDic = new Dictionary<PhotoFaceDataShortcut.ItemData, PhotoFaceDataShortcutSetter.ItemData>();
  384. private Dictionary<string, WFCheckBox> m_AddFaceOptionDic = new Dictionary<string, WFCheckBox>();
  385. public class ItemData : MonoBehaviour
  386. {
  387. public UILabel label
  388. {
  389. get
  390. {
  391. return this.m_Label;
  392. }
  393. set
  394. {
  395. this.m_Label = value;
  396. }
  397. }
  398. public Localize localize
  399. {
  400. get
  401. {
  402. return this.m_Localize;
  403. }
  404. set
  405. {
  406. this.m_Localize = value;
  407. }
  408. }
  409. private UILabel m_Label;
  410. private Localize m_Localize;
  411. }
  412. }