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