备份CatanBuilding瘦身独立工程
This commit is contained in:
235
Assets/Scripts/UI/PartnerFishBowl/EventPartnerPanel.cs
Normal file
235
Assets/Scripts/UI/PartnerFishBowl/EventPartnerPanel.cs
Normal file
@@ -0,0 +1,235 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using game;
|
||||
using asap.core;
|
||||
using UnityEngine.UI;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using UniRx;
|
||||
using System.Collections.Generic;
|
||||
using Castle.Core.Internal;
|
||||
using GameCore;
|
||||
|
||||
public class EventPartnerPanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button btnClose, btnConfirm;
|
||||
[SerializeField] private EventPartnerMainPanel mainPanel;
|
||||
[SerializeField] private EventPartnerBuildPanel buildPanel;
|
||||
[SerializeField] private EPanel curPanel;
|
||||
[SerializeField] private GameObject background;
|
||||
[SerializeField] private float zoomTime;
|
||||
[SerializeField] private float zoomScale;
|
||||
[SerializeField] private EventPartnerComponent[] components;
|
||||
[SerializeField] private CanvasGroup mask;
|
||||
[SerializeField] private Animation uiAnimation;
|
||||
[SerializeField] private EventPartnerTips tips;
|
||||
private IEventAggregator _eventAggregator;
|
||||
private EventPartnerData _data;
|
||||
private Tables _tables;
|
||||
private EventPartnerAct.Context _context;
|
||||
private IDisposable _robotAddScoreSubscription;
|
||||
private List<Tween> _tweenList;
|
||||
private List<Vector3> _posList;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_posList = new List<Vector3>();
|
||||
foreach (var component in components)
|
||||
{
|
||||
_posList.Add(component.transform.localPosition);
|
||||
// Debug.Log($"<color=#80c342>init pos: {_posList[^1]}</color>");
|
||||
}
|
||||
|
||||
btnClose.onClick.AddListener(OnClickClose);
|
||||
btnConfirm.onClick.AddListener(OnClickClose);
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("EventPartnerJurassicbuildingPanel", curPanelName: gameObject.name);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_robotAddScoreSubscription?.Dispose();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_context = EventPartnerAct.Ctx;
|
||||
_eventAggregator = _context.EventAggregator;
|
||||
_tables = _context.Tables;
|
||||
_data = _context.Data;
|
||||
// Debug.Log($"[EventPartner] Data in panel: {_data.GetHashCode()}");
|
||||
for (int i = 0; i < _data.Components.Count; i++)
|
||||
{
|
||||
var c = _data.Components[i];
|
||||
SetComponent(i, c.GetProgressIdx(c.ScoreDisplay), isInit: true);
|
||||
var now = ZZTimeHelper.UtcNow();
|
||||
if (!c.IsMatched || !c.IsPartnerRobot || c.BotActionQueue.IsNullOrEmpty() || now < c.BotActionQueue.Peek().Time)
|
||||
continue;
|
||||
if (c.Score >= c.MaxScore)
|
||||
{
|
||||
c.BotActionQueue.Clear();
|
||||
continue;
|
||||
}
|
||||
while (!c.BotActionQueue.IsNullOrEmpty() && now >= c.BotActionQueue.Peek().Time)
|
||||
{
|
||||
c.AddRobotScore();
|
||||
}
|
||||
c.SyncRobotScore();
|
||||
}
|
||||
|
||||
mask.alpha = 0;
|
||||
// TODO: Optimize to timed task instead of constant looking up.
|
||||
_robotAddScoreSubscription ??= Observable.Interval(System.TimeSpan.FromSeconds(2.0f))
|
||||
.Subscribe(x =>
|
||||
{
|
||||
// Debug.Log($"<color=#c191ff>{x} minute:</color>");
|
||||
foreach (var c in _data.Components.Where(c => c.IsMatched && c.IsPartnerRobot))
|
||||
{
|
||||
if (!c.BotActionQueue.TryPeek(out var action) || ZZTimeHelper.UtcNow() < action.Time)
|
||||
continue;
|
||||
if (c.Score >= c.MaxScore)
|
||||
{
|
||||
c.BotActionQueue.Clear();
|
||||
continue;
|
||||
}
|
||||
c.AddRobotScore();
|
||||
c.SyncRobotScore();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void ShowMainPanel()
|
||||
{
|
||||
curPanel = EPanel.Main;
|
||||
mainPanel.gameObject.SetActive(true);
|
||||
buildPanel.gameObject.SetActive(false);
|
||||
mainPanel.Init();
|
||||
}
|
||||
|
||||
public void ShowBuildPanel(EventPartnerAct.Context ctx)
|
||||
{
|
||||
curPanel = EPanel.Build;
|
||||
mainPanel.gameObject.SetActive(false);
|
||||
buildPanel.gameObject.SetActive(true);
|
||||
buildPanel.Init();
|
||||
}
|
||||
|
||||
private void OnClickClose()
|
||||
{
|
||||
// Debug.Log("<color=red>Click click click!</color>");
|
||||
if (curPanel == EPanel.Main)
|
||||
GContext.Publish(new UnloadActToNextAct());
|
||||
else
|
||||
{
|
||||
buildPanel.SetStateInactive();
|
||||
_ = _context.ShowMainPanel();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetComponent(int componentIdx, int targetGrade, bool isUpgrade = false,
|
||||
bool isInit = false)
|
||||
{
|
||||
var component = components[componentIdx];
|
||||
var componentId = _data.Components[componentIdx].ComponentId;
|
||||
var resourceList = _tables.TbEventPartnerComponent[componentId].ResourceList;
|
||||
var resource = resourceList[targetGrade];
|
||||
// Debug.Log($"<color=#c9a26d>Id: {componentId}, Index: {componentIdx}, resource: {resource}.</color>");
|
||||
if (isInit)
|
||||
component.Init(_context, targetGrade, resource);
|
||||
else if (isUpgrade)
|
||||
component.UpgradeComponent(targetGrade, resource);
|
||||
else
|
||||
component.SetComponent(targetGrade, resource);
|
||||
}
|
||||
|
||||
public void PlayAddScoreFx(int componentIdx)
|
||||
{
|
||||
components[componentIdx].PlayAddScoreFx();
|
||||
}
|
||||
|
||||
public void ZoomIn(int componentIdx)
|
||||
{
|
||||
for (int i = 0; i < _data.Components.Count; i++)
|
||||
{
|
||||
components[i].gameObject.SetActive(i == componentIdx);
|
||||
}
|
||||
|
||||
var pos = _posList[componentIdx];
|
||||
// Debug.Log($"<color=#80c342>before pos: {pos}</color>");
|
||||
// Debug.Log($"<color=#80c342>before l : {_posList[componentIdx]}</color>");
|
||||
pos *= zoomScale;
|
||||
// Debug.Log($"<color=#80c342>after pos: {pos}</color>");
|
||||
// Debug.Log($"<color=#80c342>after l : {_posList[componentIdx]}</color>");
|
||||
if (_tweenList is { Count: > 0 })
|
||||
foreach (var tween in _tweenList)
|
||||
tween.Kill();
|
||||
_tweenList = new List<Tween>
|
||||
{
|
||||
background.transform.DOLocalMove(-pos, zoomTime),
|
||||
background.transform.DOScale(zoomScale, zoomTime),
|
||||
mask.DOFadeAlpha(1.0f, zoomTime)
|
||||
};
|
||||
}
|
||||
|
||||
public void ZoomOut()
|
||||
{
|
||||
for (int i = 0; i < _data.Components.Count; i++)
|
||||
{
|
||||
components[i].gameObject.SetActive(true);
|
||||
}
|
||||
// Debug.Log($"<color=#80c342>Before ZoomOut{transform.position}</color>");
|
||||
if (_tweenList is { Count: > 0 })
|
||||
foreach (var tween in _tweenList)
|
||||
tween.Kill();
|
||||
_tweenList = new List<Tween>
|
||||
{
|
||||
background.transform.DOLocalMove(Vector3.zero, zoomTime),
|
||||
background.transform.DOScale(1, zoomTime),
|
||||
mask.DOFadeAlpha(0.0f, zoomTime)
|
||||
};
|
||||
}
|
||||
|
||||
public void PlayUiAnimation()
|
||||
{
|
||||
uiAnimation.Play("fishbowl_show");
|
||||
}
|
||||
|
||||
public void ShowMatchTip(string namePartner, string iconPartner, string nameComponent,
|
||||
bool doShowPanelTips)
|
||||
{
|
||||
mainPanel.SetMatchTip(namePartner, iconPartner, nameComponent, doShowPanelTips);
|
||||
}
|
||||
}
|
||||
|
||||
public enum EPanel
|
||||
{
|
||||
Main,
|
||||
Build,
|
||||
Info,
|
||||
Match,
|
||||
MatchPopup
|
||||
}
|
||||
|
||||
/*public class EventPartnerSwitchPanel
|
||||
{
|
||||
public EPanel panelType;
|
||||
public int ComponentIndex;
|
||||
public EventPartnerSwitchPanel (EPanel e, int c = 0)
|
||||
{
|
||||
panelType = e;
|
||||
ComponentIndex = c;
|
||||
}
|
||||
}*/
|
||||
public class EventPartnerComponentUpgrade
|
||||
{
|
||||
public int ComponentIndex, Grade;
|
||||
|
||||
public EventPartnerComponentUpgrade(int componentIndex, int grade)
|
||||
{
|
||||
ComponentIndex = componentIndex;
|
||||
Grade = grade;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user