You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.5 KiB
133 lines
3.5 KiB
using System;
|
|
using System.ComponentModel;
|
|
using UnityEngine;
|
|
|
|
public partial class MateListRow : EScrCell, IOnRecieveIntent
|
|
{
|
|
static MateListRow _hasSelectedSlotRow;
|
|
|
|
[SerializeField] SlotUI[] slotUIs;
|
|
|
|
MonoBehaviour intent;
|
|
SlotUI selected;
|
|
|
|
public MateData SelectedMateData => selected?.mateData;
|
|
|
|
public override void InitCell()
|
|
{
|
|
for(int i = 0; i < slotUIs.Length; ++i)
|
|
{
|
|
slotUIs[i].SetActiveSelectedIndicator(false);
|
|
}
|
|
}
|
|
|
|
public override void RefreshCellView()
|
|
{
|
|
intent = null;
|
|
DeselectCurrent();
|
|
}
|
|
|
|
public override void SetData(int rowIndex)
|
|
{
|
|
const int columnCount = 4;
|
|
var row = MateDataGroup.Instance.GetMateDataMatrix(columnCount)[rowIndex];
|
|
|
|
int i;
|
|
for (i = 0; i < row.Count; ++i)
|
|
{
|
|
var mateData = row[i];
|
|
if (mateData is null || slotUIs.Length <= i) continue;
|
|
|
|
slotUIs[i].SetMateData(mateData);
|
|
|
|
if (_hasSelectedSlotRow is null)
|
|
{
|
|
_hasSelectedSlotRow = this;
|
|
|
|
selected = slotUIs[i];
|
|
SelectCurrent();
|
|
|
|
var _parms = new object[] { this, false };
|
|
intent?.SendMessage(nameof(MateSettingView.OnClickedListSlot), _parms);
|
|
}
|
|
}
|
|
|
|
for (; i < slotUIs.Length; ++i)
|
|
slotUIs[i].SetMateData(null);
|
|
|
|
SelectCurrent();
|
|
}
|
|
|
|
public void OnClickSlot(int index)
|
|
{
|
|
selected = slotUIs[index];
|
|
SelectCurrent();
|
|
|
|
var _parms = new object[] { this, true };
|
|
intent?.SendMessage(nameof(MateSettingView.OnClickedListSlot), _parms);
|
|
}
|
|
|
|
public void SelectCurrent()
|
|
{
|
|
if (selected is null) return;
|
|
|
|
_hasSelectedSlotRow = this;
|
|
selected.SetActiveSelectedIndicator(true);
|
|
}
|
|
|
|
public void DeselectCurrent()
|
|
{
|
|
selected?.SetActiveSelectedIndicator(false);
|
|
selected = null;
|
|
_hasSelectedSlotRow = null;
|
|
}
|
|
|
|
public void OnRecieveIntent(object intent) => this.intent = intent as MonoBehaviour;
|
|
}
|
|
|
|
public partial class MateListRow : EScrCell
|
|
{
|
|
[Serializable]
|
|
public class SlotUI
|
|
{
|
|
public ObjectIndicator indicator;
|
|
public GameObject unlockIndicator;
|
|
public GameObject settedIndicator;
|
|
public GameObject selectedIndicator;
|
|
|
|
public MateData mateData { get; private set; }
|
|
|
|
public void SetMateData(MateData mateData)
|
|
{
|
|
if(this.mateData != null)
|
|
this.mateData.PropertyChanged -= HandlePropertyChanged;
|
|
|
|
this.mateData = mateData;
|
|
|
|
if(mateData != null)
|
|
{
|
|
mateData.SetIndicator(indicator);
|
|
unlockIndicator?.gameObject.SetActive(!mateData.IsUnlocked);
|
|
settedIndicator?.gameObject.SetActive(mateData.IsSetted);
|
|
mateData.PropertyChanged += HandlePropertyChanged;
|
|
}
|
|
else
|
|
{
|
|
indicator?.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void SetActiveSelectedIndicator(bool active)
|
|
{
|
|
selectedIndicator?.gameObject.SetActive(active);
|
|
}
|
|
|
|
private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
if(e.PropertyName == nameof(MateData.IsUnlocked))
|
|
unlockIndicator?.SetActive(!mateData.IsUnlocked);
|
|
else if(e.PropertyName == nameof(MateData.IsSetted))
|
|
settedIndicator?.SetActive(mateData.IsSetted);
|
|
}
|
|
}
|
|
}
|