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.
233 lines
7.1 KiB
233 lines
7.1 KiB
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public partial class DispatchView : View
|
|
{
|
|
[SerializeField] GameObject mapPanel;
|
|
[SerializeField] ExtendText levelFormatText;
|
|
|
|
[SerializeField] DispatchSettingView settingView;
|
|
|
|
[SerializeField] AreaUI[] areaUIs;
|
|
|
|
private void Start()
|
|
{
|
|
viewState = ViewState.Hidden;
|
|
mapPanel?.SetActive(false);
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
GameUIMgr.SSetMainUiOn(false);
|
|
|
|
ResetPosition();
|
|
mapPanel?.SetActive(true);
|
|
viewState = ViewState.Shown;
|
|
|
|
RefreshMap();
|
|
levelFormatText?.SetText(FormatString.StringFormat("[dispatch] Lv. {0}", DispatchDataGroup.Instance.DispatchData.DispatchLevel));
|
|
}
|
|
|
|
public override void Hide()
|
|
{
|
|
for(int i = 0; i < areaUIs.Length; i++)
|
|
{
|
|
areaUIs[i].Release();
|
|
}
|
|
|
|
viewState = ViewState.Hidden;
|
|
mapPanel?.SetActive(false);
|
|
|
|
GameUIMgr.SSetMainUiOn(true);
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (viewState != ViewState.Shown) return;
|
|
|
|
for (int i = 0; i < areaUIs.Length; ++i)
|
|
{
|
|
areaUIs[i].Update();
|
|
}
|
|
}
|
|
|
|
private void RefreshMap()
|
|
{
|
|
for(int i = 0; i < areaUIs.Length; ++i)
|
|
{
|
|
var targetUI = areaUIs[i];
|
|
|
|
if(DispatchDataGroup.Instance.DispatchData.TryGetArea(targetUI.areaType, out var area))
|
|
targetUI.SetArea(area, OnClickMissionButton);
|
|
}
|
|
}
|
|
|
|
private void OnClickMissionButton(AreaUI clickedArea)
|
|
{
|
|
if (settingView is null) return;
|
|
|
|
var now = TimeUtils.Now();
|
|
|
|
if (clickedArea.area.Mission.HasResult && !clickedArea.area.Mission.GotReward)
|
|
{
|
|
if (clickedArea.area.Mission.IsSucceed)
|
|
{
|
|
clickedArea.area.Mission.TryGetReward((totalReward, result) =>
|
|
{
|
|
if (!result) return;
|
|
|
|
uint exp = clickedArea.area.Mission.CalculateExp();
|
|
if (DispatchDataGroup.Instance.DispatchData.AddDispatchExp(exp))
|
|
{
|
|
levelFormatText?.SetText(FormatString.StringFormat("[dispatch] Lv. {0}", DispatchDataGroup.Instance.DispatchData.DispatchLevel));
|
|
}
|
|
|
|
clickedArea.area.StartRefreshTime(now);
|
|
|
|
GameUIMgr.SOpenPopupGoods(totalReward);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
clickedArea.area.Mission.RemoveResult();
|
|
BattleMgr.OpenFailScroll();
|
|
clickedArea.area.StartRefreshTime(now);
|
|
}
|
|
}
|
|
else if (!clickedArea.area.IsInRefreshTime(now))
|
|
{
|
|
settingView.SetArea(clickedArea.area);
|
|
settingView.Show();
|
|
}
|
|
else
|
|
{
|
|
GameUIMgr.SOpenToast(LocalizationText.GetText("try_and_failed_1"));
|
|
}
|
|
}
|
|
}
|
|
|
|
public partial class DispatchView : View
|
|
{
|
|
[Serializable]
|
|
class AreaUI
|
|
{
|
|
public WorldArea areaType;
|
|
|
|
public RectTransform mapScroller;
|
|
public RectTransform mapArea;
|
|
|
|
public Button missionBtn;
|
|
public PointArrowInBox missionBtnPointArrow;
|
|
public GameObject missionIndicator;
|
|
public ExtendImage missionContentIconImage;
|
|
public GameObject missionSuccIndicator;
|
|
public GameObject missionFailIndicator;
|
|
public DispatchersController dispatcherCtrl;
|
|
public RectTransform refreshRemainTimer;
|
|
public TextMeshProUGUI refreshRemainTimeText;
|
|
public RectTransform[] missionPositions;
|
|
|
|
public DispatchData.Area area { get; private set; }
|
|
|
|
bool prevDispatchingState;
|
|
Material grayScale;
|
|
|
|
public void SetArea(DispatchData.Area area, Action<AreaUI> onClickMissionBtn)
|
|
{
|
|
this.area = area;
|
|
|
|
missionBtn.onClick.RemoveAllListeners();
|
|
missionBtn.onClick.AddListener(() => onClickMissionBtn?.Invoke(this));
|
|
|
|
if(grayScale is null)
|
|
grayScale = new Material(GlobalShaderProperty._grayScaleShader);
|
|
|
|
missionBtn.image.material = grayScale;
|
|
|
|
area.OnRefreshMission -= OnRefreshMission;
|
|
area.OnRefreshMission += OnRefreshMission;
|
|
|
|
OnRefreshMission();
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
area.OnRefreshMission -= OnRefreshMission;
|
|
area = null;
|
|
}
|
|
|
|
private void OnRefreshMission()
|
|
{
|
|
var now = TimeUtils.Now();
|
|
|
|
missionContentIconImage?.SetImageInAtlasAsync(area.Mission.ContentIconAtlasPath, area.Mission.ContentIconNameInAtlas);
|
|
|
|
prevDispatchingState = area.Mission.InProgress(now);
|
|
SetDispatchersController(prevDispatchingState);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if(area is null) return;
|
|
|
|
var now = TimeUtils.Now();
|
|
|
|
bool refreshing = area.IsInRefreshTime(now);
|
|
bool dispatching = area.Mission.InProgress(now);
|
|
bool hasResult = area.Mission.HasResult && !area.Mission.GotReward;
|
|
|
|
refreshRemainTimer?.gameObject.SetActive(refreshing);
|
|
missionIndicator?.gameObject.SetActive(!refreshing);
|
|
if (refreshing)
|
|
{
|
|
var remainTime = area.RefreshEndTime - now;
|
|
refreshRemainTimeText?.SetText(FormatString.TextTime((int)remainTime.TotalSeconds));
|
|
}
|
|
|
|
if (prevDispatchingState != dispatching)
|
|
{
|
|
SetDispatchersController(dispatching);
|
|
prevDispatchingState = dispatching;
|
|
}
|
|
|
|
missionSuccIndicator?.SetActive(hasResult);
|
|
missionFailIndicator?.SetActive(hasResult);
|
|
missionBtnPointArrow?.gameObject.SetActive(hasResult);
|
|
|
|
if (hasResult)
|
|
{
|
|
missionSuccIndicator?.SetActive(area.Mission.IsSucceed);
|
|
missionFailIndicator?.SetActive(!area.Mission.IsSucceed);
|
|
missionBtnPointArrow?.SetViewBox(new Rect(mapScroller.anchoredPosition - mapArea.anchoredPosition, mapScroller.sizeDelta));
|
|
}
|
|
|
|
SetMissionButton(refreshing, dispatching);
|
|
}
|
|
|
|
private void SetMissionButton(bool isRefreshing, bool isDispatching)
|
|
{
|
|
bool activate = !isRefreshing || isDispatching;
|
|
missionBtn?.gameObject.SetActive(activate);
|
|
|
|
if(activate)
|
|
{
|
|
if (area.MissionPositionIndex >= 0 && area.MissionPositionIndex < missionPositions.Length)
|
|
missionBtn.transform.position = missionPositions[area.MissionPositionIndex].position;
|
|
else
|
|
missionBtn.transform.position = missionPositions[missionPositions.Length - 1].position;
|
|
|
|
grayScale.SetFloat(GlobalShaderProperty._grayscalePropertyID, isRefreshing ? 0 : 1);
|
|
}
|
|
}
|
|
|
|
private void SetDispatchersController(bool activate)
|
|
{
|
|
dispatcherCtrl?.gameObject.SetActive(activate);
|
|
|
|
if (activate)
|
|
dispatcherCtrl?.SetDispatch(missionBtn.transform as RectTransform, area);
|
|
}
|
|
}
|
|
}
|