//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, September 18, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using Snxxz.UI;
|
|
namespace Snxxz.UI
|
{
|
public class StoreWin : Window
|
{
|
[SerializeField] FunctionButton m_DayStoreTitle;
|
[SerializeField] FunctionButton m_WeekStoreTitle;
|
[SerializeField] FunctionButton m_CommonStoreTitle;
|
[SerializeField] FunctionButton m_GrowStrongerStoreTitle;
|
//[SerializeField] FunctionButton m_BindStoreTitle;
|
[SerializeField] FunctionButton m_IntegralStoreTitle;
|
[SerializeField] FunctionButtonGroup m_FuncBtnGroup;
|
[SerializeField] Button m_LeftBtn;
|
[SerializeField] Button m_RightBtn;
|
[SerializeField] Button m_CloseBtn;
|
[SerializeField] ScrollerController m_ShopCtrl;
|
[SerializeField] GameObject m_FollowStoreBottom;
|
[SerializeField] Text m_CoinsType1;
|
[SerializeField] Text m_CoinsType2;
|
[SerializeField] Text m_CoinsType3;
|
[SerializeField] RectTransform m_RefreshContainer;
|
[SerializeField] Button m_RefreshCommodities;
|
[SerializeField] Text m_RefreshTimeText;
|
[SerializeField] GameObject m_IntegralBottom;
|
[SerializeField] Button m_AssistBtn;
|
|
StoreModel model { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
private List<StoreModel.StoreData> commodities;
|
private int shopId = 0;
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_ShopCtrl.OnRefreshCell += RefreshShopCell;
|
m_ShopCtrl.lockType = EnhanceLockType.KeepVertical;
|
|
m_DayStoreTitle.SetListener(OpenDayStore);
|
m_WeekStoreTitle.SetListener(OpenMysteryStore);
|
m_CommonStoreTitle.SetListener(OpenCommonStore);
|
m_GrowStrongerStoreTitle.SetListener(OpenStrengthStore);
|
//m_BindStoreTitle.SetListener(OpenBindGoldStore);
|
m_IntegralStoreTitle.SetListener(OpenIntegralStore);
|
m_AssistBtn.SetListener(ViewAssistRecorders);
|
m_RefreshCommodities.SetListener(RefreshCommondities);
|
m_LeftBtn.SetListener(() => { m_FuncBtnGroup.TriggerLast(); });
|
m_RightBtn.SetListener(() => { m_FuncBtnGroup.TriggerNext(); });
|
m_CloseBtn.SetListener(() => { CloseImmediately(); });
|
}
|
|
protected override void OnPreOpen()
|
{
|
shopId = 0;
|
model.RefreshTCBPlayerDataEvent += OnRefreshPlayerInfo;
|
model.RefreshBuyShopLimitEvent += OnCreate;
|
model.mysteryShopRefreshEvent += OnCreate;
|
GlobalTimeEvent.Instance.secondEvent += UpdateRefreshTime;
|
RefreshCoins();
|
UpdateRefreshTime();
|
model.SetPushPetAndMountWinState(true, true);
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
|
if (!WindowJumpMgr.Instance.IsJumpState && functionOrder == 0)
|
{
|
if (model.storeFunc1Point.state == RedPointState.Simple)
|
{
|
functionOrder = m_DayStoreTitle.order;
|
}
|
else if (model.storeFunc2Point.state == RedPointState.Simple)
|
{
|
functionOrder = m_WeekStoreTitle.order;
|
}
|
else if (model.storeFunc3Point.state == RedPointState.Simple)
|
{
|
functionOrder = m_CommonStoreTitle.order;
|
}
|
else if (model.storeFunc4Point.state == RedPointState.Simple)
|
{
|
functionOrder = m_GrowStrongerStoreTitle.order;
|
}
|
else if (model.storeFunc5Point.state == RedPointState.Simple)
|
{
|
functionOrder = m_IntegralStoreTitle.order;
|
}
|
}
|
|
if (!WindowJumpMgr.Instance.IsJumpState && model.funcOrder != -1)
|
{
|
functionOrder = model.funcOrder;
|
}
|
m_FuncBtnGroup.TriggerByOrder(functionOrder);
|
}
|
|
protected override void OnAfterOpen()
|
{
|
CheckJumpToModel();
|
}
|
|
protected override void OnPreClose()
|
{
|
model.CloseAllRedpoint(StoreFunc.DayStore);
|
model.storeFuncType = StoreFunc.DayStore;
|
model.RefreshBuyShopLimitEvent -= OnCreate;
|
model.mysteryShopRefreshEvent -= OnCreate;
|
GlobalTimeEvent.Instance.secondEvent -= UpdateRefreshTime;
|
model.RefreshTCBPlayerDataEvent -= OnRefreshPlayerInfo;
|
}
|
|
protected override void OnAfterClose()
|
{
|
if (!WindowJumpMgr.Instance.IsJumpState)
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
#endregion
|
|
private void CheckJumpToModel()
|
{
|
if (AchievementGoto.guideAchievementId != 0)
|
{
|
var successConfig = SuccessConfig.Get(AchievementGoto.guideAchievementId);
|
if (successConfig.Type == 97)
|
{
|
commodities = model.TryGetStoreDatas(model.storeFuncType);
|
List<StoreModel.StoreData> orderlist = new List<StoreModel.StoreData>();
|
orderlist.AddRange(commodities);
|
orderlist.Sort(CompareByMoney);
|
for (int i = 0; i < commodities.Count; i++)
|
{
|
if (commodities[i].shopId == orderlist[0].shopId)
|
{
|
shopId = commodities[i].shopId;
|
int index = i / 2;
|
m_ShopCtrl.JumpIndex(index);
|
m_ShopCtrl.m_Scorller.RefreshActiveCellViews();
|
break;
|
}
|
}
|
AchievementGoto.guideAchievementId = 0;
|
}
|
}
|
else
|
{
|
if (model.jumpShopId != 0)
|
{
|
commodities = model.TryGetStoreDatas(model.storeFuncType);
|
for (int i = 0; i < commodities.Count; i++)
|
{
|
if (commodities[i].shopId == model.jumpShopId)
|
{
|
shopId = commodities[i].shopId;
|
int index = i / 2;
|
m_ShopCtrl.JumpIndex(index > 2 ? index - 1 : index);
|
m_ShopCtrl.m_Scorller.RefreshActiveCellViews();
|
break;
|
}
|
}
|
model.ClearJumpModel();
|
}
|
}
|
}
|
|
private void UpdateRefreshTime()
|
{
|
if (model.storeFuncType == StoreFunc.MysteryStore)
|
{
|
|
m_RefreshCommodities.gameObject.SetActive(true);
|
m_RefreshTimeText.text = model.GetMysteryStoreRefreshTime();
|
}
|
else
|
{
|
if (commodities == null || commodities.Count < 1)
|
{
|
commodities = model.TryGetStoreDatas(model.storeFuncType);
|
}
|
|
if (commodities == null || commodities.Count == 0)
|
{
|
|
return;
|
}
|
|
var refreshType = commodities[0].storeConfig.RefreshType;
|
if (refreshType == 0)
|
{
|
|
}
|
else
|
{
|
|
m_RefreshCommodities.gameObject.SetActive(false);
|
m_RefreshTimeText.text = model.GetStoreRefreshTimeByType(refreshType);
|
}
|
}
|
|
}
|
|
int CompareByMoney(StoreModel.StoreData start, StoreModel.StoreData end)
|
{
|
int money1 = start.storeConfig.MoneyNumber;
|
int money2 = end.storeConfig.MoneyNumber;
|
if (money1 != money2)
|
{
|
return money1.CompareTo(money2);
|
}
|
|
int index1 = commodities.IndexOf(start);
|
int index2 = commodities.IndexOf(end);
|
if (index1 != index2)
|
{
|
return index1.CompareTo(index2);
|
}
|
return 0;
|
}
|
|
private void RefreshUI()
|
{
|
if (commodities.Count < 1)
|
{
|
return;
|
}
|
|
var shopType = commodities[0].storeConfig.ShopType;
|
var RefreshType = commodities[0].storeConfig.RefreshType;
|
this.m_RefreshContainer.gameObject.SetActive(RefreshType != 0);
|
if (model.showCoinsUIDict != null && model.showCoinsUIDict.ContainsKey(shopType))
|
{
|
if (model.showCoinsUIDict[shopType] == 1)
|
{
|
m_FollowStoreBottom.gameObject.SetActive(true);
|
m_IntegralBottom.gameObject.SetActive(false);
|
}
|
else if (model.showCoinsUIDict[shopType] == 2)
|
{
|
m_FollowStoreBottom.gameObject.SetActive(false);
|
m_IntegralBottom.gameObject.SetActive(true);
|
}
|
}
|
}
|
|
void RefreshCoins()
|
{
|
m_CoinsType1.text = UIHelper.GetMoneyCnt(1).ToString();
|
m_CoinsType2.text = UIHelper.GetMoneyCnt(3).ToString();
|
m_CoinsType3.text = UIHelper.ReplaceXianYuanCoinsNum(UIHelper.GetMoneyCnt(17));
|
}
|
|
private void OnCreate()
|
{
|
shopId = 0;
|
commodities = model.TryGetStoreDatas(model.storeFuncType);
|
m_ShopCtrl.Refresh();
|
if (commodities.Count > 0)
|
{
|
int remain = commodities.Count % 2;
|
int line = (int)commodities.Count / 2;
|
if (remain > 0)
|
{
|
line += 1;
|
}
|
|
for (var i = 0; i < line; i++)
|
{
|
m_ShopCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
}
|
m_ShopCtrl.Restart();
|
m_ShopCtrl.JumpIndex(0);
|
RefreshUI();
|
}
|
|
private void OnRefreshPlayerInfo(PlayerDataType refreshType)
|
{
|
switch (refreshType)
|
{
|
case PlayerDataType.VIPLv:
|
OnCreate();
|
break;
|
case PlayerDataType.Gold:
|
case PlayerDataType.GoldPaper:
|
case PlayerDataType.FBHelpPoint:
|
RefreshCoins();
|
break;
|
default:
|
break;
|
}
|
}
|
|
private void RefreshShopCell(ScrollerDataType type, CellView cell)
|
{
|
for (var i = 0; i < cell.transform.childCount; i++)
|
{
|
var cellCount = (cell.transform.childCount) * cell.index + (i + 1);
|
var shopItemCell = cell.transform.GetChild(i).GetComponent<ShopItemCell>();
|
if (shopItemCell == null)
|
{
|
shopItemCell = cell.transform.GetChild(i).gameObject.AddComponent<ShopItemCell>();
|
}
|
|
if (commodities.Count >= cellCount)
|
{
|
StoreConfig shopInfo = commodities[cellCount - 1].storeConfig;
|
if (model.shopRedDict.ContainsKey(shopInfo.ID))
|
{
|
shopItemCell.redpoint.redpointId = model.shopRedDict[shopInfo.ID].id;
|
}
|
cell.transform.GetChild(i).gameObject.SetActive(true);
|
if (shopInfo.SalesStatus.Trim() != "")
|
{
|
shopItemCell.stateImage.gameObject.SetActive(true);
|
shopItemCell.stateImage.SetSprite(shopInfo.SalesStatus);
|
shopItemCell.stateImage.SetNativeSize();
|
}
|
else
|
{
|
shopItemCell.stateImage.gameObject.SetActive(false);
|
}
|
|
var config = ItemConfig.Get(model.GetReplaceId(shopInfo.ID, shopInfo.ItemID));
|
if (config != null)
|
{
|
ItemCellModel cellModel = new ItemCellModel(config.ID, true, 0,"", PackType.Deleted, true);
|
shopItemCell.itemCell.button.enabled = false;
|
shopItemCell.itemCell.Init(cellModel);
|
shopItemCell.itemNameText.text = config.ItemName;
|
shopItemCell.coinsIcon.SetIconWithMoneyType(shopInfo.MoneyType);
|
ulong shopCost = (ulong)(shopInfo.MoneyNumber);
|
shopItemCell.coinNumText.text = UIHelper.ReplaceLargeNum(shopCost);
|
BuyItemController buyItem = BuyItemController.Instance;
|
int curVipIndex = -1;
|
int nextVipIndex = -1;
|
bool isVipBuy = buyItem.CheckIsVipBuy(shopInfo, out curVipIndex, out nextVipIndex);
|
int canBuyCnt = 0;
|
int addBuyCnt = 0;
|
bool isLimitBuy = buyItem.CheckIsLimitBuyCnt(shopInfo, out canBuyCnt, out addBuyCnt);
|
bool isShowBuyPrice = true;
|
|
if (isVipBuy)
|
{
|
if (curVipIndex == -1 && nextVipIndex != -1)
|
{
|
shopItemCell.coinsIcon.gameObject.SetActive(false);
|
shopItemCell.vipText.gameObject.SetActive(true);
|
shopItemCell.vipText.text = Language.Get("StoreWin101", shopInfo.VIPLV[nextVipIndex]);
|
shopItemCell.sellImage.gameObject.SetActive(false);
|
shopItemCell.itemNameText.color = UIHelper.GetUIColor(TextColType.Red, true);
|
shopItemCell.vipText.color = UIHelper.GetUIColor(TextColType.Red, true);
|
isShowBuyPrice = false;
|
}
|
}
|
|
if (isShowBuyPrice)
|
{
|
shopItemCell.coinsIcon.gameObject.SetActive(true);
|
shopItemCell.vipText.gameObject.SetActive(false);
|
shopItemCell.sellImage.gameObject.SetActive(false);
|
|
shopItemCell.itemCell.countText.gameObject.SetActive(false);
|
if (canBuyCnt > 0)
|
{
|
shopItemCell.itemCell.countText.gameObject.SetActive(true);
|
BuyShopItemLimit shopItemLimit = model.GetBuyShopLimit((uint)shopInfo.ID);
|
int remainNum = canBuyCnt;
|
if (shopItemLimit != null)
|
{
|
remainNum = canBuyCnt - shopItemLimit.BuyCnt;
|
}
|
|
if (shopInfo.ShopType == (int)StoreFunc.MysteryStore)
|
{
|
shopItemCell.itemCell.countText.text = shopInfo.ItemCnt > 1 ? shopInfo.ItemCnt.ToString() : "";
|
}
|
else
|
{
|
var remainNumDescription = remainNum > 0 ? remainNum.ToString() : UIHelper.AppendColor(TextColType.Red, remainNum.ToString());
|
shopItemCell.itemCell.countText.text = StringUtility.Contact(remainNumDescription, "/", canBuyCnt);
|
}
|
|
if (remainNum > 0)
|
{
|
shopItemCell.sellImage.gameObject.SetActive(false);
|
}
|
else
|
{
|
shopItemCell.sellImage.gameObject.SetActive(true);
|
shopItemCell.stateImage.gameObject.SetActive(false);
|
}
|
}
|
|
shopItemCell.itemNameText.color = UIHelper.GetUIColor(config.ItemColor, true);
|
shopItemCell.vipText.color = UIHelper.GetUIColor(TextColType.Black, true);
|
}
|
|
shopItemCell.LoadGuidEffectCtrl(shopInfo.ID, shopId);
|
}
|
|
shopItemCell.ShopCellBtn.RemoveAllListeners();
|
shopItemCell.ShopCellBtn.AddListener(() =>
|
{
|
if (shopInfo.ID == shopId)
|
{
|
shopId = 0;
|
shopItemCell.LoadGuidEffectCtrl(shopInfo.ID, shopId);
|
}
|
model.CloseRedPoint(shopInfo);
|
model.OnClickShopCell(shopInfo);
|
});
|
}
|
else
|
{
|
cell.transform.GetChild(i).gameObject.SetActive(false);
|
}
|
}
|
}
|
|
private void OpenIntegralStore()
|
{
|
model.CloseAllRedpoint(StoreFunc.IntegralStore);
|
model.storeFuncType = StoreFunc.IntegralStore;
|
OnCreate();
|
UpdateRefreshTime();
|
functionOrder = m_IntegralStoreTitle.order;
|
}
|
|
//private void OpenBindGoldStore()
|
//{
|
// model.CloseAllRedpoint(StoreFunc.BindStore);
|
// model.storeFuncType = StoreFunc.BindStore;
|
// OnCreate();
|
// UpdateRefreshTime();
|
// functionOrder = m_BindStoreTitle.order;
|
//}
|
|
private void OpenStrengthStore()
|
{
|
model.CloseAllRedpoint(StoreFunc.GrowStrongerStore);
|
model.storeFuncType = StoreFunc.GrowStrongerStore;
|
OnCreate();
|
UpdateRefreshTime();
|
functionOrder = m_GrowStrongerStoreTitle.order;
|
}
|
|
private void OpenCommonStore()
|
{
|
model.CloseAllRedpoint(StoreFunc.CommonStore);
|
model.storeFuncType = StoreFunc.CommonStore;
|
OnCreate();
|
UpdateRefreshTime();
|
functionOrder = m_CommonStoreTitle.order;
|
}
|
|
private void OpenMysteryStore()
|
{
|
model.CloseAllRedpoint(StoreFunc.MysteryStore);
|
model.storeFuncType = StoreFunc.MysteryStore;
|
OnCreate();
|
UpdateRefreshTime();
|
functionOrder = m_WeekStoreTitle.order;
|
}
|
|
private void OpenDayStore()
|
{
|
model.CloseAllRedpoint(StoreFunc.DayStore);
|
model.storeFuncType = StoreFunc.DayStore;
|
OnCreate();
|
UpdateRefreshTime();
|
functionOrder = m_DayStoreTitle.order;
|
}
|
|
private void ViewAssistRecorders()
|
{
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.DungeonAssitCheckIn);
|
}
|
|
private void RefreshCommondities()
|
{
|
var config = ItemConfig.Get(GeneralDefine.mysteryShopRefreshItem);
|
if (model.isShowMysteryRefreshHint)
|
{
|
var own = packModel.GetItemCountByID(PackType.Item, GeneralDefine.mysteryShopRefreshItem);
|
var need = model.GetMysteryShopRefreshItemNeed();
|
var needMoney = need * GeneralDefine.mysteryShopRefreshItemValue;
|
var description1 = Language.Get("MysteryStore1", need);
|
|
ConfirmCancel.IconConfirmCancel(Language.Get("Mail101"), description1, GeneralDefine.mysteryShopRefreshItem,
|
own, need, Language.Get("MysteryStore2", needMoney), Language.Get("ConfirmCancel102"), (bool ok, bool isToggle) =>
|
{
|
if (ok)
|
{
|
model.RefreshMysteryShop();
|
}
|
model.isShowMysteryRefreshHint = !isToggle;
|
});
|
}
|
else
|
{
|
model.RefreshMysteryShop();
|
}
|
}
|
|
}
|
|
}
|
|
|
|
|