2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.6 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using Game.Battle;
namespace Game
{
public class PageBlessChoose : UIPageBase<ViewBlessChoose>
{
private List<string> _blessList;
private int _choiceNow = 0;
private int _choiceMax = 0;
private bool _isChoiceOpen = true;
public PageBlessChoose()
{
}
protected override void OnCreate()
{
CreateUI(true);
}
protected override void OnDestroy()
{
}
protected override void OnOpen(params object[] values)
{
UIManager.Instance.Open(EuiPage.BlessList, true);
Util.SetControl(false);
if (values.Length == 0)
{
Util.Print("PageBlessChoose 未传入目标元素");
UIManager.Instance.Close();
return;
}
RefreshBless();
}
protected override void OnClose()
{
Util.SetControl(true);
}
private void RefreshBless()
{
GameRandom.Shuffle(_blessList);
var blessNum = Mathf.Min(3, _blessList.Count);
var uiList = View.m_blessList;
uiList.RemoveChildrenToPool();
for (int i = 0; i < blessNum; i++)
{
var item = uiList.AddItemFromPool() as ViewBlessItem;
var cfg = Util.GetBlessConfig(_blessList[i]);
item.m_BlessName.text = cfg.Bless.Name;
item.m_BlessDesc.text = cfg.Bless.Describe;
item.m_BlessIcon.texture = Texture(cfg.Bless.Icon);
}
_choiceNow = 0;
_choiceMax = blessNum;
RefreshChoiceSelecet();
}
private void RefreshChoiceSelecet()
{
var choiceList = View.m_blessList.GetChildren();
for (int i = 0; i < choiceList.Length; i++)
{
var choice = choiceList[i] as ViewBlessItem;
choice.m_c1.selectedIndex = i == _choiceNow ? 1 : 0;
}
}
protected override void OnInput(PPlayerInput context)
{
if (context.Action == EKeyActionType.Press)
{
if (context.Key == EFunctionKey.Up || context.Key == EFunctionKey.Down)
{
if (!_isChoiceOpen)
{
return;
}
if (_blessList.Count == 0)
{
return;
}
var newIndex = _choiceNow;
if (context.Key == EFunctionKey.Up)
{
newIndex--;
}
else
{
newIndex++;
}
_choiceNow = (newIndex + _choiceMax) % _choiceMax;
RefreshChoiceSelecet();
}
if (context.Key == EFunctionKey.Jump)
{
if (_blessList.Count > 0)
{
var chosenBless = _blessList[_choiceNow];
var master = Util.GetMaster();
Util.AddBless(master, chosenBless);
}
UIManager.Instance.Close();
}
if (context.Key == EFunctionKey.Refresh)
{
RefreshBless();
}
}
}
}
}