//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, March 05, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class EquipGemWin : Window
|
{
|
[SerializeField] ScrollerController m_Controller;
|
[SerializeField] RectTransform m_LevelContainer;
|
[SerializeField] Transform m_ContainerGem;
|
[SerializeField] Transform m_ContainerEmpty;
|
[SerializeField] ItemCell m_EquipItem;
|
[SerializeField] Text m_EquipStar;
|
[SerializeField] EquipGemHoleBehaviour[] m_GemHoles;
|
[SerializeField] Transform m_ContainerPro;
|
[SerializeField] Transform m_ContainerProEmpty;
|
[SerializeField] EquipGemPro[] m_EquipGemPro;
|
[SerializeField] Button GemLVUP;
|
[SerializeField] Button GemOff;
|
[SerializeField] ScrollerController m_GemCostController;
|
|
[SerializeField] Transform m_MoneyContainer;
|
[SerializeField] Text m_Money;
|
|
List<int> m_Sorts = new List<int>();
|
|
EquipGemModel model
|
{
|
get { return ModelCenter.Instance.GetModel<EquipGemModel>(); }
|
}
|
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
EquipStarModel equipStarModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
m_GemCostController.OnRefreshCell += OnCostRefreshCell;
|
GemLVUP.SetListener(OnGemLVUP);
|
GemOff.SetListener(OnGemOff);
|
}
|
|
protected override void OnPreOpen()
|
{
|
|
var selectEquip = SetDefaultSelect();
|
|
Display();
|
|
model.SelectHoleIndex = 0;
|
m_Controller.JumpIndex(GetJumpIndex(model.selectLevel, model.selectEquipPlace));
|
selectHoleRefresh();
|
|
model.selectEquipRefresh += SelectEquipRefresh;
|
model.selectLevelRefresh += SelectLevelRefresh;
|
model.selectHoleRefresh += selectHoleRefresh;
|
model.equipGemRefresh += EquipGemRefresh;
|
model.equipGemLevelUp += EquipGemLevelUp;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
model.selectEquipRefresh -= SelectEquipRefresh;
|
model.selectLevelRefresh -= SelectLevelRefresh;
|
model.selectHoleRefresh -= selectHoleRefresh;
|
model.equipGemRefresh -= EquipGemRefresh;
|
model.equipGemLevelUp -= EquipGemLevelUp;
|
|
foreach (var equipGemHole in m_GemHoles)
|
{
|
equipGemHole.DisplayLevelUp(false);
|
}
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
bool SetDefaultSelect()
|
{
|
if (!model.jumpEquipPosition.Equals(Int2.zero))
|
{
|
model.selectLevel = model.jumpEquipPosition.x;
|
model.selectEquipPlace = model.jumpEquipPosition.y;
|
model.jumpEquipPosition = Int2.zero;
|
return true;
|
}
|
|
var equipSets = equipModel.GetAllEquipSets();
|
foreach (var equipSet in equipSets)
|
{
|
var places = model.GetMosaicEquipPlaces();
|
foreach (var place in places)
|
{
|
EquipGemRedpoint equipGemRedpoint;
|
if (model.TryGetRedpoint(equipSet, place, out equipGemRedpoint)
|
&& equipGemRedpoint.repoint.state == RedPointState.Simple)
|
{
|
model.selectLevel = equipSet;
|
model.selectEquipPlace = place;
|
return true;
|
}
|
}
|
}
|
|
var maxInlayCount = 0;
|
var maxSelect = Int2.zero;
|
foreach (var level in equipSets)
|
{
|
var equipSet = equipModel.GetEquipSet(level);
|
if (equipSet == null)
|
{
|
continue;
|
}
|
model.selectLevel = level;
|
var places = new List<int>(model.GetMosaicEquipPlaces());
|
places.Sort(EquipCompare);
|
if (maxSelect.x == 0)
|
{
|
maxSelect = new Int2(level, places[0]);
|
}
|
foreach (var place in places)
|
{
|
var count = model.GetEmptyGemHoleCount(level, place);
|
if (count > maxInlayCount)
|
{
|
maxInlayCount = count;
|
maxSelect.x = level;
|
maxSelect.y = place;
|
}
|
}
|
}
|
|
model.selectLevel = maxSelect.x;
|
model.selectEquipPlace = maxSelect.y;
|
return maxInlayCount != 0;
|
}
|
|
int GetJumpIndex(int selectLevel, int selectPlace)
|
{
|
var jumpIndex = 0;
|
var equipSet = equipModel.GetEquipSet(selectLevel);
|
if (equipSet == null)
|
{
|
return jumpIndex;
|
}
|
if (equipSet.unLocked)
|
{
|
var slotCount = model.GetUnlockEquipSlotCount(selectLevel);
|
if (slotCount > 0)
|
{
|
foreach (var place in m_Sorts)
|
{
|
if (equipSet.IsSlotUnLocked(place))
|
{
|
if (selectPlace == place)
|
{
|
return jumpIndex;
|
}
|
jumpIndex++;
|
}
|
}
|
}
|
|
}
|
return 0;
|
}
|
|
void Display()
|
{
|
DisplayGems();
|
DisplayEquips();
|
}
|
|
void DisplayEquips()
|
{
|
var sets = equipModel.GetUnLockedEquipSetsByFuncID(-1);
|
var behaviourCount = sets.Count;
|
var behaviourGap = behaviourCount - model.EquipSetList.Count;
|
for (var i = 0; i < behaviourGap; i++)
|
{
|
var instance = UIUtility.CreateWidget("EquipSetSelect", "EquipSetSelect");
|
instance.transform.SetParentEx(m_LevelContainer, Vector3.zero, Quaternion.identity, Vector3.one);
|
instance.transform.SetAsFirstSibling();
|
model.EquipSetList.Insert(0, instance.GetComponent<EquipSetSelect>());
|
}
|
|
m_Controller.Refresh();
|
|
for (var i = 0; i < model.EquipSetList.Count; i++)
|
{
|
var behaviour = model.EquipSetList[i];
|
if (i < behaviourCount)
|
{
|
behaviour.SetActive(true);
|
Redpoint redpoint;
|
model.TryGetRedpoint(sets[i], out redpoint);
|
behaviour.Display(sets[i], model.selectLevel == sets[i], redpoint.id);
|
}
|
else
|
{
|
behaviour.SetActive(false);
|
}
|
if (model.selectLevel == sets[i])
|
{
|
var equipSet = equipModel.GetEquipSet(sets[i]);
|
if (equipSet == null)
|
{
|
continue;
|
}
|
m_Sorts.Clear();
|
m_Sorts.AddRange(model.GetMosaicEquipPlaces());
|
m_Sorts.Sort(EquipCompare);
|
foreach (var place in m_Sorts)
|
{
|
if (equipSet.IsSlotUnLocked(place))
|
{
|
m_Controller.AddCell(ScrollerDataType.Header, sets[i] * 1000 + place);
|
}
|
}
|
|
}
|
}
|
|
m_Controller.Restart();
|
}
|
|
private int EquipCompare(int x, int y)
|
{
|
// 按宝石 攻防会排序
|
List<int> places = new List<int>() { 1, 2, 5, 8, 3, 4, 6, 7, 9, 10, 11, 12 };
|
|
return places.IndexOf(x).CompareTo(places.IndexOf(y));
|
|
}
|
|
void DisplayGems()
|
{
|
if (model.selectLevel == -1)
|
{
|
m_ContainerEmpty.SetActive(true);
|
m_ContainerGem.SetActive(false);
|
return;
|
}
|
|
m_ContainerEmpty.SetActive(false);
|
m_ContainerGem.SetActive(true);
|
|
var equipPosition = new Int2(model.selectLevel, model.selectEquipPlace);
|
var equipGuid = equipModel.GetEquip(equipPosition);
|
var equip = packModel.GetItemByGuid(equipGuid);
|
m_EquipItem.SetActive(equip != null);
|
if (equip != null)
|
{
|
m_EquipItem.Init(equip);
|
m_EquipItem.button.SetListener(() =>
|
{
|
ItemTipUtility.Show(equipGuid);
|
});
|
|
var maxStar = EquipStarModel.GetMaxStarLevel(equip.config.ItemColor, equip.config.LV);
|
var starLevel = Mathf.Min(maxStar, equipStarModel.GetStarLevel(equipPosition));
|
m_EquipStar.text = starLevel == 0 ? string.Empty : Language.Get("EquipStarLevel", starLevel);
|
}
|
|
for (int i = 0; i < m_GemHoles.Length; i++)
|
{
|
m_GemHoles[i].DisplayEquipGem(model.selectLevel, model.selectEquipPlace, i);
|
}
|
}
|
|
private void SelectEquipRefresh()
|
{
|
foreach (var equipGemHole in m_GemHoles)
|
{
|
equipGemHole.DisplayLevelUp(false);
|
}
|
model.SelectHoleIndex = 0;
|
DisplayGems();
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
private void SelectLevelRefresh()
|
{
|
DisplayEquips();
|
if (model.selectLevel != -1)
|
{
|
model.selectEquipPlace = m_Sorts[0];
|
model.SelectHoleIndex = 0;
|
}
|
DisplayGems();
|
}
|
|
private void selectHoleRefresh()
|
{
|
DisplayGems();
|
DisplayPropertyEx();
|
}
|
|
private void EquipGemRefresh(int level, int place)
|
{
|
if (level == model.selectLevel && place == model.selectEquipPlace)
|
{
|
DisplayGems();
|
DisplayPropertyEx();
|
var index = level * 1000 + place;
|
m_Controller.RefreshSingleCellView(index);
|
}
|
}
|
|
private void EquipGemLevelUp(int level, int place, int hole)
|
{
|
if (level == model.selectLevel && place == model.selectEquipPlace)
|
{
|
if (hole < m_GemHoles.Length)
|
{
|
m_GemHoles[hole].DisplayLevelUp(true);
|
}
|
}
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
switch (type)
|
{
|
case ScrollerDataType.Header:
|
var level = cell.index / 1000;
|
var place = cell.index % 1000;
|
var equipSelectCell = cell as EquipGemSelectBehaviour;
|
equipSelectCell.Display(level, place);
|
break;
|
}
|
}
|
|
public static void DisplayProperty(int equipGem, PropertyBehaviour[] properties)
|
{
|
var config = ItemConfig.Get(equipGem);
|
var index = 0;
|
|
if (config.Effect2 != 0 && index < properties.Length)
|
{
|
properties[index].SetActive(true);
|
properties[index].DisplayGem(config.Effect2, config.EffectValueA2);
|
index++;
|
}
|
|
if (config.Effect3 != 0 && index < properties.Length)
|
{
|
properties[index].SetActive(true);
|
properties[index].DisplayGem(config.Effect3, config.EffectValueA3);
|
index++;
|
}
|
|
if (config.Effect4 != 0 && index < properties.Length)
|
{
|
properties[index].SetActive(true);
|
properties[index].DisplayGem(config.Effect4, config.EffectValueA4);
|
index++;
|
}
|
|
for (int i = index; i < properties.Length; i++)
|
{
|
properties[i].SetActive(false);
|
}
|
}
|
|
public void DisplayPropertyEx()
|
{
|
int[] equipGems = null;
|
m_ContainerPro.SetActive(false);
|
m_ContainerProEmpty.SetActive(false);
|
GemLVUP.SetActive(false);
|
GemOff.SetActive(false);
|
m_GemCostController.SetActive(false);
|
m_MoneyContainer.SetActive(false);
|
if (!model.TryGetEquipGems(model.selectLevel, model.selectEquipPlace, out equipGems))
|
{
|
//无数据
|
m_ContainerProEmpty.SetActive(true);
|
return;
|
}
|
if (equipGems[model.SelectHoleIndex] == 0)
|
{
|
//空孔
|
m_ContainerProEmpty.SetActive(true);
|
return;
|
}
|
|
m_ContainerPro.SetActive(true);
|
foreach (var gemPro in m_EquipGemPro)
|
{
|
gemPro.SetActive(false);
|
}
|
var config = ItemConfig.Get(equipGems[model.SelectHoleIndex]);
|
var upConfig = ItemConfig.Get(config.EffectValueC1);
|
var index = 0;
|
|
if (upConfig != null)
|
GemLVUP.SetActive(true);
|
GemOff.SetActive(true);
|
//宝石名称
|
m_EquipGemPro[index].SetActive(true);
|
m_EquipGemPro[index].DisplayGemName(config);
|
index++;
|
|
//属性
|
if ((config.Effect2 != 0 || (upConfig != null && upConfig.Effect2 != 0)))
|
{
|
m_EquipGemPro[index].SetActive(true);
|
var nextValue = config.EffectValueC1 == 0 ? 0 : upConfig.EffectValueA2;
|
var effectID = config.EffectValueC1 == 0 ? 0 : upConfig.Effect2;
|
m_EquipGemPro[index].DisplayPro(Math.Max(config.Effect2, effectID), config.EffectValueA2, nextValue);
|
index++;
|
}
|
|
if (config.Effect3 != 0 || (upConfig != null && upConfig.Effect3 != 0))
|
{
|
m_EquipGemPro[index].SetActive(true);
|
var nextValue = config.EffectValueC1 == 0 ? 0 : upConfig.EffectValueA3;
|
var effectID = config.EffectValueC1 == 0 ? 0 : upConfig.Effect3;
|
m_EquipGemPro[index].DisplayPro(Math.Max(config.Effect3, effectID), config.EffectValueA3, nextValue);
|
index++;
|
}
|
|
if (config.Effect4 != 0 || (upConfig != null && upConfig.Effect4 != 0))
|
{
|
m_EquipGemPro[index].SetActive(true);
|
var nextValue = config.EffectValueC1 == 0 ? 0 : upConfig.EffectValueA4;
|
var effectID = config.EffectValueC1 == 0 ? 0 : upConfig.Effect4;
|
m_EquipGemPro[index].DisplayPro(Math.Max(config.Effect4, effectID), config.EffectValueA4, nextValue);
|
index++;
|
}
|
|
OnShowGemCostList(config.EffectValueC1, equipGems[model.SelectHoleIndex]);
|
}
|
|
int needMoney = 0;
|
Dictionary<int, List<int>> costDict;
|
private void OnShowGemCostList(int makeID, int itemID)
|
{
|
m_GemCostController.SetActive(true);
|
m_GemCostController.Refresh();
|
|
costDict = model.GetComposeNeedGemList(makeID, itemID);
|
needMoney = 0;
|
foreach (var itemInfo in costDict)
|
{
|
if (itemInfo.Value[0] >= itemInfo.Value[1])
|
continue;
|
m_GemCostController.AddCell(ScrollerDataType.Header, itemInfo.Key);
|
var ItemConfig = StoreConfig.GetStoreCfgByItemIDEx(itemInfo.Key, 1);
|
if (ItemConfig != null)
|
{
|
needMoney = needMoney + ItemConfig.MoneyNumber*Math.Max(itemInfo.Value[1] - itemInfo.Value[0], 0);
|
}
|
}
|
|
foreach (var itemInfo in costDict)
|
{
|
if (itemInfo.Value[0] < itemInfo.Value[1])
|
continue;
|
m_GemCostController.AddCell(ScrollerDataType.Header, itemInfo.Key);
|
}
|
|
|
m_GemCostController.Restart();
|
if (needMoney > 0)
|
{
|
m_MoneyContainer.SetActive(true);
|
m_Money.text = UIHelper.AppendColor(needMoney > PlayerDatas.Instance.baseData.diamond ? TextColType.Red : TextColType.DarkGreen,
|
needMoney.ToString());
|
}
|
else
|
{
|
m_MoneyContainer.SetActive(false);
|
}
|
|
}
|
|
private void OnCostRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
if (type != ScrollerDataType.Header)
|
return;
|
|
var itemID = cell.index;
|
var costText = cell.transform.GetComponent<Text>();
|
costText.text = UIHelper.AppendColor(costDict[itemID][1] > costDict[itemID][0] ? TextColType.Red : TextColType.DarkGreen,
|
Language.Get("GemHoleMal", itemID, costDict[itemID][0], costDict[itemID][1]), true);
|
}
|
|
private void OnGemLVUP()
|
{
|
LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(52, 1, needMoney, 2, 0);
|
LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(26, 1, 1, 3, 0);
|
if (PlayerDatas.Instance.baseData.diamond < needMoney)
|
{
|
if (VersionConfig.Get().isBanShu)
|
{
|
SysNotifyMgr.Instance.ShowTip("GoldErr");
|
return;
|
}
|
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
return;
|
}
|
|
if (needMoney == 0 || DayRemind.Instance.GetDayRemind(DayRemind.EQUIPGEMUSEGOLD))
|
{
|
model.SendGemLevelUp(model.selectLevel, model.selectEquipPlace, model.SelectHoleIndex, 0);
|
return;
|
}
|
|
ConfirmCancel.ToggleConfirmCancel(Language.Get("Mail101"),
|
Language.Get("EquipGemUseGold", needMoney),
|
Language.Get("TodayNoNotify"), (bool ok, bool isToggle) =>
|
{
|
if (isToggle)
|
{
|
DayRemind.Instance.SetDayRemind(DayRemind.EQUIPGEMUSEGOLD, true);
|
}
|
|
if (ok)
|
{
|
model.SendGemLevelUp(model.selectLevel, model.selectEquipPlace, model.SelectHoleIndex, 0);
|
}
|
});
|
|
}
|
|
private void OnGemOff()
|
{
|
var equipPosition = new Int2(model.selectLevel, model.selectEquipPlace);
|
var equipGuid = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equipGuid))
|
{
|
return;
|
}
|
|
var _pak = new CA305_tagCMEquipStonePick();
|
_pak.EquipIndex = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
|
_pak.HoleIndex = model.SelectHoleIndex == 3 ? (byte)10 : (byte)model.SelectHoleIndex;
|
GameNetSystem.Instance.SendInfo(_pak);
|
}
|
|
}
|
|
}
|
|
|
|
|