ScoutOption.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using I2.Loc;
  6. using UnityEngine;
  7. namespace scoutmode
  8. {
  9. public class ScoutOption : MonoBehaviour
  10. {
  11. private ScoutOptionData options
  12. {
  13. get
  14. {
  15. return ScoutManager.Instance.options;
  16. }
  17. }
  18. private void Start()
  19. {
  20. IEnumerator enumerator = this.buttonGroup.GetEnumerator();
  21. try
  22. {
  23. while (enumerator.MoveNext())
  24. {
  25. object obj = enumerator.Current;
  26. Transform transform = (Transform)obj;
  27. UIPopupList componentInChildren = transform.GetComponentInChildren<UIPopupList>();
  28. if (componentInChildren)
  29. {
  30. ScoutOption.NeedData needData = new ScoutOption.NeedData();
  31. if (transform.Find("Label"))
  32. {
  33. needData.label = transform.Find("Label").GetComponent<UILabel>();
  34. needData.localize = needData.label.GetComponent<Localize>();
  35. }
  36. needData.button = transform.GetComponentInChildren<UIButton>();
  37. needData.collider = transform.GetComponentInChildren<BoxCollider>();
  38. this.settingUIList.Add(componentInChildren, needData);
  39. EventDelegate.Add(componentInChildren.onChange, new EventDelegate.Callback(this.OnValueSetting));
  40. }
  41. }
  42. }
  43. finally
  44. {
  45. IDisposable disposable;
  46. if ((disposable = (enumerator as IDisposable)) != null)
  47. {
  48. disposable.Dispose();
  49. }
  50. }
  51. this.UpdateUI();
  52. }
  53. public void DisSelectable()
  54. {
  55. foreach (KeyValuePair<UIPopupList, ScoutOption.NeedData> keyValuePair in this.settingUIList)
  56. {
  57. if (keyValuePair.Value.collider)
  58. {
  59. keyValuePair.Value.collider.enabled = false;
  60. }
  61. }
  62. }
  63. public void UpdateUI()
  64. {
  65. IEnumerator enumerator = this.buttonGroup.GetEnumerator();
  66. try
  67. {
  68. while (enumerator.MoveNext())
  69. {
  70. object obj = enumerator.Current;
  71. Transform transform = (Transform)obj;
  72. UIPopupList componentInChildren = transform.GetComponentInChildren<UIPopupList>();
  73. if (componentInChildren != null)
  74. {
  75. this.SetUIValue(componentInChildren);
  76. }
  77. }
  78. }
  79. finally
  80. {
  81. IDisposable disposable;
  82. if ((disposable = (enumerator as IDisposable)) != null)
  83. {
  84. disposable.Dispose();
  85. }
  86. }
  87. }
  88. private void SetUIValue(UIPopupList list)
  89. {
  90. ScoutOption.UIInspectorSetting uiinspectorSetting = this.settingList.SingleOrDefault((ScoutOption.UIInspectorSetting e) => e.popUpUI == list);
  91. if (uiinspectorSetting == null)
  92. {
  93. return;
  94. }
  95. foreach (string text in list.items)
  96. {
  97. bool flag = false;
  98. string text2 = text.Replace("\r", string.Empty);
  99. string text3 = text2;
  100. string[] array = text2.Split(new char[]
  101. {
  102. '/'
  103. });
  104. if (array != null && 1 < array.Length)
  105. {
  106. text3 = array[array.Length - 1];
  107. flag = true;
  108. }
  109. if (this.IsMatch(uiinspectorSetting.myType, text3))
  110. {
  111. list.value = ((!flag) ? text3 : text2);
  112. break;
  113. }
  114. }
  115. }
  116. private bool IsMatch(ScoutOption.SettingType type, string text)
  117. {
  118. bool result = false;
  119. if (type == ScoutOption.SettingType.BaseChara)
  120. {
  121. if (this.options.baseCharaSelect)
  122. {
  123. result = (text == "登録キャラから選択する");
  124. }
  125. else
  126. {
  127. result = (text == "登録キャラからランダム");
  128. }
  129. }
  130. else if (type == ScoutOption.SettingType.Personality || type == ScoutOption.SettingType.Seikeiken || type == ScoutOption.SettingType.MaidPoint)
  131. {
  132. bool flag = false;
  133. if (type != ScoutOption.SettingType.Personality)
  134. {
  135. if (type != ScoutOption.SettingType.Seikeiken)
  136. {
  137. if (type == ScoutOption.SettingType.MaidPoint)
  138. {
  139. flag = this.options.inheritMaidPoint;
  140. }
  141. }
  142. else
  143. {
  144. flag = this.options.inheritSeikeiken;
  145. }
  146. }
  147. else
  148. {
  149. flag = this.options.inheritPersonality;
  150. }
  151. if (flag)
  152. {
  153. result = (text == "①のキャラと同じ");
  154. }
  155. else
  156. {
  157. result = (text == "ランダム");
  158. }
  159. }
  160. else if (type == ScoutOption.SettingType.BaseCharaDelete)
  161. {
  162. if (this.options.isBaseCharaDelete)
  163. {
  164. result = (text == "①のベースキャラを消す");
  165. }
  166. else
  167. {
  168. result = (text == "①のベースキャラを消さない");
  169. }
  170. }
  171. return result;
  172. }
  173. private void OnValueSetting()
  174. {
  175. string text = UIPopupList.current.value.Replace("\r", string.Empty);
  176. string text2 = text;
  177. bool isLocalized = UIPopupList.current.isLocalized;
  178. if (isLocalized)
  179. {
  180. string[] array = text2.Split(new char[]
  181. {
  182. '/'
  183. });
  184. if (array != null && 1 < array.Length)
  185. {
  186. text2 = array[array.Length - 1];
  187. }
  188. }
  189. ScoutOption.UIInspectorSetting uiinspectorSetting = this.settingList.SingleOrDefault((ScoutOption.UIInspectorSetting e) => e.popUpUI == UIPopupList.current);
  190. if (uiinspectorSetting == null)
  191. {
  192. return;
  193. }
  194. if (uiinspectorSetting.myType == ScoutOption.SettingType.BaseChara)
  195. {
  196. this.options.baseCharaSelect = (text2 == "登録キャラから選択する");
  197. }
  198. else if (uiinspectorSetting.myType == ScoutOption.SettingType.Personality)
  199. {
  200. this.options.inheritPersonality = (text2 == "①のキャラと同じ");
  201. }
  202. else if (uiinspectorSetting.myType == ScoutOption.SettingType.Seikeiken)
  203. {
  204. this.options.inheritSeikeiken = (text2 == "①のキャラと同じ");
  205. }
  206. else if (uiinspectorSetting.myType == ScoutOption.SettingType.MaidPoint)
  207. {
  208. this.options.inheritMaidPoint = (text2 == "①のキャラと同じ");
  209. }
  210. else if (uiinspectorSetting.myType == ScoutOption.SettingType.BaseCharaDelete)
  211. {
  212. this.options.isBaseCharaDelete = (text2 == "①のベースキャラを消す");
  213. }
  214. if (this.settingUIList[UIPopupList.current].label)
  215. {
  216. if (isLocalized && this.settingUIList[UIPopupList.current].localize != null)
  217. {
  218. this.settingUIList[UIPopupList.current].localize.SetTerm(text);
  219. }
  220. else
  221. {
  222. this.settingUIList[UIPopupList.current].label.text = text;
  223. }
  224. }
  225. if (this.onChangeValue != null)
  226. {
  227. this.onChangeValue(uiinspectorSetting.myType, text2);
  228. }
  229. }
  230. [SerializeField]
  231. [Header("ボタンUIグループ")]
  232. private Transform buttonGroup;
  233. [SerializeField]
  234. [Header("各UI設定")]
  235. private List<ScoutOption.UIInspectorSetting> settingList;
  236. public Action<ScoutOption.SettingType, string> onChangeValue;
  237. private Dictionary<UIPopupList, ScoutOption.NeedData> settingUIList = new Dictionary<UIPopupList, ScoutOption.NeedData>();
  238. public enum SettingType
  239. {
  240. BaseChara,
  241. Personality,
  242. Seikeiken,
  243. MaidPoint,
  244. BaseCharaDelete
  245. }
  246. private class NeedData
  247. {
  248. public UILabel label;
  249. public Localize localize;
  250. public UIButton button;
  251. public BoxCollider collider;
  252. }
  253. [Serializable]
  254. private class UIInspectorSetting
  255. {
  256. public ScoutOption.SettingType myType;
  257. public UIPopupList popUpUI;
  258. }
  259. }
  260. }