local UIGachaExchangePopUp = UIViewClass() local EventSystem = require('Event/EventSystem') local ColorStr = "%d" ------------------------------ 系统函数 ------------------------------------- function UIGachaExchangePopUp:OnOpened(context) self:RegistSystemEvent(EventID.UI_GachaShop_RefreshPopUp, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_OperationActivity_DataChanged, self.OnDataChanged) self:RegistSystemEvent(EventID.UI_OperationActivity_CloseView, self.OnCloseActivitySelf) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_StoreName_GoldHero) self.goodData = context.goodData self.activityId = context.activityId self.activityType = context.activityType self.purchaseCount = 1 self:RefreshPanel() EventSystem.Dispatch(EventID.UI_GachaShop_Refresh) end function UIGachaExchangePopUp:OnCloseActivitySelf(viewClassPath, activityId) if viewClassPath == self.__viewClassPath then if self.activityId and activityId == self.activityId then self:CloseView() end end end function UIGachaExchangePopUp:OnBackButtonPressed() self:OnButtonClicked(self.img_Bottom) end function UIGachaExchangePopUp:OnDataChanged() self:OnButtonClicked(self.img_Bottom) end function UIGachaExchangePopUp:OnButtonClicked(comp) if comp == self.img_Bottom or comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.item.event_Click then UTL.ItemTips.ShowCommonTipsById(self.goodData.ItemID) elseif comp == self.btn_Exchange then -- 折扣变化 local formerIsDiscount = self.isInDiscount self.isInDiscount = CTL.PayMall.IsInDiscount(self.goodData) if formerIsDiscount ~= self.isInDiscount then self:RefreshPanel() EventSystem.Dispatch(EventID.UI_GachaShop_Refresh) CTL.Tips.AddTipsMsg(Const_IDS.IDS_Store_ResetPrice) return end if CTL.PayMall.IsCanPurchase(self.goodData, self.purchaseCount) then MDL.Purchase.PurchaseItemsReq(self.goodData.ID, self.purchaseCount, self.activityId, self.activityType) self:CloseView() end elseif comp == self.group_NumSelect.bg_NumSelect then if not self.keyBoardView then self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), {parentView = self, callBackParam = data, x = 384, y = 248, minNum = 1, maxNum = self.availablePurchaseCount}) end elseif comp == self.group_NumSelect.event_Plus then self:RefreshPurchaseCount(self.purchaseCount + 1 <= self.availablePurchaseCount and self.purchaseCount + 1 or self.purchaseCount) elseif comp == self.group_NumSelect.event_Minus then self:RefreshPurchaseCount(self.purchaseCount - 1 > 0 and self.purchaseCount - 1 or self.purchaseCount) elseif comp == self.group_NumSelect.event_Min then self:RefreshPurchaseCount(1) elseif comp == self.group_NumSelect.event_Max then self:RefreshPurchaseCount(self.availablePurchaseCount) end end function UIGachaExchangePopUp:ExcuteKeyBoardBack(count, paramData) self:RefreshPurchaseCount(count) end function UIGachaExchangePopUp:CloseKeyBoardView() self.subView:CloseAll(); self.keyBoardView = nil; end ------------------------------------------------------------------------------------------- function UIGachaExchangePopUp:RefreshPanel() self.isLimit, self.limitStr, self.availablePurchaseCount = CTL.PayMall.IsLimitedGood(self.goodData) self.isInDiscount, self.discountStr, self.singlePrice = CTL.PayMall.IsInDiscount(self.goodData) UTL.Item.SetItemCell(self.item, self.goodData.ItemID, self.goodData.ItemNum) UIUtils.SetLabel(self.txt_ItemName, UTL.Item.GetItemColorName(self.goodData.ItemID)) UTL.Item.SetCurrencyImageIcon(self.img_Icon, self.goodData.MoneyID) self:RefreshPurchaseCount(self.availablePurchaseCount > 0 and 1 or 0) local isUnlock, des = CTL.PayMall.IsUnlockPurchase(self.goodData, false) UIUtils.SetActive(self.btn_Exchange, isUnlock) UIUtils.SetLabel(self.group_NumSelect.lab_Time, CTL.PayMall.GetLimitedTitle(self.goodData) .. self.limitStr) end function UIGachaExchangePopUp:RefreshPurchaseCount(purchaseCount) local canBuyCount, isEnough, costNum = CTL.PayMall.CalculateAvailablePurchase(self.goodData, purchaseCount) self.purchaseCount = canBuyCount UIUtils.SetLabel(self.group_NumSelect.txt_NumSelect, self.purchaseCount) local sumCost = self.singlePrice * self.purchaseCount UIUtils.SetLabel(self.txt_Num, (UTL.Item.GetItemStockCount(self.goodData.MoneyID) < sumCost) and string.format(ColorStr, UTL.Color.Red, sumCost) or sumCost) end return UIGachaExchangePopUp