119 lines
3.7 KiB
C#
119 lines
3.7 KiB
C#
using System.Collections.Generic;
|
|
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
//
|
|
public struct EventPartnerMiningMultiplierChange { }
|
|
|
|
namespace UI.PartnerGather.Mining
|
|
{
|
|
public class EventPartnerMiningMultiplierController : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text _textMultiplier, _textMultiplierMax;
|
|
[SerializeField] private Button _btnMultiplier;
|
|
[SerializeField] private GameObject _goNormal, _goMax;
|
|
[SerializeField] private Animator btnAnimation;
|
|
[SerializeField] private float btnReactTime = 0.05f;
|
|
|
|
private int _idx;
|
|
private int _largeIdx;
|
|
private Tables _tables;
|
|
private List<int> _multiplierList;
|
|
private PlayerItemData _playerItemData;
|
|
|
|
public int Multiplier => _multiplierList[_idx];
|
|
|
|
private void Awake()
|
|
{
|
|
_btnMultiplier.onClick.AddListener(CycleMultiplierToNext);
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
public void Init(List<int> spinMag)
|
|
{
|
|
_tables = GContext.container.Resolve<Tables>();
|
|
// _playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
// _multiplierList = _tables.TbEventPartnerMain[_redirectId].SpinMag;
|
|
_multiplierList = spinMag;
|
|
SwitchToNextMax();
|
|
// _eventAggregator = eventAggregator;
|
|
}
|
|
|
|
public async void CycleMultiplierToNext()
|
|
{
|
|
_idx++;
|
|
int currentMaxMultiplier = GetCurrentMaxMultiplier();
|
|
btnAnimation.Play("Pressed");
|
|
ToggleMultiplierButtonFunction(false);
|
|
if (_idx >= _multiplierList.Count || Multiplier > currentMaxMultiplier)
|
|
{
|
|
_idx = 0;
|
|
ToggleButtons(true);
|
|
}
|
|
else if (Multiplier == currentMaxMultiplier)
|
|
{
|
|
ToggleButtons(false);
|
|
}
|
|
else
|
|
{
|
|
ToggleButtons(true);
|
|
}
|
|
|
|
// _eventAggregator.Publish(new EventPartnerMultiplierChange());
|
|
GContext.Publish(new EventPartnerMiningMultiplierChange());
|
|
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(btnReactTime));
|
|
|
|
btnAnimation.Play("Normal");
|
|
ToggleMultiplierButtonFunction(true);
|
|
}
|
|
|
|
public void ToggleMultiplierButtonFunction(bool doEnable)
|
|
{
|
|
_btnMultiplier.enabled = doEnable;
|
|
}
|
|
|
|
public void SwitchToNextMax()
|
|
{
|
|
GetCurrentMaxMultiplier();
|
|
_idx = _largeIdx;
|
|
_textMultiplier.text = $"x{_multiplierList[_idx]}";
|
|
_textMultiplierMax.text = $"x{_multiplierList[_idx]}";
|
|
ToggleMultiplierButtonFunction(true);
|
|
_goNormal.SetActive(true);
|
|
_goMax.SetActive(false);
|
|
}
|
|
|
|
private int GetCurrentMaxMultiplier()
|
|
{
|
|
return _multiplierList[^1];
|
|
}
|
|
|
|
private void ToggleButtons(bool doShowNormal)
|
|
{
|
|
ELog($"ToggleButtons doShowNormal={doShowNormal}");
|
|
if (doShowNormal)
|
|
{
|
|
_goNormal.SetActive(true);
|
|
_goMax.SetActive(false);
|
|
_textMultiplier.text = $"x{Multiplier}";
|
|
}
|
|
else
|
|
{
|
|
_goNormal.SetActive(false);
|
|
_goMax.SetActive(true);
|
|
_textMultiplierMax.text = $"x{Multiplier}";
|
|
}
|
|
}
|
|
private static void ELog(object t)
|
|
{
|
|
#if UNITY_EDITOR
|
|
Debug.Log($"<color=cyan>{nameof(EventPartnerMiningMultiplierController)} -> {t} </color>");
|
|
#endif
|
|
}
|
|
}
|
|
} |