257 lines
8.2 KiB
C#
257 lines
8.2 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
|
|
public class MainMissionCopyitemInfo
|
|
{
|
|
public int _RewState;
|
|
public int fubenId;
|
|
public int score;
|
|
public int remainTimes;
|
|
public bool isGainFirstRew;
|
|
public int bestPassTime;
|
|
public MainMissionCopyitemInfo(int _state, int id, int _score, int time, bool gainFirst, int bestTime)
|
|
{
|
|
_RewState = _state;
|
|
fubenId = id;
|
|
score = _score;
|
|
remainTimes = time;
|
|
isGainFirstRew = gainFirst;
|
|
bestPassTime = bestTime;
|
|
}
|
|
}
|
|
|
|
public class MainMissionCopySceneRootCtr : CopyCtrBase
|
|
{
|
|
public static new MainMissionCopySceneRootCtr Instance;
|
|
public override void Awake()
|
|
{
|
|
curType = (int)CopySceneItemType.MainMission;
|
|
Instance = this;
|
|
base.Awake();
|
|
GetMainCopySceneTabInfo();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
#region
|
|
public Transform prefabParent;
|
|
public GameObject itemprefab;
|
|
|
|
public GameObject _LeftIcon;
|
|
public GameObject _RightIcon;
|
|
public GridLayoutGroup _GridLayout;
|
|
public GameObject _ContentObj;
|
|
#endregion
|
|
|
|
private List<int> copyBaseIdList = new List<int>();
|
|
public void GetMainCopySceneTabInfo()
|
|
{
|
|
var copyBaseDic = TableManager.GetNewCopyBase().Values;
|
|
foreach (var info in copyBaseDic)
|
|
{
|
|
if (info.Type == curType)
|
|
{
|
|
copyBaseIdList.Add(info.Id);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
AskForInfo();
|
|
}
|
|
|
|
public void AskForInfo()
|
|
{
|
|
CG_REQ_BASE_COPY_INFO req = (CG_REQ_BASE_COPY_INFO)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_BASE_COPY_INFO);
|
|
req.SetCopyType(curType);
|
|
req.SendPacket();
|
|
}
|
|
|
|
private List<int> _AllFBList = new List<int>();
|
|
private GC_RET_BASE_COPY_INFO Packet;
|
|
public void OnPacketReceive(GC_RET_BASE_COPY_INFO info)
|
|
{
|
|
Packet = info;
|
|
CreatePrefab();
|
|
_AllFBList = new List<int>();
|
|
|
|
//先初始化4个
|
|
if(itemPrefabList.Count > 4)
|
|
{
|
|
for (int index = 0; index < 4; index++)
|
|
{
|
|
MainMissionCopyitemInfo itemIndfo = new MainMissionCopyitemInfo(info.GetBaseCopyInfo(index).GetFirstReward,
|
|
info.GetBaseCopyInfo(index).FubenId,
|
|
info.GetBaseCopyInfo(index).Score,
|
|
info.GetBaseCopyInfo(index).Num,
|
|
info.GetBaseCopyInfo(index).GetFirstReward == 2 ? true : false,
|
|
info.GetBaseCopyInfo(index).Time
|
|
);
|
|
_AllFBList.Add(itemIndfo.fubenId);
|
|
itemPrefabList[index].GetComponent<MainMissionCopySceneItem>().InitItem(itemIndfo);
|
|
}
|
|
|
|
StartCoroutine(InitRemainCopyInfo());
|
|
}else
|
|
{
|
|
for (int index = 0; index < itemPrefabList.Count; index++)
|
|
{
|
|
MainMissionCopyitemInfo itemIndfo = new MainMissionCopyitemInfo(info.GetBaseCopyInfo(index).GetFirstReward,
|
|
info.GetBaseCopyInfo(index).FubenId,
|
|
info.GetBaseCopyInfo(index).Score,
|
|
info.GetBaseCopyInfo(index).Num,
|
|
info.GetBaseCopyInfo(index).GetFirstReward == 2 ? true : false,
|
|
info.GetBaseCopyInfo(index).Time
|
|
);
|
|
_AllFBList.Add(itemIndfo.fubenId);
|
|
itemPrefabList[index].GetComponent<MainMissionCopySceneItem>().InitItem(itemIndfo);
|
|
}
|
|
}
|
|
|
|
ShowDefaultFirst();
|
|
}
|
|
|
|
private IEnumerator InitRemainCopyInfo()
|
|
{
|
|
yield return new WaitForFixedUpdate();
|
|
for (int index = 4; index < itemPrefabList.Count; index++)
|
|
{
|
|
MainMissionCopyitemInfo itemIndfo = new MainMissionCopyitemInfo(Packet.GetBaseCopyInfo(index).GetFirstReward,
|
|
Packet.GetBaseCopyInfo(index).FubenId,
|
|
Packet.GetBaseCopyInfo(index).Score,
|
|
Packet.GetBaseCopyInfo(index).Num,
|
|
Packet.GetBaseCopyInfo(index).GetFirstReward == 2 ? true : false,
|
|
Packet.GetBaseCopyInfo(index).Time
|
|
);
|
|
_AllFBList.Add(itemIndfo.fubenId);
|
|
itemPrefabList[index].GetComponent<MainMissionCopySceneItem>().InitItem(itemIndfo);
|
|
}
|
|
CalculateContentRec();
|
|
yield break;
|
|
}
|
|
|
|
public void RefreshItemInfo(GC_RET_BASE_COPY_INFO info)
|
|
{
|
|
MainMissionCopyitemInfo itemInfo = new MainMissionCopyitemInfo(info.GetBaseCopyInfo(0).GetFirstReward, //这边判断时间,因为没有首次奖励
|
|
info.GetBaseCopyInfo(0).FubenId,
|
|
info.GetBaseCopyInfo(0).Score,
|
|
info.GetBaseCopyInfo(0).Num,
|
|
info.GetBaseCopyInfo(0).GetFirstReward == 2 ? true : false,
|
|
info.GetBaseCopyInfo(0).Time
|
|
);
|
|
for (int index = 0; index < itemPrefabList.Count; index++)
|
|
{
|
|
if (itemPrefabList[index].GetComponent<MainMissionCopySceneItem>().curBaseId == itemInfo.fubenId)
|
|
{
|
|
itemPrefabList[index].GetComponent<MainMissionCopySceneItem>().SetRemainChallengeimes(itemInfo.remainTimes);
|
|
itemPrefabList[index].GetComponent<MainMissionCopySceneItem>().RefreshFirstRewState(itemInfo._RewState);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ShowDefaultFirst()
|
|
{
|
|
if (itemPrefabList.Count > 0)
|
|
{
|
|
itemPrefabList[0].GetComponent<MainMissionCopySceneItem>().OnItemClick();
|
|
}
|
|
}
|
|
|
|
public void CreatePrefab()
|
|
{
|
|
if(itemPrefabList.Count > 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int index = 0; index < copyBaseIdList.Count; index++)
|
|
{
|
|
GameObject item = GameObject.Instantiate(itemprefab);
|
|
|
|
item.transform.SetParent(prefabParent);
|
|
item.transform.localPosition = Vector3.zero;
|
|
item.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|
item.transform.localScale = Vector3.one;
|
|
|
|
itemPrefabList.Add(item);
|
|
}
|
|
}
|
|
|
|
private bool canNormalSweep;
|
|
public void OnItemClick(int baseId)
|
|
{
|
|
base.OnCopyBaseItemClick(baseId);
|
|
SetCopySceneItemMarkIcon();
|
|
}
|
|
|
|
public void ShowSweepBtn(Tab_NewCopyBase copyBase)
|
|
{
|
|
//normalSweepBtn.gameObject.SetActive(copyBase.NormalSweepCondition != -1 ? true : false);
|
|
//advanceSweepBtn.gameObject.SetActive(copyBase.AdvancedSweepCondition != -1 ? true : false);
|
|
}
|
|
|
|
public void SetCopySceneItemMarkIcon()
|
|
{
|
|
for (int index = 0; index < itemPrefabList.Count; index++)
|
|
{
|
|
itemPrefabList[index].gameObject.GetComponent<MainMissionCopySceneItem>().ShowMarkIcon(
|
|
itemPrefabList[index].gameObject.GetComponent<MainMissionCopySceneItem>().curBaseId == _CurSelectedCopyBaseId ? true : false);
|
|
}
|
|
}
|
|
|
|
public override void OnAdvanceSweepBtnClick()
|
|
{
|
|
base.OnAdvanceSweepBtnClick();
|
|
}
|
|
|
|
public override void OnNormalSweepBtnClick()
|
|
{
|
|
base.OnNormalSweepBtnClick();
|
|
}
|
|
|
|
private float _AllRecWidth = 0;
|
|
public void CalculateContentRec()
|
|
{
|
|
//计算整个区域大小
|
|
_AllRecWidth = _GridLayout.padding.left + _GridLayout.cellSize.x * itemPrefabList.Count + (itemPrefabList.Count - 1) * _GridLayout.spacing.x;
|
|
ShowPosMarkIcon();
|
|
}
|
|
public void ShowPosMarkIcon()
|
|
{
|
|
if(_ContentObj.transform.localPosition.x < -_GridLayout.cellSize.x)
|
|
{
|
|
if(!_LeftIcon.activeInHierarchy)
|
|
{
|
|
_LeftIcon.SetActive(true);
|
|
}
|
|
}else
|
|
{
|
|
if (_LeftIcon.activeInHierarchy)
|
|
{
|
|
_LeftIcon.SetActive(false);
|
|
}
|
|
}
|
|
|
|
if(_ContentObj.transform.localPosition.x < _GridLayout.cellSize.x * 5 + _GridLayout.spacing.x * 4 + _GridLayout.padding.left - _ContentObj.GetComponent<RectTransform>().rect.width)
|
|
{
|
|
if(_RightIcon.activeInHierarchy)
|
|
{
|
|
_RightIcon.SetActive(false);
|
|
}
|
|
}else
|
|
{
|
|
if (!_RightIcon.activeInHierarchy)
|
|
{
|
|
_RightIcon.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
}
|