//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, April 11, 2018
|
//--------------------------------------------------------
|
using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System.Text;
|
using Snxxz.UI;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class HighSettingFadeInFadeOut : MonoBehaviour
|
{
|
[SerializeField] Button m_Switch;//切换按钮1
|
[SerializeField] Image m_ArrowOpen;
|
[SerializeField] Image m_ArrowClose;
|
|
[SerializeField] Vector2 m_GridSize;
|
[SerializeField] Vector2 m_Space;
|
|
[SerializeField] MainWinTopGrid[] m_GridGroup1;
|
[SerializeField] MainWinTopGrid[] m_GridGroup2;
|
|
[SerializeField] RectTransform m_GroupContainer1;
|
[SerializeField] RectTransform m_GroupContainer2;
|
|
State state = State.Closed;
|
|
static float closeTimer = 0f;
|
int openedFunctionCount = 0;
|
|
TreasureFindHostModel hostModel { get { return ModelCenter.Instance.GetModel<TreasureFindHostModel>(); } }
|
LimitedTimePackageItemClassModel limitedTimePackageItemModel { get { return ModelCenter.Instance.GetModel<LimitedTimePackageItemClassModel>(); } }
|
ImpactRankModel impactRankModel { get { return ModelCenter.Instance.GetModel<ImpactRankModel>(); } }
|
OpenServiceAchievementModel OpenServerModel { get { return ModelCenter.Instance.GetModel<OpenServiceAchievementModel>(); } }
|
|
public static void SetAutoCloseTimer()
|
{
|
closeTimer = 5f;
|
}
|
|
void Start()
|
{
|
m_Switch.SetListener(() => { Switch(state == State.Closed); });
|
openedFunctionCount = 0;
|
openedFunctionCount += CountOpenedFunction(m_GridGroup1);
|
openedFunctionCount += CountOpenedFunction(m_GridGroup2);
|
SwitchImmedidately(false);
|
}
|
|
public void Init()
|
{
|
this.enabled = true;
|
RefreshGridsActiveState();
|
|
TimeUtility.OnServerOpenDayRefresh += OnStepServerDay;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChange;
|
hostModel.TreasureFindHostCompleteAct += TreasureFindHostCompleteAct;
|
RedpointCenter.Instance.redpointValueChangeEvent += UpdateRedpoint;
|
OpenServerActivityCenter.Instance.openServerActivityStateChange += OpenServerActivityStateChange;
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
limitedTimePackageItemModel.UpdateLimitedTimePackageItem += UpdateLimitedTimePackageItem;
|
impactRankModel.inImpactRankUpdate += InImpactRankUpdate;
|
OpenServerModel.IsOpenEvent += IsOpenEvent;
|
OpenServerModel.IsPreviewTimeUpdate += IsOpenEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
|
}
|
|
public void UnInit()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChange;
|
hostModel.TreasureFindHostCompleteAct -= TreasureFindHostCompleteAct;
|
TimeUtility.OnServerOpenDayRefresh -= OnStepServerDay;
|
OpenServerActivityCenter.Instance.openServerActivityStateChange -= OpenServerActivityStateChange;
|
RedpointCenter.Instance.redpointValueChangeEvent -= UpdateRedpoint;
|
OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
|
limitedTimePackageItemModel.UpdateLimitedTimePackageItem -= UpdateLimitedTimePackageItem;
|
impactRankModel.inImpactRankUpdate -= InImpactRankUpdate;
|
OpenServerModel.IsOpenEvent -= IsOpenEvent;
|
OpenServerModel.IsPreviewTimeUpdate -= IsOpenEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent -= OperationAdvanceEvent;
|
|
this.enabled = false;
|
}
|
|
void Switch(bool active)
|
{
|
var index = 0;
|
foreach (var grid in m_GridGroup1)
|
{
|
if (!grid.alwayShow && openedFunctionCount > 5)
|
{
|
grid.Switch(active, 0, 0f);
|
}
|
|
if (grid.gameObject.activeInHierarchy)
|
{
|
index++;
|
}
|
}
|
|
index = 0;
|
foreach (var grid in m_GridGroup2)
|
{
|
if (!grid.alwayShow && openedFunctionCount > 5)
|
{
|
var offset = (index / 6) + 1;
|
grid.Switch(active, offset * (m_GridSize.y + m_Space.y), offset * 0.1f);
|
}
|
|
if (grid.gameObject.activeInHierarchy)
|
{
|
index++;
|
}
|
}
|
|
state = active ? State.Opened : State.Closed;
|
DisplayArrow(state);
|
if (state == State.Opened)
|
{
|
SetAutoCloseTimer();
|
}
|
}
|
|
public void SwitchImmedidately(bool active)
|
{
|
foreach (var grid in m_GridGroup1)
|
{
|
if (grid.alwayShow || openedFunctionCount <= 5)
|
{
|
grid.SwitchImmediately(true, 0);
|
}
|
else
|
{
|
grid.SwitchImmediately(active, 0);
|
}
|
}
|
|
var index = 0;
|
foreach (var grid in m_GridGroup2)
|
{
|
if (grid.alwayShow || openedFunctionCount <= 5)
|
{
|
grid.SwitchImmediately(true, ((index / 6) + 1) * (m_GridSize.y + m_Space.y));
|
}
|
else
|
{
|
grid.SwitchImmediately(active, ((index / 6) + 1) * (m_GridSize.y + m_Space.y));
|
}
|
|
if (grid.gameObject.activeInHierarchy)
|
{
|
index++;
|
}
|
}
|
|
state = active ? State.Opened : State.Closed;
|
DisplayArrow(state);
|
if (state == State.Opened)
|
{
|
SetAutoCloseTimer();
|
}
|
}
|
|
private void OperationAdvanceEvent(Operation obj)
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void IsOpenEvent()
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void InImpactRankUpdate()
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void UpdateLimitedTimePackageItem()
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void OperationEndEvent(Operation arg1, int arg2)
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void OperationStartEvent(Operation arg1, int arg2)
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void UpdateRedpoint(int redPointID)
|
{
|
if (redPointID == 201 || redPointID == 210)
|
{
|
RefreshGridsActiveState();
|
}
|
}
|
|
private void OpenServerActivityStateChange()
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void OnStepServerDay()//开服活动
|
{
|
var days = ModelCenter.Instance.GetModel<ImpactRankModel>().openServerActivityDays;
|
if (TimeUtility.OpenDay >= days)
|
{
|
RefreshGridsActiveState();
|
}
|
}
|
|
private void TreasureFindHostCompleteAct()//仙宝寻主
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void OnFuncStateChange(int obj)
|
{
|
RefreshGridsActiveState();
|
}
|
|
private void RefreshGridsActiveState()
|
{
|
openedFunctionCount = 0;
|
openedFunctionCount += CountOpenedFunction(m_GridGroup1);
|
openedFunctionCount += CountOpenedFunction(m_GridGroup2);
|
|
ActiveGroup(m_GridGroup1);
|
ActiveGroup(m_GridGroup2);
|
LayoutGroup(m_GridGroup1, m_GroupContainer1);
|
LayoutGroup(m_GridGroup2, m_GroupContainer2);
|
|
m_Switch.gameObject.SetActive(IsShowButton());
|
}
|
|
bool IsShowButton()
|
{
|
if (openedFunctionCount <= 5)
|
{
|
return false;
|
}
|
|
foreach (var grid in m_GridGroup1)
|
{
|
if (!grid.alwayShow && grid.gameObject.activeSelf)
|
{
|
return true;
|
}
|
}
|
|
foreach (var grid in m_GridGroup2)
|
{
|
if (!grid.alwayShow && grid.gameObject.activeSelf)
|
{
|
return true;
|
}
|
}
|
|
return false;
|
}
|
|
private void LateUpdate()
|
{
|
var alwayShow = NewBieCenter.Instance.IsAreaNeedUnflod(2) || FunctionalGuideCenter.Instance.IsAreaNeedUnflod(2);
|
if (!alwayShow)
|
{
|
if (state == State.Opened)
|
{
|
closeTimer -= Time.deltaTime;
|
if (closeTimer <= 0f)
|
{
|
Switch(false);
|
}
|
}
|
}
|
}
|
|
private void DisplayArrow(State state)
|
{
|
m_ArrowOpen.gameObject.SetActive(state == State.Opened);
|
m_ArrowClose.gameObject.SetActive(state == State.Closed);
|
}
|
|
int CountOpenedFunction(MainWinTopGrid[] grids)
|
{
|
var count = 0;
|
foreach (var grid in grids)
|
{
|
var active = grid.IsOpen();
|
count += active ? 1 : 0;
|
}
|
|
return count;
|
}
|
|
void ActiveGroup(MainWinTopGrid[] grids)
|
{
|
foreach (var grid in grids)
|
{
|
var active = grid.IsOpen();
|
if (active && !grid.gameObject.activeSelf)
|
{
|
grid.gameObject.SetActive(true);
|
}
|
|
if (grid.gameObject.activeSelf && (grid.alwayShow || openedFunctionCount <= 5))
|
{
|
grid.SwitchImmediately(true, 0);
|
}
|
|
if (!active && grid.gameObject.activeSelf)
|
{
|
grid.gameObject.SetActive(false);
|
}
|
}
|
}
|
|
void LayoutGroup(MainWinTopGrid[] grids, RectTransform container)
|
{
|
var index = 0;
|
foreach (var grid in grids)
|
{
|
if (grid.gameObject.activeSelf)
|
{
|
var row = index / 6;
|
var column = index % 6;
|
|
var x = container.rect.width * 0.5f - m_GridSize.x * (column + 0.5f) - m_Space.x * column;
|
var y = container.rect.height * 0.5f - m_GridSize.y * (row + 0.5f) - m_Space.y * row;
|
grid.rectTransform.anchoredPosition = new Vector2(x, y);
|
index++;
|
}
|
}
|
|
foreach (var grid in grids)
|
{
|
if (grid.gameObject.activeSelf)
|
{
|
grid.transform.SetAsFirstSibling();
|
}
|
}
|
}
|
|
[ContextMenu("Layout")]
|
public void LayoutGroup()
|
{
|
LayoutGroup(m_GridGroup1, m_GroupContainer1);
|
LayoutGroup(m_GridGroup2, m_GroupContainer2);
|
}
|
|
public enum State
|
{
|
Opened,
|
Closed,
|
}
|
|
}
|
|
}
|