//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, February 28, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class EquipStarWin : Window
|
{
|
[SerializeField] RectTransform m_LevelContainer;
|
[SerializeField] ScrollRect m_LevelScrollRect;
|
[SerializeField] RectTransform m_OperateContainer;
|
[SerializeField] RectTransform m_EmptyContainer;
|
[SerializeField] Star[] m_Stars;
|
[SerializeField] ItemCell m_TargetEquip;
|
[SerializeField] Text m_EquipStar;
|
[SerializeField] EquipStarUpgradeSpecialMaterialBehaviour m_SpecialMaterial1;
|
[SerializeField] EquipStarUpgradeSpecialMaterialBehaviour m_SpecialMaterial2;
|
|
[SerializeField] RectTransform m_EmptyHint;
|
[SerializeField] RectTransform m_PropertyDetails;
|
[SerializeField] BaseProperty[] m_BasePropertys;
|
[SerializeField] Text[] m_LevelUpPropertys;
|
[SerializeField] Button m_StarUpgrade;
|
[SerializeField] RectTransform m_MaxStarLevelHint;
|
[SerializeField] Button m_Preview;
|
|
[SerializeField] ToggleButton m_Auto;
|
[SerializeField] Text m_AutoMoney;
|
[SerializeField] RectTransform m_AutoContainer;
|
|
List<EquipStarLevelSelectBehaviour> levelBehaviours = new List<EquipStarLevelSelectBehaviour>();
|
int curTime = 0;
|
|
EquipStarModel model { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
EquipStarEffectTipModel starEffectTipModel { get { return ModelCenter.Instance.GetModel<EquipStarEffectTipModel>(); } }
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
|
|
#region Built-in
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void AddListeners()
|
{
|
m_StarUpgrade.SetListener(StarUpgrade);
|
m_Preview.SetListener(() =>
|
{
|
var equipStarEffectTipModel = ModelCenter.Instance.GetModel<EquipStarEffectTipModel>();
|
equipStarEffectTipModel.Preview(new Int2(model.selectedLevel.value, model.selectedPlace.value));
|
});
|
m_Auto.SetListener(ShowAuto);
|
}
|
|
private void ShowAuto()
|
{
|
m_Auto.isOn = !m_Auto.isOn;
|
model.autoBuy.value = -1;
|
}
|
|
public void ShowAutoText(int money)
|
{
|
var color = PlayerDatas.Instance.baseData.bindDiamond >= money ? TextColType.Green : TextColType.Red;
|
m_AutoMoney.text = Language.Get("StartUpAutoBuy", UIHelper.AppendColor(color, money.ToString(), true));
|
|
}
|
|
|
|
|
protected override void OnPreOpen()
|
{
|
DTCB511_tagGCEquipStarAutoBuyCostInfo.QueryAutoStarEvent += QueryAutoStarEvent;
|
storeModel.RefreshBuyResultEvent += OnItemCountRefresh;
|
if (model.selectedLevel.value == 0)
|
{
|
Int2 equipPosition;
|
if (model.jumpEquipPos != Int2.zero)
|
{
|
equipPosition = model.jumpEquipPos;
|
model.jumpEquipPos = Int2.zero;
|
}
|
else
|
{
|
equipPosition = model.GetRecommendEquipPosition();
|
}
|
model.SelectLevel(equipPosition.x);
|
model.SelectPlace(equipPosition);
|
}
|
|
DisplayBaseInfo();
|
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
storeModel.RefreshBuyResultEvent -= OnItemCountRefresh;
|
DTCB511_tagGCEquipStarAutoBuyCostInfo.QueryAutoStarEvent -= QueryAutoStarEvent;
|
|
}
|
|
protected override void OnAfterClose()
|
{
|
model.ResetOperateParams();
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
DisplayDynamicInfo(true);
|
}
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
DisplayDynamicInfo(false);
|
}
|
|
#endregion
|
|
void QueryAutoStarEvent(HB511_tagGCEquipStarAutoBuyCostInfo pack)
|
{
|
if (pack.ClassLV != model.selectedLevel.value) return;
|
if (pack.EquipPlace != model.selectedPlace.value) return;
|
var equipPosition = new Int2(model.selectedLevel.value, model.selectedPlace.value);
|
var currentStarLevel = model.GetEquipStarLevel(equipPosition);
|
if (pack.CurStar != currentStarLevel) return;
|
|
model.autoBuy.value = pack.CurRate >= 100 ? (int)pack.AutoBuyCostMoney : -2;
|
model.autoBuy.dirty = true;
|
//model.starUpgradeProbability.value = pack.CurRate;
|
}
|
|
private void OnItemCountRefresh(int index)
|
{
|
var equipPosition = new Int2(model.selectedLevel.value, model.selectedPlace.Fetch());
|
var currentStarLevel = model.GetEquipStarLevel(equipPosition);
|
DisplayMaterialSlots(equipPosition, currentStarLevel);
|
}
|
|
|
|
private void DisplayBaseInfo()
|
{
|
CreateLevelBehaviours();
|
}
|
|
|
private void DisplayDynamicInfo(bool force)
|
{
|
if (force || model.selectedLevel.dirty)
|
{
|
DisplayCandidateSlots(model.selectedLevel.Fetch(), force);
|
}
|
|
if (force || model.selectedPlace.dirty)
|
{
|
model.autoBuy.dirty = true;
|
var place = model.selectedPlace.Fetch();
|
if (place == 0)
|
{
|
m_OperateContainer.SetActive(false);
|
m_EmptyContainer.SetActive(true);
|
}
|
else
|
{
|
var currentStarLevel = 0;
|
var equipPosition = new Int2(model.selectedLevel.value, place);
|
m_OperateContainer.SetActive(true);
|
m_EmptyContainer.SetActive(false);
|
var equipGuid = equipModel.GetEquip(equipPosition);
|
var equip = packModel.GetItemByGuid(equipGuid);
|
if (equip != null)
|
{
|
m_TargetEquip.SetActive(true);
|
m_TargetEquip.Init(equip);
|
m_TargetEquip.button.SetListener(ViewEquipTip);
|
currentStarLevel = model.GetEquipStarLevel(equipPosition);
|
|
m_EquipStar.SetActive(true);
|
m_EquipStar.text = currentStarLevel >= 1 ? Language.Get("EquipStarLevel", currentStarLevel) : "";
|
}
|
else
|
{
|
m_EquipStar.SetActive(false);
|
m_TargetEquip.SetActive(false);
|
}
|
|
DisplayMaterialSlots(equipPosition, currentStarLevel);
|
DisplayPropertyPreview(equipPosition, currentStarLevel, EquipStarModel.GetMaxStarLevel(equipPosition.x));
|
DisplayStarUpgradeButton(equipPosition, currentStarLevel);
|
}
|
|
}
|
|
if (force || model.equipStarLevel.dirty || model.equipMaxStarLevel.dirty)
|
{
|
model.autoBuy.dirty = true;
|
var equipPosition = new Int2(model.selectedLevel.value, model.selectedPlace.value);
|
var starLevel = model.equipStarLevel.Fetch();
|
var maxStar = model.equipMaxStarLevel.Fetch();
|
DisplayPropertyPreview(equipPosition, starLevel, EquipStarModel.GetMaxStarLevel(equipPosition.x));
|
DisplayStarUpgradeButton(equipPosition, starLevel);
|
}
|
|
if (force || model.stars.dirty)
|
{
|
DisplayStars(model.stars.Fetch());
|
}
|
|
|
if (force || model.starResultEffect.dirty)
|
{
|
var result = model.starResultEffect.Fetch();
|
model.starResultEffect.value = 0;
|
PlayStarUpgradeEffect(result);
|
}
|
|
|
|
if (force || model.autoBuy.dirty)
|
{
|
if (model.equipMaxStarLevel.value == model.equipStarLevel.value)
|
{
|
}
|
else
|
{
|
var value = model.autoBuy.Fetch();
|
if (value == -1)
|
{
|
//不勾选自动购买
|
m_Auto.isOn = false;
|
ShowAutoText(value);
|
}
|
else
|
{
|
m_Auto.isOn = true;
|
ShowAutoText(value);
|
}
|
}
|
|
}
|
}
|
|
private void DisplayCandidateSlots(int selectedLevel, bool resetPosition)
|
{
|
for (var i = 0; i < levelBehaviours.Count; i++)
|
{
|
var behaviour = levelBehaviours[i];
|
if (behaviour.level != selectedLevel)
|
{
|
behaviour.Dispose();
|
}
|
}
|
|
RectTransform selectedBehaviour = null;
|
for (var i = 0; i < levelBehaviours.Count; i++)
|
{
|
var behaviour = levelBehaviours[i];
|
if (behaviour.level == selectedLevel)
|
{
|
behaviour.Display();
|
selectedBehaviour = behaviour.transform as RectTransform;
|
}
|
}
|
|
//if (resetPosition && selectedBehaviour != null)
|
//{
|
// var height = 0f;
|
// var totalHeight = 0f;
|
// var index = selectedBehaviour.GetSiblingIndex();
|
// var childCount = m_LevelContainer.childCount;
|
|
// //for (var i = 0; i < childCount; i++)
|
// //{
|
// // var child = m_LevelContainer.GetChild(i);
|
// // if (i < index)
|
// // {
|
// // height += (child as RectTransform).rect.height;
|
// // }
|
|
// // totalHeight += (child as RectTransform).rect.height;
|
// //}
|
|
// var viewRect = (m_LevelScrollRect.transform as RectTransform).rect;
|
// if (totalHeight > viewRect.height)
|
// {
|
// m_LevelScrollRect.verticalNormalizedPosition = 1 - height / (totalHeight - viewRect.height);
|
// }
|
// else
|
// {
|
// m_LevelScrollRect.verticalNormalizedPosition = 1;
|
// }
|
//}
|
}
|
|
private void DisplayStars(List<EquipStarModel.Star> stars)
|
{
|
StopCoroutine("Co_DisplayStars");
|
StartCoroutine("Co_DisplayStars", stars);
|
}
|
|
private void DisplayMaterialSlots(Int2 equipPosition, int currentStarLevel)
|
{
|
var equipGuid = equipModel.GetEquip(equipPosition);
|
var equip = packModel.GetItemByGuid(equipGuid);
|
|
var maxStarLevel = equip != null ? EquipStarModel.GetMaxStarLevel(equip.config.ItemColor, equip.config.LV) : 0;
|
var upgradable = maxStarLevel > 0;
|
var isMax = upgradable && currentStarLevel >= maxStarLevel;
|
|
if (!upgradable || isMax )
|
{
|
m_SpecialMaterial1.Display(false, 0, 0);
|
m_SpecialMaterial2.Display(false, 0, 0);
|
}
|
else
|
{
|
var starConfig = EquipStarConfig.Get(equipPosition.x, equipPosition.y, currentStarLevel + 1);
|
|
|
m_SpecialMaterial1.Display(starConfig.CostItemDict[0].x != 0, starConfig.CostItemDict[0].x, starConfig.CostItemDict[0].y);
|
m_SpecialMaterial2.Display(starConfig.CostItemDict[1].x != 0, starConfig.CostItemDict[1].x, starConfig.CostItemDict[1].y);
|
}
|
}
|
|
private void DisplayPropertyPreview(Int2 equipPosition, int currentStar, int maxStar)
|
{
|
var equipGuid = equipModel.GetEquip(equipPosition);
|
var isMax = maxStar > 0 && currentStar >= maxStar;
|
var upgradable = model.IsEquipPlaceUpgradable(equipGuid);
|
|
if (isMax)
|
{
|
m_EmptyHint.SetActive(false);
|
m_PropertyDetails.SetActive(true);
|
DisplayBaseProperty(equipPosition, currentStar, currentStar);
|
DisplayLevelUpProperty(equipPosition, currentStar, currentStar);
|
}
|
else if (upgradable)
|
{
|
m_EmptyHint.SetActive(false);
|
m_PropertyDetails.SetActive(true);
|
DisplayBaseProperty(equipPosition, currentStar, currentStar + 1);
|
DisplayLevelUpProperty(equipPosition, currentStar, currentStar + 1);
|
}
|
else
|
{
|
m_EmptyHint.SetActive(true);
|
m_PropertyDetails.SetActive(false);
|
}
|
}
|
|
private void DisplayBaseProperty(Int2 equipPosition, int currentStar, int nextStar)
|
{
|
var nowConfig = EquipStarConfig.Get(equipPosition.x, equipPosition.y, currentStar);
|
var nextConfig = EquipStarConfig.Get(equipPosition.x, equipPosition.y, nextStar);
|
if (nextConfig == null)
|
{
|
nextConfig = nowConfig;
|
}
|
|
var count = nextConfig != null ? nextConfig.BaseAttrInfo.Length : 0;
|
for (var i = 0; i < m_BasePropertys.Length; i++)
|
{
|
var behaviour = m_BasePropertys[i];
|
if (i < count)
|
{
|
var current = nowConfig == null ? 0 : nowConfig.BaseAttrInfo[i].y;
|
var next = nextConfig == null ? 0 : nextConfig.BaseAttrInfo[i].y;
|
behaviour.Display(nextConfig == null ? 0 : nextConfig.BaseAttrInfo[i].x, current, next);
|
}
|
else
|
{
|
behaviour.Hide();
|
}
|
}
|
}
|
|
private void DisplayLevelUpProperty(Int2 equipPosition, int currentStar, int nextStar)
|
{
|
var descriptions = starEffectTipModel.DisplayStarProperty(equipPosition);
|
for (var i = 0; i < m_LevelUpPropertys.Length; i++)
|
{
|
var behaviour = m_LevelUpPropertys[i];
|
if (i < descriptions.Count)
|
{
|
behaviour.SetActive(true);
|
behaviour.text = descriptions[i];
|
}
|
else
|
{
|
behaviour.SetActive(false);
|
}
|
}
|
}
|
|
|
|
private void DisplayStarUpgradeButton(Int2 equipPosition, int currentStarLevel)
|
{
|
if (equipPosition.y == 0)
|
{
|
m_StarUpgrade.SetActive(false);
|
m_MaxStarLevelHint.SetActive(false);
|
}
|
else
|
{
|
var maxLevel = EquipStarModel.GetMaxStarLevel(equipPosition.x);
|
var isMax = currentStarLevel >= maxLevel;
|
m_StarUpgrade.SetActive(!isMax);
|
m_MaxStarLevelHint.SetActive(isMax);
|
}
|
}
|
|
|
private void StarUpgrade()
|
{
|
if ((TimeUtility.AllSeconds - curTime) < 2)
|
{
|
return;
|
}
|
|
var equipPosition = new Int2(model.selectedLevel.value, model.selectedPlace.value);
|
var currentStarLevel = model.GetEquipStarLevel(equipPosition);
|
|
if (model.autoBuy.value == -2)
|
{
|
//库存不足
|
SysNotifyMgr.Instance.ShowTip("AuctionNoEquip");
|
return;
|
}
|
curTime = TimeUtility.AllSeconds;
|
var auto = model.autoBuy.value > 0 ? 1 : 0;
|
model.DoStarUpgrade(equipPosition, currentStarLevel + 1, auto);
|
}
|
|
private void CreateLevelBehaviours()
|
{
|
var levels = equipModel.GetUnLockedEquipSets();
|
var gap = levels.Count - levelBehaviours.Count;
|
for (var i = 0; i < gap; i++)
|
{
|
var instance = UIUtility.CreateWidget("EquipStarLevelSelectBehaviour", "EquipStarLevelSelectBehaviour");
|
var behaviour = instance.GetComponent<EquipStarLevelSelectBehaviour>();
|
behaviour.transform.SetParentEx(m_LevelContainer, Vector3.zero, Quaternion.identity, Vector3.one);
|
levelBehaviours.Add(behaviour);
|
}
|
|
for (var i = 0; i < levelBehaviours.Count; i++)
|
{
|
var behaviour = levelBehaviours[i];
|
if (i < levels.Count)
|
{
|
behaviour.SetActive(true);
|
behaviour.UnInit();
|
behaviour.Init(levels[i]);
|
}
|
else
|
{
|
behaviour.UnInit();
|
behaviour.SetActive(false);
|
}
|
}
|
}
|
|
private void PlayStarUpgradeEffect(int result)
|
{
|
if (result == 1 || result == -1)
|
{
|
//StopCoroutine("Co_PlaySuccessEffect");
|
// StopCoroutine("Co_PlayFailedEffect");
|
}
|
|
if (result == 1)
|
{
|
//StartCoroutine("Co_PlaySuccessEffect");
|
}
|
else if (result == -1)
|
{
|
//StartCoroutine("Co_PlayFailedEffect");
|
}
|
}
|
|
//IEnumerator Co_PlaySuccessEffect()
|
//{
|
// m_EffectStarFill.Play();
|
// yield return WaitingForSecondConst.WaitMS700;
|
// m_EffectSuccess.Play();
|
//}
|
|
//IEnumerator Co_PlayFailedEffect()
|
//{
|
// m_EffectStarFill.Play();
|
// yield return WaitingForSecondConst.WaitMS700;
|
// m_EffectFailed.Play();
|
//}
|
|
IEnumerator Co_DisplayStars(List<EquipStarModel.Star> stars)
|
{
|
var hasNewStar = stars.FindIndex(x => { return x.newGet; }) != -1;
|
if (hasNewStar)
|
{
|
yield return WaitingForSecondConst.WaitMS2000;
|
}
|
|
//循环显示不同颜色,如10星在第一颗图标星换颜色
|
int starCnt = stars.Count;
|
int starLevel = model.GetStarLevel(new Int2(model.selectedLevel.value, model.selectedPlace.value));
|
int iconCnt = m_Stars.Length;
|
int loop = ((int)Math.Max(starLevel - 1, 0)) / iconCnt;
|
for (var i = 0; i < iconCnt; i++)
|
{
|
if (i < starCnt)
|
{
|
var starIndex = loop * iconCnt + i < starLevel ? loop * iconCnt + i : i;
|
var star = stars[starIndex];
|
m_Stars[i].Display(star.actived, starIndex / iconCnt);
|
if (star.newGet)
|
{
|
m_Stars[i].PlayEffect();
|
}
|
}
|
else
|
{
|
m_Stars[i].Hide();
|
}
|
}
|
}
|
|
private void ViewEquipTip()
|
{
|
var level = model.selectedLevel.value;
|
var place = model.selectedPlace.value;
|
var equipPosition = new Int2(level, place);
|
var equipGuid = equipModel.GetEquip(equipPosition);
|
|
ItemTipUtility.Show(equipGuid);
|
}
|
|
[System.Serializable]
|
public class Star
|
{
|
public RectTransform container;
|
public Image imageBase;
|
public Image imageStar;
|
public UIEffect newStarEffect;
|
|
public void Display(bool active, int loopIndex)
|
{
|
container.gameObject.SetActive(true);
|
imageStar.gameObject.SetActive(active);
|
imageStar.SetSprite("ImgStar_" + loopIndex);
|
}
|
|
public void Hide()
|
{
|
container.SetActive(false);
|
}
|
|
public void PlayEffect()
|
{
|
newStarEffect.Play();
|
}
|
}
|
|
[System.Serializable]
|
public class BaseProperty
|
{
|
public RectTransform container;
|
public Text current;
|
public RectTransform arrow;
|
public Text next;
|
|
public void Display(int propertyId, int currentValue, int nextValue)
|
{
|
container.SetActive(true);
|
var config = PlayerPropertyConfig.Get(propertyId);
|
if (config != null)
|
{
|
this.current.text = StringUtility.Contact(config.Name, ":", PlayerPropertyConfig.GetValueDescription(propertyId, currentValue));
|
if (currentValue != nextValue)
|
{
|
this.arrow.SetActive(true);
|
this.next.SetActive(true);
|
this.next.text = PlayerPropertyConfig.GetValueDescription(propertyId, nextValue);
|
}
|
else
|
{
|
this.arrow.SetActive(false);
|
this.next.SetActive(false);
|
}
|
}
|
}
|
|
public void Hide()
|
{
|
container.SetActive(false);
|
}
|
}
|
|
|
}
|
|
}
|