using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class OpenServerActivityCenter : Singleton<OpenServerActivityCenter>
|
{
|
public event Action openServerActivityStateChange;
|
|
Dictionary<int, IOpenServerActivity> openServerActivitys = new Dictionary<int, IOpenServerActivity>();
|
Dictionary<int, ILuaOpenServerActivity> luaOpenServerAcitivitys = new Dictionary<int, ILuaOpenServerActivity>();
|
|
public int selectFuncOrder = -1;
|
|
public OpenServerActivityCenter()
|
{
|
TimeUtility.OnServerOpenDayRefresh += OnServerOpenDayRefresh;
|
}
|
|
public void Register(int funcOrder, IOpenServerActivity activity)
|
{
|
if (!openServerActivitys.ContainsKey(funcOrder))
|
{
|
openServerActivitys.Add(funcOrder, activity);
|
activity.onStateUpdate += OnStateUpdate;
|
}
|
}
|
|
public void RegisterLuaActivity(int funcOrder, string luaTableName)
|
{
|
if (!openServerActivitys.ContainsKey(funcOrder))
|
{
|
var activity = LuaUtility.Global.Get<IOpenServerActivity>(luaTableName);
|
if (activity != null)
|
{
|
openServerActivitys.Add(funcOrder, activity);
|
activity.onStateUpdate += OnStateUpdate;
|
}
|
|
var luaActivity = LuaUtility.Global.Get<ILuaOpenServerActivity>(luaTableName);
|
if (luaActivity != null)
|
{
|
luaOpenServerAcitivitys[funcOrder] = luaActivity;
|
}
|
}
|
}
|
|
private void OnStateUpdate(int _order)
|
{
|
if (openServerActivityStateChange != null)
|
{
|
openServerActivityStateChange();
|
}
|
}
|
|
private void OnServerOpenDayRefresh()
|
{
|
if (openServerActivityStateChange != null)
|
{
|
openServerActivityStateChange();
|
}
|
}
|
|
public bool IsAnyActivityOpen(out int _functionOrder)
|
{
|
_functionOrder = 0;
|
foreach (var _order in openServerActivitys.Keys)
|
{
|
if (openServerActivitys[_order].IsOpen || openServerActivitys[_order].IsAdvance)
|
{
|
_functionOrder = _order;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool IsActivityOpen(int _funcOrder)
|
{
|
if (openServerActivitys.ContainsKey(_funcOrder))
|
{
|
return openServerActivitys[_funcOrder].IsOpen || openServerActivitys[_funcOrder].IsAdvance;
|
}
|
return false;
|
}
|
|
public bool IsPriorityOpenOpen(int _funcOrder)
|
{
|
if (openServerActivitys.ContainsKey(_funcOrder))
|
{
|
return openServerActivitys[_funcOrder].priorityOpen;
|
}
|
return false;
|
}
|
|
public void SetSelectDefaultChildType(int _funcOrder)
|
{
|
if (luaOpenServerAcitivitys.ContainsKey(_funcOrder))
|
{
|
luaOpenServerAcitivitys[_funcOrder].SetSelectDefaultChildType();
|
}
|
}
|
|
public bool ExistChildBookmark(int _funcOrder)
|
{
|
switch (_funcOrder)
|
{
|
case 0:
|
case 2:
|
case 19:
|
case 22:
|
return true;
|
default:
|
var config = OpenServerActivityConfig.Get(_funcOrder);
|
if (config != null)
|
{
|
return config.childTypes.Length > 0;
|
}
|
return false;
|
}
|
}
|
|
public int GetChildSelectType(int _funcOrder)
|
{
|
if (luaOpenServerAcitivitys.ContainsKey(_funcOrder))
|
{
|
return luaOpenServerAcitivitys[_funcOrder].selectType;
|
}
|
return 0;
|
}
|
|
public int[] GetChildTypes(int _funcOrder)
|
{
|
var config = OpenServerActivityConfig.Get(_funcOrder);
|
if (config != null)
|
{
|
return config.childTypes;
|
}
|
return null;
|
}
|
|
public void SetSelectChildType(int _funcOrder, int type)
|
{
|
if (luaOpenServerAcitivitys.ContainsKey(_funcOrder))
|
{
|
luaOpenServerAcitivitys[_funcOrder].SetSelectChildType(type);
|
}
|
}
|
|
public void ProcessErrorTip()
|
{
|
SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
|
}
|
}
|
|
[XLua.CSharpCallLua]
|
public interface IOpenServerActivity
|
{
|
bool IsOpen { get; }
|
bool IsAdvance { get; }
|
bool priorityOpen { get; }
|
|
event Action<int> onStateUpdate;
|
}
|
|
[XLua.CSharpCallLua]
|
public interface ILuaOpenServerActivity
|
{
|
int selectType { get; }
|
void SetSelectDefaultChildType();
|
void SetSelectChildType(int type);
|
}
|
}
|