TH1/Unity/Assets/Scripts/TH1_UI/View/Outside/UIOutsideHistoryView.cs

252 lines
6.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.Net;
using TH1_Logic.Steam;
using TH1_UI.View.Announce;
using TH1Resource;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
namespace TH1_UI.View.Outside
{
public class UIOutsideHistoryView : Base.View
{
[Header("按钮")]
//public Button CloseButton;
public Button CloseButton;
public Transform ItemList;
public TMP_Dropdown DropdownForce;
public RectTransform DropdownForceRect;
private List<Empire> DropdownForceData;
// 新增:玩家人数下拉与排序下拉
public TMP_Dropdown PlayerCountDropdown;
public RectTransform PlayerCountDropdownRect;
private List<string> PlayerCountData;
public TMP_Dropdown OrderDropdown;
public RectTransform OrderDropdownRect;
private List<string> OrderDropData;
// 顶部模式选择栏: 0=DOMINATION, 1=PERFECT, 2=CREATIVE
[Header("模式选择栏")]
public UIOutsideSelectOptionGroupMono ModeOptionGroup;
public GameObject ItemPrefab;
//关闭时执行的委托
public ViDelegateAssisstant.Dele OnBtnCloseClick;
private List<UIOutsideHistoryItemMono> _items = new List<UIOutsideHistoryItemMono>();
private GameMode _currentGameMode = GameMode.DOMINATION;
protected override void OnInit()
{
base.OnInit();
CloseButton.onClick.RemoveAllListeners();
CloseButton.onClick.AddListener(OnClose);
}
private void SetItemList(List<GameRecord> dataList)
{
int dataSize = Mathf.Min(dataList.Count,100);
//var dataSize = GameRecordManager.Instance.GameRecordData.Records.Count;
//var dataList = GameRecordManager.Instance.GameRecordData.Records;
while (_items.Count < dataSize)
{
var obj = Instantiate(ItemPrefab, ItemList);
var cpn = obj?.GetComponent<UIOutsideHistoryItemMono>();
if (cpn == null) break;
_items.Add(cpn);
}
for (int i = 0; i < _items.Count; i++)
{
_items[i].gameObject.SetActive(i < dataSize);
if (i >= dataSize) continue;
_items[i].SetContent(dataList[i]);
}
}
private void SetDropForce()
{
DropdownForceData = new List<Empire>
{
new Empire(CivEnum.Common, ForceEnum.Common)
};
DropdownForce.ClearOptions();
List<string> options = new List<string>
{
MultilingualManager.Instance.GetMultilingualText(uint.Parse(Table.Instance.PlayerDataAssets.CommonForceTitleText))
};
foreach (var info in Table.Instance.PlayerDataAssets.PlayerDataList)
{
if (info == null || !ContentGate.CanSelectEmpire(info.CivId, info.ForceId)) continue;
var empire = new Empire(
Table.Instance.TransCivIdToCivEnum(info.CivId),
Table.Instance.TransForceIdToForceEnum(info.ForceId));
DropdownForceData.Add(empire);
options.Add(MultilingualManager.Instance.GetMultilingualText(info.ForceName));
}
DropdownForce.AddOptions(options);
DropdownForce.SetValueWithoutNotify(0);
DropdownForce.onValueChanged.RemoveAllListeners();
DropdownForce.onValueChanged.AddListener(OnOrderUpdate);
}
// 玩家人数下拉: index 0=NoLimit, 1..16 → 2P..17P
private void SetPlayerCountDropForce()
{
if (PlayerCountDropdown == null) return;
PlayerCountData = new List<string>();
PlayerCountData.Add(MultilingualManager.Instance.GetMultilingualText(Table.Instance.TextDataAssets.OutsideHistoryDropListNoLimitP));
for (int n = 2; n <= 17; n++)
PlayerCountData.Add(n + "P");
PlayerCountDropdown.ClearOptions();
PlayerCountDropdown.AddOptions(PlayerCountData);
PlayerCountDropdown.onValueChanged.RemoveAllListeners();
PlayerCountDropdown.onValueChanged.AddListener(OnOrderUpdate);
}
// 新增:排序下拉设置
private void SetOrderDropForce()
{
if (OrderDropdown == null) return;
OrderDropData = new List<string>() {
MultilingualManager.Instance.GetMultilingualText(Table.Instance.TextDataAssets.OutsideHistoryDropListTimeOrder),
MultilingualManager.Instance.GetMultilingualText(Table.Instance.TextDataAssets.OutsideHistoryDropListScoreOrder),
MultilingualManager.Instance.GetMultilingualText(Table.Instance.TextDataAssets.OutsideHistoryDropListTimeOrderR),
};
OrderDropdown.ClearOptions();
OrderDropdown.AddOptions(OrderDropData);
OrderDropdown.onValueChanged.RemoveAllListeners();
OrderDropdown.onValueChanged.AddListener(OnOrderUpdate);
}
private void OnOrderUpdate(int index)
{
_RefreshList();
}
private void _RefreshList()
{
var gameMode = _currentGameMode;
var forceEnum = GetSelectedForceEnum();
// index 0 = 不限, 1..16 → 玩家数 2..17
int playerCount = PlayerCountDropdown.value == 0 ? 0 : PlayerCountDropdown.value + 1;
bool isScore = false;
bool isTime = false;
bool isTurn = false;
bool order = true;
switch( OrderDropdown.value)
{
case 0:
isTime = true;
break;
case 1:
isTurn = true;
break;
case 2:
isTime = true;
order = false;
break;
}
SetItemList(GameRecordManager.Instance.GetSortGameRecordList(gameMode,forceEnum,playerCount,isScore,isTurn,isTime,order));
}
private ForceEnum GetSelectedForceEnum()
{
if (DropdownForceData == null || DropdownForce == null) return ForceEnum.Common;
var index = DropdownForce.value;
if (index < 0 || index >= DropdownForceData.Count) return ForceEnum.Common;
return DropdownForceData[index].Force;
}
public void SetContent(ShowUIOutsideHistory evt)
{
_currentGameMode = GameMode.DOMINATION;
SetItemList(GameRecordManager.Instance.GetSortGameRecordList(_currentGameMode, ForceEnum.Common, 0,
false, false, true, true));
//GameRecordManager.Instance.GameRecordData.Records);
SetDropForce();
SetPlayerCountDropForce();
SetOrderDropForce();
SetModeOptionGroup();
//如果数量不够先clone row补足
}
// 顶部模式选择栏: 0=DOMINATION, 1=PERFECT, 2=CREATIVE
private void SetModeOptionGroup()
{
if (ModeOptionGroup == null) return;
ModeOptionGroup.OnOptionClicked = null;
ModeOptionGroup.Init(0);
ModeOptionGroup.OnOptionClicked = OnModeChanged;
}
private void OnModeChanged(uint index)
{
_currentGameMode = index switch
{
0 => GameMode.DOMINATION,
1 => GameMode.PERFECT,
2 => GameMode.CREATIVE,
_ => GameMode.DOMINATION
};
_RefreshList();
}
//在Controller 调用Close的时候会先调用这个closeview
public void OnCloseView()
{
}
public void OnSettingClicked()
{
}
public void OnStartClicked()
{
EventManager.Publish(new ShowUIOutsideSelect());
}
public void OnClose()
{
OnBtnCloseClick.Invoke();
}
}
}