322 lines
9.4 KiB
C#
322 lines
9.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using Animancer;
|
||
using Logic;
|
||
using Logic.Action;
|
||
using Logic.AI;
|
||
using Logic.Audio;
|
||
using Logic.Multilingual;
|
||
using ParadoxNotion;
|
||
using RuntimeData;
|
||
using Steamworks;
|
||
using TH1_Core.Events;
|
||
using TH1_Core.Managers;
|
||
using TH1_Logic.Action;
|
||
using TH1_Logic.Config;
|
||
using TH1_Logic.Core;
|
||
using TH1_Logic.GameArchive;
|
||
using TH1_Logic.Net;
|
||
using TH1_Logic.Steam;
|
||
using TH1_UI.View.Announce;
|
||
using TH1Resource;
|
||
using TMPro;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Random = UnityEngine.Random;
|
||
|
||
namespace TH1_UI.View.Outside
|
||
{
|
||
|
||
|
||
public class UIOutsideMenuView : Base.View
|
||
{
|
||
[Header("按钮")]
|
||
//public Button CloseButton;
|
||
public Button StartButton;
|
||
public Button MultiplayButton;
|
||
public Button ResumeButton;
|
||
public Button LibraryButton;
|
||
public Button HistoryButton;
|
||
public Button TutorButton;
|
||
public Button StoryButton;
|
||
public Button TransReportButton;
|
||
|
||
public List<UIOutsideMenuButtonMono> ButtonList;
|
||
public Button AnnouncementButton;
|
||
public Button AboutButton;
|
||
public Button SettingButton;
|
||
public Button ShutdownButton;
|
||
|
||
public UIOutsideMenuAnnouncementPanelMono AnnouncementPanel;
|
||
public UIOutsideMenuAboutPanelMono AboutPanel;
|
||
public UIOutsideMenuSettingPanelMono SettingPanel;
|
||
public UIOutsideMenuShutdownPanelMono ShutdownPanel;
|
||
|
||
|
||
public TextMeshProUGUI QQHintVersion;
|
||
|
||
[Header("QQHint下的可点击Discord文字(繁中专用)")]
|
||
// QQHint下叫"text"的那个TMP,繁中下会被改写为Discord邀请文案
|
||
public TextMeshProUGUI DiscordHintText;
|
||
// 挂在同一个text节点上的Button,繁中下点击跳Discord,其他语言下禁用
|
||
public Button DiscordButton;
|
||
private const string DiscordUrl = "https://discord.gg/wu2T3FCwCC";
|
||
|
||
[Header("选择列表")]
|
||
private List<UIOutsideSelectAvatarMono> _monoList;
|
||
private Empire _selectEmpire;
|
||
|
||
[Header("详细信息")]
|
||
|
||
[Header("子界面")]
|
||
public UIOutsideSelectCheckPanelMono SelectCheckPanelMono;
|
||
|
||
//关闭时执行的委托
|
||
public ViDelegateAssisstant.Dele OnBtnCloseClick;
|
||
|
||
//开始游戏时执行的委托(目前委托内容就是执行controller的Close())
|
||
public ViDelegateAssisstant.Dele OnStartGame;
|
||
|
||
protected override void OnInit()
|
||
{
|
||
base.OnInit();
|
||
AnnouncementPanel.OnInit();
|
||
AboutPanel.OnInit();
|
||
SettingPanel.OnInit();
|
||
ShutdownPanel.OnInit();
|
||
}
|
||
|
||
|
||
private void GetRandomGiantList(int count,out List<GiantType> giantTypeList)
|
||
{
|
||
var forceList = new List<ForceEnum>() { ForceEnum.Remilia, ForceEnum.Kaguya, ForceEnum.Kanako,ForceEnum.Satori,ForceEnum.Reimu, ForceEnum.Byakuren,ForceEnum.Miko,ForceEnum.Zanmu };
|
||
var chessList = new List<ChessType>()
|
||
{ ChessType.King, ChessType.Knight, ChessType.Queen, ChessType.Rook, ChessType.Bishop };
|
||
|
||
giantTypeList = new List<GiantType>();
|
||
int tct = 0;
|
||
while (giantTypeList.Count < count && tct < 10000000)
|
||
{
|
||
var force = forceList[Random.Range(0, forceList.Count)];
|
||
var chess = chessList[Random.Range(0, chessList.Count)];
|
||
if (!Table.Instance.UnitTypeDataAssets.GetGiantTypeByChessType(chess, force, out var giantType))
|
||
continue;
|
||
bool same = false;
|
||
foreach(var t in giantTypeList)
|
||
if (t == giantType)
|
||
same = true;
|
||
if(!same) giantTypeList.Add(giantType);
|
||
tct++;
|
||
}
|
||
|
||
}
|
||
|
||
public void SetContent(ShowUIOutsideMenu evt)
|
||
{
|
||
GetRandomGiantList(ButtonList.Count,out var giantTypeList);
|
||
for(int i =0;i < ButtonList.Count;i++)
|
||
ButtonList[i].SetContent(giantTypeList[i]);
|
||
|
||
StartButton.onClick.RemoveAllListeners();
|
||
StartButton.onClick.AddListener(OnStartClicked);
|
||
MultiplayButton.onClick.RemoveAllListeners();
|
||
MultiplayButton.onClick.AddListener(OnMultiplayClicked);
|
||
ResumeButton.onClick.RemoveAllListeners();
|
||
ResumeButton.gameObject.SetActive(false);
|
||
if (GameArchiveManager.Instance.HasQuickResumeArchive(NetMode.Single))
|
||
{
|
||
ResumeButton.gameObject.SetActive(true);
|
||
ResumeButton.onClick.AddListener(OnResumeClicked);
|
||
}
|
||
|
||
|
||
TutorButton.onClick.RemoveAllListeners();
|
||
TutorButton.onClick.AddListener(OnTutorClicked);
|
||
LibraryButton.onClick.RemoveAllListeners();
|
||
LibraryButton.onClick.AddListener(OnLibraryClicked);
|
||
HistoryButton.onClick.RemoveAllListeners();
|
||
HistoryButton.onClick.AddListener(OnHistoryClicked);
|
||
|
||
StoryButton.onClick.RemoveAllListeners();
|
||
StoryButton.onClick.AddListener(OnStoryClicked);
|
||
BindTransReportButton();
|
||
|
||
SettingButton.onClick.RemoveAllListeners();
|
||
SettingButton.onClick.AddListener(OnSettingClicked);
|
||
AnnouncementButton.onClick.RemoveAllListeners();
|
||
AnnouncementButton.onClick.AddListener(OnAnnouncementClicked);
|
||
AboutButton.onClick.RemoveAllListeners();
|
||
AboutButton.onClick.AddListener(OnAboutClicked);
|
||
ShutdownButton.onClick.RemoveAllListeners();
|
||
ShutdownButton.onClick.AddListener(OnShutdownClicked);
|
||
QQHintVersion.text = "V" + ConfigManager.Instance.VersionCfg.CurVersionInfo.FullVersion;
|
||
|
||
SetupDiscordHint();
|
||
|
||
//Step #6 设置BGM
|
||
AudioManager.Instance.PlayMusic("Main",1f,2f,true);
|
||
|
||
}
|
||
|
||
//在Controller 调用Close的时候,会先调用这个closeview
|
||
public void OnCloseView()
|
||
{
|
||
}
|
||
|
||
public void OnStartClicked()
|
||
{
|
||
EventManager.Publish(new ShowUIOutsideSelect());
|
||
}
|
||
|
||
public void OnResumeClicked()
|
||
{
|
||
var record = GameArchiveManager.Instance.GetQuickResumeRecord(NetMode.Single);
|
||
if (record == null) return;
|
||
|
||
// 预读新 quick 存档拿 Empire 用于切换 Loading 图;ResumeMatch 会复用该实例,不会重复反序列化。
|
||
if (!GameArchiveManager.Instance.TryLoadContinueArchive(record, out var preread)) return;
|
||
if (preread == null) return;
|
||
// 单机存档 SelfPlayer 与 ResumeMatch 内一致:PlayerDataList[0]
|
||
var dataList = preread.PlayerMap?.PlayerDataList;
|
||
var loadingEvt = new ShowUIOutsideLoading();
|
||
if (dataList != null && dataList.Count > 0)
|
||
loadingEvt.Empire = dataList[0].Empire;
|
||
|
||
EventManager.Publish(loadingEvt);
|
||
var fadeinTime = ResourceCache.Instance.AnimCache.UICommonPanelFadeIn.length;
|
||
var prepareTime = 1f;
|
||
Timer.Instance.TimerRegister(this,()=>{Main.Instance.ResumeMatch(record, preread);EventManager.Publish(new HideUIOutsideMenu());},fadeinTime,"MenuResumeClicked1");
|
||
Timer.Instance.TimerRegister(this,()=>{EventManager.Publish(new HideUIOutsideAll());},fadeinTime+prepareTime,"MenuResumeClicked2");
|
||
}
|
||
|
||
public void OnLibraryClicked()
|
||
{
|
||
EventManager.Publish(new ShowUIOutsideLibrary());
|
||
}
|
||
|
||
public void OnMultiplayClicked()
|
||
{
|
||
EventManager.Publish(new ShowUIOutsideMultiplay(){});
|
||
}
|
||
|
||
public void OnTutorClicked()
|
||
{
|
||
EventManager.Publish(new ShowUIOutsideTutor());
|
||
}
|
||
|
||
public void OnHistoryClicked()
|
||
{
|
||
EventManager.Publish(new ShowUIOutsideHistory(){});
|
||
}
|
||
public void OnAnnouncementClicked()
|
||
{
|
||
|
||
AnnouncementPanel.Open();
|
||
AnnouncementPanel.SetContent();
|
||
}
|
||
public void OnAboutClicked()
|
||
{
|
||
AboutPanel.Open();
|
||
}
|
||
|
||
public void OnSettingClicked()
|
||
{
|
||
SettingPanel.Open();
|
||
}
|
||
|
||
public void OnStoryClicked()
|
||
{
|
||
EventManager.Publish(new ShowUIOutsideStory(){});
|
||
}
|
||
|
||
public void OnShutdownClicked()
|
||
{
|
||
ShutdownPanel.Open();
|
||
}
|
||
|
||
private void BindTransReportButton()
|
||
{
|
||
if (TransReportButton == null)
|
||
{
|
||
TransReportButton = FindOrCreateButtonInChildren("TransReport");
|
||
}
|
||
|
||
if (TransReportButton == null) return;
|
||
RestoreButtonTargetAlpha(TransReportButton);
|
||
TransReportButton.onClick.RemoveAllListeners();
|
||
TransReportButton.onClick.AddListener(OnTransReportClicked);
|
||
}
|
||
|
||
private void OnTransReportClicked()
|
||
{
|
||
EventManager.Publish(new ShowUIGlobalBugReport());
|
||
}
|
||
|
||
private Button FindOrCreateButtonInChildren(string buttonName)
|
||
{
|
||
var children = GetComponentsInChildren<Transform>(true);
|
||
foreach (var child in children)
|
||
{
|
||
if (child.name != buttonName) continue;
|
||
|
||
var button = child.GetComponent<Button>();
|
||
if (button != null) return button;
|
||
|
||
button = child.gameObject.AddComponent<Button>();
|
||
button.transition = Selectable.Transition.None;
|
||
button.targetGraphic = child.GetComponent<Graphic>();
|
||
RestoreButtonTargetAlpha(button);
|
||
return button;
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
private void RestoreButtonTargetAlpha(Button button)
|
||
{
|
||
if (button?.targetGraphic == null) return;
|
||
|
||
var color = button.targetGraphic.color;
|
||
color.a = 1f;
|
||
button.targetGraphic.color = color;
|
||
}
|
||
|
||
// Discord提示文字仅繁中显示;点击时实时判断当前语言,非繁中点击直接吞掉,确保运行时切语言后行为正确
|
||
private void SetupDiscordHint()
|
||
{
|
||
if (DiscordButton != null)
|
||
{
|
||
DiscordButton.onClick.RemoveAllListeners();
|
||
DiscordButton.gameObject.SetActive(true);
|
||
DiscordButton.interactable = true;
|
||
DiscordButton.onClick.AddListener(OnDiscordButtonClicked);
|
||
}
|
||
|
||
RefreshDiscordHintText();
|
||
}
|
||
|
||
private void RefreshDiscordHintText()
|
||
{
|
||
if (DiscordHintText == null) return;
|
||
if (IsTraditionalChinese())
|
||
DiscordHintText.text = "歡迎加入官方 Discord 社群\n" + DiscordUrl;
|
||
// 非繁中: 不覆盖文字,prefab上原本的QQ群提示保留
|
||
}
|
||
|
||
private void OnDiscordButtonClicked()
|
||
{
|
||
// 点击当下实时判断: 非繁中绝对不跳转,防止玩家在游戏中切语言后此按钮仍触发外链
|
||
if (!IsTraditionalChinese()) return;
|
||
Application.OpenURL(DiscordUrl);
|
||
}
|
||
|
||
private static bool IsTraditionalChinese()
|
||
{
|
||
return MultilingualManager.Instance != null
|
||
&& MultilingualManager.Instance.GetCurLanguage() == MultilingualType.TDZH;
|
||
}
|
||
}
|
||
|
||
}
|