|
@@ -15,16 +15,45 @@ namespace GFGGame
|
|
|
private float _delay = 300;
|
|
|
private float longpress = 900;//大于900毫秒才算长按
|
|
|
|
|
|
- private int _itemId;
|
|
|
- private int _costId;
|
|
|
- private int _perCount;
|
|
|
- private int _perCostCount;
|
|
|
+ /// <summary>
|
|
|
+ /// 购买物品编号
|
|
|
+ /// </summary>
|
|
|
+ private int _buyId;
|
|
|
+ /// <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;
|
|
|
+ private int _shopType;
|
|
|
+ private int _itemId;
|
|
|
private Action _onSuccess;
|
|
|
|
|
|
+
|
|
|
public override void Dispose()
|
|
|
{
|
|
|
base.Dispose();
|
|
@@ -49,65 +78,79 @@ namespace GFGGame
|
|
|
_ui.m_btnSure.onClick.Add(OnClickBtnSure);
|
|
|
_ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
- /// <param name="itemId">物品id</param>
|
|
|
- /// <param name="costId">消耗品id</param>
|
|
|
- /// <param name="perCount">单位兑换数量</param>
|
|
|
- /// <param name="perCostCount">单位消耗数量</param>
|
|
|
- /// <param name="onSuccess">购买完成回调</param>
|
|
|
+ /// <param name="buyId">购买物品对应的编号,非必须为物品Id</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 itemId, int costId, int perCount, int perCostCount, int count, 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)
|
|
|
{
|
|
|
- _itemId = itemId;
|
|
|
- _costId = costId;
|
|
|
- _perCount = perCount;
|
|
|
- _perCostCount = perCostCount;
|
|
|
- _count = count;
|
|
|
+ _buyId = buyId;
|
|
|
+ _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.GetCfg(buyId);
|
|
|
+ int maxBuyCount = (int)Math.Floor((decimal)(ItemDataManager.GetItemNum(itemExchangeCfg.costId) / itemExchangeCfg.costNumArr[0]));
|
|
|
+
|
|
|
+ _maxCanBuy = Math.Min(Math.Min(maxCount, maxBuyCount), itemExchangeCfg.maxLimit == 0 ? maxCount : 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;
|
|
|
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;
|
|
|
- // int price = ItemUtil.CostItemCount(_itemId, count);
|
|
|
-
|
|
|
- _ui.m_txtPrice.text = "" + price;
|
|
|
+ GetMoneyIdAndNum(_count, out _costId, out _costNum, out _buyNum);
|
|
|
+ _ui.m_txtCount.text = _buyNum.ToString();
|
|
|
+ _ui.m_txtPrice.text = _costNum.ToString();
|
|
|
SetBtnState();
|
|
|
}
|
|
|
|
|
@@ -125,7 +168,7 @@ namespace GFGGame
|
|
|
}
|
|
|
private void OnTimedEvent(object param)
|
|
|
{
|
|
|
- _selectTimeCount += _delay; //_timer.Interval;
|
|
|
+ _selectTimeCount += _delay;
|
|
|
|
|
|
if (_selectTimeCount >= longpress)
|
|
|
{
|
|
@@ -151,48 +194,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)
|
|
|
+ if (_count < _maxCanBuy)
|
|
|
{
|
|
|
- value = int.Parse(inputStr);
|
|
|
+ _count += 1;
|
|
|
}
|
|
|
- if (value < _maxCount)
|
|
|
- {
|
|
|
- value += _perCount;
|
|
|
- }
|
|
|
- _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;
|
|
|
}
|
|
@@ -201,10 +225,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;
|
|
@@ -216,7 +238,7 @@ namespace GFGGame
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- private void OnClickBtnSure()
|
|
|
+ private async void OnClickBtnSure()
|
|
|
{
|
|
|
int count = int.Parse(_ui.m_txtCount.text.Trim());
|
|
|
int price = int.Parse(_ui.m_txtPrice.text.Trim());
|
|
@@ -229,7 +251,7 @@ namespace GFGGame
|
|
|
|
|
|
if (_openSource)
|
|
|
{
|
|
|
- if (_itemId == ConstItemID.DIAMOND_RED)
|
|
|
+ if (_buyId == ConstItemID.DIAMOND_RED)
|
|
|
{
|
|
|
ItemUtil.AddDiamondPurple();
|
|
|
}
|
|
@@ -242,14 +264,24 @@ namespace GFGGame
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- int buyCount = price / _perCostCount * _perCount;
|
|
|
- ItemUtil.AddItemUseCost(_itemId, buyCount, _costId, price);
|
|
|
- // GuideController.HideGuide();
|
|
|
+
|
|
|
+ bool result = false;
|
|
|
+ switch (_buyType)
|
|
|
+ {
|
|
|
+ case ConstBuyType.TYPE_NORMAL:
|
|
|
+ break;
|
|
|
+ case ConstBuyType.TYPE_ITEM:
|
|
|
+ result = await ItemExchangeSProxy.ItemExchange(_buyId, count);
|
|
|
+ break;
|
|
|
+ case ConstBuyType.TYPE_SHOP:
|
|
|
+ result = await ShopSProxy.ShopBuy(_shopType, _buyId, count);
|
|
|
+ break;
|
|
|
+ }
|
|
|
if (_onSuccess != null)
|
|
|
{
|
|
|
_onSuccess();
|
|
|
}
|
|
|
- if (_showTips)
|
|
|
+ if (result && _showTips)
|
|
|
{
|
|
|
PromptController.Instance.ShowFloatTextPrompt("购买成功", MessageType.SUCCESS);
|
|
|
}
|
|
@@ -268,17 +300,34 @@ 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);
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
{
|
|
|
- _itemId = 0;
|
|
|
+ _buyId = 0;
|
|
|
_costId = 0;
|
|
|
- _perCount = 0;
|
|
|
- _perCostCount = 0;
|
|
|
- _count = 0;
|
|
|
- _maxCount = 0;
|
|
|
+ // _perCount = 0;
|
|
|
+ // _perCostCount = 0;
|
|
|
+ _minBuyCount = 0;
|
|
|
+ // _maxCount = 0;
|
|
|
}
|
|
|
protected override void OnHide()
|
|
|
{
|
|
@@ -287,14 +336,6 @@ namespace GFGGame
|
|
|
Reset();
|
|
|
|
|
|
}
|
|
|
- protected override void UpdateToCheckGuide(object param)
|
|
|
- {
|
|
|
- if (!ViewManager.CheckIsTopView(this.viewCom)) return;
|
|
|
-
|
|
|
- GuideController.TryGuide(_ui.m_btnSure, ConstGuideId.BUY_CLOTHING, 3, "找到需要的物品了,点击购买吧");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 是否显示购买提示
|
|
|
/// </summary>
|
|
@@ -306,5 +347,12 @@ namespace GFGGame
|
|
|
_ui.m_txtBuyTips.visible = value;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ protected override void UpdateToCheckGuide(object param)
|
|
|
+ {
|
|
|
+ if (!ViewManager.CheckIsTopView(this.viewCom)) return;
|
|
|
+
|
|
|
+ GuideController.TryGuide(_ui.m_btnSure, ConstGuideId.BUY_CLOTHING, 3, "找到需要的物品了,点击购买吧");
|
|
|
+ }
|
|
|
}
|
|
|
}
|