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.
220 lines
6.0 KiB
220 lines
6.0 KiB
using EnhancedUI;
|
|
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public partial class MateSettingView : View
|
|
{
|
|
[SerializeField] GameObject leftPanel;
|
|
[SerializeField] GameObject rightPanel;
|
|
|
|
[SerializeField] SelectedMateUI selectedMateUI;
|
|
|
|
[SerializeField] SettedSlotUI[] settedSlots;
|
|
[SerializeField] EScrController mateListScrollCtrl;
|
|
|
|
MateListRow prevSelectedListRow;
|
|
|
|
private void Start()
|
|
{
|
|
leftPanel.SetActive(false);
|
|
rightPanel.SetActive(false);
|
|
viewState = ViewState.Hidden;
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
GameUIMgr.SSetMainUiOn(false);
|
|
GameUIMgr.SOpenLeftPanel(gold: true);
|
|
|
|
ResetPosition();
|
|
leftPanel.SetActive(true);
|
|
rightPanel.SetActive(true);
|
|
viewState = ViewState.Shown;
|
|
|
|
RefreshSettedMateSlots();
|
|
RefreshMateListScroll();
|
|
}
|
|
|
|
private void RefreshMateListScroll()
|
|
{
|
|
if (mateListScrollCtrl is null) return;
|
|
|
|
const int columnCount = 4;
|
|
int rowCount = MateDataGroup.Instance.GetMateDataMatrix(columnCount).RowCount;
|
|
|
|
var mateRowIndices = new SmallList<int>();
|
|
for (int i = 0; i < rowCount; ++i)
|
|
{
|
|
mateRowIndices.Add(i);
|
|
}
|
|
|
|
mateListScrollCtrl.LoadDatas(mateRowIndices, this);
|
|
}
|
|
|
|
public override void Hide()
|
|
{
|
|
leftPanel.SetActive(false);
|
|
rightPanel.SetActive(false);
|
|
viewState = ViewState.Hidden;
|
|
|
|
prevSelectedListRow = null;
|
|
mateListScrollCtrl.scroller.RefreshActiveCellViews();
|
|
|
|
selectedMateUI.SetMateData(null);
|
|
|
|
GameUIMgr.SCloseLeftPanel();
|
|
GameUIMgr.SSetMainUiOn(true);
|
|
}
|
|
|
|
public void OnClickedSettedSlot(int slotIdx)
|
|
{
|
|
if(slotIdx < 0 || slotIdx >= settedSlots.Length) return;
|
|
RemoveSettedMateIfAvalilable(settedSlots[slotIdx]);
|
|
}
|
|
|
|
public void OnClickShowPrivateSkillButton()
|
|
{
|
|
if(prevSelectedListRow is null) return;
|
|
|
|
}
|
|
|
|
public void OnClickShowExtraEffectButton()
|
|
{
|
|
if(prevSelectedListRow is null) return;
|
|
}
|
|
|
|
public void OnClickedListSlot(object[] _parms)
|
|
{
|
|
var mateListRow = _parms[0] as MateListRow;
|
|
bool requestSpawn = (bool)_parms[1];
|
|
|
|
if(prevSelectedListRow != mateListRow)
|
|
{
|
|
prevSelectedListRow?.DeselectCurrent();
|
|
prevSelectedListRow = mateListRow;
|
|
}
|
|
|
|
if(requestSpawn)
|
|
SetSelectedMateIfAvailable();
|
|
|
|
RefreshSelectedMateUI();
|
|
}
|
|
|
|
private void RefreshSelectedMateUI()
|
|
{
|
|
if(prevSelectedListRow is null) return;
|
|
selectedMateUI.SetMateData(prevSelectedListRow.SelectedMateData);
|
|
}
|
|
|
|
private void SetSelectedMateIfAvailable()
|
|
{
|
|
if(prevSelectedListRow is null ||
|
|
prevSelectedListRow.SelectedMateData is null ||
|
|
!prevSelectedListRow.SelectedMateData.IsUnlocked)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var mateMgr = MateMgr.Instance;
|
|
|
|
mateMgr.SettedMates.GetEmptySlots(out var emptyList);
|
|
if (emptyList.Count != 0)
|
|
{
|
|
var emptySlot = emptyList[0];
|
|
mateMgr.SetMateAt(prevSelectedListRow.SelectedMateData.ID, emptySlot.slotIndex);
|
|
RefreshSettedMateSlots();
|
|
}
|
|
}
|
|
|
|
private void RemoveSettedMateIfAvalilable(SettedSlotUI targetSlot)
|
|
{
|
|
if (targetSlot.slot.IsEmpty) return;
|
|
|
|
var mateMgr = MateMgr.Instance;
|
|
if(mateMgr.ActiveMate.Data.ID == targetSlot.slot.item.Data.ID && !mateMgr.IsSafeToChangeCurrentMate())
|
|
{
|
|
GameUIMgr.SOpenToast(LocalizationText.GetText("try_and_failed_0"));
|
|
}
|
|
else
|
|
{
|
|
mateMgr.RemoveMateAt(targetSlot.slot.slotIndex);
|
|
settedSlots[targetSlot.slot.slotIndex].SetSlot(new SlotGroup<IVMate>.Slot() { slotIndex = targetSlot.slot.slotIndex });
|
|
}
|
|
}
|
|
|
|
private void RefreshSettedMateSlots()
|
|
{
|
|
int i = 0;
|
|
foreach (var slot in MateMgr.Instance.SettedMates)
|
|
{
|
|
if(i >= settedSlots.Length) break;
|
|
settedSlots[i].SetSlot(slot);
|
|
++i;
|
|
}
|
|
}
|
|
}
|
|
|
|
public partial class MateSettingView : View
|
|
{
|
|
[Serializable]
|
|
struct SelectedMateUI
|
|
{
|
|
public ObjectIndicator indicator;
|
|
public ExtendText nameText;
|
|
public GraphicsColorSetter nameTextColorSetter;
|
|
public TextMeshProUGUI levelText;
|
|
public MateData mateData { get; private set; }
|
|
|
|
public void SetMateData(MateData mateData)
|
|
{
|
|
this.mateData = mateData;
|
|
|
|
if(mateData is null)
|
|
{
|
|
indicator?.gameObject.SetActive(false);
|
|
|
|
nameText?.SetText(string.Empty);
|
|
levelText?.SetText(string.Empty);
|
|
}
|
|
else
|
|
{
|
|
mateData.SetIndicator(indicator);
|
|
indicator?.gameObject.SetActive(true);
|
|
|
|
nameText?.SetText(LocalizationInjector.MakeToLocalizationKey(mateData.NameKey));
|
|
nameTextColorSetter?.SetColor(mateData.Grade.ToString());
|
|
|
|
if(levelText != null)
|
|
levelText.text = FormatString.StringFormat("Lv.{0}/{1}", mateData.Level, MateDataGroup.Instance.MateMaxLevel);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
struct SettedSlotUI
|
|
{
|
|
public ObjectIndicator indicator;
|
|
public GameObject removeIndicator;
|
|
public GameObject emptyIndicator;
|
|
public SlotGroup<IVMate>.Slot slot { get; private set; }
|
|
|
|
public void SetSlot(SlotGroup<IVMate>.Slot slot)
|
|
{
|
|
this.slot = slot;
|
|
|
|
if(slot.IsEmpty)
|
|
{
|
|
removeIndicator?.SetActive(false);
|
|
emptyIndicator?.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
slot.item.Data.SetIndicator(indicator);
|
|
indicator.gameObject.SetActive(true);
|
|
removeIndicator.SetActive(true);
|
|
emptyIndicator.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|