SettingsView.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using System.Linq;
  7. namespace SmartBow
  8. {
  9. public class SettingsView : JCUnityLib.ViewBase, MenuBackInterface
  10. {
  11. [SerializeField] Transform panelLeftContent;
  12. [SerializeField] Transform BtnNewUserObj;
  13. [SerializeField] Text GameVersionText;
  14. void Start()
  15. {
  16. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  17. //ShowBoxSound(true);
  18. switch (CommonConfig.OP)
  19. {
  20. case OperatingPlatform.A:
  21. case OperatingPlatform.C:
  22. //隐藏弓到屏幕的距离
  23. Dictionary<string, Transform> actionMapInfrared = new Dictionary<string, Transform>
  24. {
  25. { "BtnSound", null },
  26. { "BtnLanguage", null },
  27. { "BtnNewUser", null },
  28. { "BtnLevel", null },
  29. { "BtnUserAgreement", null },
  30. { "BtnPrivacyPolicy", null },
  31. { "BtnAboutUs", null },
  32. { "BtnSignOut",null}
  33. };
  34. SortChildObjects(actionMapInfrared);
  35. //if (CommonConfig.bInfraredApp)
  36. //{
  37. // //隐藏弓到屏幕的距离
  38. // Dictionary<string, Transform> actionMapInfrared= new Dictionary<string, Transform>
  39. // {
  40. // { "BtnSound", null },
  41. // { "BtnLanguage", null },
  42. // { "BtnNewUser", null },
  43. // { "BtnLevel", null },
  44. // { "BtnUserAgreement", null },
  45. // { "BtnPrivacyPolicy", null },
  46. // { "BtnAboutUs", null },
  47. // { "BtnSignOut",null}
  48. // };
  49. // SortChildObjects(actionMapInfrared);
  50. //}
  51. //else {
  52. // Dictionary<string, Transform> actionMapA = new Dictionary<string, Transform>
  53. // {
  54. // { "BtnSound", null },
  55. // { "BtnLanguage", null },
  56. // { "BtnNewUser", null },
  57. // { "BtnScreenDistance", null },//弓到屏幕的距离
  58. // { "BtnLevel", null },
  59. // { "BtnUserAgreement", null },
  60. // { "BtnPrivacyPolicy", null },
  61. // { "BtnAboutUs", null },
  62. // { "BtnSignOut",null}
  63. // };
  64. // SortChildObjects(actionMapA);
  65. //}
  66. break;
  67. case OperatingPlatform.B:
  68. // 定义排序字典
  69. Dictionary<string, Transform> actionMapB = new Dictionary<string, Transform>
  70. {
  71. { "BtnSound", null },
  72. { "BtnLanguage", null },
  73. { "BtnLevel", null },
  74. { "BtnUserSettings", null },
  75. { "BtnBackStageManagement", null },
  76. { "BtnAboutUs", null }
  77. };
  78. SortChildObjects(actionMapB);
  79. break;
  80. }
  81. }
  82. void SortChildObjects(Dictionary<string, Transform> actionMap) {
  83. // 查找子对象并按名称填充 actionMap
  84. foreach (Transform child in panelLeftContent)
  85. {
  86. if (actionMap.ContainsKey(child.name))
  87. {
  88. actionMap[child.name] = child;
  89. }
  90. else
  91. {
  92. // 如果子对象不在 actionMap 中,则隐藏它
  93. child.gameObject.SetActive(false);
  94. }
  95. }
  96. // 获取按字典定义顺序的子对象列表(过滤掉未找到的对象)
  97. var sortedChildren = actionMap.Values.Where(child => child != null).ToList();
  98. // 重新排列子对象
  99. for (int i = 0; i < sortedChildren.Count; i++)
  100. {
  101. sortedChildren[i].SetSiblingIndex(i);
  102. }
  103. }
  104. void OnDestroy()
  105. {
  106. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  107. }
  108. public bool OnMenuBack()
  109. {
  110. ViewManager2.HideView(ViewManager2.Path_SettingsView);
  111. return true;
  112. }
  113. //模拟点击新手教程按钮
  114. public void OnClick_BtnNewUser() {
  115. this.OnClick_PanelLeftItem(BtnNewUserObj.transform);
  116. }
  117. public void OnClick_PanelLeftItem(Transform target)
  118. {
  119. foreach (Transform item in panelLeftContent)
  120. {
  121. if (item.name == "BtnSignOut") continue;
  122. if (item == target)
  123. {
  124. item.Find("Text").GetComponent<Text>().fontStyle = FontStyle.Bold;
  125. item.Find("Text").GetComponent<Text>().color = Color.white;
  126. bool oldActive = item.Find("LightMask").gameObject.activeSelf;
  127. item.Find("LightMask").gameObject.SetActive(true);
  128. if (!oldActive)
  129. {
  130. AudioMgr.ins.PlayBtn();
  131. ShowBox(item.name);
  132. }
  133. }
  134. else
  135. {
  136. item.Find("Text").GetComponent<Text>().fontStyle = FontStyle.Normal;
  137. item.Find("Text").GetComponent<Text>().color = Color.gray;
  138. item.Find("LightMask").gameObject.SetActive(false);
  139. }
  140. }
  141. }
  142. void ShowBox(string itemName)
  143. {
  144. // 定义所有 ShowBox 方法,并将初始状态设为 false
  145. var actionMap = new Dictionary<string, System.Action<bool>>
  146. {
  147. { "BtnSound", ShowBoxSound },
  148. { "BtnLevel", ShowBoxLevel },
  149. { "BtnNewUser", ShowBoxNewUser },
  150. { "BtnUserSettings", ShowBoxUserSettings },
  151. { "BtnBackStageManagement",ShowBackStageManagement},
  152. { "BtnLanguage", ShowBoxLanguage },
  153. { "BtnUserAgreement", ShowBoxUserAgreement },
  154. { "BtnPrivacyPolicy", ShowBoxPrivacyPolicy },
  155. { "BtnAboutUs", ShowBoxAboutUs }
  156. };
  157. // 如果不是红外应用,则包括 BtnScreenDistance
  158. //if (!CommonConfig.bInfraredApp)
  159. //{
  160. // actionMap["BtnScreenDistance"] = ShowBoxScreenDistance;
  161. //}
  162. // 先将所有状态设为 false
  163. foreach (var action in actionMap.Values)
  164. {
  165. action(false);
  166. }
  167. // 将指定的 itemName 对应的按钮设为 true
  168. if (actionMap.TryGetValue(itemName, out var selectedAction))
  169. {
  170. selectedAction(true);
  171. }
  172. }
  173. //void ShowBox(string itemName)
  174. //{
  175. // ShowBoxSound(itemName == "BtnSound");
  176. // ShowBoxLevel(itemName == "BtnLevel");
  177. // ShowBoxNewUser(itemName == "BtnNewUser");
  178. // ShowBoxUserSettings(itemName == "BtnUserSettings");
  179. // if (!CommonConfig.bInfraredApp)ShowBoxScreenDistance(itemName == "BtnScreenDistance");
  180. // ShowBoxLanguage(itemName == "BtnLanguage");
  181. // ShowBoxUserAgreement(itemName == "BtnUserAgreement");
  182. // ShowBoxPrivacyPolicy(itemName == "BtnPrivacyPolicy");
  183. // ShowBoxAboutUs(itemName == "BtnAboutUs");
  184. //}
  185. public void ShowBoxUserSettings(bool show) {
  186. transform.Find("PanelContent/BoxUserSettings").gameObject.SetActive(show);
  187. }
  188. public void ShowBackStageManagement(bool show)
  189. {
  190. transform.Find("PanelContent/BoxBackStageManagement").gameObject.SetActive(show);
  191. }
  192. public void ShowBoxSound(bool show)
  193. {
  194. transform.Find("PanelContent/BoxSound").gameObject.SetActive(show);
  195. }
  196. void ShowBoxLevel(bool show)
  197. {
  198. transform.Find("PanelContent/BoxLevel").gameObject.SetActive(show);
  199. }
  200. void ShowBoxNewUser(bool show)
  201. {
  202. transform.Find("PanelContent/BoxNewUser").gameObject.SetActive(show);
  203. }
  204. void ShowBoxScreenDistance(bool show)
  205. {
  206. transform.Find("PanelContent/BoxScreenDistance").gameObject.SetActive(show);
  207. }
  208. void ShowBoxLanguage(bool show)
  209. {
  210. transform.Find("PanelContent/BoxLanguage").gameObject.SetActive(show);
  211. }
  212. void ShowBoxUserAgreement(bool show)
  213. {
  214. transform.Find("PanelContent/BoxUserAgreement").gameObject.SetActive(show);
  215. }
  216. void ShowBoxPrivacyPolicy(bool show)
  217. {
  218. transform.Find("PanelContent/BoxPrivacyPolicy").gameObject.SetActive(show);
  219. }
  220. void ShowBoxAboutUs(bool show)
  221. {
  222. transform.Find("PanelContent/BoxAboutUs").gameObject.SetActive(show);
  223. GameVersionText.text = "V" + Application.version;
  224. }
  225. public void ShowModalConfirmSignOut(bool show)
  226. {
  227. transform.Find("ModalConfirmSignOut").gameObject.SetActive(show);
  228. }
  229. public void OnClick_QuitGame()
  230. {
  231. AudioMgr.ins.PlayBtn();
  232. Application.Quit();
  233. }
  234. public void OnClick_SignOut()
  235. {
  236. AudioMgr.ins.PlayBtn();
  237. ShowModalConfirmSignOut(true);
  238. }
  239. public void OnClick_Back()
  240. {
  241. AudioMgr.ins.PlayBtn();
  242. ViewManager2.HideView(ViewManager2.Path_SettingsView);
  243. }
  244. }
  245. }