//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, May 23, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class TreasureSoulWin : Window
|
{
|
[SerializeField] FunctionButton m_TreasureSoulBtn;
|
[SerializeField] Button m_CloseBtn;
|
|
[SerializeField] Image m_SelectSoulImg;
|
|
[SerializeField] Text m_SoulName;
|
[SerializeField] Text m_SoulDescription;
|
[SerializeField] Image m_SoulTarget;
|
[SerializeField] UIEffect m_SoulEffect;
|
[SerializeField] Button m_Active;
|
[SerializeField] Text m_ActiveText;
|
|
[SerializeField] List<TreasureSoulPattern> m_TreasureSouls;
|
|
[SerializeField] ScrollerController m_ScollerControl;
|
|
[SerializeField] RectTransform m_ContainerPreview;
|
[SerializeField] Text m_PreviewTitle;
|
[SerializeField] List<PropertyBehaviour> m_PreviewPropretys;
|
|
TreasureSoulModel m_Model;
|
TreasureSoulModel model
|
{
|
get
|
{
|
return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<TreasureSoulModel>());
|
}
|
}
|
PlayerSuitModel suitModel { get { return ModelCenter.Instance.GetModel<PlayerSuitModel>(); } }
|
PlayerPackModel pack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
|
|
public PlayerStrengthengDatas strengthengmodel
|
{
|
get
|
{
|
return ModelCenter.Instance.GetModel<PlayerStrengthengDatas>();
|
}
|
}
|
|
TreasureModel treasureModel
|
{
|
get { return ModelCenter.Instance.GetModel<TreasureModel>(); }
|
}
|
|
|
int m_SelectSoul = 0;
|
|
List<int> sortSouls = new List<int>();
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Active.onClick.AddListener(Active);
|
m_CloseBtn.onClick.AddListener(CloseClick);
|
m_ScollerControl.OnRefreshCell += OnRefreshCell;
|
}
|
|
protected override void OnPreOpen()
|
{
|
model.treasureSelectSoulChangeEvent += TreasureSelectSoulChangeEvent;
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
|
model.treasureSoulEvent += TreasureSoulEvent;
|
m_TreasureSoulBtn.state = TitleBtnState.Click;
|
Display();
|
model.SetViewTreasureNewGot();
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
DisplaySelect();
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataRefresh refreshType)
|
{
|
if (refreshType == PlayerDataRefresh.LV)
|
{
|
m_ScollerControl.m_Scorller.RefreshActiveCellViews();
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
model.treasureSelectSoulChangeEvent -= TreasureSelectSoulChangeEvent;
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent;
|
model.treasureSoulEvent -= TreasureSoulEvent;
|
for (int i = 0; i < m_TreasureSouls.Count; i++)
|
{
|
m_TreasureSouls[i].Dispose();
|
}
|
m_SelectSoul = model.selectSoul;
|
model.newGotSoul = 0;
|
}
|
|
protected override void OnAfterClose()
|
{
|
if (!WindowJumpMgr.Instance.IsJumpState)
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
#endregion
|
|
private void Display()
|
{
|
sortSouls.Clear();
|
var _list = model.GetTreasureSouls();
|
for (int i = 0; i < _list.Count; i++)
|
{
|
if (model.IsOpenTreasureSoul(_list[i]))
|
{
|
sortSouls.Add(_list[i]);
|
}
|
}
|
if (m_ScollerControl.GetNumberOfCells(m_ScollerControl.m_Scorller) != sortSouls.Count)
|
{
|
m_ScollerControl.Refresh();
|
for (int i = 0; i < sortSouls.Count; i++)
|
{
|
m_ScollerControl.AddCell(ScrollerDataType.Header, i);
|
}
|
m_ScollerControl.Restart();
|
}
|
sortSouls.Sort(Compare);
|
model.selectSoul = CheckOpenSelect();
|
var index = sortSouls.FindIndex((x) =>
|
{
|
return x == model.selectSoul;
|
});
|
m_ScollerControl.m_Scorller.RefreshActiveCellViews();
|
m_ScollerControl.JumpIndex(index);
|
}
|
|
int CheckOpenSelect()
|
{
|
if (WindowJumpMgr.Instance.IsJumpState && model.gotoSoul != 0)
|
{
|
var _soul = model.gotoSoul;
|
model.gotoSoul = 0;
|
return _soul;
|
}
|
model.gotoSoul = 0;
|
var _select = 0;
|
for (int i = 0; i < sortSouls.Count; i++)
|
{
|
TreasureSpecialData special;
|
if (model.TryGetTreasureSoul(sortSouls[i], out special))
|
{
|
if (special.redpoint.state == RedPointState.Simple)
|
{
|
return sortSouls[i];
|
}
|
}
|
if (!model.IsGetTreasureSoul(sortSouls[i]) && _select == 0)
|
{
|
_select = sortSouls[i];
|
}
|
}
|
if (model.newGotSoul != 0 && sortSouls.Contains(model.newGotSoul))
|
{
|
_select = model.newGotSoul;
|
model.newGotSoul = 0;
|
}
|
_select = _select == 0 ? sortSouls[0] : _select;
|
return _select;
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
TreasureSoulCell treasureSoulCell = cell as TreasureSoulCell;
|
if (cell.index < sortSouls.Count)
|
{
|
treasureSoulCell.Display(sortSouls[cell.index]);
|
}
|
}
|
|
private void TreasureSelectSoulChangeEvent(int _id)
|
{
|
DisplaySelect();
|
}
|
|
private void TreasureSoulEvent(int _id)
|
{
|
if (_id == model.selectSoul)
|
{
|
TreasureSpecialData special;
|
if (model.TryGetTreasureSoul(_id, out special))
|
{
|
DisplaySelect();
|
}
|
}
|
}
|
|
private void Active()
|
{
|
var config = TreasurePrivilegeConfig.Get(model.selectSoul);
|
treasureModel.selectedTreasure = config.treasureId;
|
treasureModel.currentCategory = TreasureCategory.Human;
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.TreasureCollectSoul);
|
}
|
|
private void DisplaySelect()
|
{
|
TreasureSpecialData special;
|
model.TryGetTreasureSoul(model.selectSoul, out special);
|
if (special != null)
|
{
|
var config = TreasurePrivilegeConfig.Get((int)special.type);
|
if (config != null)
|
{
|
m_SoulName.text = config.Name;
|
m_SoulDescription.text = UIHelper.ReplaceNewLine(config.Description);
|
m_SoulTarget.SetSprite(config.targetDescription);
|
m_SoulTarget.SetNativeSize();
|
DisplayPrivilege(special);
|
|
m_SelectSoulImg.SetSprite(config.Icon);
|
m_SelectSoulImg.material = special.active ? MaterialUtility.GetUIDefaultGraphicMaterial() : MaterialUtility.GetDefaultSpriteGrayMaterial();
|
m_SelectSoulImg.SetNativeSize();
|
|
m_Active.gameObject.SetActive(!special.active);
|
|
m_ContainerPreview.gameObject.SetActive(!special.active);
|
m_SoulEffect.StopImediatly();
|
if (!special.active)
|
{
|
DisplayPreview(model.selectSoul);
|
}
|
else
|
{
|
m_SoulEffect.effect = config.effectId;
|
m_SoulEffect.Play();
|
}
|
}
|
}
|
}
|
|
private void DisplayPrivilege(TreasureSpecialData special)
|
{
|
int _pattern = -1;
|
switch (special.type)
|
{
|
case TreasurePrivilege.Property:
|
case TreasurePrivilege.Suit:
|
case TreasurePrivilege.Wing:
|
_pattern = 3;
|
break;
|
case TreasurePrivilege.DemonJarAtk:
|
case TreasurePrivilege.MountAtk:
|
case TreasurePrivilege.PetHp:
|
case TreasurePrivilege.Sp:
|
_pattern = 0;
|
break;
|
case TreasurePrivilege.StrengthenAdd:
|
_pattern = 1;
|
break;
|
case TreasurePrivilege.Wash:
|
_pattern = 2;
|
break;
|
}
|
for (int i = 0; i < m_TreasureSouls.Count; i++)
|
{
|
m_TreasureSouls[i].Dispose();
|
m_TreasureSouls[i].gameObject.SetActive(_pattern == i && model.IsGetTreasureSoul(model.selectSoul));
|
if (m_TreasureSouls[i].bottom != null)
|
{
|
m_TreasureSouls[i].bottom.gameObject.SetActive(_pattern == i && model.IsGetTreasureSoul(model.selectSoul));
|
}
|
if (_pattern == i)
|
{
|
m_TreasureSouls[i].Display((int)special.type);
|
}
|
}
|
}
|
|
private void DisplayPreview(int _id)
|
{
|
m_ContainerPreview.gameObject.SetActive(false);
|
TreasureSpecialData special;
|
model.TryGetTreasureSoul(_id, out special);
|
switch (special.type)
|
{
|
case TreasurePrivilege.Wing:
|
case TreasurePrivilege.Suit:
|
case TreasurePrivilege.Property:
|
m_PreviewTitle.text = Language.Get("TreasureSoulAddPropertyTitle");
|
break;
|
case TreasurePrivilege.DemonJarAtk:
|
case TreasurePrivilege.StrengthenAdd:
|
case TreasurePrivilege.MountAtk:
|
case TreasurePrivilege.PetHp:
|
case TreasurePrivilege.Sp:
|
m_PreviewTitle.text = Language.Get("TreasureSoulGetPropertyTitle");
|
break;
|
}
|
for (int i = 0; i < m_PreviewPropretys.Count; i++)
|
{
|
m_PreviewPropretys[i].gameObject.SetActive(false);
|
}
|
switch (special.type)
|
{
|
case TreasurePrivilege.Property:
|
var _index = 0;
|
m_ContainerPreview.gameObject.SetActive(true);
|
foreach (var _key in special.propertyDict.Keys)
|
{
|
var _value = special.propertyDict[_key];
|
m_PreviewPropretys[_index].gameObject.SetActive(true);
|
m_PreviewPropretys[_index].DisplayUpper(_key, _value);
|
_index++;
|
}
|
break;
|
case TreasurePrivilege.Suit:
|
var percentSuit = (float)special.propertyDict[87] / 10000;
|
var dict = suitModel.GetActiveSuitAttr();
|
var _suitIndex = 0;
|
foreach (var _key in dict.Keys)
|
{
|
var propertyConfig = PlayerPropertyConfig.Get(_key);
|
if (propertyConfig == null || propertyConfig.type != 1)
|
{
|
continue;
|
}
|
m_PreviewPropretys[_suitIndex].gameObject.SetActive(true);
|
m_PreviewPropretys[_suitIndex].DisplayUpper(_key, (int)(percentSuit * dict[_key]));
|
_suitIndex++;
|
}
|
m_ContainerPreview.gameObject.SetActive(_suitIndex > 0);
|
break;
|
case TreasurePrivilege.Wing:
|
var percentWing = (float)special.propertyDict[86] / 10000;
|
var itemModel = pack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retWing);
|
m_ContainerPreview.gameObject.SetActive(itemModel != null);
|
if (itemModel != null)
|
{
|
var itemConfig = ItemConfig.Get(itemModel.itemId);
|
float value = 0;
|
if (ContainsProperty(itemConfig, 6, out value))
|
{
|
if (itemModel.GetUseDataModel(42) != null)
|
{
|
value += strengthengmodel.BackpackWings(itemModel.itemId, itemModel.GetUseDataModel(42)[0])[1];
|
}
|
}
|
m_PreviewPropretys[0].gameObject.SetActive(true);
|
m_PreviewPropretys[0].DisplayUpper(6, (int)(value * percentWing));
|
}
|
break;
|
case TreasurePrivilege.DemonJarAtk:
|
case TreasurePrivilege.PetHp:
|
case TreasurePrivilege.MountAtk:
|
case TreasurePrivilege.Sp:
|
var index = 0;
|
m_ContainerPreview.gameObject.SetActive(true);
|
foreach (var _key in special.propertyDict.Keys)
|
{
|
var _value = special.propertyDict[_key] * (special.presentGetCount / special.progress);
|
if (_value <= 0)
|
{
|
m_ContainerPreview.gameObject.SetActive(false);
|
break;
|
}
|
m_PreviewPropretys[index].gameObject.SetActive(true);
|
m_PreviewPropretys[index].DisplayUpper(_key, _value);
|
index++;
|
}
|
break;
|
case TreasurePrivilege.StrengthenAdd:
|
var configs = Config.Instance.GetAllValues<ItemPlusSumAttrConfig>();
|
var present = -1;
|
var next = 0;
|
var presentGetCount = 0;
|
foreach (var value in strengthengmodel._EqInfo.Values)
|
{
|
ItemModel equip = pack.GetItemModelByIndex(PackType.rptEquip, value.EquipIndex);
|
if (equip != null)
|
{
|
presentGetCount += value.EquipPartStarLV;
|
}
|
}
|
for (int i = 0; i < configs.Count; i++)
|
{
|
if (presentGetCount >= configs[i].countNeed)
|
{
|
present = i;
|
}
|
}
|
next = present + 1;
|
m_ContainerPreview.gameObject.SetActive(present >= 0);
|
if (present >= 0)
|
{
|
var config = configs[present];
|
for (int i = 0; i < m_PreviewPropretys.Count; i++)
|
{
|
m_PreviewPropretys[i].gameObject.SetActive(i < config.attType.Length);
|
if (i < config.attType.Length)
|
{
|
m_PreviewPropretys[i].DisplayUpper(config.attType[i], config.attValue[i]);
|
}
|
}
|
}
|
break;
|
}
|
}
|
|
int Compare(int x, int y)
|
{
|
var leftConfig = TreasurePrivilegeConfig.Get(x);
|
var rightConfig = TreasurePrivilegeConfig.Get(y);
|
if (leftConfig != null && rightConfig != null)
|
{
|
return leftConfig.sort.CompareTo(rightConfig.sort);
|
}
|
return x.CompareTo(y);
|
}
|
|
bool ContainsProperty(ItemConfig config, int _property, out float value)
|
{
|
value = 0;
|
if (config.Effect1 == _property && config.EffectValueA1 > 0)
|
{
|
value = config.EffectValueA1;
|
return true;
|
}
|
if (config.Effect2 == _property && config.EffectValueA2 > 0)
|
{
|
value = config.EffectValueA2;
|
return true;
|
}
|
if (config.Effect3 == _property && config.EffectValueA3 > 0)
|
{
|
value = config.EffectValueA3;
|
return true;
|
}
|
if (config.Effect4 == _property && config.EffectValueA4 > 0)
|
{
|
value = config.EffectValueA4;
|
return true;
|
}
|
if (config.Effect5 == _property && config.EffectValueA5 > 0)
|
{
|
value = config.EffectValueA5;
|
return true;
|
}
|
return false;
|
}
|
}
|
|
}
|
|
|
|
|