Files
JJBB/Assets/Project/Script/GUI/Market/MarketPlayerForSellPage.cs

232 lines
7.3 KiB
C#
Raw Permalink Normal View History

2024-08-23 15:49:34 +08:00
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Games.Item;
using System.Collections.Generic;
using GCGame.Table;
using Module.Log;
public class MarketPlayerForSellPage : UIControllerBase<MarketPlayerForSellPage>
{
// Use this for initialization
void OnEnable ()
{
SetInstance(this);
}
void OnDisable()
{
SetInstance(null);
}
// Update is called once per frame
void Update ()
{
}
#region
public const float _TAX_RATE = 0.01f;
public UIContainerBase _OtherSells;
public Image _ItemIcon;
public Image _ItemQuality;
public Text _ItemName;
public Text _ItemLevel;
public Text _PriceDesc;
public UIDynamicText _ItemDesc;
public UINumBoardInput _ItemPrice;
public UINumBoardInput _SellNum;
public UICurrencyItem _TotalPrice;
public UICurrencyItem _TaxPrice;
public Text _LastCanSell;
private GameItem _SellItem;
private int _BasePrice;
private int _PriceStep;
public void InitSellItem(GameItem sellItem)
{
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(sellItem.DataID, 0);
if (sellItem == null)
return;
_SellItem = sellItem;
LoadAssetBundle.Instance.SetImageSprite(_ItemIcon, commonItem.Icon);
LoadAssetBundle.Instance.SetImageSprite(_ItemQuality, GCGame.Utils.GetItemQualityFrame(commonItem));
if (commonItem.QualityEffect > 0)
{
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, _ItemIcon.transform);
}
else
{
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, _ItemIcon.transform);
}
_ItemName.text = sellItem.GetItemColorName();
_ItemLevel.text = StrDictionary.GetClientDictionaryString("#{1166}", commonItem.MinLevelRequire);
_ItemDesc.SetText(StrDictionary.GetClientString_WithNameSex(commonItem.Tips));
_SellNum.Init(0, 1, sellItem.StackCount);
var sellItemTab = TableManager.GetUserShopItemByID(_SellItem.DataID, 0);
_BasePrice = sellItemTab.SysPrice;
InitSellPrice();
OnNumChange();
_LastCanSell.text = StrDictionary.GetClientDictionaryString("#{6361}", MarketPlayerShopSellPage.Instance().MaxSellCnt - MarketPlayerShopSellPage.Instance().InSellCnt);
AskSellItems();
AskSellPrice();
//List<MarketPlayerSellItemInfo> onSellItem = new List<MarketPlayerSellItemInfo>();
//for (int i = 0; i < 4; ++i)
//{
// MarketPlayerSellItemInfo sellItem1 = new MarketPlayerSellItemInfo();
// sellItem1.IsLock = -1;
// sellItem1.DataId = sellItem.DataID;
// sellItem1.Guid = 0;
// sellItem1.SellCnt = i + 1;
// sellItem1.Price = i *2 + 50;
// sellItem1.IsOnSell = -1;
// sellItem1.IsOutTime = -1;
// onSellItem.Add(sellItem1);
//}
//_OtherSells.InitContentItem(onSellItem);
}
private void AskSellItems()
{
CG_ASK_CONSIGN_SALE_ITEMS_BY_ID packet = (CG_ASK_CONSIGN_SALE_ITEMS_BY_ID)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_CONSIGN_SALE_ITEMS_BY_ID);
packet.AddDataIdList(_SellItem.DataID);
packet.Minindex = 0;
packet.Maxindex = 3;
packet.Itemtype = 2;
packet.Itemstate = (int)CG_ASK_CONSIGN_SALE_ITEMS_BY_CLASS.EUserShopItemState.EItemOnSale;
packet.SendPacket();
}
private void AskSellPrice()
{
CG_ASK_SYS_RECOMMAND_PRICE packet = (CG_ASK_SYS_RECOMMAND_PRICE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_ASK_SYS_RECOMMAND_PRICE);
packet.DataId = _SellItem.DataID;
packet.SendPacket();
}
public void UpdateItemPrice(GC_RET_SYS_RECOMMAND_PRICE packet)
{
_BasePrice = packet.Price;
InitSellPrice();
}
public void UpdateItemList(GC_RET_CONSIGNSALEITEMINFO packet)
{
List<MarketPlayerSellItemInfo> marketItemList = new List<MarketPlayerSellItemInfo>();
for (int i = 0; i < packet.dataidCount; ++i)
{
MarketPlayerSellItemInfo item = new MarketPlayerSellItemInfo();
item.DataId = packet.GetDataid(i);
item.Guid = packet.GetGuid(i);
//item.IsWatched = packet.GetItemstate(i) == 0 ? 1 : 0;
item.Price = packet.GetPrice(i);
item.SellCnt = packet.GetStackcount(i);
//item.WatchCnt = packet.GetFocusnum(i);
//item.WatchTime = packet.GetOnsalcetm(i);
marketItemList.Add(item);
}
if (marketItemList.Count > 0)
_OtherSells.InitContentItem(marketItemList);
else
_OtherSells.InitContentItem(marketItemList);
}
private void InitSellPrice()
{
var sellItemTab = TableManager.GetUserShopItemByID(_SellItem.DataID, 0);
int minPrice = 0;
if (sellItemTab.MinPrice > 0)
{
if (_SellItem.IsEquipMent())
{
minPrice = Mathf.Max((int)(_BasePrice * 0.05f), sellItemTab.MinPrice);
}
else
{
minPrice = Mathf.Max((int)(_BasePrice * 0.05f), sellItemTab.MinPrice);
}
}
int maxPrice = 2147483647;
if (sellItemTab.MaxPrice > 0)
{
if (_SellItem.IsEquipMent())
{
maxPrice = Mathf.Max((int)(_BasePrice * 1.95f), sellItemTab.MaxPrice);
}
else
{
maxPrice = Mathf.Max((int)(_BasePrice * 1.5f), sellItemTab.MaxPrice);
}
}
if (_SellItem.IsRare || sellItemTab.Type == 2)
{
minPrice = Mathf.Max(minPrice, sellItemTab.MinProtecPrice);
maxPrice = 2147483647;
_ItemPrice._IsShowInputBoard = true;
}
else
{
_ItemPrice._IsShowInputBoard = false;
}
_ItemPrice.Init(_BasePrice, minPrice, maxPrice);
_PriceStep = (int)(_BasePrice * 0.05f);
_ItemPrice.SetStepValue(_PriceStep);
}
public void OnNumChange()
{
int totalValue = _ItemPrice.Value * _SellNum.Value;
_TotalPrice.ShowCurrency(MONEYTYPE.MONEYTYPE_COIN, totalValue);
int taxValue = Mathf.CeilToInt(totalValue * 0.01f);
_TaxPrice.ShowCurrency(MONEYTYPE.MONEYTYPE_COIN, taxValue);
int priceDiscount = (_ItemPrice.Value - _BasePrice) / _PriceStep * 5;
string exStr = "";
if (priceDiscount < 0)
{
exStr = "-" + Mathf.Abs(priceDiscount).ToString();
}
else if (priceDiscount > 0)
{
exStr = "+" + Mathf.Abs(priceDiscount).ToString();
}
else
{
exStr = Mathf.Abs(priceDiscount).ToString();
}
_PriceDesc.text = StrDictionary.GetClientDictionaryString("#{6362}", exStr);
}
public void OnBtnSell()
{
CG_CONSIGNSALEITEM packet = (CG_CONSIGNSALEITEM)PacketDistributed.CreatePacket(MessageID.PACKET_CG_CONSIGNSALEITEM);
packet.Itemguid = _SellItem.Guid;
packet.Itemcount = _SellNum.Value;
packet.Itemprice = _ItemPrice.Value;
packet.SendPacket();
MarketPlayerSell.Instance().CloseForSellPage();
LogModule.DebugLog("OnBtnSell:" + _SellItem.DataID + " num:" + _SellNum.Value);
}
#endregion
}