using asap.core; using cfg; using game; using GameCore; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class event_fishingduel_rod_change : MonoBehaviour { public Image[] traits; FishingDuelManager FDM; public Button btn_confrim; public Button btn_questionmark; public GameObject item; public Transform Content; public TMP_Text p_text; public TMP_Text text_title; public duel_rod_trait_tips trait_tips; List rodItemDatas = new List(); List rodItems = new List(); private DuelRodItem currentRodItem; Tables tables; public int allTime; private void Awake() { tables = GContext.container.Resolve(); FDM = GContext.container.Resolve(); item.SetActive(false); } private void Start() { IUIService uiService = GContext.container.Resolve(); List traitID = FDM.TraitID; for (int i = 0; i < traits.Length; i++) { if (i < traitID.Count) { RodAscendPerk rodAscendPerk = tables.TbRodAscendPerk.GetOrDefault(traitID[i]); string iconName = rodAscendPerk.Icon; uiService.SetImageSprite(traits[i], iconName); uiService.SetImageSprite(trait_tips.trait_icons[i], iconName); trait_tips.trait_names[i].text = LocalizationMgr.GetText(rodAscendPerk.Title_l10n_key); } else { traits[i].transform.parent.gameObject.SetActive(false); trait_tips.tips[i].SetActive(false); } } btn_confrim.onClick.AddListener(OnClickConfrim); btn_questionmark.onClick.AddListener(OnClickQuestion); InitRodList(); } void OnClickQuestion() { trait_tips.gameObject.SetActive(true); } void OnClickConfrim() { if (currentRodItem.data.isLock) { //弹提示 ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_85")); return; } if (GContext.container.Resolve().equipRodID != currentRodItem.data.config.ID) { GContext.container.Resolve().SetEquipRodID(currentRodItem.data.config.ID); } GContext.Publish(new ActChangeRodDataEvent(currentRodItem.data.config.ID)); FDM.SetRodData(currentRodItem.data.config.ID); gameObject.SetActive(false); } void InitRodList() { var _tables = GContext.container.Resolve(); var dataList = _tables.TbRodData.DataList; int count = dataList.Count; RodData _rodData; PlayerFishData playerFishData = GContext.container.Resolve(); for (int i = 0; i < count; i++) { _rodData = dataList[i]; bool isLock = playerFishData.NotRod(_rodData.ID); int level = playerFishData.GetRodLevel(_rodData.ID); int star = playerFishData.GetRodPiece(_rodData.ID); RodItemData rodItemData = new RodItemData() { config = dataList[i], isLock = isLock, level = level + 1, star = star, }; if (!isLock) { FDM.GetDuelPerk(rodItemData); } int skindID = playerFishData.GetRodSkin(_rodData.ID); rodItemData.skin = _tables.TbRodSkinData.GetOrDefault(skindID); rodItemDatas.Add(rodItemData); } rodItemDatas.Sort(RodItemData.Sort); for (int i = 0; i < rodItemDatas.Count; i++) { GameObject go = Instantiate(item, Content); go.SetActive(true); DuelRodItem rodItem = go.GetComponent(); rodItems.Add(rodItem); rodItem.Init(rodItemDatas[i]); rodItem.onClick = OnRodItemClick; } currentRodItem = rodItems[0]; currentRodItem.SetSelected(true); } private void OnEnable() { if (currentRodItem != null && rodItems.Count > 0) { currentRodItem = rodItems[0]; currentRodItem.SetSelected(true); } } void OnRodItemClick(DuelRodItem duelRodItem) { if (duelRodItem.data.isLock) { ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_85")); return; } if (currentRodItem != null) { currentRodItem.SetSelected(false); } currentRodItem = duelRodItem; currentRodItem.SetSelected(true); } public void SetTimer() { StartCoroutine(Close()); } IEnumerator Close() { while (allTime > 0) { p_text.text = LocalizationMgr.GetFormatTextValue("UI_EventFishingDuelPanel_41", allTime); allTime--; yield return new WaitForSeconds(1); } p_text.text = LocalizationMgr.GetFormatTextValue("UI_EventFishingDuelPanel_41", 0); OnClickConfrim(); } private void OnDisable() { p_text.text = LocalizationMgr.GetText("UI_COMMON_confirm"); StopAllCoroutines(); currentRodItem.SetSelected(false); RestartShowHomeUIEvent restartShowHomeUIEvent = new RestartShowHomeUIEvent(); GContext.Publish(restartShowHomeUIEvent); } }