备份CatanBuilding瘦身独立工程
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UniRx;
|
||||
using asap.core.common;
|
||||
|
||||
public class DeferredRewardStashButton : MonoBehaviour
|
||||
{
|
||||
private Button _btn;
|
||||
private DeferredRewardStashPanel _panel;
|
||||
private Animation _animation;
|
||||
public RectTransform Icon;
|
||||
private IObjectPoolService _objectPoolService;
|
||||
[Tooltip("Empty for old, filled with batched controller for new")]
|
||||
[SerializeField] private RewardFlyBatchController _rewardFlyBatchController;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_btn = GetComponent<Button>();
|
||||
_panel = transform.Find("EventBagRewardPopupPanel").GetComponent<DeferredRewardStashPanel>();
|
||||
_panel.gameObject.SetActive(false);
|
||||
if (_btn != null)
|
||||
_btn.onClick.AddListener(OnClick);
|
||||
_animation = GetComponent<Animation>();
|
||||
_objectPoolService = GContext.container.Resolve<IObjectPoolService>();
|
||||
GContext.OnEvent<EventRewardFlyStashRequest>().Subscribe(OnRewardFlyRequest).AddTo(this);
|
||||
}
|
||||
|
||||
private void OnClick()
|
||||
{
|
||||
if (GContext.container.Resolve<IDeferredRewardStashService>().IsEmpty)
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_EventWinterShootingPanel_11"));
|
||||
else
|
||||
_panel.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public async void PlayReceiveAnimationWithDelay(float delay)
|
||||
{
|
||||
try
|
||||
{
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
|
||||
_animation.Play("fx_anim_wintershooting_pack_01");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"{e.Message}\n{e.StackTrace}", this);
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnRewardFlyRequest(EventRewardFlyStashRequest e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collectionItemFly = new CollectionItemFly
|
||||
{
|
||||
itemID = e.Reward.id,
|
||||
numStr = $"x{ConvertTools.GetNumberString((int)e.Reward.count)}",
|
||||
sourcePos = e.SourceIconRt.position,
|
||||
destPos = Icon.position,
|
||||
scale = transform.localScale,
|
||||
isPlayOpen = e.DoesPlayOpen,
|
||||
isPlayClose = true,
|
||||
isDestinationRewardStash = true,
|
||||
targetIconSize = Icon.rect.width,
|
||||
sourceIconSize = e.SourceIconRt.rect.width,
|
||||
};
|
||||
|
||||
var rewardFlyRequest = new BatchedRewardFlyRequest
|
||||
{
|
||||
itemID = e.Reward.id,
|
||||
Quantity = e.Reward.count,
|
||||
StartPoint = new BatchedRewardFlyPoint(e.SourceIconRt),
|
||||
EndPoint = new BatchedRewardFlyPoint(Icon),
|
||||
isDestinationRewardStash = true,
|
||||
sourceTextRt = e.SourceTextRt
|
||||
};
|
||||
|
||||
if (_rewardFlyBatchController != null)
|
||||
{
|
||||
await _rewardFlyBatchController.OnRewardFlyRequestAsync(rewardFlyRequest);
|
||||
PlayReceiveAnimationWithDelay(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pool = _objectPoolService.GetPool(typeof(RewardFly));
|
||||
var rewardFly = pool.SpawnObject() as RewardFly;
|
||||
rewardFly.gameObject.SetActive(true);
|
||||
await rewardFly.ShowAsync(collectionItemFly);
|
||||
pool.DespawnObject(rewardFly);
|
||||
PlayReceiveAnimationWithDelay(0);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.Log($"[Deferred Reward Stash Button] : Error");
|
||||
Debug.LogError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public async System.Threading.Tasks.Task OnRewardFlyRequestAsync(EventRewardFlyStashRequest e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var collectionItemFly = new CollectionItemFly
|
||||
{
|
||||
itemID = e.Reward.id,
|
||||
numStr = $"x{ConvertTools.GetNumberString(e.Reward.count)}",
|
||||
sourcePos = e.SourceIconRt.position,
|
||||
destPos = Icon.position,
|
||||
scale = transform.localScale,
|
||||
isPlayOpen = e.DoesPlayOpen,
|
||||
isPlayClose = true,
|
||||
isDestinationRewardStash = true,
|
||||
targetIconSize = Icon.rect.width,
|
||||
sourceIconSize = e.SourceIconRt.rect.width
|
||||
};
|
||||
|
||||
var rewardFlyRequest = new BatchedRewardFlyRequest
|
||||
{
|
||||
itemID = e.Reward.id,
|
||||
Quantity = e.Reward.count,
|
||||
StartPoint = new BatchedRewardFlyPoint(e.SourceIconRt),
|
||||
EndPoint = new BatchedRewardFlyPoint(Icon),
|
||||
isDestinationRewardStash = true,
|
||||
sourceTextRt = e.SourceTextRt
|
||||
};
|
||||
|
||||
if (_rewardFlyBatchController != null)
|
||||
{
|
||||
await _rewardFlyBatchController.OnRewardFlyRequestAsync(rewardFlyRequest);
|
||||
PlayReceiveAnimationWithDelay(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pool = _objectPoolService.GetPool(typeof(RewardFly));
|
||||
var rewardFly = pool.SpawnObject() as RewardFly;
|
||||
rewardFly.gameObject.SetActive(true);
|
||||
await rewardFly.ShowAsync(collectionItemFly);
|
||||
pool.DespawnObject(rewardFly);
|
||||
PlayReceiveAnimationWithDelay(0);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.Log($"[Deferred Reward Stash Button] : Error");
|
||||
Debug.LogError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6835c7e4651433b4faf61c68441d3802
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,142 @@
|
||||
using asap.core;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using GameCore;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DeferredRewardStashPanel : MonoBehaviour
|
||||
{
|
||||
private IDeferredRewardStashService _stash;
|
||||
private const int RowWidth = 4;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject emptyGo, itemContainerGo, adaptiveContainer, scrollViewContainer, rowGo, rowContainer;
|
||||
[SerializeField] private List<GameObject> adaptiveItemGoList, scrollViewRowList;
|
||||
[SerializeField] private PanelScroll jiahaoScrollView;
|
||||
[SerializeField] private Button btnClose;
|
||||
private const float RewardPopSpeed = 0.075f;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
btnClose.onClick.AddListener(() => gameObject.SetActive(false));
|
||||
_stash = GContext.container.Resolve<IDeferredRewardStashService>();
|
||||
if (_stash == null)
|
||||
{
|
||||
Debug.LogError("Stash Service is not available.");
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
itemContainerGo.SetActive(false);
|
||||
adaptiveContainer.SetActive(false);
|
||||
scrollViewContainer.SetActive(false);
|
||||
adaptiveItemGoList = new List<GameObject>();
|
||||
scrollViewRowList = new List<GameObject>();
|
||||
}
|
||||
|
||||
private const int ItemCountLimit = 12;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
GContext.Publish(new EventStashPanelOpen());
|
||||
foreach (var itemGo in adaptiveItemGoList)
|
||||
Destroy(itemGo);
|
||||
adaptiveItemGoList.Clear();
|
||||
foreach (var row in scrollViewRowList)
|
||||
Destroy(row);
|
||||
scrollViewRowList.Clear();
|
||||
|
||||
if (_stash.IsEmpty)
|
||||
{
|
||||
adaptiveContainer.SetActive(true);
|
||||
emptyGo.SetActive(true);
|
||||
scrollViewContainer.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
emptyGo.SetActive(false);
|
||||
var items = _stash.Items;
|
||||
if (items.Count <= ItemCountLimit)
|
||||
ShowAdaptiveLayout(items);
|
||||
else
|
||||
_ = ShowScrollViewLayout(items);
|
||||
}
|
||||
|
||||
private void ShowAdaptiveLayout(IReadOnlyList<ItemData> items)
|
||||
{
|
||||
adaptiveContainer.SetActive(true);
|
||||
scrollViewContainer.SetActive(false);
|
||||
foreach (var item in items)
|
||||
{
|
||||
var newItemGo = Instantiate(itemContainerGo, adaptiveContainer.transform);
|
||||
adaptiveItemGoList.Add(newItemGo);
|
||||
var reward = newItemGo.transform.Find("reward").GetComponent<RewardItemNew>();
|
||||
reward.SetData(item, abbr: true);
|
||||
newItemGo.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task ShowScrollViewLayout(IReadOnlyList<ItemData> items)
|
||||
{
|
||||
adaptiveContainer.SetActive(false);
|
||||
scrollViewContainer.SetActive(true);
|
||||
for (int i = 0; i < items.Count; i += RowWidth)
|
||||
{
|
||||
var currentRow = Instantiate(rowGo, rowContainer.transform);
|
||||
currentRow.SetActive(true);
|
||||
// TODO: Is rows needed to destroy the instantiated game objects?
|
||||
scrollViewRowList.Add(currentRow.gameObject);
|
||||
var count = items.Count - i;
|
||||
for (int j = 0; j < RowWidth; j++)
|
||||
{
|
||||
currentRow.transform.GetChild(j).gameObject.SetActive(j < count);
|
||||
currentRow.transform.GetChild(j).GetChild(0).gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
await Awaiters.NextFrame;
|
||||
// jiahaoScrollView.DONormalizedPos(Vector2.zero, RewardPopSpeed);
|
||||
for (int j = 0; j < RowWidth; j++)
|
||||
{
|
||||
if (j < count)
|
||||
{
|
||||
var item = items[i + j];
|
||||
currentRow.transform.GetChild(j).gameObject.SetActive(true);
|
||||
var reward = currentRow.transform.GetChild(j).GetChild(0).GetComponent<RewardItemNew>();
|
||||
// reward.SetRewardPopupData(item);
|
||||
reward.SetData(item, abbr: true);
|
||||
reward.gameObject.SetActive(true);
|
||||
// reward.PlayOpen();
|
||||
cfg.Item itemCfg = GContext.container.Resolve<cfg.Tables>().TbItem.GetOrDefault(item.id);
|
||||
GContext.Publish(new ResAddEvent(itemCfg.ID, itemCfg.Type, itemCfg.SubType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Awaiters.NextFrame;
|
||||
// jiahaoScrollView.DONormalizedPos(Vector2.zero, RewardPopSpeed);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
GContext.Publish(new EventStashPanelClose());
|
||||
}
|
||||
|
||||
public class EventStashPanelOpen
|
||||
{
|
||||
}
|
||||
|
||||
public class EventStashPanelClose
|
||||
{
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
emptyGo = transform.Find("root/Content1/empty").gameObject;
|
||||
itemContainerGo = transform.Find("root/Content1/item1").gameObject;
|
||||
adaptiveContainer = transform.Find("root/Content1").gameObject;
|
||||
scrollViewContainer = transform.Find("root/Content2").gameObject;
|
||||
rowGo = transform.Find("root/Content2/ScrollView/Viewport/Content/reward_group1").gameObject;
|
||||
rowContainer = transform.Find("root/Content2/ScrollView/Viewport/Content").gameObject;
|
||||
jiahaoScrollView = transform.Find("root/Content2/ScrollView").GetComponent<PanelScroll>();
|
||||
btnClose = transform.Find("root/btn_close").GetComponent<Button>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bda3e2c1c3db034497796c6e08cc4cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user