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.
187 lines
6.0 KiB
C#
187 lines
6.0 KiB
C#
|
2 years ago
|
using System;
|
||
|
|
using UnityEngine;
|
||
|
|
using FairyGUI;
|
||
|
|
using Game.Battle;
|
||
|
|
|
||
|
|
namespace Game
|
||
|
|
{
|
||
|
|
public class PageWeapon : UIPageBase<ViewWeapon>
|
||
|
|
{
|
||
|
|
private int _indexNow = 0;
|
||
|
|
private float _weaponListShowTime = 0;
|
||
|
|
public PageWeapon()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
protected override void OnCreate()
|
||
|
|
{
|
||
|
|
CreateUI(false);
|
||
|
|
InitWeaponList();
|
||
|
|
}
|
||
|
|
protected override void OnDestroy()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
protected override void OnOpen()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
protected override void OnClose()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
public override void Update()
|
||
|
|
{
|
||
|
|
if (_weaponListShowTime == 0)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
_weaponListShowTime -= Time.deltaTime;
|
||
|
|
if (_weaponListShowTime <= 0)
|
||
|
|
{
|
||
|
|
_weaponListShowTime = 0;
|
||
|
|
SetListShow(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
private void InitWeaponList()
|
||
|
|
{
|
||
|
|
var master = Util.GetMaster();
|
||
|
|
var combo = master.combo;
|
||
|
|
_indexNow = combo.WeaponNow.Value;
|
||
|
|
|
||
|
|
View.m_WeaponList.RemoveChildrenToPool();
|
||
|
|
View.m_WeaponList.SetVirtualAndLoop();
|
||
|
|
View.m_WeaponList.itemRenderer = (int index, GObject obj) =>
|
||
|
|
{
|
||
|
|
var count = combo.WeaponList.Count;
|
||
|
|
var targetIndex = (index) % count;
|
||
|
|
var item = (obj as ViewWeaponItem);
|
||
|
|
item.m_index.text = $"{index}";
|
||
|
|
|
||
|
|
var weaponId = combo.WeaponList[targetIndex];
|
||
|
|
var cfg = Util.GetWeaponConfig(weaponId);
|
||
|
|
|
||
|
|
item.m_item.m_name.text = cfg.WeaponBasic.Name;
|
||
|
|
item.m_item.m_icon.texture = Texture(cfg.WeaponBasic.Icon);
|
||
|
|
item.m_item.m_icon_back.texture = Texture(cfg.WeaponBasic.Icon);
|
||
|
|
|
||
|
|
RefreshItemStatu(item);
|
||
|
|
};
|
||
|
|
|
||
|
|
var count = combo.WeaponList.Count;
|
||
|
|
var listCount = count * 2;
|
||
|
|
View.m_WeaponList.numItems = listCount;
|
||
|
|
|
||
|
|
var targetIndex = (_indexNow - 2 + listCount) % listCount;
|
||
|
|
View.m_WeaponList.ScrollToView(targetIndex, true, true);
|
||
|
|
}
|
||
|
|
protected override void OnCreateBind()
|
||
|
|
{
|
||
|
|
var master = Util.GetMaster();
|
||
|
|
BindWeapon(master); //绑定武器
|
||
|
|
}
|
||
|
|
private void BindWeapon(GameEntity entity)
|
||
|
|
{
|
||
|
|
var combo = entity.combo;
|
||
|
|
BindData(combo.WeaponNow, (_, now) =>
|
||
|
|
{
|
||
|
|
var count = combo.WeaponList.Count;
|
||
|
|
var listCount = count * 2;
|
||
|
|
var now2 = now + count;
|
||
|
|
var indexPre = _indexNow;
|
||
|
|
if (Distance(_indexNow, now, listCount) < Distance(_indexNow, now2, listCount))
|
||
|
|
{
|
||
|
|
_indexNow = now;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
_indexNow = now2;
|
||
|
|
}
|
||
|
|
if (indexPre == _indexNow)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (View.m_c1.selectedIndex == 0)
|
||
|
|
{
|
||
|
|
SetListShow(true);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
var moveDistance = DistanceDir(indexPre, _indexNow, listCount);
|
||
|
|
if (moveDistance > 0)
|
||
|
|
{
|
||
|
|
View.m_WeaponList.scrollPane.ScrollRight(Math.Abs(moveDistance), true);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
View.m_WeaponList.scrollPane.ScrollLeft(Math.Abs(moveDistance), true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
_weaponListShowTime = GameConst.WeaponListShowTime;
|
||
|
|
|
||
|
|
foreach (var itemObj in View.m_WeaponList.GetChildren())
|
||
|
|
{
|
||
|
|
RefreshItemStatu(itemObj as ViewWeaponItem);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
private void SetListShow(bool isShow)
|
||
|
|
{
|
||
|
|
if (isShow)
|
||
|
|
{
|
||
|
|
var master = Util.GetMaster();
|
||
|
|
var combo = master.combo;
|
||
|
|
var count = combo.WeaponList.Count;
|
||
|
|
var listCount = count * 2;
|
||
|
|
var targetIndex = (_indexNow - 2 + listCount) % listCount;
|
||
|
|
View.m_WeaponList.ScrollToView(targetIndex, false, true);
|
||
|
|
}
|
||
|
|
View.m_c1.selectedIndex = isShow ? 1 : 0;
|
||
|
|
}
|
||
|
|
private void RefreshItemStatu(ViewWeaponItem item)
|
||
|
|
{
|
||
|
|
var master = Util.GetMaster();
|
||
|
|
var combo = master.combo;
|
||
|
|
var count = combo.WeaponList.Count;
|
||
|
|
var listCount = count * 2;
|
||
|
|
var itemIndex = Int32.Parse(item.m_index.text);
|
||
|
|
//调整大小
|
||
|
|
var isChosen = itemIndex == _indexNow;
|
||
|
|
item.m_c1.selectedIndex = isChosen ? 1 : 0;
|
||
|
|
item.m_item.m_c1.selectedIndex = isChosen ? 1 : 0;
|
||
|
|
//调整显示
|
||
|
|
var distance = DistanceDir(_indexNow, itemIndex, listCount);
|
||
|
|
var isShow = distance >= -1 && distance <= 2;
|
||
|
|
item.m_c2.selectedIndex = isShow ? 0 : 1;
|
||
|
|
}
|
||
|
|
private int DistanceDir(int i1, int i2, int max)
|
||
|
|
{
|
||
|
|
if (i1 == i2)
|
||
|
|
{
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
var distance1 = 0;//往右
|
||
|
|
var distance2 = 0;//往左
|
||
|
|
|
||
|
|
if (i2 > i1)
|
||
|
|
{
|
||
|
|
distance1 = i2 - i1;
|
||
|
|
distance2 = i1 - i2 + max;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
distance1 = i2 - i1 + max;
|
||
|
|
distance2 = i1 - i2;
|
||
|
|
}
|
||
|
|
if (Mathf.Abs(distance1) > Mathf.Abs(distance2))
|
||
|
|
{
|
||
|
|
return -distance2;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return distance1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
private int Distance(int i1, int i2, int max)
|
||
|
|
{
|
||
|
|
return Mathf.Abs(DistanceDir(i1, i2, max));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|