|
@@ -15,12 +15,37 @@ namespace GFGGame
|
|
|
private float _delay = 300;
|
|
|
private float longpress = 900;//大于900毫秒才算长按
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 购买物品编号
|
|
|
+ /// </summary>
|
|
|
private int _buyId;
|
|
|
- private int _costId;
|
|
|
- private int _perCount;
|
|
|
- private int _perCostCount;
|
|
|
+ /// <summary>
|
|
|
+ /// 最低购买次数
|
|
|
+ /// </summary>
|
|
|
+ private int _minBuyCount;
|
|
|
+ /// <summary>
|
|
|
+ /// 当前购买次数
|
|
|
+ /// </summary>
|
|
|
private int _count;
|
|
|
- private int _maxCount;
|
|
|
+ /// <summary>
|
|
|
+ /// 购买消耗Id
|
|
|
+ /// </summary>
|
|
|
+ private int _costId;//购买消耗Id
|
|
|
+ /// <summary>
|
|
|
+ /// 购买物品数量
|
|
|
+ /// </summary>
|
|
|
+ private int _buyNum;
|
|
|
+ /// <summary>
|
|
|
+ /// 购买物品消耗数量
|
|
|
+ /// </summary>
|
|
|
+ private int _costNum;
|
|
|
+ /// <summary>
|
|
|
+ /// 最大购买量
|
|
|
+ /// </summary>
|
|
|
+ private int _maxCanBuy;
|
|
|
+ // private int _perCount;
|
|
|
+ // private int _perCostCount;
|
|
|
+ // private int _maxCount;
|
|
|
private bool _openSource;
|
|
|
private bool _showTips;
|
|
|
private int _buyType;
|
|
@@ -53,73 +78,80 @@ namespace GFGGame
|
|
|
_ui.m_btnSure.onClick.Add(OnClickBtnSure);
|
|
|
_ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
/// <param name="buyId">购买物品对应的编号,非必须为物品Id</param>
|
|
|
- /// <param name="costId">消耗品id</param>
|
|
|
- /// <param name="perCount">单位兑换数量</param>
|
|
|
- /// <param name="perCostCount">单位消耗数量</param>
|
|
|
- /// <param name="onSuccess">购买完成回调</param>
|
|
|
+ /// <param name="minBuyCount">最低兑换次数</param>
|
|
|
+ /// <param name="buyType">购买类型,对应ConstBuyType</param>
|
|
|
+ /// <param name="shopType">商店类型,仅buytype为TYPE_SHOP时有用</param>
|
|
|
+ /// <param name="onSuccess"></param>
|
|
|
/// <param name="showTips">是否弹购买成功飘字,默认是</param>
|
|
|
/// <param name="openSource">是否打开来源界面。默认否</param>
|
|
|
- /// <param name="count">兑换总量</param>
|
|
|
- public void SetParams(int buyId, int costId, int perCount, int perCostCount, int count, int buyType, int shopType = 0, Action onSuccess = null, bool showTips = true, bool openSource = false, int maxCount = 9990)
|
|
|
+ /// <param name="maxCount"></param>
|
|
|
+ public void SetParams(int buyId, int minBuyCount, int buyType, int shopType = 0, Action onSuccess = null, bool showTips = true, bool openSource = false, int maxCount = 9990)
|
|
|
{
|
|
|
- if (buyType == ConstBuyType.TYPE_SHOP)
|
|
|
- {
|
|
|
- _itemId = ClothingShopCfgManager.Instance.GetShopCfg(buyId, shopType).itemID;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _itemId = buyId;
|
|
|
- }
|
|
|
_buyId = buyId;
|
|
|
- _costId = costId;
|
|
|
- _perCount = perCount;
|
|
|
- _perCostCount = perCostCount;
|
|
|
- _count = count;
|
|
|
+ _itemId = buyId;
|
|
|
+ _minBuyCount = minBuyCount;
|
|
|
+ _count = _minBuyCount;
|
|
|
_onSuccess = onSuccess;
|
|
|
- _maxCount = maxCount;
|
|
|
_openSource = openSource;
|
|
|
_showTips = showTips;
|
|
|
_buyType = buyType;
|
|
|
_shopType = shopType;
|
|
|
+ if (buyType == ConstBuyType.TYPE_SHOP)
|
|
|
+ {
|
|
|
+ ShopCfg shopCfg = ClothingShopCfgManager.Instance.GetShopCfg(buyId, shopType);
|
|
|
+ int maxBuyCount = (int)Math.Floor((decimal)(ItemDataManager.GetItemNum(shopCfg.costID) / shopCfg.costNum));
|
|
|
+ _maxCanBuy = Math.Min(maxCount, maxBuyCount);
|
|
|
+ _itemId = shopCfg.itemID;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (buyType == ConstBuyType.TYPE_ITEM)
|
|
|
+ {
|
|
|
+ ItemExchangeCfg itemExchangeCfg = ItemExchangeCfgArray.Instance.GetCfgs(buyId)[0];
|
|
|
+ int maxBuyCount = (int)Math.Floor((decimal)(ItemDataManager.GetItemNum(itemExchangeCfg.costId) / itemExchangeCfg.costNum));
|
|
|
+
|
|
|
+ _maxCanBuy = Math.Min(Math.Min(maxCount, maxBuyCount), itemExchangeCfg.maxLimit - ItemDataManager.GetItemExchangeTimes(buyId));
|
|
|
+ _itemId = buyId;
|
|
|
+
|
|
|
+ }
|
|
|
+ GetMoneyIdAndNum(minBuyCount, out _costId, out _costNum, out _buyNum);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
protected override void OnShown()
|
|
|
{
|
|
|
base.OnShown();
|
|
|
- _ui.m_txtCount.text = "" + _count;
|
|
|
+ _ui.m_txtCount.text = "" + _minBuyCount;
|
|
|
UpdateView();
|
|
|
}
|
|
|
private void UpdateView()
|
|
|
{
|
|
|
ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemId);
|
|
|
_ui.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
|
|
|
- string itemName = itemCfg.name;
|
|
|
- _ui.m_txtName.text = itemName;
|
|
|
+ _ui.m_txtName.text = itemCfg.name;
|
|
|
+ _ui.m_rarity.visible = false;
|
|
|
+
|
|
|
if (ItemUtilCS.IsDressUpItem(_itemId))
|
|
|
{
|
|
|
_ui.m_rarity.visible = true;
|
|
|
RarityIconController.UpdateRarityIcon(_ui.m_rarity, _itemId, false);
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- _ui.m_rarity.visible = false;
|
|
|
- }
|
|
|
- ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(_costId);
|
|
|
- _ui.m_iconPrice.url = "ui://CommonGame/" + costItemCfg.res;
|
|
|
|
|
|
- _ui.m_txtBuyTips.text = string.Format("消耗{0}{1},可兑换{2}{3}", _perCostCount, costItemCfg.name, _perCount, itemCfg.name);
|
|
|
+ ItemCfg costItemCfg = ItemCfgArray.Instance.GetCfg(_costId);
|
|
|
+ _ui.m_iconPrice.url = ResPathUtil.GetCommonGameResPath(costItemCfg.res);
|
|
|
_ui.m_txtBuyTips.visible = false;
|
|
|
+
|
|
|
UpdateCost();
|
|
|
}
|
|
|
private void UpdateCost()
|
|
|
{
|
|
|
- int count = int.Parse(_ui.m_txtCount.text.Trim());
|
|
|
-
|
|
|
- int price = (int)Math.Ceiling((decimal)count / _perCount) * _perCostCount;
|
|
|
- _ui.m_txtPrice.text = "" + price;
|
|
|
+ GetMoneyIdAndNum(_count, out _costId, out _costNum, out _buyNum);
|
|
|
+ _ui.m_txtCount.text = _count.ToString();
|
|
|
+ _ui.m_txtPrice.text = _costNum.ToString();
|
|
|
SetBtnState();
|
|
|
}
|
|
|
|
|
@@ -137,7 +169,7 @@ namespace GFGGame
|
|
|
}
|
|
|
private void OnTimedEvent(object param)
|
|
|
{
|
|
|
- _selectTimeCount += _delay; //_timer.Interval;
|
|
|
+ _selectTimeCount += _delay;
|
|
|
|
|
|
if (_selectTimeCount >= longpress)
|
|
|
{
|
|
@@ -163,48 +195,29 @@ namespace GFGGame
|
|
|
}
|
|
|
private void OnClickBtnAll()
|
|
|
{
|
|
|
- int costHasNum = ItemDataManager.GetItemNum(_costId);
|
|
|
- int value = (int)Math.Floor((decimal)(costHasNum / _perCostCount * _perCount));
|
|
|
- // int value = ItemUtil.ItemExChangeCount(_itemId, costHasNum);
|
|
|
- value = Math.Min(_maxCount, value);
|
|
|
-
|
|
|
- _ui.m_txtCount.text = value.ToString();
|
|
|
+ _count = _maxCanBuy;
|
|
|
UpdateCost();
|
|
|
}
|
|
|
private void OnClickBtnPlus()
|
|
|
{
|
|
|
- string inputStr = _ui.m_txtCount.text.Trim();
|
|
|
- int value = _count;
|
|
|
- if (inputStr.Length > 0)
|
|
|
- {
|
|
|
- value = int.Parse(inputStr);
|
|
|
- }
|
|
|
- if (value < _maxCount)
|
|
|
+ if (_count < _maxCanBuy)
|
|
|
{
|
|
|
- value += _perCount;
|
|
|
+ _count += 1;
|
|
|
}
|
|
|
- _ui.m_txtCount.text = "" + value;
|
|
|
UpdateCost();
|
|
|
}
|
|
|
|
|
|
private void OnClickBtnMinus()
|
|
|
{
|
|
|
- string inputStr = _ui.m_txtCount.text.Trim();
|
|
|
- int value = _count;
|
|
|
- if (inputStr.Length > 0)
|
|
|
- {
|
|
|
- value = int.Parse(inputStr);
|
|
|
- }
|
|
|
- value -= _perCount;
|
|
|
- value = Math.Max(_count, value);
|
|
|
- _ui.m_txtCount.text = "" + value;
|
|
|
+ _count -= 1;
|
|
|
+ _count = Math.Max(_minBuyCount, _count);
|
|
|
UpdateCost();
|
|
|
}
|
|
|
private void SetBtnState()
|
|
|
{
|
|
|
string inputStr = _ui.m_txtCount.text.Trim();
|
|
|
|
|
|
- if (inputStr == null || int.Parse(inputStr) <= _count)
|
|
|
+ if (inputStr == null || int.Parse(inputStr) <= _minBuyCount)
|
|
|
{
|
|
|
_ui.m_btnMinus.enabled = false;
|
|
|
}
|
|
@@ -213,10 +226,8 @@ namespace GFGGame
|
|
|
_ui.m_btnMinus.enabled = true;
|
|
|
|
|
|
}
|
|
|
- int costHasNum = ItemDataManager.GetItemNum(_costId);
|
|
|
- int maxCanBuy = (int)Math.Floor((decimal)(costHasNum / _perCostCount * _perCount));
|
|
|
- // int maxCanBuy = ItemUtil.ItemExChangeCount(_itemId, costHasNum);
|
|
|
- if (inputStr != null && (int.Parse(inputStr) >= maxCanBuy))
|
|
|
+
|
|
|
+ if (inputStr != null && (int.Parse(inputStr) >= _maxCanBuy))
|
|
|
{
|
|
|
_ui.m_btnPlus.enabled = false;
|
|
|
_ui.m_btnAll.enabled = false;
|
|
@@ -254,10 +265,8 @@ namespace GFGGame
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- int buyCount = price / _perCostCount * _perCount;
|
|
|
- // ItemUtil.AddItemUseCost(_itemId, buyCount, _costId, price);
|
|
|
+
|
|
|
bool result = false;
|
|
|
- // result
|
|
|
switch (_buyType)
|
|
|
{
|
|
|
case ConstBuyType.TYPE_NORMAL:
|
|
@@ -292,17 +301,38 @@ namespace GFGGame
|
|
|
this.Hide();
|
|
|
}
|
|
|
|
|
|
+ private void GetMoneyIdAndNum(int count, out int _costId, out int _costNum, out int _buyNum)
|
|
|
+ {
|
|
|
+ _costId = 0;
|
|
|
+ _costNum = 0;
|
|
|
+ _buyNum = 0;
|
|
|
+ if (_buyType == ConstBuyType.TYPE_SHOP)
|
|
|
+ {
|
|
|
+
|
|
|
+ ClothingShopCfgManager.Instance.GetMoneyIdAndNum(_buyId, count, _shopType, out _costId, out _costNum, out _buyNum);
|
|
|
|
|
|
+ }
|
|
|
+ else if (_buyType == ConstBuyType.TYPE_ITEM)
|
|
|
+ {
|
|
|
+
|
|
|
+ ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(_itemId, ItemDataManager.GetItemExchangeTimes(_itemId), count, out _costId, out _costNum, out _buyNum);
|
|
|
+
|
|
|
+ }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+
|
|
|
+ // }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
{
|
|
|
_buyId = 0;
|
|
|
_costId = 0;
|
|
|
- _perCount = 0;
|
|
|
- _perCostCount = 0;
|
|
|
- _count = 0;
|
|
|
- _maxCount = 0;
|
|
|
+ // _perCount = 0;
|
|
|
+ // _perCostCount = 0;
|
|
|
+ _minBuyCount = 0;
|
|
|
+ // _maxCount = 0;
|
|
|
}
|
|
|
protected override void OnHide()
|
|
|
{
|