Files
JJBB/Assets/Project/Script/GUI/Shop/YuanBaoShopLogic.cs

945 lines
31 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Games.GlobeDefine;
using GCGame;
using GCGame.Table;
using Module.Log;
using UnityEngine;
public enum ITEM_TYPE
{
TYPE_INVALID = -1,
TYPE_ITEM = 0,
TYPE_FASHION,
TYPE_FELLOW,
TYPE_MOUNT
}
public enum DEADLINE_PRICE
{
PRICE_WEEK,
PRICE_MONTH,
PRICE_FOREVER
}
public class PriorityInfo
{
public short GoodsId;
public short Priority; // 存储表格中商品优先级 上限是32767 若该表需要同步修改此处
public PriorityInfo()
{
GoodsId = GlobeVar.INVALID_ID;
Priority = GlobeVar.INVALID_ID;
}
public PriorityInfo(short goodsId, short priority)
{
GoodsId = goodsId;
Priority = priority;
}
}
// 比较函数 left比right -1靠前 1靠后
public class PriorityInfoCompare : IComparer<PriorityInfo>
{
public int Compare(PriorityInfo left, PriorityInfo right)
{
if (left.Priority == right.Priority)
{
// 优先级相同时 GoodsId靠前的优先级高
if (left.GoodsId < right.GoodsId)
return -1;
return 1;
}
// 优先级为-1不参与排序 排最后
if (left.Priority == GlobeVar.INVALID_ID) return 1;
if (right.Priority == GlobeVar.INVALID_ID) return -1;
// 比ShowPirority 小的靠前
if (left.Priority < right.Priority)
return -1;
return 1;
}
}
public class YuanBaoShopLogic : UIControllerBase<YuanBaoShopLogic>
{
public enum OPEN_TYPE
{
OPEN_INVALID = 0,
OPEN_FUNCTION_BUTTON = 1,
OPEN_CHRISTMAS = 2,
OPEN_BEPOWER = 3,
OPEN_ITEM_GET_PATH = 4
}
private const int YUANBAO_SHOP_ID = 10001;
private const int BANGYUANBAO_SHOP_ID = 10002;
private static OPEN_TYPE m_YuanBaoShopOpenType = OPEN_TYPE.OPEN_FUNCTION_BUTTON;
public UITagPanel _TagPanel;
public UIContainerSelect UIContainerCharge;
public VipInfo vipInfo;
public static OPEN_TYPE YuanBaoShopOpenType
{
get { return m_YuanBaoShopOpenType; }
set { m_YuanBaoShopOpenType = value; }
}
public static void OpenShopPageStr(string moneyTypeStr, string pageClass)
{
var page = int.Parse(pageClass);
var moneyType = int.Parse(moneyTypeStr);
var hash = new Hashtable();
hash.Add("ShopPage", page);
hash.Add("MoneyType", moneyType);
UIManager.ShowUI(UIInfo.YuanBaoShop, OnYuanBaoShopLoad, hash);
}
public static void OpenYuanBaoShop(OPEN_TYPE openType, bool isShowBlackMarket)
{
YuanBaoShopOpenType = openType;
var hash = new Hashtable();
hash.Add("BlackMarket", isShowBlackMarket);
UIManager.ShowUI(UIInfo.YuanBaoShop, OnYuanBaoShopLoad, isShowBlackMarket);
}
//public static void OpenJiFenShop()
//{
// Hashtable hash = new Hashtable();
// hash.Add("JiFen", true);
// UIManager.ShowUI(UIInfo.YuanBaoShop, YuanBaoShopLogic.OnYuanBaoShopLoad, hash);
//}
public static void OpenShopForItemStr(string shopItemIDStr)
{
var shopItemID = int.Parse(shopItemIDStr);
OpenShopForItem(shopItemID);
}
public static void OpenShopForItem(int shopItemID)
{
var hash = new Hashtable();
hash.Add("ShopItemID", shopItemID);
UIManager.ShowUI(UIInfo.YuanBaoShop, OnYuanBaoShopLoad, hash);
}
public static void OpenShopForJiFenItem(int shopID, int shopItemID)
{
var hash = new Hashtable();
hash.Add("JiFenShopID", shopID);
hash.Add("ShopItemID", shopItemID);
UIManager.ShowUI(UIInfo.YuanBaoShop, OnYuanBaoShopLoad, hash);
}
public static void OpenChargePage()
{
var hash = new Hashtable();
hash.Add("ChargePage", true);
UIManager.ShowUI(UIInfo.YuanBaoShop, OnYuanBaoShopLoad, hash);
}
public static void OpenVipPage()
{
var hash = new Hashtable();
hash.Add("Vip", true);
UIManager.ShowUI(UIInfo.YuanBaoShop, OnYuanBaoShopLoad, hash);
}
public static void OnYuanBaoShopLoad(bool bSuccess, object param)
{
if (bSuccess)
{
var hash = param as Hashtable;
if (hash == null)
return;
if (hash.ContainsKey("JiFenShopID"))
{
Instance().ShowJiFenShopItem((int) hash["JiFenShopID"], (int) hash["ShopItemID"]);
}
else if (hash.ContainsKey("ShopItemID"))
{
Instance().ShowShopItem((int) hash["ShopItemID"]);
}
else if (hash.ContainsKey("ChargePage"))
{
Instance()._TagPanel.ShowPage(3);
}
else if (hash.ContainsKey("Vip"))
{
Instance()._TagPanel.ShowPage(3);
Instance().vipInfo.Click_OpenVIPRoot();
}
else if (hash.ContainsKey("ShopPage"))
{
Instance().ShowShopPage((int) hash["MoneyType"], (int) hash["ShopPage"]);
}
}
}
public void ShowJiFenShopItem(int shopID, int shopItemID)
{
_TagPanel.ShowPage(2);
var tab = TableManager.GetRoleIntegral().Values;
var shopStr = "";
foreach (var kv in tab)
if (kv.IntegralShopId == shopID)
{
shopStr = kv.IntegralName;
break;
}
if (!string.IsNullOrEmpty(shopStr))
{
jiFenDefaultItemID = shopItemID;
OnSubMenuClass3(shopStr);
ShowSelectedBG(shopID, _Page3ClassTag);
}
else
{
LogModule.ErrorLog("This no ji fen shopID : " + shopID);
}
}
public void InitChargeInfo()
{
var recharges = TableManager.GetRecharge();
var list = recharges.Where(a => a.Value.IfShow == 1).Select(a => a.Key).ToList();
//var keys = new List<int>(recharges.Keys);
//var list = new List<int>();
//for (int i = 0; i < keys.Count; i++)
//{
// //if (MonthCardCheckShow(keys[i]))
// // list.Add(keys[i]);
// if (recharges[keys[i]].IfShow == 1)
// list.Add(keys[i]);
//}
UIContainerCharge.InitContentItem(list, AskRecharge);
}
List<string> list1 = new List<string>() { "3500", "3400", "4000", "4001", "4002", "4003", "4004", "4005", "4100", "4200", "4600", "4601", "4602", "4010", "3801" };
List<string> list2 = new List<string>() { "4000", "4001", "4002", "4003", "4004", "4005" };
List<string> list3 = new List<string>() { "4600", "4601", "4602" };
//把原来在lua的代码挪过来那边写到Update下不知道干什么用的可能是渠道id对应不同的充值
private bool MonthCardCheckShow(int index)
{
var isHide = (NetworkConfig.Table_Version != "tablesbt"
&& index > 12
&& !list1.Contains(NetworkConfig._cchid))
|| ((index == 11 || index == 12 || index == 13)
&& list2.Contains(NetworkConfig._cchid))
|| ((index == 12 || index == 13 || index == 14)
&& NetworkConfig._cchid == "4010")
|| (list3.Contains(NetworkConfig._cchid)
&& index == 14)
|| ((NetworkConfig.Table_Version == "tablesbt"
|| NetworkConfig.Table_Version == "tablebtxy")
&& index == 1)
|| ((NetworkConfig.Table_Version != "tablesbt"
&& NetworkConfig.Table_Version != "tablebtxy")
&& index == 15);
return !isHide;
}
private void ReqRechargetInfo()
{
var req = new ReqRechargeGoodsList();
req.SendMsg();
}
public void AskRecharge(object initInfo)
{
var chargeId = (int) initInfo;
var recharge = TableManager.GetRechargeByID(chargeId);
if (recharge == null)
return;
if (recharge.Id == 1)
MessageBoxLogic.OpenOKCancelBox(60044, -1,
() => SdkControl.instance.Payment(recharge.Id));
else
SdkControl.instance.Payment(recharge.Id);
}
private void Awake()
{
SetInstance(this);
LoadAllGoodsDicPriority();
UIContainerCharge.SetShowItemFinishCallFun(ReqRechargetInfo);
}
private void OnEnable()
{
_TagPanel.ShowPage(0);
}
private void OnDisable()
{
YuanBaoShopOpenType = OPEN_TYPE.OPEN_FUNCTION_BUTTON;
}
private void OnDestroy()
{
SetInstance(null);
}
public void OnTagPage(int page)
{
switch (page)
{
case 0:
_ShopPageGO.SetActive(true);
InitPageLingyu();
break;
case 1:
_ShopPageGO.SetActive(true);
InitPageYuanbao();
break;
case 2:
_ShopPageGO.SetActive(true);
InitPageJiFen();
break;
case 3:
_ShopPageGO.SetActive(false);
InitChargeInfo();
break;
}
}
public void Close()
{
UIManager.CloseUI(UIInfo.YuanBaoShop);
}
public void ShowShopPage(int moneyType, int pageClass)
{
// 灵玉
if (moneyType == (int) MONEYTYPE.MONEYTYPE_YUANBAO)
{
_TagPanel.ShowPage(0);
ShowPageItem(pageClass);
}
// 元宝
else if (moneyType == (int) MONEYTYPE.MONEYTYPE_YUANBAO_BIND)
{
_TagPanel.ShowPage(1);
ShowPageItem(pageClass, -1, MONEYTYPE.MONEYTYPE_YUANBAO_BIND);
}
// 积分
else
{
_TagPanel.ShowPage(2);
var tab = TableManager.GetRoleIntegral().Values;
var targetStr = "";
foreach (var kv in tab)
if (kv.IntegralShopId == pageClass)
{
targetStr = kv.IntegralName;
break;
}
if (!string.IsNullOrEmpty(targetStr)) OnSubMenuClass3(targetStr);
}
}
public void ShowShopItem(int shopItemID)
{
Tab_YuanBaoShop shopTab = null;
var shopList = TableManager.GetYuanBaoShop().Values;
foreach (var item in shopList)
if (item.ItemID == shopItemID)
{
shopTab = item;
break;
}
//for (int i = 0; i < shopList.Count; ++i)
//{
// if (shopList[i][0].ItemID == shopItemID)
// {
// shopTab = shopList[i][0];
// break;
// }
//}
if (shopTab == null)
return;
if (shopTab.MoneyType == (int) MONEYTYPE.MONEYTYPE_YUANBAO)
{
_TagPanel.ShowPage(0);
ShowPageItem(shopTab.TabIndex, shopTab.ItemID);
}
else if (shopTab.MoneyType == (int) MONEYTYPE.MONEYTYPE_YUANBAO_BIND)
{
_TagPanel.ShowPage(1);
ShowPageItem(shopTab.TabIndex, shopTab.ItemID, MONEYTYPE.MONEYTYPE_YUANBAO_BIND);
}
}
// 该菜单下是否有商品,不包括商品不能出售的情况
private bool hasGoods(object tagObj, MONEYTYPE moneyType)
{
if (!_ClassTagTx.ContainsKey(tagObj.ToString()))
return false;
var index = _ClassTagTx[tagObj.ToString()];
foreach (var item in m_ListPriority)
{
var tabYuanBaoShop = TableManager.GetYuanBaoShopByID(item.GoodsId);
if (tabYuanBaoShop == null) continue;
// 金钱类型
if ((MONEYTYPE) tabYuanBaoShop.MoneyType != moneyType)
continue;
var tabCommonItem = TableManager.GetCommonItemByID(tabYuanBaoShop.ItemID);
if (tabCommonItem == null)
{
}
else
{
if (tabYuanBaoShop.TabIndex == index)
return true;
}
}
return false;
}
#region page1
public GameObject _ShopPageGO;
public UISubScollMenu _ClassTag;
public SysShopPage _ShopPage;
private Dictionary<string, int> _ClassTagTx;
private readonly List<PriorityInfo> m_ListPriority = new List<PriorityInfo>();
private int _ClassIdxVip;
public void InitPageLingyu()
{
_ClassTagTx = new Dictionary<string, int>();
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4142}"), 2);
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4140}"), 0);
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4141}"), 1);
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4145}"), 5);
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4143}"), 3);
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4144}"), 4);
_ClassIdxVip = 5;
_ClassTag.Clear();
foreach (var classStr in _ClassTagTx)
if (hasGoods(classStr.Key, MONEYTYPE.MONEYTYPE_YUANBAO))
_ClassTag.PushMenu(classStr.Key);
_ClassTag.ShowDefaultFirst();
var packet =
(CG_REQ_SHOP_ITEM_LIMIT_LIST) PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_SHOP_ITEM_LIMIT_LIST);
packet.SetShopid(YUANBAO_SHOP_ID);
packet.SendPacket();
}
private void LoadAllGoodsDicPriority()
{
if (m_ListPriority.Count > 0) return;
var list = TableManager.GetYuanBaoShop().Values;
foreach (var shopItem in list)
m_ListPriority.Add(new PriorityInfo((short) shopItem.Id, (short) shopItem.ShowPriority));
m_ListPriority.Sort(new PriorityInfoCompare());
}
// 第一个类型菜单栏回调 - 灵玉商城
public void OnSubMenuClass(object tagObj)
{
var tagTx = tagObj as string;
if (_ClassTagTx.ContainsKey(tagTx)) ShowPageItem(_ClassTagTx[tagTx]);
}
// 灵玉商城的Tag
private void ShowSelectedBG(int _Index, UISubScollMenu menuItems)
{
var classTagName = "";
foreach (var classTag in _ClassTagTx)
if (classTag.Value == _Index)
classTagName = classTag.Key;
foreach (var item in menuItems.SubBtns)
if (item.Key.MenuObj.Equals(classTagName))
item.Key.Selected();
else
item.Key.UnSelected();
}
//// 元宝商城的Tag
//private void ShowSelectedBG_YuanBaoBind(int _Index)
//{
// string classTagName = "";
// foreach (var classTag in _ClassTagTx)
// {
// if (classTag.Value == _Index)
// {
// classTagName = classTag.Key;
// }
// }
// foreach (var item in _ClassTag.SubBtns)
// {
// if (item.Key.MenuObj.Equals(classTagName))
// {
// item.Key.Selected();
// }
// else
// {
// item.Key.UnSelected();
// }
// }
//}
// 选择某个物品打开UI
private void ShowPageItem(int tagClassIdx, int shopItemID = -1, MONEYTYPE moneyType = MONEYTYPE.MONEYTYPE_YUANBAO)
{
if (moneyType == MONEYTYPE.MONEYTYPE_YUANBAO)
ShowSelectedBG(tagClassIdx, _ClassTag);
else if (moneyType == MONEYTYPE.MONEYTYPE_YUANBAO_BIND) ShowSelectedBG(tagClassIdx, _Page2ClassTag);
var shopItems = new List<SysShopPageItem.ShopItemInfo>();
var selectedItems = new List<SysShopPageItem.ShopItemInfo>();
for (var i = 0; i < m_ListPriority.Count; i++)
{
var tabYuanBaoShop = TableManager.GetYuanBaoShopByID(m_ListPriority[i].GoodsId);
if (tabYuanBaoShop == null) continue;
// MONEYTYPE_YUANBAO 写作元宝,读作灵玉。。。
if ((MONEYTYPE) tabYuanBaoShop.MoneyType != moneyType)
continue;
var tabCommonItem = TableManager.GetCommonItemByID(tabYuanBaoShop.ItemID);
if (tabCommonItem == null) continue;
if (IsTabNewGoods(tabYuanBaoShop, tagClassIdx))
{
var shopItemInfo = new SysShopPageItem.ShopItemInfo();
shopItemInfo.MoneyType = moneyType;
shopItemInfo.TabItem = tabCommonItem;
shopItemInfo.Price = tabYuanBaoShop.PriceForever;
shopItemInfo.GroupCount = tabYuanBaoShop.Num;
shopItemInfo.ItemIdxInShop = tabYuanBaoShop.Id;
shopItemInfo.LimitID = tabYuanBaoShop.LimitID;
if (_BuyLimit.ContainsKey(tabYuanBaoShop.Id))
shopItemInfo.BuyCnt = _BuyLimit[tabYuanBaoShop.Id];
else
shopItemInfo.BuyCnt = 0;
shopItemInfo.LimitCount = tabCommonItem.MaxStackSize;
shopItems.Add(shopItemInfo);
if (shopItemInfo.TabItem.Id == shopItemID)
selectedItems.Add(shopItemInfo);
}
}
if (selectedItems.Count == 0 && shopItems.Count != 0) selectedItems.Add(shopItems[0]);
//if (shopItems.Count > 0)
{
_ShopPage.InitShop(moneyType, BuyItemCallBack);
_ShopPage.SetShopItems(shopItems, selectedItems);
}
}
private bool IsTabNewGoods(Tab_YuanBaoShop tabYuanBaoShop, int tag)
{
if (tabYuanBaoShop.TabIndex != tag) return false;
if (false == IsGoodsOnSell(tabYuanBaoShop)) return false;
//if (tag == _ClassIdxVip)
//{
// if (tabYuanBaoShop.ItemType != (int)ITEM_TYPE.TYPE_ITEM)
// {
// return false;
// }
// Tab_VIPShop tabVIPShop = TableManager.GetVIPShopByID(tabYuanBaoShop.ItemID, 0);
// if (tabVIPShop == null)
// {
// return false;
// }
// int nPlayerVIPLevel = VipData.GetVipLv();
// if (nPlayerVIPLevel < tabVIPShop.ShowLevelReq)
// {
// return false;
// }
//}
return true;
}
private bool IsGoodsOnSell(Tab_YuanBaoShop tabYuanBaoShop)
{
if (tabYuanBaoShop.SellTimeStart == GlobeVar.INVALID_ID ||
tabYuanBaoShop.SellTimeEnd == GlobeVar.INVALID_ID)
return true;
var DateTimeSellStart = new DateTime(
tabYuanBaoShop.SellTimeStart / 100000000 % 100 + 2000,
tabYuanBaoShop.SellTimeStart / 1000000 % 100,
tabYuanBaoShop.SellTimeStart / 10000 % 100,
tabYuanBaoShop.SellTimeStart / 100 % 100,
tabYuanBaoShop.SellTimeStart / 1 % 100,
0);
var DateTimeSellEnd = new DateTime(
tabYuanBaoShop.SellTimeEnd / 100000000 % 100 + 2000,
tabYuanBaoShop.SellTimeEnd / 1000000 % 100,
tabYuanBaoShop.SellTimeEnd / 10000 % 100,
tabYuanBaoShop.SellTimeEnd / 100 % 100,
tabYuanBaoShop.SellTimeEnd / 1 % 100,
0);
var DateTimeNow = Utils.GetServerDateTime();
return DateTimeSellStart <= DateTimeNow && DateTimeNow < DateTimeSellEnd;
}
public void BuyItemCallBack(SysShopPageItem.ShopItemInfo shopItemInfo, int count)
{
if (shopItemInfo.MoneyType == MONEYTYPE.MONEYTYPE_YUANBAO ||
shopItemInfo.MoneyType == MONEYTYPE.MONEYTYPE_YUANBAO_BIND)
{
var tabYuanBaoShop = TableManager.GetYuanBaoShopByID(shopItemInfo.ItemIdxInShop);
if (!JudgeMoneyLogic.IsMoneyEnough((MONEYTYPE) tabYuanBaoShop.MoneyType, tabYuanBaoShop.PriceForever))
//GlobalData.ShowLessMoneyTip((MONEYTYPE)tabYuanBaoShop.MoneyType);
//GameManager.gameManager.PlayerDataPool.Money.PushMoneyLessData(tabYuanBaoShop.MoneyType);
return;
var buyPacket = (CG_BUY_YUANBAOGOODS) PacketDistributed.CreatePacket(MessageID.PACKET_CG_BUY_YUANBAOGOODS);
buyPacket.SetGoodID(shopItemInfo.ItemIdxInShop);
LogModule.DebugLog("buy shop id:" + shopItemInfo.ItemIdxInShop);
buyPacket.SetBuyNum(count);
buyPacket.SetIsUseBind(0);
buyPacket.SetDeadline((int) DEADLINE_PRICE.PRICE_FOREVER);
buyPacket.SendPacket();
}
else
{
var curItemIndex = shopItemInfo.ItemIdxInShop;
var sysShopTable = TableManager.GetSystemShopByID(_JifenShopID);
if (null == sysShopTable)
{
LogModule.ErrorLog("cur sysshop id isn't exist! : id " + _JifenShopID);
return;
}
var pid = sysShopTable.GetPricebyIndex(curItemIndex);
if (pid < 0)
{
LogModule.ErrorLog("can not find cur item pid : itemID" + pid);
return;
}
var currencyType = (MONEYTYPE) sysShopTable.GetMoneySubTypebyIndex(0);
var mainType = sysShopTable.GetMoneyTypebyIndex(0);
if (mainType == (int) CONSUM_TYPE.MONEY) //属性值
{
if (!JudgeMoneyLogic.IsMoneyEnough((MONEYTYPE) sysShopTable.GetMoneySubTypebyIndex(curItemIndex),
sysShopTable.GetPricebyIndex(curItemIndex) * count)) return;
}
else
{
//判断当前的属性值是否足够消费
if (GameManager.gameManager.PlayerDataPool.GetPropInt((PropID.PropertyID) currencyType) <
sysShopTable.GetPricebyIndex(curItemIndex) * count)
{
//积分不够
var tips = StrDictionary.GetClientDictionaryString("#{6102}",
PropID.GetAttrName((PropID.PropertyID) currencyType));
GUIData.AddNotifyData(tips);
return;
}
}
var buyPacket = (CG_SYSTEMSHOP_BUY) PacketDistributed.CreatePacket(MessageID.PACKET_CG_SYSTEMSHOP_BUY);
buyPacket.SetBuyNum(count);
buyPacket.SetShopId(_JifenShopID);
buyPacket.SetMercIndex(curItemIndex);
buyPacket.SendPacket();
}
}
public void BtnShowVip()
{
//UIManager.ShowUI(UIInfo.VipRoot);
}
public void UpdateLimitInfo()
{
switch (_TagPanel.GetShowingPage())
{
case 0:
{
var packet =
(CG_REQ_SHOP_ITEM_LIMIT_LIST) PacketDistributed.CreatePacket(MessageID
.PACKET_CG_REQ_SHOP_ITEM_LIMIT_LIST);
packet.SetShopid(YUANBAO_SHOP_ID);
packet.SendPacket();
}
break;
case 1:
{
var packet =
(CG_REQ_SHOP_ITEM_LIMIT_LIST) PacketDistributed.CreatePacket(MessageID
.PACKET_CG_REQ_SHOP_ITEM_LIMIT_LIST);
packet.SetShopid(BANGYUANBAO_SHOP_ID);
packet.SendPacket();
}
break;
case 2:
{
var packet =
(CG_REQ_SHOP_ITEM_LIMIT_LIST) PacketDistributed.CreatePacket(MessageID
.PACKET_CG_REQ_SHOP_ITEM_LIMIT_LIST);
packet.SetShopid(_JifenShopID);
packet.SendPacket();
}
break;
}
}
#endregion
#region page2
public UISubScollMenu _Page2ClassTag;
public Dictionary<int, int> _BuyLimit = new Dictionary<int, int>();
public void InitPageYuanbao()
{
_ClassTagTx = new Dictionary<string, int>();
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4142}"), 2);
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4140}"), 0);
_ClassTagTx.Add(StrDictionary.GetClientDictionaryString("#{4141}"), 1);
_ClassIdxVip = 5;
_Page2ClassTag.Clear();
foreach (var classStr in _ClassTagTx)
if (hasGoods(classStr.Key, MONEYTYPE.MONEYTYPE_YUANBAO_BIND))
_Page2ClassTag.PushMenu(classStr.Key);
_Page2ClassTag.ShowDefaultFirst();
var packet =
(CG_REQ_SHOP_ITEM_LIMIT_LIST) PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_SHOP_ITEM_LIMIT_LIST);
packet.SetShopid(BANGYUANBAO_SHOP_ID);
packet.SendPacket();
_BuyLimit.Clear();
}
// 第二个类型菜单栏回调 - 元宝商城
public void OnSubMenuClass2(object tagObj)
{
LogModule.DebugLog("OnSubMenuClass2");
var tagTx = tagObj as string;
if (!_ClassTagTx.ContainsKey(tagTx))
return;
var tagClassIdx = _ClassTagTx[tagTx];
var shopItems = new List<SysShopPageItem.ShopItemInfo>();
for (var i = 0; i < m_ListPriority.Count; i++)
{
var shopItemInfo = new SysShopPageItem.ShopItemInfo();
var tabYuanBaoShop = TableManager.GetYuanBaoShopByID(m_ListPriority[i].GoodsId);
if (tabYuanBaoShop == null) continue;
// MONEYTYPE_YUANBAO_BIND 才是元宝
if ((MONEYTYPE) tabYuanBaoShop.MoneyType != MONEYTYPE.MONEYTYPE_YUANBAO_BIND)
continue;
var tabCommonItem = TableManager.GetCommonItemByID(tabYuanBaoShop.ItemID);
if (tabCommonItem == null) continue;
if (IsTabNewGoods(tabYuanBaoShop, tagClassIdx))
{
shopItemInfo.MoneyType = MONEYTYPE.MONEYTYPE_YUANBAO_BIND;
shopItemInfo.TabItem = tabCommonItem;
shopItemInfo.Price = tabYuanBaoShop.PriceForever;
shopItemInfo.GroupCount = tabYuanBaoShop.Num;
shopItemInfo.ItemIdxInShop = tabYuanBaoShop.Id;
shopItemInfo.LimitID = tabYuanBaoShop.LimitID;
if (_BuyLimit.ContainsKey(tabYuanBaoShop.Id))
shopItemInfo.BuyCnt = _BuyLimit[tabYuanBaoShop.Id];
else
shopItemInfo.BuyCnt = 0;
shopItemInfo.LimitCount = tabCommonItem.MaxStackSize;
shopItems.Add(shopItemInfo);
}
}
//if (shopItems.Count > 0)
{
_ShopPage.InitShop(MONEYTYPE.MONEYTYPE_YUANBAO_BIND, BuyItemCallBack);
_ShopPage.SetShopItems(shopItems);
}
}
public void InitShopItemLimit(GC_RET_SHOP_ITEM_LIMIT_LIST packet)
{
_BuyLimit.Clear();
LogModule.DebugLog("InitShopItemLimit");
foreach (var itemLimit in packet.itemlimtlistList)
{
LogModule.DebugLog("ItemBuyNum:" + itemLimit.Itemindex + "," + itemLimit.Buycount);
if (_BuyLimit.ContainsKey(itemLimit.Itemindex))
_BuyLimit[itemLimit.Itemindex] = itemLimit.Buycount;
else
_BuyLimit.Add(itemLimit.Itemindex, itemLimit.Buycount);
}
_ShopPage._ShopItemContainer.ForeachActiveItem<SysShopPageItem>(shopItem =>
{
LogModule.DebugLog("ShopItemID:" + shopItem._ShopItemInfo.ItemIdxInShop);
foreach (var kv in _BuyLimit)
if (kv.Key == shopItem._ShopItemInfo.ItemIdxInShop)
{
LogModule.DebugLog("ItemBuyNum:" + kv.Key + "," + kv.Value);
shopItem.SetLimit(kv.Value);
}
});
_ShopPage.RefreshSelected();
}
#endregion
#region page3
//private Dictionary<string, int> _Class3TagTx;
private int jiFenDefaultItemID = -1;
public UISubScollMenu _Page3ClassTag;
public void InitPageJiFen()
{
_BuyLimit.Clear();
_ClassTagTx = new Dictionary<string, int>();
var tab = TableManager.GetRoleIntegral().Values;
foreach (var kv in tab) _ClassTagTx.Add(kv.IntegralName, kv.IntegralShopId);
_Page3ClassTag.Clear();
foreach (var kv in _ClassTagTx) _Page3ClassTag.PushMenu(kv.Key);
_Page3ClassTag.ShowDefaultFirst();
}
private int _JifenShopID = -1;
public void OnSubMenuClass3(object tagObj)
{
var tagTx = tagObj as string;
if (_ClassTagTx.ContainsKey(tagTx)) _JifenShopID = _ClassTagTx[tagTx];
ShowSelectedBG(_JifenShopID, _Page3ClassTag);
var m_curShopTable = TableManager.GetSystemShopByID(_JifenShopID);
var isBuyLimit = false;
var shopItems = new List<SysShopPageItem.ShopItemInfo>();
var selectedItems = new List<SysShopPageItem.ShopItemInfo>();
for (int i = 0, count = m_curShopTable.getPidCount(); i < count; i++)
{
var shopItemInfo = new SysShopPageItem.ShopItemInfo();
var curTabItem = TableManager.GetCommonItemByID(m_curShopTable.GetPidbyIndex(i));
if (null != curTabItem)
{
shopItemInfo.MoneyType = (MONEYTYPE) m_curShopTable.GetMoneySubTypebyIndex(i);
shopItemInfo.TabItem = curTabItem;
shopItemInfo.Price = m_curShopTable.GetPricebyIndex(i);
shopItemInfo.GroupCount = m_curShopTable.GetNumPerGroupbyIndex(i);
shopItemInfo.ItemIdxInShop = i;
shopItemInfo.LimitID = m_curShopTable.GetLimitIdbyIndex(i);
shopItemInfo.LimitCount = 99;
isBuyLimit |= shopItemInfo.LimitID != -1;
shopItems.Add(shopItemInfo);
if (shopItemInfo.TabItem.Id == jiFenDefaultItemID) selectedItems.Add(shopItemInfo);
}
}
if (isBuyLimit)
{
var packet =
(CG_REQ_SHOP_ITEM_LIMIT_LIST) PacketDistributed.CreatePacket(MessageID
.PACKET_CG_REQ_SHOP_ITEM_LIMIT_LIST);
packet.SetShopid(_JifenShopID);
packet.SendPacket();
}
if (shopItems.Count > 0)
{
// 必须先判断是否需要排序使用List.sort系统可能会调用不稳定的排序。除非重新写个稳定的排序
var needSort = false;
for (var i = 0; i < shopItems.Count; ++i)
if (shopItems[i].isNeed > 0)
{
needSort = true;
break;
}
if (needSort) shopItems.Sort(SysShopController.SortMyItemList);
_ShopPage.InitShop(shopItems[0].MoneyType, BuyItemCallBack);
_ShopPage.SetShopItems(shopItems, selectedItems);
}
jiFenDefaultItemID = -1;
}
private int _MarkPositionItemDataId = -1;
public void PositionItem()
{
if (_MarkPositionItemDataId == -1)
return;
_ShopPage._ShopItemContainer.ForeachActiveItem<SysShopPageItem>(item =>
{
if (item._ShopItemInfo.TabItem.Id == _MarkPositionItemDataId)
{
var pos = item.GetComponent<RectTransform>().anchoredPosition.y;
var posY = Mathf.Clamp(Mathf.Abs(pos), 0, _ShopPage._ShopItemContainer._ContainerObj.sizeDelta.y);
var containerObjLocalPos = _ShopPage._ShopItemContainer._ContainerObj.localPosition;
_ShopPage._ShopItemContainer._ContainerObj.localPosition = new Vector3(containerObjLocalPos.x, posY, 0);
_MarkPositionItemDataId = -1;
}
});
}
#endregion
}