//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, June 11, 2019
|
//--------------------------------------------------------
|
|
using LitJson;
|
using vnxbqy.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
|
public class FaQiLVUPWin : ILWindow
|
{
|
Button preViewLeft;
|
Button preViewRight;
|
Text faqiName;
|
Text faqiRank;
|
Text fightPower;
|
RawImage faqi3D;
|
List<Text> attrNames = new List<Text>();
|
List<Text> nums = new List<Text>();
|
List<Text> addNums = new List<Text>();
|
IntensifySmoothSlider expSlider;
|
Text expNum;
|
ItemCell itemCell;
|
Text itemName;
|
Text useCnt;
|
ToggleButton autoBuy;
|
Button train;
|
Button autoTrain;
|
Button stopTrain;
|
Transform activeState;
|
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModelEx<StoreModel>(); } }
|
int selectFaqiLV = 1;
|
|
#region Built-in
|
protected override void BindController()
|
{
|
preViewLeft = proxy.GetWidgtEx<Button>("leftarrow");
|
preViewRight = proxy.GetWidgtEx<Button>("rightarrow");
|
faqiName = proxy.GetWidgtEx<Text>("name");
|
faqiRank = proxy.GetWidgtEx<Text>("rank");
|
fightPower = proxy.GetWidgtEx<Text>("fightPower");
|
faqi3D = proxy.GetWidgtEx<RawImage>("FaqiRawImg");
|
for (int i = 0; i < 5; i++)
|
{
|
attrNames.Add(proxy.GetWidgtEx<Text>("attrname" + i));
|
nums.Add(proxy.GetWidgtEx<Text>("num" + i));
|
addNums.Add(proxy.GetWidgtEx<Text>("addnum" + i));
|
}
|
expSlider = proxy.GetWidgtEx<IntensifySmoothSlider>("ExpSlider");
|
expNum = proxy.GetWidgtEx<Text>("ExpNum");
|
itemCell = proxy.GetWidgtEx<ItemCell>("ItemCell1");
|
itemName = proxy.GetWidgtEx<Text>("itemName");
|
useCnt = proxy.GetWidgtEx<Text>("useCnt");
|
autoBuy = proxy.GetWidgtEx<ToggleButton>("Toggle_Inevitable");
|
train = proxy.GetWidgtEx<Button>("TrainBtn_1");
|
autoTrain = proxy.GetWidgtEx<Button>("AutoTrainBtn");
|
stopTrain = proxy.GetWidgtEx<Button>("StopTrainBtn");
|
activeState = proxy.GetWidgtEx<Transform>("activeState");
|
}
|
|
protected override void AddListeners()
|
{
|
|
preViewLeft.SetListener(()=> {
|
if (selectFaqiLV <= 1) return;
|
selectFaqiLV--;
|
DisplayPreview();
|
});
|
preViewRight.SetListener(() => {
|
if (selectFaqiLV >= ILFaQiLVUpConfig.GetKeys().Count) return;
|
selectFaqiLV++;
|
DisplayPreview();
|
});
|
|
autoTrain.SetListener(AutoTrain);
|
stopTrain.SetListener(StopAuto);
|
autoBuy.SetListener(()=> {
|
autoBuy.isOn = !autoBuy.isOn;
|
StopAuto();
|
});
|
|
train.SetListener(TrainOne);
|
}
|
|
protected override void OnPreOpen()
|
{
|
FaQiLVUPModel.Instance.onFaqiUpdateEvent += OnFaqiUpdateEvent;
|
FaQiLVUPModel.Instance.onFaqiLVChangeEvent += OnFaqiLVChangeEvent;
|
packModel.refreshItemCountEvent += RefreshItemCount;
|
selectFaqiLV = FaQiLVUPModel.Instance.faqiLV;
|
Display();
|
}
|
protected override void OnPreClose()
|
{
|
FaQiLVUPModel.Instance.onFaqiUpdateEvent -= OnFaqiUpdateEvent;
|
FaQiLVUPModel.Instance.onFaqiLVChangeEvent -= OnFaqiLVChangeEvent;
|
packModel.refreshItemCountEvent -= RefreshItemCount;
|
}
|
|
#endregion
|
|
private void RefreshItemCount(PackType type, int index, int id)
|
{
|
if (id == FaQiLVUPModel.Instance.faqiLVUPItemID)
|
{
|
ShowItemUseCnt();
|
}
|
|
}
|
|
void Display()
|
{
|
ShowFaqiOperateInfo();
|
DisplayPreview();
|
|
ItemCellModel cellModel = new ItemCellModel(FaQiLVUPModel.Instance.faqiLVUPItemID, false, 1);
|
itemCell.Init(cellModel);
|
itemCell.countText.SetActiveIL(true);
|
itemCell.countText.text = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID).ToString();
|
var itemConfig = ItemConfig.Get(FaQiLVUPModel.Instance.faqiLVUPItemID);
|
itemName.text = UIHelper.AppendColor(itemConfig.ItemColor, itemConfig.ItemName);
|
itemCell.button.SetListener(() =>
|
{
|
ItemTipUtility.Show(FaQiLVUPModel.Instance.faqiLVUPItemID);
|
});
|
}
|
|
|
void DisplayPreview()
|
{
|
ILFaQiLVUpConfig selectFaqiConfig = ILFaQiLVUpConfig.Get(selectFaqiLV);
|
faqiName.text = selectFaqiConfig.Name;
|
faqiRank.text = Language.Get("FuncRankName", selectFaqiLV);
|
string pathName;
|
if (AssetSource.uiFromEditor)
|
{
|
pathName = selectFaqiConfig.PathName + "/";
|
}
|
else
|
{
|
pathName = selectFaqiConfig.PathName.ToLower();
|
}
|
|
if (!faqi3D.gameObject.activeSelf)
|
{
|
faqi3D.SetActiveIL(true);
|
}
|
UI3DTreasureExhibition.Instance.ShowFaQiModel(pathName, selectFaqiConfig.Model, faqi3D, selectFaqiConfig.EffectID);
|
activeState.SetActiveIL(selectFaqiLV > FaQiLVUPModel.Instance.faqiLV);
|
}
|
|
void ShowFaqiOperateInfo()
|
{
|
ShowAttrText();
|
DisplayExpSlider();
|
ShowItemUseCnt();
|
ShowButton();
|
}
|
private void ShowAttrText()
|
{
|
var nextAttr = FaQiLVUPModel.Instance.GetNextTrainAttr();
|
ClearAttrText();
|
int showIndex = 0;
|
for (int i = 0; i < FaQiLVUPModel.Instance.attrSort.Count; i++)
|
{
|
var attrID = FaQiLVUPModel.Instance.attrSort[i];
|
var attrValue = FaQiLVUPModel.Instance.faqiLVUPAttr.ContainsKey(attrID) ? FaQiLVUPModel.Instance.faqiLVUPAttr[attrID] : 0;
|
attrNames[showIndex].text = PlayerPropertyConfig.Get(attrID).ShowName;
|
nums[showIndex].text = PlayerPropertyConfig.GetValueDescription(attrID, attrValue);
|
if (nextAttr.ContainsKey(attrID))
|
{
|
addNums[i].SetActiveIL(true);
|
addNums[showIndex].text = "+" + PlayerPropertyConfig.GetValueDescription(attrID, nextAttr[attrID]);
|
}
|
|
showIndex++;
|
}
|
|
fightPower.text = UIHelper.ReplaceLargeArtNum(UIHelper.GetFightPower(FaQiLVUPModel.Instance.faqiLVUPAttr));
|
}
|
|
private void ClearAttrText()
|
{
|
for (int i = 0; i < attrNames.Count; i++)
|
{
|
attrNames[i].text = string.Empty;
|
nums[i].text = string.Empty;
|
addNums[i].text = string.Empty;
|
addNums[i].SetActiveIL(false);
|
|
}
|
|
}
|
void OnFaqiUpdateEvent()
|
{
|
isHorseUpdate = true;
|
ShowFaqiOperateInfo();
|
waitServer = false;
|
}
|
|
void OnFaqiLVChangeEvent()
|
{
|
selectFaqiLV = FaQiLVUPModel.Instance.faqiLV;
|
DisplayPreview();
|
StopAuto();
|
WindowCenter.Instance.OpenIL<FaQiLVUPSuccessWin>();
|
}
|
|
private void ShowItemUseCnt()
|
{
|
int number = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID);
|
int useCount = FaQiLVUPModel.Instance.GetTrainCount();
|
useCnt.text = UIHelper.AppendColor(useCount > number ? TextColType.Red : TextColType.Green, "x" + useCount);
|
itemCell.countText.text = number.ToString();
|
}
|
|
private void ShowButton()
|
{
|
if (autoCnt > 0)
|
return;
|
train.SetActiveIL(true);
|
autoTrain.SetActiveIL(true);
|
stopTrain.SetActiveIL(false);
|
|
if (FaQiLVUPModel.Instance.GetTrainCount() == 0)
|
{
|
train.SetActiveIL(false);
|
autoTrain.SetActiveIL(false);
|
stopTrain.SetActiveIL(false);
|
|
}
|
}
|
|
private void ShowButtonState(bool autoOn)
|
{
|
if (FaQiLVUPModel.Instance.GetTrainCount() == 0)
|
{
|
train.SetActiveIL(false);
|
autoTrain.SetActiveIL(false);
|
stopTrain.SetActiveIL(false);
|
}
|
else
|
{
|
autoTrain.SetActiveIL(!autoOn);
|
stopTrain.SetActiveIL(autoOn);
|
}
|
autoCnt = 0;
|
}
|
|
private int GetNextLVNeedCnt()
|
{
|
var config = ILFaQiLVUpConfig.Get(FaQiLVUPModel.Instance.faqiLV);
|
int useCnt = FaQiLVUPModel.Instance.GetTrainCount();
|
int useAllCnt = Mathf.CeilToInt((config.NeedEatCount - FaQiLVUPModel.Instance.eatItemCount) / (float)useCnt) * useCnt;
|
|
var nextConfig = ILFaQiLVUpConfig.Get(FaQiLVUPModel.Instance.faqiLV + 1);
|
if (nextConfig.NeedEatCount == 0)
|
{
|
// 下一阶满级,只扣剩余所需不超过单次的材料数量
|
useAllCnt = config.NeedEatCount - FaQiLVUPModel.Instance.eatItemCount;
|
}
|
|
return useAllCnt;
|
}
|
|
|
private void AutoTrain()
|
{
|
autoCnt = 0;
|
int number = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID);
|
int useCnt = FaQiLVUPModel.Instance.GetTrainCount();
|
|
if (useCnt == 0)
|
{
|
ScrollTip.ShowTip(Language.Get("Z1029"));
|
return;
|
}
|
int maxNeedCnt = GetNextLVNeedCnt();
|
//材料足够升阶或不勾选自动购买的情况
|
if (number >= maxNeedCnt || !autoBuy.isOn)
|
{
|
if (useCnt > number)
|
{
|
ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
|
return;
|
}
|
ShowButtonState(true);
|
SnxxzGame.Instance.StartCoroutine(OnAutoTrain());
|
return;
|
}
|
|
//花仙玉购买限购商品
|
var config = StoreConfig.Get(FaQiLVUPModel.Instance.faqiLVUPStoreID);
|
int needBuyCnt = maxNeedCnt - number;
|
int useMoney = config.MoneyNumber * needBuyCnt;
|
if ((int)UIHelper.GetMoneyCnt(1) < useCnt * config.MoneyNumber && number < useCnt)
|
{
|
//只处理最小购买单位
|
SysNotifyMgr.Instance.ShowTip("LackMoney", 1);
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
return;
|
}
|
|
ConfirmCancel.ShowPopConfirm(
|
Language.Get("Mail101"),
|
Language.Get("FaQiWin_4", FaQiLVUPModel.Instance.faqiLV + 1, needBuyCnt),
|
|
(bool _ok) =>
|
{
|
if (_ok)
|
{
|
ShowButtonState(true);
|
SnxxzGame.Instance.StartCoroutine(OnAutoTrain());
|
}
|
}
|
);
|
}
|
|
bool waitServer = false; //等待服务器回报后才可继续发包
|
int autoCnt = 0; //用于发包数量加速
|
IEnumerator OnAutoTrain()
|
{
|
int useSingleCnt = 0;
|
int useMultiCnt = 0;
|
int number = 0;
|
while (true)
|
{
|
//不超过阶的 仙玉消耗
|
//等待服务端回包
|
if (waitServer)
|
{
|
yield return new WaitForSeconds(0.1f);
|
continue;
|
}
|
autoCnt++;
|
useSingleCnt = FaQiLVUPModel.Instance.GetTrainCount();
|
useMultiCnt = Mathf.Min(100, Mathf.Max(autoCnt - 3, 1)) * useSingleCnt;
|
LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(13, FaQiLVUPModel.Instance.faqiLVUPItemID, useMultiCnt, 1, 0);
|
if (useMultiCnt > GetNextLVNeedCnt())
|
{
|
useMultiCnt = GetNextLVNeedCnt();
|
}
|
var config = StoreConfig.Get(FaQiLVUPModel.Instance.faqiLVUPStoreID);
|
int needBuyCnt = 0;
|
//优先消耗完身上物品再扣钱
|
number = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID);
|
if (useMultiCnt > number)
|
{
|
if (useSingleCnt > number)
|
{
|
if (autoBuy.isOn)
|
{
|
// 多次购买 或者补足一次
|
needBuyCnt = number == 0 ? useMultiCnt : useSingleCnt - number;
|
int remainNum = 10000000; //没有限购
|
//storeModel.TryGetIsSellOut(config, out remainNum);
|
if (remainNum == 0 || useSingleCnt > remainNum)
|
{
|
//限购买完 或不够1次的情况
|
SysNotifyMgr.Instance.ShowTip("ShopBuyLimit");
|
yield break;
|
}
|
if (needBuyCnt > remainNum)
|
{
|
//多倍购买不够改成1倍购买
|
needBuyCnt = useSingleCnt;
|
useMultiCnt = useSingleCnt;
|
autoCnt = 1;
|
}
|
}
|
else
|
{
|
ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
|
ShowButtonState(false);
|
yield break;
|
}
|
}
|
|
if (needBuyCnt < useSingleCnt)
|
{
|
useMultiCnt = useSingleCnt;
|
autoCnt = 1;
|
}
|
}
|
|
if (needBuyCnt > 0)
|
{
|
|
if ((int)UIHelper.GetMoneyCnt(1) < needBuyCnt * config.MoneyNumber)
|
{
|
SysNotifyMgr.Instance.ShowTip("LackMoney", 1);
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
ShowButtonState(false);
|
yield break;
|
}
|
}
|
FaQiLVUPModel.Instance.UpgradeFaqi(useMultiCnt, autoBuy.isOn);
|
|
waitServer = true;
|
yield return new WaitForSeconds(0.5f);
|
}
|
}
|
|
private void StopAuto()
|
{
|
autoCnt = 0;
|
waitServer = false;
|
SnxxzGame.Instance.StopAllCoroutines();
|
ShowButtonState(false);
|
}
|
|
|
void TrainOne()
|
{
|
var singleCnt = FaQiLVUPModel.Instance.GetTrainCount();
|
if (singleCnt == 0)
|
{
|
ScrollTip.ShowTip(Language.Get("Z1029"));
|
return;
|
}
|
|
var hasCnt = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID);
|
|
if (!autoBuy.isOn && singleCnt > hasCnt)
|
{
|
ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
|
return;
|
}
|
LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(13, FaQiLVUPModel.Instance.faqiLVUPItemID, singleCnt,1, 0);
|
//var config = StoreConfig.Get(FaQiLVUPModel.Instance.faqiLVUPStoreID);
|
int remainNum = 10000000; //没有限购
|
//storeModel.TryGetIsSellOut(config, out remainNum);
|
|
if (singleCnt > (hasCnt + remainNum))
|
{
|
//限购买完 或不够1次的情况
|
SysNotifyMgr.Instance.ShowTip("ShopBuyLimit");
|
return;
|
}
|
|
FaQiLVUPModel.Instance.UpgradeFaqi(singleCnt, autoBuy.isOn);
|
}
|
|
bool isHorseUpdate = false; // 用于进度条更新
|
private void DisplayExpSlider()
|
{
|
var config = ILFaQiLVUpConfig.Get(FaQiLVUPModel.Instance.faqiLV);
|
|
if (config.NeedEatCount == 0)
|
{
|
expNum.text = Language.Get("Z1029");
|
expSlider.stage = FaQiLVUPModel.Instance.faqiLV;
|
expSlider.value = 1f;
|
expSlider.delay = 0f;
|
expSlider.ResetStage();
|
}
|
else
|
{
|
int exp = FaQiLVUPModel.Instance.eatItemCount * FaQiLVUPModel.onceItemExp;
|
int expMax = config.NeedEatCount * FaQiLVUPModel.onceItemExp;
|
expNum.text = exp + "/" + expMax;
|
expSlider.delay = isHorseUpdate ? 0.1f : 0f;
|
expSlider.stage = FaQiLVUPModel.Instance.faqiLV;
|
expSlider.value = (float)Math.Round((float)exp / expMax, 2, MidpointRounding.AwayFromZero);
|
isHorseUpdate = false;
|
}
|
}
|
}
|