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.
407 lines
13 KiB
407 lines
13 KiB
using Container;
|
|
using EnhancedUI;
|
|
using IVDataFormat;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
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;
|
|
|
|
[SerializeField] ExtendText curListViewModeText;
|
|
|
|
DispatchData.Area currentArea;
|
|
HorizontalDataMatrix<MateData> mateDataMatrix;
|
|
HashSet<MateData> allEmployeeMates;
|
|
|
|
MateData selectedMate;
|
|
MateEscrListRowSlot selectedListSlot;
|
|
|
|
SlotGroup<MateData> settedMates;
|
|
|
|
MateEscrListRowSlot.ViewMode curViewMode;
|
|
|
|
private void Start()
|
|
{
|
|
leftPanel?.SetActive(false);
|
|
rightPanel?.SetActive(false);
|
|
viewState = ViewState.Hidden;
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
ResetPosition();
|
|
|
|
leftPanel?.SetActive(true);
|
|
rightPanel?.SetActive(true);
|
|
viewState = ViewState.Shown;
|
|
|
|
if(currentArea != null)
|
|
{
|
|
selectedMissionUI.SetArea(currentArea);
|
|
settedMates = new SlotGroup<MateData>(settedSlotUIs.Length);
|
|
RefreshSettedMateSlots();
|
|
RefreshDispatchButton();
|
|
RefreshMateListScroll();
|
|
selectedMissionUI.SetNationalityBonus(settedMates);
|
|
selectedMissionUI.SetEmployeeCountBonus(settedMates);
|
|
}
|
|
}
|
|
|
|
public override void Hide()
|
|
{
|
|
selectedListSlot = null;
|
|
selectedMate = null;
|
|
|
|
mateDataMatrix = null;
|
|
|
|
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 settedMates)
|
|
{
|
|
if(!slot.IsEmpty)
|
|
currentArea.SetEmployeeID(slot.slotIndex, slot.item.ID);
|
|
}
|
|
|
|
currentArea.StartMission(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(settedMates[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);
|
|
settedMates[i] = mateData;
|
|
}
|
|
else
|
|
{
|
|
settedSlotUIs[i].SetMateData(null);
|
|
settedMates[i] = null;
|
|
}
|
|
}
|
|
|
|
for (; i < settedSlotUIs.Length; i++)
|
|
{
|
|
settedSlotUIs[i].SetMateData(null);
|
|
settedMates[i] = 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;
|
|
|
|
if (mateDataMatrix is null)
|
|
{
|
|
const int columnCount = 4;
|
|
mateDataMatrix = MateDataGroup.Instance.GetMateDataMatrix(MateData.CompareByGrade, 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(allEmployeeMates is null)
|
|
allEmployeeMates = new HashSet<MateData>();
|
|
else
|
|
allEmployeeMates.Clear();
|
|
|
|
foreach (var targetArea in DispatchDataGroup.Instance.DispatchData.Areas)
|
|
{
|
|
foreach (var id in targetArea.EmployeeIDs)
|
|
{
|
|
if (MateDataGroup.Instance.TryGetMateData(id, out var mateData))
|
|
allEmployeeMates.Add(mateData);
|
|
}
|
|
}
|
|
}
|
|
|
|
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.viewMode = curViewMode;
|
|
mateSlot.SetData(mateData);
|
|
mateSlot.SetActiveSettedIndicator(allEmployeeMates.Contains(mateData));
|
|
mateSlot.SetActiveSelectedIndicator(selectedMate == mateData);
|
|
mateSlot.OnClick -= OnClickMateListSlot;
|
|
mateSlot.OnClick += OnClickMateListSlot;
|
|
|
|
slot.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
slot.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void OnClickMateListSlot(MateEscrListRowSlot slot)
|
|
{
|
|
selectedListSlot?.SetActiveSelectedIndicator(false);
|
|
|
|
var selectedMateData = slot.GetData() as MateData;
|
|
selectedMate = selectedMateData;
|
|
selectedListSlot = slot;
|
|
selectedListSlot.SetActiveSelectedIndicator(true);
|
|
|
|
if (!selectedMateData.IsUnlocked ||
|
|
allEmployeeMates.Contains(selectedMateData) ||
|
|
!IsSafeToDispatch(TimeUtils.Now()) ||
|
|
settedMates.TryGetSlot(selectedMateData, out _))
|
|
return;
|
|
|
|
settedMates.GetEmptySlots(out var emptySlots);
|
|
if (emptySlots.Count > 0)
|
|
{
|
|
settedMates[emptySlots[0].slotIndex] = selectedMateData;
|
|
RefreshSettedMateSlots();
|
|
RefreshDispatchButton();
|
|
selectedMissionUI.SetNationalityBonus(settedMates);
|
|
selectedMissionUI.SetEmployeeCountBonus(settedMates);
|
|
}
|
|
}
|
|
|
|
public void OnClickSettedMateSlot(int index)
|
|
{
|
|
if (!IsSafeToDispatch(TimeUtils.Now()) || index >= settedMates.SlotCount) return;
|
|
|
|
settedMates[index] = null;
|
|
RefreshSettedMateSlots();
|
|
RefreshDispatchButton();
|
|
selectedMissionUI.SetNationalityBonus(settedMates);
|
|
selectedMissionUI.SetEmployeeCountBonus(settedMates);
|
|
}
|
|
|
|
public void SwitchViewMode()
|
|
{
|
|
string viewModeKey;
|
|
if (curViewMode == MateEscrListRowSlot.ViewMode.Character)
|
|
{
|
|
curViewMode = MateEscrListRowSlot.ViewMode.Nationality;
|
|
viewModeKey = "show_nationality";
|
|
}
|
|
else
|
|
{
|
|
curViewMode = MateEscrListRowSlot.ViewMode.Character;
|
|
viewModeKey = "show_character";
|
|
}
|
|
|
|
curListViewModeText?.SetText(LocalizationInjector.MakeToLocalizationKey(viewModeKey));
|
|
mateListScrollCtrl?.scroller.RefreshActiveCellViews();
|
|
}
|
|
}
|
|
|
|
public partial class DispatchSettingView : View
|
|
{
|
|
[Serializable]
|
|
struct SelectedMissionUI
|
|
{
|
|
[Serializable]
|
|
public struct NationalitySlotUI
|
|
{
|
|
public GameObject indicator;
|
|
public ExtendImage iconImage;
|
|
}
|
|
|
|
[Serializable]
|
|
public struct BonusRewardSlotUI
|
|
{
|
|
public ObjectIndicator indicator;
|
|
public TextMeshProUGUI bonusCountText;
|
|
}
|
|
|
|
public ExtendImage areaImage;
|
|
public ExtendText areaContentText;
|
|
public ExtendImage areaContentIconImage;
|
|
public ExtendText recommendBattlePowerText;
|
|
public ExtendText succRateStrText;
|
|
public GraphicsColorSetter succRateStrTextColorSetter;
|
|
public NationalitySlotUI[] recommendNationalitySlots;
|
|
public ObjectIndicator[] rewardIndicators;
|
|
public BonusRewardSlotUI dispatchLvBonus;
|
|
public BonusRewardSlotUI nationalityBonus;
|
|
public BonusRewardSlotUI employeeCountBonus;
|
|
|
|
public DispatchData.Area area { get; private set; }
|
|
|
|
public void SetArea(DispatchData.Area area)
|
|
{
|
|
this.area = area;
|
|
|
|
areaImage?.SetImageInAtlasAsync(area.ImageAtlasPath, area.ImageNameInAtlas);
|
|
areaContentText?.SetText(LocalizationInjector.MakeToLocalizationKey(area.Mission.ContentStringKey));
|
|
areaContentIconImage?.SetImageInAtlasAsync(area.Mission.ContentIconAtlasPath, area.Mission.ContentIconNameInAtlas);
|
|
|
|
if(recommendBattlePowerText != null)
|
|
{
|
|
switch (area.Mission.Type)
|
|
{
|
|
case DispatchMissionProperty.MissionType.Normal:
|
|
recommendBattlePowerText.SetText("[own_effect_none]");
|
|
break;
|
|
case DispatchMissionProperty.MissionType.Battle:
|
|
recommendBattlePowerText.SetText(FormatString.BigIntString1(area.Mission.RecommendBattlePower));
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(succRateStrText != null)
|
|
{
|
|
var scLevel = area.Mission.GetSuccessRateLevel(BuffMgr.Instance.GetBattlePower());
|
|
|
|
string scLevelKey = FormatString.StringFormat("[success_rate_string_{0}]", scLevel);
|
|
succRateStrText.SetText(scLevelKey);
|
|
|
|
succRateStrTextColorSetter?.SetColor(scLevel.ToString());
|
|
}
|
|
|
|
for (int i = 0; i < recommendNationalitySlots.Length; i++)
|
|
{
|
|
if (i < area.Mission.RecommendNationalities.Length)
|
|
{
|
|
var nationality = area.Mission.RecommendNationalities[i];
|
|
|
|
recommendNationalitySlots[i].indicator?.SetActive(true);
|
|
recommendNationalitySlots[i].iconImage?.SetImageInAtlasAsync(nationality.IconAtlasName, nationality.IconNameInAtals);
|
|
}
|
|
else
|
|
{
|
|
recommendNationalitySlots[i].indicator?.SetActive(false);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < rewardIndicators.Length; i++)
|
|
{
|
|
if (i < area.Mission.DefaultRewards.Length)
|
|
{
|
|
ObjectIndicatorSetter.SetWith(rewardIndicators[i], area.Mission.DefaultRewards[i]);
|
|
rewardIndicators[i].gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
rewardIndicators[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
SetDispatchLvBonus();
|
|
}
|
|
|
|
public void SetDispatchLvBonus() => SetBonusSlot(dispatchLvBonus, area.Mission.bonusRewardByDispatchLv);
|
|
public void SetNationalityBonus(SlotGroup<MateData> mates) => SetBonusSlot(nationalityBonus, area.Mission.GetBonusRewardByNationality(mates));
|
|
public void SetEmployeeCountBonus(SlotGroup<MateData> mates) => SetBonusSlot(employeeCountBonus, area.Mission.GetBonusRewardByEmployeeCount(mates));
|
|
|
|
private void SetBonusSlot(BonusRewardSlotUI slotUI, nGoods bonusGoods)
|
|
{
|
|
ObjectIndicatorSetter.SetWith(slotUI.indicator, bonusGoods);
|
|
|
|
if(slotUI.bonusCountText != null)
|
|
slotUI.bonusCountText.text = FormatString.StringFormat("+{0}", bonusGoods.propertyCount);
|
|
}
|
|
}
|
|
|
|
[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
|
|
{
|
|
ObjectIndicatorSetter.SetWith(indicator, mateData);
|
|
indicator?.gameObject.SetActive(true);
|
|
removeIndicator?.SetActive(true);
|
|
emptyIndicator?.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|