SettingsView.cs 9.7 KB

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