local UIHeroSubstituteMain = UIViewClass() function UIHeroSubstituteMain:OnOpened(context) self.isRegretSubstitute = context.isRegretSubstitute if not self.isRegretSubstitute then local itemCfgData = DataSheetManager.ItemData:GetDataByID(context.itemData.CfgId) if itemCfgData.FirstType ~= LuaConst.ItemHeroSubstituteType.AllCountry then self.countryLimit = itemCfgData.ThirdType end end self.itemExpireTime = context.itemData.ExpireTime self.itemId = context.itemData.Id if self.isRegretSubstitute then local heroSubstituteItemExtraData = MDL.Bag.GetHeroReSubstituteItemExtraDataById(self.itemId) self.sourceHeroId = heroSubstituteItemExtraData.hero1ID self.targetHeroId = heroSubstituteItemExtraData.hero2ID UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_HeroSubstitute_Title_2) else self.sourceHeroId = 0 self.targetHeroId = 0 UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_HeroSubstitute_Title_1) UIUtils.SetLabelText(self.txt_Tips, Const_IDS.IDS_HeroSubstitute_Hint_7) end UIUtils.SetActive(self.UICommonPopUp.img_Info, true) UIUtils.SetActive(self.event_Confirm, not self.isRegretSubstitute) UIUtils.SetActive(self.event_Regret, self.isRegretSubstitute) self:RegistSystemEvent(EventID.UI_HeroSubstitute_UpdateSlotHero, self.UpdateSlotHero) self:RefreshItemExpireTime() self:RefreshSourceHeroInfo() self:RefreshTargetHeroInfo() if self.isRegretSubstitute then UIUtils.SetLabel(self.txt_Tips, string.FormatByIdsId(Const_IDS.IDS_HeroSubstitute_Hint_13,self.sourceName,self.targetName)) end end function UIHeroSubstituteMain:UpdateSlotHero(isSelectedTargetSolt, heroId) if isSelectedTargetSolt then self.targetHeroId = heroId self:RefreshTargetHeroInfo() else self.sourceHeroId = heroId self:RefreshSourceHeroInfo() end end function UIHeroSubstituteMain:RefreshItemExpireTime() if self.itemExpireTime and self.itemExpireTime > 0 then UIUtils.SetActive(self.img_TimeBG, true) local ids = self.isRegretSubstitute and "IDS_HeroSubstitute_Hint_2" or "IDS_HeroSubstitute_Hint_1" local str = string.FormatByIdsId(Const_IDS[ids], UIUtils.GetLocalizedTxt(Const_IDS.IDS_FreeBuy_TimeInfo)) self.group_Time:SetCustomString(str,1,1) self.group_Time:ResetAndBeginTimer(false, self.itemExpireTime - UTL.Time.GetServerTimestamp(), 0) else UIUtils.SetActive(self.img_TimeBG, false) end end function UIHeroSubstituteMain:RefreshSourceHeroInfo() if self.sourceHeroId > 0 then self.cell_Hero_01.cell_hero1_state:SetState(1) UTL.Color.SetQualityImageByType(self.cell_Hero_01.img_Qua, CTL.HeroAwaken.GetHeroQuality(self.sourceHeroId, MDL.HeroAwaken.GetIsHeroAwaken(self.sourceHeroId)), UTL.Color.QualityType.Square) UTL.Item.SetHeroIconByHeroId(self.cell_Hero_01.img_Hero, self.sourceHeroId, MDL.HeroAwaken.GetIsHeroAwaken(self.sourceHeroId)) self.sourceName = CTL.HeroSelect.GetHeroQualityName(self.sourceHeroId) local heroBreak = MDL.HeroStar.GetHeroStarLevel(self.sourceHeroId) if heroBreak == 0 then UIUtils.SetLabel(self.cell_Hero_01.txt_Name, self.sourceName) else UIUtils.SetLabel(self.cell_Hero_01.txt_Name, self.sourceName.."+"..heroBreak) end else self.cell_Hero_01.cell_hero1_state:SetState(0) end end function UIHeroSubstituteMain:RefreshTargetHeroInfo() if self.targetHeroId and self.targetHeroId > 0 then self.cell_Hero_02.cell_hero2_state:SetState(1) UTL.Color.SetQualityImageByType(self.cell_Hero_02.img_Qua, CTL.HeroAwaken.GetHeroQuality(self.targetHeroId, MDL.HeroAwaken.GetIsHeroAwaken(self.targetHeroId)), UTL.Color.QualityType.Square) UTL.Item.SetHeroIconByHeroId(self.cell_Hero_02.img_Hero, self.targetHeroId, MDL.HeroAwaken.GetIsHeroAwaken(self.targetHeroId)) self.targetName = CTL.HeroSelect.GetHeroQualityName(self.targetHeroId) local heroBreak = MDL.HeroStar.GetHeroStarLevel(self.targetHeroId) if heroBreak == 0 then UIUtils.SetLabel(self.cell_Hero_02.txt_Name, self.targetName) else UIUtils.SetLabel(self.cell_Hero_02.txt_Name, self.targetName.."+"..heroBreak) end else self.cell_Hero_02.cell_hero2_state:SetState(0) end end function UIHeroSubstituteMain:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIHeroSubstituteMain:OnClosed() UIUtils.SetActive(self.UICommonPopUp.img_Info, false) end function UIHeroSubstituteMain:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close or comp == self.event_Cancel then self:CloseView() elseif comp == self.UICommonPopUp.img_Info then if self.isRegretSubstitute then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.ReHeroSubstitute}) else UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.HeroSubstitute}) end elseif comp == self.event_Confirm then if self.targetHeroId == 0 or self.sourceHeroId ==0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroSubstitute_Hint_14"]) return end local heroId if CTL.HeroAwaken.IsEnableAwake(self.sourceHeroId) then heroId = self.sourceHeroId end if not heroId and CTL.HeroAwaken.IsEnableAwake(self.targetHeroId) then heroId = self.targetHeroId end if heroId then local heroNameIDS = DataSheetManager.HeroNum:GetDataByID(heroId).NameIDS UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_EquipMelting_Rebirth_Title, string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_UnAwaken, UIUtils.GetLocalizedTxt(Const_IDS[heroNameIDS])), function() local showStr = string.FormatByIdsId(Const_IDS["IDS_HeroSubstitute_Hint_3"], self.sourceName ,self.targetName) UTL.MessageBox.ShowOKCancelBox(nil, showStr, function() MDL.Bag.UseHeroSubstituteItemReq(self.itemId, self.sourceHeroId, self.targetHeroId, MDL.Bag.HeroSubstituteType.substitute) -- 确定置换 end ) end) else local showStr = string.FormatByIdsId(Const_IDS["IDS_HeroSubstitute_Hint_3"], self.sourceName ,self.targetName) UTL.MessageBox.ShowOKCancelBox(nil, showStr, function() MDL.Bag.UseHeroSubstituteItemReq(self.itemId, self.sourceHeroId, self.targetHeroId, MDL.Bag.HeroSubstituteType.substitute) -- 确定置换 end ) end elseif comp == self.event_Regret then if self.targetHeroId == 0 or self.sourceHeroId == 0 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroSubstitute_Hint_14"]) return end local showStr = string.FormatByIdsId(Const_IDS["IDS_HeroSubstitute_Hint_12"], self.sourceName ,self.targetName) UTL.MessageBox.ShowOKCancelBox(nil, showStr, function() MDL.Bag.UseHeroSubstituteItemReq(self.itemId, self.sourceHeroId, self.targetHeroId, MDL.Bag.HeroSubstituteType.regret) --- 确定反悔置换 end ) elseif comp == self.cell_Hero_01.event_click then if self.isRegretSubstitute then CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroSubstitute_Hint_6"]) return end UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroSubstituteChooseView, {selectedSourceHeroId = self.sourceHeroId, selectedTargetHeroId = self.targetHeroId, isSelectedTargetSolt = false, countryLimit = self.countryLimit}, "Formation/UIHeroChangeView") elseif comp == self.cell_Hero_02.event_click then if self.isRegretSubstitute then CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroSubstitute_Hint_6"]) return end UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroSubstituteChooseView, {selectedSourceHeroId = self.sourceHeroId, selectedTargetHeroId = self.targetHeroId, isSelectedTargetSolt = true, countryLimit = self.countryLimit}, "Formation/UIHeroChangeView") end end return UIHeroSubstituteMain