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

272 lines
7.7 KiB
C#
Raw Normal View History

2024-12-09 17:02:39 +08:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
using Toggle = UnityEngine.UI.Toggle;
using PhxhSDK;
using Framework;
2024-12-12 19:11:59 +08:00
using Cysharp.Threading.Tasks;
using Gameplay.Net;
using Gameplay.Common;
2024-12-13 14:56:43 +08:00
using Gameplay;
2024-12-09 17:02:39 +08:00
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;
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();
}
// 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-12 19:11:59 +08:00
var currencyList = GetComponent<UI_CurrencyList>("UI_CurrencyList");
2024-12-16 12:04:37 +08:00
currencyList.SetData(GLConfig.Inst.data.GoldItemId);//GLConfig.Inst.data.DiamondItemId,
2024-12-12 19:11:59 +08:00
BindButton(Button_back, OnClickBack);
BindButton(Button_Back, () =>
{
var parentID = VehicleCultivateManager.Instance.GetVehicleParent(curVehicleID).ID;
curVehicleID = parentID;
UpdateTreePrefab();
});
var path = string.Format(UIManager.UI_PREFAB_PATH, "Interface_Vehicle/TechTree/TechTree_" + curVehicleID);
uiPrefab = GameObject.Instantiate(GetPreLoadResult<GameObject>(path), ScrollView_PartsTree.content, false);
2024-12-16 12:04:37 +08:00
EventManager.Instance.Register(EventManager.EventName.VehecleUpgrade, UpdateTreeNode);
2024-12-12 19:11:59 +08:00
}
2024-12-09 17:02:39 +08:00
2024-12-16 12:04:37 +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();
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)
{
}
//invoke when close window
protected override void OnHideWindow()
{
}
//invoke when destroy
public override void OnRelease()
{
base.OnRelease();
2024-12-13 14:56:43 +08:00
EventManager.Instance.Send(EventManager.EventName.EN_UIControllCultivateMainInput, true);
CommonUtils.ScreenshotReset();
2024-12-16 12:04:37 +08:00
EventManager.Instance.Unregister(EventManager.EventName.VehecleUpgrade, UpdateTreeNode);
2024-12-13 14:56:43 +08:00
}
2024-12-12 19:11:59 +08:00
/// <summary>
2024-12-19 13:09:17 +08:00
/// 加载树形结构预制体
/// </summary>
2024-12-13 14:56:43 +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();
}
/// <summary>
2024-12-19 13:09:17 +08:00
/// 更新树形结构节点显示内容
/// </summary>
2024-12-12 19:11:59 +08:00
void UpdateTreeNode()
{
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);
VehicleDevelopmentInfo 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-17 13:26:31 +08:00
DebugUtil.Log("node id: " + 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)
{
unlock = Actor.Instance.Character.GetVehicleDevelopment(vehicleNode.ID) != null;
#region vehicle_level
var Text_level = CommonUtils.GetComponent<TMP_Text>(treeNode.transform.GetChild(0).gameObject, "Text_Level");
if (Text_level != null)
{
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)
{
if (data != null)
unlock = data.UpgradedComponents.Contains((uint)componentNode.ID);
#region component_level
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);
}
#endregion
}
2024-12-12 19:11:59 +08:00
2024-12-16 12:04:37 +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");
var vehicleCostText = treeNode.transform.GetChild(0).Find("Text_CostValue");
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)
{
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)
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;
DebugUtil.Log("click node: " + id);
2024-12-17 13:26:31 +08:00
if (node is VehicleTreeNode Vehicle)
{
if (curVehicleID != Vehicle.ID)
{
curVehicleID = Vehicle.ID;
UpdateTreePrefab();
}
else
UI_VehiclePartTreeDetailController.Open(id).Forget();
}
else
{
UI_VehiclePartTreeDetailController.Open(id).Forget();
}
}
2024-12-12 19:11:59 +08:00
void OnClickBack()
{
CloseWindow();
}
//void OnClickHome()
//{
// UIManager.Instance.CloseAllWindow();
// UIManager.Instance.OpenWindow(UINameConst.UI_VehicleMain);
//}
}