SettingsView.cs 9.2 KB

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