247 lines
6.7 KiB
C#
247 lines
6.7 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.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(){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},
|
||
new Empire(){Civ = CivEnum.Indian,Force = ForceEnum.Satori},
|
||
};
|
||
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(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 = DropdownForce.value switch
|
||
{
|
||
0 => ForceEnum.Common,
|
||
1 => ForceEnum.Remilia,
|
||
2 => ForceEnum.Kaguya,
|
||
3 => ForceEnum.Kanako,
|
||
4 => ForceEnum.Satori,
|
||
_ => ForceEnum.Common
|
||
};
|
||
// 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));
|
||
}
|
||
|
||
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();
|
||
}
|
||
}
|
||
|
||
}
|