//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, January 30, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class JadeDynastySelectGemWin : Window
|
{
|
[SerializeField] ScrollerController m_SrollerControl;
|
[SerializeField] Button m_Strike;
|
[SerializeField] Button m_Close;
|
|
JadeDynastyGemModel model
|
{
|
get { return ModelCenter.Instance.GetModel<JadeDynastyGemModel>(); }
|
}
|
|
PlayerPackModel playerPack
|
{
|
get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); }
|
}
|
|
GemModel gemModel
|
{
|
get { return ModelCenter.Instance.GetModel<GemModel>(); }
|
}
|
|
List<ItemModel> gemItems = new List<ItemModel>();
|
|
public static int equipPlace = 0;
|
public static int equipHole = 0;
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_SrollerControl.OnRefreshCell += OnRefreshCell;
|
m_Close.AddListener(OnClose);
|
m_Strike.AddListener(OnStrikeBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
Display();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
void Display()
|
{
|
var itemId = 0;
|
var bind = 0;
|
JadeDynastyGemModel.GemEquipData equipData;
|
var existStone = model.TryGetEquipGems(equipPlace, out equipData);
|
if (existStone)
|
{
|
itemId = (int)equipData.items[equipHole];
|
bind = equipData.binds[equipHole];
|
}
|
|
var itemModel = playerPack.GetItemModelByIndex(PackType.JadeDynastyEquip, equipPlace);
|
m_SrollerControl.Refresh();
|
m_Strike.gameObject.SetActive(itemId != 0);
|
var type = model.GetGemType(equipPlace);
|
SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.JadeDynastyItem);
|
List<ItemModel> _list = null;
|
singlePack.GetItemCountByType(JadeDynastyGemModel.GEMTYPE, out _list);
|
GetGemByEffectType(_list, type);
|
if (itemId != 0 && !model.IsHightestLevelGem(itemId))
|
{
|
CellInfo _cellInfo = CellInfo.Default;
|
_cellInfo.infoInt1 = itemId;
|
m_SrollerControl.AddCell(ScrollerDataType.Header, 0, OnGemItemClick, _cellInfo);
|
}
|
if (itemId != 0 && model.IsHightestLevelGem(itemId))
|
{
|
CellInfo _cellInfo = CellInfo.Default;
|
_cellInfo.infoInt1 = (int)itemId;
|
_cellInfo.infoInt2 = bind;
|
m_SrollerControl.AddCell(ScrollerDataType.Extra2, 0, _cellInfo);
|
}
|
for (int i = 0; i < gemItems.Count; i++)
|
{
|
ItemModel _item = gemItems[i];
|
CellInfo _cellInfo = CellInfo.Default;
|
_cellInfo.infoInt1 = _item.itemId;
|
_cellInfo.infoInt2 = _item.itemInfo.ItemPlace;
|
_cellInfo.SetInfo(_item.itemInfo.IsBind);
|
_cellInfo.infoStr1 = _item.itemInfo.ItemCount.ToString();
|
m_SrollerControl.AddCell(ScrollerDataType.Normal, i, OnGemItemClick, _cellInfo);
|
}
|
if (itemId == 0 && gemModel.gemShopIds.ContainsKey(type))
|
{
|
CellInfo _cellInfo = CellInfo.Default;
|
ItemConfig _itemCfg = ItemConfig.GetGemDataByLevelAndType(1, type);
|
_cellInfo.infoInt1 = _itemCfg.ID;
|
m_SrollerControl.AddCell(ScrollerDataType.Tail, 0, OnGemItemClick, _cellInfo);
|
}
|
if (gemModel.gemGetWays.ContainsKey(type))
|
{
|
var list = gemModel.gemGetWays[type];
|
for (int i = 0; i < list.Count; i++)
|
{
|
if (list[i] == 0)
|
{
|
continue;
|
}
|
CellInfo _cellInfo = CellInfo.Default;
|
_cellInfo.infoInt1 = list[i];
|
m_SrollerControl.AddCell(ScrollerDataType.Extra1, i, OnGemItemClick, _cellInfo);
|
}
|
}
|
m_SrollerControl.Restart();
|
}
|
|
void OnGemItemClick(CellView cell)
|
{
|
switch (cell.type)
|
{
|
case ScrollerDataType.Header:
|
CloseImmediately();
|
OnLevelUpGemBtn();
|
break;
|
case ScrollerDataType.Normal:
|
OnInlayGem(cell.info);
|
break;
|
case ScrollerDataType.Tail:
|
CloseImmediately();
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.StoreFunc3);
|
break;
|
case ScrollerDataType.Extra1:
|
if (cell.info.HasValue)
|
{
|
CloseImmediately();
|
var config = GetItemWaysConfig.Get(cell.info.Value.infoInt1);
|
WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)config.OpenpanelId);
|
}
|
break;
|
}
|
}
|
|
void OnStrikeBtn()
|
{
|
ItemModel _itemModel = playerPack.GetItemModelByIndex(PackType.JadeDynastyEquip, equipPlace);
|
if (_itemModel == null)
|
{
|
return;
|
}
|
model.inlayHole = -1;
|
CA305_tagCMEquipStonePick _pak = new CA305_tagCMEquipStonePick();
|
_pak.EquipIndex = (byte)equipPlace;
|
_pak.HoleIndex = equipHole == 3 ? (byte)10 : (byte)equipHole;
|
GameNetSystem.Instance.SendInfo(_pak);
|
CloseImmediately();
|
}
|
|
void OnLevelUpGemBtn()
|
{
|
ItemModel _itemModel = playerPack.GetItemModelByIndex(PackType.JadeDynastyEquip, equipPlace);
|
if (_itemModel == null)
|
{
|
return;
|
}
|
JadeDynastyGemModel.GemEquipData equipData;
|
var existGem = model.TryGetEquipGems(equipPlace, out equipData);
|
if (!existGem)
|
{
|
return;
|
}
|
int id = (int)equipData.items[equipHole];
|
if (model.IsHightestLevelGem(id))
|
{
|
SysNotifyMgr.Instance.ShowTip("GemFullLevelError");
|
return;
|
}
|
GemLevelUpWin.equipHole = equipHole;
|
GemLevelUpWin.equipPlace = equipPlace;
|
GemLevelUpWin.packType = PackType.JadeDynastyEquip;
|
WindowCenter.Instance.Open<GemLevelUpWin>();
|
}
|
|
void OnInlayGem(CellInfo? info)
|
{
|
ItemModel _itemModel = playerPack.GetItemModelByIndex(PackType.JadeDynastyEquip, equipPlace);
|
if (_itemModel == null)
|
{
|
return;
|
}
|
model.inlayHole = equipHole;
|
CA304_tagCMEquipEnchase _pak = new CA304_tagCMEquipEnchase();
|
_pak.HoleIndex = equipHole == 3 ? (byte)10 : (byte)equipHole;
|
_pak.StoneIndex = (byte)info.Value.infoInt2;
|
_pak.EquipIndex = (byte)equipPlace;
|
GameNetSystem.Instance.SendInfo(_pak);
|
CloseClick();
|
}
|
|
void GetGemByEffectType(List<ItemModel> list, int type)
|
{
|
gemItems.Clear();
|
if (list == null || list.Count == 0)
|
{
|
return;
|
}
|
for (int i = 0; i < list.Count; i++)
|
{
|
ItemModel _itemModel = list[i];
|
ItemConfig _itemCfg = ItemConfig.Get(_itemModel.itemId);
|
if (_itemCfg.EffectValueA1 == type)
|
{
|
gemItems.Add(_itemModel);
|
}
|
}
|
gemItems.Sort(Compare);
|
}
|
|
private int Compare(ItemModel x, ItemModel y)
|
{
|
ItemConfig cfgx = ItemConfig.Get((int)x.itemId);
|
ItemConfig cfgy = ItemConfig.Get((int)y.itemId);
|
if (cfgx.EffectValueB1.CompareTo(cfgy.EffectValueB1) != 0)
|
{
|
return -cfgx.EffectValueB1.CompareTo(cfgy.EffectValueB1);
|
}
|
return x.itemInfo.ItemPlace.CompareTo(y.itemInfo.ItemPlace);
|
}
|
|
private void OnClose()
|
{
|
model.inlayHole = -1;
|
CloseImmediately();
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
switch (type)
|
{
|
case ScrollerDataType.Header:
|
{
|
if (!cell.info.HasValue)
|
{
|
return;
|
}
|
GemLevelUpCell _levelUpCell = cell as GemLevelUpCell;
|
ItemConfig _itemCfg = ItemConfig.Get(cell.info.Value.infoInt1);
|
ItemConfig _nextCfg = ItemConfig.GetGemDataByLevelAndType(_itemCfg.EffectValueB1, _itemCfg.EffectValueA1);
|
if (_nextCfg != null && _itemCfg.Type == _nextCfg.Type && _itemCfg.EffectValueA1 == _nextCfg.EffectValueA1)
|
{
|
_levelUpCell.itemBG.SetItemBackGround(_nextCfg.ItemColor);
|
_levelUpCell.itemIcon.SetSprite(_nextCfg.IconKey);
|
}
|
_levelUpCell.nameText.text = string.Empty;
|
PlayerPropertyConfig _propertyCfg = null;
|
for (int i = _itemCfg.EffectValueB1 + 1; i <= gemModel.gemHighestLevelDict[_itemCfg.EffectValueA1]; i++)
|
{
|
_nextCfg = ItemConfig.GetGemDataByLevelAndType(i, _itemCfg.EffectValueA1);
|
if (_nextCfg == null)
|
{
|
continue;
|
}
|
if (_itemCfg.Effect2 == 0 && _nextCfg.Effect2 != 0)
|
{
|
_propertyCfg = PlayerPropertyConfig.Get(_nextCfg.Effect2);
|
break;
|
}
|
else if (_itemCfg.Effect3 == 0 && _nextCfg.Effect3 != 0)
|
{
|
_propertyCfg = PlayerPropertyConfig.Get(_nextCfg.Effect3);
|
break;
|
}
|
else if (_itemCfg.Effect4 == 0 && _nextCfg.Effect4 != 0)
|
{
|
_propertyCfg = PlayerPropertyConfig.Get(_nextCfg.Effect4);
|
break;
|
}
|
}
|
if (_propertyCfg != null)
|
{
|
_levelUpCell.nameText.text = Language.Get("GemNewAttr", _nextCfg.EffectValueB1, _propertyCfg.Name);
|
}
|
else
|
{
|
_levelUpCell.nameText.text = Language.Get("GemPropertyUpper");
|
}
|
_levelUpCell.redpoint.redpointId = JadeDynastyGemModel.REDPOINTID * GemModel.REDPOINT_INTERVAL + 30 + equipHole;
|
}
|
break;
|
case ScrollerDataType.Normal:
|
{
|
if (cell.info.HasValue)
|
{
|
GemEquipCell _gemEquipCell = cell as GemEquipCell;
|
ItemConfig cfg = ItemConfig.Get(cell.info.Value.infoInt1);
|
if (cfg != null)
|
{
|
_gemEquipCell.itemBG.SetItemBackGround(cfg.ItemColor);
|
_gemEquipCell.itemIcon.SetSprite(cfg.IconKey);
|
if (cell.info.HasValue)
|
{
|
InlaidPanel.ShowGemInfo(_gemEquipCell.property, cell.info.Value.infoInt1, false);
|
}
|
_gemEquipCell.count.text = cell.info.Value.infoStr1;
|
_gemEquipCell.bind.gameObject.SetActive(cell.info.Value.infoInt3 == 1);
|
_gemEquipCell.redpoint.gameObject.SetActive(IsBestGem(cfg.ID, gemItems)
|
&& model.GetHoleRedpoint(equipPlace, equipHole)
|
&& model.CheckEquipHole(equipPlace, equipHole, cfg.ID)
|
&& cell.index == 0);
|
}
|
}
|
}
|
break;
|
case ScrollerDataType.Tail:
|
{
|
if (cell.info.HasValue)
|
{
|
var _gemShopCell = cell as GemShopCell;
|
ItemConfig cfg = ItemConfig.Get(cell.info.Value.infoInt1);
|
if (cfg != null)
|
{
|
_gemShopCell.itemBG.SetItemBackGround(cfg.ItemColor);
|
_gemShopCell.itemIcon.SetSprite(cfg.IconKey);
|
FuncConfigConfig func = FuncConfigConfig.Get(string.Format("GemType{0}", cfg.EffectValueA1));
|
if (func != null)
|
{
|
_gemShopCell.nameText.text = func.Numerical2;
|
}
|
}
|
}
|
}
|
break;
|
case ScrollerDataType.Extra1:
|
{
|
if (cell.info.HasValue)
|
{
|
var gemGetWayCell = cell as GemGetWayCell;
|
gemGetWayCell.Display(model.GetGemType(equipPlace), cell.info.Value.infoInt1);
|
}
|
}
|
break;
|
case ScrollerDataType.Extra2:
|
{
|
if (cell.info.HasValue)
|
{
|
var _gemFlauntCell = cell as GemFlauntCell;
|
_gemFlauntCell.Display(cell.info.Value.infoInt1, cell.info.Value.infoInt2 == 1);
|
}
|
}
|
break;
|
}
|
}
|
|
bool IsBestGem(int itemId, List<ItemModel> list)
|
{
|
var config = ItemConfig.Get(itemId);
|
for (int i = 0; i < list.Count; i++)
|
{
|
var compareItem = list[i];
|
var compareConfig = ItemConfig.Get(compareItem.itemId);
|
if (compareConfig.EffectValueB1 > config.EffectValueB1)
|
{
|
return false;
|
}
|
}
|
return true;
|
}
|
}
|
|
}
|
|
|
|
|