636 lines
18 KiB
C#
636 lines
18 KiB
C#
using cfg.CharacterCfg;
|
|
using cfg.LevelCfg;
|
|
using cfg.VihecleCultivateCfg;
|
|
using Framework;
|
|
using Gameplay;
|
|
using PhxhSDK;
|
|
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 UITextDropdown<int> terrainDropDown;
|
|
private UITextDropdown<int> strengthDropDown;
|
|
|
|
List<VehicleCultivateData> mCurVehicles;
|
|
List<VehicleCultivateData> mShowList;
|
|
private int mCurTerrainId;
|
|
private EStrenthSortType mCurStrengthSortType;
|
|
|
|
private GameObject mTerrainBtnObj;
|
|
private GameObject mStrengthBtnObj;
|
|
private GameObject mLevelBtnObj;
|
|
|
|
Dictionary<GameObject, VehicleCultivateData> mUIHeadGoDic;
|
|
|
|
PhxhScrollView _mCurrentScrollView = null;
|
|
|
|
List<VehicleCultivateData> mSortedCInfoList = new List<VehicleCultivateData>();
|
|
|
|
|
|
private bool IsSmall2Big = false;
|
|
private Team _curTeam;
|
|
private OpenType _curOpenType = OpenType.Normal;
|
|
private const int ALL_DROPDOWN_VALUE = -1;
|
|
|
|
enum OpenType
|
|
{
|
|
Normal,
|
|
EditTeam
|
|
}
|
|
|
|
///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<VehicleCultivateData>();
|
|
mShowList = new List<VehicleCultivateData>();
|
|
mUIHeadGoDic = new Dictionary<GameObject, VehicleCultivateData>();
|
|
|
|
|
|
mCurrentScrollViewContentObj = FindObj("Image_BG/UI_Vehicle/ScrollView/Viewport/Content");
|
|
_mCurrentScrollView = GetComponent<PhxhScrollView>("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 =
|
|
new UITextDropdown<int>(FindObj("Image_BG/Button_AllTerrian"), FindObj("Image_BG/Button_AllTerrian/Text_AllTerrian"), TerrainDropdownValueChanged, TerrainDropdownData2Text);
|
|
|
|
|
|
strengthDropDown =
|
|
new UITextDropdown<int>(FindObj("Image_BG/Button_AllType"), FindObj("Image_BG/Button_AllType/Text_AllType"), StrengthDropdownValueChanged, StrengthDropdownData2Text);
|
|
|
|
|
|
mCurTerrainId = 0;
|
|
mCurStrengthSortType = EStrenthSortType.EAll;
|
|
}
|
|
|
|
private string TerrainDropdownData2Text(int value)
|
|
{
|
|
if (value == ALL_DROPDOWN_VALUE)
|
|
{
|
|
return CommonUtils.GetLocalizeText("vehicleCultivate_AllTerrain");
|
|
}
|
|
else
|
|
{
|
|
DataTerrianProp dataTerrianProp = TableManager.Instance.Tables.TerrianProp.DataList[value];
|
|
return CommonUtils.GetLocalizeText(dataTerrianProp.DisplayName);
|
|
|
|
}
|
|
}
|
|
private string StrengthDropdownData2Text(int value)
|
|
{
|
|
if (value == ALL_DROPDOWN_VALUE)
|
|
{
|
|
return CommonUtils.GetLocalizeText("vehicleCultivate_AllType");
|
|
}
|
|
else
|
|
{
|
|
|
|
return GetStrenthSortTypeLocalize((EStrenthSortType)value);
|
|
|
|
}
|
|
}
|
|
private void TerrainDropdownValueChanged(int value)
|
|
{
|
|
if ((int)mCurTerrainId == value)
|
|
{
|
|
return;
|
|
}
|
|
mCurTerrainId = value;
|
|
|
|
if (value == 0)
|
|
{
|
|
CommonUtils.GetComponent<TMP_Text>(CommonUtils.GetGameObject(mTerrainBtnObj, "Text_AllTerrian")).text = CommonUtils.GetLocalizeText("vehicleCultivate_AllTerrain");
|
|
|
|
}
|
|
else
|
|
{
|
|
DataTerrianProp dataTerrianProp = TableManager.Instance.Tables.TerrianProp.DataList[value];
|
|
CommonUtils.GetComponent<TMP_Text>(CommonUtils.GetGameObject(mTerrainBtnObj, "Text_AllTerrian")).text = CommonUtils.GetLocalizeText(dataTerrianProp.DisplayName);
|
|
|
|
}
|
|
|
|
SortListByTerrainAdapt(mCurTerrainId);
|
|
SortListByStrengthType();
|
|
RefreshScrollView();
|
|
}
|
|
private void StrengthDropdownValueChanged(int value)
|
|
{
|
|
if ((int)mCurStrengthSortType == value)
|
|
{
|
|
return;
|
|
}
|
|
mCurStrengthSortType = (EStrenthSortType)value;
|
|
|
|
SortListByTerrainAdapt(mCurTerrainId);
|
|
SortListByStrengthType();
|
|
RefreshScrollView();
|
|
}
|
|
|
|
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()
|
|
{
|
|
CommonUtils.GetGameObject(mLevelBtnObj, "Image_Default/Image_UP").SetActive(IsSmall2Big);
|
|
CommonUtils.GetGameObject(mLevelBtnObj, "Image_Default/Image_Down").SetActive(!IsSmall2Big);
|
|
}
|
|
|
|
|
|
private void StrengthDropdownValueChanged(TMP_Dropdown change)
|
|
{
|
|
if ((int)mCurStrengthSortType == change.value)
|
|
{
|
|
return;
|
|
}
|
|
mCurStrengthSortType = (EStrenthSortType)change.value;
|
|
|
|
if (change.value == 0)
|
|
{
|
|
CommonUtils.GetComponent<TMP_Text>(CommonUtils.GetGameObject(mStrengthBtnObj, "Text_AllType")).text = CommonUtils.GetLocalizeText("vehicleCultivate_AllType");
|
|
}
|
|
else
|
|
{
|
|
CommonUtils.GetComponent<TMP_Text>(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();
|
|
}
|
|
|
|
protected override void OnOpenWindow(object data = null)
|
|
{
|
|
if (data != null)
|
|
{
|
|
_curTeam = data as Team;
|
|
_curOpenType = OpenType.EditTeam;
|
|
}
|
|
AddDropDownOption();
|
|
GetStorageData();
|
|
PreLoadAllVehicle();
|
|
RegisterEvent();
|
|
GetSelectedList();
|
|
CreateScrollView();
|
|
}
|
|
private void AddDropDownOption()
|
|
{
|
|
AddTerrainDropDownOption();
|
|
AddStrenthDropDownOption();
|
|
}
|
|
private void AddTerrainDropDownOption()
|
|
{
|
|
var dropDownData = new List<int>() { ALL_DROPDOWN_VALUE };
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
dropDownData.Add(i);
|
|
}
|
|
terrainDropDown.SetData(dropDownData);
|
|
|
|
}
|
|
|
|
private void AddStrenthDropDownOption()
|
|
{
|
|
|
|
var dropDownData = new List<int>();
|
|
System.Array ints = System.Enum.GetValues(typeof(EStrenthSortType));
|
|
for (int i = 0; i < ints.Length; i++)
|
|
{
|
|
dropDownData.Add((int)ints.GetValue(i));
|
|
|
|
}
|
|
|
|
strengthDropDown.SetData(dropDownData);
|
|
|
|
|
|
|
|
}
|
|
|
|
private string GetStrenthSortTypeLocalize(EStrenthSortType strenthSortType)
|
|
{
|
|
switch (strenthSortType)
|
|
{
|
|
case EStrenthSortType.EAll:
|
|
return CommonUtils.GetLocalizeText("vehicleCultivate_AllType");
|
|
case EStrenthSortType.EAttack:
|
|
return CommonUtils.GetLocalizeText("cultivate_Attack");
|
|
case EStrenthSortType.EHP:
|
|
return CommonUtils.GetLocalizeText("cultivate_Hp");
|
|
case EStrenthSortType.EDenfense:
|
|
return 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)
|
|
{
|
|
CommonUtils.DestoryAllChildGameObject(mCurrentScrollViewContentObj);
|
|
}
|
|
|
|
if (_curOpenType == OpenType.Normal)
|
|
{
|
|
_mCurrentScrollView.SetUpdateFunc(RefreshItem);
|
|
_mCurrentScrollView.SetItemCountFunc(GetCountFunc);
|
|
_mCurrentScrollView.UpdateData(false);
|
|
_mCurrentScrollView.SetButton(SetScrollviewItemButton);
|
|
return;
|
|
}
|
|
|
|
if (_curOpenType == OpenType.EditTeam)
|
|
{
|
|
_mCurrentScrollView.SetUpdateFunc(RefreshItem_EditTeam);
|
|
_mCurrentScrollView.SetItemCountFunc(GetCountFunc_EditTeam);
|
|
_mCurrentScrollView.UpdateData(false);
|
|
_mCurrentScrollView.SetButton(SetItemButton);
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void SetScrollviewItemButton(GameObject obj)
|
|
{
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
GameObject singleObj = CommonUtils.GetGameObject(obj, (i + 1).ToString());
|
|
if (singleObj != null)
|
|
{
|
|
ClearBind(singleObj);
|
|
BindButton<GameObject>(singleObj, On2DPicClick, singleObj);
|
|
}
|
|
}
|
|
}
|
|
public class VehicleCultivateParam
|
|
{
|
|
public List<VehicleCultivateData> 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 = 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;
|
|
if (index == 0 && i == 0)
|
|
{
|
|
var imgBack = CommonUtils.GetComponent<Image>(singleItem, "Image_Back");
|
|
imgBack.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
singleItem.SetActive(false);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void RefreshSingleItem(GameObject singleItem, VehicleCultivateData tempVehcile)
|
|
{
|
|
CommonUtils.GetComponent<TMP_Text>(singleItem, "Image_BlackDown/Text_Lv").text = tempVehcile.SumPowerLevel().ToString();
|
|
CommonUtils.GetComponent<TMP_Text>(singleItem, "Image_BlackDown/Text_Name").text = tempVehcile.Cfg.Name.ToString();
|
|
Image img = CommonUtils.GetComponent<Image>(singleItem, "Image_HeadPic");
|
|
var imgMask = CommonUtils.GetComponent<Image>(singleItem, "Image_Mask");
|
|
imgMask.gameObject.SetActive(false);
|
|
|
|
string imgPath = VehicleDataHelper.GetVehiclePicPath(tempVehcile.Cfg.ID);
|
|
|
|
if (imgPath != null)
|
|
{
|
|
AssetManager.Instance.LoadAssetOnCallBack<Sprite>(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;
|
|
}
|
|
|
|
CommonUtils.GetComponent<TMP_Text>(singleItem, "Image_BlackDown/Text_PropertyValue").text = strengthPoint;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编队选择模式
|
|
/// </summary>
|
|
private void RefreshItem_EditTeam(int index, RectTransform item)
|
|
{
|
|
item.gameObject.SetActive(true);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
GameObject singleItem = CommonUtils.GetGameObject(item.gameObject, (i + 1).ToString());
|
|
|
|
var realIdx = index * 4 + i - 1;
|
|
if (realIdx < 0)
|
|
{
|
|
RefreshSingleItem_EditTeam(singleItem, null, true);
|
|
}
|
|
else if (realIdx < mShowList.Count)
|
|
{
|
|
var tempDataInfo = mShowList[realIdx];
|
|
RefreshSingleItem_EditTeam(singleItem, tempDataInfo);
|
|
mUIHeadGoDic[singleItem] = tempDataInfo;
|
|
}
|
|
else
|
|
{
|
|
singleItem.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RefreshSingleItem_EditTeam(GameObject go, VehicleCultivateData tempDataInfo, bool isFirst = false)
|
|
{
|
|
var goMask = CommonUtils.GetGameObject(go, "Image_Mask");
|
|
if (isFirst)
|
|
{
|
|
var goHeadPic = CommonUtils.GetGameObject(go, "Image_HeadPic");
|
|
var goBlackDown = CommonUtils.GetGameObject(go, "Image_BlackDown");
|
|
var goBack = CommonUtils.GetGameObject(go, "Image_Back");
|
|
goHeadPic.SetActive(false);
|
|
goBlackDown.SetActive(false);
|
|
goMask.SetActive(false);
|
|
goBack.SetActive(true);
|
|
return;
|
|
}
|
|
RefreshSingleItem(go, tempDataInfo);
|
|
goMask.SetActive(_curTeam.GetVehicleID() == tempDataInfo.nID);
|
|
}
|
|
|
|
private int GetCountFunc_EditTeam()
|
|
{
|
|
var count = mShowList.Count + 1;
|
|
int row;
|
|
if (count % 4 == 0)
|
|
{
|
|
row = count / 4;
|
|
}
|
|
else
|
|
{
|
|
row = count / 4 + 1;
|
|
}
|
|
return row;
|
|
}
|
|
|
|
private void SetItemButton(GameObject go)
|
|
{
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
var obj = CommonUtils.GetGameObject(go, (i + 1).ToString());
|
|
if (obj != null)
|
|
{
|
|
ClearBind(obj);
|
|
BindButton(obj, OnClickItem, obj);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnClickItem(GameObject obj)
|
|
{
|
|
uint vehicleID = Team.NONE_ID;
|
|
if (mUIHeadGoDic.TryGetValue(obj, out var vehicleData))
|
|
{
|
|
vehicleID = vehicleData.nID;
|
|
}
|
|
EventManager.Instance.Send(EventManager.EventName.TeamEditVehicleChoose, vehicleID);
|
|
RefreshScrollView();
|
|
}
|
|
///
|
|
|
|
private void RegisterEvent()
|
|
{
|
|
|
|
}
|
|
//invoke when reload window
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
|
|
protected override void OnCloseWindow()
|
|
{
|
|
mUIHeadGoDic.Clear();
|
|
}
|
|
void GetStorageData()
|
|
{
|
|
mCurVehicles.Clear();
|
|
mCurVehicles.AddRange(VehicleCultivateDataManager.Instance.DataList);
|
|
}
|
|
private void PreLoadAllVehicle()
|
|
{
|
|
for (int i = 0; i < mCurVehicles.Count; i++)
|
|
{
|
|
string strPath = VehicleDataHelper.GetVehiclePicPath(mCurVehicles[i].Cfg.ID);
|
|
AssetManager.Instance.PostPreload<Sprite>(strPath);
|
|
}
|
|
}
|
|
|
|
} |