local UIItemBuyPanel = UIViewClass() local ChangeItemCountSpeed = 0.3 local BuyType = { None = 0,--None Activity = 1, --活动购买次数 Items = 2, --道具购买次数 HonorOrder = 3, --战令购买等级 } function UIItemBuyPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_OperationActivity_DataChanged, self.OnDataChanged) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_COMMON_PROMPT) self.CurBuyType = BuyType.None self.type = context.type self.isHonorOrder = context.isHonorOrder self.ItemId = context.ItemId self.ItemStoreId = context.ItemStoreId self.CurrencyCount = context.CurrencyCount self.CurrencyId = context.CurrencyId self.leftNumByNext = context.leftNumByNext self.DrawCardMax = DataSheetManager.ConstData:GetDataByID("DrawCardBuyItemShowMax").IntValue local goodData = MDL.OperationActivity.StoreGoodsData:GetDataByID(self.ItemStoreId) if goodData then local _, _, availablePurchaseCount = CTL.PayMall.IsLimitedGood(goodData) self.DrawCardMax = availablePurchaseCount end --按住的状态 self._pressPlus=false self._pressMinus=false self:RegistTriggerEvent(self.btn_Plus, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.btn_Plus, UIEventTriggerType.PointerUp) self:RegistTriggerEvent(self.btn_Minus, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.btn_Minus, UIEventTriggerType.PointerUp) if self:IsActivity() then self.CurBuyType = BuyType.Activity self:InitActivityNums() elseif self:IsItems() then self.CurBuyType = BuyType.Items self:InitItems() elseif self.isHonorOrder then self.CurBuyType = BuyType.HonorOrder self:InitHonorOrderLevel() end if self.leftNumByNext ~= nil and self.leftNumByNext > 0 then self._currentBuyCount = self.leftNumByNext else self._currentBuyCount = 1 end self:RefreshBuyCount() end function UIItemBuyPanel:OnDataChanged() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIItemBuyPanel:InitActivityNums() local payItemIconPath = "" if self.type == LuaConst.ActivityType.GuildMine then local curPayNum = MDL.GuildMine.GetMinePurchaseNum() payItemIconPath = DataSheetManager.ItemData:GetDataByID(DataSheetManager.MinePlunderCost:GetDataByID(curPayNum > 0 and curPayNum or 1).MinePlunderCostItem).Icon self.Count = DataSheetManager.MinePlunderCost:GetDataCount() - curPayNum else payItemIconPath = DataSheetManager.ItemData:GetDataByID(DataSheetManager.ActivityData:GetDataByID(self.type).PayItem).Icon self.Count = MDL.Purchase.GetAvailablePurchaseTimes(self.type) end UTL.Item.ItemIconByName(self.icon_Cost, payItemIconPath) UIUtils.SetLabel(self.txt_Times,string.FormatByIdsId(Const_IDS.IDS_BuyTimes_Info,self.Count)) UIUtils.SetLabelText(self.txt_Max, Const_IDS.IDS_Item_Max) UIUtils.SetLabelText(self.txt_Min, Const_IDS.IDS_Item_Min) --官职收益 UIUtils.SetLabel(self.txt_Info, MDL.OfficialPosition.GetPurchaseTimesDesc(self.type)) end --购买道具 function UIItemBuyPanel:InitItems() self.txt_Max.text = "+10" self.txt_Min.text = "-10" UTL.Item.ItemIconByName(self.icon_Cost, DataSheetManager.ItemData:GetDataByID(self.CurrencyId).Icon) UIUtils.SetLabel(self.lab_Times, UTL.Item.GetItemDataSpliceByType(self.ItemId).Name) self.txt_Times.text = nil UIUtils.SetLabel(self.txt_Cost, self.CurrencyCount) end -- 购买战令等级 function UIItemBuyPanel:InitHonorOrderLevel() local itemID = MDL.HonorOrder:GetCurHonorOrderConstData().BuyGradeCurrency self.Count = MDL.HonorOrder.GetBuyHonorOrderLevelNum() UTL.Item.ItemIconByName(self.icon_Cost, DataSheetManager.ItemData:GetDataByID(itemID).Icon) UIUtils.SetLabel(self.txt_Cost, MDL.HonorOrder:GetCurHonorOrderConstData().EachGradePrice) UIUtils.SetLabel(self.txt_Times, UIUtils.GetLocalizedTxt(Const_IDS.IDS_HonorOrder_GouMaiDengJiShangXian)..self.Count) UIUtils.SetLabelText(self.txt_Max, Const_IDS.IDS_Item_Max) UIUtils.SetLabelText(self.txt_Min, Const_IDS.IDS_Item_Min) self.CurrencyId = MDL.HonorOrder:GetCurHonorOrderConstData().BuyGradeCurrency self.CurrencyCount = MDL.HonorOrder:GetCurHonorOrderConstData().EachGradePrice end --检测按钮按住 function UIItemBuyPanel:OnUpdateFun(deltaTime, timeSineUpdate) if not self._pressPlus and not self._pressMinus then return end if self.CurBuyType == BuyType.Items then return end if self._pressPlus then self:PlusItemCount() end if self._pressMinus then self:MinusItemCount() end end --以下为按钮点击事件 function UIItemBuyPanel:OnClickBuy() self._currentBuyCount = tonumber(self.txt_Num.text) if self.CurBuyType == BuyType.Activity then if CTL.Purchase.ClickPurchaseNums(self.type, self._currentBuyCount) then self:CloseView() end elseif self.CurBuyType == BuyType.Items then local sum = self._currentBuyCount * self.CurrencyCount local isEnough = MDL.Currency.IsMoneyEnough(self.CurrencyId, sum) if isEnough == true then if self.ItemStoreId ~= nil then MDL.Purchase.PurchaseItemsReq(self.ItemStoreId, self._currentBuyCount) else MDL.Purchase.PurchaseItemsReq(self.ItemId, self._currentBuyCount) end self:CloseView() else CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS["IDS_DrawCard_Tip_LackItem"], UTL.Item.GetItemDataSpliceByType(self.CurrencyId).Name)) end elseif self.CurBuyType == BuyType.HonorOrder then local sum = self._currentBuyCount * self.CurrencyCount local isEnough = MDL.Currency.IsMoneyEnough(self.CurrencyId, sum) if isEnough == true then MDL.HonorOrder.HonorOrderAwardBuyLvRequest(self._currentBuyCount) self:CloseView() else CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS["IDS_DrawCard_Tip_LackItem"], UTL.Item.GetItemDataSpliceByType(self.CurrencyId).Name)) end end end function UIItemBuyPanel:OnClickMax() if self:IsActivity() or self.isHonorOrder then self._currentBuyCount = self.Count elseif self:IsItems() then self._currentBuyCount = self._currentBuyCount + 10 if self._currentBuyCount > self.DrawCardMax then self._currentBuyCount = self.DrawCardMax end end self:RefreshBuyCount() end function UIItemBuyPanel:OnClickMin() if self:IsActivity() or self.isHonorOrder then self._currentBuyCount = 1 elseif self:IsItems() then if self._currentBuyCount >= 10 then self._currentBuyCount = self._currentBuyCount - 10 else self._currentBuyCount = 1 end end self:RefreshBuyCount() end function UIItemBuyPanel:OnClickPlus() if self:IsActivity() or self.isHonorOrder then if self._currentBuyCount < self.Count then self._currentBuyCount = self._currentBuyCount + 1 end elseif self:IsItems() then if self._currentBuyCount < self.DrawCardMax then self._currentBuyCount = self._currentBuyCount + 1 else self._currentBuyCount = self.DrawCardMax end end self:RefreshBuyCount() end function UIItemBuyPanel:OnClickMinus() if self:IsActivity() or self.isHonorOrder then if self._currentBuyCount > 1 then self._currentBuyCount = self._currentBuyCount - 1 end elseif self:IsItems() then if self._currentBuyCount > 1 then self._currentBuyCount = self._currentBuyCount - 1 end end self:RefreshBuyCount() end function UIItemBuyPanel:RefreshBuyCount() if self:IsActivity() then if self._currentBuyCount > self.Count then self._currentBuyCount = self.Count self._pressPlus = false self:StopRepeatFunc(self.OnUpdateFun) end if self._currentBuyCount < 1 then self._currentBuyCount = 1 self._pressMinus = false self:StopRepeatFunc(self.OnUpdateFun) end local payItemId if self.type == LuaConst.ActivityType.GuildMine then local curPayNum = MDL.GuildMine.GetMinePurchaseNum() payItemId = DataSheetManager.MinePlunderCost:GetDataByID(curPayNum > 0 and curPayNum or 1).MinePlunderCostItem else payItemId = DataSheetManager.ActivityData:GetDataByID(self.type).PayItem end local hasNums = MDL.Currency.GetMoneyCount(payItemId) self.txt_Num.text = self._currentBuyCount local costNum costNum = CTL.Purchase.GetCostNums(self.type, self._currentBuyCount) if hasNums >= costNum then UIUtils.SetLabel(self.txt_Cost, costNum) self.btn_Buy:SetGray(false) else UIUtils.SetLabel(self.txt_Cost, UTL.Color.FormatRedColor(costNum)) self.btn_Buy:SetGray(true, true) end --self. 根据货币ID修改ICON elseif self:IsItems() then if self._currentBuyCount <= 0 then self._currentBuyCount = 1 end if self._currentBuyCount > self.DrawCardMax then self._currentBuyCount = self.DrawCardMax end self.txt_Num.text = self._currentBuyCount local sum = self._currentBuyCount * self.CurrencyCount local isEnough = MDL.Currency.IsMoneyEnough(self.CurrencyId, sum) if isEnough == false then UIUtils.SetLabel(self.txt_Cost, UTL.Color.FormatRedColor(sum)) else UIUtils.SetLabel(self.txt_Cost, sum) end elseif self.isHonorOrder then if self._currentBuyCount <= 0 then self._currentBuyCount = 1 end if self._currentBuyCount > self.DrawCardMax then self._currentBuyCount = self.DrawCardMax end self.txt_Num.text = self._currentBuyCount local sum = self._currentBuyCount * self.CurrencyCount local isEnough = MDL.Currency.IsMoneyEnough(self.CurrencyId, sum) if isEnough == false then UIUtils.SetLabel(self.txt_Cost, UTL.Color.FormatRedColor(sum)) else UIUtils.SetLabel(self.txt_Cost, sum) end end end function UIItemBuyPanel:OnPressPlus() self._pressPlus = true self:StartRepeatFunc(self.OnUpdateFun, ChangeItemCountSpeed) end function UIItemBuyPanel:PlusItemCount() self._currentBuyCount = self._currentBuyCount + 1 self:RefreshBuyCount() end function UIItemBuyPanel:OnPressPlusStop() self._pressPlus = false self:StopRepeatFunc(self.OnUpdateFun) end function UIItemBuyPanel:OnPressMinus() self._pressMinus = true self:StartRepeatFunc(self.OnUpdateFun, ChangeItemCountSpeed) end function UIItemBuyPanel:MinusItemCount() self._currentBuyCount = self._currentBuyCount - 1 self:RefreshBuyCount() end function UIItemBuyPanel:OnPressMinusStop() self._pressMinus = false self:StopRepeatFunc(self.OnUpdateFun) end function UIItemBuyPanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIItemBuyPanel:OnButtonClicked(comp) if comp == self.btn_Buy then self:OnClickBuy() elseif comp == self.btn_Max then self:OnClickMax() elseif comp == self.btn_Min then self:OnClickMin() elseif comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.event_Count then if not self.keyBoardView then local maxCount = 0 if self:IsActivity() or self.isHonorOrder then maxCount = self.Count elseif self:IsItems() then maxCount = self.DrawCardMax end self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), {parentView = self, x = 40, y = 280, minNum = 1, maxNum = maxCount}, nil, nil); end end end function UIItemBuyPanel:ExcuteKeyBoardBack(count, param) self._currentBuyCount = count self:RefreshBuyCount() end function UIItemBuyPanel:CloseKeyBoardView() self.keyBoardView:CloseView() self.keyBoardView = nil end function UIItemBuyPanel:OnPointerDown(comp, eventData) if comp == self.btn_Plus then self:OnClickPlus() self:OnPressPlus() elseif comp == self.btn_Minus then self:OnClickMinus() self:OnPressMinus() end end function UIItemBuyPanel:OnPointerUp(comp, eventData) if comp == self.btn_Plus then self:OnPressPlusStop() elseif comp == self.btn_Minus then self:OnPressMinusStop() end end function UIItemBuyPanel:IsActivity( ) return self.type ~= nil end function UIItemBuyPanel:IsItems( ) return self.ItemId ~= nil end return UIItemBuyPanel