local UIEquipStarSpecialAttr = UIViewClass() local equip_pb = require('Proto/equip_pb') local FormationIndexToSettingState = { LuaConst.BattleSettingEnum.LockEquipStarSkill1, LuaConst.BattleSettingEnum.LockEquipStarSkill2, LuaConst.BattleSettingEnum.LockEquipStarSkill3, LuaConst.BattleSettingEnum.LockEquipStarSkill4, LuaConst.BattleSettingEnum.LockEquipStarSkill5, LuaConst.BattleSettingEnum.LockEquipStarSkill6 } function UIEquipStarSpecialAttr:OnOpened(context) self.UICommonPopUpTab.loop_Tab:AddData(Const_IDS.IDS_EquipStar_Tittle8, 0) self.UICommonPopUpTab.loop_Tab:AddData(Const_IDS.IDS_EquipStar_Tittle9, 0) self.UICommonPopUpTab.loop_Tab:SelectIndex(0) self:RegistSystemEvent(EventID.UI_EquipStarSkillOpt, self.OnEquipStarSkillOpt) UIUtils.SetLabelText(self.UICommonPopUpTab.txt_Title, Const_IDS.IDS_EquipStar_Tittle7) local heroStage, heroStar = MDL.Equipment.GetHeroStageAndStar(self.context.heroId) local data = DataSheetManager.EquipStarStage:GetDataByStarStage(heroStage) UIUtils.SetImageByAssetBundle(self.titleImg_Star, data.Icon) self.titleTxt_Num.text = heroStar end function UIEquipStarSpecialAttr:ShowCurSkillInfo() local heroInfo = MDL.HeroSelect.GetHeroInfo(self.context.heroId) self.equipStarSkillId = heroInfo.equipStarSkillId local skillData = DataSheetManager.EquipSkillLib:GetDataByEquipSkillID(heroInfo.equipStarSkillId) UIUtils.SetImageByAssetBundle(self.img_AttrLevel1, skillData.SkillLevelIcon) self.txt_AttrInfo1.text = string.gsub(UIUtils.GetLocalizedTxt(Const_IDS[skillData.EquipSkillDes]), " ", " ") end function UIEquipStarSpecialAttr:ShowLevelUp() self:ShowCurSkillInfo() if self.context.curSkillMax then self.state_Btn:SetState(0) self.state_Preview:SetState(2) self.btn_LevelUp:SetGray(true) UIUtils.SetActive(self.group_Cost, false) UIUtils.SetActive(self.group_Lock, false) UIUtils.SetActive(self.lab_Level, false) else UIUtils.SetActive(self.group_Cost, true) UIUtils.SetActive(self.group_Lock, true) local stageData = DataSheetManager.EquipStarStage:GetDataByStarStage(self.context.nextStage) self.stageData = stageData local index = MDL.Formation.GetSlotIndexByHeroId(self.context.heroId) local state = MDL.Setting.GetState(FormationIndexToSettingState[index]) or false if self.toggle_Lock.isOn ~= state then self.toggle_Lock.isOn = state else self:SetCostInfo(stageData, state) end self.state_Btn:SetState(0) self:CalCanLevelUp() end self.state_Lab:SetState(0) end function UIEquipStarSpecialAttr:ShowSwitch() UIUtils.SetActive(self.lab_Level, false) local heroInfo = MDL.HeroSelect.GetHeroInfo(self.context.heroId) self:ShowCurSkillInfo() UIUtils.SetActive(self.group_Cost, true) UIUtils.SetActive(self.group_Lock, true) if heroInfo.equipStarReplaceSkillId > 0 then self.state_Btn:SetState(2) self.state_Preview:SetState(0) local skillData = DataSheetManager.EquipSkillLib:GetDataByEquipSkillID(heroInfo.equipStarReplaceSkillId) UIUtils.SetImageByAssetBundle(self.img_AttrLevel2, skillData.SkillLevelIcon) self.txt_AttrInfo2.text = string.gsub(UIUtils.GetLocalizedTxt(Const_IDS[skillData.EquipSkillDes]), " ", " ") else self.state_Btn:SetState(1) self.state_Preview:SetState(1) local heroStage, heroStar = MDL.Equipment.GetHeroStageAndStar(self.context.heroId) local startage = DataSheetManager.EquipSkillLib:GetDataByEquipSkillID(heroInfo.equipStarSkillId) local skillStage = nil for i, v in DataSheetManager.EquipStarStage:GetEnumerator() do if startage.EquipSkillLibID == v.EquipSkillLibID then skillStage = v break end end self.costEnough = true UIUtils.SetImageByAssetBundle(self.img_Star, skillStage.Icon) self.txt_Num.text = skillStage.LibStarLevel self:SetCollectionCost(self.icon_Cost3, self.txt_Cost3, skillStage.ReplaceCostItemID[1], skillStage.ReplaceCostItemNum[1]) self:SetCollectionCost(self.icon_Cost4, self.txt_Cost4, skillStage.ReplaceCostItemID[2], skillStage.ReplaceCostItemNum[2]) end self.state_Lab:SetState(1) end function UIEquipStarSpecialAttr:OnCellInit(scrollRect, index, cellTable, data) UIUtils.SetLabelText(cellTable.txt_Name_Nomal, data) UIUtils.SetLabelText(cellTable.txt_Name_Selected, data) cellTable.state_ArrowState:SetState(0) end function UIEquipStarSpecialAttr:OnCellSelect(scrollRect, index, cellTable, data) self.selectIndex = index if index == 0 then self:ShowLevelUp() else self:ShowSwitch() end end function UIEquipStarSpecialAttr:ClickChange() if self.costEnough then MDL.Equipment.EquipStarSkillOptReq(equip_pb.ESChange, self.context.heroId) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Equip_Enchance_CoinNotEnough) end end function UIEquipStarSpecialAttr:ClickLevelUp() local data = self:GetNextSkillData(self.equipStarSkillId) if data == nil then--满级 CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips13) else if self.canLevelUp then if self.costEnough then if self:HasEquipStarReplaceSkillId() then MDL.Equipment.EquipStarSkillOptReq(equip_pb.ESLevelUp, self.context.heroId, self.toggle_Lock.isOn) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Equip_Enchance_CoinNotEnough) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_EquipStar_Tips14) end end end function UIEquipStarSpecialAttr:OnButtonClicked(comp) if comp == self.UICommonPopUpTab.btn_Close then self:CloseView() elseif comp == self.btn_View then UIManager.OpenView(Const_UI_Lua.UIEnum.UIEquipStarAttrPreview, { heroId = self.context.heroId, isShowNext = self.selectIndex == 0 }) elseif comp == self.btn_LevelUp then self:ClickLevelUp() elseif comp == self.btn_Change then self:ClickChange() elseif comp == self.btn_Cancel then MDL.Equipment.EquipStarSkillOptReq(equip_pb.ESCancelReplace, self.context.heroId) elseif comp == self.btn_Confirm then MDL.Equipment.EquipStarSkillOptReq(equip_pb.ESReplace, self.context.heroId) end end function UIEquipStarSpecialAttr:SetCostInfo(data, isLock) if isLock then self.costEnough = true self:SetCollectionCost(self.icon_Cost1, self.txt_Cost1, data.LevelUPCostItemID[1], data.LevelUPCostItemNum[1]) self:SetCollectionCost(self.icon_Cost2, self.txt_Cost2, data.LevelUPCostItemID[2], data.LevelUPCostItemNum[2]) self.state_Preview:SetState(0) local skillData = self:GetNextSkillData(self.equipStarSkillId) if skillData then UIUtils.SetImageByAssetBundle(self.img_AttrLevel2, skillData.SkillLevelIcon) self.txt_AttrInfo2.text = string.gsub(UIUtils.GetLocalizedTxt(Const_IDS[skillData.EquipSkillDes]), " ", " ") else self.state_Btn:SetState(0) self.state_Preview:SetState(2) self.btn_LevelUp:SetGray(true) UIUtils.SetActive(self.group_Cost, false) UIUtils.SetActive(self.group_Lock, false) UIUtils.SetActive(self.lab_Level, false) end else self.costEnough = true self:SetCollectionCost(self.icon_Cost1, self.txt_Cost1, data.LibUPCostItemID[1], data.LibUPCostItemNum[1]) self:SetCollectionCost(self.icon_Cost2, self.txt_Cost2, data.LibUPCostItemID[2], data.LibUPCostItemNum[2]) self.state_Preview:SetState(1) UIUtils.SetImageByAssetBundle(self.img_Star, data.Icon) self.txt_Num.text = data.LibStarLevel end end function UIEquipStarSpecialAttr:SetCollectionCost(img, txt, id, count) UTL.Item.ItemIconWithoutBg(img, id) local hasCount = CTL.Bag.GetHasCountByItemCfgID(id) if hasCount >= count then txt.text = UTL.Color.FormatWhiteColor(count) else txt.text = UTL.Color.FormatRedColor(count) self.costEnough = false end end function UIEquipStarSpecialAttr:GetNextSkillData(skilId) local skillData = DataSheetManager.EquipSkillLib:GetDataByEquipSkillID(skilId) for i, v in DataSheetManager.EquipSkillLib:GetEnumerator() do if skillData.EquipSkillTypeID == v.EquipSkillTypeID and skilId < v.EquipSkillID then return v end end end function UIEquipStarSpecialAttr:OnValueChanged(comp, value) if comp == self.toggle_Lock then self:SetCostInfo(self.stageData, value) local index = MDL.Formation.GetSlotIndexByHeroId(self.context.heroId) MDL.Setting.PrepareSetSettingState(FormationIndexToSettingState[index], value) MDL.Setting.SendPlayerSetting() end end function UIEquipStarSpecialAttr:OnEquipStarSkillOpt(msg) if msg.opt == equip_pb.ESCancelReplace then self:ShowSwitch() elseif msg.opt == equip_pb.ESChange then self:ShowSwitch() elseif msg.opt == equip_pb.ESReplace then self:ShowSwitch() elseif msg.opt == equip_pb.ESLevelUp then self:CalSkillMax() self:CalNextStage() self:ShowLevelUp() end end function UIEquipStarSpecialAttr:HasEquipStarReplaceSkillId() local heroInfo = MDL.HeroSelect.GetHeroInfo(self.context.heroId) if heroInfo.equipStarReplaceSkillId > 0 then UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_EquipStar_Tips17, function() MDL.Equipment.EquipStarSkillOptReq(equip_pb.ESLevelUp, self.context.heroId, self.toggle_Lock.isOn) end) return false end return true end function UIEquipStarSpecialAttr:CalCanLevelUp() local data = self:GetNextSkillData(self.equipStarSkillId) local stage, num for i, v in DataSheetManager.EquipStarStage:GetEnumerator() do if data.EquipSkillLibID == v.EquipSkillLibID then stage = v.StarStage num = v.LibStarLevel break end end local heroStage, heroStar, _ = MDL.Equipment.GetHeroStageAndStar(self.context.heroId) if heroStage > stage or (heroStage == stage and num <= heroStar) then self.canLevelUp = true UIUtils.SetActive(self.lab_Level, false) else self.canLevelUp = false local stageData = DataSheetManager.EquipStarStage:GetDataByStarStage(stage) UIUtils.SetImageByAssetBundle(self.img_LockStar, stageData.Icon) self.txt_LockNum.text = stageData.LibStarLevel UIUtils.SetActive(self.lab_Level, true) end end function UIEquipStarSpecialAttr:CalSkillMax() local heroInfo = MDL.HeroSelect.GetHeroInfo(self.context.heroId) local skillData = DataSheetManager.EquipSkillLib:GetDataByEquipSkillID(heroInfo.equipStarSkillId) local skillData = self:GetNextSkillData(heroInfo.equipStarSkillId) if skillData then self.context.curSkillMax = false else self.context.curSkillMax = true end end function UIEquipStarSpecialAttr:CalNextStage() local heroInfo = MDL.HeroSelect.GetHeroInfo(self.context.heroId) local skillData = DataSheetManager.EquipSkillLib:GetDataByEquipSkillID(heroInfo.equipStarSkillId) if heroInfo.equipStarSkillId > 0 then local stage = nil for i, v in DataSheetManager.EquipStarStage:GetEnumerator() do if v.EquipSkillLibID > skillData.EquipSkillLibID then self.context.nextStage = v.StarStage break end end end end return UIEquipStarSpecialAttr