370 lines
11 KiB
C#
370 lines
11 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using UnityEngine.UIElements;
|
||
using Button = UnityEngine.UI.Button;
|
||
using Image = UnityEngine.UI.Image;
|
||
using Toggle = UnityEngine.UI.Toggle;
|
||
using ScrollView = PhxhSDK.PhxhScrollView;
|
||
using Framework;
|
||
using Cysharp.Threading.Tasks;
|
||
using DG.Tweening;
|
||
using System;
|
||
using Gameplay.Net;
|
||
using cfg.VihecleCultivateCfg;
|
||
using cfg.SkillCfg;
|
||
using Gameplay;
|
||
|
||
public class UI_VehiclePartTreeDetailController : UIWindow
|
||
{
|
||
#region UI
|
||
//UI GameObj
|
||
///Auto Gen Start///
|
||
public Image Image_Bg;
|
||
public TMP_Text Text_Name;
|
||
public Button Button_Check;
|
||
public Image Image_Attributes;
|
||
public TMP_Text Text_AttributesTitle;
|
||
public Image Image_UpSign_Hp;
|
||
public Image Image_UpBg_Hp;
|
||
public TMP_Text Text_Title_Hp;
|
||
public TMP_Text Text_UpTitle_Hp;
|
||
public TMP_Text Text_Value_Hp;
|
||
public Image Image_UpSign_MemberCount;
|
||
public Image Image_UpBg_MemberCount;
|
||
public TMP_Text Text_Title_MemberCount;
|
||
public TMP_Text Text_UpTitle_MemberCount;
|
||
public TMP_Text Text_Value_MemberCount;
|
||
public Image Image_UpSign_Def;
|
||
public Image Image_UpBg_Def;
|
||
public TMP_Text Text_Title_Def;
|
||
public TMP_Text Text_UpTitle_Def;
|
||
public TMP_Text Text_Value_Def;
|
||
public Image Image_UpSign_Atk;
|
||
public Image Image_UpBg_Atk;
|
||
public TMP_Text Text_Title_Atk;
|
||
public TMP_Text Text_UpTitle_Atk;
|
||
public TMP_Text Text_Value_Atk;
|
||
public Image Image_UpSign_BulletCount;
|
||
public Image Image_UpBg_BulletCount;
|
||
public TMP_Text Text_Title_BulletCount;
|
||
public TMP_Text Text_UpTitle_BulletCount;
|
||
public TMP_Text Text_Value_BulletCount;
|
||
public Image Image_UpSign_Speed;
|
||
public Image Image_UpBg_Speed;
|
||
public TMP_Text Text_Title_Speed;
|
||
public TMP_Text Text_UpTitle_Speed;
|
||
public TMP_Text Text_Value_Speed;
|
||
public Image Image_Terrain;
|
||
public TMP_Text Text_TerrainTitle;
|
||
public TMP_Text Text_Title_Ground;
|
||
public TMP_Text Text_Value_Ground;
|
||
public TMP_Text Text_Title_Mountain;
|
||
public TMP_Text Text_Value_Mountain;
|
||
public TMP_Text Text_Title_Snow;
|
||
public TMP_Text Text_Value_Snow;
|
||
public TMP_Text Text_Title_Wood;
|
||
public TMP_Text Text_Value_Wood;
|
||
public Image Image_SkillBg;
|
||
public Image Image_VehicleSkill;
|
||
public TMP_Text Text_TitleSkill;
|
||
public TMP_Text Text_SkillName;
|
||
public TMP_Text Text_ClassTitle;
|
||
public TMP_Text Text_SkillLevel;
|
||
public Image Image_SkillIcon;
|
||
public Image Image_SkillCoolingTimeBg;
|
||
public TMP_Text Text_SkillCoolingTimeValue;
|
||
public TMP_Text Text_SkillInfo;
|
||
public Button Button_Equipment;
|
||
|
||
///Auto Gen End///
|
||
#endregion
|
||
|
||
|
||
private long ID;
|
||
//private bool EnterPartTree;
|
||
private Action m_ReleaseCallback;
|
||
|
||
class InitData
|
||
{
|
||
public long ID;
|
||
public bool EnterPartTree;
|
||
public Action callback;
|
||
|
||
public InitData(long id, bool enterPartTree,Action onReleaseCallback)
|
||
{
|
||
ID = id;
|
||
EnterPartTree = enterPartTree;
|
||
callback = onReleaseCallback;
|
||
}
|
||
}
|
||
|
||
public async static UniTask<UIWindow> Open(long TreeNodeID, bool EnterPartTree = false, Action OnReleaseCallback = null)
|
||
{
|
||
var initdata = new InitData(TreeNodeID, EnterPartTree, OnReleaseCallback);
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_VehiclePartTreeDetail, initdata);
|
||
}
|
||
|
||
// deal with input data
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
var input = data as InitData;
|
||
ID = input.ID;
|
||
m_ReleaseCallback = input.callback;
|
||
DebugUtil.Log("Vehicle Part Tree Detail ID: " + ID);
|
||
}
|
||
|
||
// Use this for initialization
|
||
public override void OnInit()
|
||
{
|
||
//bind UI GameObj
|
||
UI_VehiclePartTreeDetailBinder.GetComponents(this);
|
||
|
||
BindButton(Button_Check, OnCheckButtonClick);
|
||
|
||
bool canUpgrade = false; // = Actor.Instance.Character.GetVehicleDevelopment(ID);
|
||
VehicleCultivateData vehicleData;
|
||
var node = VehicleCultivateManager.Instance.Get(ID);
|
||
if (node is VehicleTreeNode vehicle)
|
||
{
|
||
Text_Name.text = VehicleDataHelper.GetVehicleLocalizeName((int)ID);
|
||
vehicleData = VehicleCultivateDataManager.Instance.GetVehicleCultivateData(ID);
|
||
if(vehicleData == null)
|
||
{
|
||
vehicleData = new VehicleCultivateData((int)ID);
|
||
}
|
||
SetVehicleData(vehicleData);
|
||
|
||
canUpgrade = Actor.Instance.Character.GetVehicleDevelopment(ID) == null;
|
||
|
||
if (TableManager.Instance.Tables.VehicleConfig.Get((int)ID).UnlockType == UnlockType.Buy)
|
||
{
|
||
Button_Equipment.GetComponentInChildren<TMP_Text>().text = "直购";
|
||
}
|
||
}
|
||
else if (node is VehicleComponentTreeNode comp)
|
||
{
|
||
var compCfg = TableManager.Instance.Tables.VehicleComponent.Get(ID);
|
||
Text_Name.text = CommonUtils.GetLocalizeText("vehicleCultivate_Upgrade") + ":" + CommonUtils.GetLocalizeText("Vehicle_CompName_" + ID);
|
||
|
||
var vehicleID = compCfg.VehicleID;
|
||
vehicleData = VehicleCultivateDataManager.Instance.GetVehicleCultivateData(vehicleID);
|
||
if (vehicleData == null)
|
||
{
|
||
vehicleData = new VehicleCultivateData(vehicleID);
|
||
}
|
||
if (vehicleData.UpgradedComponents.Contains((uint)ID))//组件已经强化
|
||
{
|
||
SetVehicleData(vehicleData);
|
||
canUpgrade = false;
|
||
}
|
||
else//组件未强化,显示提升数值
|
||
{
|
||
SetVehicleData(vehicleData, compCfg);
|
||
canUpgrade = true;
|
||
}
|
||
|
||
//canUpgrade = Actor.Instance.Character.GetVehicleDevelopment(vehicleID);
|
||
}
|
||
|
||
if (!canUpgrade)
|
||
{
|
||
Button_Equipment.gameObject.SetActive(false);
|
||
}
|
||
BindButton(Button_Equipment, OnUpgradeClick);
|
||
|
||
Image_Bg.GetComponent<RectTransform>().pivot = new Vector2(0, 0.5f);
|
||
OnSwitchAnim(true);
|
||
var BgClose = FindObj("Bg_Close");
|
||
BindButton(BgClose, () =>
|
||
{
|
||
OnSwitchAnim(false, () =>
|
||
{
|
||
CloseWindow();
|
||
});
|
||
});
|
||
}
|
||
|
||
void OnCheckButtonClick()
|
||
{
|
||
//CloseWindow();
|
||
//UI_VehiclePartTreeController.Open(ID).Forget();
|
||
DebugUtil.Log("查看详细属性");
|
||
}
|
||
|
||
async void SetVehicleData(VehicleCultivateData data, DataVehicleComponent config = null)
|
||
{
|
||
#region 属性值
|
||
HideAllUpSign();
|
||
Color highLight = new Color(221 / 255.0f, 223 / 255.0f, 52 / 255.0f);
|
||
if (config == null)
|
||
{
|
||
Text_Value_Hp.text = data.Hp().ToString();
|
||
Text_Value_MemberCount.text = data.SeatCount().ToString();
|
||
Text_Value_Def.text = data.Defense().ToString();
|
||
Text_Value_Atk.text = data.Attack().ToString();
|
||
Text_Value_BulletCount.text = data.BulletCapacity().ToString();
|
||
Text_Value_Speed.text = data.MoveSpeed().ToString();
|
||
}
|
||
else
|
||
{
|
||
Text_Value_Hp.text = (data.Hp() + config.HP).ToString();
|
||
if (config.HP > 0)
|
||
{
|
||
Image_UpBg_Hp.gameObject.SetActive(true);
|
||
Image_UpSign_Hp.gameObject.SetActive(true);
|
||
Text_UpTitle_Hp.color = highLight;
|
||
}
|
||
|
||
Text_Value_MemberCount.text = data.SeatCount().ToString();
|
||
|
||
Text_Value_Def.text = (data.Defense() + config.Defense).ToString();
|
||
if (config.Defense > 0)
|
||
{
|
||
Image_UpBg_Def.gameObject.SetActive(true);
|
||
Image_UpSign_Def.gameObject.SetActive(true);
|
||
Text_UpTitle_Def.color = highLight;
|
||
}
|
||
|
||
if (config.ComponentType != ComponentType.Component_2)
|
||
{
|
||
Text_Value_Atk.text = (data.Attack()).ToString();
|
||
Text_Value_BulletCount.text = (data.BulletCapacity()).ToString();
|
||
}
|
||
else
|
||
{
|
||
var batteryCfg = TableManager.Instance.Tables.BatteryConfig.Get(config.BatteryID);
|
||
var atk = batteryCfg.DamagePower;
|
||
var bulletCount = batteryCfg.MaxBulletCount;
|
||
Text_Value_Atk.text = atk.ToString();
|
||
Text_Value_BulletCount.text = bulletCount.ToString();
|
||
|
||
bool isHighLight = atk > data.Attack();
|
||
Image_UpBg_Atk.gameObject.SetActive(isHighLight);
|
||
Image_UpSign_Atk.gameObject.SetActive(isHighLight);
|
||
Text_UpTitle_Atk.color = isHighLight ? highLight : Color.white;
|
||
|
||
isHighLight = bulletCount > data.BulletCapacity();
|
||
Image_UpBg_BulletCount.gameObject.SetActive(isHighLight);
|
||
Image_UpSign_BulletCount.gameObject.SetActive(isHighLight);
|
||
Text_UpTitle_BulletCount.color = isHighLight ? highLight : Color.white;
|
||
}
|
||
|
||
Text_Value_Speed.text = (data.MoveSpeed()).ToString();
|
||
}
|
||
#endregion
|
||
|
||
#region 适应性
|
||
Text_Value_Ground.text = data.GetTerrainAdapt(BonusType.TerrainPlain).ToString();
|
||
Text_Value_Mountain.text = data.GetTerrainAdapt(BonusType.TerrainMountain).ToString();
|
||
Text_Value_Snow.text = data.GetTerrainAdapt(BonusType.TerrainSnow).ToString();
|
||
Text_Value_Wood.text = data.GetTerrainAdapt(BonusType.TerrainForest).ToString();
|
||
#endregion
|
||
|
||
#region 技能
|
||
DataSkill nowSkillCfg = TableManager.Instance.Tables.SkillConfig.Get(VehicleDataHelper.GetVehicleSkillId(data));
|
||
if (nowSkillCfg == null)
|
||
{
|
||
nowSkillCfg = TableManager.Instance.Tables.SkillConfig.DataList[0];
|
||
DebugUtil.LogError("载具技能配置未能找到!载具ID为{0},技能ID为{1}\n>>请检查相关配置表:VehicleSkllUpgrade/SkillConfig_Vehicle", data.Cfg.ID, VehicleDataHelper.GetVehicleSkillId(data.Cfg.ID));
|
||
}
|
||
|
||
Text_SkillCoolingTimeValue.text = nowSkillCfg.ChargeParam.ToString() + "s";
|
||
Text_SkillName.text = CommonUtils.GetLocalizeText(E_LocalizePrefix.skill, nowSkillCfg.ID);
|
||
|
||
var skillIcon = await LoadAssetAsync<Sprite>(Framework.Constants.UI_Cultivata_skillIconFolder + nowSkillCfg.IconPath);
|
||
Image_SkillIcon.sprite = skillIcon;
|
||
|
||
Text_SkillInfo.text = CommonUtils.GetLocalizeText(E_LocalizePrefix.skill_desc, nowSkillCfg.ID);
|
||
#endregion
|
||
}
|
||
|
||
|
||
void HideAllUpSign()
|
||
{
|
||
Image_UpBg_Atk.gameObject.SetActive(false);
|
||
Image_UpBg_Def.gameObject.SetActive(false);
|
||
Image_UpBg_Hp.gameObject.SetActive(false);
|
||
Image_UpBg_MemberCount.gameObject.SetActive(false);
|
||
Image_UpBg_BulletCount.gameObject.SetActive(false);
|
||
Image_UpBg_Speed.gameObject.SetActive(false);
|
||
Image_UpSign_Atk.gameObject.SetActive(false);
|
||
Image_UpSign_Def.gameObject.SetActive(false);
|
||
Image_UpSign_Hp.gameObject.SetActive(false);
|
||
Image_UpSign_MemberCount.gameObject.SetActive(false);
|
||
Image_UpSign_BulletCount.gameObject.SetActive(false);
|
||
Image_UpSign_Speed.gameObject.SetActive(false);
|
||
|
||
Text_UpTitle_Hp.color = Color.white;
|
||
Text_UpTitle_MemberCount.color = Color.white;
|
||
Text_UpTitle_Def.color = Color.white;
|
||
Text_UpTitle_Atk.color = Color.white;
|
||
Text_UpTitle_BulletCount.color = Color.white;
|
||
}
|
||
|
||
void OnSwitchAnim(bool isShow, Action callback = null)
|
||
{
|
||
if (isShow)
|
||
{
|
||
//play show anim
|
||
Image_Bg.GetComponent<RectTransform>().DOPivotX(1f, 0.5f).SetEase(Ease.OutBack).OnComplete(() => callback?.Invoke());
|
||
}
|
||
else
|
||
{
|
||
Image_Bg.GetComponent<RectTransform>().DOPivotX(0f, 0.5f).OnComplete(() => callback?.Invoke());
|
||
}
|
||
}
|
||
|
||
//invoke when open window
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when reload window
|
||
protected override void OnReloadWindow(object data = null)
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when close window
|
||
protected override void OnHideWindow()
|
||
{
|
||
|
||
}
|
||
|
||
//invoke when destroy
|
||
public override void OnRelease()
|
||
{
|
||
m_ReleaseCallback?.Invoke();
|
||
base.OnRelease();
|
||
}
|
||
|
||
void OnUpgradeClick()
|
||
{
|
||
var node = VehicleCultivateManager.Instance.Get(ID);
|
||
if (node == null)
|
||
{
|
||
DebugUtil.Log("Vehicle Part Tree Detail ID: " + ID + " not found");
|
||
return;
|
||
}
|
||
TreeNodeBase parentNode = VehicleCultivateManager.Instance.Get(node.ParentID);
|
||
if(parentNode != null)
|
||
{
|
||
if (!parentNode.IsUpgraded())
|
||
{
|
||
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("vehicleCultivate_PreNodeLocked"));
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DebugUtil.Log("Vehicle Part Tree Detail ID: " + ID + " parent not found");
|
||
}
|
||
|
||
if (VehicleCultivateManager.Instance.Get(ID).Upgrade())
|
||
CloseWindow();
|
||
}
|
||
} |