using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
///
/// 英雄列表滑动功能组件
///
public class UI_HeroScrollFlowComponment : MonoBehaviour
{
///
/// 操作控制层
///
public UI_ScrollFlow mScrollFlow;
///
/// 模板
///
public GameObject mPrefab;
///
/// 子对象节点
///
public GameObject mNodes;
///
/// 是否显示 可以上阵或者详细信息的操作功能
///
private bool IsShowBattleOrQueryButton = false;
///
/// 是否要接收 数据发生变化的事件
///
private bool IsNeedReceiveDataChangedEvent = false;
///
/// 初始化UI
///
/// 是否显示 可以上阵或者详细信息的操作功能
/// 是否要接收 数据发生变化的事件
public void InitComponments(bool isShowOperateButton = false,bool isNeedReceiveDataChangedEvent= false)
{
this.IsShowBattleOrQueryButton = isShowOperateButton;
this.IsNeedReceiveDataChangedEvent = isNeedReceiveDataChangedEvent;
mPrefab = this.transform.Find("prefab").gameObject;
mPrefab.SetActive(false);
mNodes = this.transform.Find("Nodes").gameObject;
mScrollFlow = mNodes.GetComponent();
if (mScrollFlow == null)
{
AssemblyHelper.Instance.BindScript("UI_ScrollFlow", mNodes);
mScrollFlow = mNodes.GetComponent();
}
mNodes.GetComponent().anchoredPosition = new Vector2(-250, 0);
mScrollFlow.InitHeroComponmentsSetting();
mScrollFlow.goItemPrefab = mPrefab;
mScrollFlow.nodeContent = mNodes.GetComponent();
CreateElement();
mScrollFlow.EventRefreshCardState += RefreshCardState;
}
///
/// 刷新卡牌的状态
///
/// 是否选中
/// 卡牌
private void RefreshCardState(bool isSelected, UI_ScrollFlow_Item t)
{
if (t != null && t.gameObject != null)
{
UI_HeroMustCardElement go = t.gameObject.GetComponent();
go.RefreshSelectedState(isSelected);
if (isSelected)
{
_curHeroUID = go.mData;
if (Action_ChangeCurrentCard != null)
{
Action_ChangeCurrentCard(go.mData, t.gameObject);
}
}
}
}
///
/// 销毁
///
private void OnDestory()
{
mScrollFlow.EventRefreshCardState -= RefreshCardState;
}
///
/// 创建元素
///
private void CreateElement()
{
mScrollFlow.onInitializeItem = onInitializeItem;
mScrollFlow.Init(0);
}
///
/// 元素初始化
///
/// 元素对象
/// 数据索引
private void onInitializeItem(GameObject go, int dataIndex)
{
UI_HeroMustCardElement element = go.GetComponent();
if (null == element)
{
AssemblyHelper.Instance.BindScript("UI_HeroMustCardElement", go);
element = go.GetComponent();
}
element.Init(this.IsNeedReceiveDataChangedEvent, this.IsShowBattleOrQueryButton);
element.Action_QueryButton = OnClicked_QueryButton;
element.Action_SelectedSomeCard = OnClicked_Select;
element.Action_UseButton = OnClicked_UseButton;
////element.Action_UNLockButton = OnClicked_LockButton;
element.Action_BuyButton = OnClicked_BuyHeroButton;
element.Action_GetMethodButton = OnClicked_GetMethodButton;
if (dataIndex >= 0 && dataIndex < mDataList.Count)
{
element.SetData(mDataList[dataIndex]);
////LogHelper.LogError("onInitializeItem:::" + dataIndex + " uid::" + mDataList[dataIndex]);
if (elements.ContainsKey(dataIndex))
{
elements[dataIndex] = go;
}
else
{
elements.Add(dataIndex, go);
}
}
}
///
/// 数据列表
///
private List mDataList = new List();
///
/// 刷新元素
///
/// 英雄列表
/// 是否重设位置
public void SetHeroData(List heroUIDList, bool bResetPos = false)
{
mDataList = new List();
elements = new Dictionary();
mDataList.AddRange(heroUIDList);
mScrollFlow.Hero_DataChanged(heroUIDList.Count, bResetPos);
if (heroUIDList.Count == 0)
{
mScrollFlow.enabled = false;
_curHeroUID = string.Empty;
}
else
{
mScrollFlow.enabled = true;
}
}
///
/// 子对象集合
///
private Dictionary elements = new Dictionary();
///
/// 当前英雄UID
///
public string _curHeroUID = string.Empty;
///
/// 获得当前英雄UID
///
/// string
internal string GetCurHeroUID()
{
return _curHeroUID;
}
///
/// 刷新卡牌锁定以及上阵状态
///
internal void RefeshHeroCardLockAndFightState()
{
foreach (GameObject xx in elements.Values)
{
UI_HeroMustCardElement ele = xx.GetComponent();
bool isInTeam = UserProxy.Instance.player.heroTeamConfig.CheckSomeHeroBeUsed(ele.mHeroUIDData);
ele.RefreshCardLockAndFightState(isInTeam);
}
}
///
/// 更改当前选择的卡牌
///
internal Action Action_ChangeCurrentCard;
///
/// 点击卡牌事件
///
internal Action Action_SelectedSomeCard;
///
/// 点击卡牌上阵事件
///
internal Action Action_UseButton;
///
/// 点击卡牌查询事件
///
internal Action Action_QueryButton;
///
/// 点击卡牌 购买按钮
///
public Action Action_BuyButton;
///
/// 点击卡牌 未解锁按钮
///
public Action Action_UNLockButton;
///
/// 点击卡牌 获取按钮
///
public Action Action_GetMethodButton;
///
/// 查询
///
/// 按钮对象
private void OnClicked_QueryButton(GameObject go)
{
UI_HeroMustCardElement ele = go.GetComponent();
if (ele == null)
{
return;
}
if (Action_QueryButton != null)
{
Action_QueryButton(ele.mData, go);
}
}
///
/// 上阵
///
/// 按钮对象
private void OnClicked_UseButton(GameObject go)
{
UI_HeroMustCardElement ele = go.GetComponent();
if (ele == null)
{
return;
}
if (Action_UseButton != null)
{
Action_UseButton(ele.mData, go);
}
}
///
/// 未解锁按钮
///
/// 按钮对象
private void OnClicked_LockButton(GameObject go)
{
UI_HeroMustCardElement ele = go.GetComponent();
if (ele == null)
{
return;
}
if (Action_UNLockButton != null)
{
Action_UNLockButton(ele.mData, go);
}
}
///
/// 点击 获取按钮
///
///
private void OnClicked_GetMethodButton(GameObject go)
{
UI_HeroMustCardElement ele = go.GetComponent();
if (ele == null)
{
return;
}
if (Action_GetMethodButton != null)
{
Action_GetMethodButton(ele.mData, go);
}
}
///
/// 购买 按钮
///
/// 按钮对象
private void OnClicked_BuyHeroButton(GameObject go)
{
UI_HeroMustCardElement ele = go.GetComponent();
if (ele == null)
{
return;
}
if (Action_BuyButton != null)
{
Action_BuyButton(ele.mData, go);
}
}
///
/// 点击选择
///
/// 按钮对象
private void OnClicked_Select(GameObject go)
{
UI_ScrollFlow_Item script = go.GetComponent();
if (script == null)
{
return;
}
if (mScrollFlow.Current != script)
{
mScrollFlow.ToAppointedItem(script);
}
else
{
UI_HeroMustCardElement ele = go.GetComponent();
if (ele == null)
{
return;
}
if (Action_SelectedSomeCard != null)
{
Action_SelectedSomeCard(ele.mData, go);
}
}
}
///
/// 对外的外界: 设定选中的卡牌
/// 来促使卡牌进行移动
///
///
public void OnChangeSelectData(string data)
{
if (string.IsNullOrEmpty(data))
return;
foreach (GameObject xx in elements.Values)
{
UI_HeroMustCardElement ele = xx.GetComponent();
if (ele.mData == data)
{
OnClicked_Select(ele.gameObject);
}
}
}
}