//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, January 05, 2018
|
//--------------------------------------------------------
|
|
using vnxbqy.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
//坐骑面板
|
namespace vnxbqy.UI
|
{
|
|
public class MountWin : Window
|
{
|
[SerializeField] Text HorseName;
|
[SerializeField] Text HorseRank;
|
[SerializeField] Button ChangeLookLib;
|
[SerializeField] Text FightPower;
|
[SerializeField] RawImage Hosrse3D;
|
[SerializeField] Button UseModel;
|
[SerializeField] Button CancelHorseClothe; //取消幻化并使用原阶模型
|
[SerializeField] Image HorseState; //骑乘中或未激活
|
[SerializeField] Text HorseStateText; //骑乘中或未激活
|
[SerializeField] Button Left;
|
[SerializeField] Button Right;
|
[SerializeField] Button MountHunBtn;//坐骑兽魂按钮
|
|
[SerializeField] UIEffect m_UieffectLVUp;//坐骑升级特效
|
[SerializeField] PositionTween m_PositionTweenLVUp;
|
|
[SerializeField] List<Text> AttrNameList;
|
[SerializeField] List<Text> AttrValueList;
|
[SerializeField] List<Text> AttrAddValueList;
|
|
|
[SerializeField] ItemCell UseItem;
|
[SerializeField] Text UseItemName;
|
[SerializeField] Button m_TrainBtn_1;//坐骑驯养
|
[SerializeField] Text m_TrainUseCnt;
|
[SerializeField] Button m_AutoTrainBtn;//自动驯养
|
[SerializeField] Button m_StopTrainBtn;//停止驯养
|
|
[SerializeField] ToggleButton m_Inevitable;
|
|
[SerializeField] UIEffect effectSlider; //进度条
|
[SerializeField] Text Exp;
|
[SerializeField] IntensifySmoothSlider ExpSlider;
|
[SerializeField] Button UseFoster;
|
|
#region Built-in
|
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
MountModel mountModel { get { return ModelCenter.Instance.GetModel<MountModel>(); } }
|
RidingAndPetActivationModel ridingAndPetActivationModel { get { return ModelCenter.Instance.GetModel<RidingAndPetActivationModel>(); } }
|
|
int m_ShowHorseLV = 1; // 当前显示的马匹阶
|
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
MountHunBtn.AddListener(OnClickMountHunButton);
|
UseFoster.SetListener(() => {
|
if(FosterModel.Instance.CheckHorseOpen(true))
|
{
|
WindowJumpMgr.Instance.WindowJumpToEx("FosterWin");
|
}
|
});
|
ChangeLookLib.SetListener(()=> {
|
WindowJumpMgr.Instance.ClearJumpData();
|
WindowCenter.Instance.Open<MountSkinWin>();
|
WindowCenter.Instance.Close<PetWin>();
|
});
|
Left.SetListener(()=> {
|
m_ShowHorseLV = m_ShowHorseLV - 1;
|
ShowHorse();
|
});
|
Right.SetListener(() => {
|
if (m_ShowHorseLV - mountModel.HorseLV > 2)
|
{
|
ScrollTip.ShowTip(Language.Get("HorseLVUPCanSee"));
|
return;
|
}
|
m_ShowHorseLV = m_ShowHorseLV + 1;
|
ShowHorse();
|
});
|
UseModel.SetListener(()=> {
|
if (m_ShowHorseLV > mountModel.HorseLV)
|
{
|
ScrollTip.ShowTip(Language.Get("HorseLVUPCanSee"));
|
return;
|
}
|
mountModel.AppearanceSwitch((byte)m_ShowHorseLV, 1);
|
ScrollTip.ShowTip(Language.Get("Z1062")); //外观切换成功
|
});
|
CancelHorseClothe.SetListener(() => {
|
mountModel.AppearanceSwitch((byte)m_ShowHorseLV, 1);
|
ScrollTip.ShowTip(Language.Get("Z1062")); //外观切换成功
|
});
|
|
m_TrainBtn_1.SetListener(() => {
|
if (mountModel.GetTrainCount() == 0)
|
{
|
ScrollTip.ShowTip(Language.Get("Z1029"));
|
return;
|
}
|
|
if (!m_Inevitable.isOn && mountModel.GetTrainCount() > playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId))
|
{
|
ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
|
return;
|
}
|
|
mountModel.MountDanUse(mountModel.GetTrainCount(), m_Inevitable.isOn);
|
});
|
|
m_AutoTrainBtn.SetListener(AutoTrain);
|
|
m_StopTrainBtn.SetListener(()=> {
|
StopAuto();
|
});
|
|
m_Inevitable.SetListener(()=> {
|
m_Inevitable.isOn = !m_Inevitable.isOn;
|
StopAuto();
|
});
|
}
|
|
private void StopAuto()
|
{
|
autoCnt = 0;
|
waitServer = false;
|
StopCoroutine("OnAutoTrain");
|
ShowButtonState(false);
|
}
|
|
|
protected override void OnPreOpen()
|
{
|
m_ShowHorseLV = mountModel.HorseLV; //默认当前阶
|
mountModel.onHorseInfoUpdate += HorseInfoUpdate;
|
mountModel.onHorseLVUP += HorseLVUP;
|
mountModel.HorseExpItemRefresh += HorseExpItemRefresh;
|
MountModel.Event_MountAlteration += ShowHorse;
|
ShowHorse();
|
DisplayHorseInfo();
|
|
ItemCellModel cellModel = new ItemCellModel(mountModel.horseUpItemId, false, 1);
|
UseItem.Init(cellModel);
|
UseItem.countText.SetActive(true);
|
UseItem.countText.text = playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId).ToString();
|
var itemConfig = ItemConfig.Get(mountModel.horseUpItemId);
|
UseItemName.text = UIHelper.AppendColor(itemConfig.ItemColor, itemConfig.ItemName);
|
UseItem.button.SetListener(() =>
|
{
|
ItemTipUtility.Show(mountModel.horseUpItemId);
|
});
|
mountModel.MountStoneRed();
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
}
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
mountModel.onHorseInfoUpdate -= HorseInfoUpdate;
|
mountModel.onHorseLVUP -= HorseLVUP;
|
MountModel.Event_MountAlteration -= ShowHorse;
|
mountModel.HorseExpItemRefresh -= HorseExpItemRefresh;
|
|
StopAuto();
|
UI3DModelExhibition.Instance.StopShow();
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
#endregion
|
|
private void RefreshLeftRightBtn()
|
{
|
|
}
|
|
bool isHorseUpdate = false; // 用于进度条更新
|
private void HorseInfoUpdate()
|
{
|
isHorseUpdate = true;
|
effectSlider.Play();
|
DisplayHorseInfo();
|
waitServer = false;
|
}
|
|
private void DisplayHorseInfo()
|
{
|
ShowAttrText();
|
|
HorseExpItemRefresh();
|
|
ShowButton();
|
|
DisplayExpSlider();
|
}
|
|
private void HorseExpItemRefresh()
|
{
|
ShowItemUseCnt();
|
ShowButton();
|
}
|
|
private void ShowItemUseCnt()
|
{
|
int number = playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId);
|
int useCnt = mountModel.GetTrainCount();
|
m_TrainUseCnt.text = UIHelper.AppendColor(useCnt > number ? TextColType.Red : TextColType.Green, "x" + mountModel.GetTrainCount());
|
UseItem.countText.text = number.ToString();
|
}
|
|
private void OnClickMountHunButton()
|
{
|
StopAuto();
|
WindowCenter.Instance.Open<MountStoneTipsWin>();
|
}
|
|
private void ShowButton()
|
{
|
if (autoCnt > 0)
|
return;
|
m_TrainBtn_1.SetActive(true);
|
m_AutoTrainBtn.SetActive(true);
|
m_StopTrainBtn.SetActive(false);
|
|
if (mountModel.GetTrainCount() == 0)
|
{
|
m_TrainBtn_1.SetActive(false);
|
m_AutoTrainBtn.SetActive(false);
|
m_StopTrainBtn.SetActive(false);
|
|
}
|
}
|
|
// 幻化模型替换当前阶模型,左右按钮改变m_ShowHorseLV
|
private void ShowHorse()
|
{
|
var horseInfo = HorseLVUpConfig.Get(m_ShowHorseLV);
|
if (horseInfo == null)
|
{
|
//防止意外情况,正常不会出现
|
m_ShowHorseLV = mountModel.HorseLV;
|
horseInfo = HorseLVUpConfig.Get(m_ShowHorseLV);
|
}
|
int curShowHorseID = horseInfo.HorseID;
|
HorseName.text = HorseConfig.Get(horseInfo.HorseID).Name;
|
HorseRank.text = Language.Get("FuncRankName", m_ShowHorseLV);
|
|
if (!Hosrse3D.gameObject.activeSelf)
|
{
|
Hosrse3D.SetActive(true);
|
}
|
|
int model3D = horseInfo.HorseID;
|
if (mountModel.HorseIDNow != 0 && mountModel.HorseLV == m_ShowHorseLV && !mountModel.RankHorseIDList.Contains(mountModel.HorseIDNow))
|
{
|
//当前阶有幻化情况下替换幻化模型
|
model3D = mountModel.HorseIDNow;
|
}
|
|
HorseConfig _model = HorseConfig.Get(model3D);
|
UI3DModelExhibition.Instance.ShowHourse(_model.Model, Hosrse3D);
|
if (UI3DModelExhibition.Instance.NpcModelHorse != null)
|
{
|
var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.Play(GAStaticDefine.State_Dance);
|
|
}
|
}
|
Left.SetActive(true);
|
Right.SetActive(true);
|
if (m_ShowHorseLV == 1)
|
{
|
Left.SetActive(false);
|
}
|
if (HorseLVUpConfig.Get(m_ShowHorseLV + 1) == null)
|
{
|
Right.SetActive(false);
|
}
|
|
UseModel.SetActive(false);
|
CancelHorseClothe.SetActive(false);
|
HorseState.SetActive(false);
|
if (mountModel.RankHorseIDList.Contains(mountModel.HorseIDNow))
|
{
|
if (curShowHorseID == mountModel.HorseIDNow)
|
{
|
HorseState.SetActive(true);
|
HorseStateText.text = UIHelper.AppendColor(TextColType.NavyBrown, Language.Get("Petwin8"));
|
}
|
else
|
{
|
UseModel.SetActive(true);
|
}
|
}
|
else
|
{
|
//幻化情况
|
if (mountModel.HorseLV == m_ShowHorseLV)
|
{
|
CancelHorseClothe.SetActive(true);
|
}
|
else
|
{
|
UseModel.SetActive(true);
|
}
|
}
|
|
if (m_ShowHorseLV > mountModel.HorseLV)
|
{
|
UseModel.SetActive(false);
|
HorseState.SetActive(true);
|
HorseStateText.text = UIHelper.AppendColor(TextColType.Red, Language.Get("MountWin113"));
|
}
|
|
}
|
|
private void ShowAttrText()
|
{
|
ClearAttrText();
|
Dictionary<int, int> allAttr = mountModel.GetHorseAllAttr();
|
Dictionary<int, int> nextAttr = mountModel.GetNextTrainAttr();
|
int showIndex = 0;
|
foreach (var attrID in mountModel.HorseAttrSort)
|
{
|
if (!allAttr.ContainsKey(attrID) && !nextAttr.ContainsKey(attrID))
|
{
|
continue;
|
}
|
|
AttrNameList[showIndex].text = PlayerPropertyConfig.Get(attrID).ShowName;
|
AttrValueList[showIndex].text = allAttr.ContainsKey(attrID) ? PlayerPropertyConfig.GetValueDescription(attrID, allAttr[attrID]) : PlayerPropertyConfig.GetValueDescription(attrID, 0);
|
AttrAddValueList[showIndex].text = nextAttr.ContainsKey(attrID) ? "+" + PlayerPropertyConfig.GetValueDescription(attrID, nextAttr[attrID]) : (mountModel.GetTrainCount() == 0 ? string.Empty : "+" + PlayerPropertyConfig.GetValueDescription(attrID, 0));
|
showIndex++;
|
}
|
|
FightPower.text = (UIHelper.GetFightPower(allAttr) + mountModel.GetMountSkinAddFightPower()).ToString() ;
|
}
|
|
private void ClearAttrText()
|
{
|
for (int i = 0; i < AttrNameList.Count; i++)
|
{
|
AttrNameList[i].text = string.Empty;
|
AttrValueList[i].text = string.Empty;
|
AttrAddValueList[i].text = string.Empty;
|
|
}
|
|
}
|
|
private void HorseLVUP()
|
{
|
if (!m_UieffectLVUp.IsPlaying)
|
{
|
m_UieffectLVUp.Play();
|
m_PositionTweenLVUp.Play();
|
}
|
m_ShowHorseLV = mountModel.HorseLV;
|
mountModel.AppearanceSwitch((byte)mountModel.HorseLV, 1);
|
ScrollTip.ShowTip(Language.Get("Z1062")); //外观切换成功
|
ShowHorse();
|
StopAuto();
|
//WindowCenter.Instance.Open<HorseLvUpWin>();
|
ridingAndPetActivationModel.RidingAndPetActivationSet(RidingAndPetActivation.MountRankUp, HorseLVUpConfig.Get(m_ShowHorseLV).HorseID);
|
|
}
|
|
|
private void DisplayExpSlider()
|
{
|
var config = HorseLVUpConfig.Get(mountModel.HorseLV);
|
|
if (config.NeedEatCount == 0)
|
{
|
Exp.text = Language.Get("Z1029");
|
ExpSlider.stage = mountModel.HorseLV;
|
ExpSlider.value = 1f;
|
ExpSlider.delay = 0f;
|
ExpSlider.ResetStage();
|
}
|
else
|
{
|
int exp = mountModel.HorseEatCount * mountModel.HorseDanExp;
|
int expMax = config.NeedEatCount * mountModel.HorseDanExp;
|
Exp.text = exp + "/" + expMax;
|
ExpSlider.delay = isHorseUpdate ? 0.1f : 0f;
|
ExpSlider.stage = mountModel.HorseLV;
|
ExpSlider.value = (float)Math.Round((float)exp / expMax, 2, MidpointRounding.AwayFromZero);
|
isHorseUpdate = false;
|
}
|
}
|
|
private void ShowButtonState(bool autoOn)
|
{
|
if (mountModel.GetTrainCount() == 0)
|
{
|
m_TrainBtn_1.SetActive(false);
|
m_AutoTrainBtn.SetActive(false);
|
m_StopTrainBtn.SetActive(false);
|
}
|
else
|
{
|
m_AutoTrainBtn.SetActive(!autoOn);
|
m_StopTrainBtn.SetActive(autoOn);
|
}
|
autoCnt = 0;
|
}
|
|
|
private void AutoTrain()
|
{
|
autoCnt = 0;
|
int number = playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId);
|
int useCnt = mountModel.GetTrainCount();
|
|
if (useCnt == 0)
|
{
|
ScrollTip.ShowTip(Language.Get("Z1029"));
|
return;
|
}
|
|
int maxNeedCnt = GetNextLVNeedCnt();
|
//材料足够升阶或不勾选自动购买的情况
|
if (number >= maxNeedCnt || !m_Inevitable.isOn)
|
{
|
if (useCnt > number)
|
{
|
ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
|
return;
|
}
|
ShowButtonState(true);
|
StartCoroutine("OnAutoTrain");
|
return;
|
}
|
|
//花仙玉购买
|
var config = StoreConfig.GetStoreCfg(mountModel.horseUpItemId, 1, 1);
|
int needBuyCnt = maxNeedCnt - number;
|
int useMoney = config.MoneyNumber * needBuyCnt;
|
LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(52, 1, useMoney, 2, 0);
|
if (PlayerDatas.Instance.baseData.diamond < useCnt * config.MoneyNumber && number < useCnt)
|
{
|
//只处理最小购买单位
|
SysNotifyMgr.Instance.ShowTip("GoldErr");
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
return;
|
}
|
|
ConfirmCancel.ShowPopConfirm(
|
Language.Get("Mail101"),
|
Language.Get("Z1032", mountModel.HorseLV+1, needBuyCnt),
|
|
(bool _ok) =>
|
{
|
if (_ok)
|
{
|
ShowButtonState(true);
|
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 = mountModel.GetTrainCount();
|
useMultiCnt = Math.Min(200, Math.Max(autoCnt - 3, 1)) * useSingleCnt;
|
if (useMultiCnt > GetNextLVNeedCnt())
|
{
|
useMultiCnt = GetNextLVNeedCnt();
|
}
|
|
int needBuyCnt = 0;
|
//优先消耗完身上物品再扣仙玉
|
number = playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId);
|
if (useMultiCnt > number)
|
{
|
if (useSingleCnt > number)
|
{
|
if (m_Inevitable.isOn)
|
{
|
// 多次购买 或者补足一次
|
needBuyCnt = number == 0 ? useMultiCnt : useSingleCnt - number;
|
}
|
else
|
{
|
ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
|
ShowButtonState(false);
|
yield break;
|
}
|
}
|
if (needBuyCnt < useSingleCnt)
|
{
|
useMultiCnt = useSingleCnt;
|
autoCnt = 1;
|
}
|
}
|
|
if (needBuyCnt > 0)
|
{
|
var config = StoreConfig.GetStoreCfg(mountModel.horseUpItemId, 1, 1);
|
if (PlayerDatas.Instance.baseData.diamond < needBuyCnt * config.MoneyNumber)
|
{
|
SysNotifyMgr.Instance.ShowTip("GoldErr");
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
ShowButtonState(false);
|
yield break;
|
}
|
}
|
mountModel.MountDanUse(useMultiCnt, m_Inevitable.isOn);
|
|
waitServer = true;
|
yield return new WaitForSeconds(0.5f);
|
}
|
}
|
|
|
private int GetNextLVNeedCnt()
|
{
|
var config = HorseLVUpConfig.Get(mountModel.HorseLV);
|
int useCnt = mountModel.GetTrainCount();
|
int useAllCnt = (int)Math.Ceiling((config.NeedEatCount - mountModel.HorseEatCount) / (float)useCnt) * useCnt;
|
|
var nextConfig = HorseLVUpConfig.Get(mountModel.HorseLV + 1);
|
if (nextConfig.NeedEatCount == 0)
|
{
|
// 下一阶满级,只扣剩余所需不超过单次的材料数量
|
useAllCnt = config.NeedEatCount - mountModel.HorseEatCount;
|
}
|
|
return useAllCnt;
|
}
|
|
}
|
}
|