NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_VehiclePartTreeControlle...

333 lines
9.3 KiB
C#
Raw Normal View History

2024-12-30 16:13:58 +08:00
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay;
using Gameplay.Common;
using Gameplay.Net;
using PhxhSDK;
2024-12-09 17:02:39 +08:00
using TMPro;
using UnityEngine;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
using Toggle = UnityEngine.UI.Toggle;
public class UI_VehiclePartTreeController : UIWindow
{
//UI GameObj
///Auto Gen Start///
public Image Image_Bg;
public Image Image_TreeBg1;
2024-12-12 19:11:59 +08:00
//public Button Button_Return;
2024-12-09 17:02:39 +08:00
public Button Button_back;
public TMP_Text Text_Back;
public Button Button_Home;
public Image Image_TreeBg0;
public Toggle Toggle_Dev;
public Toggle Toggle_Reinforce;
public Toggle Toggle_BlueMap;
public Toggle Toggle_Repair;
public PhxhScrollView ScrollView_PartsTree;
public Button Button_Back;
2024-12-12 19:11:59 +08:00
2024-12-09 17:02:39 +08:00
///Auto Gen End///
2024-12-12 19:11:59 +08:00
private long curVehicleID = -1;
private GameObject uiPrefab;
2024-12-30 16:13:58 +08:00
private GameObject highLightNode;
2024-12-12 19:11:59 +08:00
public async static UniTask<UIWindow> Open(object data = null)
{
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_VehiclePartTree, data);
}
2024-12-09 17:02:39 +08:00
// deal with input data
public override void PreLoad(object data = null)
2024-12-12 19:11:59 +08:00
{
curVehicleID = (long)data;
var path = string.Format(UIManager.UI_PREFAB_PATH, "Interface_Vehicle/TechTree/TechTree_" + curVehicleID);
PostPreload<GameObject>(path).Forget();
}
2024-12-30 16:13:58 +08:00
// Use this for initialization
public override void OnInit()
2024-12-09 17:02:39 +08:00
{
//bind UI GameObj
UI_VehiclePartTreeBinder.GetComponents(this);
2024-12-30 16:13:58 +08:00
var currencyList = GetComponent<UI_CurrencyList>("UI_CurrencyList");
currencyList.SetData(GLConfig.Inst.data.GoldItemId);//GLConfig.Inst.data.DiamondItemId,
2024-12-12 19:11:59 +08:00
2024-12-30 16:13:58 +08:00
BindButton(Button_back, OnClickBack);
2025-01-15 17:25:50 +08:00
BindButton(Button_Home, OnClickHome);
2024-12-30 16:13:58 +08:00
BindButton(Button_Back, () =>
{
var parentID = VehicleCultivateManager.Instance.GetVehicleParent(curVehicleID).ID;
curVehicleID = parentID;
UpdateTreePrefab();
});
2024-12-12 19:11:59 +08:00
2024-12-30 16:13:58 +08:00
var path = string.Format(UIManager.UI_PREFAB_PATH, "Interface_Vehicle/TechTree/TechTree_" + curVehicleID);
2025-01-15 15:25:23 +08:00
try
{
uiPrefab = GameObject.Instantiate(GetPreLoadResult<GameObject>(path), ScrollView_PartsTree.content, false);
}
catch
{
DebugUtil.LogError("科技树预制体加载失败:" + curVehicleID + ",请检查是否已生成");
}
2024-12-16 12:04:37 +08:00
2024-12-30 16:13:58 +08:00
EventManager.Instance.Register(EventManager.EventName.VehecleUpgrade, UpdateTreeNode);
2025-02-06 11:51:36 +08:00
highLightNode = CommonUtils.GetGameObject(uiPrefab, "v_" + curVehicleID);
if (highLightNode != null)
{
var img = CommonUtils.GetComponent<Image>(highLightNode, "Image_CurrentVehicle/Image_SelectBorder");
if (img != null)
{
highLightNode = img.gameObject;
img.enabled = true;
}
}
UI_VehiclePartTreeDetailController.Open(curVehicleID, OnReleaseCallback: HideHighlight).Forget();
}
2024-12-09 17:02:39 +08:00
2024-12-30 16:13:58 +08:00
//invoke when open window
protected override void OnShowWindow(object data = null)
2024-12-09 17:02:39 +08:00
{
2024-12-12 19:11:59 +08:00
UpdateTreeNode();
2024-12-30 16:13:58 +08:00
var currencyList = GetComponent<UI_CurrencyList>("UI_CurrencyList");
currencyList.Refresh();
}
2024-12-09 17:02:39 +08:00
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
2024-12-30 16:13:58 +08:00
2024-12-09 17:02:39 +08:00
}
2024-12-30 16:13:58 +08:00
2024-12-09 17:02:39 +08:00
//invoke when close window
protected override void OnHideWindow()
{
2024-12-30 16:13:58 +08:00
2024-12-09 17:02:39 +08:00
}
2024-12-30 16:13:58 +08:00
2024-12-09 17:02:39 +08:00
//invoke when destroy
public override void OnRelease()
{
2024-12-30 16:13:58 +08:00
base.OnRelease();
CommonUtils.ScreenshotReset();
2024-12-16 12:04:37 +08:00
2024-12-30 16:13:58 +08:00
EventManager.Instance.Unregister(EventManager.EventName.VehecleUpgrade, UpdateTreeNode);
}
2024-12-12 19:11:59 +08:00
/// <summary>
2024-12-19 13:09:17 +08:00
/// 加载树形结构预制体
/// </summary>
2024-12-30 16:13:58 +08:00
async void UpdateTreePrefab()
2024-12-12 19:11:59 +08:00
{
var path = string.Format(UIManager.UI_PREFAB_PATH, "Interface_Vehicle/TechTree/TechTree_" + curVehicleID);
var go = await AssetManager.Instance.LoadAssetAsync<GameObject>(path);
if (go == null)
{
DebugUtil.LogError("go is null");
return;
}
if (uiPrefab != null)
{
Destroy(uiPrefab);
}
uiPrefab = GameObject.Instantiate(go, ScrollView_PartsTree.content, false);
UpdateTreeNode();
highLightNode = CommonUtils.GetGameObject(uiPrefab, "v_" + curVehicleID);
if (highLightNode != null)
{
var img = CommonUtils.GetComponent<Image>(highLightNode, "Image_CurrentVehicle/Image_SelectBorder");
if (img != null)
{
highLightNode = img.gameObject;
img.enabled = true;
}
}
UI_VehiclePartTreeDetailController.Open(curVehicleID, OnReleaseCallback: HideHighlight).Forget();
}
/// <summary>
/// 更新树形结构节点显示内容
/// </summary>
void UpdateTreeNode()
2024-12-12 19:11:59 +08:00
{
var partTree = VehicleCultivateManager.Instance.GetPartialTree(curVehicleID);
if (VehicleCultivateManager.Instance.GetVehicleParent(curVehicleID) == null)
{
Button_Back.gameObject.SetActive(false);
}
else
{
Button_Back.gameObject.SetActive(true);
}
if (partTree == null)
{
DebugUtil.LogError("partTree is null");
return;
}
2024-12-16 12:04:37 +08:00
GameObject rootVehicleNode = CommonUtils.GetGameObject(uiPrefab, "v_" + curVehicleID);
CommonUtils.GetComponent<TMP_Text>(rootVehicleNode, "Image_CurrentVehicle/Text_PartName").text
= VehicleDataHelper.GetVehicleLocalizeName((int)curVehicleID);
2025-01-08 16:01:19 +08:00
CommonUtils.GetComponent<TMP_Text>(rootVehicleNode, "Image_CurrentVehicle/Text_VehicleTypeName").text
= VehicleDataHelper.GetVehicleCategory((int)curVehicleID);
2024-12-30 16:13:58 +08:00
VehicleInfo data = Actor.Instance.Character.GetVehicleDevelopment(curVehicleID);
foreach (var node in partTree)
2024-12-12 19:11:59 +08:00
{
var id = node.ID;
2024-12-16 12:04:37 +08:00
var treeNode = CommonUtils.GetGameObject(uiPrefab, "v_" + id);
2024-12-12 19:11:59 +08:00
if (treeNode == null)
{
DebugUtil.LogError("treeNode is null");
continue;
}
var button = treeNode.GetComponent<Button>();
if (button == null)
{
DebugUtil.LogError("button is null");
}
BindButton(button, () => OnNodeClick(node));
2024-12-12 19:11:59 +08:00
2024-12-16 12:04:37 +08:00
bool unlock = false;
if (node is VehicleTreeNode vehicleNode)
{
2024-12-30 16:13:58 +08:00
unlock = Actor.Instance.Character.GetVehicleDevelopment(vehicleNode.ID) != null;
2024-12-16 12:04:37 +08:00
2024-12-30 16:13:58 +08:00
#region vehicle_level
var Text_level = CommonUtils.GetComponent<TMP_Text>(treeNode.transform.GetChild(0).gameObject, "Text_Level");
2024-12-16 12:04:37 +08:00
if (Text_level != null)
2024-12-30 16:13:58 +08:00
{
var vehicleLevel = 1;
if (TableManager.Instance.Tables.VehicleConfig.DataMap.ContainsKey((int)vehicleNode.ID))
vehicleLevel = TableManager.Instance.Tables.VehicleConfig.DataMap[(int)vehicleNode.ID].VehicleLevel;
Text_level.text = CommonUtils.GetRomanCode(vehicleLevel);
}
#endregion
}
else if (node is VehicleComponentTreeNode componentNode)
2024-12-16 12:04:37 +08:00
{
if (data != null)
unlock = data.UpgradedComponents.Contains((uint)componentNode.ID);
2024-12-30 16:13:58 +08:00
#region component_level
2024-12-16 12:04:37 +08:00
var Text_level = CommonUtils.GetComponent<TMP_Text>(treeNode.transform.GetChild(0).gameObject, "Text_Level");
if (Text_level != null)
{
int compLevel = (int)(componentNode.ID % 100);
Text_level.text = CommonUtils.GetRomanCode(compLevel);
}
2024-12-30 16:13:58 +08:00
#endregion
}
2024-12-16 12:04:37 +08:00
2024-12-12 19:11:59 +08:00
2024-12-30 16:13:58 +08:00
var tag = treeNode.transform.GetChild(0).Find("Image_Unlock");
2024-12-18 19:58:14 +08:00
var cost = treeNode.transform.GetChild(0).Find("Text_Cost");
2024-12-30 16:13:58 +08:00
var vehicleCostText = treeNode.transform.GetChild(0).Find("Text_CostValue");
2024-12-18 19:58:14 +08:00
2024-12-30 16:13:58 +08:00
if (tag == null)
2024-12-12 19:11:59 +08:00
{
DebugUtil.LogWarning("tag is null");
}
2024-12-16 12:04:37 +08:00
if (!unlock)
2024-12-12 19:11:59 +08:00
{
if (tag != null)
tag.gameObject.SetActive(false);
2024-12-17 13:26:31 +08:00
if (cost != null)
{
cost.gameObject.SetActive(true);
var itemCost = node.GetUpgradeCost();
cost.GetComponent<TMP_Text>().text = itemCost.Counts[0].ToString();
}
2024-12-18 19:58:14 +08:00
if (vehicleCostText != null)
2024-12-30 16:13:58 +08:00
{
vehicleCostText.gameObject.SetActive(true);
var itemCost = node.GetUpgradeCost();
vehicleCostText.GetComponent<TMP_Text>().text = itemCost.Counts[0].ToString();
}
2024-12-12 19:11:59 +08:00
}
else
{
if (tag != null)
tag.gameObject.SetActive(true);
2024-12-17 13:26:31 +08:00
if (cost != null)
cost.gameObject.SetActive(false);
2024-12-18 19:58:14 +08:00
if (vehicleCostText != null)
2024-12-30 16:13:58 +08:00
vehicleCostText.gameObject.SetActive(false);
2024-12-12 19:11:59 +08:00
}
}
}
/// <summary>
2024-12-19 13:09:17 +08:00
/// 树节点点击事件
/// </summary>
/// <param name="node"></param>
void OnNodeClick(TreeNodeBase node)
{
var id = node.ID;
2024-12-30 16:13:58 +08:00
DebugUtil.Log("click node: " + id);
2025-02-06 11:51:36 +08:00
HideHighlight();
2024-12-17 13:26:31 +08:00
if (node is VehicleTreeNode Vehicle)
{
if (curVehicleID != Vehicle.ID)
{
curVehicleID = Vehicle.ID;
UpdateTreePrefab();
}
else
2025-02-06 11:51:36 +08:00
{
highLightNode = CommonUtils.GetGameObject(uiPrefab, "v_" + id);
if (highLightNode != null)
{
var img = CommonUtils.GetComponent<Image>(highLightNode, "Image_CurrentVehicle/Image_SelectBorder");
if (img != null)
{
highLightNode = img.gameObject;
img.enabled = true;
}
}
UI_VehiclePartTreeDetailController.Open(id, OnReleaseCallback: HideHighlight).Forget();
}
2024-12-17 13:26:31 +08:00
}
else
{
highLightNode = CommonUtils.GetGameObject(uiPrefab, "v_" + id);
2024-12-30 16:13:58 +08:00
if (highLightNode != null)
{
2025-02-06 11:51:36 +08:00
var img = CommonUtils.GetComponent<Image>(highLightNode, "Image_Part/Image_SelectBorder");
if(img != null)
{
highLightNode = img.gameObject;
img.enabled = true;
}
2024-12-30 16:13:58 +08:00
}
UI_VehiclePartTreeDetailController.Open(id, OnReleaseCallback: HideHighlight).Forget();
}
2024-12-30 16:13:58 +08:00
}
2024-12-12 19:11:59 +08:00
void OnClickBack()
2024-12-30 16:13:58 +08:00
{
2024-12-12 19:11:59 +08:00
CloseWindow();
2024-12-30 16:13:58 +08:00
}
2025-01-15 17:25:50 +08:00
void OnClickHome()
{
CommonUtils.ChangeUIScene(Framework.Constants.MAIN_SCENE_PATH);
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
}
2024-12-30 16:13:58 +08:00
void HideHighlight()
{
if (highLightNode != null)
2025-02-06 11:51:36 +08:00
CommonUtils.GetComponent<Image>(highLightNode).enabled = false;
2024-12-30 16:13:58 +08:00
}
2024-12-12 19:11:59 +08:00
}