329 lines
11 KiB
C#
329 lines
11 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using GCGame.Table;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class OrnamentPanel : MonoBehaviour {
|
|||
|
|
|||
|
public static OrnamentPanel Instance;
|
|||
|
void Awake()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
InitPanel();
|
|||
|
}
|
|||
|
|
|||
|
void InitPanel()
|
|||
|
{
|
|||
|
//按照类型分类
|
|||
|
SortByType();
|
|||
|
InitMenuItemContainer();
|
|||
|
}
|
|||
|
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
Instance = null;
|
|||
|
ClearAllEffect();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
ShowDefaultFirst();
|
|||
|
}
|
|||
|
|
|||
|
public UIContainerBase _MenuItemContainer;
|
|||
|
public UIContainerBase _ItemContainer;
|
|||
|
public Text _LPanelTitle; //左侧标题
|
|||
|
public Text _LDescText; //左侧描述
|
|||
|
|
|||
|
public GameObject _HeadPanel;
|
|||
|
public Image _ChatBG;
|
|||
|
public Image _HeadIcon;
|
|||
|
|
|||
|
public GameObject _PopPanel;
|
|||
|
public Image _PopImage;
|
|||
|
|
|||
|
public GameObject _FootPrintPanel;
|
|||
|
|
|||
|
public GameObject _AttrPanel;
|
|||
|
private Dictionary<int, List<Tab_Ornament>> ornamentDic;
|
|||
|
private List<int> _MenuItemTypeList;
|
|||
|
private void SortByType()
|
|||
|
{
|
|||
|
ornamentDic = new Dictionary<int, List<Tab_Ornament>>();
|
|||
|
_MenuItemTypeList = new List<int>();
|
|||
|
foreach (var tab in TableManager.GetOrnament())
|
|||
|
{
|
|||
|
if (!_MenuItemTypeList.Contains(tab.Value.Type))
|
|||
|
_MenuItemTypeList.Add(tab.Value.Type);
|
|||
|
if (ornamentDic.ContainsKey(tab.Value.Type))
|
|||
|
{
|
|||
|
ornamentDic[tab.Value.Type].Add(tab.Value);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
List<Tab_Ornament> tabList = new List<Tab_Ornament>();
|
|||
|
tabList.Add(tab.Value);
|
|||
|
ornamentDic.Add(tab.Value.Type, tabList);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void InitMenuItemContainer()
|
|||
|
{
|
|||
|
_MenuItemContainer.InitContentItem(_MenuItemTypeList, OnMenuItemClick);
|
|||
|
_MenuItemContainer.SetShowItemFinishCallFun(ClickDefaultFirstMenuItem);
|
|||
|
}
|
|||
|
|
|||
|
private void ClickDefaultFirstMenuItem()
|
|||
|
{
|
|||
|
OnMenuItemClick(_MenuItemTypeList[0]);
|
|||
|
}
|
|||
|
|
|||
|
public enum OrnamentType
|
|||
|
{
|
|||
|
Head = 1,
|
|||
|
Pop,
|
|||
|
footprint
|
|||
|
}
|
|||
|
|
|||
|
private void ShowDefaultFirst()
|
|||
|
{
|
|||
|
//OnMenuItemClick(_CurSelectType);
|
|||
|
InitMenuItemContainer();
|
|||
|
}
|
|||
|
|
|||
|
private int _CurSelectType = (int)OrnamentType.Head;
|
|||
|
public void OnMenuItemClick(object initInfo)
|
|||
|
{
|
|||
|
_CurSelectType = (int)initInfo;
|
|||
|
ShowMenuItemMark();
|
|||
|
InitItemContainer();
|
|||
|
}
|
|||
|
|
|||
|
private void ShowMenuItemMark()
|
|||
|
{
|
|||
|
_MenuItemContainer.ForeachActiveItem<OrnamentMenuItem>((item)=> {
|
|||
|
item.IsShowMark(item._CurType == _CurSelectType);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
private Tab_Ornament _FirstItem = null;
|
|||
|
private void InitItemContainer()
|
|||
|
{
|
|||
|
if(ornamentDic.ContainsKey(_CurSelectType))
|
|||
|
{
|
|||
|
var tabList = ornamentDic[_CurSelectType];
|
|||
|
|
|||
|
if(tabList.Count <= 0)
|
|||
|
{
|
|||
|
Debug.LogError("tabList is null");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
_FirstItem = tabList[0];
|
|||
|
_ItemContainer.InitContentItem(tabList);
|
|||
|
_ItemContainer.SetShowItemFinishCallFun(ClickDefaultFirstItem);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ClickDefaultFirstItem()
|
|||
|
{
|
|||
|
OnOrnamentItemClick(_FirstItem);
|
|||
|
ShowItemMark(_FirstItem.ID);
|
|||
|
RefreshCurSelectTypeItemState();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private Tab_Ornament selectOrnamentTab = null;
|
|||
|
public Tab_Ornament SelectOrnamentTab
|
|||
|
{
|
|||
|
get { return selectOrnamentTab; }
|
|||
|
private set { selectOrnamentTab = value; }
|
|||
|
}
|
|||
|
public void OnOrnamentItemClick(object initInfo)
|
|||
|
{
|
|||
|
var clickInfo = (Tab_Ornament)initInfo;
|
|||
|
if (selectOrnamentTab!= null && clickInfo.ID == selectOrnamentTab.ID)
|
|||
|
return;
|
|||
|
selectOrnamentTab = clickInfo;
|
|||
|
if (selectOrnamentTab == null)
|
|||
|
{
|
|||
|
Debug.LogError("selectOrnamentTab is null");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
ShowItemMark(selectOrnamentTab.ID);
|
|||
|
|
|||
|
InitLPanel();
|
|||
|
InitAttrPanel();
|
|||
|
|
|||
|
RefreshCurSelectTypeItemState();
|
|||
|
}
|
|||
|
|
|||
|
private void InitAttrPanel()
|
|||
|
{
|
|||
|
if (OrnamentAttrPanel.Instance)
|
|||
|
OrnamentAttrPanel.Instance.InitAttr(selectOrnamentTab);
|
|||
|
}
|
|||
|
|
|||
|
private void ShowItemMark(int id)
|
|||
|
{
|
|||
|
_ItemContainer.ForeachActiveItem<OrnamentItem>((item)=> {
|
|||
|
item.ShowMark(item.ornamentId ==id);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
//刷新左边显示面板
|
|||
|
private Dictionary<string, GameObject> _EffectPoolDic = new Dictionary<string, GameObject>();
|
|||
|
private void InitLPanel()
|
|||
|
{
|
|||
|
_HeadPanel.SetActive(_CurSelectType == (int)OrnamentType.Head);
|
|||
|
_PopPanel.SetActive(_CurSelectType == (int)OrnamentType.Pop);
|
|||
|
_FootPrintPanel.SetActive(_CurSelectType == (int)OrnamentType.footprint);
|
|||
|
|
|||
|
//左侧标题
|
|||
|
if (!_LPanelTitle.text.Equals(selectOrnamentTab.TypeName))
|
|||
|
_LPanelTitle.text = selectOrnamentTab.TypeName;
|
|||
|
|
|||
|
//左侧描述
|
|||
|
var lDescId = "#{" + selectOrnamentTab.ItemGetDescId + "}";
|
|||
|
_LDescText.text = StrDictionary.GetClientDictionaryString(lDescId);
|
|||
|
|
|||
|
switch (_CurSelectType)
|
|||
|
{
|
|||
|
case (int)OrnamentType.Head:
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_HeadIcon, GCGame.Utils.GetProfessionSpriteName(
|
|||
|
GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession));
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_ChatBG, selectOrnamentTab.ShowIconName,
|
|||
|
delegate(bool isSucess, GameObject obj) {
|
|||
|
_ChatBG.SetNativeSize();
|
|||
|
});
|
|||
|
}
|
|||
|
break;
|
|||
|
case (int)OrnamentType.Pop:
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_PopImage, selectOrnamentTab.ShowIconName,
|
|||
|
delegate(bool isSucess, GameObject obj) {
|
|||
|
_PopImage.SetNativeSize();
|
|||
|
});
|
|||
|
}
|
|||
|
break;
|
|||
|
case (int)OrnamentType.footprint:
|
|||
|
{
|
|||
|
HideAllEffectObj();
|
|||
|
|
|||
|
var bundlePathTab = TableManager.GetBundlePathByID(selectOrnamentTab.BundlePathID, 0);
|
|||
|
if(bundlePathTab == null)
|
|||
|
{
|
|||
|
Debug.LogError(" BundlePath is null, id is : " + selectOrnamentTab.BundlePathID);
|
|||
|
return;
|
|||
|
}
|
|||
|
var effectName = bundlePathTab.Name;
|
|||
|
var _EffectName = bundlePathTab.Name;
|
|||
|
if (_EffectPoolDic.ContainsKey(effectName))
|
|||
|
{
|
|||
|
var _EffectObj = _EffectPoolDic[effectName];
|
|||
|
_EffectObj.gameObject.SetActive(true);
|
|||
|
_EffectObj.transform.SetParent(_FootPrintPanel.gameObject.transform);
|
|||
|
_EffectObj.transform.localPosition = Vector3.zero;
|
|||
|
_EffectObj.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|||
|
_EffectObj.transform.localScale = Vector3.one * bundlePathTab.Scale;
|
|||
|
_EffectObj.EnsureComponent<UIParticleSystem>();
|
|||
|
|
|||
|
WindowSign wnd = gameObject.GetComponentInParent<WindowSign>();
|
|||
|
if (wnd != null)
|
|||
|
wnd.SetWndDirty();
|
|||
|
else
|
|||
|
{
|
|||
|
#if UNITY_EDITOR
|
|||
|
Debug.LogError("wnd is null");
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.LoadGameObject(LoadAssetBundle.BUNDLE_PATH_EFFECT, effectName,
|
|||
|
delegate (string assetName, GameObject resObj, Hashtable hashParam)
|
|||
|
{
|
|||
|
if (resObj != null)
|
|||
|
{
|
|||
|
var effect = Instantiate(resObj);
|
|||
|
|
|||
|
effect.gameObject.SetActive(true);
|
|||
|
effect.transform.SetParent(_FootPrintPanel.gameObject.transform);
|
|||
|
effect.transform.localPosition = Vector3.zero;
|
|||
|
effect.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|||
|
effect.transform.localScale = Vector3.one;
|
|||
|
SetChildScale(effect.transform, bundlePathTab.Scale);
|
|||
|
if (!_EffectPoolDic.ContainsKey(_EffectName))
|
|||
|
_EffectPoolDic.Add(_EffectName, effect);
|
|||
|
|
|||
|
|
|||
|
effect.EnsureComponent<UIParticleSystem>();
|
|||
|
|
|||
|
WindowSign wnd = gameObject.GetComponentInParent<WindowSign>();
|
|||
|
if (wnd != null)
|
|||
|
wnd.SetWndDirty();
|
|||
|
}
|
|||
|
}, new Hashtable());
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SetChildScale(Transform obj, float scale)
|
|||
|
{
|
|||
|
var allChilsTransform = obj.GetComponentsInChildren<Transform>();
|
|||
|
for (int index = 0; index < allChilsTransform.Length; index++)
|
|||
|
allChilsTransform[index].transform.localScale *= scale;
|
|||
|
}
|
|||
|
|
|||
|
private void HideAllEffectObj()
|
|||
|
{
|
|||
|
foreach(var item in _EffectPoolDic)
|
|||
|
item.Value.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
private void ClearAllEffect()
|
|||
|
{
|
|||
|
foreach(var item in _EffectPoolDic)
|
|||
|
GameObject.Destroy(item.Value.gameObject);
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
HideAllEffectObj();
|
|||
|
selectOrnamentTab = null;
|
|||
|
}
|
|||
|
|
|||
|
public void RefreshCurSelectTypeItemState()
|
|||
|
{
|
|||
|
var stateInfoList = GameManager.gameManager.PlayerDataPool.PlayerOrnamentStateInfo.GetStateInfoByType(_CurSelectType);
|
|||
|
if(stateInfoList == null || stateInfoList.Count <= 0)
|
|||
|
{
|
|||
|
_ItemContainer.ForeachActiveItem<OrnamentItem>((item)=> {
|
|||
|
item.ShowGetPathState();
|
|||
|
});
|
|||
|
Debug.LogError("stateInfoList is null");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
_ItemContainer.ForeachActiveItem<OrnamentItem>((item)=> {
|
|||
|
for(int index = 0; index < stateInfoList.Count; index++)
|
|||
|
{
|
|||
|
if(item.ornamentId == stateInfoList[index].Id)
|
|||
|
{
|
|||
|
item.RefreshItemState(stateInfoList[index]);
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|