using System; using UnityEngine; namespace Wizard; public class SelectBuyNumPopupBase : UIBase { private const int DEFAULT_BUY_NUM = 1; protected const string BUY_BTN_OFF_CRYSTAL_SPRITE = "btn_input_03_off"; protected const string BUY_BTN_ON_CRYSTAL_SPRITE = "btn_input_03_on"; protected const string BUY_BTN_OFF_TICKET_SPRITE = "btn_input_04_off"; protected const string BUY_BTN_ON_TICKET_SPRITE = "btn_input_04_on"; protected const string BUY_BTN_OFF_RUPY_SPRITE = "btn_input_01_off"; protected const string BUY_BTN_ON_RUPY_SPRITE = "btn_input_01_on"; [SerializeField] protected float PRESS_TIME_FOR_CHANGE_NUM = 0.4f; [SerializeField] protected UITexture _PackLogo; [SerializeField] protected UILabel _buyPackLabel; [SerializeField] protected UITexture _iconTicket; [SerializeField] protected UISprite _iconCrystal; [SerializeField] protected UISprite _iconRupy; [SerializeField] protected UIButton _buttonPlus; [SerializeField] protected UIButton _buttonMinus; [SerializeField] protected UIButton _buttonMax; [SerializeField] protected UIButton _buttonPurchase; [SerializeField] protected UILabel _labelHaveItemName; [SerializeField] protected UILabel _labelHaveNumItems; [SerializeField] protected UILabel _labelCostPerPack; [SerializeField] protected UILabel _labelBuyNum; [SerializeField] protected UILabel _labelBuyNumPurchaseBtn; [SerializeField] protected UILabel _labelCostNamePurchaseBtn; [SerializeField] protected UILabel _labelCostNumPurchaseBtn; [SerializeField] protected UILabel _labelBtnMax; [SerializeField] private bool _isOverrideDisableMaxLabelColor; [SerializeField] private Color32 _maxLabelOverrideColor; protected DialogBase _dialog; protected int _gachaCostPerPack; protected int _buyNum = 1; protected int _ableBuyNum; protected bool _isChangedNum; protected bool _isPressingPlusBtn; protected bool _isPressingMinusBtn; protected float _timePressingPlusBtn; protected float _timePressingMinusBtn; protected virtual string _labelBuyNumPurchaseBtnTextId => "Shop_0046"; protected void OnPressToPlusBtn(GameObject go, bool state) { _isPressingPlusBtn = state; if (!state) { if (!_isChangedNum && !_isPressingMinusBtn) { PlusBuyNum(); } } else { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON); } _timePressingPlusBtn = 0f; _isChangedNum = false; } protected void OnPressToMinusBtn(GameObject go, bool state) { _isPressingMinusBtn = state; if (!state) { if (!_isChangedNum && !_isPressingPlusBtn) { MinusBuyNum(); } } else { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON); } _timePressingMinusBtn = 0f; _isChangedNum = false; } protected void Update() { if (_isPressingPlusBtn) { if (!_isPressingMinusBtn) { _timePressingPlusBtn += Time.deltaTime; if (_timePressingPlusBtn >= PRESS_TIME_FOR_CHANGE_NUM) { _timePressingPlusBtn = 0f; _isChangedNum = true; GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BAR_SLIDE); PlusBuyNum(); } } } else if (_isPressingMinusBtn && !_isPressingPlusBtn) { _timePressingMinusBtn += Time.deltaTime; if (_timePressingMinusBtn >= PRESS_TIME_FOR_CHANGE_NUM) { _timePressingMinusBtn = 0f; _isChangedNum = true; GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BAR_SLIDE); MinusBuyNum(); } } } protected void PlusBuyNum() { if (_buyNum < _ableBuyNum) { _buyNum++; UpdateBuyNumDisplays(); } } protected void MinusBuyNum() { if (_buyNum > 1) { _buyNum--; UpdateBuyNumDisplays(); } } protected void SetEnablePlusBtn(bool _isEnable) { _buttonPlus.isEnabled = _isEnable; if (!_isEnable) { _isPressingPlusBtn = false; _timePressingPlusBtn = 0f; _isChangedNum = false; } } protected void SetEnableMinusBtn(bool _isEnable) { _buttonMinus.isEnabled = _isEnable; if (!_isEnable) { _isPressingMinusBtn = false; _timePressingMinusBtn = 0f; _isChangedNum = false; } } protected void OnBtnPurchase(Action OnClickPurchase, PackConfig packConfig, PackChildGachaInfo gachaInfo) { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE); OnClickPurchase(packConfig, gachaInfo, _buyNum); _dialog.CloseWithoutSelect(); } protected void OnBtnMax() { GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON); _buyNum = _ableBuyNum; UpdateBuyNumDisplays(); } protected void UpdateBuyNumDisplays() { int num = _buyNum * _gachaCostPerPack; _labelBuyNum.text = _buyNum.ToString(); _labelBuyNumPurchaseBtn.text = Data.SystemText.Get(_labelBuyNumPurchaseBtnTextId, _buyNum.ToString()); _labelCostNumPurchaseBtn.text = num.ToString(); if (_buyNum >= _ableBuyNum) { SetEnablePlusBtn(_isEnable: false); _buttonMax.isEnabled = false; } else { SetEnablePlusBtn(_isEnable: true); _buttonMax.isEnabled = true; } if (_buyNum <= 1) { SetEnableMinusBtn(_isEnable: false); } else { SetEnableMinusBtn(_isEnable: true); } ShopCommonUtility.SetButtonLabelStyle(_buttonMax, _labelBtnMax); if (_isOverrideDisableMaxLabelColor && !_buttonMax.isEnabled) { _labelBtnMax.color = _maxLabelOverrideColor; } } }