| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using Newtonsoft.Json.Linq;
- public class PersonalPlayGameInfo
- {
- public string scoreType;
- public int playTime;
- public int currentGameType;
- }
- public class PersonalView : MonoBehaviour, MenuBackInterface
- {
- [SerializeField] Transform panelLeftContent;
- [SerializeField] GameObject gameRecordItem;
- [SerializeField] GameObject gameRecordContent;
- void Start()
- {
- PersistenHandler.ins?.menuBackCtr.views.Add(this);
- RenderUserInfo();
- getPlayTimeByGameType();
- ShowBoxPersonalProfile(true);
- //ShowBoxUserSettings(true);
- }
- void OnDestroy()
- {
- PersistenHandler.ins?.menuBackCtr.views.Remove(this);
- }
- public bool OnMenuBack()
- {
- ViewManager2.HideView(ViewManager2.Path_PersonalView);
- return true;
- }
- public void OnClick_PanelLeftItem(Transform target)
- {
- foreach (Transform item in panelLeftContent)
- {
- if (item == target)
- {
- item.Find("Text").GetComponent<Text>().fontStyle = FontStyle.Bold;
- item.Find("Text").GetComponent<Text>().color = Color.white;
- bool oldActive = item.Find("LightMask").gameObject.activeSelf;
- item.Find("LightMask").gameObject.SetActive(true);
- item.Find("IconOn").GetComponent<Image>().enabled = true;
- item.Find("IconOn/IconOff").GetComponent<Image>().enabled = false;
- if (!oldActive)
- {
- AudioMgr.ins.PlayBtn();
- ShowBox(item.name);
- }
- }
- else
- {
- item.Find("Text").GetComponent<Text>().fontStyle = FontStyle.Normal;
- item.Find("Text").GetComponent<Text>().color = Color.gray;
- item.Find("LightMask").gameObject.SetActive(false);
- item.Find("IconOn").GetComponent<Image>().enabled = false;
- item.Find("IconOn/IconOff").GetComponent<Image>().enabled = true;
- }
- }
- }
- void ShowBox(string itemName)
- {
- ShowBoxPersonalProfile(itemName == "BtnPersonalProfile");
- ShowBoxUserSettings(itemName == "BtnUserSettings");
- }
- void ShowBoxPersonalProfile(bool show)
- {
- transform.Find("PanelContent/BoxPersonalProfile").gameObject.SetActive(show);
- }
- void ShowBoxUserSettings(bool show)
- {
- transform.Find("PanelContent/BoxUserSettings").gameObject.SetActive(show);
- }
- public void ShowModalDeleteAccount(bool show)
- {
- transform.Find("ModalDeleteAccount").gameObject.SetActive(show);
- }
- public void NotifyUserInfoRefresh()
- {
- RenderUserInfo();
- HomeView.ins.RenderNameOrGender();
- HomeView.ins.RenderMyAvatarSprite();
- }
- void RenderUserInfo()
- {
- Transform userTitle = transform.Find("PanelLeft/UserTitle");
- Image avatarImage = userTitle.Find("Avatar/Sprite").GetComponent<Image>();
- RoleMgr.SetAvatarToImage(avatarImage, LoginMgr.myUserInfo.avatarID, LoginMgr.myUserInfo.avatarUrl);
- //userTitle.Find("Text").GetComponent<Text>().text = LoginMgr.myUserInfo.nickname; // + "’s Page"
- var tal = userTitle.Find("Text").gameObject.AddComponent<TextAutoLanguage2>();
- tal.textFormatArgs = new object[] { LoginMgr.myUserInfo.nickname };
- tal.SetTextKey("Personal_LeftName");
- BoxPersonalProfile _BoxPersonalProfile = transform.Find("PanelContent/BoxPersonalProfile").GetComponent<BoxPersonalProfile>();
- _BoxPersonalProfile.setProfileUserInfo(avatarImage.sprite, LoginMgr.myUserInfo.nickname, LoginMgr.myUserInfo.id);
- }
- public void OnClick_DeleteAccount()
- {
- AudioMgr.ins.PlayBtn();
- ShowModalDeleteAccount(true);
- }
- public void OnClick_Back()
- {
- AudioMgr.ins.PlayBtn();
- ViewManager2.HideView(ViewManager2.Path_PersonalView);
- }
- void getPlayTimeByGameType()
- {
- System.Action<JArray> cb = delegate (JArray result)
- {
- //Debug.Log(result);
- //处理分数叠加的情况
- List<PersonalPlayGameInfo> personalPlayGameInfos = new List<PersonalPlayGameInfo>();
- foreach (var itemInfo in result)
- {
- string scoreType = "";
- int currentGameType = -1; // 选一个 gameType用以查询数据
- int time = itemInfo.Value<int>("totalDuration");
- int gameType = itemInfo.Value<int>("gameType");
- //Debug.Log(gameType+" = " + time);
- switch (gameType)
- {
- case 1: //静止靶 (单人)
- case 2: //静止靶 (本地PK)
- case 9: //静止靶 (联机PK)
- scoreType = "OlynpicArchery";
- currentGameType = 1;
- break;
- case 3://兔子关卡 (单人)
- case 6://兔子关卡 (本地PK)
- case 10://兔子关卡 (联机PK)
- scoreType = "HareHunt";
- currentGameType = 3;
- break;
- case 4: //野鸡关卡 (单人)
- case 7: //野鸡关卡 (本地PK)
- case 11://野鸡关卡 (联机PK)
- scoreType = "PheasuntHunt";
- currentGameType = 4;
- break;
- case 5: //野狼关卡 (单人)
- case 8: //野狼关卡 (本地PK)
- case 12://野狼关卡 (联机PK)
- scoreType = "WolfHunt";
- currentGameType = 5;
- break;
- case 13: //野鸭关卡 (单人)
- scoreType = "LevelDuckHunter";
- currentGameType = 13;
- break;
- case 14: //荒野射击 (单人)
- scoreType = "LevelWildAttack";
- currentGameType = 14;
- break;
- case 15: //水果达人 (单人)
- scoreType = "FruitExpert";
- currentGameType = 15;
- break;
- }
- if (scoreType != "")
- {
- bool bCanAdd = true;
- foreach (PersonalPlayGameInfo _item in personalPlayGameInfos)
- {
- if (_item.scoreType == scoreType) {
- _item.playTime += time;
- bCanAdd = false;
- }
- }
- if (bCanAdd) {
- PersonalPlayGameInfo PersonalPlayGameInfo = new PersonalPlayGameInfo();
- PersonalPlayGameInfo.playTime = time;
- PersonalPlayGameInfo.scoreType = scoreType;
- PersonalPlayGameInfo.currentGameType = currentGameType;
- personalPlayGameInfos.Add(PersonalPlayGameInfo);
- }
- }
- }
- foreach (var itemInfo in personalPlayGameInfos)
- {
- int gameType = itemInfo.currentGameType;
- if (gameType == -1) continue;
- //int time = itemInfo.Value<int>("totalDuration");
- //int gameType = itemInfo.Value<int>("gameType");
- int time = itemInfo.playTime;
- int hour = time / 3600;
- int minute = (time - hour * 3600) / 60;
- if (minute < 0) minute = 0;
- int second = time % 60;
- if (second < 0) second = 0;
- //Debug.Log(" = " + time);
- GameObject o = Instantiate(gameRecordItem, gameRecordContent.transform);
- o.SetActive(true);
- //o.transform.Find("time/Text").GetComponent<Text>().text = string.Format("{0} h {1} m {2} s",hour,minute,second);
- var tal = o.transform.Find("time/Text").GetComponent<TextAutoLanguage2>();
- tal.textFormatArgs = new object[] { hour, minute, second };
- tal.SetTextKey("Personal_RecordTime2");
- Transform _name = o.transform.Find("name/Label");
- Transform _sprite = o.transform.Find("Icon/Sprite");
- GameInfo gameInfo = TextureMgr.ins.GetGameInfos(gameType);
- //_name.GetComponent<Text>().text = gameInfo.name;
- _name.gameObject.AddComponent<TextAutoLanguage2>().SetTextKey(gameInfo.textId);
- Sprite texSprite = Sprite.Create(gameInfo.texture2D, new Rect(0, 0, gameInfo.texture2D.width, gameInfo.texture2D.height), new Vector2(0.5f, 0.5f));
- _sprite.GetComponent<Image>().sprite = texSprite;
- }
- };
- UserPlayer.ins.call("UserGameAnalyseComp.getUserGamePlayTime", null, cb);
- }
- }
|