zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/HotfixView/UI/StarSoulBagUI/StarSoulBagUI.cs

348 lines
11 KiB
C#
Raw Normal View History

2021-05-01 22:06:12 +08:00
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
{
2021-05-05 13:36:19 +08:00
private enum SortType: byte
{
2021-05-07 23:50:22 +08:00
Time = 0,
SuitType = 1,
PosType = 2,
2021-05-05 13:36:19 +08:00
}
2021-05-01 22:06:12 +08:00
public FUI_StarSoulBagUI ui;
private Scene zoneScene;
private StarSoulBag bag;
2021-05-05 13:36:19 +08:00
2021-05-01 22:06:12 +08:00
private bool isInit;
2021-05-07 23:50:22 +08:00
private SortType sortType = SortType.Time;
2021-05-05 13:36:19 +08:00
private Quality sortQuality = Quality.Common;
2021-05-14 15:28:23 +08:00
private EquipType equipType = EquipType.;
2021-05-05 13:36:19 +08:00
private List<long> list = new List<long>();
private LinkedList<StarSoulItem> tempList = new LinkedList<StarSoulItem>();
2021-05-15 14:29:48 +08:00
private List<long> selection = new List<long>();
2021-05-05 13:36:19 +08:00
public static event Action<long> clickEvent;
2021-05-01 22:06:12 +08:00
public void Awake()
{
zoneScene = this.ZoneScene();
ui = GetParent<FUI_StarSoulBagUI>();
if (!this.isInit)
{
2021-05-02 23:18:14 +08:00
isInit = true;
2021-05-01 22:06:12 +08:00
this.ui.m_slotList.SetVirtual();
// this.rollOverAction = this.OnRollOver;
this.ui.m_slotList.itemRenderer = OnItemRender;
2021-05-05 13:36:19 +08:00
RegistEvent();
2021-05-15 14:29:48 +08:00
ReFreshSelection();
2021-05-01 22:06:12 +08:00
}
2021-05-05 13:36:19 +08:00
2021-05-01 22:06:12 +08:00
AwakeAsync().Coroutine();
}
private async ETVoid AwakeAsync()
{
2021-05-14 15:28:23 +08:00
bag ??= this.zoneScene.GetComponent<UnitComponent>().MyUnit.GetComponent<StarSoulBag>();
2021-05-15 14:29:48 +08:00
clickEvent += OnClickStarSoul;
2021-05-01 22:06:12 +08:00
ShowSlots();
await ETTask.CompletedTask;
}
private void ShowSlots()
{
2021-05-05 13:36:19 +08:00
this.SortByQulity();
this.ui.m_slotList.numItems = this.list.Count;
2021-05-01 22:06:12 +08:00
this.ui.m_slotList.RefreshVirtualList();
2021-05-05 13:36:19 +08:00
this.ui.m_txtCapity.text = $"容量:{bag.ItemCount}/1000";
2021-05-01 22:06:12 +08:00
}
private void OnItemRender(int index, GObject item)
{
2021-05-05 13:36:19 +08:00
FUI_ButtonStarSoulSlot btn = FUI_ButtonStarSoulSlot.GetFormPool(this.zoneScene, item);
long id = list[index];
2021-05-02 23:18:14 +08:00
var data = this.bag.Get(id);
2021-05-05 13:36:19 +08:00
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);
});
2021-05-14 15:28:23 +08:00
#else
2021-05-13 20:14:23 +08:00
btn.self.onRollOver.Set(() =>EquipStarSoul(data, id));
2021-05-05 13:36:19 +08:00
#endif
2021-05-14 15:28:23 +08:00
btn.self.onRightClick.Set(() => EquipStarSoul(data, id));
2021-05-05 13:36:19 +08:00
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 });
});
}
2021-05-13 20:14:23 +08:00
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;
}
});
}
2021-05-05 13:36:19 +08:00
private static void ItemDataView(FUI_ButtonStarSoulSlot btn, StarSoulItem data)
{
2021-05-02 23:18:14 +08:00
StarSoulTypeConfig soulTypeConfig = StarSoulTypeConfigCategory.Instance.Get(data.typeId);
2021-05-05 13:36:19 +08:00
btn.self.icon = UIPackage.GetItemURL(FUIPackage.Bag, soulTypeConfig.Icon);
btn.m_txtLevel.text = data.level + string.Empty;
2021-05-02 23:18:14 +08:00
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;
2021-05-05 13:36:19 +08:00
Color color = ColorHelper.GetColorByStr(TabHelper.GetQualityColor(data.quality));
2021-05-02 23:18:14 +08:00
btn.m_img.color = color;
2021-05-05 13:36:19 +08:00
btn.m_btnLock.self.selected = data.isLocked;
}
private void RegistEvent()
{
this.ui.m_sortType.onChanged.Set(SortTypeChanged);
this.ui.m_quality.onChanged.Set(QualityTypeChanged);
2021-05-14 15:28:23 +08:00
ui.m_comBoxPos.self.onChanged.Set(ChangeEquipPos);
2021-05-15 14:29:48 +08:00
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} 个星魂";
2021-05-14 15:28:23 +08:00
}
private void ChangeEquipPos()
{
this.equipType = (EquipType) this.ui.m_comBoxPos.self.selectedIndex;
ReFresh();
2021-05-05 13:36:19 +08:00
}
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)
2021-05-03 01:54:31 +08:00
{
2021-05-05 13:36:19 +08:00
var item = kv.Value;
if (item.quality == this.sortQuality)
this.list.Add(item.Id);
}
2021-05-14 15:28:23 +08:00
2021-05-07 23:50:22 +08:00
if (this.sortType == SortType.Time)
{
return;
}
2021-05-05 13:36:19 +08:00
tempList.Clear();
foreach (long l in this.list)
2021-05-02 23:18:14 +08:00
{
2021-05-05 13:36:19 +08:00
var item = this.bag.Get(l);
if (item == null)
{
Log.Error($"item == null where id = {l}");
continue;
}
2021-05-03 01:54:31 +08:00
2021-05-14 15:28:23 +08:00
if (this.sortType == SortType.PosType)
{
//排除
if (item.posType != this.equipType)
continue;
}
2021-05-05 13:36:19 +08:00
var curr = this.tempList.First;
if (curr == null)
2021-05-02 23:18:14 +08:00
{
2021-05-05 13:36:19 +08:00
this.tempList.AddLast(item);
continue;
}
bool isAdd = false;
while (curr != null)
{
var compareItem = curr.Value;
if (compareItem == null)
continue;
if (this.sortType == SortType.SuitType)
2021-05-02 23:18:14 +08:00
{
2021-05-05 13:36:19 +08:00
if (compareItem.typeId > item.typeId)
{
tempList.AddBefore(curr, item);
isAdd = true;
break;
}
2021-05-03 01:54:31 +08:00
}
2021-05-05 13:36:19 +08:00
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();
2021-05-01 22:06:12 +08:00
}
2021-05-05 13:36:19 +08:00
2021-05-02 01:19:35 +08:00
public void ReFresh()
{
AwakeAsync().Coroutine();
}
2021-05-01 22:06:12 +08:00
2021-05-05 13:36:19 +08:00
public void SelectAll0LevelItem(List<long> selectedId)
2021-05-01 22:06:12 +08:00
{
2021-05-05 13:36:19 +08:00
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++;
}
2021-05-01 22:06:12 +08:00
}
2021-05-02 01:19:35 +08:00
2021-05-05 13:36:19 +08:00
public void Destroy()
{
list.Clear();
2021-05-15 14:29:48 +08:00
this.selection.Clear();
clickEvent -= OnClickStarSoul;
2021-05-05 13:36:19 +08:00
}
2021-05-01 22:06:12 +08:00
}
}