CTT/Unity/Assets/HotfixView/UI/StarSoulBagUI/StarSoulBagUI.cs

458 lines
15 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Cal.DataTable;
using FairyGUI;
using System;
using System.Collections.Generic;
using UnityEngine;
using AttributeType = Cal.AttributeType;
namespace ET
{
public class StarSoulBagUIAwakeSyatem: AwakeSystem<StarSoulBagUI>
{
public override void Awake(StarSoulBagUI self)
{
self.Awake();
}
}
public class StarSoulBagUIDestroySyatem: DestroySystem<StarSoulBagUI>
{
public override void Destroy(StarSoulBagUI self)
{
self.Destroy();
}
}
public class StarSoulBagUI: Entity
{
private enum SortType: byte
{
Time = 0,
SuitType = 1,
PosType = 2,
}
public FUI_StarSoulBagUI ui;
private Scene zoneScene;
private StarSoulBag bag;
private bool isInit;
private SortType sortType = SortType.Time;
private Quality sortQuality = Quality.Common;
private EquipType equipType = EquipType.;
private AttributeType mainAttribute = AttributeType.;
private AttributeType viceAttribute = AttributeType.;
//兑换
private int selectStarSoulitemType = 0;
private EquipType selectGetStarSoulPosType = 0;
private List<long> list = new List<long>();
private LinkedList<StarSoulItem> tempList = new LinkedList<StarSoulItem>();
private List<long> selection = new List<long>();
public static event Action<long> clickEvent;
public void Awake()
{
zoneScene = this.ZoneScene();
ui = GetParent<FUI_StarSoulBagUI>();
if (!this.isInit)
{
isInit = true;
this.ui.m_slotList.SetVirtual();
// this.rollOverAction = this.OnRollOver;
this.ui.m_slotList.itemRenderer = OnItemRender;
RegistEvent();
ReFreshSelection();
}
AwakeAsync().Coroutine();
}
private async ETVoid AwakeAsync()
{
bag ??= this.zoneScene.GetComponent<UnitComponent>().MyUnit.GetComponent<StarSoulBag>();
clickEvent += OnClickStarSoul;
ShowSlots();
await ETTask.CompletedTask;
}
private void ShowSlots()
{
this.SortByQulity();
this.ui.m_slotList.numItems = this.list.Count;
this.ui.m_slotList.RefreshVirtualList();
this.ui.m_txtCapity.text = $"容量:{bag.ItemCount}/1000";
}
private void OnItemRender(int index, GObject item)
{
FUI_ButtonStarSoulSlot btn = FUI_ButtonStarSoulSlot.GetFormPool(this.zoneScene, item);
long id = list[index];
var data = this.bag.Get(id);
ItemDataView(btn, data);
TabHelper.SetTab(btn.self, () =>
{
#if !UNITY_STANDALONE
long id = list[index];
clickEvent?.Invoke(id);
#endif
TabHelper.OpenStarSoulUI(this.bag, id);
}, true);
#if UNITY_STANDALONE
btn.self.onClick.Set1(context =>
{
long id = list[index];
clickEvent?.Invoke(id);
});
#else
btn.self.onRollOver.Set(() =>EquipStarSoul(data, id));
#endif
btn.self.onRightClick.Set(() => EquipStarSoul(data, id));
btn.m_btnLock.self.onClick.Set1(context =>
{
context.StopPropagation();
this.zoneScene.GetComponent<SessionComponent>().Session
.Send(new C2M_LockStarSoulItem() { itemId = id, isLock = btn.m_btnLock.self.selected });
});
}
private void EquipStarSoul(StarSoulItem data, long id)
{
string tip = null;
tip = data.isUsed? "是否卸载此星魂?" : "是否放置此星魂到装备上?";
var tipUi = TipHelper.OpenUI(tip, tipType: TipType.Double);
tipUi.m_btnYes.self.onClick.Set(async () =>
{
var ret = await this.zoneScene.GetComponent<SessionComponent>()
.Call<M2C_PutonStarSoulItem>(new C2M_PutonStarSoulItem { itemId = id });
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
});
}
private static void ItemDataView(FUI_ButtonStarSoulSlot btn, StarSoulItem data)
{
StarSoulTypeConfig soulTypeConfig = StarSoulTypeConfigCategory.Instance.Get(data.typeId);
btn.self.icon = UIPackage.GetItemURL(FUIPackage.Bag, soulTypeConfig.Icon);
btn.m_txtLevel.text = data.level + string.Empty;
btn.m_txtUsed.text = data.isUsed? "用" : null;
btn.self.title = soulTypeConfig.Name;
int viceCount = 0;
foreach (int i in data.viceAttribute)
{
if (i != 0)
viceCount++;
}
string str = null;
for (int i = 0; i < 4; i++)
{
if (i < viceCount)
{
str += TabHelper.YellowStar;
}
else
{
str += TabHelper.SliverStar;
}
}
btn.m_txtStar.text = str;
Color color = ColorHelper.GetColorByStr(TabHelper.GetQualityColor(data.quality));
btn.m_img.color = color;
btn.m_btnLock.self.selected = data.isLocked;
}
private void RegistEvent()
{
this.ui.m_sortType.onChanged.Set(SortTypeChanged);
this.ui.m_quality.onChanged.Set(QualityTypeChanged);
ui.m_comBoxPos.self.onChanged.Set(ChangeEquipPos);
this.ui.m_btnReslove.self.onClick.Set(Resolve);
var arr = Enum.GetNames(typeof (AttributeType));
this.ui.m_comBoxMainAttibute.self.items = arr;
this.ui.m_comBoxViceAttribute.self.items = arr;
this.ui.m_comBoxMainAttibute.self.onChanged.Set(MainAttibuteChange);
this.ui.m_comBoxViceAttribute.self.onChanged.Set(ViceAttributeChange);
var starSoulTypeArr = StarSoulTypeConfigCategory.Instance.arr;
this.ui.m_comBoxGetStarSoul.self.items = new string[starSoulTypeArr.Length];
for (var i = 0; i < starSoulTypeArr.Length; i++)
{
this.ui.m_comBoxGetStarSoul.self.items[i] = starSoulTypeArr[i]?.Name;
}
this.ui.m_comBoxGetStarSoul.self.onChanged.Set(GetStarSoulChange);
arr = Enum.GetNames(typeof (EquipType));
this.ui.m_comBoxGetStarSoulPosType.self.items = arr;
this.ui.m_comBoxGetStarSoulPosType.self.onChanged.Set(GetStarSoulPosTypeChange);
this.ui.m_btnGetStarSoul.self.onClick.Set(GetStarSoulItem);
}
private void GetStarSoulItem()
{
StarSoulTypeConfig config = StarSoulTypeConfigCategory.Instance.GetByIndex(this.selectStarSoulitemType);
if (config == null) return;
SessionComponentHelper.TipCall(this.zoneScene, "是否花费个30星魂碎片兑换1个选定类型的随机天工星魂",
new C2M_GetStarSoulItem() { configId = (int) config.Id * 100 + (int) this.selectGetStarSoulPosType },
(M2C_GetStarSoulItem ret) => { TipHelper.OpenUI("兑换成功"); });
}
private void GetStarSoulPosTypeChange()
{
selectGetStarSoulPosType = (EquipType) this.ui.m_comBoxGetStarSoulPosType.self.selectedIndex;
}
private void GetStarSoulChange()
{
selectStarSoulitemType = this.ui.m_comBoxGetStarSoul.self.selectedIndex;
}
private void MainAttibuteChange()
{
this.mainAttribute = EnumHelper.GetByIndex<AttributeType>(this.ui.m_comBoxMainAttibute.self.selectedIndex);
ReFresh();
}
private void ViceAttributeChange()
{
this.viceAttribute = EnumHelper.GetByIndex<AttributeType>(this.ui.m_comBoxViceAttribute.self.selectedIndex);
ReFresh();
}
private void OnClickStarSoul(long obj)
{
var item = this.bag.Get(obj);
if (item.isLocked || item.isUsed)
return;
if (this.selection.Contains(obj))
this.selection.Remove(obj);
else
this.selection.Add(obj);
this.ReFreshSelection();
}
private void Resolve()
{
FUI_TipUI tip = TipHelper.OpenUI($"是否分解已经选择的 {selection.Count} 个星魂?", tipType: TipType.Double);
tip.m_btnYes.self.onClick.Set(async () =>
{
var proto = new C2M_ResolveStarSoul();
proto.ids.AddRange(this.selection);
selection.Clear();
this.ReFreshSelection();
M2C_ResolveStarSoul ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_ResolveStarSoul>(proto);
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
string str = null;
foreach (RewardItem rewardItem in ret.itenList)
{
str += $"{BagHelper.GetIconName(rewardItem.Id).Item1} X {rewardItem.Count}\n";
}
TipHelper.OpenUI(str);
});
}
private void ReFreshSelection()
{
if (this.selection.Count == 0)
{
this.ui.m_txtSelection.text = null;
return;
}
this.ui.m_txtSelection.text = $"已经选择 {this.selection.Count} 个星魂";
}
private void ChangeEquipPos()
{
this.equipType = (EquipType) this.ui.m_comBoxPos.self.selectedIndex;
ReFresh();
}
private void SortTypeChanged()
{
sortType = (SortType) this.ui.m_sortType.selectedIndex;
ReFresh();
}
private void QualityTypeChanged()
{
this.sortQuality = (Quality) (this.ui.m_quality.selectedIndex + 1);
ReFresh();
}
private void SortByQulity()
{
this.list.Clear();
foreach (var kv in this.bag.itemDic)
{
var item = kv.Value;
if (item.quality != this.sortQuality)
{
continue;
}
//有属性筛选
if (this.ui.m_btnAttributeSelect.self.selected)
{
if (this.mainAttribute == AttributeType.)
{
if (this.viceAttribute == AttributeType.)
this.list.Add(item.Id);
else if (CheckViceAttribute())
this.list.Add(item.Id);
}
else
{
if (this.viceAttribute == AttributeType.)
{
if (CheckMainAttribute())
this.list.Add(item.Id);
}
else if (CheckMainAttribute() && CheckViceAttribute())
this.list.Add(item.Id);
}
bool CheckMainAttribute()
{
if (item.mainAttribute == 0) return false;
StarSoulAttributeConfig starSoulAttributeConfig = StarSoulAttributeConfigCategory.Instance.Get(item.mainAttribute);
return starSoulAttributeConfig.Key == (int) this.mainAttribute;
}
bool CheckViceAttribute()
{
bool hasItem = false;
foreach (int id in item.viceAttribute)
{
if (id == 0) continue;
StarSoulAttributeConfig starSoulAttributeConfig = StarSoulAttributeConfigCategory.Instance.Get(id);
if (starSoulAttributeConfig.Key == (int) this.viceAttribute)
{
hasItem = true;
break;
}
}
return hasItem;
}
}
else
{
this.list.Add(item.Id);
}
}
if (this.sortType == SortType.Time)
{
return;
}
tempList.Clear();
foreach (long l in this.list)
{
var item = this.bag.Get(l);
if (item == null)
{
Log.Error($"item == null where id = {l}");
continue;
}
if (this.sortType == SortType.PosType)
{
//排除
if (item.posType != this.equipType)
continue;
}
var curr = this.tempList.First;
if (curr == null)
{
this.tempList.AddLast(item);
continue;
}
bool isAdd = false;
while (curr != null)
{
var compareItem = curr.Value;
if (compareItem == null)
continue;
if (this.sortType == SortType.SuitType)
{
if (compareItem.typeId > item.typeId)
{
tempList.AddBefore(curr, item);
isAdd = true;
break;
}
}
else if (this.sortType == SortType.PosType)
{
if (compareItem.posType > item.posType)
{
tempList.AddBefore(curr, item);
isAdd = true;
break;
}
}
curr = curr.Next;
}
if (!isAdd)
{
tempList.AddLast(item);
}
}
this.list.Clear();
foreach (var starsoulIttem in tempList)
{
this.list.Add(starsoulIttem.Id);
}
tempList.Clear();
}
public void ReFresh()
{
AwakeAsync().Coroutine();
}
public void SelectAll0LevelItem(List<long> selectedId)
{
int count = 0;
foreach (long l in this.list)
{
var item = this.bag.Get(l);
if (item.isLocked || item.isUsed)
continue;
if (count >= 20) return;
selectedId.Add(l);
count++;
}
}
public void Destroy()
{
list.Clear();
this.selection.Clear();
clickEvent -= OnClickStarSoul;
}
}
}