local UITreasureInfo = UIViewClass() local UnActiveInfoHeight = 600 local ActiveInfoHeight = 760 function UITreasureInfo:OnOpened(context) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshTreasureInfo) self:RegistSystemEvent(EventID.UI_UpdateTreasureInfo, self.RefreshTreasureInfo) self:RefreshTreasureInfo(context.treasureId) end function UITreasureInfo:OnButtonClicked(comp) if comp == self.btn_Active then if self.isEnough then MDL.Treasure.TreasureActiveReq(self.treasureId) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Horse_Information_6"]) end elseif comp == self.group_NeedItem.item.event_Click then local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(self.treasureId) UTL.ItemTips.ShowCommonTipsById(treasureData.Item_Table[1].ItemID) elseif comp == self.event_Attr then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureInfoView, {treasureId = self.treasureId}) elseif comp == self.btn_SkillEnlarge then local activeInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) local treasureSkillId if activeInfo and activeInfo.TreasureInfo.starLevel > 0 then local treasureInfo = activeInfo.TreasureInfo local treasureStarData = DataSheetManager.TreasureStar:GetDataByTreasureID_Star(self.treasureId, treasureInfo.starLevel - 1) treasureSkillId = treasureStarData.TreasureSkill else local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(self.treasureId) treasureSkillId = treasureData.TreasureSkill end UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSkillTips, {treasureId = self.treasureId, treasureSkillId = treasureSkillId}, "Common/UITalentSkillTips") elseif comp == self.btn_Enlarge then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureBreakDetail, {treasureId = self.treasureId, onlyShowSkill = true}, "HeroShow/UIHeroInfoView") end end function UITreasureInfo:RefreshTreasureInfo(treasureId) self.treasureId = treasureId or self.treasureId self.activeInfo = MDL.Treasure.GetTreasureInfo(treasureId) self:RefreshTreasureSkill(self.treasureId) self:RefreshTitleInfo(self.treasureId) self:RefreshInfoAndAttr(self.treasureId) self:RefreshTreasureDesc(self.treasureId) self:RefreshActiveItem(self.treasureId) UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.content_TreasureInfo) end function UITreasureInfo:RefreshTitleInfo(treasureId) local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) UIUtils.SetLabel(self.txt_TreasureTalent, treasureData.TreasureTalent) UIUtils.SetLabel(self.lab_TreasureName, UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[treasureData.TreasureName]), treasureData.TreasureQuality)) -- 宝物名 UIUtils.SetLabel(self.txt_Break, self.activeInfo and string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Handbook_Hero_BreakLevel), self.activeInfo.TreasureInfo.starLevel) or "") -- 突破等级 end function UITreasureInfo:RefreshInfoAndAttr(treasureId) local index = 0 --属性数量 if self.activeInfo then --战力 UTL.Attr.SetAttrItemByCompName(self.group_AttrList[1], 0, self.activeInfo.TreasureInfo.gs, true) --属性 index = 1 for i = 1, 3 do local v = self.activeInfo.TreasureInfo.attr.attrs[i] index = index + 1 if self.group_AttrList[index] == nil then self:InstantiateCollection(self.group_AttrList, self.group_AttrList[1].gameObject) end UIUtils.SetActive(self.group_AttrList[index].gameObject, true) UTL.Attr.SetAttrItemByCompName(self.group_AttrList[index], i, v, true) end for i = #self.group_AttrList, index + 1, -1 do self:DestroyCollection(self.group_AttrList, i) end self.panel_TreasureInfo:SetSizeDelta(nil, ActiveInfoHeight) else local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) --战力 local fight = UTL.Attr.CalculateFight(treasureData.Attr_Table) UTL.Attr.SetAttrItemByCompName(self.group_AttrList[1], 0, fight, true) index = 1 --属性 for i = 1, 3 do index = index + 1 if self.group_AttrList[index] == nil then self:InstantiateCollection(self.group_AttrList, self.group_AttrList[1].gameObject) end UIUtils.SetActive(self.group_AttrList[index].gameObject, true) UTL.Attr.SetAttrItemByCompName(self.group_AttrList[index], treasureData.Attr_Table[i].AttrType, treasureData.Attr_Table[i].AttrNum, true) end for i = #self.group_AttrList, index + 1, -1 do self:DestroyCollection(self.group_AttrList, i) end self.panel_TreasureInfo:SetSizeDelta(nil, UnActiveInfoHeight) end end function UITreasureInfo:RefreshTreasureSkill(treasureId) local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) local treasureSkillId = treasureData.TreasureSkill local treasureSkillData = DataSheetManager.TreasureSkillData:GetDataByTreasureSkill(treasureSkillId) -- 宝物技能 UIUtils.SetImageByAssetBundle(self.sprite_Skill, treasureSkillData.TreasureSkillIcon) UIUtils.SetLabelText(self.txt_SkillName, Const_IDS[treasureSkillData.TreasureSkillName]) self.txt_SkillDesc.text = UTL.String.FormatCombineTextByID(treasureSkillData.TreasureSkillDes) local treasureRelationData = CTL.Treasure.GetTreasureRelationData(treasureId) -- 羁绊技能 if treasureRelationData and MDL.HideGolden.IsShowGoldenByID(LuaConst.ShowGoldenType.Hero, treasureRelationData.HeroID) then UIUtils.SetActive(self.group_Fetter, true) UIUtils.SetLabel(self.txt_SkillRelationDes,CTL.Treasure.GetRelationSkillDesc(treasureId, 0)) else UIUtils.SetActive(self.group_Fetter, false) end end function UITreasureInfo:RefreshTreasureDesc(treasureId) local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) UIUtils.SetLabelText(self.txt_TreasureDesc, Const_IDS[treasureData.TreasureDes]) end function UITreasureInfo:RefreshActiveItem(treasureId) if not self.activeInfo then UIUtils.SetActive(self.group_Active.gameObject, true) local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(treasureId) local needItem = treasureData.Item_Table[1] local count = MDL.Bag.GetItemCount(needItem.ItemID) or 0 local countText if count >= needItem.ItemNum then self.isEnough = true countText = UTL.Color.FormatGreenColor(count) .. "/" .. needItem.ItemNum else self.isEnough = false countText = UTL.Color.FormatRedColor(count) .. "/" .. needItem.ItemNum end UTL.Item.SetItemCell(self.group_NeedItem.item, needItem.ItemID, countText) self.btn_Active:SetRedPoint(self.isEnough) self.btn_Active:SetGray(not self.isEnough, true) self.Loc_ChangeColor:SetState(self.isEnough and 0 or 1) else UIUtils.SetActive(self.group_Active.gameObject, false) end end return UITreasureInfo