//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, September 08, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using vnxbqy.UI;
|
|
//灵兽魂石
|
namespace vnxbqy.UI
|
{
|
|
public class PetStoneTipsWin : Window,SecondWindowInterface
|
{
|
[SerializeField] ScrollerController m_ScrollerController;
|
[SerializeField] GameObject m_Text_Power;
|
[SerializeField] Text m_PowerNum;
|
private Dictionary<int, int> tag_Item = new Dictionary<int, int>();
|
Dictionary<string, ItemConfig> tagCIM = new Dictionary<string, ItemConfig>();
|
|
private List<int> ListID = new List<int>();
|
|
PackModel _playerPack;
|
PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
|
|
#region Built-in
|
PetModel m_petModel;
|
PetModel petmodel { get { return m_petModel ?? (m_petModel = ModelCenter.Instance.GetModel<PetModel>()); } }
|
|
RoleParticularModel m_RoleParticularModel;
|
RoleParticularModel roleParticularModel { get { return m_RoleParticularModel ?? (m_RoleParticularModel = ModelCenter.Instance.GetModel<RoleParticularModel>()); } }
|
|
public Button close { get; set; }
|
|
protected override void BindController()
|
{
|
if (this is SecondWindowInterface)
|
{
|
var frame = this.GetComponentInChildren<SecondFrameLoader2>();
|
frame.Create();
|
close = frame.GetComponentInChildren<Button>();
|
}
|
|
tag_Item = petmodel._TagPetItem;
|
}
|
|
protected override void AddListeners()
|
{
|
close.onClick.AddListener(CloseButtonHS);
|
}
|
|
protected override void OnPreOpen()
|
{
|
GetPetPower();
|
ListId();
|
ListSortId();//排序
|
m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
|
OnCreateGridLineCell(m_ScrollerController);
|
m_ScrollerController.JumpIndex(JumpIndex());
|
}
|
|
|
|
protected override void OnAfterOpen()
|
{
|
|
PetModel.Event_Ha339 += HA339;
|
roleParticularModel.PowerUpdate += PowerUpdate;
|
}
|
|
protected override void OnPreClose()
|
{
|
m_petModel.PetStoneItemId = 0;
|
m_ScrollerController.OnRefreshCell -= OnRefreshGridCell;
|
PetModel.Event_Ha339 -= HA339;
|
roleParticularModel.PowerUpdate -= PowerUpdate;
|
}
|
|
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void PowerUpdate()
|
{
|
GetPetPower();
|
}
|
private void GetPetPower()
|
{
|
ulong PetPower = roleParticularModel.GetFuncFightPower((int)FuncPowerType.PetSoul);
|
if (PetPower > 0)
|
{
|
m_Text_Power.SetActive(true);
|
m_PowerNum.SetActive(true);
|
m_PowerNum.text = "+" + PetPower;
|
}
|
else
|
{
|
m_Text_Power.SetActive(false);
|
m_PowerNum.SetActive(false);
|
}
|
}
|
#endregion
|
|
private void OnCreateGridLineCell(ScrollerController gridCtrl)
|
{
|
gridCtrl.Refresh();
|
|
for (int i = 0; i < ListID.Count; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, ListID[i]);
|
}
|
gridCtrl.Restart();
|
}
|
|
private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
|
{
|
int _id = cell.index;
|
MountStoneItem _MountStoneItem = cell.GetComponent<MountStoneItem>();
|
ItemConfig _item = ItemConfig.Get(_id.ToString());
|
if (ItemConfig.Get(_id) == null)
|
return;
|
_MountStoneItem.m_BGMItem.SetItemBackGround(_item.ItemColor);
|
_MountStoneItem.Item.SetSprite(_item.IconKey);
|
int hs_number = playerPack.GetItemCountByID(PackType.Item, _id);//魂石数量
|
List<int> bagIndex = null;
|
if (hs_number <= 0)
|
{
|
_MountStoneItem.UserBtn.interactable = false;
|
_MountStoneItem.UserBtn.GetComponent<ImageEx>().gray = true;
|
_MountStoneItem.m_UseTxt.color = UIHelper.GetUIColor(TextColType.White);
|
_MountStoneItem.ItemNum.text = " <color=#ff2828>" + hs_number.ToString() + "</color>" + "/1";
|
}
|
else
|
{
|
_MountStoneItem.UserBtn.interactable = true;
|
_MountStoneItem.UserBtn.GetComponent<ImageEx>().gray = false;
|
_MountStoneItem.m_UseTxt.color = UIHelper.GetUIColor(TextColType.NavyBrown);
|
_MountStoneItem.ItemNum.text = hs_number.ToString() + "/1";
|
bagIndex = playerPack.GetSinglePack(PackType.Item).GetItemIndexsAppointedCount(_id, 1);
|
}
|
int _maxuse = AttrFruitConfig.Get(_id).basicUseLimit;
|
_MountStoneItem.PetExpNum.text = tag_Item[_id].ToString() + "/" + _maxuse.ToString();
|
_MountStoneItem.Slider.value = (float)Math.Round((float)tag_Item[_id] / _maxuse, 2, MidpointRounding.AwayFromZero);
|
SpiritBeastsText(_id.ToString(), _MountStoneItem.Some_text, tag_Item[_id]);
|
if (tag_Item[_id] >= _maxuse)
|
_MountStoneItem.UserBtn.SetActive(false);
|
else
|
_MountStoneItem.UserBtn.SetActive(true);
|
_MountStoneItem.ItemButton.GetComponent<Button>().RemoveAllListeners();
|
_MountStoneItem.ItemButton.GetComponent<Button>().AddListener(() =>
|
{
|
ItemTipUtility.Show(_item.ID);
|
});
|
|
//一次使用物品多个,不算多格子
|
int useCnt = 0;
|
var item = playerPack.GetItemByID(PackType.Item, _id);
|
if (item != null)
|
{
|
|
useCnt = Math.Min(_maxuse - tag_Item[_id], item.count);
|
}
|
_MountStoneItem.UserBtn.RemoveAllListeners();
|
_MountStoneItem.UserBtn.AddListener(() =>
|
{
|
if (item == null || useCnt < 0)
|
{
|
return;
|
}
|
ItemOperateUtility.Instance.UseItem(item.guid, useCnt);
|
});
|
|
}
|
|
void CloseButtonHS()//灵兽魂石关闭
|
{
|
Close();
|
}
|
|
void SpiritBeastsText(string _id, Text _text, int _max)//兽魂文本的判定赋值
|
{
|
Dictionary<int, int> _dic = new Dictionary<int, int>();
|
var config = ItemConfig.Get(_id);
|
|
if (config.Effect1 != 0)
|
{
|
_dic.Add(config.Effect1, config.EffectValueA1);
|
}
|
if (config.Effect2 != 0)
|
{
|
_dic.Add(config.Effect2, config.EffectValueA2);
|
}
|
if (config.Effect3 != 0)
|
{
|
_dic.Add(config.Effect3, config.EffectValueA3);
|
}
|
if (config.Effect4 != 0)
|
{
|
_dic.Add(config.Effect4, config.EffectValueA4);
|
}
|
if (config.Effect5 != 0)
|
{
|
_dic.Add(config.Effect5, config.EffectValueA5);
|
}
|
|
if (_dic.Count == 0)
|
return;
|
|
int textNumber = 0;
|
if (_dic.Count > 2)
|
{
|
string val = string.Empty;
|
foreach (var item in _dic.Keys)
|
{
|
textNumber += 1;
|
var propertyConfig = PlayerPropertyConfig.Get(item);
|
val += propertyConfig.Name;
|
|
switch (propertyConfig.ISPercentage)
|
{
|
case 0:
|
val += "<color=#109d06> +" + (_dic[item] * _max) + " </color>";
|
break;
|
case 1:
|
val += "<color=#109d06> +" + (_dic[item] * _max) / 100 + "% </color>";
|
break;
|
case 2:
|
val += "<color=#109d06> +" + (_dic[item] * _max) + "% </color>";
|
break;
|
}
|
|
if (textNumber == 2)
|
{
|
val += "\n";
|
}
|
|
}
|
_text.text = val;
|
}
|
else
|
{
|
string val = string.Empty;
|
foreach (var item in _dic.Keys)
|
{
|
var propertyConfig = PlayerPropertyConfig.Get(item);
|
val += propertyConfig.Name;
|
|
switch (propertyConfig.ISPercentage)
|
{
|
case 0:
|
val += "<color=#009f3c> +" + (_dic[item] * _max) + " </color>";
|
break;
|
case 1:
|
val += "<color=#009f3c> +" + (_dic[item] * _max) / 100 + "% </color>";
|
break;
|
case 2:
|
val += "<color=#009f3c> +" + (_dic[item] * _max) + "% </color>";
|
break;
|
}
|
}
|
_text.text = val;
|
}
|
_dic.Clear();
|
}
|
|
void HA339(HA339_tagMCAttrFruitEatCntList info)
|
{
|
tag_Item = petmodel._TagPetItem;
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
}
|
|
|
private void ListId()
|
{
|
if (ListID.Count <= 0)
|
{
|
foreach (var key in petmodel._TagPetItem.Keys)
|
{
|
ListID.Add(key);
|
}
|
}
|
}
|
private int JumpIndex()
|
{
|
SuccessConfig successConfig = SuccessConfig.Get(AchievementGoto.guideAchievementId);
|
if (successConfig != null)
|
{
|
int[] StoneId = successConfig.Condition;
|
if (StoneId.Length > 0)
|
{
|
if (ListID.Contains(StoneId[0]))
|
{
|
if (playerPack.GetItemCountByID(PackType.Item, StoneId[0]) <= 0)
|
{
|
SysNotifyMgr.Instance.ShowTip("PetStone_1");
|
}
|
return ListID.IndexOf(StoneId[0]);
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
else
|
{
|
if (ListID.Contains(m_petModel.PetStoneItemId))
|
{
|
return ListID.IndexOf(m_petModel.PetStoneItemId);
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
}
|
else
|
{
|
if (ListID.Contains(m_petModel.PetStoneItemId))
|
{
|
return ListID.IndexOf(m_petModel.PetStoneItemId);
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
}
|
|
private void ListSortId()//排序
|
{
|
ListID.Sort(Compare);
|
}
|
|
private int Compare(int x, int y)
|
{
|
int index_x = MaxSortIndex(x);
|
int index_y = MaxSortIndex(y);
|
bool havex = IsUse(x);
|
bool havey = IsUse(y);
|
bool IsFull_x = IsFull(x);
|
bool IsFull_y = IsFull(y);
|
if (havex.CompareTo(havey) != 0)
|
{
|
return -havex.CompareTo(havey);
|
}
|
if (IsFull_x.CompareTo(IsFull_y) != 0)
|
{
|
return -IsFull_x.CompareTo(IsFull_y);
|
}
|
if (index_x.CompareTo(index_y) != 0)
|
{
|
return -index_x.CompareTo(index_y);
|
}
|
if (x.CompareTo(y) != 0)
|
{
|
return x.CompareTo(y);
|
}
|
return 1;
|
}
|
private int MaxSortIndex(int sortId)
|
{
|
int index = 0;
|
var AttrFruitconfig = AttrFruitConfig.Get(sortId);
|
if (AttrFruitconfig != null)
|
{
|
index = AttrFruitconfig.Sort;
|
}
|
return index;
|
}
|
private bool IsUse(int Id)
|
{
|
int hs_number = playerPack.GetItemCountByID(PackType.Item, Id);//魂石数量
|
int _maxuse = AttrFruitConfig.Get(Id.ToString()).basicUseLimit;
|
if (tag_Item.ContainsKey(Id))
|
{
|
if (hs_number > 0 && _maxuse > tag_Item[Id])
|
{
|
return true;
|
}
|
|
}
|
return false;
|
}
|
private bool IsFull(int Id)
|
{
|
bool IsBool = true;
|
int _maxuse = AttrFruitConfig.Get(Id.ToString()).basicUseLimit;
|
if (tag_Item.ContainsKey(Id))
|
{
|
if (tag_Item[Id] >= _maxuse)
|
{
|
IsBool = false;
|
}
|
}
|
return IsBool;
|
}
|
}
|
|
}
|
|
|
|
|