// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2021-03-26 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** namespace G.UI { using Spine.Unity; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; /// /// /// partial class PetWindow { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] Button _btnBack; [KUIFlag] Slider _sldExp; [KUIFlag] TextMeshProUGUI _tmpExp; [KUIFlag] Button _btnOnekeyUpgrade; [KUIFlag] Button _btnUpgrade; [KUIFlag] Button _btnFeed; [KUIFlag] Button _btnFeedAd; [KUIFlag] TextMeshProUGUI _tmpFeedTime; [KUIFlag] TextMeshProUGUI _tmpFeedCount; [KUIFlag] KUIImage _imgPrivilege; [KUIFlag] GameObject __goMoney1; [KUIFlag] GameObject __goMoney2; [KUIFlag] KUIList __listSkill; [KUIFlag] Button _btnRecast; [KUIFlag] GameObject __goSkillDetail; [KUIFlag] GameObject _goUnlock; [KUIFlag] GameObject _goLock; [KUIFlag] KUIList __listPets; [KUIFlag] GameObject __goRecast; [KUIFlag] GameObject __goReplace; [KUIFlag] Button _btnSkillBook; [KUIFlag] Button _btnRename; [KUIFlag] Button _btnRanking; [KUIFlag] Button _btnLeft; [KUIFlag] Button _btnRight; [KUIFlag] Button _btnGet; [KUIFlag] TextMeshProUGUI _tmpGet; [KUIFlag] GameObject __goGetCost; [KUIFlag] Image _imgIcon; [KUIFlag] TextMeshProUGUI _tmpName; [KUIFlag] TextMeshProUGUI _tmpGrade; [KUIFlag] TextMeshProUGUI _tmpCombatValue; [KUIFlag] GameObject __mainSkill; [KUIFlag] GameObject _goStatus; [KUIFlag] GameObject _goLabel; [KUIFlag] Button _btnBattle; [KUIFlag] TextMeshProUGUI _tmpBattle; [KUIFlag] PetSpineWidget _skeleton; [KUIFlag] KUIImage _imgSpecialIcon; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null /// /// /// //private CostWidget _upgradeCost1; //private CostWidget _upgradeCost2; /// /// /// private CostWidget _getCostWidget; private RecastPanel _recastPanel; private ReplacePanel _replacePanel; private SkillDetailWidget _skillDetailWidget; private SkillWidget _mainSkillWidget; /// /// /// private readonly List _petWidgets = new List(); private int _petIndex; private readonly List _pets = new List(); private SmartCostWidget _smartCostWidget; private bool _isTiger = false; #endregion #region Property /// /// /// PetProxy.PetInfo selectedPet => _pets[_petIndex]; #endregion #region Method /// /// /// public void InitView() { SetViewData(); _recastPanel = __goRecast.AddComponent(); __goRecast.SetActive(false); _replacePanel = __goReplace.AddComponent(); __goReplace.SetActive(false); _skillDetailWidget = __goSkillDetail.AddComponent(); __goSkillDetail.SetActive(false); __listPets.AddTemplate(true); __listSkill.AddTemplate(true); _mainSkillWidget = __mainSkill.AddComponent(); //__goMoney1.SetActive(false); //_upgradeCost1 = __goMoney1.AddComponent(); //__goMoney2.SetActive(false); //_upgradeCost2 = __goMoney2.AddComponent(); _getCostWidget = __goGetCost.AddComponent(); _btnBack.onClick.AddListener(this.OnBackBtnClick); _btnOnekeyUpgrade.onClick.AddListener(this.OnOnekeyUpgradeBtnClick); _btnUpgrade.onClick.AddListener(this.OnUpgradeBtnClick); _btnRecast.onClick.AddListener(this.OnRecastBtnClick); _btnBattle.onClick.AddListener(OnBattleBtnClick); _btnSkillBook.onClick.AddListener(this.OnSkillBookBtnClick); _btnRename.onClick.AddListener(this.OnRenameBtnClick); _btnRanking.gameObject.SetActive(FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Pet_Rank)); _btnRanking.onClick.AddListener(this.OnRankingBtnClick); _btnLeft.onClick.AddListener(this.OnLeftBtnClick); _btnRight.onClick.AddListener(this.OnRightBtnClick); _btnGet.onClick.AddListener(this.OnGetBtnClick); _btnFeed.onClick.AddListener(this.OnFeedBtnClick); _btnFeedAd.onClick.AddListener(this.OnAdFeedBtnClick); _smartCostWidget = _btnFeedAd.gameObject.AddComponent(); } /// /// /// public void RefreshView() { __goSkillDetail.SetActive(false); RefreshPetList(); if (_isTiger) { _petIndex = _pets.Count - 1; _isTiger = false; } else { for (int i = 0; i < _pets.Count; i++) { if (_pets[i].isBattling) _petIndex = i; } } RefreshPetSelect(); } public void UpdateView() { RefreshFeed(); } /// /// /// void RefreshFeed() { if (!this.selectedPet.isMaxGrade) { var remainTime = PetProxy.Instance.petFeedTimestamp - Launch.Timestamp; if (remainTime > 0) { var ts = F.Utils.Time.ToTimeString2(remainTime); _tmpFeedTime.text = $"免费培养恢复时间:{ts}"; _btnFeed.gameObject.SetActive(false); _btnFeedAd.gameObject.SetActive(true); _smartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket)); } else { _tmpFeedTime.text = ""; _btnFeed.gameObject.SetActive(true); _btnFeedAd.gameObject.SetActive(false); } } } /// /// /// void RefreshPetList() { _pets.Clear(); var allPets = PetProxy.Instance.GetAllPets(); foreach (var pet in allPets) { if (pet.isUnlock) _pets.Add(pet); } //_pets.AddRange(PetProxy.Instance.GetAllPets()); _petWidgets.Clear(); __listPets.Clear(); foreach (var pet in _pets) { var widget = __listPets.GetItem(); widget.SetData(pet); _petWidgets.Add(widget); } } /// /// /// void RefreshPetSelect() { _btnLeft.gameObject.SetActive(_petIndex > 0); _btnRight.gameObject.SetActive(_petIndex < _pets.Count - 1); for (int i = 0; i < _petWidgets.Count; i++) { _petWidgets[i].SetSelect(i == _petIndex); } var pet = _pets[_petIndex]; _tmpName.text = pet.name; _tmpGrade.text = pet.grade + "级"; _goLabel.SetActive(pet.item.label == 1); _mainSkillWidget.SetData(pet.mainSkill); //AssetProxy.Instance.SetSprite(_imgIcon, petInfo.icon); _tmpCombatValue.text = pet.combatValue.ToString(); var skinAssets = pet.item.skins; if (skinAssets != null && skinAssets.Length > 0) { int skinIndex = 0; if (pet.isMaxGrade) skinIndex = 2; else if (pet.CheckRecast()) skinIndex = 1; if (skinIndex >= skinAssets.Length) skinIndex = skinAssets.Length - 1; StartCoroutine(SetSkin(skinAssets[skinIndex])); } _goStatus.SetActive(pet.isBattling); _tmpBattle.text = pet.isBattling ? "休息" : "出战"; if (pet.isFriend) { _goUnlock.SetActive(true); _goLock.SetActive(false); //_btnRename.gameObject.SetActive(true); RefreshGradeAndExp(false); RefreshSkills(); } else { _goUnlock.SetActive(false); _goLock.SetActive(true); //_btnRename.gameObject.SetActive(false); var accessItem = pet.access; if (accessItem != null) _tmpGet.text = accessItem.name; var friendId = pet.friendId; if (friendId == Item.Id.kFriend) { _getCostWidget.SetPrice(pet.friendId, Mathf.Max(0, pet.friend), pet.friendMax); _imgSpecialIcon.gameObject.SetActive(false); } else { var propCount = ItemProxy.Instance.GetPropCount(friendId); var propCountMax = pet.friendMax; _getCostWidget.SetPrice(friendId, propCount, propCountMax); if (propCount >= propCountMax) { _tmpGet.text = "激活"; } if (friendId ==3002) { _imgSpecialIcon.gameObject.SetActive(true); //_imgSpecialIcon.SetDefaultSprite(0); } else { _imgSpecialIcon.gameObject.SetActive(false); } } } } void RefreshName() { _tmpName.text = selectedPet.name; _petWidgets[_petIndex].RefreshName(); } void RefreshSkills() { var petInfo = selectedPet; var petSkills = petInfo.CheckSkill(); __listSkill.Clear(); for (int i = 0; i < petSkills.Count; i++) { __listSkill.GetItem().SetData(petSkills[i]); } _btnSkillBook.gameObject.SetActive(petInfo.CheckRecast()); _btnRecast.gameObject.SetActive(petInfo.CheckRecast()); } IEnumerator SetSkin(string skinAsset) { if (!string.IsNullOrEmpty(skinAsset)) { if (skinAsset.EndsWith("pic")) { _skeleton.gameObject.SetActive(false); var handle = AssetProxy.Instance.TryGetTemporaryAssetAsync(skinAsset); yield return handle; if (handle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded) { _imgIcon.enabled = true; _imgIcon.overrideSprite = handle.Result; } } else { _imgIcon.enabled = false; _skeleton.gameObject.SetActive(true); _skeleton.Show(skinAsset, null); //var handle = AssetProxy.Instance.TryGetGlobalAssetAsync(spriteAsset); //yield return handle; //Object.Instantiate(handle.Result, _imgIcon.transform); } } } void ShowSkillDetail(PetProxy.PetSkillInfo petSkill) { __goSkillDetail.SetActive(true); _skillDetailWidget.SetData(petSkill); } void RefreshGradeAndExp(bool anim) { //RefreshUpgradeCost(); var pet = this.selectedPet; if (!pet.isMaxGrade) { _tmpExp.text = $"<#FF9A00>{pet.grade}级 {pet.exp}/{pet.expMax}"; float target = pet.exp / (float)pet.expMax; if (anim) StartCoroutine(ShowExpWithAnim(target)); else _sldExp.value = target; var feedCount = TimeProxy.Instance.GetTimeInfo2(TimeProxy.宠物升级); _tmpFeedCount.text = $"今日剩余次数:{feedCount.remain}/{feedCount.max}"; RefreshFeed(); } else { _sldExp.value = 1f; _tmpExp.text = "已满级"; _btnFeed.gameObject.SetActive(false); _btnFeedAd.gameObject.SetActive(false); } } IEnumerator ShowExpWithAnim(float target) { if (_sldExp.value < target) { for (int i = 0; i < 20; i++) { _sldExp.value += 0.05f; if (_sldExp.value >= target) { _sldExp.value = target; break; } yield return null; } } else { for (int i = 0; i < 20; i++) { _sldExp.value += 0.05f; if (_sldExp.value >= 1f) { _sldExp.value = 0f; break; } yield return null; } for (int i = 0; i < 20; i++) { _sldExp.value += 0.05f; if (_sldExp.value >= target) { _sldExp.value = target; break; } yield return null; } } } void RefreshGrade() { var petGrade = selectedPet.grade; _tmpGrade.text = petGrade + "级"; foreach (var widget in _petWidgets) { widget.RefreshGrade(); } if (petGrade % 10 == 0) RefreshSkills(); var feedCount = TimeProxy.Instance.GetTimeInfo2(TimeProxy.宠物升级); _tmpFeedCount.text = $"今日剩余次数:{feedCount.remain}/{feedCount.max}"; } public void RefreshUpgradeCost() { _recastPanel.RefreshCost(); //var costs = selectedPet.CalcUpgradeCost(); //_upgradeCost1.SetPriceWithMax(costs[0]); //_upgradeCost2.SetAndCheckPrice(costs[1]); } /// /// /// void RefreshBattleStatus() { foreach (var widget in _petWidgets) { widget.RefreshBattleStatus(); } } /// /// /// /// void ShowRecastPanel(bool reset = false) { var pet = this.selectedPet; if (pet != null) { if (reset) { pet.ResetRecast(); } __goRecast.SetActive(true); _recastPanel.SetData(pet); if (reset) { _recastPanel.ResetLock(); } } } /// /// /// void ShowReplacePanel() { __goReplace.SetActive(true); _replacePanel.SetData(this.selectedPet); } bool LockSkill(SkillWidget skillWidget) { return _recastPanel.LockSkill(skillWidget); } /// /// /// /// public void OnPetSelect(PetProxy.PetInfo petInfo) { for (int i = 0; i < _pets.Count; i++) { if (_pets[i] == petInfo) { _petIndex = i; RefreshPetSelect(); break; } } } /// /// /// private void OnUpgradeBtnClick() { var pet = this.selectedPet; if (pet != null) { var cost = pet.CalcUpgradeCost(); int shortId = MoneyProxy.Instance.CheckMoney2(cost); if (shortId > 0) { if (shortId != Item.Id.kCoin) { OpenWindow(ItemProxy.Instance.GetStaticItem(shortId)); } else ToastBox.ShowText("货币不足"); return; } var result = pet.Upgrade(); if (result > 0) { MoneyProxy.Instance.CostMoney(cost); ToastBox.ShowText("获得100经验"); RefreshGradeAndExp(true); if (result > 1) { RefreshGrade(); } } else { ToastBox.ShowText("宠物已满级"); } } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } /// /// /// private void OnOnekeyUpgradeBtnClick() { var pet = this.selectedPet; if (pet != null) { int result = -1; while (true) { var cost = pet.CalcUpgradeCost(); int shortId = MoneyProxy.Instance.CheckMoney2(cost); if (shortId > 0) { break; } int upResult = pet.Upgrade(); if (upResult == 0) break; result = upResult; MoneyProxy.Instance.CostMoney(cost); } if (result > 0) { RefreshGradeAndExp(true); if (result > 1) { RefreshGrade(); } if (pet.isMaxGrade) { ToastBox.ShowText("宠物已满级"); } } else { } } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnFeedBtnClick() { //int feedCount = TimeProxy.Instance.GetDailyAmount(4); //if (feedCount <= 0) //{ // ToastBox.ShowText("今天次数不足,请明天再来."); // return; //} var pet = this.selectedPet; if (!pet.isMaxGrade) { var result = PetProxy.Instance.UpgradePet(pet, false); if (result > 0) { RefreshGrade(); UpdateView(); RefreshFeed(); } if (result > 1) ToastBox.ShowEffect("UI_fx_chongwutupo"); //ToastBox.ShowText("获得1000经验"); } else { ToastBox.ShowText("宠物已满级"); } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnAdFeedBtnClick() { int feedCount = TimeProxy.Instance.GetTimes(TimeProxy.宠物升级); if (feedCount <= 0) { ToastBox.ShowText("今天次数不足,请明天再来."); return; } var pet = this.selectedPet; if (!pet.isMaxGrade) { AdProxy.Instance.PlayAdChange("pet", "ads_pet_feed", (error, message) => { if (error == 0) { var result = PetProxy.Instance.UpgradePet(pet, true); if (result > 0) { RefreshGrade(); UpdateView(); RefreshFeed(); } if (result > 1) ToastBox.ShowEffect("UI_fx_chongwutupo"); //ToastBox.ShowText("获得2000经验"); } }); } else { ToastBox.ShowText("宠物已满级"); } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } void OnBattleBtnClick() { var petInfo = this.selectedPet; if (petInfo.isFriend) { petInfo.isBattling = !petInfo.isBattling; _goStatus.SetActive(petInfo.isBattling); _tmpBattle.text = petInfo.isBattling ? "休息" : "出战"; RefreshBattleStatus(); } else { ToastBox.ShowText("宠物未获得"); } } private void OnSkillBookBtnClick() { OpenWindow(); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnRenameBtnClick() { var pet = selectedPet; if (pet.isFriend) NameBox.Show(selectedPet.name, (result) => { selectedPet.name = result; RefreshName(); }); else ToastBox.ShowText("宠物获得后才能改名"); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } void OnRankingBtnClick() { OpenWindow("pet"); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } void OnGetBtnClick() { var pet = selectedPet; if (pet != null) { if (pet.item.access == 1) { CloseWindow(this); PostNotification(GlobalDefine.EVENT_MAIN_WINDOW_PAGE, null, "0"); } else { var friendId = pet.friendId; if (friendId != Item.Id.kFriend) { var propCount = ItemProxy.Instance.GetPropCount(friendId); var propCountMax = pet.friendMax; if (propCount >= propCountMax) { ItemProxy.Instance.SetPropCount(friendId, propCount - propCountMax); pet.Active(); RefreshView(); } else { //ToastBox.ShowText("道具不足"); if (pet.item.access == 7) { if (QingMingActivity.Instance.isStartActivity) { CloseWindow(this); OpenWindow(); } else { ToastBox.ShowText("活动未开启"); } return; } var gemProp = ItemProxy.Instance.GetStaticItem(26);//修改为打开道具获取路径 OpenWindow(gemProp); } } } } } private void OnBackBtnClick() { CloseWindow(this); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnLeftBtnClick() { if (_petIndex > 0) { _petIndex--; RefreshPetSelect(); } } private void OnRightBtnClick() { if (_petIndex < _pets.Count - 1) { _petIndex++; RefreshPetSelect(); } } private void OnRecastBtnClick() { ShowRecastPanel(true); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } #endregion } }