368 lines
9.4 KiB
C#
368 lines
9.4 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 PhxhSDK;
|
||
using Framework;
|
||
using Cysharp.Threading.Tasks;
|
||
using Gameplay.Common;
|
||
using cfg.VihecleCultivateCfg;
|
||
using Gameplay.Net;
|
||
using Gameplay;
|
||
|
||
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;
|
||
|
||
///Auto Gen End///
|
||
|
||
VehicleType curType = VehicleType.None;
|
||
VehicleType CurType
|
||
{
|
||
get
|
||
{
|
||
return curType;
|
||
}
|
||
set
|
||
{
|
||
curType = value;
|
||
Text_Title.text = VehicleDataHelper.GetVehicleOrganization(curType);//CommonUtils.GetLocalizeText("VehicleOrg_" + curType);
|
||
}
|
||
}
|
||
List<Toggle> Toggles;
|
||
Dictionary<VehicleType, GameObject> TreePrefabs;//= new();
|
||
|
||
|
||
public async static UniTask<UIWindow> Open(object data = null)
|
||
{
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_VehicleTechTree, data);
|
||
}
|
||
|
||
// deal with input data
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
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();
|
||
}
|
||
}
|
||
|
||
// Use this for initialization
|
||
public override void OnInit()
|
||
{
|
||
//bind UI GameObj
|
||
UI_VehicleTechTreeBinder.GetComponents(this);
|
||
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;
|
||
|
||
EventManager.Instance.Register(EventManager.EventName.CharacterInfoRefresh, OnCharacterDataRefresh);
|
||
|
||
|
||
}
|
||
|
||
//invoke when open window
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
var currencyList = GetComponent<UI_CurrencyList>("UI_CurrencyList");
|
||
currencyList.Refresh();
|
||
}
|
||
|
||
//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();
|
||
//EventManager.Instance.Send(EventManager.EventName.EN_UIControllCultivateMainInput, true);
|
||
CommonUtils.ScreenshotReset();
|
||
}
|
||
|
||
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);
|
||
uiPrefab.SetActive(false);
|
||
}
|
||
TreePrefabs.Add(type, uiPrefab);
|
||
BindTreeButton(uiPrefab, type);
|
||
}
|
||
|
||
void OnCharacterDataRefresh()
|
||
{
|
||
if (TreePrefabs.TryGetValue(curType, out GameObject go) && go != null)
|
||
{
|
||
go.SetActive(true);
|
||
RefreshTreeContent(go, curType);
|
||
}
|
||
}
|
||
|
||
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)
|
||
{
|
||
go.SetActive(true);
|
||
ScrollView_TechTree.content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, go.GetComponent<RectTransform>().sizeDelta.y);
|
||
ScrollView_TechTree.content.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, go.GetComponent<RectTransform>().sizeDelta.x);
|
||
|
||
RefreshTreeContent(go, type);
|
||
}
|
||
}
|
||
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);
|
||
}
|
||
}
|
||
|
||
void BindTreeButton(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);
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
void VehicleNodeClick(VehicleTreeNode node)
|
||
{
|
||
if (node == null)
|
||
{
|
||
Debug.LogError("VehicleNodeClick node is null");
|
||
return;
|
||
}
|
||
|
||
var cfg = TableManager.Instance.Tables.VehicleConfig.GetOrDefault((int)node.ID);
|
||
if(cfg == null)
|
||
{
|
||
Debug.LogError("VehicleNode cfg is null");
|
||
return;
|
||
}
|
||
var data = Actor.Instance.Character.GetVehicleDevelopment(node.ID);
|
||
if (data != null)
|
||
{
|
||
DebugUtil.Log("VehicleNodeClick " + node.ID + " is unlocked");
|
||
}
|
||
else
|
||
{
|
||
var UnlockMethod = cfg.UnlockType;
|
||
DebugUtil.Log("VehicleNode " + node.ID + " is locked, unlock method is " + UnlockMethod);
|
||
}
|
||
UI_VehiclePartTreeController.Open(node.ID).Forget();
|
||
}
|
||
|
||
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();
|
||
var childGO = CommonUtils.GetGameObject(Tree, "v_" + node.ID);
|
||
if (childGO == null)
|
||
{
|
||
Debug.LogError("Can't find node " + node.ID);
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
//<2F>༭<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>ʾ
|
||
|
||
#region <20><><EFBFBD><EFBFBD>״̬
|
||
var data = Actor.Instance.Character.GetVehicleDevelopment(node.ID);
|
||
var tag = CommonUtils.GetGameObject(childGO, "Image_Unlock");
|
||
|
||
var costTag = CommonUtils.GetGameObject(childGO, "Image_PriceBg");
|
||
var costText = CommonUtils.GetComponent<TMP_Text>(childGO, "Text_Price");
|
||
|
||
var cfg = TableManager.Instance.Tables.VehicleConfig.GetOrDefault((int)node.ID);
|
||
if (cfg != null)
|
||
{
|
||
costText.text = cfg.UnlockCost[0].Count.ToString();
|
||
}
|
||
|
||
if (data != null)
|
||
{
|
||
if (tag != null)
|
||
tag.SetActive(true);
|
||
if (costTag != null)
|
||
costTag.SetActive(false);
|
||
if(costText != null)
|
||
costText.gameObject.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
if (tag != null)
|
||
tag.SetActive(false);
|
||
if (costTag != null)
|
||
costTag.SetActive(true);
|
||
if(costText != null)
|
||
costText.gameObject.SetActive(true);
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region <20>ȼ<EFBFBD>
|
||
var Text_level = CommonUtils.GetComponent<TMP_Text>(childGO.gameObject, "Text_Level");
|
||
if (Text_level != null)
|
||
{
|
||
var vehicleLevel = 1;
|
||
if (TableManager.Instance.Tables.VehicleConfig.DataMap.ContainsKey((int)node.ID))
|
||
vehicleLevel = TableManager.Instance.Tables.VehicleConfig.DataMap[(int)node.ID].VehicleLevel;
|
||
Text_level.text = CommonUtils.GetRomanCode(vehicleLevel);
|
||
}
|
||
#endregion
|
||
|
||
#region <20><><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD><EFBFBD><EFBFBD>
|
||
var Text_Name = CommonUtils.GetComponent<TMP_Text>(childGO.gameObject, "Text_Name");
|
||
if (Text_Name != null)
|
||
{
|
||
Text_Name.text=VehicleDataHelper.GetVehicleLocalizeName((int)node.ID);
|
||
}
|
||
#endregion
|
||
|
||
var children = VehicleCultivateManager.Instance.GetVehicleChildren(node.ID);
|
||
foreach (var child in children)
|
||
{
|
||
queue.Enqueue(child);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void ButtonBind()
|
||
{
|
||
BindButton(Button_Back, OnClickBack);
|
||
}
|
||
|
||
#region Button Click
|
||
void OnClickBack()
|
||
{
|
||
CloseWindow();
|
||
}
|
||
#endregion
|
||
}
|