507 lines
16 KiB
C#
507 lines
16 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using GCGame.Table;
|
|||
|
using Module.Log;
|
|||
|
|
|||
|
public class CaptainWelfareRoot : MonoBehaviour {
|
|||
|
public static CaptainWelfareRoot Instance;
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
Instance = this;
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
Instance = null;
|
|||
|
}
|
|||
|
|
|||
|
public UIContainerBase _missionListContainer;
|
|||
|
public UIContainerBase _rewItemContainer;
|
|||
|
public UIContainerBase _valRewItemContainer;
|
|||
|
|
|||
|
public Slider _captainerLevelSlider;
|
|||
|
public Text _curLevelExpValText;
|
|||
|
public Slider _weekProgressSlider;
|
|||
|
public Text _curLevelTypeDesc;
|
|||
|
public GameObject _mask;
|
|||
|
public Text _costValText;
|
|||
|
|
|||
|
public Image _captainIcon;
|
|||
|
//周奖励
|
|||
|
public GameObject _weekRewItemPrefab;
|
|||
|
public RectTransform _weekSliderBGRect;
|
|||
|
|
|||
|
//刮刮乐
|
|||
|
public ScratchTicket _scratchRawImage;
|
|||
|
public Text _curVal;
|
|||
|
public Transform _captainWelfareWeekRewItemParant;
|
|||
|
|
|||
|
//特效
|
|||
|
public GameObject _particalPanel;
|
|||
|
private ParticleSystem _particle;
|
|||
|
|
|||
|
private int _costVal = -1; //刮一次需要的值
|
|||
|
|
|||
|
public GameObject captainWelfareRewPreviewPanel;
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
_scratchRawImage.onCleanRatioUpdate += OnCleanDataChanged;
|
|||
|
InitPanel();
|
|||
|
//ResetScratchRawImage(); //遮挡初始化
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
_scratchRawImage.onCleanRatioUpdate -= OnCleanDataChanged;
|
|||
|
}
|
|||
|
|
|||
|
private void InitPanel()
|
|||
|
{
|
|||
|
//任务ListItem
|
|||
|
if (_animItemList.Count <= 0 ||
|
|||
|
_teamLeaderTabIdList.Count <= 0 ||
|
|||
|
_animItemList.Count < _teamLeaderTabIdList.Count)
|
|||
|
StartCoroutine(InitAnimItem());
|
|||
|
else
|
|||
|
ReqInfo();
|
|||
|
|
|||
|
InitWeekRewContainer();
|
|||
|
}
|
|||
|
|
|||
|
private void ResetScratchRawImage()
|
|||
|
{
|
|||
|
_scratchRawImage.Reset();
|
|||
|
}
|
|||
|
|
|||
|
private List<CaptainWelfareRewItemInfo> _rewDataIdList = new List<CaptainWelfareRewItemInfo>();
|
|||
|
private Dictionary<int, int> _rewIdAndCountDic = new Dictionary<int, int>();
|
|||
|
|
|||
|
public struct CaptainWelfareRewItemInfo
|
|||
|
{
|
|||
|
public int _itemId;
|
|||
|
public int _itemCout;
|
|||
|
public CaptainWelfareRewItemInfo(int itemId, int itemCount)
|
|||
|
{
|
|||
|
_itemId = itemId;
|
|||
|
_itemCout = itemCount;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void InitWeekRewContainer()
|
|||
|
{
|
|||
|
if(_rewDataIdList.Count == 0)
|
|||
|
{
|
|||
|
foreach (var info in TableManager.GetTeamLeaderAwardItem().Values)
|
|||
|
{
|
|||
|
CaptainWelfareRewItemInfo _itemInfo = new CaptainWelfareRewItemInfo(info.AwardSubId, info.AwardCount);
|
|||
|
_rewDataIdList.Add(_itemInfo);
|
|||
|
}
|
|||
|
}
|
|||
|
if(_rewDataIdList.Count > 0)
|
|||
|
_rewItemContainer.InitContentItem(_rewDataIdList);
|
|||
|
}
|
|||
|
|
|||
|
private void ReqInfo()
|
|||
|
{
|
|||
|
ReqGetTeamLeaderAwardInfo req = new ReqGetTeamLeaderAwardInfo();
|
|||
|
req.flag = 1;
|
|||
|
req.SendMsg();
|
|||
|
}
|
|||
|
|
|||
|
private List<int> _teamLeaderTabIdList = new List<int>();
|
|||
|
IEnumerator InitAnimItem()
|
|||
|
{
|
|||
|
yield return new WaitForEndOfFrame();
|
|||
|
_teamLeaderTabIdList.Clear();
|
|||
|
foreach (var info in TableManager.GetTeamLeaderAwardActivity().Values)
|
|||
|
{
|
|||
|
_teamLeaderTabIdList.Add(info.GetId());
|
|||
|
}
|
|||
|
|
|||
|
if (_teamLeaderTabIdList.Count > 0)
|
|||
|
_missionListContainer.InitContentItem(_teamLeaderTabIdList);
|
|||
|
|
|||
|
ReqInfo();
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
private List<CaptainWelfareAimItem> _animItemList = new List<CaptainWelfareAimItem>();
|
|||
|
private int _CurSelectMissionType = -1;
|
|||
|
public void OnAimItemClick(int missionType)
|
|||
|
{
|
|||
|
_CurSelectMissionType = missionType;
|
|||
|
ShowMarkIcon();
|
|||
|
}
|
|||
|
|
|||
|
public void ShowMarkIcon()
|
|||
|
{
|
|||
|
for(int index = 0; index < _animItemList.Count; index++)
|
|||
|
{
|
|||
|
_animItemList[index].ShowMarkIcon(_animItemList[index].MissionType == _CurSelectMissionType);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public RespGetTeamLeaderAwardInfo _packet = null;
|
|||
|
private bool _canRefresh = false;
|
|||
|
public void OnPacket(RespGetTeamLeaderAwardInfo packet)
|
|||
|
{
|
|||
|
_packet = packet;
|
|||
|
|
|||
|
RefreshMissionItemListState(); //刷新预设状态
|
|||
|
InitSliderValAndDesc(); //刷新Slider
|
|||
|
RefreshWeekRewState(); //周进度奖励
|
|||
|
InitScratchState();
|
|||
|
InitMaskState(); //队长值不够不能刮
|
|||
|
InitCurVal();
|
|||
|
StartCoroutine(CreateValRew());
|
|||
|
}
|
|||
|
|
|||
|
private void InitCurVal()
|
|||
|
{
|
|||
|
_curVal.text = _packet.point.ToString();
|
|||
|
}
|
|||
|
|
|||
|
private void InitMaskState()
|
|||
|
{
|
|||
|
var teamLeaderAwardLevelTab = TableManager.GetTeamLeaderAwardLevelByID(_packet.level, 0);
|
|||
|
if(teamLeaderAwardLevelTab == null)
|
|||
|
{
|
|||
|
LogModule.ErrorLog("teamLeaderAwardLevelTab is null, level : " + _packet.level);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//设置队长图标
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(_captainIcon, teamLeaderAwardLevelTab.IconPath);
|
|||
|
_costVal = teamLeaderAwardLevelTab.PointCost;
|
|||
|
_costValText.text = teamLeaderAwardLevelTab.PointCost.ToString();
|
|||
|
_mask.SetActive(_packet.point < _costVal);
|
|||
|
}
|
|||
|
|
|||
|
//创建活力奖励
|
|||
|
IEnumerator CreateValRew()
|
|||
|
{
|
|||
|
yield return new WaitForEndOfFrame();
|
|||
|
|
|||
|
List<CaptainWelfareRewItemInfo> _rewIdList = new List<CaptainWelfareRewItemInfo>();
|
|||
|
for (int index = 0; index < _packet.awardList.Count; index++)
|
|||
|
{
|
|||
|
_rewIdList.Add(new CaptainWelfareRewItemInfo(_packet.awardList[index].subId, _packet.awardList[index].count));
|
|||
|
}
|
|||
|
|
|||
|
if (_rewIdList.Count > 0)
|
|||
|
_valRewItemContainer.InitContentItem(_rewIdList);
|
|||
|
|
|||
|
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
private void InitScratchState()
|
|||
|
{
|
|||
|
if (_scratchRawImage.gameObject.activeInHierarchy)
|
|||
|
//没有奖励 清除区域为0
|
|||
|
_canRefresh = _packet.awardList.Count <= 0 && _scratchRawImage.cleanRatio == 0 && _packet.exp_week >= _costVal;
|
|||
|
else
|
|||
|
_canRefresh = true;
|
|||
|
}
|
|||
|
|
|||
|
public void OnCleanDataChanged(float _cleanData)
|
|||
|
{
|
|||
|
if(_cleanData > 0 && _packet.awardList.Count == 0) //生成一次奖励
|
|||
|
{
|
|||
|
ReqCreateTeamLeaderAward req = new ReqCreateTeamLeaderAward();
|
|||
|
req.flag = 1;
|
|||
|
req.SendMsg();
|
|||
|
}
|
|||
|
|
|||
|
if (!_canRefresh)
|
|||
|
{
|
|||
|
InitScratchState(); //刷新当前能否刷新奖励的状态
|
|||
|
}
|
|||
|
|
|||
|
if (_cleanData >= 0.5f)
|
|||
|
{
|
|||
|
_scratchRawImage.gameObject.SetActive(false);
|
|||
|
InitScratchState();
|
|||
|
|
|||
|
//播放特效
|
|||
|
if (_particle == null)
|
|||
|
_particle = _particalPanel.GetComponentInChildren<ParticleSystem>();
|
|||
|
if (_particle != null)
|
|||
|
{
|
|||
|
_particle.Stop();
|
|||
|
_particle.Play();
|
|||
|
}
|
|||
|
|
|||
|
//申请领奖
|
|||
|
ReqCetTeamLeaderAward req = new ReqCetTeamLeaderAward();
|
|||
|
req.flag = 1;
|
|||
|
req.SendMsg();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private Dictionary<int, int> _weekRewStateDic;
|
|||
|
private void RefreshWeekRewState()
|
|||
|
{
|
|||
|
if(_isInitWeekRewOver)
|
|||
|
{
|
|||
|
for(int index = 0; index < _packet.awardWeek.Count; index++)
|
|||
|
{
|
|||
|
for (int rewIndex = 0; rewIndex < _weekRewItemList.Count; rewIndex++)
|
|||
|
{
|
|||
|
if(_weekRewItemList[rewIndex]._curItemIndex == _packet.awardWeek[index].index)
|
|||
|
{
|
|||
|
_weekRewItemList[rewIndex].RefreshItemState(_packet.awardWeek[index].state);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}else
|
|||
|
{
|
|||
|
if (_weekRewStateDic == null)
|
|||
|
_weekRewStateDic = new Dictionary<int, int>();
|
|||
|
|
|||
|
for(int index = 0; index < _packet.awardWeek.Count; index++)
|
|||
|
{
|
|||
|
if(_weekRewStateDic.ContainsKey(_packet.awardWeek[index].index))
|
|||
|
{
|
|||
|
_weekRewStateDic[_packet.awardWeek[index].index] = _packet.awardWeek[index].state;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_weekRewStateDic.Add(_packet.awardWeek[index].index, _packet.awardWeek[index].state);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private enum CAPTAINLEVELTYPE
|
|||
|
{
|
|||
|
LEVEL_0 = 1, //小白 对应ID是1
|
|||
|
LEVEL_1,
|
|||
|
LEVEL_2,
|
|||
|
LEVEL_3,
|
|||
|
LEVEL_4,
|
|||
|
LEVEL_5,
|
|||
|
}
|
|||
|
//等级 经验
|
|||
|
private Dictionary<int, int> _captainLevelExpDic = new Dictionary<int, int>();
|
|||
|
|
|||
|
private void InitSliderValAndDesc()
|
|||
|
{
|
|||
|
_curLevelTypeDesc.text = GetCurCaptainLevelDesc();
|
|||
|
InitCurLevelExpAndVal();
|
|||
|
InitWeekSliderVal();
|
|||
|
}
|
|||
|
|
|||
|
private int _weekMaxExp = -1;
|
|||
|
private void InitWeekSliderVal()
|
|||
|
{
|
|||
|
if(_weekMaxExp == -1)
|
|||
|
{
|
|||
|
foreach(var weekInfo in TableManager.GetTeamLeaderAwardWeek().Values)
|
|||
|
{
|
|||
|
if (weekInfo.WeekNeedExp > _weekMaxExp)
|
|||
|
_weekMaxExp = weekInfo.WeekNeedExp;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//初始化进度值
|
|||
|
_weekProgressSlider.value = Mathf.Clamp((float)_packet.exp_week / (float)_weekMaxExp, 0, 1);
|
|||
|
|
|||
|
//计算奖励应该出现的位置
|
|||
|
StartCoroutine(CreateWeekRewAndSetPos());
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private bool _isInitWeekRewOver = false;
|
|||
|
private List<CaptainWelfareWeekRewItem> _weekRewItemList = new List<CaptainWelfareWeekRewItem>();
|
|||
|
IEnumerator CreateWeekRewAndSetPos()
|
|||
|
{
|
|||
|
yield return new WaitForEndOfFrame();
|
|||
|
if (_weekRewItemList.Count < TableManager.GetTeamLeaderAwardWeek().Count)
|
|||
|
{
|
|||
|
var _startIndex = _weekRewItemList.Count;
|
|||
|
for (int index = _startIndex; _weekRewItemList.Count < TableManager.GetTeamLeaderAwardWeek().Count; index++)
|
|||
|
{
|
|||
|
var obj = GameObject.Instantiate(_weekRewItemPrefab);
|
|||
|
|
|||
|
obj.transform.SetParent(_captainWelfareWeekRewItemParant);
|
|||
|
obj.transform.localScale = Vector3.one;
|
|||
|
obj.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|||
|
|
|||
|
var teamWeekAwardTab = TableManager.GetTeamLeaderAwardWeekByID(index + 1, 0);
|
|||
|
if(teamWeekAwardTab == null)
|
|||
|
{
|
|||
|
LogModule.ErrorLog("teamWeekAwardTab is null, id : " + index + 1);
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
//pos cueExp / maxExp * rect.width
|
|||
|
obj.transform.localPosition = new Vector3(
|
|||
|
Mathf.Clamp((float)teamWeekAwardTab.WeekNeedExp / (float)_weekMaxExp * _weekSliderBGRect.rect.width, 0, _weekSliderBGRect.rect.width), 0, 0);
|
|||
|
|
|||
|
obj.GetComponent<CaptainWelfareWeekRewItem>().InitItem(index + 1);
|
|||
|
_weekRewItemList.Add(obj.GetComponent<CaptainWelfareWeekRewItem>());
|
|||
|
}
|
|||
|
_isInitWeekRewOver = true;
|
|||
|
}
|
|||
|
|
|||
|
if(_weekRewStateDic != null && _weekRewStateDic.Count > 0)
|
|||
|
{
|
|||
|
for (int index = 0; index < _packet.awardWeek.Count; index++)
|
|||
|
{
|
|||
|
for (int rewIndex = 0; rewIndex < _weekRewItemList.Count; rewIndex++)
|
|||
|
{
|
|||
|
if (_weekRewItemList[rewIndex]._curItemIndex == _packet.awardWeek[index].index)
|
|||
|
{
|
|||
|
_weekRewItemList[rewIndex].RefreshItemState(_packet.awardWeek[index].state);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
yield break;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public void InitCurLevelExpAndVal()
|
|||
|
{
|
|||
|
var _nextLevel = -1; //初始化 后面判断用
|
|||
|
_nextLevel = Mathf.Clamp(_packet.level + 1, 2, _maxLevel); //ID从1开始的话下个等级最低是2,默认的是1
|
|||
|
|
|||
|
var _curLevelTotalExp = 0;
|
|||
|
_curLevelTotalExp = _captainLevelExpDic[_nextLevel] - _captainLevelExpDic[_packet.level];
|
|||
|
_captainerLevelSlider.value = Mathf.Clamp((float)_packet.exp / (float)_captainLevelExpDic[_nextLevel], 0, 1);
|
|||
|
_curLevelExpValText.text = Mathf.Clamp(_packet.exp, 0, _captainLevelExpDic[_nextLevel]) + "/" + _captainLevelExpDic[_nextLevel];
|
|||
|
}
|
|||
|
|
|||
|
public string GetCurCaptainLevelDesc()
|
|||
|
{
|
|||
|
if (_captainLevelExpDic.Count <= 0)
|
|||
|
GetCaptainLevelExpDic();
|
|||
|
|
|||
|
Tab_TeamLeaderAwardLevel teamLevelTab = null;
|
|||
|
if (_packet.exp == 0)
|
|||
|
{
|
|||
|
teamLevelTab = TableManager.GetTeamLeaderAwardLevelByID(1, 0); //最小
|
|||
|
if (teamLevelTab != null)
|
|||
|
return teamLevelTab.Name;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if(_packet.level == _maxLevel)
|
|||
|
{
|
|||
|
teamLevelTab = TableManager.GetTeamLeaderAwardLevelByID(_maxLevel, 0); //最大
|
|||
|
if (teamLevelTab != null)
|
|||
|
return teamLevelTab.Name;
|
|||
|
}
|
|||
|
|
|||
|
foreach (var exp in _captainLevelExpDic)
|
|||
|
{
|
|||
|
if (_packet.exp < exp.Value)
|
|||
|
{
|
|||
|
teamLevelTab = TableManager.GetTeamLeaderAwardLevelByID(exp.Key - 1, 0);
|
|||
|
if (teamLevelTab != null)
|
|||
|
return teamLevelTab.Name;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return "WRONG";
|
|||
|
}
|
|||
|
|
|||
|
private int _maxLevel = -1;
|
|||
|
private int _maxExp = -1;
|
|||
|
private void GetCaptainLevelExpDic()
|
|||
|
{
|
|||
|
var teamTab = TableManager.GetTeamLeaderAwardLevel().Values;
|
|||
|
foreach(var info in teamTab)
|
|||
|
{
|
|||
|
if (!_captainLevelExpDic.ContainsKey(info.Level))
|
|||
|
_captainLevelExpDic.Add(info.Level, info.Exp);
|
|||
|
if (info.Level >= _maxLevel)
|
|||
|
_maxLevel = info.Level;
|
|||
|
if (info.Exp >= _maxExp)
|
|||
|
_maxExp = info.Exp;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private void RefreshMissionItemListState()
|
|||
|
{
|
|||
|
//刷新当前次数
|
|||
|
if (_packet.activityList.Count == 0)
|
|||
|
{
|
|||
|
List<int> _missiontypeList = new List<int>();
|
|||
|
var missionDic = TableManager.GetTeamLeaderAwardActivity();
|
|||
|
foreach (var mission in missionDic)
|
|||
|
{
|
|||
|
_missiontypeList.Add(mission.Key);
|
|||
|
}
|
|||
|
_missionListContainer.ForeachActiveItem<CaptainWelfareAimItem>((item) => {
|
|||
|
for (int index = 0; index < _missiontypeList.Count; index++)
|
|||
|
{
|
|||
|
item.RefreshItemState(0);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_missionListContainer.ForeachActiveItem<CaptainWelfareAimItem>((item) => {
|
|||
|
for (int index = 0; index < _packet.activityList.Count; index++)
|
|||
|
{
|
|||
|
if(item.MissionType == _packet.activityList[index].type)
|
|||
|
{
|
|||
|
item.RefreshItemState(_packet.activityList[index].count);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void OnRefreshRewBtnClick()
|
|||
|
{
|
|||
|
if(!_canRefresh)
|
|||
|
{
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{68002}")); //未完成当前刮奖
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
_scratchRawImage.gameObject.SetActive(true);
|
|||
|
_scratchRawImage.Reset();
|
|||
|
|
|||
|
ReqCreateTeamLeaderAward req = new ReqCreateTeamLeaderAward();
|
|||
|
req.flag = 1;
|
|||
|
req.SendMsg();
|
|||
|
}
|
|||
|
|
|||
|
public void OnHelpBtnClick()
|
|||
|
{
|
|||
|
MessageHelpLogic.ShowHelpMessage(41);
|
|||
|
}
|
|||
|
|
|||
|
public void OnMaskBtnClick()
|
|||
|
{
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{68001}"));
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
public void OnCloseBtnClick()
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.CaptainWelfare);
|
|||
|
}
|
|||
|
|
|||
|
public void OnCaptainNameClick()
|
|||
|
{
|
|||
|
MessageHelpLogic.ShowHelpMessage(42);
|
|||
|
}
|
|||
|
|
|||
|
public void OnWeekItemClick(int weekId, int state)
|
|||
|
{
|
|||
|
captainWelfareRewPreviewPanel.SetActive(true);
|
|||
|
if (CaptainWelfareRewPreviewCtr.Instance)
|
|||
|
CaptainWelfareRewPreviewCtr.Instance.InitWelfareRewPreview(weekId, state);
|
|||
|
}
|
|||
|
}
|