344 lines
10 KiB
C#
344 lines
10 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using GCGame.Table;
|
|
using Module.Log;
|
|
using UnityEngine.UI;
|
|
|
|
public class PrivilegeWelfarePanelCtr : MonoBehaviour {
|
|
|
|
private enum PRIVILEGEWELFAREREWSTATE
|
|
{
|
|
CANT = 0, //条件不足
|
|
CAN, //可以领取
|
|
ACCEPTED, //已经领取
|
|
}
|
|
|
|
public static PrivilegeWelfarePanelCtr Instance;
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
public GameObject _MenuItemPrefab;
|
|
public Transform _MenuItemParent;
|
|
|
|
public GameObject _RewItemPrefab;
|
|
public Transform _RewItemParent;
|
|
|
|
public UICameraTexture _CamerTexture;
|
|
|
|
public GameObject _CantBtn;
|
|
public GameObject _CanBtn;
|
|
public GameObject _HasAcceptBtn;
|
|
|
|
public List<Image> _DescIconList;
|
|
public GameObject _canGetRewMatkIcon;
|
|
private List<GameObject> _MenuItemPrefabList = new List<GameObject>();
|
|
IEnumerator CreateMenuItem()
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
for (int i = 0; i < _MenuItemParent.childCount; i++)
|
|
{
|
|
_MenuItemParent.GetChild(i).gameObject.SetActive(false);
|
|
}
|
|
//_MenuItemPrefabList.Clear();
|
|
foreach (var info in TableManager.GetVipBook().Values)
|
|
{
|
|
if(info.VipLevel == 0)
|
|
{
|
|
continue;
|
|
}
|
|
var item = GameObject.Instantiate(_MenuItemPrefab);
|
|
item.transform.SetParent(_MenuItemParent);
|
|
item.transform.localPosition = Vector3.zero;
|
|
item.transform.localScale = Vector3.one;
|
|
item.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|
|
|
item.GetComponent<PrivilegeWelfareMenuItem>().InitMenuItem(info.VipLevel);
|
|
|
|
_MenuItemPrefabList.Add(item);
|
|
}
|
|
for (int i = 0; i < _MenuItemParent.childCount; i++)
|
|
{
|
|
_MenuItemParent.GetChild(i).gameObject.SetActive(false);
|
|
if (i<12)
|
|
{
|
|
_MenuItemParent.GetChild(i).gameObject.SetActive(true);
|
|
}
|
|
}
|
|
ReqWelfarePanelInfo();
|
|
yield break;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
//if (_MenuItemPrefabList.Count <= 0)
|
|
//{
|
|
// StartCoroutine(CreateMenuItem());
|
|
//}else
|
|
//{
|
|
// ReqWelfarePanelInfo();
|
|
//}
|
|
StartCoroutine(CreateMenuItem());
|
|
}
|
|
|
|
public void ReqWelfarePanelInfo()
|
|
{
|
|
ReqVipInfo req = new ReqVipInfo();
|
|
req._NodeId = 1;
|
|
req.SendMsg();
|
|
}
|
|
|
|
//<等级,状态> VIP0没有奖励 从1开始到16
|
|
private Dictionary<int, int> _PrivilegeWelfareRewStateDic = new Dictionary<int, int>();
|
|
public void OnPacket(RetVipRewardInfo packet)
|
|
{
|
|
for(int index = 0; index < packet._RewardState.Count; index++)
|
|
{
|
|
if(!_PrivilegeWelfareRewStateDic.ContainsKey(index + 1))
|
|
{
|
|
_PrivilegeWelfareRewStateDic.Add(index + 1, packet._RewardState[index]);
|
|
}
|
|
else
|
|
{
|
|
_PrivilegeWelfareRewStateDic[index + 1] = packet._RewardState[index];
|
|
}
|
|
}
|
|
SetRedDot();
|
|
//打开第一个可以领奖的界面 没有就默认最高
|
|
ShowFirstCanAcceptPanel();
|
|
}
|
|
|
|
|
|
|
|
public bool isUse;
|
|
private void scrollViewShowPosition(int vipLevel)
|
|
{
|
|
if (isUse)
|
|
{
|
|
return;
|
|
}
|
|
if (vipLevel <= 4)
|
|
{
|
|
_MenuItemParent.transform.localPosition = new Vector3(_MenuItemParent.transform.localPosition.x, 0, 0);
|
|
}
|
|
if (vipLevel > 4 && vipLevel <= 8)
|
|
{
|
|
_MenuItemParent.transform.localPosition = new Vector3(_MenuItemParent.transform.localPosition.x, 300, 0);
|
|
}
|
|
if (vipLevel > 8)
|
|
{
|
|
_MenuItemParent.transform.localPosition = new Vector3(_MenuItemParent.transform.localPosition.x, 670, 0);
|
|
}
|
|
}
|
|
|
|
public int newCurSelectVipLevel = -1;
|
|
public void ShowFirstCanAcceptPanel()
|
|
{
|
|
foreach (var info in _PrivilegeWelfareRewStateDic)
|
|
{
|
|
if(info.Value == (int)PRIVILEGEWELFAREREWSTATE.CAN)
|
|
{
|
|
OnMenuItemClick(info.Key);
|
|
return;
|
|
}
|
|
}
|
|
if (newCurSelectVipLevel > 0)
|
|
{
|
|
OnMenuItemClick(newCurSelectVipLevel);
|
|
}
|
|
else
|
|
{
|
|
//当前页面没有奖励可以领取的时候 就显示当前玩家VIP等级的界面
|
|
OnMenuItemClick(GameManager.gameManager.PlayerDataPool.VipCost <= 0 ? 1 : GameManager.gameManager.PlayerDataPool.VipCost);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public int _CurSelectVipLevel = -1;
|
|
public void OnMenuItemClick(int vipLevel)
|
|
{
|
|
|
|
_CurSelectVipLevel = vipLevel;
|
|
scrollViewShowPosition(vipLevel);
|
|
|
|
for (int index = 0; index < _MenuItemPrefabList.Count; index++)
|
|
{
|
|
_MenuItemPrefabList[index].GetComponent<PrivilegeWelfareMenuItem>().ShowMarkIcon(
|
|
vipLevel == _MenuItemPrefabList[index].GetComponent<PrivilegeWelfareMenuItem>()._MenuItemVipLevel);
|
|
}
|
|
|
|
StartCoroutine(InitPage());
|
|
}
|
|
|
|
private Tab_VipBook _CurPageVipBookTab = null;
|
|
IEnumerator InitPage()
|
|
{
|
|
if (!TableManager.GetVipBook().TryGetValue(_CurSelectVipLevel, out _CurPageVipBookTab))
|
|
{
|
|
LogModule.ErrorLog("_CurSelectVipLevel is null : " + _CurSelectVipLevel);
|
|
yield break;
|
|
}
|
|
|
|
//实例并初始化奖励
|
|
InitRewItem();
|
|
|
|
//初始化模型
|
|
ShowModel();
|
|
|
|
//初始化描述文字Icon
|
|
InitPageDescIcon();
|
|
|
|
InitBtnState();
|
|
|
|
SetRedDot();
|
|
|
|
_canGetRewMatkIcon.SetActive(false/*_PrivilegeWelfareRewStateDic.ContainsKey(_CurSelectVipLevel) && _PrivilegeWelfareRewStateDic[_CurSelectVipLevel] == 1*/);
|
|
yield break;
|
|
}
|
|
|
|
private void SetRedDot()
|
|
{
|
|
foreach (var item in _PrivilegeWelfareRewStateDic)
|
|
{
|
|
_MenuItemPrefabList[ item.Key - 1].GetComponent<PrivilegeWelfareMenuItem>().ShowMarkIconAndRemainTime(item.Value);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void InitPageDescIcon()
|
|
{
|
|
for(int index = 0; index < _DescIconList.Count; index++)
|
|
{
|
|
if(_CurPageVipBookTab.GetIconPathbyIndex(index).Equals("-1"))
|
|
{
|
|
_DescIconList[index].gameObject.SetActive(false);
|
|
}else
|
|
{
|
|
_DescIconList[index].gameObject.SetActive(true);
|
|
LoadAssetBundle.Instance.SetImageSprite(_DescIconList[index], _CurPageVipBookTab.GetIconPathbyIndex(index));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void InitBtnState()
|
|
{
|
|
if(_PrivilegeWelfareRewStateDic.ContainsKey(_CurPageVipBookTab.VipLevel))
|
|
{
|
|
if(_PrivilegeWelfareRewStateDic[_CurPageVipBookTab.VipLevel] == (int)PRIVILEGEWELFAREREWSTATE.CANT)
|
|
{
|
|
_CantBtn.SetActive(true);
|
|
_HasAcceptBtn.SetActive(false);
|
|
_CanBtn.SetActive(false);
|
|
}
|
|
if (_PrivilegeWelfareRewStateDic[_CurPageVipBookTab.VipLevel] == (int)PRIVILEGEWELFAREREWSTATE.CAN)
|
|
{
|
|
_CantBtn.SetActive(false);
|
|
_HasAcceptBtn.SetActive(false);
|
|
_CanBtn.SetActive(true);
|
|
}
|
|
if (_PrivilegeWelfareRewStateDic[_CurPageVipBookTab.VipLevel] == (int)PRIVILEGEWELFAREREWSTATE.ACCEPTED)
|
|
{
|
|
_CantBtn.SetActive(false);
|
|
_HasAcceptBtn.SetActive(true);
|
|
_CanBtn.SetActive(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LogModule.ErrorLog("No state");
|
|
_CantBtn.SetActive(false);
|
|
_HasAcceptBtn.SetActive(false);
|
|
_CanBtn.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void OnGainBtnClick()
|
|
{
|
|
ReqGetPrivilegeWelfare req = new ReqGetPrivilegeWelfare();
|
|
req._vipLevel = _CurSelectVipLevel;
|
|
req.SendMsg();
|
|
}
|
|
|
|
public void OnCantBtnClick()
|
|
{
|
|
GUIData.AddNotifyData(GCGame.Table.StrDictionary.GetClientDictionaryString("#{87333}"));
|
|
}
|
|
void ShowModel()
|
|
{
|
|
var CharModel = TableManager.GetCharModelByID(GetShowModelId(_CurPageVipBookTab.ShowModeId), 0);
|
|
if (CharModel == null)
|
|
{
|
|
_CamerTexture.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
_CamerTexture._CanDrag = false;
|
|
_CamerTexture.gameObject.SetActive(true);
|
|
if (_CamerTexture._FakeObj != null)
|
|
{
|
|
_CamerTexture._FakeObj.Disable();
|
|
_CamerTexture._FakeObj.Enable();
|
|
}
|
|
_CamerTexture.InitModelPath(CharModel.ResPath, CharModel, LoadAssetBundle.BUNDLE_PATH_MODEL, true, null, false,
|
|
_CurPageVipBookTab.ShowModeId.Contains("|") ? GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession : -1);
|
|
}
|
|
|
|
public int GetShowModelId(string modelStr)
|
|
{
|
|
if (!modelStr.Contains("|"))
|
|
{
|
|
return int.Parse(modelStr);
|
|
}
|
|
else
|
|
{
|
|
var modelIdStr = modelStr.Split('|');
|
|
return int.Parse(modelIdStr[GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private List<GameObject> _RewList = new List<GameObject>();
|
|
void InitRewItem()
|
|
{
|
|
if(_RewList.Count < _CurPageVipBookTab.getRewItemCount())
|
|
{
|
|
var _NeedCreateCount = _CurPageVipBookTab.getRewItemCount() - _RewList.Count;
|
|
for (int index = 0; index < _NeedCreateCount; index++)
|
|
{
|
|
GameObject rewItem = GameObject.Instantiate(_RewItemPrefab);
|
|
rewItem.transform.SetParent(_RewItemParent);
|
|
rewItem.transform.localPosition = Vector3.zero;
|
|
rewItem.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|
rewItem.transform.localScale = Vector3.one;
|
|
rewItem.SetActive(false);
|
|
|
|
_RewList.Add(rewItem);
|
|
}
|
|
}
|
|
|
|
|
|
for (int index = 0; index < _CurPageVipBookTab.getRewItemCount(); index++)
|
|
{
|
|
if (_CurPageVipBookTab.GetRewItembyIndex(index) == -1)
|
|
{
|
|
_RewList[index].SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_RewList[index].SetActive(true);
|
|
_RewList[index].GetComponent<PrivilegeVipRewItem>().InitItem(_CurPageVipBookTab.GetRewItembyIndex(index), _CurPageVipBookTab.GetRewNumbyIndex(index));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|