270 lines
6.8 KiB
C#
270 lines
6.8 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 cfg.VihecleCultivateCfg;
|
||
using System;
|
||
using NPOI.SS.Formula.Functions;
|
||
using static CriWare.CriAtomExBeatSync;
|
||
using Gameplay;
|
||
using Gameplay.Net;
|
||
|
||
public class UI_VehicleSkinController : UIWindow
|
||
{
|
||
//UI GameObj
|
||
///Auto Gen Start///
|
||
//public Button Button_Back;
|
||
public Button Button_back;
|
||
public TMP_Text Text_Back;
|
||
public Button Button_Home;
|
||
public Image Image_DarkLeft;
|
||
public Image Image_DarkLeftTop;
|
||
public Image Image_DarkTop;
|
||
public Image Image_DarkBottom;
|
||
public Image Image_OrganizatioFlag;
|
||
public Image Image_AngularShape0;
|
||
public TMP_Text Text_VehicleType;
|
||
public Image Image_AngularShape1;
|
||
public TMP_Text Text_Level;
|
||
public Image Image_AngularShape2;
|
||
public TMP_Text Text_Organization;
|
||
public TMP_Text Text_VehicleName;
|
||
public Button Button_Part0;
|
||
//public Image Image_LightBar0;
|
||
public Button Button_Part1;
|
||
//public Image Image_LightBar1;
|
||
public Button Button_Part2;
|
||
//public Image Image_LightBar2;
|
||
public Image Image_LineLeft;
|
||
public Image Image_LineBottom;
|
||
public TMP_Text Text_Title;
|
||
public TMP_Text Text_PartName;
|
||
public TMP_Text Text_Count;
|
||
public ScrollRect ScrollRect_VehicleSkin;
|
||
public Image Image_Bg;
|
||
public Image Image_SelectedBorder;
|
||
public Image Image_Icon;
|
||
public TMP_Text Text_Name;
|
||
public Image Image_DrakHide;
|
||
public Image Image_Locked;
|
||
public Image Image_CurrentEquipment;
|
||
public Button Button_Equipment;
|
||
|
||
///Auto Gen End///
|
||
|
||
private RecycleView SkinScrollView;
|
||
|
||
private long VehicleID = -1;
|
||
private PaintType CurType = PaintType.None;
|
||
private List<TypeToggle> toggles = new();
|
||
|
||
private Dictionary<PaintType,int> curSelectSkinIDs = new();
|
||
//private List<DataVehiclePaint> VehiclePaints = new List<DataVehiclePaint>();
|
||
private Dictionary<PaintType, List<DataVehiclePaint>> VehiclePaintDic = new();
|
||
private Dictionary<int, SkinItem> recycleItem = new();
|
||
|
||
public async static UniTask<UIWindow> Open(object data = null)
|
||
{
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_VehicleSkin, data);
|
||
}
|
||
|
||
|
||
// deal with input data
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
VehicleID = (long)data;
|
||
DebugUtil.Log("VehicleID : " + VehicleID);
|
||
}
|
||
|
||
// Use this for initialization
|
||
public override void OnInit()
|
||
{
|
||
//bind UI GameObj
|
||
UI_VehicleSkinBinder.GetComponents(this);
|
||
SkinScrollView = ScrollRect_VehicleSkin.GetComponent<RecycleView>();
|
||
SkinScrollView.Init(OnRefreshItem);
|
||
BindButton(Button_back, OnBack_Click);
|
||
|
||
CurType = PaintType.Entirety;
|
||
toggles = new List<TypeToggle>() {
|
||
new TypeToggle(Button_Part0.gameObject, PaintType.Entirety, OnTypeToggleClick),
|
||
new TypeToggle(Button_Part1.gameObject, PaintType.Fort, OnTypeToggleClick),
|
||
new TypeToggle(Button_Part2.gameObject, PaintType.CaterpillarBelt, OnTypeToggleClick)
|
||
};
|
||
foreach (var toggle in toggles)
|
||
{
|
||
toggle.ResetLightBar(CurType);
|
||
}
|
||
|
||
VehiclePaint cfg = TableManager.Instance.Tables.VehiclePaint;
|
||
foreach (var item in cfg.DataList)
|
||
{
|
||
if (item.HostVehicle == VehicleID)
|
||
{
|
||
var paintType = item.PaintType;
|
||
if (!VehiclePaintDic.ContainsKey(paintType))
|
||
{
|
||
VehiclePaintDic.Add(paintType, new List<DataVehiclePaint>());
|
||
}
|
||
|
||
VehiclePaintDic[paintType].Add(item);
|
||
}
|
||
}
|
||
|
||
var Vehiclecfg = Actor.Instance.Character.GetVehicleDevelopment(VehicleID);//.paint_set;
|
||
if (Vehiclecfg != null)
|
||
{
|
||
var paintSet = Vehiclecfg.paint_set;
|
||
for (int i = 1; i < (int)PaintType.Max; i++)
|
||
{
|
||
var type = (PaintType)i;
|
||
|
||
if (i - 1 < paintSet.Length)
|
||
{
|
||
int paintID = (int)paintSet[i - 1];
|
||
curSelectSkinIDs.Add(type, paintID);
|
||
}
|
||
else
|
||
{
|
||
curSelectSkinIDs.Add(type, 0);
|
||
DebugUtil.LogError(" paint_set <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㹻<EFBFBD>IJ<EFBFBD>λͿװ ");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DebugUtil.LogError("VehicleID = " + VehicleID + " δ<>ҵ<EFBFBD>Ϳװ<CDBF><D7B0><EFBFBD><EFBFBD>");
|
||
}
|
||
}
|
||
|
||
//invoke when open window
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
SkinScrollView.ShowList(VehiclePaintDic[CurType].Count);
|
||
}
|
||
|
||
//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 OnBack_Click()
|
||
{
|
||
CloseWindow();
|
||
}
|
||
|
||
#region RecycleView
|
||
private void OnRefreshItem(GameObject cell, int index)
|
||
{
|
||
if (!recycleItem.TryGetValue(cell.GetInstanceID(), out SkinItem item))
|
||
{
|
||
item = new SkinItem(cell, OnSelectSkin);
|
||
recycleItem.Add(cell.GetInstanceID(), item);
|
||
}
|
||
item.SetInfo(VehiclePaintDic[CurType][index]);
|
||
item.RefreshSelected(curSelectSkinIDs[CurType]);
|
||
}
|
||
|
||
public class SkinItem : UIGameObjectWrapper
|
||
{
|
||
int SkinID;
|
||
Action<int> callback;
|
||
|
||
public SkinItem(GameObject root, Action<int> OnClickCallback) : base(root)
|
||
{
|
||
callback = OnClickCallback;
|
||
}
|
||
|
||
public void SetInfo(DataVehiclePaint data)
|
||
{
|
||
SkinID = data.PaintID;
|
||
GetComponent<TMP_Text>("Text_Name").text = data.PaintName;
|
||
var button = GoRoot.GetComponent<Button>();
|
||
|
||
CommonUtils.BindButton(button, OnClick);
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
private void OnClick()
|
||
{
|
||
callback?.Invoke(SkinID);
|
||
}
|
||
|
||
public void RefreshSelected(int SkinID)
|
||
{
|
||
var selected = FindObj("Image_SelectedBorder");
|
||
selected.SetActive(SkinID == this.SkinID);
|
||
}
|
||
}
|
||
|
||
void OnSelectSkin(int SkinID)
|
||
{
|
||
DebugUtil.Log("OnSelectSkin SkinID = " + SkinID);
|
||
curSelectSkinIDs[CurType] = SkinID;
|
||
|
||
SkinScrollView.ShowList(VehiclePaintDic[CurType].Count);
|
||
}
|
||
#endregion
|
||
|
||
void OnTypeToggleClick(PaintType type)
|
||
{
|
||
CurType = type;
|
||
foreach(var toggle in toggles)
|
||
{
|
||
toggle.ResetLightBar(CurType);
|
||
}
|
||
SkinScrollView.ShowList(VehiclePaintDic[CurType].Count);
|
||
}
|
||
|
||
public class TypeToggle : UIGameObjectWrapper
|
||
{
|
||
Action<PaintType> callback;
|
||
GameObject lightBar;
|
||
PaintType toggleType;
|
||
|
||
public TypeToggle(GameObject root, PaintType toggleType, Action<PaintType> OnToggleCallback) : base(root)
|
||
{
|
||
lightBar = FindObj("LightBar");
|
||
callback = OnToggleCallback;
|
||
this.toggleType = toggleType;
|
||
|
||
var button = GetComponent<Button>();
|
||
CommonUtils.BindButton(button, OnButtonClick);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
void OnButtonClick()
|
||
{
|
||
callback?.Invoke(toggleType);
|
||
}
|
||
public void ResetLightBar(PaintType curPaintType)
|
||
{
|
||
lightBar.SetActive(curPaintType == toggleType);
|
||
}
|
||
}
|
||
}
|