348 lines
11 KiB
C#
348 lines
11 KiB
C#
using Cal.DataTable;
|
|
using FairyGUI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
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 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);
|
|
}
|
|
|
|
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)
|
|
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;
|
|
}
|
|
}
|
|
} |