145 lines
4.3 KiB
C#
145 lines
4.3 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using GCGame.Table;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using UnityEngine.UI;
|
|
|
|
public class ActvitiesInTimeController : MonoBehaviour {
|
|
|
|
void Awake()
|
|
{
|
|
ReLoadAllListCompnent();
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
SortActivities();
|
|
}
|
|
|
|
public void ReLoadAllListCompnent()
|
|
{
|
|
parentList = new List<Transform>();
|
|
for (int index = 0; index < weekItemList.Count; index++)
|
|
{
|
|
parentList.Add(weekItemList[index].parentTrans);
|
|
}
|
|
}
|
|
|
|
public List<WeekItem> weekItemList;
|
|
|
|
private List<Transform> parentList; //父节点(周一到周日)
|
|
public GameObject itemPrefab;
|
|
|
|
private List<GameObject> itemPrefabList = new List<GameObject>();
|
|
|
|
private Dictionary<int, List<int>> limitActivityDic = new Dictionary<int, List<int>>();
|
|
public void SortActivities()
|
|
{
|
|
List<int> m_LimitActivities = new List<int>();
|
|
//限时活动
|
|
foreach(var m_Pair in TableManager.GetActivityBase().Values)
|
|
{
|
|
if((m_Pair.ActivityType & 1) != 0 && m_Pair.ShowWeekDesc == 1)
|
|
{
|
|
m_LimitActivities.Add(m_Pair.Id);
|
|
}
|
|
}
|
|
ClearAllItemPrefab();
|
|
for (int m_index = 0; m_index < m_LimitActivities.Count; m_index++)
|
|
{
|
|
int m_ActivityId = m_LimitActivities[m_index];
|
|
Tab_ActivityBase activityBase = TableManager.GetActivityBaseByID(m_ActivityId, 0);
|
|
if (activityBase == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
string[] m_LimitWeeks = activityBase.Recurrent.Split('|');
|
|
|
|
for (int index = 0; index < m_LimitWeeks.Length; index++)
|
|
{
|
|
if(limitActivityDic.ContainsKey(int.Parse(m_LimitWeeks[index])))
|
|
{
|
|
limitActivityDic[int.Parse(m_LimitWeeks[index])].Add(m_ActivityId);
|
|
}
|
|
else
|
|
{
|
|
List<int> idList = new List<int>();
|
|
idList.Add(m_ActivityId);
|
|
limitActivityDic.Add(int.Parse(m_LimitWeeks[index]), idList);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (var actDic in limitActivityDic)
|
|
{
|
|
actDic.Value.Sort(SortListByTime);
|
|
for(int index = 0; index < actDic.Value.Count; index++)
|
|
{
|
|
CreateItemPrefab(parentList[actDic.Key ], actDic.Value[index]);
|
|
}
|
|
}
|
|
|
|
InitItem();
|
|
}
|
|
|
|
public int SortListByTime(int idA, int idB)
|
|
{
|
|
Tab_ActivityBase tabA = TableManager.GetActivityBaseByID(idA, 0);
|
|
Tab_ActivityBase tabB = TableManager.GetActivityBaseByID(idB, 0);
|
|
if(tabA != null && tabB != null)
|
|
{
|
|
int timeA = int.Parse(tabA.GetTimebyIndex(0).Split('|')[0]);
|
|
int timeB = int.Parse(tabB.GetTimebyIndex(0).Split('|')[0]);
|
|
return timeA < timeB ? -1 : 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public void ClearAllItemPrefab()
|
|
{
|
|
for(int index = 0; index < itemPrefabList.Count; index++)
|
|
{
|
|
GameObject.Destroy(itemPrefabList[index]);
|
|
}
|
|
itemPrefabList.Clear();
|
|
limitActivityDic.Clear();
|
|
}
|
|
|
|
public void CreateItemPrefab(Transform parent, int id)
|
|
{
|
|
GameObject item = GameObject.Instantiate(itemPrefab);
|
|
item.transform.SetParent(parent);
|
|
item.transform.localPosition = Vector3.zero;
|
|
item.transform.localRotation = Quaternion.Euler(Vector3.zero);
|
|
item.transform.localScale = Vector3.one;
|
|
|
|
itemPrefabList.Add(item);
|
|
item.GetComponent<MyWeekButton>().InitMyWeekButton(id);
|
|
}
|
|
|
|
public void InitItem()
|
|
{
|
|
DateTime dt = GCGame.Utils.GetServerDateTime();
|
|
int m_OnTime = (int)dt.DayOfWeek;
|
|
|
|
for(int index = 0; index < weekItemList.Count; index++)
|
|
{
|
|
var isOnTime = m_OnTime == weekItemList[index].week;
|
|
weekItemList[index].ShowBG(isOnTime);
|
|
var weekBtns = weekItemList[index].GetComponentsInChildren<MyWeekButton>();
|
|
for (int btnIndex = 0; btnIndex < weekBtns.Length; btnIndex++)
|
|
{
|
|
weekBtns[btnIndex].InitOnOpenTime(isOnTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void myCloseButtonClick()
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
}
|