248 lines
4.9 KiB
C#
248 lines
4.9 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-14
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "WorldPanel" company="KUNPO"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using DG.Tweening;
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
namespace G.UI
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 世界
|
|||
|
/// </summary>
|
|||
|
partial class WorldPanel : KUIWidget
|
|||
|
{
|
|||
|
#region Field
|
|||
|
|
|||
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listCities;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnTravel;
|
|||
|
[KUIFlag]
|
|||
|
TextMeshProUGUI _tmpRemain;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnMotionAdd;
|
|||
|
[KUIFlag]
|
|||
|
RectTransform _goMe;
|
|||
|
[KUIFlag]
|
|||
|
ScrollRect _goScroll;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnSummary;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnStatus;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnEvents;
|
|||
|
|
|||
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void InitView()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
|
|||
|
__listCities.AddTemplate<CityWidget>(true);
|
|||
|
_goMe.SetParent(__listCities.transform);
|
|||
|
|
|||
|
_btnTravel.onClick.AddListener(this.OnTravelBtnClick);
|
|||
|
_btnSummary.onClick.AddListener(this.OnSummaryBtnClick);
|
|||
|
_btnStatus.onClick.AddListener(this.OnStatusBtnClick);
|
|||
|
_btnEvents.onClick.AddListener(this.OnEventsBtnClick);
|
|||
|
_btnMotionAdd.onClick.AddListener(this.OnMotionAddBtnClick);
|
|||
|
}
|
|||
|
|
|||
|
void SetMapSize()
|
|||
|
{
|
|||
|
var scrollSize = ((RectTransform)_goScroll.transform).rect.size;
|
|||
|
__listCities.transform.localScale = Vector3.one * (scrollSize.y / 1820f);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void RefreshView()
|
|||
|
{
|
|||
|
var proxy = CityProxy.Instance;
|
|||
|
if (proxy != null)
|
|||
|
{
|
|||
|
if (proxy.travelCount > 0)
|
|||
|
{
|
|||
|
_tmpRemain.text = $"{proxy.travelCount}/{proxy.travelCountMax}";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_tmpRemain.text = proxy.recoverTimeText;
|
|||
|
}
|
|||
|
|
|||
|
__listCities.Clear();
|
|||
|
var cities = proxy.GetAllCities();
|
|||
|
foreach (var city in cities)
|
|||
|
{
|
|||
|
var widget = __listCities.GetItem();
|
|||
|
widget.SetData(city);
|
|||
|
}
|
|||
|
|
|||
|
TravelCity(proxy.lastTravelCity, false);
|
|||
|
}
|
|||
|
PostNotification(GlobalDefine.EVENT_WINDOW_OPENED, 0, "");
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateView()
|
|||
|
{
|
|||
|
if (CityProxy.Instance.travelCount <= 0)
|
|||
|
{
|
|||
|
_tmpRemain.text = CityProxy.Instance.recoverTimeText;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_tmpRemain.text = $"{CityProxy.Instance.travelCount}/{CityProxy.Instance.travelCountMax}";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private bool _isTraveling;
|
|||
|
private void TravelCity(CityProxy.CityInfo cityInfo, bool anim)
|
|||
|
{
|
|||
|
_isTraveling = true;
|
|||
|
_goMe.SetAsLastSibling();
|
|||
|
|
|||
|
var pos = GlobalUtils.GetVector2(cityInfo.item.iconPos);
|
|||
|
var hor = pos.x;
|
|||
|
if (anim)
|
|||
|
{
|
|||
|
KUIWindow.OpenWindow<IndicatorBox>();
|
|||
|
_goMe.DOAnchorPos(pos, 2f)
|
|||
|
.OnUpdate(() =>
|
|||
|
{
|
|||
|
SetScroll(_goMe.anchoredPosition);
|
|||
|
})
|
|||
|
.OnComplete(() =>
|
|||
|
{
|
|||
|
KUIWindow.CloseWindow<IndicatorBox>();
|
|||
|
//_isTraveling = false;
|
|||
|
SetScroll(pos);
|
|||
|
if (cityInfo.currCityEvent != null)
|
|||
|
KUIWindow.OpenWindow<TravelWindow>(cityInfo, () =>
|
|||
|
{
|
|||
|
_isTraveling = false;
|
|||
|
});
|
|||
|
else
|
|||
|
_isTraveling = false;
|
|||
|
|
|||
|
});
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goMe.anchoredPosition = pos;
|
|||
|
SetScroll(pos);
|
|||
|
_isTraveling = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SetScroll(Vector2 pos)
|
|||
|
{
|
|||
|
float x = pos.x;
|
|||
|
if (x <= 540f)
|
|||
|
{
|
|||
|
_goScroll.horizontalNormalizedPosition = 0f;
|
|||
|
}
|
|||
|
else if (x >= 3310f)
|
|||
|
{
|
|||
|
_goScroll.horizontalNormalizedPosition = 1f;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_goScroll.horizontalNormalizedPosition = (x - 540f) / 2850f;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnTravelBtnClick()
|
|||
|
{
|
|||
|
if (!_isTraveling)
|
|||
|
{
|
|||
|
#if UNITY_EDITOR
|
|||
|
if (true || CityProxy.Instance.travelCount > 0)
|
|||
|
#else
|
|||
|
if (CityProxy.Instance.travelCount > 0)
|
|||
|
#endif
|
|||
|
{
|
|||
|
var city = CityProxy.Instance.RandomTravel();
|
|||
|
if (city != null)
|
|||
|
TravelCity(city, true);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ToastBox.ShowText(KLocalization.GetLocalString(22));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnSummaryBtnClick()
|
|||
|
{
|
|||
|
KUIWindow.OpenWindow<FriendBox>();
|
|||
|
}
|
|||
|
|
|||
|
private void OnStatusBtnClick()
|
|||
|
{
|
|||
|
KUIWindow.OpenWindow<CityStatusBox>();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEventsBtnClick()
|
|||
|
{
|
|||
|
KUIWindow.OpenWindow<CityRewardBox>();
|
|||
|
}
|
|||
|
|
|||
|
private void OnMotionAddBtnClick()
|
|||
|
{
|
|||
|
AdMoneyBox.ShowAdMoney(Item.Id.kMotility, true);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
InitView();
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
RefreshView();
|
|||
|
}
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
SetMapSize();
|
|||
|
}
|
|||
|
|
|||
|
private float _lastUpdateTime;
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (Time.time - _lastUpdateTime > 1f)
|
|||
|
{
|
|||
|
_lastUpdateTime = Time.time;
|
|||
|
UpdateView();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|