PersonalView.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using Newtonsoft.Json.Linq;
  7. public class PersonalPlayGameInfo
  8. {
  9. public string scoreType;
  10. public int playTime;
  11. public int currentGameType;
  12. }
  13. public class PersonalView : MonoBehaviour, MenuBackInterface
  14. {
  15. [SerializeField] Transform panelLeftContent;
  16. [SerializeField] GameObject gameRecordItem;
  17. [SerializeField] GameObject gameRecordContent;
  18. void Start()
  19. {
  20. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  21. RenderUserInfo();
  22. getPlayTimeByGameType();
  23. ShowBoxPersonalProfile(true);
  24. //ShowBoxUserSettings(true);
  25. }
  26. void OnDestroy()
  27. {
  28. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  29. }
  30. public bool OnMenuBack()
  31. {
  32. ViewManager2.HideView(ViewManager2.Path_PersonalView);
  33. return true;
  34. }
  35. public void OnClick_PanelLeftItem(Transform target)
  36. {
  37. foreach (Transform item in panelLeftContent)
  38. {
  39. if (item == target)
  40. {
  41. item.Find("Text").GetComponent<Text>().fontStyle = FontStyle.Bold;
  42. item.Find("Text").GetComponent<Text>().color = Color.white;
  43. bool oldActive = item.Find("LightMask").gameObject.activeSelf;
  44. item.Find("LightMask").gameObject.SetActive(true);
  45. item.Find("IconOn").GetComponent<Image>().enabled = true;
  46. item.Find("IconOn/IconOff").GetComponent<Image>().enabled = false;
  47. if (!oldActive)
  48. {
  49. AudioMgr.ins.PlayBtn();
  50. ShowBox(item.name);
  51. }
  52. }
  53. else
  54. {
  55. item.Find("Text").GetComponent<Text>().fontStyle = FontStyle.Normal;
  56. item.Find("Text").GetComponent<Text>().color = Color.gray;
  57. item.Find("LightMask").gameObject.SetActive(false);
  58. item.Find("IconOn").GetComponent<Image>().enabled = false;
  59. item.Find("IconOn/IconOff").GetComponent<Image>().enabled = true;
  60. }
  61. }
  62. }
  63. void ShowBox(string itemName)
  64. {
  65. ShowBoxPersonalProfile(itemName == "BtnPersonalProfile");
  66. ShowBoxUserSettings(itemName == "BtnUserSettings");
  67. }
  68. void ShowBoxPersonalProfile(bool show)
  69. {
  70. transform.Find("PanelContent/BoxPersonalProfile").gameObject.SetActive(show);
  71. }
  72. void ShowBoxUserSettings(bool show)
  73. {
  74. transform.Find("PanelContent/BoxUserSettings").gameObject.SetActive(show);
  75. }
  76. public void ShowModalDeleteAccount(bool show)
  77. {
  78. transform.Find("ModalDeleteAccount").gameObject.SetActive(show);
  79. }
  80. public void NotifyUserInfoRefresh()
  81. {
  82. RenderUserInfo();
  83. HomeView.ins.RenderNameOrGender();
  84. HomeView.ins.RenderMyAvatarSprite();
  85. }
  86. void RenderUserInfo()
  87. {
  88. Transform userTitle = transform.Find("PanelLeft/UserTitle");
  89. Image avatarImage = userTitle.Find("Avatar/Sprite").GetComponent<Image>();
  90. RoleMgr.SetAvatarToImage(avatarImage, LoginMgr.myUserInfo.avatarID, LoginMgr.myUserInfo.avatarUrl);
  91. //userTitle.Find("Text").GetComponent<Text>().text = LoginMgr.myUserInfo.nickname; // + "’s Page"
  92. var tal = userTitle.Find("Text").gameObject.AddComponent<TextAutoLanguage2>();
  93. tal.textFormatArgs = new object[] { LoginMgr.myUserInfo.nickname };
  94. tal.SetTextKey("Personal_LeftName");
  95. BoxPersonalProfile _BoxPersonalProfile = transform.Find("PanelContent/BoxPersonalProfile").GetComponent<BoxPersonalProfile>();
  96. _BoxPersonalProfile.setProfileUserInfo(avatarImage.sprite, LoginMgr.myUserInfo.nickname, LoginMgr.myUserInfo.id);
  97. }
  98. public void OnClick_DeleteAccount()
  99. {
  100. AudioMgr.ins.PlayBtn();
  101. ShowModalDeleteAccount(true);
  102. }
  103. public void OnClick_Back()
  104. {
  105. AudioMgr.ins.PlayBtn();
  106. ViewManager2.HideView(ViewManager2.Path_PersonalView);
  107. }
  108. void getPlayTimeByGameType()
  109. {
  110. System.Action<JArray> cb = delegate (JArray result)
  111. {
  112. //Debug.Log(result);
  113. //处理分数叠加的情况
  114. List<PersonalPlayGameInfo> personalPlayGameInfos = new List<PersonalPlayGameInfo>();
  115. foreach (var itemInfo in result)
  116. {
  117. string scoreType = "";
  118. int currentGameType = -1; // 选一个 gameType用以查询数据
  119. int time = itemInfo.Value<int>("totalDuration");
  120. int gameType = itemInfo.Value<int>("gameType");
  121. //Debug.Log(gameType+" = " + time);
  122. switch (gameType)
  123. {
  124. case 1: //静止靶 (单人)
  125. case 2: //静止靶 (本地PK)
  126. case 9: //静止靶 (联机PK)
  127. scoreType = "OlynpicArchery";
  128. currentGameType = 1;
  129. break;
  130. case 3://兔子关卡 (单人)
  131. case 6://兔子关卡 (本地PK)
  132. case 10://兔子关卡 (联机PK)
  133. scoreType = "HareHunt";
  134. currentGameType = 3;
  135. break;
  136. case 4: //野鸡关卡 (单人)
  137. case 7: //野鸡关卡 (本地PK)
  138. case 11://野鸡关卡 (联机PK)
  139. scoreType = "PheasuntHunt";
  140. currentGameType = 4;
  141. break;
  142. case 5: //野狼关卡 (单人)
  143. case 8: //野狼关卡 (本地PK)
  144. case 12://野狼关卡 (联机PK)
  145. scoreType = "WolfHunt";
  146. currentGameType = 5;
  147. break;
  148. case 13: //野鸭关卡 (单人)
  149. scoreType = "LevelDuckHunter";
  150. currentGameType = 13;
  151. break;
  152. case 14: //荒野射击 (单人)
  153. scoreType = "LevelWildAttack";
  154. currentGameType = 14;
  155. break;
  156. case 15: //水果达人 (单人)
  157. scoreType = "FruitExpert";
  158. currentGameType = 15;
  159. break;
  160. }
  161. if (scoreType != "")
  162. {
  163. bool bCanAdd = true;
  164. foreach (PersonalPlayGameInfo _item in personalPlayGameInfos)
  165. {
  166. if (_item.scoreType == scoreType) {
  167. _item.playTime += time;
  168. bCanAdd = false;
  169. }
  170. }
  171. if (bCanAdd) {
  172. PersonalPlayGameInfo PersonalPlayGameInfo = new PersonalPlayGameInfo();
  173. PersonalPlayGameInfo.playTime = time;
  174. PersonalPlayGameInfo.scoreType = scoreType;
  175. PersonalPlayGameInfo.currentGameType = currentGameType;
  176. personalPlayGameInfos.Add(PersonalPlayGameInfo);
  177. }
  178. }
  179. }
  180. foreach (var itemInfo in personalPlayGameInfos)
  181. {
  182. int gameType = itemInfo.currentGameType;
  183. if (gameType == -1) continue;
  184. //int time = itemInfo.Value<int>("totalDuration");
  185. //int gameType = itemInfo.Value<int>("gameType");
  186. int time = itemInfo.playTime;
  187. int hour = time / 3600;
  188. int minute = (time - hour * 3600) / 60;
  189. if (minute < 0) minute = 0;
  190. int second = time % 60;
  191. if (second < 0) second = 0;
  192. //Debug.Log(" = " + time);
  193. GameObject o = Instantiate(gameRecordItem, gameRecordContent.transform);
  194. o.SetActive(true);
  195. //o.transform.Find("time/Text").GetComponent<Text>().text = string.Format("{0} h {1} m {2} s",hour,minute,second);
  196. var tal = o.transform.Find("time/Text").GetComponent<TextAutoLanguage2>();
  197. tal.textFormatArgs = new object[] { hour, minute, second };
  198. tal.SetTextKey("Personal_RecordTime2");
  199. Transform _name = o.transform.Find("name/Label");
  200. Transform _sprite = o.transform.Find("Icon/Sprite");
  201. GameInfo gameInfo = TextureMgr.ins.GetGameInfos(gameType);
  202. //_name.GetComponent<Text>().text = gameInfo.name;
  203. _name.gameObject.AddComponent<TextAutoLanguage2>().SetTextKey(gameInfo.textId);
  204. Sprite texSprite = Sprite.Create(gameInfo.texture2D, new Rect(0, 0, gameInfo.texture2D.width, gameInfo.texture2D.height), new Vector2(0.5f, 0.5f));
  205. _sprite.GetComponent<Image>().sprite = texSprite;
  206. }
  207. };
  208. UserPlayer.ins.call("UserGameAnalyseComp.getUserGamePlayTime", null, cb);
  209. }
  210. }