/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FL.Data.Items;
using FL.Network;
using XGame.Database;
using XGame.Framework.UI;
namespace FL.FGUI
{
public class ItemParam
{
public long id;
public int tableId;
public int count;
public int level;
}
///
/// UI逻辑处理类
///
///
public partial class ItemRewardItemCtrl : UIController
{
private long _equipId; // 装备的uid
protected override void OnEnable(object intent)
{
AddUIListenres();
}
protected override void OnDisable()
{
RemoveUIListenres();
}
#region UI事件
private void AddUIListenres()
{
}
private void RemoveUIListenres()
{
}
#endregion
public void OnRefresh(int index, KindItem param)
{
EquipItem equipData = null;
Item _item = new Item();
bool bEquip = param.count == 0;
int itemId = param.id;
if (bEquip)
{
equipData = EquipData.Instance.GetTemporaryEquipItem(itemId);
itemId = equipData.TableId;
_item.Level = equipData.Level;
_equipId = itemId;
}
else
_equipId = 0;
ShowCompareEquip(bEquip, equipData);
var itemInfo = ItemTableRepo.Get(itemId);
if (itemInfo != null)
{
_item.Count = param.count.ToString();
_item.Init(itemInfo, bEquip ? param.id : 0);
UiParam _uiParam = new UiParam();
_uiParam.bShowBtn = true;
_uiParam.bShowName = false;
_uiParam.bShowCount = param.count > 1;
_uiParam.bShowLevel = bEquip;
_uiParam.bShowBaseInfo = bEquip ? false : true;
VM.ItemBtn.Ctrl.ShowUI(_item, _uiParam);
}
}
///
/// 装备战力比较标识
///
private void ShowCompareEquip(bool bEquip, EquipItem equipData)
{
ShowEquipCtrlIndex(bEquip ? GetCompareValue(equipData) : 0);
}
private void ShowEquipCtrlIndex(int index)
{
VM.EquipCtrl.selectedIndex = index;
}
///
/// 与身上穿戴部位战力比较
///
///
///
private int GetCompareValue(EquipItem equipData)
{
int compareFlag = 0;
if (equipData?.Table?.Part > 0)
{
var wearEquipItem = EquipData.Instance.GetWearEquipData(equipData.Table.Part);
long wearFightingPower = wearEquipItem?.FightingPower ?? 0;
if (equipData.FightingPower > wearFightingPower)
compareFlag = 1;
else if (equipData.FightingPower < wearFightingPower)
compareFlag = 2;
}
return compareFlag;
}
}
}