local UICommonExchange = UIViewClass() function UICommonExchange:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_OmnipotentFragment_MassExchange) self.costItemId = context.costItemId self.giveItemId = context.giveItemId self.costItemCount = MDL.Bag.GetItemCount(self.costItemId) -- 拥有的金品质万能碎片数量 self.needCount = context.needCount -- 需要碎片数量 self.minNum = 1 if self.needCount > self.costItemCount then self._currentBuyCount = self.costItemCount self.maxNum = self.costItemCount elseif self.needCount < self.costItemCount then self._currentBuyCount = self.needCount self.maxNum = self.costItemCount else self._currentBuyCount = self.costItemCount self.maxNum = self.costItemCount end UTL.Item.SetItemCell(self.img_Item1, self.costItemId, 0) UTL.Item.SetItemCell(self.img_Item2, self.giveItemId, 0) UIUtils.SetLabel(self.item_Name1, UTL.Item.GetItemColorName(self.costItemId)) UIUtils.SetLabel(self.item_Name2, UTL.Item.GetItemColorName(self.giveItemId)) local costItemCfgData = DataSheetManager.ItemData:GetDataByID(self.costItemId) if costItemCfgData.SecondType == LuaConst.ItemMaterialsType.GoldFragment then if costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Hero then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_Num"], self.costItemCount, self.needCount)) elseif costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Weapon then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Weapon_Num"], self.costItemCount, self.needCount)) elseif costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Horse then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_NumGoldMount"], self.costItemCount, self.needCount)) elseif costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Treasure then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_NumGoldTreasure"], self.costItemCount, self.needCount)) elseif costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.GodBeast then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_NumGoldGodBeast"], self.costItemCount, self.needCount)) end elseif costItemCfgData.SecondType == LuaConst.ItemMaterialsType.SuperGoldFragment then if costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Hero then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_NumColourHero"], self.costItemCount, self.needCount)) elseif costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Weapon then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_NumColourDivineTroops"], self.costItemCount, self.needCount)) elseif costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Horse then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_NumColourMount"], self.costItemCount, self.needCount)) elseif costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.Treasure then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_NumColourTreasure"], self.costItemCount, self.needCount)) elseif costItemCfgData.ThirdType == LuaConst.ItemGoldFragmentType.GodBeast then UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS["IDS_OmnipotentFragment_Hero_NumColourGodBeast"], self.costItemCount, self.needCount)) end end self:RefreshBuyCount() end function UICommonExchange:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close or comp == self.btn_Cancel then self:CloseView() elseif comp == self.btn_Exchange then MDL.ItemUse.UseUniversalFragmentReq(self.costItemId, self.giveItemId, self._currentBuyCount) CTL.Tips.AddTipsMsg(Const_IDS["IDS_OmnipotentFragment_RedemptionSucceeded"]) self:CloseView() elseif comp == self.btn_Max then self:OnClickMax() elseif comp == self.btn_Min then self:OnClickMin() elseif comp == self.btn_Plus then self:OnClickPlus() elseif comp == self.btn_Minus then self:OnClickMinus() elseif comp == self.event_Count then if not self.keyBoardView then self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), {parentView = self, x = 40, y = 200, minNum = self.minNum, maxNum = self.maxNum}, nil, nil); end end end function UICommonExchange:ExcuteKeyBoardBack(count, param) self._currentBuyCount = count self:RefreshBuyCount() end function UICommonExchange:CloseKeyBoardView() self.keyBoardView:CloseView() self.keyBoardView = nil end function UICommonExchange:OnClickMax() self._currentBuyCount = self.maxNum self:RefreshBuyCount() end function UICommonExchange:OnClickMin() self._currentBuyCount = self.minNum self:RefreshBuyCount() end function UICommonExchange:OnClickPlus() if self._currentBuyCount < self.maxNum then self._currentBuyCount = self._currentBuyCount + 1 else self._currentBuyCount = self.maxNum end self:RefreshBuyCount() end function UICommonExchange:OnClickMinus() if self._currentBuyCount > self.minNum then self._currentBuyCount = self._currentBuyCount - 1 else self._currentBuyCount = self.minNum end self:RefreshBuyCount() end function UICommonExchange:RefreshBuyCount() UIUtils.SetLabel(self.img_Item1.lab_Count, self._currentBuyCount) UIUtils.SetLabel(self.img_Item2.lab_Count, self._currentBuyCount) self.txt_Count.text = self._currentBuyCount end return UICommonExchange