//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, May 23, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using TableConfig;
|
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_SelectTreasureName;
|
|
[SerializeField] Text m_SoulName;
|
[SerializeField] Text m_SoulDescription;
|
[SerializeField] Image m_SoulTarget;
|
[SerializeField] Button m_GotoGetBtn;
|
|
[SerializeField] List<TreasureSoulPattern> m_TreasureSouls;
|
|
[SerializeField] RectTransform m_ContainerPreview;
|
[SerializeField] Text m_PropertyTitle;
|
[SerializeField] List<PropertyBehaviour> propertys;
|
|
[SerializeField] ScrollerController m_ScollerControl;
|
|
TreasureModel m_Model;
|
TreasureModel model
|
{
|
get
|
{
|
return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<TreasureModel>());
|
}
|
}
|
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>();
|
}
|
}
|
|
|
bool m_CorrectClose = true;
|
int m_SelectSoul = 0;
|
|
List<int> sortSouls = new List<int>();
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_GotoGetBtn.onClick.AddListener(OnGotoGet);
|
m_CloseBtn.onClick.AddListener(CloseClick);
|
m_ScollerControl.OnRefreshCell += OnRefreshCell;
|
}
|
|
protected override void OnPreOpen()
|
{
|
m_CorrectClose = true;
|
model.treasureSelectSoulChangeEvent += TreasureSelectSoulChangeEvent;
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
|
m_TreasureSoulBtn.state = TitleBtnState.Click;
|
Display();
|
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;
|
for (int i = 0; i < m_TreasureSouls.Count; i++)
|
{
|
m_TreasureSouls[i].Dispose();
|
}
|
m_SelectSoul = model.selectSoul;
|
}
|
|
protected override void OnAfterClose()
|
{
|
if (m_CorrectClose)
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
}
|
#endregion
|
|
private void Display()
|
{
|
sortSouls.Clear();
|
var _list = model.GetTreasureCategory(TreasureCategory.Human);
|
sortSouls.AddRange(_list);
|
if (m_ScollerControl.GetNumberOfCells(m_ScollerControl.m_Scorller) == 0)
|
{
|
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 _list = model.GetTreasureCategory(TreasureCategory.Human);
|
var _select = _list[0];
|
for (int i = 0; i < _list.Count; i++)
|
{
|
Treasure treasure;
|
if (model.TryGetTreasure(_list[i], out treasure))
|
{
|
if (treasure.specialData.privilegeRedpoint != null
|
&& treasure.specialData.privilegeRedpoint.state == RedPointState.Simple)
|
{
|
return _list[i];
|
}
|
}
|
}
|
for (int i = 0; i < _list.Count; i++)
|
{
|
Treasure treasure;
|
if (model.TryGetTreasure(_list[i], out treasure))
|
{
|
if (treasure.state == TreasureState.Collected)
|
{
|
if (!treasure.IsMaxStage())
|
{
|
return _list[i];
|
}
|
_select = treasure.id;
|
}
|
}
|
}
|
if (_list.Contains(m_SelectSoul))
|
{
|
return m_SelectSoul;
|
}
|
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 OnGotoGet()
|
{
|
m_CorrectClose = false;
|
CloseImmediately();
|
model.currentCategory = TreasureCategory.Human;
|
model.selectedTreasure = model.selectSoul;
|
model.openFromTreasureSoul = true;
|
WindowCenter.Instance.Open<TreasureLevelUpWin>();
|
}
|
|
private void DisplaySelect()
|
{
|
Treasure treasure;
|
model.TryGetTreasure(model.selectSoul, out treasure);
|
if (treasure != null)
|
{
|
var _privilege = treasure.unLockPrivilege;
|
var config = ConfigManager.Instance.GetTemplate<TreasurePrivilegeConfig>(_privilege);
|
if (config != null)
|
{
|
m_SoulName.text = config.Name;
|
m_SoulDescription.text = UIHelper.ReplaceNewLine(config.Description);
|
m_SoulTarget.SetSprite(config.targetDescription);
|
m_SoulTarget.SetNativeSize();
|
m_GotoGetBtn.gameObject.SetActive(!treasure.IsMaxStage());
|
DisplayPrivilege(treasure);
|
|
m_SelectSoulImg.SetSprite(config.Icon);
|
m_SelectSoulImg.material = treasure.IsMaxStage() ? MaterialUtility.GetUIDefaultGraphicMaterial() : MaterialUtility.GetDefaultSpriteGrayMaterial();
|
}
|
|
var treasureConfig = ConfigManager.Instance.GetTemplate<TreasureConfig>(model.selectSoul);
|
m_SelectTreasureName.text = treasureConfig.Name;
|
|
DisplyPreview(treasure);
|
}
|
}
|
|
private void DisplayPrivilege(Treasure treasure)
|
{
|
int _pattern = -1;
|
switch (treasure.specialData.type)
|
{
|
case TreasurePrivilege.Property:
|
case TreasurePrivilege.Suit:
|
case TreasurePrivilege.Wing:
|
_pattern = 3;
|
break;
|
case TreasurePrivilege.DemonJarAtk:
|
case TreasurePrivilege.MountAtk:
|
case TreasurePrivilege.PetHp:
|
case TreasurePrivilege.Boss:
|
_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 && treasure.IsMaxStage());
|
if (_pattern == i && treasure.IsMaxStage())
|
{
|
m_TreasureSouls[i].Display(treasure.id);
|
}
|
}
|
}
|
|
private void DisplyPreview(Treasure treasure)
|
{
|
m_ContainerPreview.gameObject.SetActive(false);
|
if (treasure.IsMaxStage())
|
{
|
return;
|
}
|
switch (treasure.specialData.type)
|
{
|
case TreasurePrivilege.Wing:
|
case TreasurePrivilege.Suit:
|
case TreasurePrivilege.Property:
|
m_PropertyTitle.text = Language.Get("TreasureSoulAddPropertyTitle");
|
break;
|
case TreasurePrivilege.DemonJarAtk:
|
case TreasurePrivilege.StrengthenAdd:
|
case TreasurePrivilege.MountAtk:
|
case TreasurePrivilege.PetHp:
|
case TreasurePrivilege.Boss:
|
m_PropertyTitle.text = Language.Get("TreasureSoulGetPropertyTitle");
|
break;
|
}
|
var specialData = treasure.specialData;
|
for (int i = 0; i < propertys.Count; i++)
|
{
|
propertys[i].gameObject.SetActive(false);
|
}
|
switch (specialData.type)
|
{
|
case TreasurePrivilege.Property:
|
var _index = 0;
|
m_ContainerPreview.gameObject.SetActive(true);
|
foreach (var _key in specialData.propertyDict.Keys)
|
{
|
var _value = specialData.propertyDict[_key];
|
propertys[_index].gameObject.SetActive(true);
|
propertys[_index].DisplayUpper(_key, _value);
|
_index++;
|
}
|
break;
|
case TreasurePrivilege.Suit:
|
var percentSuit = (float)specialData.propertyDict[87] / 10000;
|
var dict = suitModel.GetActiveSuitAttr();
|
var _suitIndex = 0;
|
foreach (var _key in dict.Keys)
|
{
|
var propertyConfig = ConfigManager.Instance.GetTemplate<PlayerPropertyConfig>(_key);
|
if (propertyConfig == null || propertyConfig.type != 1)
|
{
|
continue;
|
}
|
propertys[_suitIndex].gameObject.SetActive(true);
|
propertys[_suitIndex].DisplayUpper(_key, (int)(percentSuit * dict[_key]));
|
_suitIndex++;
|
}
|
m_ContainerPreview.gameObject.SetActive(_suitIndex > 0);
|
break;
|
case TreasurePrivilege.Wing:
|
var percentWing = (float)specialData.propertyDict[86] / 10000;
|
var itemModel = pack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retWing);
|
m_ContainerPreview.gameObject.SetActive(itemModel != null);
|
if (itemModel != null)
|
{
|
var itemConfig = ConfigManager.Instance.GetTemplate<ItemConfig>(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];
|
}
|
}
|
propertys[0].gameObject.SetActive(true);
|
propertys[0].Display(6, (int)(value * percentWing));
|
}
|
break;
|
case TreasurePrivilege.DemonJarAtk:
|
case TreasurePrivilege.PetHp:
|
case TreasurePrivilege.MountAtk:
|
case TreasurePrivilege.Boss:
|
var index = 0;
|
m_ContainerPreview.gameObject.SetActive(true);
|
foreach (var _key in specialData.propertyDict.Keys)
|
{
|
var _value = specialData.propertyDict[_key] * (specialData.presentGetCount / specialData.progress);
|
if (_value <= 0)
|
{
|
m_ContainerPreview.gameObject.SetActive(false);
|
break;
|
}
|
propertys[index].gameObject.SetActive(true);
|
propertys[index].DisplayUpper(_key, _value);
|
index++;
|
}
|
break;
|
case TreasurePrivilege.StrengthenAdd:
|
var configs = ConfigManager.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 < propertys.Count; i++)
|
{
|
propertys[i].gameObject.SetActive(i < config.attType.Length);
|
if (i < config.attType.Length)
|
{
|
propertys[i].DisplayUpper(config.attType[i], config.attValue[i]);
|
}
|
}
|
}
|
break;
|
}
|
}
|
|
int Compare(int x, int y)
|
{
|
//Treasure treasure_x;
|
//Treasure treasure_y;
|
//if (model.TryGetTreasure(x, out treasure_x) && model.TryGetTreasure(y, out treasure_y))
|
//{
|
// var stage_x = treasure_x.treasureStages[treasure_x.StageCount - 1];
|
// var stage_y = treasure_y.treasureStages[treasure_y.StageCount - 1];
|
// bool awaking_x = PlayerDatas.Instance.baseData.LV >= stage_x.limitLevel && !treasure_x.IsMaxStage();
|
// bool awaking_y = PlayerDatas.Instance.baseData.LV >= stage_y.limitLevel && !treasure_y.IsMaxStage();
|
// if (awaking_x != awaking_y)
|
// {
|
// return -awaking_x.CompareTo(awaking_y);
|
// }
|
// bool awoke_x = treasure_x.IsMaxStage();
|
// bool awoke_y = treasure_y.IsMaxStage();
|
// if (awoke_x != awoke_y)
|
// {
|
// return -awoke_x.CompareTo(awoke_y);
|
// }
|
//}
|
return x.CompareTo(y);
|
}
|
|
public 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;
|
}
|
}
|
|
}
|
|
|
|
|