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.
259 lines
7.0 KiB
259 lines
7.0 KiB
using Container;
|
|
using EnhancedUI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public partial class DispatchSettingView : View
|
|
{
|
|
[SerializeField] GameObject leftPanel;
|
|
[SerializeField] GameObject rightPanel;
|
|
|
|
[SerializeField] SelectedMissionUI selectedMissionUI;
|
|
|
|
[SerializeField] SettedSlotUI[] settedSlotUIs;
|
|
[SerializeField] ButtonIV dispatchButton;
|
|
[SerializeField] EScrController mateListScrollCtrl;
|
|
|
|
DispatchData.Area currentArea;
|
|
HorizontalDataMatrix<MateData> mateDataMatrix;
|
|
HashSet<uint> allEmployeeMateIDs;
|
|
MateEscrListRowSlot selectedListSlot;
|
|
|
|
SlotGroup<MateData> settedMateGroup;
|
|
|
|
public override void Show()
|
|
{
|
|
ResetPosition();
|
|
|
|
leftPanel?.SetActive(true);
|
|
rightPanel?.SetActive(true);
|
|
viewState = ViewState.Shown;
|
|
|
|
if(currentArea != null)
|
|
{
|
|
selectedMissionUI.SetArea(currentArea);
|
|
settedMateGroup = new SlotGroup<MateData>(settedSlotUIs.Length);
|
|
selectedListSlot = null;
|
|
RefreshSettedMateSlots();
|
|
RefreshDispatchButton();
|
|
RefreshMateListScroll();
|
|
}
|
|
}
|
|
|
|
public override void Hide()
|
|
{
|
|
viewState = ViewState.Hidden;
|
|
rightPanel?.SetActive(false);
|
|
leftPanel?.SetActive(false);
|
|
}
|
|
|
|
public void SetArea(DispatchData.Area area)
|
|
{
|
|
currentArea = area;
|
|
}
|
|
|
|
public void DispatchWithCurSetting()
|
|
{
|
|
var now = TimeUtils.Now();
|
|
|
|
if(!IsSafeToDispatch(now)) return;
|
|
|
|
foreach (var slot in settedMateGroup)
|
|
{
|
|
if(!slot.IsEmpty)
|
|
currentArea.SetEmployeeID(slot.slotIndex, slot.item.ID);
|
|
}
|
|
|
|
currentArea.Mission.Start(now);
|
|
RefreshDispatchButton();
|
|
RefreshMateListScroll();
|
|
}
|
|
|
|
private bool IsSafeToDispatch(DateTime now)
|
|
{
|
|
if (currentArea.IsInRefreshTime(now)) return false;
|
|
if (currentArea.Mission.InProgress(now)) return false;
|
|
return currentArea.Mission.GotReward;
|
|
}
|
|
|
|
private void RefreshSettedMateSlots()
|
|
{
|
|
if(IsSafeToDispatch(TimeUtils.Now()))
|
|
{
|
|
for (int i = 0; i < settedSlotUIs.Length; i++)
|
|
settedSlotUIs[i].SetMateData(settedMateGroup[i]);
|
|
}
|
|
else
|
|
{
|
|
int i;
|
|
for (i = 0; i < currentArea.EmployeeIDs.Count; i++)
|
|
{
|
|
if (MateDataGroup.Instance.TryGetMateData(currentArea.EmployeeIDs[i], out var mateData))
|
|
settedSlotUIs[i].SetMateData(mateData);
|
|
else
|
|
settedSlotUIs[i].SetMateData(null);
|
|
}
|
|
|
|
for (; i < settedSlotUIs.Length; i++)
|
|
settedSlotUIs[i].SetMateData(null);
|
|
}
|
|
}
|
|
|
|
private void RefreshDispatchButton()
|
|
{
|
|
if(dispatchButton is null) return;
|
|
|
|
if(IsSafeToDispatch(TimeUtils.Now()))
|
|
{
|
|
foreach (var slot in settedSlotUIs)
|
|
{
|
|
if (slot.mateData != null)
|
|
{
|
|
dispatchButton.interactable = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
dispatchButton.interactable = false;
|
|
}
|
|
|
|
private void RefreshMateListScroll()
|
|
{
|
|
if (mateListScrollCtrl is null) return;
|
|
|
|
const int columnCount = 4;
|
|
mateDataMatrix = MateDataGroup.Instance.GetMateDataMatrix(columnCount);
|
|
|
|
var mateRowIndices = new SmallList<int>();
|
|
for (int i = 0; i < mateDataMatrix.RowCount; ++i)
|
|
{
|
|
mateRowIndices.Add(i);
|
|
}
|
|
|
|
GetAllEmployeeMateIDs();
|
|
|
|
mateListScrollCtrl.LoadDatas(mateRowIndices, new ListRowDelegate
|
|
{
|
|
OnSetData = OnSetMateListRow
|
|
});
|
|
}
|
|
|
|
private void GetAllEmployeeMateIDs()
|
|
{
|
|
if(allEmployeeMateIDs is null)
|
|
allEmployeeMateIDs = new HashSet<uint>();
|
|
else
|
|
allEmployeeMateIDs.Clear();
|
|
|
|
foreach (var targetArea in DispatchDataGroup.Instance.DispatchData.Areas)
|
|
{
|
|
foreach (var id in targetArea.EmployeeIDs)
|
|
{
|
|
if (MateDataGroup.Instance.TryGetMateData(id, out var mateData))
|
|
allEmployeeMateIDs.Add(mateData.ID);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnSetMateListRow(EscrListRowSlot slot)
|
|
{
|
|
MateEscrListRowSlot mateSlot = slot as MateEscrListRowSlot;
|
|
if(mateSlot is null) return;
|
|
|
|
if (mateDataMatrix.TryGetValue(slot.RowIndex, slot.ColumnIndex, out var mateData))
|
|
{
|
|
mateSlot.SetData(mateData);
|
|
mateSlot.SetActiveSettedIndicator(allEmployeeMateIDs.Contains(mateData.ID));
|
|
mateSlot.SetActiveSelectedIndicator(selectedListSlot == mateSlot);
|
|
mateSlot.OnClick -= OnClickMateListSlot;
|
|
mateSlot.OnClick += OnClickMateListSlot;
|
|
|
|
slot.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
slot.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void OnClickMateListSlot(MateEscrListRowSlot slot)
|
|
{
|
|
if(slot == selectedListSlot) return;
|
|
|
|
if(selectedListSlot != null)
|
|
{
|
|
selectedListSlot.SetActiveSelectedIndicator(false);
|
|
}
|
|
|
|
selectedListSlot = slot;
|
|
selectedListSlot.SetActiveSelectedIndicator(true);
|
|
|
|
var selectedMateData = slot.GetData() as MateData;
|
|
|
|
if( selectedMateData is null ||
|
|
allEmployeeMateIDs.Contains(selectedMateData.ID) ||
|
|
!IsSafeToDispatch(TimeUtils.Now()))
|
|
return;
|
|
|
|
settedMateGroup.GetEmptySlots(out var emptySlots);
|
|
if(emptySlots.Count > 0)
|
|
{
|
|
settedMateGroup[emptySlots[0].slotIndex] = selectedMateData;
|
|
RefreshSettedMateSlots();
|
|
RefreshDispatchButton();
|
|
}
|
|
}
|
|
|
|
public void OnClickSettedMateSlot(int index)
|
|
{
|
|
if (!IsSafeToDispatch(TimeUtils.Now()) || index >= settedMateGroup.SlotCount) return;
|
|
|
|
settedMateGroup[index] = null;
|
|
RefreshSettedMateSlots();
|
|
RefreshDispatchButton();
|
|
}
|
|
}
|
|
|
|
public partial class DispatchSettingView : View
|
|
{
|
|
[Serializable]
|
|
struct SelectedMissionUI
|
|
{
|
|
public GameObject dummy;
|
|
public DispatchData.Area area { get; private set; }
|
|
|
|
public void SetArea(DispatchData.Area area)
|
|
{
|
|
this.area = area;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
struct SettedSlotUI
|
|
{
|
|
public ObjectIndicator indicator;
|
|
public GameObject removeIndicator;
|
|
public GameObject emptyIndicator;
|
|
public MateData mateData { get; private set; }
|
|
|
|
public void SetMateData(MateData mateData)
|
|
{
|
|
this.mateData = mateData;
|
|
|
|
if(mateData is null)
|
|
{
|
|
removeIndicator?.SetActive(false);
|
|
emptyIndicator?.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
mateData.SetIndicator(indicator);
|
|
indicator?.gameObject.SetActive(true);
|
|
removeIndicator?.SetActive(true);
|
|
emptyIndicator?.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|