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

310 lines
12 KiB
C#
Raw Normal View History

2021-05-29 15:07:44 +08:00
using Cal.DataTable;
2021-04-08 20:09:59 +08:00
using ET;
using FairyGUI;
using System;
using System.Collections.Generic;
using Equip = ET.Equip;
namespace ET
{
2021-05-29 15:07:44 +08:00
public class ConsignmentUIAwakeSyatem: AwakeSystem<ConsignmentUI, List<ConsignMap>, int>
2021-04-08 20:09:59 +08:00
{
public override void Awake(ConsignmentUI self, List<ConsignMap> map, int totalPage)
{
self.Awake(map, totalPage);
}
}
2021-05-29 15:07:44 +08:00
public class ConsignmentUIDestroySyatem: DestroySystem<ConsignmentUI>
2021-04-08 20:09:59 +08:00
{
public override void Destroy(ConsignmentUI self)
{
self.Destroy();
}
}
2021-05-29 15:07:44 +08:00
public class ConsignmentUI: Entity
2021-04-08 20:09:59 +08:00
{
public FUI_ConsignmentUI ui;
private Scene zoneScene;
2021-05-29 15:07:44 +08:00
private List<ConsignMap> consignMapList = new List<ConsignMap>(10);
private int currPage;
public int totalPage;
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>();
2021-05-29 15:07:44 +08:00
consignMapList.Clear();
consignMapList.AddRange(map);
2021-04-08 20:09:59 +08:00
this.totalPage = totalPage;
AwakeAsync().Coroutine();
}
2021-05-29 15:07:44 +08:00
2021-04-08 20:09:59 +08:00
private async ETVoid AwakeAsync()
{
//!+临时变量
2021-05-29 15:07:44 +08:00
int itemTypeIndex = 0, jobTypeIndex = 0;
currPage = 0;
2021-04-08 20:09:59 +08:00
2021-05-29 15:07:44 +08:00
ShowListItem();
2021-04-08 20:09:59 +08:00
//!+出售按钮点击事件
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-05-29 15:07:44 +08:00
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;
}
2021-05-29 15:07:44 +08:00
2021-04-08 20:09:59 +08:00
long price = gold;
2021-05-29 15:07:44 +08:00
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;
}
2021-05-29 15:07:44 +08:00
Game.EventSystem.Publish_Sync(new ET.EventType.UpdateBagUI { list = ret.BagMapList });
2021-04-08 20:09:59 +08:00
});
});
//!+购买按钮点击事件
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;
2021-05-29 15:07:44 +08:00
}
if (data.isNeedPwd)
{
FUI_TipUI tipUI = TipHelper.OpenUI("请输入密码:", true, TipType.DoubleInput);
tipUI.m_btnYes.self.onClick.Clear();
tipUI.m_btnYes.self.onClick.Add(() =>
{
var pwd = tipUI.m_IptTxt.text;
this.SendProto(data, pwd);
});
return;
}
FUI_TipUI tip = TipHelper.OpenUI("是否购买此商品:", true, TipType.Double);
tip.m_btnYes.self.onClick.Clear();
tip.m_btnYes.self.onClick.Add(() =>
2021-04-08 20:09:59 +08:00
{
string pwd = string.Empty;
2021-05-29 15:07:44 +08:00
this.SendProto(data, pwd);
});
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;
}
2021-05-29 15:07:44 +08:00
2021-04-08 20:09:59 +08:00
await SendGetConsigbmentProto();
});
ui.m_btnNextPage.self.onClick.Set(async () =>
{
if (currPage++ >= totalPage - 1)
{
currPage = totalPage - 1;
return;
}
2021-05-29 15:07:44 +08:00
2021-04-08 20:09:59 +08:00
await SendGetConsigbmentProto();
});
2021-05-29 15:07:44 +08:00
2021-04-08 20:09:59 +08:00
async ETTask SendGetConsigbmentProto()
{
M2C_GetConsignment ret = await zoneScene.GetComponent<SessionComponent>().Call<M2C_GetConsignment>(new C2M_GetConsignment
2021-04-08 20:09:59 +08:00
{
2021-05-29 15:07:44 +08:00
ItemType = (ItemType) (itemTypeIndex), JobType = (JobType) (jobTypeIndex), Page = currPage
2021-04-08 20:09:59 +08:00
});
if (!ret.Message.IsNullOrEmpty())
{
TipHelper.OpenUI(ret.Message);
return;
}
2021-05-29 15:07:44 +08:00
this.consignMapList.Clear();
consignMapList.AddRange( ret.ConsignMapList);
this.totalPage = ret.TotalPage;
ShowListItem();
2021-04-08 20:09:59 +08:00
}
await ETTask.CompletedTask;
}
2021-05-29 15:07:44 +08:00
private void Refresh()
{
ShowListItem();
}
private async void SendProto(ConsignmentItemData _data, string _pwd)
{
M2C_BuyInConsignment ret = await this.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 });
}
private void ShowListItem()
2021-04-08 20:09:59 +08:00
{
//!页码
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-05-29 15:07:44 +08:00
var dic = ClientItemDataComponent.Instance.ConsignmentDic;
2021-04-08 20:09:59 +08:00
//!添加数据
2021-05-29 15:07:44 +08:00
if (!dic.TryGetValue(temp, out ConsignmentItemData data))
2021-04-08 20:09:59 +08:00
{
data = EntityFactory.CreateWithParent<ConsignmentItemData>(ClientItemDataComponent.Instance);
2021-05-29 15:07:44 +08:00
dic.Add(temp, data);
2021-04-08 20:09:59 +08:00
}
2021-05-29 15:07:44 +08:00
2021-04-08 20:09:59 +08:00
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-05-29 15:07:44 +08:00
{
if (ClientItemDataComponent.Instance.ConsignmentDic.TryGetValue(temp, out ConsignmentItemData __data))
{
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;
}
2021-05-29 15:07:44 +08:00
2021-04-08 20:09:59 +08:00
btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, itemIcon);
btnitem.m_txtName.text = itemName;
2021-05-29 15:07:44 +08:00
btnitem.m_txtTime.text =
(DateTimeOffset.FromUnixTimeMilliseconds(consignMap.RemainTime).DateTime - DateTime.UtcNow).ToString("hh\\:mm");
2021-04-08 20:09:59 +08:00
btnitem.m_txtPrice.text = $"{consignMap.Price:###,###}星币";
btnitem.m_txtSeller.text = consignMap.Name;
2021-05-29 15:07:44 +08:00
btnitem.m_txtCount.text = consignMap.Item.Count == 1? null : consignMap.Item.Count.ToString();
2021-04-08 20:09:59 +08:00
}
}
2021-05-29 15:07:44 +08:00
2021-04-08 20:09:59 +08:00
public void Destroy()
{
}
}
2021-05-29 15:07:44 +08:00
}