//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, February 28, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI {
|
|
public class RealmPreviewWin : Window
|
{
|
[SerializeField] ScrollerController m_Controller;
|
[SerializeField] Image m_SelectRealmIcon;
|
[SerializeField] RealmPropertyCell m_SelectRealmProperty;
|
[SerializeField] Button m_BtnClose;
|
int m_SelectRealm = 0;
|
#region Built-in
|
protected override void BindController()
|
{
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
}
|
|
protected override void AddListeners()
|
{
|
m_BtnClose.onClick.AddListener(CloseClick);
|
}
|
|
protected override void OnPreOpen()
|
{
|
var _cfgs = RealmConfig.GetValues();
|
var _index = _cfgs.FindIndex((x) =>
|
{
|
return x.Lv == PlayerDatas.Instance.baseData.realmLevel;
|
});
|
m_SelectRealm = Mathf.Max(1, _cfgs[_index].Lv);
|
if (m_Controller.GetNumberOfCells(m_Controller.m_Scorller) == 0)
|
{
|
m_Controller.Refresh();
|
for (int i = 0; i < _cfgs.Count; i++)
|
{
|
if (_cfgs[i].Lv == 0)
|
{
|
continue;
|
}
|
m_Controller.AddCell(ScrollerDataType.Header, _cfgs[i].Lv,OnRealmClick);
|
}
|
m_Controller.Restart();
|
}
|
else
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
m_Controller.JumpIndex(Mathf.Max(0, _index - 3));
|
UpdateRealmProperty();
|
}
|
|
private void OnRealmClick(CellView cell)
|
{
|
m_SelectRealm = cell.index;
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
UpdateRealmProperty();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
private void UpdateRealmProperty()
|
{
|
m_SelectRealmProperty.Display(m_SelectRealm, false);
|
var _realmCfg = RealmConfig.Get(m_SelectRealm);
|
m_SelectRealmIcon.SetSprite(_realmCfg.Img);
|
m_SelectRealmIcon.SetNativeSize();
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
var _realmCell = cell as RealmCell;
|
_realmCell.Display(m_SelectRealm == cell.index, cell.index);
|
}
|
|
}
|
|
}
|
|
|
|
|