using cfg.CharacterCfg; using cfg.LevelCfg; using cfg.VihecleCultivateCfg; using Framework; using Gameplay; using PhxhSDK; using System; using System.Collections.Generic; using TMPro; using UnityEngine; using Button = UnityEngine.UI.Button; using Image = UnityEngine.UI.Image; public class UI_VehicleChooseController : UIWindow { //UI GameObj ///Auto Gen Start/// public Image Image_BG; public Button Button_Back; public TMP_Text Text_Back; public Button Button_Home; public Image Image_HeadPic; public Image Image_BlackDown; public Image Image_Job; public TMP_Text Text_Lv; public TMP_Text Text_PropertyValue; public TMP_Text Text_Name; public Image Image_LevelBG; public Button Button_Level; public TMP_Text Text_Level; public Button Button_Team; public TMP_Text Text_Team; public Button Button_AllTerrian; public TMP_Text Text_AllTerrian; public Button Button_AllType; public TMP_Text Text_AllType; private GameObject mCurrentScrollViewContentObj = null; private TMP_Dropdown terrainDropDown; private TMP_Dropdown strengthDropDown; List mCurVehicles; List mShowList ; List disPlayTerrianTypeList; private int mCurTerrainId ; private EStrenthSortType mCurStrengthSortType ; private GameObject mTerrainBtnObj; private GameObject mStrengthBtnObj; private GameObject mLevelBtnObj; Dictionary mUIHeadGoDic; Framework.PhxhScrollView _mCurrentScrollView = null; List mSortedCInfoList = new List(); private bool IsSmall2Big = false; ///Auto Gen End/// // Use this for initialization enum EStrenthSortType { EAll=0, EHP=1, EAttack=2, EDenfense=3, } public override void OnAwake() { //bind UI GameObj UI_VehicleChooseBinder.GetComponents(this); BindButton(Button_Back, OnBackClick); BindButton(Button_Home, OnClickHome); BindButton("Image_BG/Level", OnButton_LevelClick); mCurVehicles = new List(); mShowList = new List(); disPlayTerrianTypeList = new List(); mUIHeadGoDic = new Dictionary(); terrainDropDown = GetComponent("Image_BG/Button_AllTerrian"); strengthDropDown = GetComponent("Image_BG/Button_AllType"); mCurrentScrollViewContentObj = FindObj("Image_BG/UI_Vehicle/ScrollView/Viewport/Content"); _mCurrentScrollView = GetComponent("Image_BG/UI_Vehicle/ScrollView"); mCurrentScrollViewContentObj = FindObj("Image_BG/UI_Vehicle/ScrollView/Viewport/Content"); mTerrainBtnObj = FindObj("Image_BG/Button_AllTerrian"); mStrengthBtnObj = FindObj("Image_BG/Button_AllType"); mLevelBtnObj = FindObj("Image_BG/Level"); terrainDropDown.onValueChanged.AddListener(delegate { TerrainDropdownValueChanged(terrainDropDown); }); strengthDropDown.onValueChanged.AddListener(delegate { StrengthDropdownValueChanged(strengthDropDown); }); mCurTerrainId = 0; mCurStrengthSortType = EStrenthSortType.EAll; } private void OnButton_LevelClick() { IsSmall2Big = !IsSmall2Big; mShowList.Clear(); mShowList.AddRange(mCurVehicles); if (!IsSmall2Big) { mShowList.Sort((a, b) => { return a.SumPowerLevel().CompareTo(b.SumPowerLevel()); }); } else { mShowList.Sort((a, b) => { return b.SumPowerLevel().CompareTo(a.SumPowerLevel()); }); } RefreshScrollView(); //RefreshLevelUpSortBtn(); } private void RefreshLevelUpSortBtn() { Utils.CommonUtils.GetGameObject(mLevelBtnObj, "Image_Default/Image_UP").SetActive(IsSmall2Big); Utils.CommonUtils.GetGameObject(mLevelBtnObj, "Image_Default/Image_Down").SetActive(!IsSmall2Big); } private void TerrainDropdownValueChanged(TMP_Dropdown change) { if ((int)mCurTerrainId == change.value) { return; } mCurTerrainId= change.value; if (change.value == 0) { Utils.CommonUtils.GetComponent(Utils.CommonUtils.GetGameObject(mTerrainBtnObj, "Text_AllTerrian")).text = Utils.CommonUtils.GetLocalizeText("vehicleCultivate_AllTerrain"); } else { DataTerrianProp dataTerrianProp = disPlayTerrianTypeList[change.value-1]; Utils.CommonUtils.GetComponent(Utils.CommonUtils.GetGameObject(mTerrainBtnObj, "Text_AllTerrian")).text = Utils.CommonUtils.GetLocalizeText(dataTerrianProp.DisplayName); } SortListByTerrainAdapt(mCurTerrainId); SortListByStrengthType(); RefreshScrollView(); } private void StrengthDropdownValueChanged(TMP_Dropdown change) { if ((int)mCurStrengthSortType == change.value) { return; } mCurStrengthSortType = (EStrenthSortType)change.value; if (change.value == 0) { Utils.CommonUtils.GetComponent(Utils.CommonUtils.GetGameObject(mStrengthBtnObj, "Text_AllType")).text = Utils.CommonUtils.GetLocalizeText("vehicleCultivate_AllType"); } else { Utils.CommonUtils.GetComponent(Utils.CommonUtils.GetGameObject(mStrengthBtnObj, "Text_AllType")).text = GetStrenthSortTypeLocalize(mCurStrengthSortType); } SortListByTerrainAdapt(mCurTerrainId); SortListByStrengthType(); RefreshScrollView(); } private void RefreshScrollView() { _mCurrentScrollView.UpdateData(true); } private void SortListByStrengthType() { mShowList.Clear(); mShowList.AddRange(mSortedCInfoList); if (mCurStrengthSortType ==EStrenthSortType.EAll) { return; } switch (mCurStrengthSortType) { case EStrenthSortType.EAttack: mShowList.Sort((a, b) => { return b.Attack().CompareTo(a.Attack()); }); return; case EStrenthSortType.EHP: mShowList.Sort((a, b) => { return b.Hp().CompareTo(a.Hp()); }); return; case EStrenthSortType.EDenfense: mShowList.Sort((a, b) => { return b.Defense().CompareTo(a.Defense()); }); return; } DebugUtil.LogError("按照常理来说不可能走到这里,走到了说明代码没加完,但是还是写上,虽然可能莫得用"); return; } void SortListByTerrainAdapt(int terrainId) { mSortedCInfoList.Clear(); mSortedCInfoList.AddRange(mCurVehicles); mCurTerrainId = terrainId; if (terrainId==0) { return; } BonusType bonusType = VehicleDataHelper.GetBonusTypeByTerrainID(terrainId); if (!IsSmall2Big) { mSortedCInfoList.Sort((a, b) => { return a.GetTerrainAdapt(bonusType).CompareTo(b.GetTerrainAdapt(bonusType)); }); } else { mSortedCInfoList.Sort((a, b) => { return b.GetTerrainAdapt(bonusType).CompareTo(a.GetTerrainAdapt(bonusType)); }); } } private void OnClickHome() { UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel); } private void OnBackClick() { CloseWindow(); } //invoke when open window protected override void OnOpenWindow() { AddDropDownOption(); GetStorageData(); PreLoadAllVehicle(); RegisterEvent(); GetSelectedList(); CreateScrollView(); } private void AddDropDownOption() { AddTerrainDropDownOption(); AddStrenthDropDownOption(); } private void AddTerrainDropDownOption() { terrainDropDown.ClearOptions(); TMP_Dropdown.OptionData m_NewData1 = new TMP_Dropdown.OptionData(); m_NewData1.text = Utils.CommonUtils.GetLocalizeText("vehicleCultivate_AllTerrain"); terrainDropDown.options.Add(m_NewData1); disPlayTerrianTypeList.Clear(); for (int i = 0; i < 4; i++) { DataTerrianProp terrianProp = TableManager.Instance.Tables.TerrianProp.DataList[i]; disPlayTerrianTypeList.Add(terrianProp); TMP_Dropdown.OptionData m_NewData2 = new TMP_Dropdown.OptionData(); m_NewData2.text =Utils.CommonUtils.GetLocalizeText( terrianProp.DisplayName); terrainDropDown.options.Add(m_NewData2); } } private void AddStrenthDropDownOption() { strengthDropDown.ClearOptions(); System.Array ints = System.Enum.GetValues(typeof(EStrenthSortType)); for (int i = 0; i < ints.Length; i++) { TMP_Dropdown.OptionData m_NewData1 = new TMP_Dropdown.OptionData(); m_NewData1.text = GetStrenthSortTypeLocalize(((EStrenthSortType)ints.GetValue(i))).ToString(); strengthDropDown.options.Add(m_NewData1); } } private string GetStrenthSortTypeLocalize(EStrenthSortType strenthSortType) { switch (strenthSortType) { case EStrenthSortType.EAll: return Utils.CommonUtils.GetLocalizeText("vehicleCultivate_AllType"); case EStrenthSortType.EAttack: return Utils.CommonUtils.GetLocalizeText("cultivate_Attack"); case EStrenthSortType.EHP: return Utils.CommonUtils.GetLocalizeText("cultivate_Hp"); case EStrenthSortType.EDenfense: return Utils.CommonUtils.GetLocalizeText("cultivate_Defense"); } return ""; } private void GetSelectedList() { SortListByTerrainAdapt(mCurTerrainId); SortListByStrengthType(); } private void CreateScrollView() { if (!ShowIfNull()) { SetScrollViewAll(); } } private bool ShowIfNull() { if (mShowList.Count == 0) { FindObj("Nothing").SetActive(true); return true; } else { FindObj("Nothing").SetActive(false); return false; } } private void SetScrollViewAll() { if (null != mCurrentScrollViewContentObj) { Utils.CommonUtils.DestoryAllChildGameObject(mCurrentScrollViewContentObj); } _mCurrentScrollView.SetUpdateFunc(RefreshItem); _mCurrentScrollView.SetItemCountFunc(GetCountFunc); _mCurrentScrollView.UpdateData(false); _mCurrentScrollView.SetButton(SetScrollviewItemButton); } private void SetScrollviewItemButton(GameObject obj) { for (int i = 0; i < 4; i++) { GameObject singleObj = Utils.CommonUtils.GetGameObject(obj, (i + 1).ToString()); if (singleObj != null) { ClearBind(singleObj); BindButton(singleObj, On2DPicClick, singleObj); } } } public class VehicleCultivateParam { public List showList; public VehicleCultivateData info; } private async void On2DPicClick(GameObject go) { VehicleCultivateData info = mUIHeadGoDic[go]; VehicleCultivateParam cultivateStruct = new VehicleCultivateParam(); cultivateStruct.showList = mShowList; cultivateStruct.info = info; await UIManager.Instance.OpenWindow(UINameConst.UI_VehicleCultivate, cultivateStruct); } private int GetCountFunc() { int row; if (mShowList.Count % 4 == 0) { row = mShowList.Count / 4; } else { row = mShowList.Count / 4 + 1; } return row; } private void RefreshItem(int index, RectTransform item) { item.gameObject.SetActive(true); for (int i = 0; i < 4; i++) { GameObject singleItem = Utils.CommonUtils.GetGameObject(item.gameObject, (i + 1).ToString()); if (index * 4 + i < mShowList.Count) { singleItem.SetActive(true); VehicleCultivateData tempDataInfo = mShowList[index * 4 + i]; RefreshSingleItem(singleItem, tempDataInfo); mUIHeadGoDic[singleItem] = tempDataInfo; } else { singleItem.SetActive(false); } } } private void RefreshSingleItem(GameObject singleItem, VehicleCultivateData tempVehcile) { Utils.CommonUtils.GetComponent(singleItem, "Image_BlackDown/Text_Lv").text = tempVehcile.SumPowerLevel().ToString(); Utils.CommonUtils.GetComponent(singleItem, "Image_BlackDown/Text_Name").text = tempVehcile.Cfg.Name.ToString(); Image img = Utils.CommonUtils.GetComponent(singleItem, "Image_HeadPic"); string imgPath = Utils.CommonUtils.GetVehiclePicPath(tempVehcile.Cfg.ID); if (imgPath != null) { AssetManager.Instance.LoadAssetOnCallBack(imgPath, spr => { img.sprite = spr; img.gameObject.SetActive(true); }); } string strengthPoint = ""; switch (mCurStrengthSortType) { case EStrenthSortType.EAll: break; case EStrenthSortType.EDenfense: strengthPoint ="+"+ tempVehcile.Defense(); break; case EStrenthSortType.EAttack: strengthPoint="+"+ tempVehcile.Attack(); break; case EStrenthSortType.EHP: strengthPoint = "+" + tempVehcile.Hp(); break; } Utils.CommonUtils.GetComponent(singleItem, "Image_BlackDown/Text_PropertyValue").text = strengthPoint; } private void RegisterEvent() { } //invoke when reload window protected override void OnReloadWindow(object data = null) { } void GetStorageData() { mCurVehicles.Clear(); mCurVehicles.AddRange(VehicleCultivateDataManager.Instance.DataList); } private void PreLoadAllVehicle() { for (int i = 0; i < mCurVehicles.Count; i++) { string strPath = Utils.CommonUtils.GetVehiclePicPath(mCurVehicles[i].Cfg.ID); AssetManager.Instance.PostPreload(strPath); } } }