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

292 lines
12 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00

using Cal.DataTable;
using ET;
using FairyGUI;
using System;
using System.Collections.Generic;
using Equip = ET.Equip;
namespace ET
{
public class ConsignmentUIAwakeSyatem : AwakeSystem<ConsignmentUI, List<ConsignMap>, int>
{
public override void Awake(ConsignmentUI self, List<ConsignMap> map, int totalPage)
{
self.Awake(map, totalPage);
}
}
public class ConsignmentUIDestroySyatem : DestroySystem<ConsignmentUI>
{
public override void Destroy(ConsignmentUI self)
{
self.Destroy();
}
}
public class ConsignmentUI : Entity
{
public FUI_ConsignmentUI ui;
public int totalPage;
public List<ConsignMap> consignMapList;
private Scene zoneScene;
2021-04-08 20:09:59 +08:00
public void Awake(List<ConsignMap> map, int totalPage)
{
zoneScene = this.ZoneScene();
2021-04-08 20:09:59 +08:00
ui = GetParent<FUI_ConsignmentUI>();
this.consignMapList = map;
this.totalPage = totalPage;
AwakeAsync().Coroutine();
}
private async ETVoid AwakeAsync()
{
//!+临时变量
int itemTypeIndex = 0, jobTypeIndex = 0;
int currPage = 0;
ShowListItem(ui, currPage, totalPage, consignMapList);
//!+出售按钮点击事件
ui.m_btnSell.self.onClick.Set(() =>
{
//!临时变量
int selectedIndexInBag = -1;
ClientItemData data = null;
//!打开输入窗口
if (!(FUIComponent.Instance.Get(FUIPackage.Consignment_ConsignmentPutInUI) is FUI_ConsignmentPutInUI inputUI))
{
inputUI = FUI_ConsignmentPutInUI.CreateInstance(this.ui);
inputUI.Name = FUIPackage.Consignment_ConsignmentPutInUI;
FUIComponent.Instance.Add(inputUI, true);
}
2021-04-11 19:50:39 +08:00
FUIWindowComponent inputUIwindow = inputUI.GetOrAddComponent<FUIWindowComponent>();
2021-04-08 20:09:59 +08:00
if (inputUIwindow.IsShowing) return;
inputUIwindow.Show();
//ui.m_Effect.Play();
inputUIwindow.Window.Center();
//!设置图标为空白
inputUI.m_btnSlot.self.icon = null;
//!物品放入事件
inputUI.m_btnSlot.self.onDrop.Set1(content =>
{
if (content.data is UIDragArgs args)
{
int index = args.index;
args.Release();
selectedIndexInBag = index;
if (ClientItemDataComponent.Instance.ItemDic.TryGetValueByKey1(index, out data))
{
inputUI.m_btnSlot.self.icon = UIPackage.GetItemURL(FUIPackage.Bag, BagHelper.GetIconName(data.ItemId).Item2);
}
}
});
//!确实出售按钮点击事件
inputUI.m_btnSure.self.onClick.Set(async () =>
{
if (data == null) return;
if (!int.TryParse(inputUI.m_inpCount.text, out int count))
return;
if (count <= 0) return;
if (data.ItemType == ItemType.EquipItem)
{
if (count != 1)
{
2021-04-11 19:50:39 +08:00
FUI_TipUI tipUI = TipHelper.OpenUI("只能寄售【1个】装备");
2021-04-08 20:09:59 +08:00
return;
}
}
if (!long.TryParse(inputUI.m_inpGold.text, out long gold))
return;
if (gold < 1000 || gold > long.MaxValue)
{
2021-04-11 19:50:39 +08:00
FUI_TipUI tipUI = TipHelper.OpenUI("出售价格最低【1000星币】");
2021-04-08 20:09:59 +08:00
return;
}
long price = gold;
M2C_PutInConsignment ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_PutInConsignment>(new C2M_PutInConsignment { Index = selectedIndexInBag, Count = count, Price = price, Pwd = inputUI.m_inpPwd.text });
2021-04-08 20:09:59 +08:00
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = ret.BagMapList
});
});
});
//!+购买按钮点击事件
ui.m_btnBuy.self.onClick.Set(() =>
{
2021-04-11 19:50:39 +08:00
if (!ClientItemDataComponent.Instance.ConsignmentDic.TryGetValue(ui.m_itemList.selectedIndex, out ConsignmentItemData data))
2021-04-08 20:09:59 +08:00
{
return;
}
FUI_TipUI tip = TipHelper.OpenUI("是否购买此商品:", true, TipType.DoubleInput);
tip.m_btnYes.self.onClick.Clear();
tip.m_btnYes.self.onClick.Add(() =>
2021-04-08 20:09:59 +08:00
{
string pwd = string.Empty;
if (data.isNeedPwd)
2021-04-08 20:09:59 +08:00
{
FUI_TipUI tipUI = TipHelper.OpenUI("请输入密码:", true, TipType.DoubleInput);
tipUI.m_btnYes.self.onClick.Clear();
tipUI.m_btnYes.self.onClick.Add(() =>
{
pwd = tipUI.m_IptTxt.text;
SendProto(data, pwd);
});
2021-04-08 20:09:59 +08:00
return;
}
SendProto(data,pwd);
async void SendProto(ConsignmentItemData _data, string _pwd)
2021-04-08 20:09:59 +08:00
{
M2C_BuyInConsignment ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_BuyInConsignment>(new C2M_BuyInConsignment
{
ConsignmentId = _data.Id,
Pwd = _pwd
});
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI
{
list = ret.BagMapList
});
}
});
2021-04-08 20:09:59 +08:00
});
//!+点击物品类型下拉框事件
ui.m_ComboItemType.self.onChanged.Set1(async concent =>
{
if (!int.TryParse(ui.m_ComboItemType.self.value, out int index)) return;
itemTypeIndex = index;
await SendGetConsigbmentProto();
});
//!+点击职业类型下拉框事件
ui.m_ComboJobType.self.onChanged.Set1(async concent =>
{
if (!int.TryParse(ui.m_ComboJobType.self.value, out int index)) return;
jobTypeIndex = index;
await SendGetConsigbmentProto();
});
//!+切换页数按钮事件
ui.m_btnLastPage.self.onClick.Set(async () =>
{
if (currPage-- <= 0)
{
currPage = 0;
return;
}
await SendGetConsigbmentProto();
});
ui.m_btnNextPage.self.onClick.Set(async () =>
{
if (currPage++ >= totalPage - 1)
{
currPage = totalPage - 1;
return;
}
await SendGetConsigbmentProto();
});
async ETTask SendGetConsigbmentProto()
{
M2C_GetConsignment ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetConsignment>(new C2M_GetConsignment
2021-04-08 20:09:59 +08:00
{
ItemType = (ItemType)(itemTypeIndex),
JobType = (JobType)(jobTypeIndex),
Page = currPage
});
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
ShowListItem(ui, currPage, ret.TotalPage, ret.ConsignMapList);
}
await ETTask.CompletedTask;
}
private void ShowListItem(FUI_ConsignmentUI ui, int currPage, int totalPage, List<ConsignMap> consignMapList)
{
//!页码
ui.m_txtPage.text = $"{currPage + 1}/{totalPage}";
ui.m_itemList.RemoveChildrenToPool();
//!显示列表
int consignMapIndex = 0;
2021-04-11 19:50:39 +08:00
foreach (ConsignMap consignMap in consignMapList)
2021-04-08 20:09:59 +08:00
{
int temp = consignMapIndex++;
//!添加数据
2021-04-11 19:50:39 +08:00
if (!ClientItemDataComponent.Instance.ConsignmentDic.TryGetValue(temp, out ConsignmentItemData data))
2021-04-08 20:09:59 +08:00
{
data = EntityFactory.CreateWithParent<ConsignmentItemData>(ClientItemDataComponent.Instance);
ClientItemDataComponent.Instance.ConsignmentDic.Add(temp, data);
}
NetItem item = consignMap.Item;
data.Id = consignMap.ConsignItemId;
data.ItemId = item.ItemId;
data.ItemType = item.ItemType;
data.Count = item.Count;
data.isNeedPwd = consignMap.NeedPwd;
if (data.ItemType == ItemType.EquipItem)
{
//!装备赋值
data.Equip = new Equip(consignMap.EquipTransMessage);
}
2021-04-11 19:50:39 +08:00
GButton btn = ui.m_itemList.AddItemFromPool().asButton;
2021-04-08 20:09:59 +08:00
FUI_ButtonConsignmentItem btnitem = FUI_ButtonConsignmentItem.GetFormPool(this.ui, btn);
//!显示页签
btn.onRollOver.Set(() =>
{
2021-04-11 19:50:39 +08:00
if (ClientItemDataComponent.Instance.ConsignmentDic.TryGetValue(temp, out ConsignmentItemData __data))
2021-04-08 20:09:59 +08:00
{
2021-05-14 15:28:23 +08:00
TabHelper.OpenUI(zoneScene,__data);
2021-04-08 20:09:59 +08:00
}
});
//!隐藏页签
btn.onRollOut.Set(TabHelper.HideUI);
string itemName = null, itemIcon = null;
2021-04-11 19:50:39 +08:00
IConfig itemBase = BagHelper.GetItemBase(consignMap.Item.ItemId);
2021-04-08 20:09:59 +08:00
switch (itemBase)
{
case EquipBase equipBase:
itemName = equipBase.Name;
itemIcon = equipBase.IconName;
btnitem.m_txtLevel.text = equipBase.UseLevel.ToString();
break;
case GoodsBase goodsBase:
itemName = goodsBase.Name;
itemIcon = goodsBase.IconName;
btnitem.m_txtLevel.text = "1";
break;
case MaterialBase materialBase:
itemName = materialBase.Name;
itemIcon = materialBase.IconName;
btnitem.m_txtLevel.text = "1";
break;
}
btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, itemIcon);
btnitem.m_txtName.text = itemName;
btnitem.m_txtTime.text = (DateTimeOffset.FromUnixTimeMilliseconds(consignMap.RemainTime).DateTime - DateTime.UtcNow).ToString("hh\\:mm");
btnitem.m_txtPrice.text = $"{consignMap.Price:###,###}星币";
btnitem.m_txtSeller.text = consignMap.Name;
btnitem.m_txtCount.text = consignMap.Item.Count == 1 ? null : consignMap.Item.Count.ToString();
}
}
public void Destroy()
{
}
}
}