TH1/Unity/Assets/Scripts/TH1_UI/View/Outside/UIOutsideHistoryView.cs
2026-01-10 00:34:08 +08:00

186 lines
5.1 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;
public GameObject ItemPrefab;
//关闭时执行的委托
public ViDelegateAssisstant.Dele OnBtnCloseClick;
private List<UIOutsideHistoryItemMono> _items = new List<UIOutsideHistoryItemMono>();
protected override void OnInit()
{
base.OnInit();
CloseButton.onClick.RemoveAllListeners();
CloseButton.onClick.AddListener(OnClose);
}
private void SetItemList()
{
var dataSize = GameRecordManager.Instance.GameRecordData.Records.Count;
var dataList = GameRecordManager.Instance.GameRecordData.Records;
if (dataSize > 100) dataSize = 100;
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);
_items[i].SetContent(dataList[i]);
}
}
private void SetDropForce()
{
DropdownForceData = new List<Empire>() {
new Empire(){Civ = CivEnum.Common,Force = ForceEnum.Common},
new Empire(){Civ = CivEnum.Egyptian,Force = ForceEnum.Remilia},
new Empire(){Civ = CivEnum.French,Force = ForceEnum.Kaguya},
new Empire(){Civ = CivEnum.Germany,Force = ForceEnum.Kanako},
};
DropdownForce.ClearOptions();
List<string> options = new List<string>();
options.Add(MultilingualManager.Instance.GetMultilingualText(uint.Parse(Table.Instance.PlayerDataAssets.CommonForceTitleText)));
foreach (var item in DropdownForceData)
{
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(item.Civ, item.Force, out var info)) continue;
options.Add(MultilingualManager.Instance.GetMultilingualText(info.ForceName));
}
DropdownForce.AddOptions(options);
DropdownForce.onValueChanged.RemoveAllListeners();
DropdownForce.onValueChanged.AddListener(OnDropdownForceSelect);
}
// 新增:玩家人数下拉设置
private void SetPlayerCountDropForce()
{
if (PlayerCountDropdown == null) return;
PlayerCountData = new List<string>() { "不限", "2人", "3人", "4人", "5人", "6人", "7人", "8人" };
PlayerCountDropdown.ClearOptions();
PlayerCountDropdown.AddOptions(PlayerCountData);
PlayerCountDropdown.onValueChanged.RemoveAllListeners();
PlayerCountDropdown.onValueChanged.AddListener(OnPlayerCountSelect);
}
private void OnPlayerCountSelect(int index)
{
if (PlayerCountData == null || index < 0 || index >= PlayerCountData.Count) return;
Debug.Log($"PlayerCount selected: {PlayerCountData[index]}");
// TODO: 根据需要在这里处理筛选逻辑
}
// 新增:排序下拉设置
private void SetOrderDropForce()
{
if (OrderDropdown == null) return;
OrderDropData = new List<string>() { "按时间顺序", "按成绩顺序", "按时间倒序" };
OrderDropdown.ClearOptions();
OrderDropdown.AddOptions(OrderDropData);
OrderDropdown.onValueChanged.RemoveAllListeners();
OrderDropdown.onValueChanged.AddListener(OnOrderSelect);
}
private void OnOrderSelect(int index)
{
if (OrderDropData == null || index < 0 || index >= OrderDropData.Count) return;
Debug.Log($"Order selected: {OrderDropData[index]}");
// TODO: 根据需要在这里处理排序逻辑
}
private void OnDropdownForceSelect(int index)
{
if(!Table.Instance.PlayerDataAssets.GetPlayerInfo(DropdownForceData[index].Civ, DropdownForceData[index].Force, out var info))return;
Debug.Log(MultilingualManager.Instance.GetMultilingualText(info.ForceName));
}
public void SetContent(ShowUIOutsideHistory evt)
{
SetItemList();
SetDropForce();
SetPlayerCountDropForce();
SetOrderDropForce();
//如果数量不够先clone row补足
}
//在Controller 调用Close的时候会先调用这个closeview
public void OnCloseView()
{
}
public void OnSettingClicked()
{
}
public void OnStartClicked()
{
EventManager.Publish(new ShowUIOutsideSelect());
}
public void OnClose()
{
OnBtnCloseClick.Invoke();
}
}
}