local UIDrawStrawsMain = UIViewClass() local EventSystem = require('Event/EventSystem') local draw_straws_pb = require 'Proto.draw_straws_pb' local DrawStrawsAniName = "DrawStraws" local DrawStrawItem_CountFive = 5 local DrawStrawItem_CountTen = 10 local DrawStrawItem_CountFifty = 50 ---------------------------------- 系统函数 ----------------------------------- function UIDrawStrawsMain:OnOpened(context) self.isCanDraw = true UIUtils.SetActive(self.group_Reward.panel_TipsInfo, false) UIUtils.SetActive(self.btn_BgClose, false) self:RegistSystemEvent(EventID.UI_DrawStraws_RefreshMain, self.RefreshPanel) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_DrawStraws_RefreshRp, self.RefreshBtnTaskRp) self:InitPanel() MDL.DrawStraws.RequestMainPanel() end function UIDrawStrawsMain:OnClosed() if self.drawRewardItems then UIManager.OpenView(Const_UI_Lua.UIEnum.UIRewardGainPanel, self.drawRewardItems) end MDL.Reward.SetCloseRewardTipShow(false) end function UIDrawStrawsMain:OnButtonClicked(comp) if comp == self.btn_Task then -- 活跃任务 UIManager.OpenView(Const_UI_Lua.UIEnum.UIDrawStrawsPopUp, {selectIndex = 0, cfgData = self.cfgData}) elseif comp == self.btn_TitleInfo or comp == self.btn_TitleInfoLoc then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.DrawStraws}) elseif comp == self.btn_Info then -- 说明 UIManager.OpenView(Const_UI_Lua.UIEnum.UIDrawStrawsPopUp, {selectIndex = 1, cfgData = self.cfgData}) elseif comp == self.group_Reward.btn_Info02 then UIUtils.SetActive(self.group_Reward.panel_TipsInfo, true) UIUtils.SetActive(self.btn_BgClose, true) elseif comp == self.btn_BgClose then UIUtils.SetActive(self.group_Reward.panel_TipsInfo, false) UIUtils.SetActive(self.btn_BgClose, false) elseif comp == self.btn_Name then -- 武将详情 UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroSelectPanel, {heroID = self.cfgData.HeroID}) elseif comp == self.btn_Name02 then -- 日本新增武将详情 UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHeroSelectPanel, {heroID = self.cfgDataJP.HeroID}) elseif comp == self.btn_Reset then -- 重置进度 if not self.isCanDraw then return end if MDL.DrawStraws.IsHasDrawNumReward() then UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_DrawStraws_Reset, Const_IDS.IDS_DrawStraws_ResetInfo, MDL.DrawStraws.RequestReset) return end MDL.DrawStraws.RequestReset() elseif comp == self.group_Draw.btn_Five then -- 抽5次 if not self.isCanDraw then return end if self.multiDrawNum > UTL.Item.GetItemStockCount(self.cfgData.UseItem) then local itemData = DataSheetManager.ItemData:GetDataByID(self.cfgData.UseItem) CTL.Tips.AddTipsMsg(string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_DrawCard_Tip_LackItem"]), UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name]))) return end MDL.Reward.SetCloseRewardTipShow(true) MDL.DrawStraws.RequestDraw(self.multiDrawNum) elseif comp == self.group_Draw.btn_One then -- 抽1次 if not self.isCanDraw then return end if UTL.Item.GetItemStockCount(self.cfgData.UseItem) == 0 then local itemData = DataSheetManager.ItemData:GetDataByID(self.cfgData.UseItem) CTL.Tips.AddTipsMsg(string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_DrawCard_Tip_LackItem"]), UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name]))) return end MDL.Reward.SetCloseRewardTipShow(true) MDL.DrawStraws.RequestDraw(1) elseif comp == self.group_Draw.btn_Icon_One or comp == self.group_Draw.btn_Icon_Five then UTL.ItemTips.ShowCommonTipsById(self.cfgData.UseItem) else for i, item in ipairs (self.group_Reward.group_Gift) do if comp == item.item.event_Click then local itemData = self.totalRewardData.TotalReward_Table[i] local rewardState = MDL.DrawStraws.GetDrawCountRewardState(itemData.TotalNum) if rewardState == draw_straws_pb.State_ReachNoGet then MDL.DrawStraws.RequestDrawNumRewards(itemData.TotalNum) else UTL.ItemTips.ShowCommonTipsById(itemData.ItemId) end break end end end end function UIDrawStrawsMain:OnFocusChanged(isFocus) if isFocus then UIUtils.SetActive(self.img_One, false) end end function UIDrawStrawsMain:OnUIAnimationStoped(playingID) if self.aniID == playingID and self.drawRewardItems then UIManager.OpenView(Const_UI_Lua.UIEnum.UIRewardGainPanel, self.drawRewardItems) MDL.Reward.SetCloseRewardTipShow(false) self.isCanDraw = true self.drawRewardItems = nil end end function UIDrawStrawsMain:DrawStrawResShow() UIManager.OpenView(Const_UI_Lua.UIEnum.UIRewardGainPanel, self.drawRewardItems) MDL.Reward.SetCloseRewardTipShow(false) self.isCanDraw = true self.drawRewardItems = nil end ------------------------------------------------------------------------------- function UIDrawStrawsMain:InitPanel() self.cfgData = DataSheetManager.DrawStraws:GetDataByID(self.context.type) local heroData = DataSheetManager.HeroNum:GetDataByID(self.cfgData.HeroID) UIUtils.SetLabelText(self.txt_Name, Const_IDS[heroData.NameIDS]) UIUtils.SetLabel(self.txt_Qua, heroData.HeroIntelligence) --处理日本地区的逻辑 self:JPConfigAdjust() UTL.Item.SetItemIcon(self.group_Draw.btn_Icon_One, self.cfgData.UseItem) UTL.Item.SetItemIcon(self.group_Draw.btn_Icon_Five, self.cfgData.UseItem) self.totalRewardData = DataSheetManager.DrawStrawsTotalReward:GetDataByID(self.cfgData.DrawStrawsTotalReward) self.maxDrawCount = 0 for i, item in ipairs (self.group_Reward.group_Gift) do local itemData = self.totalRewardData.TotalReward_Table[i] if itemData then UIUtils.SetActive(item.gameObject, true) item.Fill.fillAmount = 0 UIUtils.SetLabel(item.txt_Point01, itemData.TotalNum) UTL.Item.SetItemCell(item.item, itemData.ItemId,itemData.ItemCount) item.State:SetState(0) if itemData.TotalNum > self.maxDrawCount then self.maxDrawCount = itemData.TotalNum end else UIUtils.SetActive(item.gameObject, false) end end UIUtils.SetLabel(self.group_Draw.txt_Task, string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_DrawStraws_Button_StartNum), 1)) end function UIDrawStrawsMain:RefreshPanel(drawRewardItems) -- 操作区 local stockCount = UTL.Item.GetItemStockCount(self.cfgData.UseItem) local drawCount = MDL.DrawStraws.GetDrawNumCount() UIUtils.SetLabel(self.group_Reward.txt_CurDrawNum, drawCount) UIUtils.SetLabel(self.group_Draw.txt_Num, stockCount >= 1 and UTL.Color.FormatWhiteColor("x" .. 1) or UTL.Color.FormatRedColor("x" .. 1)) local availableDrawCount = self.maxDrawCount - drawCount if availableDrawCount < DrawStrawItem_CountFive then-- 0~5 if stockCount == 0 then self.multiDrawNum = 1 else self.multiDrawNum = stockCount >= availableDrawCount and availableDrawCount or stockCount end elseif availableDrawCount < DrawStrawItem_CountTen then-- 5~10 self.multiDrawNum = DrawStrawItem_CountFive elseif availableDrawCount < DrawStrawItem_CountFifty then-- 10~50 self.multiDrawNum = stockCount >= DrawStrawItem_CountTen and DrawStrawItem_CountTen or DrawStrawItem_CountFive else --50以上 local canDrawNum = 0 if stockCount >= DrawStrawItem_CountFifty then canDrawNum = DrawStrawItem_CountFifty elseif stockCount >= DrawStrawItem_CountTen then canDrawNum = DrawStrawItem_CountTen else canDrawNum = DrawStrawItem_CountFive end self.multiDrawNum = canDrawNum end UIUtils.SetLabel(self.group_Draw.txt_MultipleTask, string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_DrawStraws_Button_StartNum), self.multiDrawNum)) UIUtils.SetLabel(self.group_Draw.txt_MultipleNum, stockCount >= self.multiDrawNum and UTL.Color.FormatWhiteColor("x" .. self.multiDrawNum) or UTL.Color.FormatRedColor("x" .. self.multiDrawNum)) UIUtils.SetActive(self.group_Draw.gameObject, drawCount < self.maxDrawCount) UIUtils.SetActive(self.btn_Reset, drawCount == self.maxDrawCount) -- 奖励进度 for i, item in ipairs (self.group_Reward.group_Gift) do local itemData = self.totalRewardData.TotalReward_Table[i] if itemData then item.Fill.fillAmount = 0 if drawCount >= itemData.TotalNum then item.Fill.fillAmount = 1 else local formerItemData = self.totalRewardData.TotalReward_Table[i - 1] if not formerItemData or (formerItemData and drawCount <= itemData.TotalNum and drawCount >= formerItemData.TotalNum) then local startNum = formerItemData and formerItemData.TotalNum or 0 item.Fill.fillAmount = (drawCount - startNum) / (itemData.TotalNum - startNum) end end item.State:SetState(0) local rewardState = MDL.DrawStraws.GetDrawCountRewardState(itemData.TotalNum) if rewardState == draw_straws_pb.State_ReachNoGet then item.effect_Reward:PlayUIEffect() item.State:SetState(1) elseif rewardState == draw_straws_pb.State_Get then item.State:SetState(2) end end end if drawRewardItems then -- 抽签结果 self.isCanDraw = false self.drawRewardItems = drawRewardItems UIUtils.SetActive(self.img_One, true) if self.aniID then self:PlayUIAnimation(self.aniID) else self.aniID = self:PlayUIAnimation(DrawStrawsAniName, true) end CTL.Sound.PlayGameSound("UI_drawing") end self:RefreshBtnTaskRp() end function UIDrawStrawsMain:RefreshBtnTaskRp() self.btn_Task:SetRedPoint(MDL.DrawStraws.IsHasTaskReward()) end --日本地区在这个界面多投放一个黄忠 function UIDrawStrawsMain:JPConfigAdjust() if GameAppInfo.IsJapanesePackage() then UIUtils.SetActive(self.group_JP, true) if self.context.typeJP then self.cfgDataJP = DataSheetManager.DrawStraws:GetDataByID(self.context.typeJP) local heroData = DataSheetManager.HeroNum:GetDataByID(self.cfgDataJP.HeroID) UIUtils.SetLabelText(self.txt_Name02, Const_IDS[heroData.NameIDS]) UIUtils.SetLabel(self.txt_Qua02, heroData.HeroIntelligence) end else UIUtils.SetActive(self.group_JP, false) end end return UIDrawStrawsMain