2025-05-18 01:04:31 +08:00

128 lines
2.7 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-04-20
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "EquipmentWindow.View" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G.UI
{
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using static G.PlayerProxy;
/// <summary>
///
/// </summary>
partial class EquipmentWindow
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Button _btnBack;
[KUIFlag]
KUIList _listSlots;
[KUIFlag]
GameObject __goSelectSlot;
[KUIFlag]
GameObject __goPanel1;
[KUIFlag]
GameObject __goPanel2;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private EquipmentUpgradeWidget _upgradeWidget;
private EquipmentSlotWidget _selectSlotWidget;
private readonly List<EquipmentSlotWidget> _slotWidgets = new List<EquipmentSlotWidget>(6);
#endregion
#region Method
/// <summary>
///
/// </summary>
public void InitView()
{
SetViewData();
_listSlots.AddTemplate<EquipmentSlotWidget>(true);
_btnBack.onClick.AddListener(this.OnBackBtnClick);
_selectSlotWidget = __goSelectSlot.GetComponent<EquipmentSlotWidget>();
_upgradeWidget = __goPanel1.GetComponent<EquipmentUpgradeWidget>();
}
/// <summary>
///
/// </summary>
public void RefreshView()
{
EquipmentSlotInfo firstSlot = null;
_slotWidgets.Clear();
_listSlots.Clear();
var slots = PlayerProxy.Instance.GetEquipmentSlots();
for (int i = 0; i < slots.Length; i++)
{
if (slots[i].equipment != null)
{
var slotW = _listSlots.GetItem<EquipmentSlotWidget>();
slotW.SetData(slots[i]);
_slotWidgets.Add(slotW);
if (firstSlot == null)
{
firstSlot = slots[i];
}
}
}
if (this.data is EquipmentSlotInfo equipmentSlot)
{
SetSelect(equipmentSlot);
}
else
{
SetSelect(firstSlot);
}
}
private void RefreshSlot()
{
foreach (var slotWidget in _slotWidgets)
{
slotWidget.Refresh();
}
_selectSlotWidget.Refresh();
_upgradeWidget.Refresh();
}
private void SetSelect(EquipmentSlotInfo equipmentSlot)
{
_selectSlotWidget.SetData(equipmentSlot);
_upgradeWidget.SetData(equipmentSlot);
}
/// <summary>
///
/// </summary>
public void UpdateView()
{
}
private void OnBackBtnClick()
{
CloseWindow(this);
}
#endregion
}
}