2024-12-09 17:02:39 +08:00
|
|
|
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 PhxhSDK;
|
|
|
|
|
using Framework;
|
2024-12-11 11:16:11 +08:00
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using Gameplay.Common;
|
|
|
|
|
using cfg.VihecleCultivateCfg;
|
2024-12-12 19:11:59 +08:00
|
|
|
using Gameplay.Net;
|
|
|
|
|
using Gameplay;
|
2024-12-09 17:02:39 +08:00
|
|
|
|
|
|
|
|
public class UI_VehicleTechTreeController : UIWindow
|
|
|
|
|
{
|
|
|
|
|
//UI GameObj
|
|
|
|
|
///Auto Gen Start///
|
|
|
|
|
public Image Image_Bg;
|
|
|
|
|
public Image Image_LeftPanelBg;
|
|
|
|
|
public Button Button_Back;
|
|
|
|
|
public TMP_Text Text_Back;
|
|
|
|
|
public Toggle Toggle_0;
|
|
|
|
|
public Toggle Toggle_1;
|
|
|
|
|
public Toggle Toggle_2;
|
|
|
|
|
public Toggle Toggle_3;
|
|
|
|
|
public Toggle Toggle_4;
|
|
|
|
|
public Toggle Toggle_5;
|
|
|
|
|
public Image Image_TitleIcon;
|
|
|
|
|
public TMP_Text Text_Title;
|
|
|
|
|
public TMP_Text Text_TitleEn0;
|
|
|
|
|
public TMP_Text Text_TitleEn1;
|
|
|
|
|
public PhxhScrollView ScrollView_TechTree;
|
2024-12-11 11:16:11 +08:00
|
|
|
|
2024-12-12 19:11:59 +08:00
|
|
|
///Auto Gen End///
|
2024-12-11 11:16:11 +08:00
|
|
|
|
2024-12-12 19:11:59 +08:00
|
|
|
VehicleType curType = VehicleType.None;
|
2024-12-11 11:16:11 +08:00
|
|
|
VehicleType CurType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return curType;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
curType = value;
|
|
|
|
|
Text_Title.text = "TechTree_" + curType.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<Toggle> Toggles;
|
|
|
|
|
Dictionary<VehicleType, GameObject> TreePrefabs;//= new();
|
2024-12-09 17:02:39 +08:00
|
|
|
|
2024-12-11 11:16:11 +08:00
|
|
|
|
|
|
|
|
public async static UniTask<UIWindow> Open(object data = null)
|
|
|
|
|
{
|
|
|
|
|
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_VehicleTechTree, data);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 17:02:39 +08:00
|
|
|
// deal with input data
|
|
|
|
|
public override void PreLoad(object data = null)
|
2024-12-11 11:16:11 +08:00
|
|
|
{
|
|
|
|
|
TreePrefabs = new Dictionary<VehicleType, GameObject>();
|
|
|
|
|
var VehicleTypeCount = (int)VehicleType.Max - 1;
|
|
|
|
|
for (int i = 0; i < VehicleTypeCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var type = (VehicleType)(i + 1);
|
|
|
|
|
var path = string.Format(UIManager.UI_PREFAB_PATH, "Interface_Vehicle/TechTree/" + type.ToString() + "_0");
|
|
|
|
|
PostPreload<GameObject>(path).Forget();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-09 17:02:39 +08:00
|
|
|
// Use this for initialization
|
|
|
|
|
public override void OnInit()
|
|
|
|
|
{
|
|
|
|
|
//bind UI GameObj
|
|
|
|
|
UI_VehicleTechTreeBinder.GetComponents(this);
|
2024-12-11 11:16:11 +08:00
|
|
|
ButtonBind();
|
|
|
|
|
|
|
|
|
|
var currencyList = GetComponent<UI_CurrencyList>("UI_CurrencyList");
|
|
|
|
|
currencyList.SetData(GLConfig.Inst.data.DiamondItemId, GLConfig.Inst.data.GoldItemId);
|
|
|
|
|
|
|
|
|
|
Toggles = new List<Toggle> { Toggle_0, Toggle_1, Toggle_2, Toggle_3, Toggle_4, Toggle_5 };
|
|
|
|
|
var VehicleTypeCount = (int)VehicleType.Max - 1;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < VehicleTypeCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var toggle = Toggles[i];
|
|
|
|
|
var type = (VehicleType)(i + 1);
|
|
|
|
|
toggle.onValueChanged.AddListener((isOn) => OnToggleValueChanged(toggle, type, isOn));
|
|
|
|
|
SetTreePrefab(type);
|
|
|
|
|
}
|
|
|
|
|
for (int i = VehicleTypeCount; i < Toggles.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Toggles[i].gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
Toggles[0].isOn = true;
|
2024-12-09 17:02:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//invoke when open window
|
|
|
|
|
protected override void OnShowWindow(object data = null)
|
|
|
|
|
{
|
2024-12-11 11:16:11 +08:00
|
|
|
var currencyList = GetComponent<UI_CurrencyList>("UI_CurrencyList");
|
|
|
|
|
currencyList.Refresh();
|
2024-12-09 17:02:39 +08:00
|
|
|
}
|
2024-12-11 11:16:11 +08:00
|
|
|
|
2024-12-09 17:02:39 +08:00
|
|
|
//invoke when reload window
|
|
|
|
|
protected override void OnReloadWindow(object data = null)
|
|
|
|
|
{
|
2024-12-11 11:16:11 +08:00
|
|
|
|
2024-12-09 17:02:39 +08:00
|
|
|
}
|
2024-12-11 11:16:11 +08:00
|
|
|
|
2024-12-09 17:02:39 +08:00
|
|
|
//invoke when close window
|
|
|
|
|
protected override void OnHideWindow()
|
|
|
|
|
{
|
2024-12-11 11:16:11 +08:00
|
|
|
|
2024-12-09 17:02:39 +08:00
|
|
|
}
|
2024-12-11 11:16:11 +08:00
|
|
|
|
2024-12-09 17:02:39 +08:00
|
|
|
//invoke when destroy
|
|
|
|
|
public override void OnRelease()
|
|
|
|
|
{
|
2024-12-11 11:16:11 +08:00
|
|
|
base.OnRelease();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetTreePrefab(VehicleType type)
|
|
|
|
|
{
|
|
|
|
|
GameObject uiPrefab = null;
|
|
|
|
|
var path = string.Format(UIManager.UI_PREFAB_PATH, "Interface_Vehicle/TechTree/" + type.ToString() + "_0");
|
|
|
|
|
var res = GetPreLoadResult<GameObject>(path);
|
|
|
|
|
if (res != null)
|
|
|
|
|
uiPrefab = GameObject.Instantiate(GetPreLoadResult<GameObject>(path), ScrollView_TechTree.content, false);
|
|
|
|
|
TreePrefabs.Add(type, uiPrefab);
|
2024-12-12 19:11:59 +08:00
|
|
|
BindTreeButton(uiPrefab, type);
|
2024-12-11 11:16:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnToggleValueChanged(Toggle changeToggle, VehicleType type, bool isOn)
|
|
|
|
|
{
|
|
|
|
|
if (isOn)
|
|
|
|
|
{
|
|
|
|
|
foreach (var toggle in Toggles)
|
|
|
|
|
{
|
|
|
|
|
if (toggle != changeToggle)
|
|
|
|
|
{
|
|
|
|
|
toggle.isOn = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CurType = type;
|
|
|
|
|
|
|
|
|
|
if (TreePrefabs.TryGetValue(type, out GameObject go) && go != null)
|
2024-12-12 19:11:59 +08:00
|
|
|
{
|
2024-12-11 11:16:11 +08:00
|
|
|
go.SetActive(true);
|
2024-12-12 19:11:59 +08:00
|
|
|
RefreshTreeContent(go, type);
|
|
|
|
|
}
|
2024-12-11 11:16:11 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var isOnCnt = 0;
|
|
|
|
|
foreach (var toggle in Toggles)
|
|
|
|
|
{
|
|
|
|
|
if (toggle.isOn)
|
|
|
|
|
{
|
|
|
|
|
isOnCnt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isOnCnt == 0)
|
|
|
|
|
{
|
|
|
|
|
changeToggle.isOn = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TreePrefabs.TryGetValue(type, out GameObject go) && go != null)
|
|
|
|
|
go.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 19:11:59 +08:00
|
|
|
void BindTreeButton(GameObject Tree, VehicleType type)
|
|
|
|
|
{
|
|
|
|
|
if (Tree == null)
|
|
|
|
|
return;
|
2024-12-11 11:16:11 +08:00
|
|
|
|
|
|
|
|
var root = VehicleCultivateManager.Instance.GetVehicleForest(type);
|
|
|
|
|
Queue<VehicleTreeNode> queue = new Queue<VehicleTreeNode>();
|
2024-12-12 19:11:59 +08:00
|
|
|
foreach (var child in root.VehicleChildren)
|
2024-12-11 11:16:11 +08:00
|
|
|
{
|
|
|
|
|
var node = VehicleCultivateManager.Instance.Get(child) as VehicleTreeNode;
|
|
|
|
|
queue.Enqueue(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (queue.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var node = queue.Dequeue();
|
2024-12-12 19:11:59 +08:00
|
|
|
Transform childGO = Tree.transform.Find("v_" + node.ID);
|
|
|
|
|
if (childGO == null)
|
2024-12-11 11:16:11 +08:00
|
|
|
{
|
|
|
|
|
Debug.LogError("Can't find node " + node.ID);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-12-12 19:11:59 +08:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var data = Actor.Instance.Character.GetVehicleDevelopment(node.ID);
|
|
|
|
|
Button btn = CommonUtils.GetComponent<Button>(childGO.gameObject);
|
|
|
|
|
|
|
|
|
|
if (btn != null)
|
|
|
|
|
{
|
|
|
|
|
BindButton(btn, () => VehicleNodeClick(node));
|
|
|
|
|
}
|
|
|
|
|
var children = VehicleCultivateManager.Instance.GetVehicleChildren(node.ID);
|
|
|
|
|
foreach (var child in children)
|
|
|
|
|
{
|
|
|
|
|
queue.Enqueue(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-11 11:16:11 +08:00
|
|
|
}
|
2024-12-12 19:11:59 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VehicleNodeClick(VehicleTreeNode node)
|
|
|
|
|
{
|
|
|
|
|
if (node == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("VehicleNodeClick node is null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = Actor.Instance.Character.GetVehicleDevelopment(node.ID);
|
|
|
|
|
if (data != null)
|
|
|
|
|
{
|
|
|
|
|
DebugUtil.Log("VehicleNodeClick " + node.ID + " is unlocked");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DebugUtil.Log("VehicleNodeClick " + node.ID + " is locked");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RefreshTreeContent(GameObject Tree, VehicleType type)
|
|
|
|
|
{
|
|
|
|
|
if (Tree == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var root = VehicleCultivateManager.Instance.GetVehicleForest(type);
|
|
|
|
|
Queue<VehicleTreeNode> queue = new Queue<VehicleTreeNode>();
|
|
|
|
|
foreach (var child in root.VehicleChildren)
|
|
|
|
|
{
|
|
|
|
|
var node = VehicleCultivateManager.Instance.Get(child) as VehicleTreeNode;
|
|
|
|
|
queue.Enqueue(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (queue.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var node = queue.Dequeue();
|
|
|
|
|
Transform childGO = Tree.transform.Find("v_" + node.ID);
|
|
|
|
|
if (childGO == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Can't find node " + node.ID);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var data = Actor.Instance.Character.GetVehicleDevelopment(node.ID);
|
|
|
|
|
var tag = childGO.transform.Find("Image_Unlock");
|
|
|
|
|
|
|
|
|
|
if (data != null)
|
|
|
|
|
{
|
|
|
|
|
if (tag != null)
|
|
|
|
|
tag.gameObject.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (tag != null)
|
|
|
|
|
tag.gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
var children = VehicleCultivateManager.Instance.GetVehicleChildren(node.ID);
|
|
|
|
|
foreach (var child in children)
|
|
|
|
|
{
|
|
|
|
|
queue.Enqueue(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-11 11:16:11 +08:00
|
|
|
|
|
|
|
|
void ButtonBind()
|
|
|
|
|
{
|
|
|
|
|
BindButton(Button_Back, OnClickBack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Button Click
|
|
|
|
|
void OnClickBack()
|
|
|
|
|
{
|
|
|
|
|
CloseWindow();
|
2024-12-09 17:02:39 +08:00
|
|
|
}
|
2024-12-11 11:16:11 +08:00
|
|
|
#endregion
|
2024-12-09 17:02:39 +08:00
|
|
|
}
|