123 lines
3.9 KiB
C#
123 lines
3.9 KiB
C#
// 文件位置建议: Assets/Scripts/TH1_UI/Controller/UIAnnounceMajorEventController.cs
|
||
|
||
using RuntimeData;
|
||
using TH1_Core.Events;
|
||
using TH1_Core.Managers;
|
||
using TH1_Logic.Core;
|
||
using TH1_Logic.MatchConfig;
|
||
using TH1_UI.Controller.Base;
|
||
using TH1_UI.View.Outside;
|
||
using TH1Resource;
|
||
using UnityEngine;
|
||
|
||
// 确保这里引用了View脚本的命名空间
|
||
|
||
namespace TH1_UI.Controller.Outside
|
||
{
|
||
/// <summary>
|
||
/// 重大事件公告界面的控制器。
|
||
/// 它的职责是处理玩家相遇、玩家被消灭之类的宣告
|
||
/// </summary>
|
||
public class UIOutsideTutorController : ViewController<UIOutsideTutorView> // 泛型参数是对应的View脚本
|
||
{
|
||
|
||
public UIOutsideTutorController() { }
|
||
|
||
private ShowUIOutsideTutor _evt;
|
||
protected override void RegisterEventCallback()
|
||
{
|
||
base.RegisterEventCallback();
|
||
if (WindowScript != null)
|
||
{
|
||
WindowScript.OnBtnCloseClick += _OnBtnCloseClick;
|
||
WindowScript.OnBtnStartClick += _OnStartGameClick;
|
||
WindowScript.OnBtnWikiClick += _OnBtnWikiClick;
|
||
}
|
||
|
||
}
|
||
|
||
public override void UpdateView()
|
||
{
|
||
if (WindowScript != null)
|
||
{
|
||
//Debug.Log("Update View Success!!!!");
|
||
}
|
||
|
||
base.UpdateView();
|
||
}
|
||
protected override void UnregisterEventCallback()
|
||
{
|
||
if (WindowScript != null)
|
||
{
|
||
WindowScript.OnBtnCloseClick -= _OnBtnCloseClick;
|
||
WindowScript.OnBtnStartClick -= _OnStartGameClick;
|
||
WindowScript.OnBtnWikiClick -= _OnBtnWikiClick;
|
||
}
|
||
base.UnregisterEventCallback();
|
||
}
|
||
|
||
protected override void OnOpen()
|
||
{
|
||
base.OnOpen();
|
||
// 检查暂存的参数是否存在且类型正确
|
||
if (_openParameter is ShowUIOutsideTutor evt)
|
||
{
|
||
_evt = evt;
|
||
// 使用接收到的数据设置UI内容
|
||
if (WindowScript != null)
|
||
{
|
||
//Param1 = cid Param2 = cityLv
|
||
WindowScript.SetContent(evt);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 如果没有参数或参数类型不符,可以提供默认内容或打印警告
|
||
Debug.LogWarning("[UIAnnounceMajorEventController] Opened without valid parameters.");
|
||
if (WindowScript != null)
|
||
{
|
||
//WindowScript.SetContent("警告", "内容未提供");
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
void _OnBtnCloseClick()
|
||
{
|
||
EventManager.Publish(new ShowUIOutsideMenu());
|
||
Close();
|
||
}
|
||
|
||
void _OnBtnWikiClick()
|
||
{
|
||
// Wiki 是浮窗,不会关闭 Tutor;与 Library 同样的接入方式
|
||
EventManager.Publish(new ShowUIOutsideWiki());
|
||
}
|
||
|
||
void _OnStartGameClick(ScenarioPack pack)
|
||
{
|
||
Main.Instance.MapConfig = MatchConfigManager.Instance.GetMatchConfig(pack.levelId);
|
||
EventManager.Publish(new ShowUIOutsideLoading());
|
||
float fadeout = ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length;
|
||
float prepare = 2f;
|
||
Timer.Instance.TimerRegister(this, () =>
|
||
{
|
||
Close();
|
||
Main.Instance.StartMatch();
|
||
EventManager.Publish(new HideUIOutsideTutor());
|
||
},fadeout,"UIOutsideTutorController");
|
||
|
||
Timer.Instance.TimerRegister(this, () =>
|
||
{
|
||
EventManager.Publish(new HideUIOutsideLoading());
|
||
},prepare + fadeout,"UIOutsideTutorController");
|
||
|
||
}
|
||
|
||
public override bool Close()
|
||
{
|
||
//WindowScript?.OnCloseView();
|
||
return base.Close();
|
||
}
|
||
}
|
||
} |